♻️ Address pull request feedback
This commit is contained in:
61
src/components/Manage/Board/delete-board.modal.tsx
Normal file
61
src/components/Manage/Board/delete-board.modal.tsx
Normal file
@@ -0,0 +1,61 @@
|
||||
import { Button, Group, Stack, Text, Title } from '@mantine/core';
|
||||
import { ContextModalProps, modals } from '@mantine/modals';
|
||||
import { Trans, useTranslation } from 'next-i18next';
|
||||
import { api } from '~/utils/api';
|
||||
|
||||
type InnerProps = { boardName: string; onConfirm: () => Promise<void> };
|
||||
|
||||
export const DeleteBoardModal = ({ id, innerProps }: ContextModalProps<InnerProps>) => {
|
||||
const { t } = useTranslation('manage/boards');
|
||||
const utils = api.useContext();
|
||||
const { isLoading, mutateAsync } = api.config.delete.useMutation({
|
||||
onSuccess: async () => {
|
||||
await utils.config.all.invalidate();
|
||||
modals.close(id);
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<Stack>
|
||||
<Text>{t('modals.delete.text')}</Text>
|
||||
|
||||
<Group grow>
|
||||
<Button
|
||||
onClick={() => {
|
||||
modals.close(id);
|
||||
}}
|
||||
variant="light"
|
||||
color="gray"
|
||||
>
|
||||
{t('common:cancel')}
|
||||
</Button>
|
||||
<Button
|
||||
onClick={async () => {
|
||||
modals.close(id);
|
||||
await innerProps.onConfirm();
|
||||
await mutateAsync({
|
||||
name: innerProps.boardName,
|
||||
});
|
||||
}}
|
||||
disabled={isLoading}
|
||||
variant="light"
|
||||
color="red"
|
||||
>
|
||||
{t('common:delete')}
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
|
||||
export const openDeleteBoardModal = (innerProps: InnerProps) => {
|
||||
modals.openContextModal({
|
||||
modal: 'deleteBoardModal',
|
||||
title: (
|
||||
<Title order={4}>
|
||||
<Trans i18nKey="manage/boards:modals.delete.title" />
|
||||
</Title>
|
||||
),
|
||||
innerProps,
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user