| 1 | 'use client' |
| 2 | |
| 3 | import { useRouter } from '@bprogress/next/app' |
| 4 | import { AlertTriangle } |
| 5 | import { useAction } |
| 6 | import { useState } |
| 7 | import { toast } |
| 8 | import { ConfirmDeleteDialog } |
| 9 | import { Button } |
| 10 | import { |
| 11 | Card, |
| 12 | CardContent, |
| 13 | CardDescription, |
| 14 | CardHeader, |
| 15 | CardTitle, |
| 16 | } from '@/components/ui/card' |
| 17 | import { deleteProjectAction } |
| 18 | |
| 19 | export function DangerZoneCard({ |
| 20 | project, |
| 21 | organizationId, |
| 22 | orgSlug, |
| 23 | }: { |
| 24 | project: { |
| 25 | organizationId: string |
| 26 | orgSlug: string |
| 27 | }) { |
| 28 | const router = |
| 29 | const [open, |
| 30 | |
| 31 | const { execute, |
| 32 | onSuccess() { |
| 33 | toast.success('Project deleted |
| 34 | router.replace(`/ |
| 35 | }, |
| 36 | onError({ error |
| 37 | toast.error(error |
| 38 | }, |
| 39 | }) |
| 40 | |
| 41 | return ( |
| 42 | <> |
| 43 | <Card className=' |
| 44 | <CardHeader> |
| 45 | <CardTitle className=' |
| 46 | <CardDescription> |
| 47 | Permanently delete this project and all of its data. This action |
| 48 | cannot be undone. |
| 49 | </CardDescription> |
| 50 | </CardHeader> |
| 51 | <CardContent> |
| 52 | <Button |
| 53 | loading={isPending} |
| 54 | onClick={() => |
| 55 | variant='destructive' |
| 56 | > |
| 57 | <AlertTriangle className=' |
| 58 | Delete Project |
| 59 | </Button> |
| 60 | </CardContent> |
| 61 | </Card> |
| 62 | |
| 63 | <ConfirmDeleteDialog |
| 64 | confirmationText={project.name |
| 65 | description={ |
| 66 | <> |
| 67 | This will permanently delete{' '} |
| 68 | <span className='font-semibold text-foreground |
| 69 | "{project.name}" |
| 70 | </span>{' '} |
| 71 | and all associated data including timesheets, invoices, and |
| 72 | milestones. This action cannot be undone. |
| 73 | </> |
| 74 | } |
| 75 | onConfirm={() => |
| 76 | execute({ |
| 77 | projectId: project.id |
| 78 | confirmName: project.name |
| 79 | organizationId, |
| 80 | }) |
| 81 | }} |
| 82 | onOpenChange={setOpen} |
| 83 | open={open} |
| 84 | title='Delete Project' |
| 85 | /> |
| 86 | </> |
| 87 | ) |
| 88 | } |