feat(14-02): add LeadsSearch, rewire leads pages, surface tags in LeadDetail (CRM-08/09)
- New LeadsSearch.tsx: client-side instant filter across name/email/ company/status/tags (mirrors CatalogSearch.tsx) - page.tsx: fetch via getLeadsWithTags()/getLeadFieldOptions(), render LeadsSearch + CreateLeadModal, revalidate=0 - [id]/page.tsx: fetch getLeadsWithTags()/getLeadFieldOptions(), find lead by id, pass tags/tagOptions to LeadDetail - LeadDetail.tsx: add OptionMultiSelect for lead tags in the "Profilo" card, wired to addLeadTag/removeLeadTag/renameLeadTag with error display
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useMemo } from "react";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Search } from "lucide-react";
|
||||
import { LeadTable } from "@/components/admin/leads/LeadTable";
|
||||
import type { LeadWithTags, LeadFieldOptions } from "@/lib/admin-queries";
|
||||
|
||||
export function LeadsSearch({
|
||||
leads,
|
||||
options,
|
||||
}: {
|
||||
leads: LeadWithTags[];
|
||||
options: LeadFieldOptions;
|
||||
}) {
|
||||
const [query, setQuery] = useState("");
|
||||
|
||||
const filtered = useMemo(() => {
|
||||
const q = query.trim().toLowerCase();
|
||||
if (!q) return leads;
|
||||
return leads.filter((l) => {
|
||||
if (l.name.toLowerCase().includes(q)) return true;
|
||||
if (l.email?.toLowerCase().includes(q)) return true;
|
||||
if (l.company?.toLowerCase().includes(q)) return true;
|
||||
if (l.status.toLowerCase().includes(q)) return true;
|
||||
if (l.tags.some((t) => t.toLowerCase().includes(q))) return true;
|
||||
return false;
|
||||
});
|
||||
}, [leads, query]);
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="relative max-w-sm">
|
||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-[#71717a]" />
|
||||
<Input
|
||||
type="text"
|
||||
placeholder="Cerca lead..."
|
||||
value={query}
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
className="pl-9 h-9"
|
||||
/>
|
||||
</div>
|
||||
<LeadTable leads={filtered} options={options} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,10 +1,17 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import { getLeadById, getActivityLog, getUpcomingReminders } from "@/lib/lead-service";
|
||||
import { getActivityLog, getUpcomingReminders } from "@/lib/lead-service";
|
||||
import { getLeadsWithTags, getLeadFieldOptions } from "@/lib/admin-queries";
|
||||
import { LeadDetail } from "@/components/admin/leads/LeadDetail";
|
||||
|
||||
export default async function LeadDetailPage({ params }: { params: Promise<{ id: string }> }) {
|
||||
const { id } = await params;
|
||||
const lead = await getLeadById(id);
|
||||
|
||||
const [leads, options] = await Promise.all([
|
||||
getLeadsWithTags(),
|
||||
getLeadFieldOptions(),
|
||||
]);
|
||||
|
||||
const lead = leads.find((l) => l.id === id);
|
||||
|
||||
if (!lead) {
|
||||
notFound();
|
||||
@@ -13,5 +20,13 @@ export default async function LeadDetailPage({ params }: { params: Promise<{ id:
|
||||
const activities = await getActivityLog(id);
|
||||
const reminders = await getUpcomingReminders(id);
|
||||
|
||||
return <LeadDetail lead={lead} activities={activities} reminders={reminders} />;
|
||||
return (
|
||||
<LeadDetail
|
||||
lead={lead}
|
||||
activities={activities}
|
||||
reminders={reminders}
|
||||
tags={lead.tags}
|
||||
tagOptions={options.tags}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,25 +1,23 @@
|
||||
import { Suspense } from "react";
|
||||
import { getAllLeads } from "@/lib/lead-service";
|
||||
import { LeadTable } from "@/components/admin/leads/LeadTable";
|
||||
import { getLeadsWithTags, getLeadFieldOptions } from "@/lib/admin-queries";
|
||||
import { LeadsSearch } from "./LeadsSearch";
|
||||
import { CreateLeadModal } from "@/components/admin/leads/LeadForm";
|
||||
|
||||
async function LeadsList() {
|
||||
const leads = await getAllLeads();
|
||||
export const revalidate = 0;
|
||||
|
||||
export default async function LeadsPage() {
|
||||
const [leads, options] = await Promise.all([
|
||||
getLeadsWithTags(),
|
||||
getLeadFieldOptions(),
|
||||
]);
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex justify-between items-center">
|
||||
<h1 className="text-3xl font-bold">Lead Pipeline</h1>
|
||||
<h1 className="text-2xl font-bold text-[#1a1a1a]">Lead Pipeline</h1>
|
||||
<CreateLeadModal />
|
||||
</div>
|
||||
|
||||
<Suspense fallback={<div className="animate-pulse">Loading...</div>}>
|
||||
<LeadTable leads={leads} />
|
||||
</Suspense>
|
||||
<LeadsSearch leads={leads} options={options} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function LeadsPage() {
|
||||
return <LeadsList />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user