when you click on edit flows, the whole flow sjould be displayed with an

This commit is contained in:
Leon Serfaty G
2025-07-18 05:34:46 +00:00
parent 80aa0f32ba
commit 8e4af8e745
2 changed files with 135 additions and 32 deletions
+39 -31
View File
@@ -8,11 +8,12 @@ import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Textarea } from '@/components/ui/textarea';
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card';
import { Card, CardContent, CardHeader, CardTitle, CardDescription, CardFooter } from '@/components/ui/card';
import { useToast } from '@/hooks/use-toast';
import Link from 'next/link';
import { ChevronLeft } from 'lucide-react';
import { ChevronLeft, Plus } from 'lucide-react';
import { Skeleton } from '@/components/ui/skeleton';
import { FlowCanvas } from '@/components/admin/flow-canvas';
interface FlowFormPageProps {
params: { id: string };
@@ -93,7 +94,7 @@ export default function FlowFormPage({ params }: FlowFormPageProps) {
}
return (
<form action={formAction} className="space-y-8">
<div className="space-y-8">
<div className="flex items-center gap-4">
<Button variant="outline" size="icon" asChild>
<Link href="/admin/flows">
@@ -106,34 +107,41 @@ export default function FlowFormPage({ params }: FlowFormPageProps) {
</h1>
</div>
<Card>
<CardHeader>
<CardTitle>Flow Details</CardTitle>
<CardDescription>
{isNew ? 'Fill in the details for your new flow.' : 'Update the details for this flow.'}
</CardDescription>
</CardHeader>
<CardContent className="space-y-6">
<input type="hidden" name="id" value={flow?.id} />
<div className="space-y-2">
<Label htmlFor="name">Flow Name</Label>
<Input id="name" name="name" defaultValue={flow?.name} required />
{getError('name') && <p className="text-sm text-destructive">{getError('name')}</p>}
</div>
<div className="space-y-2">
<Label htmlFor="path">Path</Label>
<Input id="path" name="path" defaultValue={flow?.path} placeholder="/my-cool-flow" required />
{getError('path') && <p className="text-sm text-destructive">{getError('path')}</p>}
</div>
<div className="space-y-2">
<Label htmlFor="description">Description</Label>
<Textarea id="description" name="description" defaultValue={flow?.description || ''} placeholder="A brief description of what this flow does." />
{getError('description') && <p className="text-sm text-destructive">{getError('description')}</p>}
</div>
</CardContent>
</Card>
<form action={formAction} className="space-y-8">
<Card>
<CardHeader>
<CardTitle>Flow Details</CardTitle>
<CardDescription>
{isNew ? 'Fill in the details for your new flow.' : 'Update the details for this flow.'}
</CardDescription>
</CardHeader>
<CardContent className="space-y-6">
<input type="hidden" name="id" value={flow?.id} />
<div className="space-y-2">
<Label htmlFor="name">Flow Name</Label>
<Input id="name" name="name" defaultValue={flow?.name} required />
{getError('name') && <p className="text-sm text-destructive">{getError('name')}</p>}
</div>
<div className="space-y-2">
<Label htmlFor="path">Path</Label>
<Input id="path" name="path" defaultValue={flow?.path} placeholder="/my-cool-flow" required />
{getError('path') && <p className="text-sm text-destructive">{getError('path')}</p>}
</div>
<div className="space-y-2">
<Label htmlFor="description">Description</Label>
<Textarea id="description" name="description" defaultValue={flow?.description || ''} placeholder="A brief description of what this flow does." />
{getError('description') && <p className="text-sm text-destructive">{getError('description')}</p>}
</div>
</CardContent>
<CardFooter>
<SubmitButton isNew={isNew} />
</CardFooter>
</Card>
</form>
<SubmitButton isNew={isNew} />
</form>
{!isNew && (
<FlowCanvas />
)}
</div>
);
}
+95
View File
@@ -0,0 +1,95 @@
'use client';
import React from 'react';
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card';
import { MoreVertical, Trash2, Edit, Plus, Move } from 'lucide-react';
import { Button } from '@/components/ui/button';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
// Mock data for the flow steps. In a real app, this would come from a database.
const flowSteps = [
{ id: 1, title: 'Project Type', type: 'Step 1', description: 'What are you looking to build?' },
{ id: 2, title: 'Service Type', type: 'Step 2', description: 'Choose a service.' },
{ id: 3, title: 'Project Stage', type: 'Step 3', description: 'Choose the stage of your project.' },
{ id: 4, title: 'Design Process', type: 'Step 4', description: 'What type of design process?' },
{ id: 5, title: 'Page Count', type: 'Step 5', description: 'How many pages/screens?' },
{ id: 6, title: 'Animations', type: 'Step 6', description: 'Implement animated elements?' },
{ id: 7, title: 'Illustrations', type: 'Step 7', description: 'Create tailored illustrations?' },
{ id: 8, title: 'Branding', type: 'Step 8', description: 'Have you thought about branding?' },
{ id: 9, title: 'Additional Features', type: 'Step 9', description: 'Develop additional features?' },
{ id: 10, title: 'Shopping Cart', type: 'Step 10', description: 'Need a shopping cart?' },
{ id: 11, title: 'UI/UX Design', type: 'Step 12', description: 'What type of design process?' },
{ id: 12, title: 'Results', type: 'Results', description: 'Show the project estimate.' },
];
function FlowStepCard({ step }: { step: typeof flowSteps[0] }) {
return (
<Card className="w-72 shadow-md hover:shadow-lg transition-shadow bg-card">
<CardHeader className="flex flex-row items-center justify-between pb-2">
<div className="space-y-1">
<p className="text-xs font-semibold uppercase text-primary">{step.type}</p>
<CardTitle className="text-lg">{step.title}</CardTitle>
</div>
<div className="flex items-center gap-1">
<Button variant="ghost" size="icon" className="cursor-move h-8 w-8">
<Move className="h-4 w-4" />
</Button>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" size="icon" className="h-8 w-8">
<MoreVertical className="h-4 w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem>
<Edit className="mr-2 h-4 w-4" />
<span>Edit</span>
</DropdownMenuItem>
<DropdownMenuItem className="text-destructive">
<Trash2 className="mr-2 h-4 w-4" />
<span>Delete</span>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
</CardHeader>
<CardContent>
<p className="text-sm text-muted-foreground">{step.description}</p>
</CardContent>
</Card>
);
}
export function FlowCanvas() {
return (
<div className="space-y-4">
<Card>
<CardHeader>
<CardTitle>Flow Canvas</CardTitle>
<CardDescription>
Visually represent and manage the steps of your flow.
</CardDescription>
</CardHeader>
<CardContent>
<div className="relative rounded-lg border border-dashed bg-muted/50 p-8 min-h-[500px]">
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-8">
{flowSteps.map((step) => (
<FlowStepCard key={step.id} step={step} />
))}
<Button variant="outline" className="w-72 h-full min-h-[150px] border-dashed flex flex-col gap-2 items-center justify-center text-muted-foreground hover:text-foreground hover:border-primary">
<Plus className="h-8 w-8" />
<span>Add New Step</span>
</Button>
</div>
</div>
</CardContent>
</Card>
</div>
);
}