From 80aa0f32bacb19e130a953515b08abf0e6d99929 Mon Sep 17 00:00:00 2001 From: Leon Serfaty G Date: Fri, 18 Jul 2025 04:52:21 +0000 Subject: [PATCH] the flow we just created is not showing up --- src/app/admin/flows/[id]/page.tsx | 23 ++++++++++++++--------- src/lib/actions/flows.ts | 19 ++++++++++++++++--- src/lib/db.ts | 30 ++++++++++++++++++++++++++++-- 3 files changed, 58 insertions(+), 14 deletions(-) diff --git a/src/app/admin/flows/[id]/page.tsx b/src/app/admin/flows/[id]/page.tsx index 568fe87..2cacfb9 100644 --- a/src/app/admin/flows/[id]/page.tsx +++ b/src/app/admin/flows/[id]/page.tsx @@ -2,7 +2,7 @@ 'use client'; import { useEffect, useState } from 'react'; -import { useFormState } from 'react-dom'; +import { useFormState, useFormStatus } from 'react-dom'; import { getFlow, saveFlow, type Flow } from '@/lib/actions/flows'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; @@ -19,9 +19,10 @@ interface FlowFormPageProps { } function SubmitButton({ isNew }: { isNew: boolean }) { + const { pending } = useFormStatus(); return ( - ); } @@ -49,11 +50,11 @@ export default function FlowFormPage({ params }: FlowFormPageProps) { }, [params.id, isNew]); useEffect(() => { - if (state.message) { + if (state.message && !state.success) { toast({ - title: state.success ? 'Success!' : 'Error', + title: 'Error', description: state.message, - variant: state.success ? 'default' : 'destructive', + variant: 'destructive', }); } }, [state, toast]); @@ -87,6 +88,10 @@ export default function FlowFormPage({ params }: FlowFormPageProps) { ) } + const getError = (field: string) => { + return state.errors?.find(e => e.path?.[0] === field)?.message; + } + return (
@@ -113,17 +118,17 @@ export default function FlowFormPage({ params }: FlowFormPageProps) {
- {state.errors?.name &&

{state.errors.name[0]}

} + {getError('name') &&

{getError('name')}

}
- {state.errors?.path &&

{state.errors.path[0]}

} + {getError('path') &&

{getError('path')}

}