Files
Homarr/src/components/Dashboard/Tiles/Widgets/WidgetsRemoveModal.tsx

49 lines
1.4 KiB
TypeScript
Raw Normal View History

2022-12-10 22:14:31 +01:00
import React from 'react';
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';
2022-12-19 19:01:50 +01:00
import { useConfigContext } from '../../../../config/provider';
import { useConfigStore } from '../../../../config/store';
2022-12-10 22:14:31 +01:00
export type WidgetsRemoveModalInnerProps = {
2022-12-19 19:01:50 +01:00
widgetId: string;
2022-12-10 22:14:31 +01:00
};
export const WidgetsRemoveModal = ({
2022-12-10 22:14:31 +01:00
context,
id,
innerProps,
}: ContextModalProps<WidgetsRemoveModalInnerProps>) => {
2022-12-19 19:01:50 +01:00
const { t } = useTranslation([`modules/${innerProps.widgetId}`, 'common']);
const { name: configName } = useConfigContext();
if (!configName) return null;
const updateConfig = useConfigStore((x) => x.updateConfig);
2022-12-10 22:14:31 +01:00
const handleDeletion = () => {
updateConfig(
configName,
(prev) => ({
...prev,
widgets: prev.widgets.filter((w) => w.id !== innerProps.widgetId),
}),
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} />]}
values={{ item: innerProps.widgetId }}
/>
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>
);
};