From 24dc4855d7352df9be189a9cc707abe390675969 Mon Sep 17 00:00:00 2001 From: caitlin Date: Thu, 18 Jun 2026 13:45:46 +0200 Subject: [PATCH] Fixed button in view --- src/app/(dashboard)/leads/new/page.tsx | 271 ++++++++++++++++++++++ src/app/(dashboard)/leads/page.tsx | 8 +- src/components/leads/lead-form-dialog.tsx | 14 +- 3 files changed, 283 insertions(+), 10 deletions(-) create mode 100644 src/app/(dashboard)/leads/new/page.tsx diff --git a/src/app/(dashboard)/leads/new/page.tsx b/src/app/(dashboard)/leads/new/page.tsx new file mode 100644 index 0000000..4db1ae7 --- /dev/null +++ b/src/app/(dashboard)/leads/new/page.tsx @@ -0,0 +1,271 @@ +"use client" + +import { useState } from "react" +import { useRouter } from "next/navigation" +import Link from "next/link" +import { useForm } from "react-hook-form" +import { zodResolver } from "@hookform/resolvers/zod" +import * as z from "zod" +import { Button } from "@/components/ui/button" +import { Input } from "@/components/ui/input" +import { Textarea } from "@/components/ui/textarea" +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form" +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select" +import { Card, CardContent } from "@/components/ui/card" +import { ArrowLeft } from "lucide-react" +import { Lead, LeadStatus } from "@/types" +import { leads } from "@/data/leads" +import { users } from "@/data/users" +import { LEAD_SOURCES, LEAD_STATUSES } from "@/lib/constants" + +const leadFormSchema = z.object({ + companyName: z.string().min(1, "Company name is required"), + contactName: z.string().min(1, "Contact name is required"), + email: z.string().email("Invalid email address"), + phone: z.string().optional(), + source: z.string().optional(), + description: z.string().optional(), + status: z.string(), + assignedUserId: z.string().optional(), +}) + +type LeadFormValues = z.infer + +export default function CreateLeadPage() { + const router = useRouter() + const [saving, setSaving] = useState(false) + + const form = useForm({ + resolver: zodResolver(leadFormSchema), + defaultValues: { + companyName: "", + contactName: "", + email: "", + phone: "", + source: "", + description: "", + status: "open", + assignedUserId: "none", + }, + }) + + function onSubmit(values: LeadFormValues) { + setSaving(true) + const now = new Date().toISOString() + const assignedUserId: string | null = values.assignedUserId === "none" ? null : (values.assignedUserId ?? null) + const assignedUser = assignedUserId ? users.find((u) => u.id === assignedUserId) ?? null : null + + const newLead: Lead = { + id: `lead-${String(leads.length + 1).padStart(3, "0")}`, + companyName: values.companyName, + contactName: values.contactName, + email: values.email, + phone: values.phone ?? "", + source: values.source ?? "", + description: values.description ?? "", + status: values.status as LeadStatus, + assignedUserId, + assignedUser, + createdAt: now, + updatedAt: now, + } + + leads.unshift(newLead) + router.push("/leads") + } + + return ( +
+ + + Back to leads + + +
+

Create New Lead

+

Fill in the details to add a new lead.

+
+ + + +
+ +
+ ( + + Company Name + + + + + + )} + /> + ( + + Contact Name + + + + + + )} + /> + ( + + Email + + + + + + )} + /> + ( + + Phone + + + + + + )} + /> + ( + + Source + + + + )} + /> + ( + + Status + + + + )} + /> +
+ ( + + Description + +