/** * NewWorkflowModal (Phase 4a) — the "New workflow" chooser. Replaces the old * FlowsPage `/chat` TODO with three ways to start: * * - **Start from scratch** — `flows_create` a blank graph carrying a single * `manual` trigger, then open it in the editable canvas. * - **From a template** — switch to the {@link FlowTemplateGallery} view; * picking a card creates a flow from that template's graph and opens it. * * The old "Describe it" option was dropped: the Flows page already shows the * `WorkflowPromptBar` at all times (hero when empty, compact otherwise), so a * modal option that only re-focused that same bar was redundant. * * Create + navigate is delegated to {@link useCreateFlow}; this component only * owns which view is showing and assembles the name/graph for each path. */ import createDebug from 'debug'; import { useState } from 'react'; import { createBlankWorkflowGraph } from '../../lib/flows/newFlow'; import { type FlowTemplate, templateNameKey } from '../../lib/flows/templates'; import { useT } from '../../lib/i18n/I18nContext'; import { ModalShell } from '../ui/ModalShell'; import FlowTemplateGallery from './FlowTemplateGallery'; import { BLANK_FLOW_KEY, useCreateFlow } from './useCreateFlow'; interface NewWorkflowModalProps { onClose: () => void; } type View = 'chooser' | 'gallery'; /** One big tap-target row in the chooser view. */ function ChooserOption({ testId, title, description, disabled, onClick, }: { testId: string; title: string; description: string; disabled?: boolean; onClick: () => void; }) { return ( ); } const log = createDebug('app:flows:new'); export default function NewWorkflowModal({ onClose }: NewWorkflowModalProps) { const { t } = useT(); const [view, setView] = useState('chooser'); const { create, busyKey, error, clearError } = useCreateFlow(); const startFromScratch = () => { const name = t('flows.page.newWorkflow'); const graph = createBlankWorkflowGraph(name, t('flows.nodeKind.trigger')); log('start from scratch'); void create(BLANK_FLOW_KEY, name, graph); }; const startFromTemplate = (template: FlowTemplate) => { const name = t(templateNameKey(template.id)); log('start from template: id=%s', template.id); void create(template.id, name, template.graph); }; const openGallery = () => { clearError(); setView('gallery'); }; const backToChooser = () => { clearError(); setView('chooser'); }; const busy = Boolean(busyKey); const title = view === 'gallery' ? t('flows.templates.title') : t('flows.chooser.title'); const subtitle = view === 'gallery' ? t('flows.templates.subtitle') : t('flows.chooser.subtitle'); return (
{error && (

{error}

)} {view === 'chooser' ? ( <> ) : ( <> )}
); }