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