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

+40 -1
View File
@@ -81,6 +81,9 @@ export function LeadsRoute() {
}
function LeadImportDialog({ onClose }: { onClose: () => void }) {
const projectsQ = trpc.project.list.useQuery();
const projects = (projectsQ.data ?? []).map((r) => ({ id: r.project.id, name: r.project.name }));
const [projectId, setProjectId] = useState('');
const [fileName, setFileName] = useState('');
const [csv, setCsv] = useState('');
const [result, setResult] = useState<{
@@ -124,6 +127,22 @@ function LeadImportDialog({ onClose }: { onClose: () => void }) {
</p>
<div className="mt-4 space-y-3">
<label className="block">
<span className="text-sm font-medium">Projekt zuordnen (optional)</span>
<select
value={projectId}
onChange={(e) => setProjectId(e.target.value)}
disabled={!!result}
className="mt-1 w-full rounded-[var(--radius-md)] border border-[var(--color-border)] bg-white px-3 py-2 text-sm"
>
<option value="">— kein Projekt —</option>
{projects.map((p) => (
<option key={p.id} value={p.id}>
{p.name}
</option>
))}
</select>
</label>
<label className="block">
<span className="text-sm font-medium">CSV-Datei</span>
<input
@@ -160,7 +179,7 @@ function LeadImportDialog({ onClose }: { onClose: () => void }) {
{!result && (
<Button
type="button"
onClick={() => importMut.mutate({ csv })}
onClick={() => importMut.mutate({ csv, projectId: projectId || undefined })}
disabled={!csv || importMut.isPending}
>
{importMut.isPending ? 'Importiere…' : 'Importieren'}
@@ -182,6 +201,7 @@ function LeadCard({
status: LeadStatus;
score: number;
ownerName: string | null;
projectName: string | null;
branche: string | null;
subSegment: string | null;
naechsterSchrittDatum: string | null;
@@ -200,6 +220,11 @@ function LeadCard({
</span>
</div>
{sub && <p className="text-xs text-[var(--color-ink-muted)]">{sub}</p>}
{lead.projectName && (
<p className="text-xs text-[var(--color-ink-muted)]">
<span className="rounded-full bg-black/5 px-2 py-0.5">↳ {lead.projectName}</span>
</p>
)}
<div className="flex items-center justify-between text-xs text-[var(--color-ink-muted)]">
<span>{lead.ownerName ?? 'ohne Owner'}</span>
<span className="font-mono tabular-nums">Score {lead.score}/10</span>
@@ -217,12 +242,15 @@ function LeadCard({
function LeadCreateDialog({ onClose }: { onClose: () => void }) {
const users = trpc.user.list.useQuery();
const projectsQ = trpc.project.list.useQuery();
const projects = (projectsQ.data ?? []).map((r) => ({ id: r.project.id, name: r.project.name }));
const [firma, setFirma] = useState('');
const [branche, setBranche] = useState('');
const [subSegment, setSubSegment] = useState('');
const [website, setWebsite] = useState('');
const [quelle, setQuelle] = useState('');
const [ownerUserId, setOwnerUserId] = useState('');
const [projectId, setProjectId] = useState('');
const [status, setStatus] = useState<LeadStatus>('cold');
const [score, setScore] = useState(0);
@@ -245,6 +273,7 @@ function LeadCreateDialog({ onClose }: { onClose: () => void }) {
website: website.trim() || undefined,
quelle: quelle.trim() || undefined,
ownerUserId: ownerUserId || undefined,
projectId: projectId || undefined,
status,
score,
});
@@ -287,6 +316,16 @@ function LeadCreateDialog({ onClose }: { onClose: () => void }) {
<Field label="Quelle (wie gefunden)">
<input value={quelle} onChange={(e) => setQuelle(e.target.value)} className={inputCls} />
</Field>
<Field label="Projekt (optional)">
<select value={projectId} onChange={(e) => setProjectId(e.target.value)} className={inputCls}>
<option value="">— kein Projekt —</option>
{projects.map((p) => (
<option key={p.id} value={p.id}>
{p.name}
</option>
))}
</select>
</Field>
<div className="grid grid-cols-2 gap-3">
<Field label="Owner">
<select