import { useMemo, useState } from "react"; import { BasicsStep, CredentialsStep, EndpointsStep, TransportStep } from "../wizard/steps.js"; import type { ServiceDraft, WizardStep } from "../wizard/types.js"; import { validateBasics, validateCredentials, validateDraft, validateEndpoints, validateTransport } from "../wizard/validation.js"; const STEPS: WizardStep[] = ["basics", "transport", "endpoints", "credentials", "review"]; export function EditDraftModal({ initialDraft, onClose, onSave, }: { initialDraft: ServiceDraft; onClose: () => void; onSave: (draft: ServiceDraft) => Promise; }) { const [draft, setDraft] = useState(initialDraft); const [stepIndex, setStepIndex] = useState(0); const [error, setError] = useState(null); const [saving, setSaving] = useState(false); const currentStep = STEPS[stepIndex]; const currentValidation = useMemo(() => { if (currentStep === "basics") return validateBasics(draft); if (currentStep === "transport") return validateTransport(draft); if (currentStep === "endpoints") return validateEndpoints(draft); if (currentStep === "credentials") return validateCredentials(draft.credential); return { ok: true } as const; }, [currentStep, draft]); async function saveDraft() { const validation = validateDraft(draft); if (!validation.ok) { setError(Object.values(validation.errors)[0] ?? "Draft validation failed"); return; } setSaving(true); setError(null); try { await onSave(draft); } catch (err) { setError(err instanceof Error ? err.message : "Failed to save draft"); } finally { setSaving(false); } } return (

Edit Service CLI Draft

{error ?

{error}

: null} {currentStep === "basics" ? setDraft((current) => ({ ...current, ...patch }))} /> : null} {currentStep === "transport" ? : null} {currentStep === "endpoints" ? setDraft((current) => ({ ...current, endpoints }))} /> : null} {currentStep === "credentials" ? setDraft((current) => ({ ...current, credential }))} /> : null} {currentStep === "review" ?
{JSON.stringify(draft, null, 2)}
: null}
{stepIndex < STEPS.length - 1 ? ( ) : ( )}
); }