import { useState } from "react"; import { FIELD_INPUT, FIELD_LABEL, FORM_BUTTON, FORM_BUTTON_SECONDARY, FORM_ERROR, FORM_FIELDSET, } from "./form-shared"; interface Props { connectorId: string; onSaved?: () => void; } export function VertexForm({ connectorId, onSaved }: Props) { const [project, setProject] = useState(""); const [location, setLocation] = useState(""); const [credentialsPath, setCredentialsPath] = useState(""); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const handleSubmit = async () => { const desktop = window.agentCompany; if (!desktop) return; if (project.trim().length === 0 || location.trim().length === 0) { setError("Project and location are required."); return; } setBusy(true); setError(null); const result = await desktop.saveCredential({ connectorId, payload: { kind: "gcp_adc", value: { project: project.trim(), location: location.trim(), credentialsPath: credentialsPath.trim() || undefined, }, }, }); setBusy(false); if (!result.ok) { setError(result.error.message); return; } onSaved?.(); }; const pickCredentialsFile = async () => { const desktop = window.agentCompany; if (!desktop) return; const result = await desktop.pickDirectory(); if (result.ok && result.data) setCredentialsPath(result.data); }; return (
{ event.preventDefault(); void handleSubmit(); }} className={FORM_FIELDSET} >
setProject(event.target.value)} disabled={busy} className={FIELD_INPUT} placeholder="my-gcp-project" />
setLocation(event.target.value)} disabled={busy} className={FIELD_INPUT} placeholder="us-central1" />
setCredentialsPath(event.target.value)} disabled={busy} className={FIELD_INPUT} placeholder="/path/to/service-account.json" />
{error ?
{error}
: null}
); }