| 1 | "use client"; |
| 2 | |
| 3 | import { |
| 4 | useAuth, |
| 5 | useAuthPlugin, |
| 6 | useCopyToClipboard, |
| 7 | } from "@better-auth-ui/react"; |
| 8 | import { Check, Copy |
| 9 | import { toast } |
| 10 | |
| 11 | import { Button } |
| 12 | import { |
| 13 | Dialog, |
| 14 | DialogContent, |
| 15 | DialogDescription, |
| 16 | DialogFooter, |
| 17 | DialogHeader, |
| 18 | DialogTitle, |
| 19 | } from "@/components/ui/dialog"; |
| 20 | import { |
| 21 | InputGroup, |
| 22 | InputGroupAddon, |
| 23 | InputGroupButton, |
| 24 | InputGroupInput, |
| 25 | } from "@/components/ui/input-group"; |
| 26 | import { Label } |
| 27 | import { apiKeyPlugin } |
| 28 | |
| 29 | export type NewApiKeyDialogProps |
| 30 | open: boolean |
| 31 | onOpenChange: (open |
| 32 | name: string |
| 33 | secretKey: string |
| 34 | }; |
| 35 | |
| 36 | export function NewApiKeyDialog({ |
| 37 | open, |
| 38 | onOpenChange, |
| 39 | name, |
| 40 | secretKey, |
| 41 | }: NewApiKeyDialogProps) |
| 42 | const { localization |
| 43 | const { localization: |
| 44 | |
| 45 | const { copied, |
| 46 | onError: (error) |
| 47 | toast.error(error |
| 48 | }); |
| 49 | |
| 50 | const handleOpenChange = |
| 51 | if (!nextOpen) |
| 52 | reset(); |
| 53 | } |
| 54 | |
| 55 | onOpenChange(nextOpen); |
| 56 | }; |
| 57 | |
| 58 | const copySecretKey = |
| 59 | if (!secretKey) |
| 60 | |
| 61 | await copy(secretKey |
| 62 | }; |
| 63 | |
| 64 | return ( |
| 65 | <Dialog open={ |
| 66 | <DialogContent showCloseButton={ |
| 67 | <DialogHeader> |
| 68 | <DialogTitle className=" |
| 69 | <Key /> |
| 70 | {apiKeyLocalization.newApiKey} |
| 71 | </DialogTitle> |
| 72 | |
| 73 | <DialogDescription> |
| 74 | {apiKeyLocalization.newApiKeyWarning} |
| 75 | </DialogDescription> |
| 76 | </DialogHeader> |
| 77 | |
| 78 | <div className="flex flex-col gap-2 |
| 79 | <Label htmlFor=" |
| 80 | {name || apiKeyLocalization |
| 81 | </Label> |
| 82 | |
| 83 | <InputGroup> |
| 84 | <InputGroupInput |
| 85 | id="new-api-key-secret" |
| 86 | value={secretKey ?? |
| 87 | readOnly |
| 88 | className="font-mono text-xs" |
| 89 | /> |
| 90 | |
| 91 | <InputGroupAddon align=" |
| 92 | <InputGroupButton |
| 93 | size="icon-xs" |
| 94 | aria-label={ |
| 95 | copied |
| 96 | ? localization.settings. |
| 97 | : localization.settings. |
| 98 | } |
| 99 | onClick={copySecretKey} |
| 100 | > |
| 101 | {copied ? <Check |
| 102 | </InputGroupButton> |
| 103 | </InputGroupAddon> |
| 104 | </InputGroup> |
| 105 | </div> |
| 106 | |
| 107 | <DialogFooter> |
| 108 | <Button type=" |
| 109 | {apiKeyLocalization.dismissNewKey} |
| 110 | </Button> |
| 111 | </DialogFooter> |
| 112 | </DialogContent> |
| 113 | </Dialog> |
| 114 | ); |
| 115 | } |