| import { Trash2 } from "lucide-react"; |
| 4 | import { useRouter } from "next/navigation"; |
| 5 | import { useAction } from "next-safe-action/hooks"; |
| 6 | import { toast } from "sonner"; |
| 7 |
| 8 | import { deleteOauthApp } from "@/components/oauth-apps/actions"; |
| 9 | import { |
| 10 | AlertDialog, |
| 11 | AlertDialogCancel, |
| 12 | AlertDialogContent, |
| 13 | AlertDialogDescription, |
| 14 | AlertDialogFooter, |
| 15 | AlertDialogHeader, |
| 16 | AlertDialogTitle, |
| 17 | AlertDialogTrigger, |
| 18 | } from "@/components/ui/alert-dialog"; |
| 19 | import { Button } from "@/components/ui/button"; |
| 20 | import { Card } from "@/components/ui/card"; |
| 21 | import { FieldError } from "@/components/ui/field"; |
| 22 | import { Spinner } from "@/components/ui/spinner"; |
| 23 |
| 24 | import { oauthAppsPath } from "./paths"; |
| 25 |
| 26 | export function DeleteOauthAppCard({ |
| 27 | app, |
| 28 | organization, |
| 29 | }: { |
| 30 | app: { clientId: string; name: string }; |
| 31 | organization?: string; |
| 32 | }) { |
| 33 | const router = useRouter(); |
| 34 | const remove = useAction(deleteOauthApp, { |
| 35 | onSuccess: () => { |
| 36 | toast.success(`${app.name} deleted`); |
| 37 | router.push(oauthAppsPath(organization)); |
| 38 | }, |
| 39 | }); |
| 40 |
| 41 | return ( |
| 42 | <section> |
| 43 | <h2 className="mb-3 text-sm font-semibold">Delete</h2> |
| 44 | <Card className="flex-row items-center justify-between gap-4 border-destructive/40 px-6"> |
| 45 | <p className="text-sm text-muted-foreground"> |
| 46 | Signs everyone out of {app.name}. Its access to every account ends at |
| 47 | once. |
| 48 | </p> |
| 49 | <AlertDialog> |
| 50 | <AlertDialogTrigger asChild> |
| 51 | <Button size="sm" variant="destructive" className="shrink-0"> |
| 52 | <Trash2 /> |
| 53 | Delete app |
| 54 | </Button> |
| 55 | </AlertDialogTrigger> |
| 56 | <AlertDialogContent> |
| 57 | <AlertDialogHeader> |
| 58 | <AlertDialogTitle>Delete {app.name}?</AlertDialogTitle> |
| 59 | <AlertDialogDescription> |
| 60 | Every token it was given, for every person, stops working. This |
| 61 | cannot be undone. |
| 62 | </AlertDialogDescription> |
| 63 | </AlertDialogHeader> |
| 64 | {remove.result.serverError && ( |
| 65 | <FieldError>{remove.result.serverError}</FieldError> |
| 66 | )} |
| 67 | <AlertDialogFooter> |
| 68 | <AlertDialogCancel>Cancel</AlertDialogCancel> |
| 69 | <Button |
| 70 | variant="destructive" |
| 71 | disabled={remove.isExecuting} |
| 72 | onClick={() => remove.execute({ clientId: app.clientId })} |
| 73 | > |
| 74 | {remove.isExecuting && <Spinner />} |
| 75 | Delete app |
| 76 | </Button> |
| 77 | </AlertDialogFooter> |
| 78 | </AlertDialogContent> |
| 79 | </AlertDialog> |
| 80 | </Card> |
| 81 | </section> |
| 82 | ); |
| 83 | } |