-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeleteTeamDialog.tsx
93 lines (89 loc) · 3.36 KB
/
DeleteTeamDialog.tsx
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
'use client';
import { Button } from '@/components/ui/button';
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from '@/components/ui/dialog';
import { deleteTeamFromOrganization } from '@/data/admin/teams';
import { useSAToastMutation } from '@/hooks/useSAToastMutation';
import { TrashIcon } from 'lucide-react';
import UsersIcon from 'lucide-react/dist/esm/icons/users';
import { useRouter } from 'next/navigation';
import { useState } from 'react';
type DeleteTeamDialogProps = {
organizationId: string;
teamId: number;
teamName: string;
isOrganizationAdmin: boolean;
};
export function DeleteTeamDialog({ organizationId, teamId, teamName, isOrganizationAdmin }: DeleteTeamDialogProps) {
const [open, setOpen] = useState(false);
const router = useRouter();
const { mutate, isLoading } = useSAToastMutation(
async () => await deleteTeamFromOrganization(teamId, organizationId),
{
loadingMessage: 'Deleting team...',
successMessage: 'Team deleted successfully!',
errorMessage: 'Failed to delete team',
onSuccess: () => {
setOpen(false);
router.refresh();
},
},
);
const handleDelete = () => {
if (!isOrganizationAdmin) return;
mutate();
};
return (
<>
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<Button variant="destructive" size="sm" disabled={!isOrganizationAdmin || isLoading}>
<TrashIcon className="size-4" />
</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<div className="p-3 w-fit bg-gray-200/50 dark:bg-gray-700/40 mb-2 rounded-lg">
<UsersIcon className="w-6 h-6" />
</div>
<div className="p-1">
<DialogTitle className="text-lg">Delete Team</DialogTitle>
<DialogDescription className="text-base mt-0">
Are you sure you want to delete the team "{teamName}"? This action cannot be undone.
</DialogDescription>
</div>
</DialogHeader>
<DialogFooter>
<Button
type="button"
variant="outline"
disabled={isLoading}
className="w-full"
onClick={() => {
setOpen(false);
}}
>
Cancel
</Button>
<Button
type="button"
variant="destructive"
className="w-full"
disabled={isLoading}
onClick={handleDelete}
>
{isLoading ? 'Deleting Team...' : 'Delete Team'}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</>
);
}