| 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 { deleteOrganizationAction } |
| 18 | |
| 19 | export function DangerZoneCard({ |
| 20 | organization, |
| 21 | }: { |
| 22 | organization: { |
| 23 | }) { |
| 24 | const router = |
| 25 | const [open, |
| 26 | |
| 27 | const { execute, |
| 28 | onSuccess() { |
| 29 | toast.success('Workspace deleted |
| 30 | router.push('/ |
| 31 | }, |
| 32 | onError({ error |
| 33 | toast.error(error |
| 34 | }, |
| 35 | }) |
| 36 | |
| 37 | return ( |
| 38 | <> |
| 39 | <Card className=' |
| 40 | <CardHeader> |
| 41 | <CardTitle className=' |
| 42 | <CardDescription> |
| 43 | Permanently delete this workspace and all of its data. This action |
| 44 | cannot be undone. |
| 45 | </CardDescription> |
| 46 | </CardHeader> |
| 47 | <CardContent> |
| 48 | <Button onClick={ |
| 49 | <AlertTriangle className=' |
| 50 | Delete Workspace |
| 51 | </Button> |
| 52 | </CardContent> |
| 53 | </Card> |
| 54 | |
| 55 | <ConfirmDeleteDialog |
| 56 | actionLabel='Delete Workspace' |
| 57 | confirmationText={organization.name |
| 58 | description={ |
| 59 | <> |
| 60 | This will permanently delete{' '} |
| 61 | <span className='font-semibold text-foreground |
| 62 | {organization.name} |
| 63 | </span>{' '} |
| 64 | and all associated data including projects, timesheets, and |
| 65 | invoices. This action cannot be undone. |
| 66 | </> |
| 67 | } |
| 68 | loading={isPending} |
| 69 | onConfirm={() => |
| 70 | execute({ |
| 71 | organizationId: organization.id |
| 72 | confirmName: organization.name |
| 73 | }) |
| 74 | } |
| 75 | onOpenChange={setOpen} |
| 76 | open={open} |
| 77 | title='Delete Workspace' |
| 78 | /> |
| 79 | </> |
| 80 | ) |
| 81 | } |