feat(leads): Leads universell mit Projekten verknüpfen
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:
1 parent
68480c1eb1
commit
19db774c4c
10 files changed
+3522
-3
No files matched your search
@@ -11,6 +11,7 @@ import { useCurrentUser } from '../hooks/useCurrentUser';
|
||||
import { voice } from '../lib/voice';
|
||||
import { toast } from 'sonner';
|
||||
import { clsx } from 'clsx';
|
||||
import { LEAD_STATUS_META, type LeadStatus } from '../lib/lead-meta';
|
||||
import {
|
||||
MODUS_META,
|
||||
MODI,
|
||||
@@ -176,6 +177,8 @@ export function ProjektRoute() {
|
||||
|
||||
<StakeholdersSection projectId={p.id} />
|
||||
|
||||
<LeadsSection projectId={p.id} />
|
||||
|
||||
<RisksSection projectId={p.id} />
|
||||
|
||||
<ChangeLogSection projectId={p.id} />
|
||||
@@ -1106,6 +1109,100 @@ function LevelSelect({
|
||||
);
|
||||
}
|
||||
|
||||
// --- Leads (Vertriebs-Sicht des Projekts) -----------------------------------
|
||||
function LeadsSection({ projectId }: { projectId: string }) {
|
||||
const utils = trpc.useUtils();
|
||||
const q = trpc.lead.forProject.useQuery({ projectId });
|
||||
const [adding, setAdding] = useState(false);
|
||||
const [firma, setFirma] = useState('');
|
||||
const create = trpc.lead.create.useMutation({
|
||||
onSuccess: async () => {
|
||||
await utils.lead.forProject.invalidate({ projectId });
|
||||
await utils.lead.list.invalidate();
|
||||
setFirma('');
|
||||
setAdding(false);
|
||||
},
|
||||
});
|
||||
const list = q.data ?? [];
|
||||
return (
|
||||
<Card.Root>
|
||||
<Card.Header className="flex items-center justify-between">
|
||||
<h2 className="text-lg font-semibold">
|
||||
Leads{list.length > 0 && <span className="text-sm font-normal text-[var(--color-ink-muted)]"> ({list.length})</span>}
|
||||
</h2>
|
||||
<div className="flex items-center gap-3">
|
||||
<Link
|
||||
to="/leads"
|
||||
className="text-xs text-[var(--color-ink-muted)] hover:text-[var(--color-ink)] hover:underline"
|
||||
>
|
||||
Alle Leads →
|
||||
</Link>
|
||||
{!adding && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setAdding(true)}
|
||||
className="inline-flex items-center gap-1 text-xs text-[var(--color-ink-muted)] hover:text-[var(--color-ink)]"
|
||||
>
|
||||
<Plus size={13} /> Lead
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</Card.Header>
|
||||
<Card.Body className="space-y-2">
|
||||
{list.length === 0 && !adding && (
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
Noch keine Leads mit diesem Projekt verknüpft.
|
||||
</p>
|
||||
)}
|
||||
{list.map((l) => (
|
||||
<Link
|
||||
key={l.id}
|
||||
to={`/lead/${l.id}`}
|
||||
className="flex items-center justify-between gap-2 rounded-[var(--radius-md)] border border-[var(--color-border)] p-2.5 text-sm hover:border-[var(--color-ink)]"
|
||||
>
|
||||
<span className="flex items-center gap-2">
|
||||
<span
|
||||
className={clsx('h-2 w-2 rounded-full', LEAD_STATUS_META[l.status as LeadStatus].dot)}
|
||||
/>
|
||||
<span className="font-medium">{l.firma}</span>
|
||||
{l.branche && <span className="text-xs text-[var(--color-ink-muted)]">{l.branche}</span>}
|
||||
</span>
|
||||
<span className="flex items-center gap-2 text-xs text-[var(--color-ink-muted)]">
|
||||
<span className={clsx('rounded-full px-2 py-0.5', LEAD_STATUS_META[l.status as LeadStatus].badge)}>
|
||||
{LEAD_STATUS_META[l.status as LeadStatus].label}
|
||||
</span>
|
||||
<span className="font-mono tabular-nums">{l.score}/10</span>
|
||||
</span>
|
||||
</Link>
|
||||
))}
|
||||
{adding && (
|
||||
<form
|
||||
className="flex gap-2"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
if (!firma.trim()) return;
|
||||
create.mutate({ firma: firma.trim(), projectId, status: 'cold', score: 0 });
|
||||
}}
|
||||
>
|
||||
<input
|
||||
value={firma}
|
||||
onChange={(e) => setFirma(e.target.value)}
|
||||
placeholder="Firma / Lead-Name"
|
||||
className={inputCls}
|
||||
/>
|
||||
<Button type="submit" size="sm" disabled={create.isPending}>
|
||||
Anlegen
|
||||
</Button>
|
||||
<Button type="button" size="sm" variant="ghost" onClick={() => setAdding(false)}>
|
||||
Abbrechen
|
||||
</Button>
|
||||
</form>
|
||||
)}
|
||||
</Card.Body>
|
||||
</Card.Root>
|
||||
);
|
||||
}
|
||||
|
||||
// --- Risiken & Chancen ------------------------------------------------------
|
||||
function RisksSection({ projectId }: { projectId: string }) {
|
||||
const q = trpc.risk.forProject.useQuery({ projectId });
|
||||
|
||||
Reference in new issue
Block a user