Eine Tabelle aller Besetzungen der Person, juengste zuerst: Von, Bis (letzter Tag auf der Stelle), Planstelle mit Taetigkeit, Organisations- einheit, Kostenstelle zum letzten Tag und der Vorgang, mit dem der Abschnitt beginnt (Eintritt, Wiedereintritt, Versetzung, Befoerderung am selben Tag in der Historie). Die laufende Besetzung steht fett. Gelesen aus den Besetzungen selbst, nicht aus den Texten der Historie; die Daten laedt die Akte bereits, es kommt keine Abfrage hinzu. Geprueft: lint, tsc, npm test (1041, neu: stellenverlauf), Waechter.
157 lines
6.9 KiB
TypeScript
157 lines
6.9 KiB
TypeScript
import { Network } from "lucide-react";
|
||
import Link from "next/link";
|
||
import { Avatar } from "@/components/ui/Avatar";
|
||
import { LINK_BUTTON_CLASS } from "@/components/ui/Button";
|
||
import { fmtDate, fmtName } from "@/lib/format";
|
||
import type { StellenAbschnitt } from "@/lib/stellenverlauf";
|
||
|
||
type MiniEmployee = { id: string; first_name: string; last_name: string; job_title: string; status?: string };
|
||
|
||
type OrganisationTabProps = {
|
||
employeeId: string;
|
||
manager: MiniEmployee | null;
|
||
/** Nur gesetzt, wenn die zuständige Leitung abwesend ist und vertreten wird. */
|
||
formalManager: MiniEmployee | null;
|
||
directReports: MiniEmployee[];
|
||
breadcrumb: string;
|
||
/**
|
||
* Die Kostenstelle der Planstelle, auf der die Person heute sitzt — nicht
|
||
* ihre eigene: sie kontiert dorthin, wo ihr Sitz kontiert ist. Fehlt sie,
|
||
* hat die Person keine laufende Besetzung (geplanter Eintritt, Austritt).
|
||
*/
|
||
kostenstelle: { code: string; name: string } | null;
|
||
/** Alle Besetzungen, jüngste zuerst. */
|
||
stellenverlauf: StellenAbschnitt[];
|
||
};
|
||
|
||
// Die Niederlassung steht fachlich bewusst nicht hier neben Einheit und
|
||
// Kostenstelle, sondern im Vertragsblatt.
|
||
|
||
export function OrganisationTab({
|
||
employeeId,
|
||
manager,
|
||
formalManager,
|
||
directReports,
|
||
breadcrumb,
|
||
kostenstelle,
|
||
stellenverlauf,
|
||
}: OrganisationTabProps) {
|
||
return (
|
||
<div className="flex flex-col gap-6">
|
||
<div className="flex flex-wrap items-start justify-between gap-3">
|
||
<div>
|
||
<h3 className="text-xs font-semibold uppercase tracking-wide text-ink-muted">Organisationseinheit</h3>
|
||
<p className="mt-1 text-sm text-ink">{breadcrumb}</p>
|
||
<h3 className="mt-4 text-xs font-semibold uppercase tracking-wide text-ink-muted">Kostenstelle</h3>
|
||
<p className="mt-1 text-sm text-ink">
|
||
{kostenstelle ? (
|
||
<>
|
||
<span className="font-semibold tabular-nums">{kostenstelle.code}</span>
|
||
<span className="text-ink-body"> · {kostenstelle.name}</span>
|
||
</>
|
||
) : (
|
||
<span className="text-ink-muted">Keine laufende Planstellenbesetzung</span>
|
||
)}
|
||
</p>
|
||
</div>
|
||
{/* ?focus= drives the same highlight/auto-expand path the org chart
|
||
search already uses, so the person is unfolded and centred on
|
||
arrival instead of the user hunting for them. */}
|
||
<Link href={`/orgchart?focus=${employeeId}`} className={LINK_BUTTON_CLASS}>
|
||
<Network className="h-4 w-4" />
|
||
Im Organigramm anzeigen
|
||
</Link>
|
||
</div>
|
||
|
||
<div>
|
||
<h3 className="mb-2 text-xs font-semibold uppercase tracking-wide text-ink-muted">
|
||
{formalManager ? "Führungskraft (Vertretung)" : "Führungskraft"}
|
||
</h3>
|
||
{formalManager && (
|
||
<p className="mb-2 text-xs text-ink-muted">
|
||
Zuständig ist {fmtName(formalManager.first_name, formalManager.last_name)}; während der Abwesenheit übernimmt die nächste
|
||
besetzte Ebene.
|
||
</p>
|
||
)}
|
||
{manager ? (
|
||
<Link href={`/employees/${manager.id}`} className="flex w-fit items-center gap-3 rounded border border-border p-3 hover:bg-surface">
|
||
<Avatar firstName={manager.first_name} lastName={manager.last_name} />
|
||
<div>
|
||
<div className="text-sm font-semibold text-ink">
|
||
{fmtName(manager.first_name, manager.last_name)}
|
||
</div>
|
||
<div className="text-xs text-ink-muted">{manager.job_title}</div>
|
||
</div>
|
||
</Link>
|
||
) : (
|
||
<p className="text-sm text-ink-muted">Keine Führungskraft (Geschäftsführung)</p>
|
||
)}
|
||
</div>
|
||
|
||
<div>
|
||
<h3 className="mb-2 text-xs font-semibold uppercase tracking-wide text-ink-muted">Direkte Berichte ({directReports.length})</h3>
|
||
{directReports.length > 0 ? (
|
||
<div className="grid grid-cols-1 gap-2 sm:grid-cols-2 lg:grid-cols-3">
|
||
{directReports.map((r) => (
|
||
<Link key={r.id} href={`/employees/${r.id}`} className="flex items-center gap-3 rounded border border-border p-3 hover:bg-surface">
|
||
<Avatar firstName={r.first_name} lastName={r.last_name} />
|
||
<div>
|
||
<div className="text-sm font-semibold text-ink">
|
||
{fmtName(r.first_name, r.last_name)}
|
||
</div>
|
||
<div className="text-xs text-ink-muted">{r.job_title}</div>
|
||
</div>
|
||
</Link>
|
||
))}
|
||
</div>
|
||
) : (
|
||
<p className="text-sm text-ink-muted">Keine direkten Berichte.</p>
|
||
)}
|
||
</div>
|
||
|
||
<div>
|
||
<h3 className="mb-2 text-xs font-semibold uppercase tracking-wide text-ink-muted">Stellenverlauf</h3>
|
||
{stellenverlauf.length > 0 ? (
|
||
<div className="overflow-x-auto">
|
||
<table className="w-full text-sm">
|
||
<thead>
|
||
<tr className="border-b border-border text-left text-[11px] font-bold uppercase tracking-wider text-ink-muted">
|
||
<th className="py-2 pr-4">Von</th>
|
||
<th className="py-2 pr-4">Bis</th>
|
||
<th className="py-2 pr-4">Planstelle</th>
|
||
<th className="py-2 pr-4">Organisationseinheit</th>
|
||
<th className="py-2 pr-4">Kostenstelle</th>
|
||
<th className="py-2">Anlass</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{stellenverlauf.map((s) => (
|
||
<tr key={`${s.von}-${s.planstelle}`} className={`border-b border-border-subtle align-top ${s.laufend ? "font-semibold text-ink" : "text-ink-body"}`}>
|
||
<td className="whitespace-nowrap py-2 pr-4 tabular-nums">{fmtDate(s.von)}</td>
|
||
<td className="whitespace-nowrap py-2 pr-4 tabular-nums">{s.bis ? fmtDate(s.bis) : "–"}</td>
|
||
<td className="py-2 pr-4">
|
||
<span className="tabular-nums">{s.planstelle}</span>
|
||
<span className="font-normal text-ink-muted"> · {s.taetigkeit}</span>
|
||
{s.leitung && <span className="font-normal text-ink-muted"> (Leitung)</span>}
|
||
</td>
|
||
<td className="py-2 pr-4">{s.einheit ?? "–"}</td>
|
||
<td className="py-2 pr-4 tabular-nums" title={s.kostenstelle?.name}>
|
||
{s.kostenstelle ? s.kostenstelle.code : "–"}
|
||
</td>
|
||
<td className="py-2 font-normal">{s.anlass ?? "–"}</td>
|
||
</tr>
|
||
))}
|
||
</tbody>
|
||
</table>
|
||
{/* Bis ist der letzte Tag auf der Stelle; der nächste Abschnitt
|
||
beginnt am Tag danach. Fett steht die Besetzung zum Stichtag
|
||
der Akte. */}
|
||
</div>
|
||
) : (
|
||
<p className="text-sm text-ink-muted">Keine Planstellenbesetzung erfasst.</p>
|
||
)}
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|