2022-12-10 22:14:31 +01:00
|
|
|
import { Button, Group, Stack, Text } from '@mantine/core';
|
|
|
|
|
import { ContextModalProps } from '@mantine/modals';
|
2023-01-13 10:57:13 +09:00
|
|
|
import { Trans, useTranslation } from 'next-i18next';
|
2023-07-21 18:08:40 +09:00
|
|
|
|
2023-09-03 16:23:40 +02:00
|
|
|
import { useConfigContext } from '~/config/provider';
|
|
|
|
|
import { useConfigStore } from '~/config/store';
|
2022-12-10 22:14:31 +01:00
|
|
|
|
2022-12-16 21:01:06 +01:00
|
|
|
export type WidgetsRemoveModalInnerProps = {
|
2023-03-30 22:54:08 +02:00
|
|
|
widgetId: string;
|
2023-03-30 22:20:56 +02:00
|
|
|
widgetType: string;
|
2022-12-10 22:14:31 +01:00
|
|
|
};
|
|
|
|
|
|
2022-12-16 21:01:06 +01:00
|
|
|
export const WidgetsRemoveModal = ({
|
2022-12-10 22:14:31 +01:00
|
|
|
context,
|
|
|
|
|
id,
|
|
|
|
|
innerProps,
|
2022-12-16 21:01:06 +01:00
|
|
|
}: ContextModalProps<WidgetsRemoveModalInnerProps>) => {
|
2023-03-30 22:20:56 +02:00
|
|
|
const { t } = useTranslation([`modules/${innerProps.widgetType}`, 'common']);
|
2022-12-19 19:01:50 +01:00
|
|
|
const { name: configName } = useConfigContext();
|
|
|
|
|
if (!configName) return null;
|
|
|
|
|
const updateConfig = useConfigStore((x) => x.updateConfig);
|
2022-12-10 22:14:31 +01:00
|
|
|
const handleDeletion = () => {
|
2022-12-19 21:27:44 +01:00
|
|
|
updateConfig(
|
|
|
|
|
configName,
|
|
|
|
|
(prev) => ({
|
|
|
|
|
...prev,
|
2023-03-30 22:54:08 +02:00
|
|
|
widgets: prev.widgets.filter((w) => w.id !== innerProps.widgetId),
|
2022-12-19 21:27:44 +01:00
|
|
|
}),
|
|
|
|
|
true
|
|
|
|
|
);
|
2022-12-10 22:14:31 +01:00
|
|
|
context.closeModal(id);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Stack>
|
2023-01-13 10:57:13 +09:00
|
|
|
<Trans
|
|
|
|
|
i18nKey="common:removeConfirm"
|
|
|
|
|
components={[<Text weight={500} />]}
|
2023-03-30 22:20:56 +02:00
|
|
|
values={{ item: innerProps.widgetType }}
|
2023-01-13 10:57:13 +09:00
|
|
|
/>
|
2022-12-10 22:14:31 +01:00
|
|
|
<Group position="right">
|
|
|
|
|
<Button onClick={() => context.closeModal(id)} variant="light">
|
2022-12-20 16:54:22 +09:00
|
|
|
{t('common:cancel')}
|
2022-12-10 22:14:31 +01:00
|
|
|
</Button>
|
2022-12-20 16:54:22 +09:00
|
|
|
<Button onClick={() => handleDeletion()}>{t('common:ok')}</Button>
|
2022-12-10 22:14:31 +01:00
|
|
|
</Group>
|
|
|
|
|
</Stack>
|
|
|
|
|
);
|
|
|
|
|
};
|