| 1 | "use client"; |
| 2 | |
| 3 | import { KeyRound } from |
| 4 | import { useAction } |
| 5 | import { toast } |
| 6 | |
| 7 | import { |
| 8 | AlertDialog, |
| 9 | AlertDialogCancel, |
| 10 | AlertDialogContent, |
| 11 | AlertDialogDescription, |
| 12 | AlertDialogFooter, |
| 13 | AlertDialogHeader, |
| 14 | AlertDialogTitle, |
| 15 | AlertDialogTrigger, |
| 16 | } from "@/components/ui/alert-dialog"; |
| 17 | import { Button } |
| 18 | import { Card } |
| 19 | import { Spinner } |
| 20 | import type { WebhookOwner |
| 21 | |
| 22 | import { rollWebhookSecret } |
| 23 | import { SecretAlert } |
| 24 | |
| 25 | export function RollSecretCard({ |
| 26 | owner, |
| 27 | webhook, |
| 28 | }: { |
| 29 | owner: WebhookOwner |
| 30 | webhook: { |
| 31 | }) { |
| 32 | const roll = |
| 33 | onError: ({ error |
| 34 | toast.error(error |
| 35 | }); |
| 36 | const secret = |
| 37 | |
| 38 | return ( |
| 39 | <section className="flex flex-col gap-3 |
| 40 | <h2 className="text-sm font-semibold |
| 41 | {secret && <SecretAlert |
| 42 | <Card className=" |
| 43 | <p className="text-sm text-muted-foreground |
| 44 | Replace the secret if it leaked. The old one stops working at once. |
| 45 | </p> |
| 46 | <AlertDialog> |
| 47 | <AlertDialogTrigger asChild> |
| 48 | <Button size=" |
| 49 | <KeyRound /> |
| 50 | Replace secret |
| 51 | </Button> |
| 52 | </AlertDialogTrigger> |
| 53 | <AlertDialogContent> |
| 54 | <AlertDialogHeader> |
| 55 | <AlertDialogTitle>Replace the signing secret?</AlertDialogTitle |
| 56 | <AlertDialogDescription> |
| 57 | Every delivery from now on, retries included, is signed with the |
| 58 | new secret. {webhook.url} rejects them until it has the new one. |
| 59 | </AlertDialogDescription> |
| 60 | </AlertDialogHeader> |
| 61 | <AlertDialogFooter> |
| 62 | <AlertDialogCancel>Cancel</AlertDialogCancel |
| 63 | <AlertDialogCancel asChild> |
| 64 | <Button |
| 65 | disabled={roll.isExecuting |
| 66 | onClick={() => |
| 67 | > |
| 68 | {roll.isExecuting && |
| 69 | Replace secret |
| 70 | </Button> |
| 71 | </AlertDialogCancel> |
| 72 | </AlertDialogFooter> |
| 73 | </AlertDialogContent> |
| 74 | </AlertDialog> |
| 75 | </Card> |
| 76 | </section> |
| 77 | ); |
| 78 | } |