import { Link, NavLink, useParams } from 'react-router';
import { useState } from 'react';
import { trpc } from '../lib/trpc';
import { voice } from '../lib/voice';
import { Card } from '../components/ui/Card';
import { Button } from '../components/ui/Button';
import { SkeletonCard } from '../components/ui/SkeletonCard';
import { toast } from 'sonner';
import { clsx } from 'clsx';
import { LEAD_STATUS_META, type LeadStatus } from '../lib/lead-meta';
import { MODUS_META, type ProjectModus } from '../lib/project-meta';
const BEREICHE: Array<{ slug: 'entwicklung' | 'vertrieb' | 'marketing'; label: string }> = [
{ slug: 'entwicklung', label: 'Entwicklung' },
{ slug: 'vertrieb', label: 'Vertrieb' },
{ slug: 'marketing', label: 'Marketing' },
];
function BereichTabs({ active }: { active: string }) {
return (
);
}
export function BereichRoute() {
const { slug } = useParams<{ slug?: string }>();
// Default: Entwicklung, wenn /bereich ohne Slug.
const effective = slug && BEREICHE.some((b) => b.slug === slug) ? slug : 'entwicklung';
return (
{effective === 'entwicklung' && }
{effective === 'vertrieb' && }
{effective === 'marketing' && }
);
}
function EntwicklungDetail() {
const q = trpc.project.byAreaSlug.useQuery({ slug: 'entwicklung' });
const areas = trpc.area.list.useQuery();
const [open, setOpen] = useState(false);
if (q.isPending) return ;
const projects = q.data ?? [];
const kunden = projects.filter((p) => p.kind === 'kundenprojekt');
const intern = projects.filter((p) => p.kind === 'internes_projekt');
return (
{open && (
setOpen(false)}
areas={areas.data ?? []}
defaultSlug="entwicklung"
/>
)}
);
}
function Section({
title,
projects,
}: {
title: string;
projects: Array<{
id: string;
name: string;
statusCache: 'green' | 'amber' | 'red' | null;
deadline: string | null;
modus: ProjectModus;
pflichtMinimumState: Record;
}>;
}) {
return (
{title}
{projects.length === 0 ? (
{voice.empty.projects}
) : (
{projects.map((p) => (
{p.name}
{p.modus !== 'standard' && (
{MODUS_META[p.modus].label}
)}
{p.deadline ? `bis ${p.deadline}` : 'kein Deadline'}
))}
)}
);
}
function PflichtMinimumIndicator({ state }: { state: Record }) {
const points = [
state.steckbrief_freigegeben,
state.verantwortlicher,
state.plane_board,
state.meilensteine,
state.status_aktuell,
state.retrospektive,
];
const filled = points.filter(Boolean).length;
return (
{points.map((p, i) => (
))}
{filled}/6
);
}
function ProjectCreateDialog({
onClose,
areas,
defaultSlug,
}: {
onClose: () => void;
areas: Array<{ id: string; slug: string; name: string }>;
defaultSlug: string;
}) {
const defaultArea = areas.find((a) => a.slug === defaultSlug);
const [name, setName] = useState('');
const [description, setDescription] = useState('');
const [areaId, setAreaId] = useState(defaultArea?.id ?? '');
const [kind, setKind] = useState<'kundenprojekt' | 'internes_projekt'>('internes_projekt');
const [arbeitsmodus, setArbeitsmodus] = useState<'cycle' | 'kanban'>('kanban');
const [steckbrief, setSteckbrief] = useState('');
const [plane, setPlane] = useState('');
const utils = trpc.useUtils();
const create = trpc.project.create.useMutation({
onSuccess: async () => {
toast(voice.toast.projectCreated);
await utils.project.byAreaSlug.invalidate();
await utils.dashboard.overview.invalidate();
onClose();
},
});
function submit(e: React.FormEvent) {
e.preventDefault();
if (!areaId) return;
create.mutate({
areaId,
name,
description: description.trim() || undefined,
kind,
arbeitsmodus,
outlineSteckbriefUrl: steckbrief,
planeProjectUrl: plane,
milestones: [],
});
}
return (
e.stopPropagation()}
>
Neues Projekt
);
}
function Field({ label, children }: { label: string; children: React.ReactNode }) {
return (
);
}
function VertriebDetail() {
return (
);
}
function LeadsTeaser() {
const q = trpc.lead.list.useQuery();
const leads = q.data ?? [];
const offen = leads.filter((l) => l.status !== 'won' && l.status !== 'lost');
const top = [...offen]
.sort((a, b) => b.score - a.score)
.slice(0, 3);
return (
Leads
Alle Leads ({leads.length}) →
{q.isPending ? (
Lädt…
) : offen.length === 0 ? (
Keine offenen Leads.{' '}
Lege einen an.
) : (
{top.map((l) => {
const meta = LEAD_STATUS_META[l.status as LeadStatus];
return (
-
{l.firma}
{l.subSegment && (
{l.subSegment}
)}
{l.score}/10
);
})}
)}
);
}
function MarketingDetail() {
return ;
}
function ProjektListeFuerBereich({ slug }: { slug: 'vertrieb' | 'marketing' }) {
const q = trpc.project.byAreaSlug.useQuery({ slug });
const areas = trpc.area.list.useQuery();
const [open, setOpen] = useState(false);
if (q.isPending) return ;
const projects = q.data ?? [];
const kunden = projects.filter((p) => p.kind === 'kundenprojekt');
const intern = projects.filter((p) => p.kind === 'internes_projekt');
return (
{open && (
setOpen(false)}
areas={areas.data ?? []}
defaultSlug={slug}
/>
)}
);
}