Consolidation pass: HR-only access, effective-dated mutations, data integrity guards, test suite

Reworks the app from a two-role (hr_admin/manager) model to a single
HR-only role gated by profiles.is_active, fixes transfer/promote/karenz/
reorg RPCs to actually defer future-dated changes via a new
pending_org_changes table instead of writing them immediately (applied
by a daily Vercel Cron route), makes reorg undo append-only instead of
deleting history, adds Karenz-return and history-date integrity guards,
deprecates the salary column, and adds explicit schema grants + perf
indexes needed to run against a fresh (non-hosted) Postgres instance.

Adds vitest unit + integration test suites (the latter against a real
local Supabase instance) covering all of the above, plus lint/typecheck/
build wiring (`npm run check`).
This commit is contained in:
2026-07-14 20:32:20 +02:00
parent 4299277af0
commit 901c5c426e
67 changed files with 4765 additions and 286 deletions

View File

@@ -1,6 +1,6 @@
"use client";
import { useEffect, useMemo, useState } from "react";
import { useMemo, useState } from "react";
import { useRouter } from "next/navigation";
import { hireEmployee } from "@/actions/employees";
import { deleteHireDraft, saveHireDraft } from "@/actions/hireDrafts";
@@ -27,24 +27,18 @@ type HireWizardProps = {
export function HireWizard({ open, onClose, openPositions, locations, resumeDraft, initialPositionId }: HireWizardProps) {
const { showToast } = useToast();
const router = useRouter();
const [step, setStep] = useState(0);
const [draft, setDraft] = useState<HireDraftData>(EMPTY_HIRE_DRAFT);
const [draftId, setDraftId] = useState<string | undefined>(undefined);
// The parent remounts this component (via a changing `key`) each time it's
// freshly opened, so these initializers — reading resumeDraft/
// initialPositionId once at mount — are the reset, no effect needed.
const [step, setStep] = useState(() => resumeDraft?.step ?? 0);
const [draft, setDraft] = useState<HireDraftData>(() =>
resumeDraft
? { ...EMPTY_HIRE_DRAFT, ...(resumeDraft.payload as Partial<HireDraftData>) }
: { ...EMPTY_HIRE_DRAFT, positionId: initialPositionId ?? "" }
);
const [draftId] = useState<string | undefined>(() => resumeDraft?.id);
const [submitting, setSubmitting] = useState(false);
useEffect(() => {
if (!open) return;
if (resumeDraft) {
setDraft({ ...EMPTY_HIRE_DRAFT, ...(resumeDraft.payload as Partial<HireDraftData>) });
setStep(resumeDraft.step);
setDraftId(resumeDraft.id);
} else {
setDraft({ ...EMPTY_HIRE_DRAFT, positionId: initialPositionId ?? "" });
setStep(0);
setDraftId(undefined);
}
}, [open, resumeDraft, initialPositionId]);
const selectedPosition = useMemo(
() => openPositions.find((p) => p.id === draft.positionId) ?? null,
[openPositions, draft.positionId]
@@ -57,7 +51,7 @@ export function HireWizard({ open, onClose, openPositions, locations, resumeDraf
const stepValid = [
Boolean(draft.firstName && draft.lastName && draft.birthDate && draft.locationId),
Boolean(draft.positionId && draft.besetzung),
Boolean(draft.entryDate && draft.salary),
Boolean(draft.entryDate),
true,
][step];
@@ -89,7 +83,6 @@ export function HireWizard({ open, onClose, openPositions, locations, resumeDraf
contract_end_date: draft.contractType === "befristet" ? draft.contractEndDate : undefined,
employment_type: draft.employmentType,
weekly_hours: Number(draft.weeklyHours),
monthly_salary_gross: Number(draft.salary),
paygrade: draft.paygrade,
source: draft.besetzung,
});