import { useState } from "react"; import { errorMessage } from "../api/client.js"; import { useUpsertSecret } from "../api/hooks.js"; import { FormInput } from "./FormControls.jsx"; import { Modal } from "./Modal.jsx"; import { DEFAULT_OWNER } from "../lib/tenant.js"; /** * Add / replace an encrypted secret. * * @param {"add" | "replace"} mode * @param {{ owner: string, name?: string }} initial * @param {() => void} onClose * @param {(saved: unknown) => void} [onSaved] */ export function SecretEditorModal({ mode, initial, onClose, onSaved }) { const upsert = useUpsertSecret(); const [form, setForm] = useState(() => ({ owner: initial.owner || DEFAULT_OWNER, name: initial.name || "", value: "", })); function onSubmit(e) { e.preventDefault(); upsert.mutate( { owner: form.owner, name: form.name, value: form.value }, { onSuccess: (data) => { onSaved?.(data?.secret ?? data); onClose(); }, }, ); } const title = mode === "add" ? "New secret" : `Replace ${form.name}`; return (

{title}

{mode === "add" ? ( ) : null}

Values are encrypted at rest and never shown again after save. Values shorter than 8 characters are not redacted from logs. In workflows use{" "} {"{{ secrets.name }}"} (quote in YAML).

{upsert.isError ? (

{errorMessage(upsert.error)}

) : null}
); }