From 8a76b3688fb779dc355b82e4383ab1fbd466066c Mon Sep 17 00:00:00 2001 From: Maximilian Stubhan Date: Fri, 14 Aug 2026 11:44:03 +0200 Subject: [PATCH] Show people surname first MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Employee names now read "Winkler, Hannah" wherever a person appears in a list, a table, a heading or a tree node. That is the order a personnel list is kept in, it is the order people are looked up in, and it finally matches the sorting — the employee list has always been ordered by surname, which made an alphabetical page look unsorted. The name was being assembled inline in about twenty places. A rename that catches half of them is worse than none, so it now goes through fmtName in lib/format.ts and every display site calls it. Sentences keep the natural order: "Hannah Winkler wurde versetzt" reads like German, "Winkler, Hannah wurde versetzt" reads like a form. So the toasts are unchanged and only labels moved. Two things the change would have quietly broken: The org chart's own filter matched against "first last". It now matches either order, with or without the comma, so typing what you see works and so does typing what you remember. The print model sorted by the last word of the composed name, which happened to be the surname and is now the first name — every printed unit would have come out sorted by first name. It sorts on the surname field itself now, which is what it meant all along. Co-Authored-By: Claude Opus 5 --- app/(app)/employees/page.tsx | 4 +-- app/(app)/page.tsx | 10 +++--- app/api/export/employees/route.ts | 4 +-- components/employees/panels/KarenzPanel.tsx | 4 +-- components/employees/panels/PromotePanel.tsx | 3 +- components/employees/panels/RehirePanel.tsx | 4 +-- .../employees/panels/TerminatePanel.tsx | 3 +- components/employees/panels/TransferPanel.tsx | 3 +- components/employees/tabs/OrganisationTab.tsx | 7 ++-- components/orgchart/EmployeeTree.tsx | 18 +++++++--- components/orgchart/PositionTree.tsx | 5 +-- lib/format.ts | 25 ++++++++++++-- lib/notes.ts | 3 +- lib/orgchart-print.ts | 17 ++++++++-- lib/positions.ts | 4 +-- lib/reports.ts | 6 ++-- tests/components/PrintChart.test.tsx | 8 ++--- tests/unit/format.test.ts | 34 ++++++++++++++++++- 18 files changed, 120 insertions(+), 42 deletions(-) diff --git a/app/(app)/employees/page.tsx b/app/(app)/employees/page.tsx index ab4d4dd..d490a34 100644 --- a/app/(app)/employees/page.tsx +++ b/app/(app)/employees/page.tsx @@ -9,7 +9,7 @@ import { currentUserId } from "@/lib/auth/session"; import { sql, withUser } from "@/lib/db"; import { istPersonalnummer, suchMuster } from "@/lib/employee-search"; import { derivedStatusFilter } from "@/lib/employee-status-filter"; -import { fmtDate, todayIso } from "@/lib/format"; +import { fmtDate, fmtName, todayIso } from "@/lib/format"; import { breadcrumbLabel, divisionOf, loadOrgMaps, subtreeOf, unitOf } from "@/lib/org"; import { loadPlacements } from "@/lib/placement"; import type { EmploymentStatus } from "@/lib/supabase/types"; @@ -240,7 +240,7 @@ export default async function EmployeesPage({ searchParams }: EmployeesPageProps
- {e.first_name} {e.last_name} + {fmtName(e.first_name, e.last_name)}
{placement?.jobTitle ?? e.job_title}
diff --git a/app/(app)/page.tsx b/app/(app)/page.tsx index 55936ee..37d9e54 100644 --- a/app/(app)/page.tsx +++ b/app/(app)/page.tsx @@ -3,7 +3,7 @@ import Link from "next/link"; import { DraftsCard } from "@/components/dashboard/DraftsCard"; import { Card, CARD_CLASS, CardTitle } from "@/components/ui/Card"; import { actionBadgeStyle } from "@/lib/colors"; -import { addDaysIso, fmtDate, todayIso } from "@/lib/format"; +import { addDaysIso, fmtDate, fmtName, todayIso } from "@/lib/format"; import { divisionOf, loadOrgMaps } from "@/lib/org"; import { loadPlacements } from "@/lib/placement"; import { loadOpenPositions } from "@/lib/positions"; @@ -205,19 +205,19 @@ export default async function DashboardPage() { const upcoming: UpcomingItem[] = [ ...(upcomingHires).map((e) => ({ id: e.id, - label: `${e.first_name} ${e.last_name}`, + label: fmtName(e.first_name, e.last_name), date: e.entry_date, kind: "hire" as const, })), ...(upcomingExits).map((e) => ({ id: e.id, - label: `${e.first_name} ${e.last_name}`, + label: fmtName(e.first_name, e.last_name), date: e.exit_date!, kind: "exit" as const, })), ...(upcomingReturns).map((e) => ({ id: e.id, - label: `${e.first_name} ${e.last_name}`, + label: fmtName(e.first_name, e.last_name), date: e.karenz_return_date!, kind: "return" as const, })), @@ -338,7 +338,7 @@ export default async function DashboardPage() {
- {h.first_name && h.last_name ? `${h.first_name} ${h.last_name}` : "Unbekannt"} + {h.first_name && h.last_name ? fmtName(h.first_name, h.last_name) : "Unbekannt"} {h.event_type} diff --git a/app/api/export/employees/route.ts b/app/api/export/employees/route.ts index 8c32f88..2e779d3 100644 --- a/app/api/export/employees/route.ts +++ b/app/api/export/employees/route.ts @@ -1,7 +1,7 @@ import { NextResponse, type NextRequest } from "next/server"; import { statusLabel } from "@/lib/absence"; import { exportFilename, exportResponseHeaders, toCsv, toXlsx, type ExportColumn } from "@/lib/export"; -import { todayIso } from "@/lib/format"; +import { fmtName, todayIso } from "@/lib/format"; import { subtreeOf } from "@/lib/org"; import { loadPlacements, loadReportingLineMap } from "@/lib/placement"; import { LEERE_CRITERIA, parseCriteria, passtImSpeicher } from "@/lib/report-criteria"; @@ -76,7 +76,7 @@ export async function GET(request: NextRequest) { } ); - const managerName = new Map(allEmployees.map((e) => [e.id, `${e.first_name} ${e.last_name}`])); + const managerName = new Map(allEmployees.map((e) => [e.id, fmtName(e.first_name, e.last_name)])); // Der Einheitenfilter meint den ganzen Teilbaum — sonst enthielte ein // Export für "Produktion" nur die Bereichsleitung. const allowedUnits = filters.division ? new Set(subtreeOf(orgMaps, filters.division)) : null; diff --git a/components/employees/panels/KarenzPanel.tsx b/components/employees/panels/KarenzPanel.tsx index 3522ac2..6eb9d7f 100644 --- a/components/employees/panels/KarenzPanel.tsx +++ b/components/employees/panels/KarenzPanel.tsx @@ -9,7 +9,7 @@ import { SegmentedControl } from "@/components/ui/SegmentedControl"; import { SlideOver } from "@/components/ui/SlideOver"; import { useToast } from "@/components/ui/Toast"; import { ABSENCE_TYPES, absenceLabel } from "@/lib/absence"; -import { fmtDate } from "@/lib/format"; +import { fmtDate, fmtName } from "@/lib/format"; import type { Database } from "@/lib/supabase/types"; type EmployeeRow = Database["public"]["Tables"]["employees"]["Row"]; @@ -127,7 +127,7 @@ export function KarenzPanel({ open, onClose, employee }: { open: boolean; onClos open={open} onClose={onClose} title={isOnKarenz ? "Langzeitabwesenheit verwalten" : "Langzeitabwesenheit erfassen"} - subtitle={`${employee.first_name} ${employee.last_name} · ${employee.job_title}`} + subtitle={`${fmtName(employee.first_name, employee.last_name)} · ${employee.job_title}`} footer={ <>