* The create dialog's state-bearing body, shared by both key kinds. Remounted * per open via a key bump (self-contained modal): form and in-flight state are * destroyed on close instead of hand-reset, while the Dialog shell stays * mounted so Radix's exit animation keeps its last frame. A create
(props: {
readonly title: string;
readonly description: string;
readonly defaultName: string;
readonly placeholder: string;
readonly onCreate: (name: string) => Promise<CreatedKey | null>;
readonly onCopy: (kind: "value" | "bearer_header") => void;
})
| 159 | * next open on the previous key's reveal. |
| 160 | */ |
| 161 | function CreateKeyDialogBody(props: { |
| 162 | readonly title: string; |
| 163 | readonly description: string; |
| 164 | readonly defaultName: string; |
| 165 | readonly placeholder: string; |
| 166 | readonly onCreate: (name: string) => Promise<CreatedKey | null>; |
| 167 | readonly onCopy: (kind: "value" | "bearer_header") => void; |
| 168 | }) { |
| 169 | const [name, setName] = useState(props.defaultName); |
| 170 | const [createdKey, setCreatedKey] = useState<CreatedKey | null>(null); |
| 171 | const [creating, setCreating] = useState(false); |
| 172 | |
| 173 | const handleCreate = async () => { |
| 174 | const trimmed = name.trim(); |
| 175 | if (!trimmed) return; |
| 176 | setCreating(true); |
| 177 | const created = await props.onCreate(trimmed); |
| 178 | setCreating(false); |
| 179 | if (created) setCreatedKey(created); |
| 180 | }; |
| 181 | |
| 182 | return ( |
| 183 | <> |
| 184 | <DialogHeader> |
| 185 | <DialogTitle className="font-display text-xl">{props.title}</DialogTitle> |
| 186 | <DialogDescription className="text-sm leading-relaxed"> |
| 187 | {props.description} |
| 188 | </DialogDescription> |
| 189 | </DialogHeader> |
| 190 | |
| 191 | {createdKey ? ( |
| 192 | <CreatedKeyReveal value={createdKey.value} onCopy={props.onCopy} /> |
| 193 | ) : ( |
| 194 | <div className="grid gap-4 py-3"> |
| 195 | <div className="grid gap-1.5"> |
| 196 | <Label htmlFor="create-key-name" className="text-sm font-medium text-foreground"> |
| 197 | Name |
| 198 | </Label> |
| 199 | <Input |
| 200 | id="create-key-name" |
| 201 | value={name} |
| 202 | onChange={(event) => setName(event.target.value)} |
| 203 | placeholder={props.placeholder} |
| 204 | maxLength={80} |
| 205 | autoFocus |
| 206 | /> |
| 207 | </div> |
| 208 | </div> |
| 209 | )} |
| 210 | |
| 211 | <DialogFooter> |
| 212 | <DialogClose asChild> |
| 213 | <Button variant="ghost">Close</Button> |
| 214 | </DialogClose> |
| 215 | {!createdKey && ( |
| 216 | <Button onClick={handleCreate} disabled={creating || !name.trim()}> |
| 217 | {creating ? "Creating..." : "Create key"} |
| 218 | </Button> |
nothing calls this directly
no outgoing calls
no test coverage detected