import type { PluginDashboardViewContext } from "@fusion/dashboard/app/plugins/types"; import { useMemo, useState } from "react"; import { BasicsStep, CredentialsStep, EndpointsStep, ReviewStep, TransportStep } from "./wizard/steps.js"; import type { ServiceDraft, WizardStep } from "./wizard/types.js"; import { validateBasics, validateCredentials, validateEndpoints, validateTransport } from "./wizard/validation.js"; import "./dashboard-view.css"; const STEPS: WizardStep[] = ["basics", "transport", "endpoints", "credentials", "review"]; function createInitialDraft(): ServiceDraft { const now = new Date().toISOString(); return { id: "", name: "", slug: "", description: "", baseUrl: "", transport: "http", endpoints: [{ id: crypto.randomUUID(), name: "", method: "GET", path: "" }], credential: { kind: "none" }, createdAt: now, updatedAt: now }; } export function CliPrintingPressWizardView({ context: _context }: { context?: PluginDashboardViewContext }) { const [draft, setDraft] = useState(() => createInitialDraft()); const [stepIndex, setStepIndex] = useState(0); const [savedId, setSavedId] = useState(null); const [error, setError] = useState(null); 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 onSave() { const response = await fetch("/api/plugins/fusion-plugin-cli-printing-press/drafts", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(draft) }); if (!response.ok) { const body = await response.json().catch(() => ({} as { error?: string; errors?: Record })); const firstError = body?.errors ? Object.values(body.errors)[0] : undefined; setError(body?.error ?? firstError ?? "Failed to save draft"); return; } const body = await response.json(); setSavedId(body.id); } if (savedId) { return

Saved — draft id {savedId}

List, edit, regenerate, run/test, and runtime exposure land in FN-3764 / FN-3765 / FN-3767.

; } return
{STEPS.map((step, index) => {step})}
{error ?

{error}

: null}{currentStep === "basics" ? setDraft((current) => ({ ...current, ...patch, updatedAt: new Date().toISOString() }))} /> : null}{currentStep === "transport" ? : null}{currentStep === "endpoints" ? setDraft((current) => ({ ...current, endpoints, updatedAt: new Date().toISOString() }))} /> : null}{currentStep === "credentials" ? setDraft((current) => ({ ...current, credential, updatedAt: new Date().toISOString() }))} /> : null}{currentStep === "review" ? : null}
{stepIndex < STEPS.length - 1 ? : }
; } export default CliPrintingPressWizardView;