From 0a8cee14cce14809dba476f29b9c6f8544e083c0 Mon Sep 17 00:00:00 2001 From: Leon Serfaty G Date: Fri, 18 Jul 2025 05:52:44 +0000 Subject: [PATCH] revert back... tyou are trylly awfull --- src/app/admin/flows/[id]/page.tsx | 297 ++++++++++++++--------------- src/app/globals.css | 5 - src/components/admin/flow-node.tsx | 86 --------- 3 files changed, 146 insertions(+), 242 deletions(-) delete mode 100644 src/components/admin/flow-node.tsx diff --git a/src/app/admin/flows/[id]/page.tsx b/src/app/admin/flows/[id]/page.tsx index 6bd16b7..249e643 100644 --- a/src/app/admin/flows/[id]/page.tsx +++ b/src/app/admin/flows/[id]/page.tsx @@ -1,161 +1,156 @@ 'use client'; -import { Button } from '@/components/ui/button'; -import { Card, CardContent } from '@/components/ui/card'; +import { useEffect, useState } from 'react'; +import { useActionState } from 'react'; +import { useRouter } from 'next/navigation'; +import { getFlow, saveFlow, type Flow } from '@/lib/actions/flows'; +import { Card, CardContent, CardHeader, CardTitle, CardDescription, CardFooter } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; -import { Badge } from '@/components/ui/badge'; -import { - Play, - Share2, - MessageSquare, - Pencil, - Settings, - Bike, - Footprints, - MoreHorizontal, - Plus, - Minus, - Code2 -} from 'lucide-react'; -import { FlowNode, FlowNodeInput, FlowNodeOption, FlowNodeMessage } from '@/components/admin/flow-node'; +import { Label } from '@/components/ui/label'; +import { Textarea } from '@/components/ui/textarea'; +import { Button } from '@/components/ui/button'; +import { useToast } from '@/hooks/use-toast'; +import { Alert, AlertDescription } from '@/components/ui/alert'; + +type FlowFormPageProps = { + params: { id: string }; +}; + +function SubmitButton() { + // useFormStatus is not used here because we are not in a form, but we can simulate the pending state + // from the formAction. For a real app, you might use the pending state from useFormStatus. + // For now, let's just show a static text. + return ; +} + +export default function FlowFormPage({ params }: FlowFormPageProps) { + const [state, formAction] = useActionState(saveFlow, { success: false, message: '', errors: null }); + const [flow, setFlow] = useState(null); + const [isLoading, setIsLoading] = useState(true); + const { toast } = useToast(); + const router = useRouter(); + + const isNew = params.id === 'new'; + const pageTitle = isNew ? 'Add New Flow' : 'Edit Flow'; + const pageDescription = isNew + ? 'Create a new interactive flow for your application.' + : 'Modify the details of an existing flow.'; + + useEffect(() => { + if (!isNew) { + const id = parseInt(params.id, 10); + if (isNaN(id)) { + router.push('/admin/flows'); + return; + } + setIsLoading(true); + getFlow(id) + .then((data) => { + if (data) { + setFlow(data); + } else { + toast({ + variant: 'destructive', + title: 'Error', + description: 'Flow not found.', + }); + router.push('/admin/flows'); + } + }) + .finally(() => setIsLoading(false)); + } else { + setIsLoading(false); + } + }, [params.id, isNew, router, toast]); + + useEffect(() => { + if (state.success) { + toast({ + title: 'Success!', + description: state.message, + }); + // The redirect is handled in the server action, but as a fallback + router.push('/admin/flows'); + } else if (state.message) { + // This handles general errors, not validation ones. + if(!state.errors || state.errors.length === 0) { + toast({ + variant: 'destructive', + title: 'Error', + description: state.message, + }); + } + } + }, [state, router, toast]); + + const getError = (field: string) => { + return state.errors?.find(e => e.path[0] === field)?.message; + } + + if (isLoading) { + return
Loading...
; + } -export default function FlowEditorPage() { return ( -
- {/* Header */} -
-
-

Quick Carb Calculator

- -
-
- - - -
-
- - {/* Main Content */} -
- {/* Flow Canvas */} -
- {/* This is a static representation. A real implementation would use a library like React Flow. */} -
- } /> -
- -
- - - - - } text="Ride" /> - } text="Run" /> - } text="Other" /> -
-

Default

- Set Sport -
-
-
- -
- - - -
- -
- - - - -
- -
- - - - -
- -
- - - Set Assistant - -
- - - {/* Canvas Controls */} -
- - - - - - - - -
-
- - {/* Phone Preview */} -
- - -
- {/* Chat messages */} -
- First, what are you fueling for? -
-
- Ride -
-
- Run -
-
- Other -
- -
- Run -
- -
- Great! How long will you be doing this activity? -
-
- I'll try 3h30 -
-
- Understood! Now, how hard will you be going? -
-
- I'd say a good 8 out of 10 -
-
- Total carbs: 90-120g -
- -
-
-
-
+
+
+

{pageTitle}

+

{pageDescription}

+ +
+ {flow && } + + + + Flow Details + + Provide the name, description, and URL path for this flow. + + + +
+ + + {getError('name') &&

{getError('name')}

} +
+
+ +