Org assignment history, mobile support, and a correctness pass
Data model - employee_assignments records org placement over time (valid_from/valid_to), written by a trigger on `employees` rather than inside each RPC: ~70 `update employees` statements spread over fifteen migrations mean per-call bookkeeping would miss paths today and again with every future RPC. A partial unique index enforces the one-open-interval invariant the trigger relies on when closing the current row. - The Organigramm gains a Stichtag (default today). Membership comes from entry/exit/karenz, past placement from the new history, future placement projected from pending_org_changes. Placements predating the migration are backfilled with today's values and flagged as such in the UI, since employee_history only ever stored free text and cannot be reconstructed. Correctness - Reports and exports silently truncated at PostgREST's 1000-row cap (db.max_rows); employee_history is already past it at ~800 staff. Every whole-table read now pages explicitly. - XLSX date cells were a day early: ExcelJS converts a Date to an Excel serial straight off getTime(), so a Date built at local midnight lands on the previous day's serial in any positive-offset zone. - Date handling is pinned to Europe/Vienna throughout, and date-only strings are formatted without a Date round-trip. The dashboard's YTD window was built by round-tripping a local Date through toISOString(), which shifted it a day early and dropped 31 December entirely. - Export routes parsed measure/group/split/eventType with unchecked `as` casts, so an unknown value reached column headers as `undefined` and the Content-Disposition filename. Parsed against the label maps now, with the filename slugged as a backstop. - toXlsx keyed columns by header text, silently dropping the second of any two columns sharing a name — split columns take their header from data. - The org chart tree walks had no cycle guard; nothing in the schema forbids a manager_id cycle, and one would hang the tab rather than misreport. - The login page reflected ?error= verbatim, letting anyone put arbitrary text on the real sign-in screen; messages are looked up by code now. - React Flow needs elementsSelectable on, or it sets pointer-events:none on the whole node and the expand control stops responding. UI - Mobile: the shell was unusable below lg — a fixed 236px margin pushed content off-screen with no mobile navigation at all. The sidebar is now a drawer, dvh replaces vh, safe-area insets are honoured, inputs are 16px so iOS stops zooming on focus, and form grids stack. - Org chart nodes redesigned: per-kind accent stripes and icons, vacant roles called out, expand control moved to the bottom edge carrying the child count. - Pagination is windowed; it previously rendered one link per page (54 for the employee list, unbounded for the audit log). - Positions page reduced to open positions with a single "Besetzen" action. - The employee Organisation tab links into the org chart focused on that person, reusing the chart's existing search-match highlighting. Also included, uncommitted until now - Dependants, HR notes, academic titles, split address fields, position validity and role/employment fields, with their migrations and UI. - Docker/compose deployment setup, data-model and security-review docs.
This commit is contained in:
@@ -1,14 +1,53 @@
|
||||
const dateFormatter = new Intl.DateTimeFormat("de-AT", {
|
||||
// This app stores dates as date-only strings ("YYYY-MM-DD") and timestamps as
|
||||
// timestamptz, and is used from a single timezone. Every conversion here is
|
||||
// pinned to Europe/Vienna rather than the runtime's zone: the server renders
|
||||
// in UTC (Docker/Vercel) while the browser renders in Vienna, so an unpinned
|
||||
// formatter produces a different day on each side — wrong dates for the user
|
||||
// near midnight, and a React hydration mismatch.
|
||||
const TIMEZONE = "Europe/Vienna";
|
||||
|
||||
const dateTimeFormatter = new Intl.DateTimeFormat("de-AT", {
|
||||
day: "2-digit",
|
||||
month: "2-digit",
|
||||
year: "numeric",
|
||||
timeZone: TIMEZONE,
|
||||
});
|
||||
|
||||
// en-CA formats as "YYYY-MM-DD", which is the shape the rest of the app and
|
||||
// the database speak.
|
||||
const isoFormatter = new Intl.DateTimeFormat("en-CA", {
|
||||
day: "2-digit",
|
||||
month: "2-digit",
|
||||
year: "numeric",
|
||||
timeZone: TIMEZONE,
|
||||
});
|
||||
|
||||
const DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/;
|
||||
|
||||
// Today in Vienna. Deliberately not new Date().toISOString().slice(0, 10):
|
||||
// that is the *UTC* date, which for part of every day is already tomorrow
|
||||
// relative to Austria.
|
||||
export function todayIso(): string {
|
||||
return isoFormatter.format(new Date());
|
||||
}
|
||||
|
||||
// Normalizes either input to a "YYYY-MM-DD" string. A date-only string is
|
||||
// returned as-is — parsing it into a Date first would anchor it to UTC
|
||||
// midnight and shift it in any negative-offset zone.
|
||||
export function toIsoDate(value: string | Date): string {
|
||||
if (typeof value === "string") return DATE_ONLY.test(value) ? value : isoFormatter.format(new Date(value));
|
||||
return isoFormatter.format(value);
|
||||
}
|
||||
|
||||
export function fmtDate(date: string | Date | null | undefined): string {
|
||||
if (!date) return "–";
|
||||
if (typeof date === "string" && DATE_ONLY.test(date)) {
|
||||
const [year, month, day] = date.split("-");
|
||||
return `${day}.${month}.${year}`;
|
||||
}
|
||||
const d = typeof date === "string" ? new Date(date) : date;
|
||||
if (Number.isNaN(d.getTime())) return "–";
|
||||
return dateFormatter.format(d);
|
||||
return dateTimeFormatter.format(d);
|
||||
}
|
||||
|
||||
export function initials(firstName: string, lastName: string): string {
|
||||
@@ -17,24 +56,37 @@ export function initials(firstName: string, lastName: string): string {
|
||||
return `${a}${b}`;
|
||||
}
|
||||
|
||||
// "Dr. Max Mustermann, MSc MBA" — prefix titles precede the name, suffix
|
||||
// titles follow after a comma, both space-joined in the stored order.
|
||||
export function fmtFullName(
|
||||
firstName: string,
|
||||
lastName: string,
|
||||
titlePrefix: string[] | null | undefined,
|
||||
titleSuffix: string[] | null | undefined
|
||||
): string {
|
||||
const prefix = titlePrefix && titlePrefix.length > 0 ? `${titlePrefix.join(" ")} ` : "";
|
||||
const suffix = titleSuffix && titleSuffix.length > 0 ? `, ${titleSuffix.join(" ")}` : "";
|
||||
return `${prefix}${firstName} ${lastName}${suffix}`;
|
||||
}
|
||||
|
||||
// Whole years between two ISO dates. Compares the "MM-DD" tails as strings,
|
||||
// which is exact and needs no Date arithmetic at all.
|
||||
export function yearsBetweenIso(from: string, to: string): number {
|
||||
const years = Number(to.slice(0, 4)) - Number(from.slice(0, 4));
|
||||
return to.slice(5) < from.slice(5) ? years - 1 : years;
|
||||
}
|
||||
|
||||
export function fmtAge(birthDate: string | Date): number {
|
||||
const d = typeof birthDate === "string" ? new Date(birthDate) : birthDate;
|
||||
const today = new Date();
|
||||
let age = today.getFullYear() - d.getFullYear();
|
||||
const hasHadBirthdayThisYear =
|
||||
today.getMonth() > d.getMonth() ||
|
||||
(today.getMonth() === d.getMonth() && today.getDate() >= d.getDate());
|
||||
if (!hasHadBirthdayThisYear) age -= 1;
|
||||
return age;
|
||||
return yearsBetweenIso(toIsoDate(birthDate), todayIso());
|
||||
}
|
||||
|
||||
export function tenure(entryDate: string | Date, endDate?: string | Date | null): string {
|
||||
const start = typeof entryDate === "string" ? new Date(entryDate) : entryDate;
|
||||
const end = endDate ? (typeof endDate === "string" ? new Date(endDate) : endDate) : new Date();
|
||||
const start = toIsoDate(entryDate);
|
||||
const end = endDate ? toIsoDate(endDate) : todayIso();
|
||||
|
||||
let years = end.getFullYear() - start.getFullYear();
|
||||
let months = end.getMonth() - start.getMonth();
|
||||
if (end.getDate() < start.getDate()) months -= 1;
|
||||
let years = Number(end.slice(0, 4)) - Number(start.slice(0, 4));
|
||||
let months = Number(end.slice(5, 7)) - Number(start.slice(5, 7));
|
||||
if (Number(end.slice(8, 10)) < Number(start.slice(8, 10))) months -= 1;
|
||||
if (months < 0) {
|
||||
years -= 1;
|
||||
months += 12;
|
||||
@@ -47,8 +99,16 @@ export function tenure(entryDate: string | Date, endDate?: string | Date | null)
|
||||
return yearPart || monthPart || "unter 1 Monat";
|
||||
}
|
||||
|
||||
export function daysBetween(a: string | Date, b: string | Date = new Date()): number {
|
||||
const start = typeof a === "string" ? new Date(a) : a;
|
||||
const end = typeof b === "string" ? new Date(b) : b;
|
||||
return Math.round((end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));
|
||||
// Anchored at UTC midnight on both sides so the difference is a whole number
|
||||
// of calendar days regardless of DST transitions in between.
|
||||
export function daysBetweenIso(from: string, to: string = todayIso()): number {
|
||||
const start = Date.parse(`${from}T00:00:00Z`);
|
||||
const end = Date.parse(`${to}T00:00:00Z`);
|
||||
return Math.round((end - start) / 86_400_000);
|
||||
}
|
||||
|
||||
export function addDaysIso(iso: string, days: number): string {
|
||||
const d = new Date(`${iso}T00:00:00Z`);
|
||||
d.setUTCDate(d.getUTCDate() + days);
|
||||
return d.toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user