feat(leads): Leads universell mit Projekten verknüpfen
ci / quality (push) Failing after 44s
ci / build (push) Has been skipped
deploy / deploy (push) Successful in 54s

Ein Projekt lebt in genau einem Heimat-Bereich und wird einmal angelegt;
Leads bekommen eine optionale Verknüpfung dorthin (lead.projectId), egal in
welchem Bereich das Projekt wohnt — kein redundantes Anlegen mehr.

- Migration 0011: lead.project_id (FK → project, ON DELETE SET NULL).
- Lead anlegen / CSV-Import / Lead-Detail: Projekt zuordnen; CSV ordnet alle
  importierten Leads einem Projekt zu.
- Projektseite: neue "Leads"-Sektion (Vertriebs-Sicht des Projekts).
- Vertrieb: "Projekte mit Vertriebsaktivität" — bereichsübergreifend alle
  Projekte mit verknüpften Leads (so erscheint ein Entwicklungsprojekt hier,
  WEIL es Leads hat). Rein interne Projekte ohne Leads tauchen nicht auf.
- Lead-Liste/Detail zeigen das verknüpfte Projekt.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
dejanandClaude Opus 4.8 committed 2026-06-06 16:08:59 +02:00
1 parent 68480c1eb1
commit 19db774c4c
10 files changed
+3522 -3

No files matched your search

+39
View File
@@ -327,11 +327,50 @@ function VertriebDetail() {
return (
<div className="space-y-6">
<LeadsTeaser />
<ProjekteMitLeads />
<ProjektListeFuerBereich slug="vertrieb" />
</div>
);
}
// Bereichsübergreifend: Projekte (egal aus welchem Bereich), die verknüpfte
// Leads haben — so taucht z. B. ein Entwicklungsprojekt hier auf, WEIL es
// Vertriebsaktivität hat, ohne redundant angelegt werden zu müssen.
function ProjekteMitLeads() {
const q = trpc.lead.list.useQuery();
const leads = q.data ?? [];
const map = new Map<string, { id: string; name: string; total: number; open: number }>();
for (const l of leads) {
if (!l.projectId || !l.projectName) continue;
const e = map.get(l.projectId) ?? { id: l.projectId, name: l.projectName, total: 0, open: 0 };
e.total++;
if (l.status !== 'won' && l.status !== 'lost') e.open++;
map.set(l.projectId, e);
}
const projects = Array.from(map.values()).sort((a, b) => b.open - a.open);
if (projects.length === 0) return null;
return (
<section>
<h2 className="mb-2 text-lg font-semibold">Projekte mit Vertriebsaktivität</h2>
<div className="grid grid-cols-1 gap-3 md:grid-cols-2 lg:grid-cols-3">
{projects.map((p) => (
<Link key={p.id} to={`/projekt/${p.id}`} className="contents">
<Card.Root className="cursor-pointer hover:shadow-[var(--shadow-md)]">
<Card.Body className="flex items-center justify-between gap-2">
<p className="font-medium">{p.name}</p>
<span className="shrink-0 text-xs text-[var(--color-ink-muted)]">
{p.total} {p.total === 1 ? 'Lead' : 'Leads'}
{p.open > 0 && ` · ${p.open} offen`}
</span>
</Card.Body>
</Card.Root>
</Link>
))}
</div>
</section>
);
}
function LeadsTeaser() {
const q = trpc.lead.list.useQuery();
const leads = q.data ?? [];