feat: LeadVault - zentrale Lead-Datenbank mit CRM-Funktionen

- Prisma-Schema: Lead + LeadEvent Modelle (Migration 20260320)
- lib/services/leadVault.ts: sinkLeadsToVault mit Deduplizierung
- Auto-Sync: alle 4 Pipelines schreiben Leads in LeadVault
- GET /api/leads: Filter, Sortierung, Pagination (Server-side)
- PATCH/DELETE /api/leads/[id]: Status, Priorität, Tags, Notizen
- POST /api/leads/bulk: Bulk-Aktionen für mehrere Leads
- GET /api/leads/stats: Statistiken + 7-Tage-Sparkline
- POST /api/leads/quick-serp: SERP-Capture ohne Enrichment
- GET /api/leads/export: CSV-Export mit allen Feldern
- app/leadvault/page.tsx: vollständige UI mit Stats, Quick SERP,
  Filter-Leiste, sortierbare Tabelle, Bulk-Aktionen, Side Panel
- Sidebar: LeadVault-Eintrag mit Live-Badge (neue Leads)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Timo Uttenweiler
2026-03-20 17:33:12 +01:00
parent 6711633a5d
commit 042fbeb672
16 changed files with 1800 additions and 5 deletions

View File

@@ -3,7 +3,7 @@
import Link from "next/link";
import { usePathname } from "next/navigation";
import { cn } from "@/lib/utils";
import { Building2, Linkedin, Search, BarChart3, Settings, Zap, ChevronLeft, ChevronRight, MapPin } from "lucide-react";
import { Building2, Linkedin, Search, BarChart3, Settings, Zap, ChevronLeft, ChevronRight, MapPin, Database } from "lucide-react";
import { useAppStore } from "@/lib/store";
import { useEffect, useState } from "react";
@@ -12,8 +12,9 @@ const navItems = [
{ href: "/linkedin", icon: Linkedin, label: "LinkedIn → Email", color: "text-blue-500" },
{ href: "/serp", icon: Search, label: "SERP → Email", color: "text-purple-400" },
{ href: "/maps", icon: MapPin, label: "Maps → Email", color: "text-green-400" },
{ href: "/results", icon: BarChart3, label: "Results & History", color: "text-yellow-400" },
{ href: "/settings", icon: Settings, label: "Settings", color: "text-gray-400" },
{ href: "/leadvault", icon: Database, label: "LeadVault", color: "text-violet-400", badge: true },
{ href: "/results", icon: BarChart3, label: "Ergebnisse & Verlauf", color: "text-yellow-400" },
{ href: "/settings", icon: Settings, label: "Einstellungen", color: "text-gray-400" },
];
interface CredentialStatus {
@@ -27,6 +28,7 @@ export function Sidebar() {
const pathname = usePathname();
const { sidebarCollapsed, setSidebarCollapsed } = useAppStore();
const [creds, setCreds] = useState<CredentialStatus>({ anymailfinder: false, apify: false, vayne: false, googlemaps: false });
const [newLeadsCount, setNewLeadsCount] = useState(0);
useEffect(() => {
fetch("/api/credentials")
@@ -35,6 +37,18 @@ export function Sidebar() {
.catch(() => {});
}, []);
useEffect(() => {
function fetchNewLeads() {
fetch("/api/leads/stats")
.then(r => r.json())
.then((d: { new?: number }) => setNewLeadsCount(d.new ?? 0))
.catch(() => {});
}
fetchNewLeads();
const t = setInterval(fetchNewLeads, 30000);
return () => clearInterval(t);
}, []);
return (
<aside
className={cn(
@@ -54,8 +68,9 @@ export function Sidebar() {
{/* Nav */}
<nav className="flex-1 px-2 py-4 space-y-1">
{navItems.map(({ href, icon: Icon, label, color }) => {
{navItems.map(({ href, icon: Icon, label, color, badge }) => {
const active = pathname === href || pathname.startsWith(href + "/");
const showBadge = badge && newLeadsCount > 0;
return (
<Link
key={href}
@@ -68,7 +83,19 @@ export function Sidebar() {
)}
>
<Icon className={cn("w-5 h-5 flex-shrink-0", active ? color : "")} />
{!sidebarCollapsed && <span>{label}</span>}
{!sidebarCollapsed && (
<>
<span className="flex-1">{label}</span>
{showBadge && (
<span className="ml-auto bg-blue-500 text-white text-[10px] font-bold rounded-full min-w-[18px] h-[18px] flex items-center justify-center px-1">
{newLeadsCount > 99 ? "99+" : newLeadsCount}
</span>
)}
</>
)}
{sidebarCollapsed && showBadge && (
<span className="absolute right-1 top-1 w-2 h-2 bg-blue-500 rounded-full" />
)}
</Link>
);
})}

View File

@@ -9,6 +9,7 @@ const BREADCRUMBS: Record<string, string> = {
"/linkedin": "LinkedIn → E-Mail",
"/serp": "SERP → E-Mail",
"/maps": "Google Maps → E-Mail",
"/leadvault": "🗄️ LeadVault",
"/results": "Ergebnisse & Verlauf",
"/settings": "Einstellungen",
};