| 1 | "use client"; |
| 2 | |
| 3 | import { Trash2 } from |
| 4 | import { useRouter } |
| 5 | import { useAction } |
| 6 | import { toast } |
| 7 | |
| 8 | import { |
| 9 | AlertDialog, |
| 10 | AlertDialogCancel, |
| 11 | AlertDialogContent, |
| 12 | AlertDialogDescription, |
| 13 | AlertDialogFooter, |
| 14 | AlertDialogHeader, |
| 15 | AlertDialogTitle, |
| 16 | AlertDialogTrigger, |
| 17 | } from "@/components/ui/alert-dialog"; |
| 18 | import { Button } |
| 19 | import { Card } |
| 20 | import { FieldError } |
| 21 | import { Spinner } |
| 22 | import { type WebhookOwner, |
| 23 | |
| 24 | import { deleteWebhook } |
| 25 | |
| 26 | export function DeleteWebhookCard({ |
| 27 | owner, |
| 28 | webhook, |
| 29 | }: { |
| 30 | owner: WebhookOwner |
| 31 | webhook: { |
| 32 | }) { |
| 33 | const router = |
| 34 | const remove = |
| 35 | onSuccess: () => |
| 36 | toast.success("Webhook deleted |
| 37 | router.push(webhooksPath |
| 38 | }, |
| 39 | }); |
| 40 | |
| 41 | return ( |
| 42 | <section> |
| 43 | <h2 className="mb-3 text-sm font-semibold |
| 44 | <Card className=" |
| 45 | <p className="text-sm text-muted-foreground |
| 46 | Stops all deliveries, including retries still waiting. |
| 47 | </p> |
| 48 | <AlertDialog> |
| 49 | <AlertDialogTrigger asChild> |
| 50 | <Button size=" |
| 51 | <Trash2 /> |
| 52 | Delete |
| 53 | </Button> |
| 54 | </AlertDialogTrigger> |
| 55 | <AlertDialogContent> |
| 56 | <AlertDialogHeader> |
| 57 | <AlertDialogTitle>Delete this webhook?</AlertDialogTitle |
| 58 | <AlertDialogDescription> |
| 59 | {webhook.url} stops receiving deliveries, and its delivery log |
| 60 | is deleted. |
| 61 | </AlertDialogDescription> |
| 62 | </AlertDialogHeader> |
| 63 | {remove.result.serverError |
| 64 | <FieldError>{remove. |
| 65 | )} |
| 66 | <AlertDialogFooter> |
| 67 | <AlertDialogCancel>Cancel</AlertDialogCancel |
| 68 | <Button |
| 69 | variant="destructive" |
| 70 | disabled={remove.isExecuting |
| 71 | onClick={() => |
| 72 | > |
| 73 | {remove.isExecuting && |
| 74 | Delete webhook |
| 75 | </Button> |
| 76 | </AlertDialogFooter> |
| 77 | </AlertDialogContent> |
| 78 | </AlertDialog> |
| 79 | </Card> |
| 80 | </section> |
| 81 | ); |
| 82 | } |