diff --git a/frontend/src/pages/WorkflowEditor.tsx b/frontend/src/pages/WorkflowEditor.tsx index cef2ffa..6753d2d 100644 --- a/frontend/src/pages/WorkflowEditor.tsx +++ b/frontend/src/pages/WorkflowEditor.tsx @@ -70,7 +70,6 @@ export default function WorkflowEditor() { useEffect(() => { if (!id) return; - setWorkflowId(id); setLoading(true); workflowsApi .get(id) @@ -105,13 +104,12 @@ export default function WorkflowEditor() { .map((t) => t.trim()) .filter(Boolean); - const buildMetadataPayload = (status?: Workflow['status']) => ({ + const buildMetadataPayload = () => ({ title, description: description || undefined, categoryId: categoryId || undefined, tags: parseTags(), isTemplate, - ...(status ? { status } : {}), }); const syncSteps = async (wfId: string) => { @@ -161,7 +159,7 @@ export default function WorkflowEditor() { setSaving(true); try { if (isNew) { - // Build create payload with tenantId, status, and inline steps + // Build create payload with tenantId and inline steps const effectiveTenantId = tenantId || user?.tenantId; if (!effectiveTenantId) { toast.error('Bitte wählen Sie einen Mandanten'); @@ -175,7 +173,6 @@ export default function WorkflowEditor() { categoryId: categoryId || undefined, tags: parseTags(), isTemplate, - status: status || 'DRAFT', steps: steps.map((s, idx) => ({ title: s.title || 'Unbenannter Schritt', content: s.content || ' ', @@ -185,15 +182,26 @@ export default function WorkflowEditor() { })), }; const created = await workflowsApi.create(createPayload as Partial); + // Change status if not DRAFT (status must be set via separate endpoint) + if (status && status !== 'DRAFT') { + await workflowsApi.changeStatus(created.id, status); + } toast.success('Workflow erstellt'); - navigate(`/workflows/${created.id}/edit`, { replace: true }); + navigate(`/workflows/${created.id}`, { replace: true }); } else { // Update metadata first - const payload = buildMetadataPayload(status); + const payload = buildMetadataPayload(); await workflowsApi.update(id!, payload as Partial); // Sync steps via individual step endpoints await syncSteps(id!); + // Change status if requested (via separate endpoint) + if (status) { + await workflowsApi.changeStatus(id!, status); + } toast.success('Workflow gespeichert'); + if (status === 'PUBLISHED') { + navigate(`/workflows/${id}`, { replace: true }); + } } } catch { toast.error('Speichern fehlgeschlagen'); @@ -211,7 +219,8 @@ export default function WorkflowEditor() { autoSaveTimer.current = setTimeout(async () => { if (!title.trim()) return; try { - await workflowsApi.update(id!, buildMetadataPayload() as Partial); + const payload = buildMetadataPayload(); + await workflowsApi.update(id!, payload as Partial); setAutoSaved(true); setTimeout(() => setAutoSaved(false), 2000); } catch {