UI improvements: Leadspeicher, Maps enrichment, exports
- Rename LeadVault → Leadspeicher throughout (sidebar, topbar, page) - SidePanel: full lead detail view with contact, source, tags (read-only), Google Maps link for address - Tags: kontaktiert stored as tag (toggleable), favorit tag toggle - Remove Status column, StatusBadge dropdown, Priority feature - Remove Aktualisieren button from Leadspeicher - Bulk actions: remove status dropdown - Export: LeadVault Excel-only, clean columns, freeze row + autofilter - Export dropdown: click-based (fix overflow-hidden clipping) - ExportButtons: remove CSV, Excel only everywhere - Maps page: post-search Anymailfinder enrichment button - ProgressCard: "Suche läuft..." instead of "Warte auf Anymailfinder-Server..." - Quick SERP renamed to "Schnell neue Suche" - Results page: Excel export, always-enabled download button - Anymailfinder: fix bulk field names, array-of-arrays format - Apify: fix countryCode lowercase - API: sourceTerm search, contacted/favorite tag filters Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/db";
|
||||
import Papa from "papaparse";
|
||||
import * as XLSX from "xlsx";
|
||||
|
||||
export async function GET(
|
||||
req: NextRequest,
|
||||
@@ -16,23 +16,22 @@ export async function GET(
|
||||
if (!job) return NextResponse.json({ error: "Job not found" }, { status: 404 });
|
||||
|
||||
const rows = job.results.map(r => ({
|
||||
company_name: r.companyName || "",
|
||||
domain: r.domain || "",
|
||||
contact_name: r.contactName || "",
|
||||
contact_title: r.contactTitle || "",
|
||||
email: r.email || "",
|
||||
confidence_score: r.confidence !== null ? Math.round((r.confidence || 0) * 100) + "%" : "",
|
||||
source_tab: job.type,
|
||||
job_id: job.id,
|
||||
found_at: r.createdAt.toISOString(),
|
||||
"Unternehmen": r.companyName || "",
|
||||
"Domain": r.domain || "",
|
||||
"Kontaktname": r.contactName || "",
|
||||
"Position": r.contactTitle || "",
|
||||
"E-Mail": r.email || "",
|
||||
}));
|
||||
|
||||
const csv = Papa.unparse(rows);
|
||||
const ws = XLSX.utils.json_to_sheet(rows);
|
||||
const wb = XLSX.utils.book_new();
|
||||
XLSX.utils.book_append_sheet(wb, ws, "Leads");
|
||||
const arr = XLSX.write(wb, { type: "array", bookType: "xlsx" });
|
||||
|
||||
return new NextResponse(csv, {
|
||||
return new NextResponse(new Uint8Array(arr), {
|
||||
headers: {
|
||||
"Content-Type": "text/csv",
|
||||
"Content-Disposition": `attachment; filename="leadflow-${job.type}-${jobId.slice(0, 8)}.csv"`,
|
||||
"Content-Type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
"Content-Disposition": `attachment; filename="leadflow-${job.type}-${jobId.slice(0, 8)}.xlsx"`,
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
|
||||
@@ -28,17 +28,29 @@ export async function GET(
|
||||
error: job.error,
|
||||
createdAt: job.createdAt,
|
||||
updatedAt: job.updatedAt,
|
||||
results: job.results.map(r => ({
|
||||
id: r.id,
|
||||
companyName: r.companyName,
|
||||
domain: r.domain,
|
||||
contactName: r.contactName,
|
||||
contactTitle: r.contactTitle,
|
||||
email: r.email,
|
||||
confidence: r.confidence,
|
||||
linkedinUrl: r.linkedinUrl,
|
||||
createdAt: r.createdAt,
|
||||
})),
|
||||
results: job.results.map(r => {
|
||||
let address: string | null = null;
|
||||
let phone: string | null = null;
|
||||
if (r.source) {
|
||||
try {
|
||||
const src = JSON.parse(r.source) as { address?: string; phone?: string };
|
||||
address = src.address ?? null;
|
||||
phone = src.phone ?? null;
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
return {
|
||||
id: r.id,
|
||||
companyName: r.companyName,
|
||||
domain: r.domain,
|
||||
contactName: r.contactName,
|
||||
contactTitle: r.contactTitle,
|
||||
email: r.email,
|
||||
linkedinUrl: r.linkedinUrl,
|
||||
address,
|
||||
phone,
|
||||
createdAt: r.createdAt,
|
||||
};
|
||||
}),
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("GET /api/jobs/[id]/status error:", err);
|
||||
|
||||
@@ -83,7 +83,6 @@ async function runEnrichment(
|
||||
contactName: result.person_full_name || null,
|
||||
contactTitle: result.person_job_title || null,
|
||||
email: result.email || null,
|
||||
confidence: result.valid_email ? 1.0 : result.email_status === "risky" ? 0.5 : 0,
|
||||
linkedinUrl: result.person_linkedin_url || null,
|
||||
source: JSON.stringify({ email_status: result.email_status, category: result.decision_maker_category }),
|
||||
},
|
||||
@@ -104,7 +103,6 @@ async function runEnrichment(
|
||||
contactTitle: r.person_job_title || null,
|
||||
email: r.email || null,
|
||||
linkedinUrl: r.person_linkedin_url || null,
|
||||
emailConfidence: r.valid_email ? 1.0 : r.email_status === "risky" ? 0.5 : 0,
|
||||
})),
|
||||
"airscale",
|
||||
undefined,
|
||||
|
||||
@@ -110,7 +110,6 @@ async function runLinkedInEnrich(
|
||||
where: { id: result.id },
|
||||
data: {
|
||||
email: email || null,
|
||||
confidence: isValid ? 1.0 : emailStatus === "risky" ? 0.5 : 0,
|
||||
contactName: row["person_full_name"] || row["Full Name"] || result.contactName || null,
|
||||
contactTitle: row["person_job_title"] || row["Job Title"] || result.contactTitle || null,
|
||||
},
|
||||
@@ -135,7 +134,6 @@ async function runLinkedInEnrich(
|
||||
where: { id: r.id },
|
||||
data: {
|
||||
email: found.email || null,
|
||||
confidence: isValid ? 1.0 : found.email_status === "risky" ? 0.5 : 0,
|
||||
contactName: found.person_full_name || r.contactName || null,
|
||||
contactTitle: found.person_job_title || r.contactTitle || null,
|
||||
},
|
||||
@@ -162,7 +160,6 @@ async function runLinkedInEnrich(
|
||||
contactTitle: r.contactTitle,
|
||||
email: r.email,
|
||||
linkedinUrl: r.linkedinUrl,
|
||||
emailConfidence: r.confidence,
|
||||
})),
|
||||
"linkedin",
|
||||
undefined,
|
||||
|
||||
@@ -99,6 +99,8 @@ async function runMapsEnrich(
|
||||
companyName: p.name || null,
|
||||
phone: p.phone,
|
||||
address: p.address,
|
||||
description: p.description,
|
||||
industry: p.category,
|
||||
})),
|
||||
"maps",
|
||||
params.queries.join(", "),
|
||||
@@ -132,7 +134,7 @@ async function runMapsEnrich(
|
||||
);
|
||||
|
||||
for (const result of enrichResults) {
|
||||
const hasEmail = !!result.valid_email;
|
||||
const hasEmail = !!result.email;
|
||||
if (hasEmail) emailsFound++;
|
||||
|
||||
const resultId = domainToResultId.get(result.domain || "");
|
||||
@@ -144,7 +146,6 @@ async function runMapsEnrich(
|
||||
contactName: result.person_full_name || null,
|
||||
contactTitle: result.person_job_title || null,
|
||||
email: result.email || null,
|
||||
confidence: result.valid_email ? 1.0 : result.email_status === "risky" ? 0.5 : 0,
|
||||
linkedinUrl: result.person_linkedin_url || null,
|
||||
},
|
||||
});
|
||||
@@ -167,7 +168,6 @@ async function runMapsEnrich(
|
||||
contactTitle: r.person_job_title || null,
|
||||
email: r.email || null,
|
||||
linkedinUrl: r.person_linkedin_url || null,
|
||||
emailConfidence: r.valid_email ? 1.0 : r.email_status === "risky" ? 0.5 : 0,
|
||||
})),
|
||||
"maps",
|
||||
params.queries.join(", "),
|
||||
|
||||
@@ -122,7 +122,6 @@ async function runSerpEnrich(
|
||||
contactName: result.person_full_name || null,
|
||||
contactTitle: result.person_job_title || null,
|
||||
email: result.email || null,
|
||||
confidence: result.valid_email ? 1.0 : result.email_status === "risky" ? 0.5 : 0,
|
||||
linkedinUrl: result.person_linkedin_url || null,
|
||||
source: JSON.stringify({
|
||||
url: serpData?.url,
|
||||
@@ -150,7 +149,6 @@ async function runSerpEnrich(
|
||||
contactTitle: r.person_job_title || null,
|
||||
email: r.email || null,
|
||||
linkedinUrl: r.person_linkedin_url || null,
|
||||
emailConfidence: r.valid_email ? 1.0 : r.email_status === "risky" ? 0.5 : 0,
|
||||
serpTitle: serpData?.title || null,
|
||||
serpSnippet: serpData?.description || null,
|
||||
serpRank: serpData?.position ?? null,
|
||||
|
||||
@@ -36,30 +36,18 @@ export async function GET(req: NextRequest) {
|
||||
});
|
||||
|
||||
const rows = leads.map(l => ({
|
||||
"Status": l.status,
|
||||
"Priorität": l.priority,
|
||||
"Unternehmen": l.companyName || "",
|
||||
"Domain": l.domain || "",
|
||||
"Kontaktname": l.contactName || "",
|
||||
"Jobtitel": l.contactTitle || "",
|
||||
"E-Mail": l.email || "",
|
||||
"E-Mail Konfidenz": l.emailConfidence != null ? Math.round(l.emailConfidence * 100) + "%" : "",
|
||||
"LinkedIn": l.linkedinUrl || "",
|
||||
"Telefon": l.phone || "",
|
||||
"Quelle": l.sourceTab,
|
||||
"Suchbegriff": l.sourceTerm || "",
|
||||
"Tags": l.tags ? JSON.parse(l.tags).join(", ") : "",
|
||||
"Land": l.country || "",
|
||||
"Mitarbeiter": l.headcount || "",
|
||||
"Branche": l.industry || "",
|
||||
"Notizen": l.notes || "",
|
||||
"Erfasst am": new Date(l.capturedAt).toLocaleString("de-DE"),
|
||||
"Kontaktiert am": l.contactedAt ? new Date(l.contactedAt).toLocaleString("de-DE") : "",
|
||||
"SERP Rang": l.serpRank?.toString() || "",
|
||||
"SERP URL": l.serpUrl || "",
|
||||
"SERP Titel": l.serpTitle || "",
|
||||
"SERP Snippet": l.serpSnippet || "",
|
||||
"Lead ID": l.id,
|
||||
"Unternehmen": l.companyName || "",
|
||||
"Domain": l.domain || "",
|
||||
"Kontaktname": l.contactName || "",
|
||||
"Position": l.contactTitle || "",
|
||||
"E-Mail": l.email || "",
|
||||
"Telefon": l.phone || "",
|
||||
"Adresse": l.address || "",
|
||||
"LinkedIn": l.linkedinUrl || "",
|
||||
"Branche": l.industry || "",
|
||||
"Suchbegriff": l.sourceTerm || "",
|
||||
"Tags": l.tags ? (JSON.parse(l.tags) as string[]).join(", ") : "",
|
||||
"Erfasst am": new Date(l.capturedAt).toLocaleDateString("de-DE", { day: "2-digit", month: "2-digit", year: "numeric" }),
|
||||
}));
|
||||
|
||||
const filename = `leadflow-vault-${new Date().toISOString().split("T")[0]}`;
|
||||
@@ -67,22 +55,36 @@ export async function GET(req: NextRequest) {
|
||||
if (format === "xlsx") {
|
||||
const ws = XLSX.utils.json_to_sheet(rows);
|
||||
|
||||
// Column widths
|
||||
// Column widths (one per column)
|
||||
ws["!cols"] = [
|
||||
{ wch: 14 }, { wch: 10 }, { wch: 28 }, { wch: 28 }, { wch: 22 },
|
||||
{ wch: 22 }, { wch: 32 }, { wch: 14 }, { wch: 30 }, { wch: 16 },
|
||||
{ wch: 12 }, { wch: 24 }, { wch: 20 }, { wch: 8 }, { wch: 10 },
|
||||
{ wch: 16 }, { wch: 30 }, { wch: 18 }, { wch: 18 }, { wch: 8 },
|
||||
{ wch: 40 }, { wch: 30 }, { wch: 40 }, { wch: 28 },
|
||||
{ wch: 30 }, // Unternehmen
|
||||
{ wch: 28 }, // Domain
|
||||
{ wch: 24 }, // Kontaktname
|
||||
{ wch: 24 }, // Position
|
||||
{ wch: 34 }, // E-Mail
|
||||
{ wch: 18 }, // Telefon
|
||||
{ wch: 36 }, // Adresse
|
||||
{ wch: 36 }, // LinkedIn
|
||||
{ wch: 22 }, // Branche
|
||||
{ wch: 30 }, // Suchbegriff
|
||||
{ wch: 28 }, // Tags
|
||||
{ wch: 14 }, // Erfasst am
|
||||
];
|
||||
|
||||
// Freeze header row
|
||||
ws["!freeze"] = { xSplit: 0, ySplit: 1 };
|
||||
|
||||
// Autofilter across all columns
|
||||
const colCount = Object.keys(rows[0] ?? {}).length || 17;
|
||||
const lastCol = String.fromCharCode(64 + colCount);
|
||||
ws["!autofilter"] = { ref: `A1:${lastCol}1` };
|
||||
|
||||
const wb = XLSX.utils.book_new();
|
||||
XLSX.utils.book_append_sheet(wb, ws, "LeadVault");
|
||||
|
||||
const arr = XLSX.write(wb, { type: "array", bookType: "xlsx" }) as number[];
|
||||
const buf = new Uint8Array(arr).buffer;
|
||||
|
||||
return new NextResponse(buf, {
|
||||
return new NextResponse(new Uint8Array(arr).buffer, {
|
||||
headers: {
|
||||
"Content-Type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
"Content-Disposition": `attachment; filename="${filename}.xlsx"`,
|
||||
@@ -90,26 +92,19 @@ export async function GET(req: NextRequest) {
|
||||
});
|
||||
}
|
||||
|
||||
// CSV — UTF-8 BOM so Excel opens it correctly + \r\n line endings
|
||||
const headers = Object.keys(rows[0] ?? {
|
||||
"Status": "", "Priorität": "", "Unternehmen": "", "Domain": "", "Kontaktname": "",
|
||||
"Jobtitel": "", "E-Mail": "", "E-Mail Konfidenz": "", "LinkedIn": "", "Telefon": "",
|
||||
"Quelle": "", "Suchbegriff": "", "Tags": "", "Land": "", "Mitarbeiter": "",
|
||||
"Branche": "", "Notizen": "", "Erfasst am": "", "Kontaktiert am": "",
|
||||
"SERP Rang": "", "SERP URL": "", "SERP Titel": "", "SERP Snippet": "", "Lead ID": "",
|
||||
});
|
||||
|
||||
// CSV — UTF-8 BOM so Excel opens it correctly
|
||||
const colKeys = Object.keys(rows[0] ?? {});
|
||||
const escape = (v: string) =>
|
||||
v.includes(",") || v.includes('"') || v.includes("\n") || v.includes("\r")
|
||||
? `"${v.replace(/"/g, '""')}"`
|
||||
: v;
|
||||
|
||||
const csv =
|
||||
"\uFEFF" + // UTF-8 BOM — tells Excel to use UTF-8
|
||||
"\uFEFF" +
|
||||
[
|
||||
headers.map(escape).join(","),
|
||||
...rows.map(r => headers.map(h => escape(String(r[h as keyof typeof r] ?? ""))).join(",")),
|
||||
].join("\r\n"); // Windows line endings for Excel
|
||||
colKeys.map(escape).join(","),
|
||||
...rows.map(r => colKeys.map(h => escape(String(r[h as keyof typeof r] ?? ""))).join(",")),
|
||||
].join("\r\n");
|
||||
|
||||
return new NextResponse(csv, {
|
||||
headers: {
|
||||
|
||||
@@ -20,6 +20,8 @@ export async function GET(req: NextRequest) {
|
||||
const priorities = searchParams.getAll("priority");
|
||||
const tags = searchParams.getAll("tags");
|
||||
const searchTerms = searchParams.getAll("searchTerm");
|
||||
const contacted = searchParams.get("contacted");
|
||||
const favorite = searchParams.get("favorite");
|
||||
|
||||
const where: Prisma.LeadWhereInput = {};
|
||||
|
||||
@@ -30,6 +32,7 @@ export async function GET(req: NextRequest) {
|
||||
{ contactName: { contains: search } },
|
||||
{ email: { contains: search } },
|
||||
{ notes: { contains: search } },
|
||||
{ sourceTerm: { contains: search } },
|
||||
];
|
||||
}
|
||||
|
||||
@@ -50,6 +53,14 @@ export async function GET(req: NextRequest) {
|
||||
where.sourceTerm = { in: searchTerms };
|
||||
}
|
||||
|
||||
if (contacted === "yes") {
|
||||
where.tags = { contains: "kontaktiert" };
|
||||
}
|
||||
|
||||
if (favorite === "yes") {
|
||||
where.tags = { contains: "favorit" };
|
||||
}
|
||||
|
||||
if (tags.length > 0) {
|
||||
// SQLite JSON contains — search for each tag in the JSON string
|
||||
where.AND = tags.map(tag => ({
|
||||
|
||||
Reference in New Issue
Block a user