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:
@@ -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,
|
||||
});
|
||||
|
||||
@@ -29,17 +29,24 @@ export function HireWizardProvider({
|
||||
const [open, setOpen] = useState(false);
|
||||
const [resumeDraft, setResumeDraft] = useState<HireDraft | null>(null);
|
||||
const [initialPositionId, setInitialPositionId] = useState<string | undefined>(undefined);
|
||||
// Forces HireWizard to remount fresh each time it's opened, so its
|
||||
// internal draft/step state is (re-)initialized directly from the current
|
||||
// resumeDraft/initialPositionId props at mount time — no reset-on-open
|
||||
// effect needed inside HireWizard itself.
|
||||
const [openKey, setOpenKey] = useState(0);
|
||||
|
||||
function openWizard(options?: OpenWizardOptions) {
|
||||
setResumeDraft(options?.draftId ? (drafts.find((d) => d.id === options.draftId) ?? null) : null);
|
||||
setInitialPositionId(options?.positionId);
|
||||
setOpen(true);
|
||||
setOpenKey((k) => k + 1);
|
||||
}
|
||||
|
||||
return (
|
||||
<HireWizardContext.Provider value={{ openWizard }}>
|
||||
{children}
|
||||
<HireWizard
|
||||
key={openKey}
|
||||
open={open}
|
||||
onClose={() => setOpen(false)}
|
||||
openPositions={openPositions}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { fmtDate, fmtEUR } from "@/lib/format";
|
||||
import { fmtDate } from "@/lib/format";
|
||||
import type { OpenPositionResolved } from "@/lib/positions";
|
||||
import type { HireDraftData } from "./types";
|
||||
|
||||
@@ -34,7 +34,6 @@ export function StepSummary({ draft, selectedPosition, locations }: StepSummaryP
|
||||
["Eintrittsdatum", fmtDate(draft.entryDate)],
|
||||
["Vertragsart", draft.contractType === "befristet" ? `befristet bis ${fmtDate(draft.contractEndDate)}` : "unbefristet"],
|
||||
["Beschäftigungsausmaß", `${draft.employmentType} (${draft.weeklyHours} h)`],
|
||||
["Bruttogehalt (14x/Jahr)", fmtEUR(Number(draft.salary))],
|
||||
["Paygrade", PAYGRADE_LABELS[draft.paygrade]],
|
||||
];
|
||||
|
||||
|
||||
@@ -72,10 +72,6 @@ export function StepVertrag({ draft, update }: { draft: HireDraftData; update: (
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label className="mb-1 block text-sm font-semibold text-ink">Bruttogehalt/Monat (14x)*</label>
|
||||
<input type="number" value={draft.salary} onChange={(e) => update({ salary: e.target.value })} className="w-full rounded border border-border px-3 py-2 text-sm" />
|
||||
</div>
|
||||
<div>
|
||||
<label className="mb-1 block text-sm font-semibold text-ink">Paygrade*</label>
|
||||
<select
|
||||
|
||||
@@ -19,7 +19,6 @@ export type HireDraftData = {
|
||||
contractEndDate: string;
|
||||
employmentType: EmploymentType;
|
||||
weeklyHours: string;
|
||||
salary: string;
|
||||
paygrade: PaygradeType;
|
||||
};
|
||||
|
||||
@@ -39,6 +38,5 @@ export const EMPTY_HIRE_DRAFT: HireDraftData = {
|
||||
contractEndDate: "",
|
||||
employmentType: "Vollzeit",
|
||||
weeklyHours: "38.5",
|
||||
salary: "",
|
||||
paygrade: "B",
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user