-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathdelete-discussion.tsx
More file actions
53 lines (48 loc) · 1.45 KB
/
delete-discussion.tsx
File metadata and controls
53 lines (48 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { Trash } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { ConfirmationDialog } from '@/components/ui/dialog';
import { useNotifications } from '@/components/ui/notifications';
import { Authorization, ROLES } from '@/lib/authorization';
import { useDeleteDiscussion } from '../api/delete-discussion';
type DeleteDiscussionProps = {
id: string;
};
export const DeleteDiscussion = ({ id }: DeleteDiscussionProps) => {
const { addNotification } = useNotifications();
const deleteDiscussionMutation = useDeleteDiscussion({
mutationConfig: {
onSuccess: () => {
addNotification({
type: 'success',
title: 'Discussion Deleted',
});
},
},
});
return (
<Authorization allowedRoles={[ROLES.ADMIN]}>
<ConfirmationDialog
icon="danger"
title="Delete Discussion"
body="Are you sure you want to delete this discussion?"
triggerButton={
<Button variant="destructive" icon={<Trash className="size-4" />}>
Delete Discussion
</Button>
}
confirmButton={
<Button
isLoading={deleteDiscussionMutation.isPending}
type="button"
variant="destructive"
onClick={() =>
deleteDiscussionMutation.mutate({ discussionId: id })
}
>
Delete Discussion
</Button>
}
/>
</Authorization>
);
};