feat(dashboard): Startansicht mit Bewerbungen, Wandlung und Gewinnen
Erster Menuepunkt und Startansicht; das Logo oben links fuehrt dorthin zurueck. Vier Kennzahlen (Bewerbungen, daraus Opportunities samt Quote, gewonnene Projekte, aktuell beim Kunden), ein Saeulendiagramm mit denselben drei Reihen ueber der Zeit, die Bewerbungen je Berater, die naechsten Termine und alle Opportunities in Kundenvorstellung bzw. Interview Kunde. Zeitraum ueber vier Vorgaben oder frei, Einteilung nach Tag, Monat, Quartal oder Jahr. Bewerbung heisst dabei: ein Eintrag in der Akquise - jeder Eintrag bedeutet, dass ein Profil raus ist (so vom Nutzer festgelegt). Zwei Dinge dafuer am Datenmodell: - crm_opportunities.won_at haelt den Zeitpunkt des Wechsels nach "Beauftragt". Die Phase allein sagt nur, wie es jetzt steht, nicht wann es passiert ist. Beim Wechsel heraus wird das Datum geleert, sonst zaehlt das Dashboard einen Gewinn, den es nicht gibt. - Die Akquise loescht nach 90 Tagen - damit waere jede Jahresauswertung falsch. Der Aufraeumlauf sichert deshalb vorher Tag, Berater und Anzahl in crm_acquisition_history, in derselben Transaktion wie das Loeschen. Gesichert wird nur, was verschwindet; die Auswertung addiert beide Quellen und kann sich damit nicht ueberschneiden. Projektdaten sind nach dem Loeschen weiterhin weg. Termine und die Phasenlisten kommen nicht aus einem eigenen Endpunkt: Termine und Opportunities laedt die App ohnehin komplett, das Dashboard filtert sie selbst. Diagramme von Hand (SVG-freie Balken plus Tailwind-Uebergaenge) statt einer Bibliothek - drei Darstellungen rechtfertigen keine weitere Abhaengigkeit, und so kommen die Farben aus denselben Tokens wie der Rest. Die Zahlen laufen hoch, die Saeulen wachsen; wer Bewegung im System abgeschaltet hat, bekommt sofort den Endwert. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
42639c65fa
commit
6f57483f33
+6
-1
@@ -4,6 +4,7 @@ import { Header } from './components/Header';
|
||||
import { LoginScreen } from './components/LoginScreen';
|
||||
import { Leads } from './components/leads/Leads';
|
||||
import { MailPoolLeads } from './components/leads/MailPoolLeads';
|
||||
import { Dashboard } from './components/dashboard/Dashboard';
|
||||
import { Acquisitions } from './components/acquisition/Acquisitions';
|
||||
import { Opportunities } from './components/opportunities/Opportunities';
|
||||
import { OpportunityTrash } from './components/opportunities/OpportunityTrash';
|
||||
@@ -50,7 +51,7 @@ const Splash: React.FC = () => (
|
||||
);
|
||||
|
||||
/** Erster Reiter im Menue - hier startet die App. */
|
||||
const DEFAULT_VIEW: ViewState = 'Opportunities';
|
||||
const DEFAULT_VIEW: ViewState = 'Dashboard';
|
||||
|
||||
const App: React.FC = () => {
|
||||
const { user, isLoading } = useAuth();
|
||||
@@ -160,6 +161,7 @@ const App: React.FC = () => {
|
||||
// Untertitel der Kopfzeile. Die Scanner-Reiter bringen ihre Kennzahlen selbst
|
||||
// mit, deshalb steht hier nur, worum es auf der Seite geht.
|
||||
const STATIC_SUBTITLES: Partial<Record<ViewState, string>> = {
|
||||
Dashboard: 'Wie der Vertrieb läuft - Bewerbungen, Opportunities, gewonnene Projekte',
|
||||
Akquise: 'Gefundene Projekte - eintragen, prüfen, zur Opportunity machen',
|
||||
'Opportunity-Papierkorb': 'Gelöschte Opportunities - nach 90 Tagen endgültig entfernt',
|
||||
Archiv: 'Akquise-Einträge älter als 14 Tage - nach 90 Tagen werden sie gelöscht',
|
||||
@@ -216,6 +218,9 @@ const App: React.FC = () => {
|
||||
/>
|
||||
|
||||
<div className="scrollbar-slim flex-1 overflow-y-auto p-4 md:p-6">
|
||||
{currentView === 'Dashboard' && (
|
||||
<Dashboard opportunities={opportunities} events={events} isLoading={isDataLoading} />
|
||||
)}
|
||||
{currentView === 'Akquise' && <Acquisitions reload={() => loadData(true)} />}
|
||||
{currentView === 'Archiv' && (
|
||||
<Acquisitions view="archiv" reload={() => loadData(true)} />
|
||||
|
||||
@@ -62,6 +62,9 @@ const CONTACTS_GROUP: MenuGroup = {
|
||||
],
|
||||
};
|
||||
|
||||
const DASHBOARD_ICON =
|
||||
'M4 5a1 1 0 011-1h4a1 1 0 011 1v6a1 1 0 01-1 1H5a1 1 0 01-1-1V5zm10 0a1 1 0 011-1h4a1 1 0 011 1v3a1 1 0 01-1 1h-4a1 1 0 01-1-1V5zM4 16a1 1 0 011-1h4a1 1 0 011 1v3a1 1 0 01-1 1H5a1 1 0 01-1-1v-3zm10-4a1 1 0 011-1h4a1 1 0 011 1v7a1 1 0 01-1 1h-4a1 1 0 01-1-1v-7z';
|
||||
|
||||
const ACQUISITION_ICON =
|
||||
'M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01';
|
||||
const ARCHIVE_ICON =
|
||||
@@ -146,6 +149,7 @@ const SCANNER_GROUP: MenuGroup = {
|
||||
// Kategorien in Anzeigereihenfolge, einzelne Punkte und Gruppen gemischt.
|
||||
// Einstellungen bleibt separat am unteren Rand.
|
||||
const CATEGORY_ENTRIES: (MenuItem | MenuGroup)[] = [
|
||||
{ name: 'Dashboard', icon: DASHBOARD_ICON },
|
||||
ACQUISITION_GROUP,
|
||||
OPPORTUNITIES_GROUP,
|
||||
{
|
||||
@@ -351,8 +355,14 @@ export const Sidebar: React.FC<SidebarProps> = ({
|
||||
}`}
|
||||
>
|
||||
{/* Logo */}
|
||||
<div
|
||||
className={`flex shrink-0 items-center border-b border-ink-100 ${
|
||||
<button
|
||||
onClick={() => {
|
||||
onViewChange('Dashboard');
|
||||
if (isMobile) onToggle();
|
||||
}}
|
||||
title="Zum Dashboard"
|
||||
aria-label="Zum Dashboard"
|
||||
className={`flex shrink-0 items-center border-b border-ink-100 transition hover:bg-ink-50 ${
|
||||
showLabels ? 'px-5 py-5' : 'justify-center px-0 py-5'
|
||||
}`}
|
||||
>
|
||||
@@ -363,7 +373,7 @@ export const Sidebar: React.FC<SidebarProps> = ({
|
||||
p
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</button>
|
||||
|
||||
{/* Kategorien */}
|
||||
<nav className="scrollbar-slim flex-1 space-y-1 overflow-y-auto overflow-x-hidden px-3 py-4">
|
||||
|
||||
@@ -0,0 +1,458 @@
|
||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { BarList, Panel, SeriesChart, StatCard, type SeriesPoint } from './dashboardUi';
|
||||
import { StageBadge } from '../opportunities/opportunityUi';
|
||||
import { UserAvatar } from '../ui/UserAvatar';
|
||||
import { useToast } from '../Toast';
|
||||
import { useNavigation } from '../../lib/navigation';
|
||||
import { dashboardApi, type DashboardBucket, type DashboardStats } from '../../lib/api';
|
||||
import {
|
||||
formatEuro,
|
||||
opportunityVolume,
|
||||
type CalendarEvent,
|
||||
type Opportunity,
|
||||
} from '../../types';
|
||||
|
||||
/*
|
||||
* Dashboard: was der Vertrieb wissen muss, ohne irgendwo hineinzuklicken.
|
||||
*
|
||||
* Die drei Reihen (Bewerbungen, daraus Opportunities, gewonnene Projekte) kommen
|
||||
* gerechnet aus dem Backend. Termine und die Listen zu den Phasen filtert die
|
||||
* Ansicht aus dem, was die App ohnehin geladen hat - ein zweiter Weg zu denselben
|
||||
* Daten waere doppelte Pflege.
|
||||
*/
|
||||
|
||||
interface DashboardProps {
|
||||
opportunities: Opportunity[];
|
||||
events: CalendarEvent[];
|
||||
isLoading: boolean;
|
||||
}
|
||||
|
||||
/** Zeitraum-Vorgaben. Jede bringt die Einteilung mit, die zu ihr passt. */
|
||||
const RANGES = [
|
||||
{ id: 'tage30', label: '30 Tage', bucket: 'tag' as DashboardBucket, days: 29 },
|
||||
{ id: 'monate12', label: '12 Monate', bucket: 'monat' as DashboardBucket, months: 11 },
|
||||
{ id: 'quartale8', label: '8 Quartale', bucket: 'quartal' as DashboardBucket, months: 23 },
|
||||
{ id: 'jahre5', label: '5 Jahre', bucket: 'jahr' as DashboardBucket, years: 4 },
|
||||
];
|
||||
|
||||
const BUCKETS: { id: DashboardBucket; label: string }[] = [
|
||||
{ id: 'tag', label: 'Tag' },
|
||||
{ id: 'monat', label: 'Monat' },
|
||||
{ id: 'quartal', label: 'Quartal' },
|
||||
{ id: 'jahr', label: 'Jahr' },
|
||||
];
|
||||
|
||||
const iso = (date: Date) => date.toISOString().slice(0, 10);
|
||||
|
||||
/** Anfang und Ende einer Vorgabe - `to` ist immer heute. */
|
||||
function rangeDates(range: (typeof RANGES)[number]): { from: string; to: string } {
|
||||
const to = new Date();
|
||||
const from = new Date(to);
|
||||
if (range.days !== undefined) from.setDate(from.getDate() - range.days);
|
||||
if (range.months !== undefined) from.setMonth(from.getMonth() - range.months, 1);
|
||||
if (range.years !== undefined) from.setFullYear(from.getFullYear() - range.years, 0, 1);
|
||||
return { from: iso(from), to: iso(to) };
|
||||
}
|
||||
|
||||
const MONTHS = ['Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'];
|
||||
|
||||
/**
|
||||
* Alle Abschnitte zwischen zwei Daten - auch die leeren. Ohne sie waere eine
|
||||
* Woche ohne Bewerbung im Diagramm nicht zu sehen, und die Achse wuerde luegen.
|
||||
*/
|
||||
function buildAxis(from: string, to: string, bucket: DashboardBucket): { key: string; label: string }[] {
|
||||
const start = new Date(`${from}T00:00:00`);
|
||||
const end = new Date(`${to}T00:00:00`);
|
||||
const out: { key: string; label: string }[] = [];
|
||||
const guard = 400;
|
||||
|
||||
if (bucket === 'tag') {
|
||||
for (const cursor = new Date(start); cursor <= end && out.length < guard; cursor.setDate(cursor.getDate() + 1)) {
|
||||
out.push({
|
||||
key: iso(cursor),
|
||||
label: `${String(cursor.getDate()).padStart(2, '0')}.${String(cursor.getMonth() + 1).padStart(2, '0')}.`,
|
||||
});
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
if (bucket === 'monat') {
|
||||
const cursor = new Date(start.getFullYear(), start.getMonth(), 1);
|
||||
while (cursor <= end && out.length < guard) {
|
||||
out.push({
|
||||
key: `${cursor.getFullYear()}-${String(cursor.getMonth() + 1).padStart(2, '0')}`,
|
||||
label: `${MONTHS[cursor.getMonth()]} ${String(cursor.getFullYear()).slice(2)}`,
|
||||
});
|
||||
cursor.setMonth(cursor.getMonth() + 1);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
if (bucket === 'quartal') {
|
||||
const cursor = new Date(start.getFullYear(), Math.floor(start.getMonth() / 3) * 3, 1);
|
||||
while (cursor <= end && out.length < guard) {
|
||||
const quarter = Math.floor(cursor.getMonth() / 3) + 1;
|
||||
out.push({
|
||||
key: `${cursor.getFullYear()}-Q${quarter}`,
|
||||
label: `Q${quarter} ${String(cursor.getFullYear()).slice(2)}`,
|
||||
});
|
||||
cursor.setMonth(cursor.getMonth() + 3);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
for (let year = start.getFullYear(); year <= end.getFullYear() && out.length < guard; year += 1) {
|
||||
out.push({ key: String(year), label: String(year) });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** MariaDB-DATETIME (Wandzeit) nach Date - wie in der Terminansicht. */
|
||||
function parseLocal(value: string): Date | null {
|
||||
const date = new Date(value.replace(' ', 'T'));
|
||||
return Number.isNaN(date.getTime()) ? null : date;
|
||||
}
|
||||
|
||||
function formatEventDate(event: CalendarEvent): string {
|
||||
const date = parseLocal(event.starts_at);
|
||||
if (!date) return '—';
|
||||
const day = date.toLocaleDateString('de-DE', { weekday: 'short', day: '2-digit', month: '2-digit' });
|
||||
if (event.all_day) return `${day} · ganztägig`;
|
||||
return `${day} · ${date.toLocaleTimeString('de-DE', { hour: '2-digit', minute: '2-digit' })}`;
|
||||
}
|
||||
|
||||
/** "heute", "morgen", sonst der Abstand in Tagen. */
|
||||
function relativeDay(value: string): string {
|
||||
const date = parseLocal(value);
|
||||
if (!date) return '';
|
||||
const today = new Date();
|
||||
today.setHours(0, 0, 0, 0);
|
||||
const target = new Date(date);
|
||||
target.setHours(0, 0, 0, 0);
|
||||
const days = Math.round((target.getTime() - today.getTime()) / 86_400_000);
|
||||
if (days === 0) return 'heute';
|
||||
if (days === 1) return 'morgen';
|
||||
return `in ${days} Tagen`;
|
||||
}
|
||||
|
||||
export const Dashboard: React.FC<DashboardProps> = ({ opportunities, events, isLoading }) => {
|
||||
const { addToast } = useToast();
|
||||
const { goTo } = useNavigation();
|
||||
|
||||
const [rangeId, setRangeId] = useState('monate12');
|
||||
const [bucket, setBucket] = useState<DashboardBucket>('monat');
|
||||
const [custom, setCustom] = useState<{ from: string; to: string } | null>(null);
|
||||
const [stats, setStats] = useState<DashboardStats | null>(null);
|
||||
const [isStatsLoading, setIsStatsLoading] = useState(true);
|
||||
|
||||
const range = RANGES.find((entry) => entry.id === rangeId) ?? RANGES[1];
|
||||
const dates = useMemo(() => custom ?? rangeDates(range), [custom, range]);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setIsStatsLoading(true);
|
||||
try {
|
||||
setStats(await dashboardApi.stats({ ...dates, bucket }));
|
||||
} catch (err) {
|
||||
addToast(err instanceof Error ? err.message : 'Auswertung nicht abrufbar.', 'error');
|
||||
} finally {
|
||||
setIsStatsLoading(false);
|
||||
}
|
||||
}, [dates, bucket, addToast]);
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, [load]);
|
||||
|
||||
const points = useMemo<SeriesPoint[]>(() => {
|
||||
if (!stats) return [];
|
||||
return buildAxis(stats.from, stats.to, stats.bucket).map((step) => ({
|
||||
key: step.key,
|
||||
label: step.label,
|
||||
applications: stats.series.applications[step.key] ?? 0,
|
||||
converted: stats.series.converted[step.key] ?? 0,
|
||||
won: stats.series.won[step.key] ?? 0,
|
||||
}));
|
||||
}, [stats]);
|
||||
|
||||
const consultantRows = useMemo(
|
||||
() =>
|
||||
(stats?.by_consultant ?? []).map((row) => ({
|
||||
label: row.consultant ?? 'Ohne Berater',
|
||||
value: row.applications,
|
||||
hint: row.consultant
|
||||
? `${row.applications} Bewerbung(en) für ${row.consultant}`
|
||||
: 'Einträge ohne hinterlegten Berater',
|
||||
})),
|
||||
[stats]
|
||||
);
|
||||
|
||||
// Anstehende Termine: alles ab jetzt, das Naechste zuerst.
|
||||
const upcoming = useMemo(() => {
|
||||
const now = Date.now();
|
||||
return events
|
||||
.filter((event) => {
|
||||
const end = parseLocal(event.ends_at) ?? parseLocal(event.starts_at);
|
||||
return end !== null && end.getTime() >= now;
|
||||
})
|
||||
.sort((a, b) => a.starts_at.localeCompare(b.starts_at))
|
||||
.slice(0, 8);
|
||||
}, [events]);
|
||||
|
||||
/** Die beiden Phasen, in denen der Kunde am Zug ist. */
|
||||
const atCustomer = useMemo(
|
||||
() =>
|
||||
opportunities
|
||||
.filter(
|
||||
(item) => item.stage === 'Kundenvorstellung' || item.stage === 'Interview Kunde'
|
||||
)
|
||||
.sort((a, b) => (b.updated_at ?? '').localeCompare(a.updated_at ?? '')),
|
||||
[opportunities]
|
||||
);
|
||||
|
||||
const totals = stats?.totals ?? { applications: 0, converted: 0, won: 0 };
|
||||
const quote = (part: number, whole: number) =>
|
||||
whole === 0 ? 'noch keine Grundlage' : `${Math.round((part / whole) * 100)} % der Bewerbungen`;
|
||||
|
||||
const periodLabel = custom
|
||||
? `${dates.from.split('-').reverse().join('.')} – ${dates.to.split('-').reverse().join('.')}`
|
||||
: range.label;
|
||||
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
{/* Steuerleiste */}
|
||||
<div className="flex flex-col gap-3 rounded-2xl border border-ink-200 bg-surface p-4 shadow-card lg:flex-row lg:items-center">
|
||||
<div className="flex flex-wrap items-center gap-1 rounded-xl border border-ink-200 p-1">
|
||||
{RANGES.map((entry) => (
|
||||
<button
|
||||
key={entry.id}
|
||||
onClick={() => {
|
||||
setRangeId(entry.id);
|
||||
setBucket(entry.bucket);
|
||||
setCustom(null);
|
||||
}}
|
||||
className={`rounded-lg px-3 py-1.5 text-sm font-bold transition ${
|
||||
!custom && rangeId === entry.id
|
||||
? 'bg-brand-500 text-white'
|
||||
: 'text-ink-500 hover:bg-brand-50 hover:text-brand-700'
|
||||
}`}
|
||||
>
|
||||
{entry.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<label className="text-[11px] font-extrabold uppercase tracking-wider text-ink-400" htmlFor="dash-from">
|
||||
von
|
||||
</label>
|
||||
<input
|
||||
id="dash-from"
|
||||
type="date"
|
||||
value={dates.from}
|
||||
max={dates.to}
|
||||
onChange={(event) => setCustom({ from: event.target.value, to: dates.to })}
|
||||
className="rounded-xl border border-ink-300 bg-ink-50 px-3 py-2 text-sm text-ink-900 outline-none transition focus:border-brand-500 focus:bg-surface"
|
||||
/>
|
||||
<label className="text-[11px] font-extrabold uppercase tracking-wider text-ink-400" htmlFor="dash-to">
|
||||
bis
|
||||
</label>
|
||||
<input
|
||||
id="dash-to"
|
||||
type="date"
|
||||
value={dates.to}
|
||||
min={dates.from}
|
||||
onChange={(event) => setCustom({ from: dates.from, to: event.target.value })}
|
||||
className="rounded-xl border border-ink-300 bg-ink-50 px-3 py-2 text-sm text-ink-900 outline-none transition focus:border-brand-500 focus:bg-surface"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2 lg:ml-auto">
|
||||
<span className="text-[11px] font-extrabold uppercase tracking-wider text-ink-400">
|
||||
Einteilung
|
||||
</span>
|
||||
<select
|
||||
value={bucket}
|
||||
onChange={(event) => setBucket(event.target.value as DashboardBucket)}
|
||||
aria-label="Zeiteinteilung der Auswertung"
|
||||
className="rounded-xl border border-ink-300 bg-ink-50 px-3 py-2 text-sm font-semibold text-ink-700 outline-none transition focus:border-brand-500 focus:bg-surface"
|
||||
>
|
||||
{BUCKETS.map((entry) => (
|
||||
<option key={entry.id} value={entry.id}>
|
||||
{entry.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
{isStatsLoading && (
|
||||
<span className="h-4 w-4 animate-spin rounded-full border-2 border-brand-200 border-t-brand-500" />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Kennzahlen */}
|
||||
<div className="grid gap-4 sm:grid-cols-2 xl:grid-cols-4">
|
||||
<StatCard
|
||||
label="Bewerbungen"
|
||||
value={totals.applications}
|
||||
accent="border-l-sky-500"
|
||||
icon="M12 19l9 2-9-18-9 18 9-2zm0 0v-8"
|
||||
hint="Einträge in der Akquise im gewählten Zeitraum"
|
||||
footnote={`versendet · ${periodLabel}`}
|
||||
/>
|
||||
<StatCard
|
||||
label="Zu Opportunity"
|
||||
value={totals.converted}
|
||||
accent="border-l-violet-500"
|
||||
icon="M13 7h8m0 0v8m0-8l-8 8-4-4-6 6"
|
||||
hint="Bewerbungen, aus denen eine Opportunity geworden ist"
|
||||
footnote={quote(totals.converted, totals.applications)}
|
||||
/>
|
||||
<StatCard
|
||||
label="Gewonnen"
|
||||
value={totals.won}
|
||||
accent="border-l-brand-500"
|
||||
icon="M5 3v4M3 5h4M6 17v4m-2-2h4m5-16l2.286 6.857L21 12l-5.714 2.143L13 21l-2.286-6.857L5 12l5.714-2.143L13 3z"
|
||||
hint="Opportunities, die in der Phase „Beauftragt“ gelandet sind"
|
||||
footnote={`Projekte · ${quote(totals.won, totals.applications)}`}
|
||||
/>
|
||||
<StatCard
|
||||
label="Beim Kunden"
|
||||
value={atCustomer.length}
|
||||
accent="border-l-amber-500"
|
||||
icon="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z"
|
||||
hint="Opportunities in Kundenvorstellung oder Interview Kunde - jetzt, unabhängig vom Zeitraum"
|
||||
footnote="Kundenvorstellung + Interview"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Verlauf und Berater */}
|
||||
<div className="grid gap-5 xl:grid-cols-[2fr_1fr]">
|
||||
<Panel
|
||||
title="Verlauf"
|
||||
hint={`Bewerbungen, daraus entstandene Opportunities und gewonnene Projekte · ${periodLabel}`}
|
||||
>
|
||||
{points.length === 0 ? (
|
||||
<p className="rounded-xl border border-dashed border-ink-200 px-4 py-12 text-center text-xs font-semibold text-ink-400">
|
||||
Für diesen Zeitraum gibt es noch keine Zahlen.
|
||||
</p>
|
||||
) : (
|
||||
<SeriesChart points={points} />
|
||||
)}
|
||||
</Panel>
|
||||
|
||||
<Panel
|
||||
title="Bewerbungen je Berater"
|
||||
hint={`Wer im Zeitraum ${periodLabel} vorgeschlagen wurde`}
|
||||
>
|
||||
<BarList
|
||||
rows={consultantRows}
|
||||
color="#0284c7"
|
||||
emptyText="Im gewählten Zeitraum wurde noch keine Bewerbung eingetragen."
|
||||
/>
|
||||
</Panel>
|
||||
</div>
|
||||
|
||||
{/* Termine und Opportunities beim Kunden */}
|
||||
<div className="grid gap-5 xl:grid-cols-2">
|
||||
<Panel
|
||||
title="Anstehende Interviews"
|
||||
hint="Die nächsten Termine aus dem gemeinsamen Kalender"
|
||||
action={
|
||||
<button
|
||||
onClick={() => goTo('Interviews')}
|
||||
className="shrink-0 rounded-xl border border-ink-200 px-3 py-1.5 text-xs font-bold text-ink-600 transition hover:border-brand-300 hover:text-brand-700"
|
||||
>
|
||||
Alle Termine
|
||||
</button>
|
||||
}
|
||||
>
|
||||
{isLoading && upcoming.length === 0 ? (
|
||||
<p className="py-8 text-center text-xs font-semibold text-ink-400">Lade...</p>
|
||||
) : upcoming.length === 0 ? (
|
||||
<p className="rounded-xl border border-dashed border-ink-200 px-4 py-8 text-center text-xs font-semibold text-ink-400">
|
||||
Nichts geplant.
|
||||
</p>
|
||||
) : (
|
||||
<ul className="space-y-2">
|
||||
{upcoming.map((event) => (
|
||||
<li
|
||||
key={event.id}
|
||||
className="flex items-center gap-3 rounded-xl border border-ink-200 bg-ink-50/50 px-3 py-2.5"
|
||||
>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="truncate text-sm font-bold text-ink-900">{event.title}</p>
|
||||
<p className="truncate text-xs text-ink-400">
|
||||
{formatEventDate(event)}
|
||||
{event.location ? ` · ${event.location}` : ''}
|
||||
</p>
|
||||
</div>
|
||||
<span className="shrink-0 rounded-md border border-brand-200 bg-brand-50 px-2 py-0.5 text-[10px] font-extrabold uppercase tracking-wider text-brand-700">
|
||||
{relativeDay(event.starts_at)}
|
||||
</span>
|
||||
{event.participants.length > 0 && (
|
||||
<div className="flex shrink-0 -space-x-2">
|
||||
{event.participants.slice(0, 3).map((person) => (
|
||||
<UserAvatar key={person.id} user={person} size={24} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</Panel>
|
||||
|
||||
<Panel
|
||||
title="Beim Kunden"
|
||||
hint="Opportunities in Kundenvorstellung und Interview Kunde"
|
||||
action={
|
||||
<button
|
||||
onClick={() => goTo('Opportunities')}
|
||||
className="shrink-0 rounded-xl border border-ink-200 px-3 py-1.5 text-xs font-bold text-ink-600 transition hover:border-brand-300 hover:text-brand-700"
|
||||
>
|
||||
Zur Pipeline
|
||||
</button>
|
||||
}
|
||||
>
|
||||
{atCustomer.length === 0 ? (
|
||||
<p className="rounded-xl border border-dashed border-ink-200 px-4 py-8 text-center text-xs font-semibold text-ink-400">
|
||||
Gerade liegt nichts beim Kunden.
|
||||
</p>
|
||||
) : (
|
||||
<ul className="space-y-2">
|
||||
{atCustomer.map((opportunity) => (
|
||||
<li
|
||||
key={opportunity.id}
|
||||
className="flex flex-wrap items-center gap-3 rounded-xl border border-ink-200 bg-ink-50/50 px-3 py-2.5"
|
||||
>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="truncate text-sm font-bold text-ink-900">{opportunity.title}</p>
|
||||
<p className="truncate text-xs text-ink-400">
|
||||
{opportunity.company || 'Ohne Firma'}
|
||||
{opportunity.contacts.length > 0 &&
|
||||
` · ${opportunity.contacts.length} Ansprechpartner`}
|
||||
</p>
|
||||
</div>
|
||||
<StageBadge stage={opportunity.stage} />
|
||||
<span className="shrink-0 text-sm font-extrabold tabular-nums text-ink-800">
|
||||
{formatEuro(opportunityVolume(opportunity))}
|
||||
</span>
|
||||
{opportunity.owner_id !== null && (
|
||||
<UserAvatar
|
||||
user={{
|
||||
id: opportunity.owner_id,
|
||||
name: opportunity.owner_name ?? '?',
|
||||
color: opportunity.owner_color ?? null,
|
||||
avatar: opportunity.owner_avatar ?? null,
|
||||
}}
|
||||
size={24}
|
||||
/>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</Panel>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,298 @@
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
|
||||
/*
|
||||
* Bausteine des Dashboards: Kachel mit hochlaufender Zahl, Saeulendiagramm und
|
||||
* Balkenliste. Alles von Hand als SVG bzw. mit Tailwind-Uebergaengen - eine
|
||||
* Diagrammbibliothek waere fuer drei Darstellungen mehr Abhaengigkeit als Nutzen,
|
||||
* und die Farben kommen so aus denselben Design-Tokens wie der Rest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Zaehlt eine Zahl in ~700 ms hoch. Bewusst ueber requestAnimationFrame und nicht
|
||||
* per Intervall: das laeuft im Bildtakt und haelt an, wenn der Reiter im
|
||||
* Hintergrund liegt.
|
||||
*
|
||||
* Wer Bewegung im System abgeschaltet hat, bekommt sofort den Endwert.
|
||||
*/
|
||||
export function useCountUp(target: number, duration = 700): number {
|
||||
const [value, setValue] = useState(0);
|
||||
const fromRef = useRef(0);
|
||||
|
||||
useEffect(() => {
|
||||
const reduce =
|
||||
typeof window !== 'undefined' &&
|
||||
window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
|
||||
if (reduce || duration <= 0) {
|
||||
fromRef.current = target;
|
||||
setValue(target);
|
||||
return;
|
||||
}
|
||||
|
||||
const from = fromRef.current;
|
||||
const start = performance.now();
|
||||
let frame = 0;
|
||||
|
||||
const step = (now: number) => {
|
||||
const progress = Math.min(1, (now - start) / duration);
|
||||
// Sanft auslaufen; linear wirkt bei Zahlen mechanisch.
|
||||
const eased = 1 - (1 - progress) ** 3;
|
||||
setValue(Math.round(from + (target - from) * eased));
|
||||
if (progress < 1) frame = requestAnimationFrame(step);
|
||||
else fromRef.current = target;
|
||||
};
|
||||
|
||||
frame = requestAnimationFrame(step);
|
||||
return () => cancelAnimationFrame(frame);
|
||||
}, [target, duration]);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
interface StatCardProps {
|
||||
label: string;
|
||||
value: number;
|
||||
hint: string;
|
||||
/** Tailwind-Klassen fuer den Akzent - Rand links und Zahl. */
|
||||
accent: string;
|
||||
icon: string;
|
||||
/** Zweite Zahl unter dem Wert, z. B. eine Quote. */
|
||||
footnote?: string;
|
||||
}
|
||||
|
||||
export const StatCard: React.FC<StatCardProps> = ({
|
||||
label,
|
||||
value,
|
||||
hint,
|
||||
accent,
|
||||
icon,
|
||||
footnote,
|
||||
}) => {
|
||||
const shown = useCountUp(value);
|
||||
|
||||
return (
|
||||
<section
|
||||
title={hint}
|
||||
className={`rounded-2xl border border-ink-200 border-l-4 bg-surface p-5 shadow-card transition hover:shadow-lift ${accent}`}
|
||||
>
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<p className="text-[11px] font-extrabold uppercase tracking-[0.14em] text-ink-400">
|
||||
{label}
|
||||
</p>
|
||||
<svg className="h-5 w-5 shrink-0 text-ink-300" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.8} d={icon} />
|
||||
</svg>
|
||||
</div>
|
||||
<p className="mt-2 text-3xl font-extrabold tabular-nums text-ink-900">
|
||||
{shown.toLocaleString('de-DE')}
|
||||
</p>
|
||||
<p className="mt-1 text-xs text-ink-400">{footnote ?? hint}</p>
|
||||
</section>
|
||||
);
|
||||
};
|
||||
|
||||
export interface SeriesPoint {
|
||||
key: string;
|
||||
label: string;
|
||||
applications: number;
|
||||
converted: number;
|
||||
won: number;
|
||||
}
|
||||
|
||||
/** Beschriftung, Farbe und Erklaerung der drei Reihen - einmal definiert. */
|
||||
export const SERIES = [
|
||||
{
|
||||
id: 'applications' as const,
|
||||
label: 'Bewerbungen',
|
||||
color: '#0284c7',
|
||||
hint: 'Einträge in der Akquise - jeder Eintrag ist eine versendete Bewerbung',
|
||||
},
|
||||
{
|
||||
id: 'converted' as const,
|
||||
label: 'Zu Opportunity',
|
||||
color: '#7c3aed',
|
||||
hint: 'Bewerbungen, aus denen eine Opportunity geworden ist',
|
||||
},
|
||||
{
|
||||
id: 'won' as const,
|
||||
label: 'Gewonnen',
|
||||
color: '#6ba04a',
|
||||
hint: 'Opportunities in der Phase „Beauftragt“',
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* Saeulendiagramm mit drei Reihen je Zeitabschnitt.
|
||||
*
|
||||
* Die Saeulen wachsen beim Aufbau und bei jedem Wechsel des Zeitraums von unten
|
||||
* heraus - das macht sichtbar, dass sich die Zahlen geaendert haben. Umgesetzt
|
||||
* ueber die Hoehe plus `transition`, nicht ueber ein Keyframe: so bewegt sich auch
|
||||
* der Wechsel von einem Wert zum naechsten.
|
||||
*/
|
||||
export const SeriesChart: React.FC<{ points: SeriesPoint[] }> = ({ points }) => {
|
||||
const [grown, setGrown] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setGrown(false);
|
||||
const timer = setTimeout(() => setGrown(true), 30);
|
||||
return () => clearTimeout(timer);
|
||||
}, [points]);
|
||||
|
||||
const max = Math.max(1, ...points.flatMap((p) => [p.applications, p.converted, p.won]));
|
||||
// Runde Obergrenze, damit die Hilfslinien lesbare Werte tragen.
|
||||
const step = Math.max(1, Math.ceil(max / 4));
|
||||
const top = step * 4;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="mb-4 flex flex-wrap items-center gap-4">
|
||||
{SERIES.map((series) => (
|
||||
<span key={series.id} className="flex items-center gap-2 text-xs font-bold text-ink-600" title={series.hint}>
|
||||
<span className="h-2.5 w-2.5 rounded-sm" style={{ backgroundColor: series.color }} />
|
||||
{series.label}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="scrollbar-slim overflow-x-auto">
|
||||
<div className="flex" style={{ minWidth: `${Math.max(560, points.length * 74)}px` }}>
|
||||
{/* Werteachse */}
|
||||
<div className="relative w-10 shrink-0" style={{ height: '260px' }}>
|
||||
{[4, 3, 2, 1, 0].map((line) => (
|
||||
<span
|
||||
key={line}
|
||||
className="absolute right-1 -translate-y-1/2 text-[10px] font-bold tabular-nums text-ink-400"
|
||||
style={{ top: `${((4 - line) / 4) * 100}%` }}
|
||||
>
|
||||
{step * line}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="relative flex-1">
|
||||
{/* Hilfslinien */}
|
||||
<div className="absolute inset-x-0 top-0" style={{ height: '260px' }}>
|
||||
{[0, 1, 2, 3, 4].map((line) => (
|
||||
<div
|
||||
key={line}
|
||||
className={`absolute inset-x-0 border-t ${
|
||||
line === 4 ? 'border-ink-300' : 'border-ink-100'
|
||||
}`}
|
||||
style={{ top: `${(line / 4) * 100}%` }}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="relative flex items-end gap-2" style={{ height: '260px' }}>
|
||||
{points.map((point) => (
|
||||
<div key={point.key} className="flex h-full min-w-0 flex-1 items-end justify-center gap-1">
|
||||
{SERIES.map((series) => {
|
||||
const value = point[series.id];
|
||||
const height = grown ? (value / top) * 100 : 0;
|
||||
|
||||
return (
|
||||
<div
|
||||
key={series.id}
|
||||
title={`${point.label} · ${series.label}: ${value}`}
|
||||
className="relative flex w-full max-w-[16px] flex-1 justify-center rounded-t-sm transition-all duration-700 ease-out"
|
||||
style={{
|
||||
height: `${height}%`,
|
||||
minHeight: value > 0 ? '3px' : '0',
|
||||
backgroundColor: series.color,
|
||||
opacity: value > 0 ? 1 : 0.15,
|
||||
}}
|
||||
>
|
||||
{value > 0 && (
|
||||
<span className="absolute -top-5 text-[10px] font-extrabold tabular-nums text-ink-500">
|
||||
{value}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="mt-2 flex gap-2">
|
||||
{points.map((point) => (
|
||||
<p
|
||||
key={point.key}
|
||||
className="min-w-0 flex-1 truncate text-center text-[10px] font-bold text-ink-400"
|
||||
title={point.label}
|
||||
>
|
||||
{point.label}
|
||||
</p>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
/** Waagerechte Balken - fuer die Bewerbungen je Berater. */
|
||||
export const BarList: React.FC<{
|
||||
rows: { label: string; value: number; hint?: string }[];
|
||||
color: string;
|
||||
emptyText: string;
|
||||
}> = ({ rows, color, emptyText }) => {
|
||||
const [grown, setGrown] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setGrown(false);
|
||||
const timer = setTimeout(() => setGrown(true), 30);
|
||||
return () => clearTimeout(timer);
|
||||
}, [rows]);
|
||||
|
||||
if (rows.length === 0) {
|
||||
return (
|
||||
<p className="rounded-xl border border-dashed border-ink-200 px-4 py-8 text-center text-xs font-semibold text-ink-400">
|
||||
{emptyText}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
const max = Math.max(1, ...rows.map((row) => row.value));
|
||||
|
||||
return (
|
||||
<ul className="space-y-2.5">
|
||||
{rows.map((row) => (
|
||||
<li key={row.label} title={row.hint}>
|
||||
<div className="mb-1 flex items-baseline justify-between gap-3">
|
||||
<span className="min-w-0 truncate text-sm font-bold text-ink-800">{row.label}</span>
|
||||
<span className="shrink-0 text-sm font-extrabold tabular-nums text-ink-900">
|
||||
{row.value.toLocaleString('de-DE')}
|
||||
</span>
|
||||
</div>
|
||||
<div className="h-2 overflow-hidden rounded-full bg-ink-100">
|
||||
<div
|
||||
className="h-full rounded-full transition-all duration-700 ease-out"
|
||||
style={{ width: grown ? `${(row.value / max) * 100}%` : '0%', backgroundColor: color }}
|
||||
/>
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
};
|
||||
|
||||
/** Rahmen fuer die Abschnitte des Dashboards. */
|
||||
export const Panel: React.FC<{
|
||||
title: string;
|
||||
hint?: string;
|
||||
action?: React.ReactNode;
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
}> = ({ title, hint, action, children, className = '' }) => (
|
||||
<section className={`rounded-2xl border border-ink-200 bg-surface p-5 shadow-card ${className}`}>
|
||||
<div className="mb-4 flex flex-wrap items-start justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<h3 className="text-base text-ink-900">{title}</h3>
|
||||
{hint && <p className="mt-0.5 text-xs text-ink-400">{hint}</p>}
|
||||
</div>
|
||||
{action}
|
||||
</div>
|
||||
{children}
|
||||
</section>
|
||||
);
|
||||
@@ -209,6 +209,35 @@ export const opportunitiesApi = {
|
||||
request<{ ok: true; purged: number }>('/opportunities/trash/empty', { method: 'POST' }),
|
||||
};
|
||||
|
||||
// ---------- Dashboard ----------
|
||||
|
||||
/** Zeiteinteilung der Auswertung. */
|
||||
export type DashboardBucket = 'tag' | 'monat' | 'quartal' | 'jahr';
|
||||
|
||||
/**
|
||||
* Zahlen des Dashboards. Die Reihen kommen als Zuordnung Zeitabschnitt -> Anzahl;
|
||||
* die Achse baut die Ansicht selbst, damit auch leere Abschnitte erscheinen.
|
||||
*/
|
||||
export interface DashboardStats {
|
||||
from: string;
|
||||
to: string;
|
||||
bucket: DashboardBucket;
|
||||
series: {
|
||||
applications: Record<string, number>;
|
||||
converted: Record<string, number>;
|
||||
won: Record<string, number>;
|
||||
};
|
||||
totals: { applications: number; converted: number; won: number };
|
||||
by_consultant: { consultant: string | null; applications: number }[];
|
||||
}
|
||||
|
||||
export const dashboardApi = {
|
||||
stats: (params: { from: string; to: string; bucket: DashboardBucket }) =>
|
||||
request<DashboardStats>(
|
||||
`/dashboard?from=${params.from}&to=${params.to}&bucket=${params.bucket}`
|
||||
),
|
||||
};
|
||||
|
||||
// ---------- Zaehler der Seitenleiste ----------
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export type ViewState =
|
||||
| 'Dashboard'
|
||||
| 'Akquise'
|
||||
| 'Archiv'
|
||||
| 'Opportunities'
|
||||
@@ -274,6 +275,8 @@ export interface Opportunity {
|
||||
notes: string | null;
|
||||
owner_id: number | null;
|
||||
created_by: number | null;
|
||||
/** Zeitpunkt des Wechsels nach "Beauftragt" - Grundlage der Gewinn-Auswertung. */
|
||||
won_at: string | null;
|
||||
/** Gesetzt = liegt im Papierkorb; nach 90 Tagen wird sie dort geloescht. */
|
||||
deleted_at: string | null;
|
||||
deleted_by: number | null;
|
||||
|
||||
Reference in New Issue
Block a user