import { useState } from "react" import { ShieldCheck } from "@phosphor-icons/react" import { useT } from "../../i18n" import { unwrap } from "../../lib/desktop" import { ActionButton, InlineNotice, Input, TextArea } from "../ui" import { describeActionError } from "./execution-utils" export function SecretCreator({ companyId, onSaved }: { companyId: string; onSaved: () => Promise }) { const t = useT() const [name, setName] = useState(""); const [description, setDescription] = useState(""); const [value, setValue] = useState("") const [errors, setErrors] = useState<{ name?: string; value?: string }>({}); const [submitError, setSubmitError] = useState(null); const [submitting, setSubmitting] = useState(false) function validate(): boolean { const next: typeof errors = {} if (!name.trim()) next.name = "Secret name is required." else if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name.trim())) next.name = "Name must be alphanumeric with underscores, starting with a letter or underscore." if (!value.trim()) next.value = "Secret value cannot be empty." setErrors(next); return Object.keys(next).length === 0 } return (
{ setName(v); if (errors.name) setErrors((e) => ({ ...e, name: undefined })) }} placeholder="e.g. ANTHROPIC_API_KEY" />{errors.name ?
{errors.name}
: null}