fix: WorkflowEditor crash (setWorkflowId undefined) + status via PATCH endpoint
- Remove non-existent setWorkflowId call that caused white screen - Use separate PATCH /status endpoint for publish/review (not in PUT payload) - Redirect to workflow view after publishing
This commit is contained in:
parent
acaec8e0c2
commit
9e3b431e7c
@ -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<Workflow>);
|
||||
// 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<Workflow>);
|
||||
// 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<Workflow>);
|
||||
const payload = buildMetadataPayload();
|
||||
await workflowsApi.update(id!, payload as Partial<Workflow>);
|
||||
setAutoSaved(true);
|
||||
setTimeout(() => setAutoSaved(false), 2000);
|
||||
} catch {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user