| 1 | "use client"; |
| 2 | |
| 3 | import { KeyRound } from |
| 4 | import { useAction } |
| 5 | import { toast } |
| 6 | |
| 7 | import { |
| 8 | AlertDialog, |
| 9 | AlertDialogAction, |
| 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 { Spinner } |
| 21 | import type { WebhookOwner |
| 22 | |
| 23 | import { rollWebhookSecret } |
| 24 | import { SecretAlert } |
| 25 | |
| 26 | export function RollSecretCard({ |
| 27 | owner, |
| 28 | webhook, |
| 29 | }: { |
| 30 | owner: WebhookOwner |
| 31 | webhook: { |
| 32 | }) { |
| 33 | const roll = |
| 34 | onError: ({ error |
| 35 | toast.error(error |
| 36 | }); |
| 37 | const secret = |
| 38 | |
| 39 | return ( |
| 40 | <section className="flex flex-col gap-3 |
| 41 | <h2 className="text-sm font-semibold |
| 42 | {secret && ( |
| 43 | <SecretAlert |
| 44 | title={`Copy the signing secret for ${webhook |
| 45 | description={ |
| 46 | <> |
| 47 | Ghost will not show it again. Use it to check the{" "} |
| 48 | <code className="font-mono text-xs |
| 49 | header on each delivery. |
| 50 | </> |
| 51 | } |
| 52 | secret={secret} |
| 53 | /> |
| 54 | )} |
| 55 | <Card className=" |
| 56 | <p className="text-sm text-muted-foreground |
| 57 | Replace the secret if it leaked. The old one stops working at once. |
| 58 | </p> |
| 59 | <AlertDialog> |
| 60 | <AlertDialogTrigger asChild> |
| 61 | <Button size=" |
| 62 | <KeyRound /> |
| 63 | Replace secret |
| 64 | </Button> |
| 65 | </AlertDialogTrigger> |
| 66 | <AlertDialogContent> |
| 67 | <AlertDialogHeader> |
| 68 | <AlertDialogTitle>Replace the signing secret?</AlertDialogTitle |
| 69 | <AlertDialogDescription> |
| 70 | Every delivery from now on, retries included, is signed with the |
| 71 | new secret. {webhook.url} rejects them until it has the new one. |
| 72 | </AlertDialogDescription> |
| 73 | </AlertDialogHeader> |
| 74 | <AlertDialogFooter> |
| 75 | <AlertDialogCancel>Cancel</AlertDialogCancel |
| 76 | <AlertDialogAction |
| 77 | disabled={roll.isExecuting |
| 78 | onClick={() => |
| 79 | > |
| 80 | {roll.isExecuting && |
| 81 | Replace secret |
| 82 | </AlertDialogAction> |
| 83 | </AlertDialogFooter> |
| 84 | </AlertDialogContent> |
| 85 | </AlertDialog> |
| 86 | </Card> |
| 87 | </section> |
| 88 | ); |
| 89 | } |