// "API-Schluessel bearbeiten" on the shared FormDialog chrome. // // The edit route rendered the boilerplate ApiKeyForm inside an OpenModal, so it // wore the same odd popup shape the create route did — plus a FormGroup footer // whose delete button raised its own confirm. The fields are the same three the // action already accepts; rotate and delete sit in their own section below them, // because both are irreversible in a way that saving a new alias is not. // // Presentational: the route owns the submits. The admin API-key routes keep the // shared ApiKeyForm for now. import { useState } from "react"; import { useTranslation } from "react-i18next"; import { FeatherRefreshCw, FeatherSave, FeatherTrash2 } from "@subframe/core"; import { Alert } from "~/ui/components/Alert"; import { Button } from "~/ui/components/Button"; import { Checkbox } from "~/ui/components/Checkbox"; import { TextInput } from "~/ui/components/TextInput"; import { DateField } from "../tasks/DateField"; import { FormDialog } from "../shared/FormDialog"; export type ApiKeyEditInput = { alias: string; /** ISO date (yyyy-mm-dd) or "" for a key that does not expire. */ expires: string; active: boolean; }; export type ApiKeyEditData = { /** Redacted key (prefix…last four) — the raw secret never reaches the client. */ redactedKey: string; alias: string; expires: string; active: boolean; canUpdate: boolean; canDelete: boolean; canRotate: boolean; }; export function ApiKeyEditDialog({ data, submitting, errorMessage, onSave, onRotate, onDelete, onClose, }: { data: ApiKeyEditData; submitting: boolean; errorMessage: string | null; onSave: (input: ApiKeyEditInput) => void; onRotate: () => void; onDelete: () => void; onClose: () => void; }): React.JSX.Element { const { t } = useTranslation(); const [alias, setAlias] = useState(data.alias); const [expires, setExpires] = useState(data.expires); const [active, setActive] = useState(data.active); const [confirm, setConfirm] = useState<"rotate" | "delete" | null>(null); const disabled = !data.canUpdate; const canSubmit = !disabled && alias.trim().length > 0 && !submitting; if (confirm) { const isDelete = confirm === "delete"; return ( (open ? undefined : setConfirm(null))} size="xs" uiId={`ui.settings.apiKeys.editDialog.${confirm}Confirm`} title={isDelete ? t("models.apiKey.deleteTitle") : t("models.apiKey.rotateTitle")} footer={ <> } > {isDelete ? t("models.apiKey.deleteBody", { alias: data.alias }) : t("models.apiKey.rotateBody", { alias: data.alias })} ); } return ( (open ? undefined : onClose())} title={t("models.apiKey.editTitle")} subtitle={data.redactedKey} uiId="ui.settings.apiKeys.editDialog" footer={ <> } > {errorMessage ? : null} setAlias(event.target.value)} disabled={disabled} autoComplete="off" required data-ui-id="ui.settings.apiKeys.editDialog.alias" />
{t("models.apiKey.expiresHint")}
setActive(checked)} /> {data.canRotate || data.canDelete ? (
{/* Both are irreversible in a way that renaming a key is not, so they stand apart from the save action and ask before they run. */} {t("models.apiKey.dangerSection")}
{data.canRotate ? ( ) : null} {data.canDelete ? ( ) : null}
) : null}
); }