diff --git a/src/components/admin/leads/SendQuoteModal.tsx b/src/components/admin/leads/SendQuoteModal.tsx new file mode 100644 index 0000000..101de2a --- /dev/null +++ b/src/components/admin/leads/SendQuoteModal.tsx @@ -0,0 +1,129 @@ +"use client"; + +import { useState } from "react"; +import { useForm } from "react-hook-form"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { z } from "zod"; +import { assignQuoteToLead } from "@/app/admin/leads/actions"; +import { + Dialog, + DialogContent, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog"; +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form"; +import { Input } from "@/components/ui/input"; +import { Button } from "@/components/ui/button"; +import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; +import { Loader2 } from "lucide-react"; + +const assignQuoteSchema = z.object({ + lead_id: z.string().min(1), + quote_token: z.string().min(1).optional(), + generate_new: z.boolean(), +}).transform(data => ({ + ...data, + generate_new: data.generate_new ?? false, +})); + +export function SendQuoteModal({ leadId }: { leadId: string }) { + const [open, setOpen] = useState(false); + const [loading, setLoading] = useState(false); + const [tab, setTab] = useState<"existing" | "new">("existing"); + const form = useForm>({ + resolver: zodResolver(assignQuoteSchema), + defaultValues: { + lead_id: leadId, + generate_new: false, + }, + }); + + async function onSubmit(data: z.infer) { + setLoading(true); + try { + const result = await assignQuoteToLead({ + ...data, + generate_new: tab === "new", + }); + if (result.success) { + setOpen(false); + form.reset(); + } + } finally { + setLoading(false); + } + } + + return ( + + + + + + + Invia Preventivo al Lead + + setTab(v as "existing" | "new")}> + + Preventivo Esistente + Crea Nuovo + + + +
+ + ( + + Token Preventivo + + + + + + )} + /> +

+ Copia il token dal preventivo e incollalo qui. Il lead sarĂ  aggiornato a "Proposal Sent". +

+ + + +
+ + +

+ Crea un nuovo preventivo per questo lead. Ti reindirizzeremo al builder. +

+ +
+
+
+
+ ); +}