123 lines
4.2 KiB
TypeScript
123 lines
4.2 KiB
TypeScript
import type { VMState } from "../index.js";
|
|
|
|
/**
|
|
* HR leave/vacation view-models (AK-P17b). Pure functions: the loader builds
|
|
* them once server-side from already-resolved rows (dates as ISO strings,
|
|
* employee display names resolved by the loader). No React, no Prisma, no app
|
|
* imports (DoD A.3). All static texts are i18n keys.
|
|
*/
|
|
|
|
export type HrLeaveStatus = "submitted" | "clarification" | "approved" | "rejected" | "withdrawn";
|
|
export type HrVacationRequestKind = "vacation" | "special_leave" | "unpaid_leave" | "overtime_compensation";
|
|
|
|
export interface HrLeaveOwnRow {
|
|
readonly id: string;
|
|
readonly kind: HrVacationRequestKind;
|
|
/** i18n key for the kind label, e.g. `hr.leave.kind.vacation`. */
|
|
readonly kindLabelKey: string;
|
|
readonly status: HrLeaveStatus;
|
|
/** i18n key for the status label, e.g. `hr.leave.status.approved`. */
|
|
readonly statusLabelKey: string;
|
|
readonly startDateIso: string;
|
|
readonly endDateIso: string;
|
|
readonly note: string | null;
|
|
readonly clarificationNote: string | null;
|
|
readonly decisionNote: string | null;
|
|
readonly detailHref: string;
|
|
/** Requester may withdraw while still open. */
|
|
readonly canWithdraw: boolean;
|
|
/** Requester must reply when the approver asked a question. */
|
|
readonly canReply: boolean;
|
|
}
|
|
|
|
export interface HrLeaveOwnData {
|
|
readonly rows: readonly HrLeaveOwnRow[];
|
|
readonly canCreate: boolean;
|
|
readonly newHref: string;
|
|
readonly emptyHeadlineKey: string;
|
|
readonly emptyBodyKey: string;
|
|
}
|
|
|
|
export type HrLeaveOwnVM = VMState<HrLeaveOwnData>;
|
|
|
|
export interface HrLeaveApproverRow {
|
|
readonly id: string;
|
|
readonly employeeLabel: string;
|
|
readonly kindLabelKey: string;
|
|
readonly statusLabelKey: string;
|
|
readonly startDateIso: string;
|
|
readonly endDateIso: string;
|
|
readonly note: string | null;
|
|
/** Number of OTHER approved absences overlapping this window. */
|
|
readonly conflictCount: number;
|
|
/** True when there is at least one overlapping approved absence. */
|
|
readonly hasConflict: boolean;
|
|
readonly detailHref: string;
|
|
}
|
|
|
|
export interface HrLeaveApproverData {
|
|
readonly rows: readonly HrLeaveApproverRow[];
|
|
readonly conflictHintKey: string;
|
|
readonly emptyHeadlineKey: string;
|
|
readonly emptyBodyKey: string;
|
|
}
|
|
|
|
export type HrLeaveApproverVM = VMState<HrLeaveApproverData>;
|
|
|
|
const OPEN_STATUSES: ReadonlySet<HrLeaveStatus> = new Set<HrLeaveStatus>(["submitted", "clarification"]);
|
|
|
|
export interface BuildHrLeaveOwnInput {
|
|
readonly rows: ReadonlyArray<Omit<HrLeaveOwnRow, "kindLabelKey" | "statusLabelKey" | "canWithdraw" | "canReply">>;
|
|
readonly canCreate: boolean;
|
|
readonly newHref: string;
|
|
}
|
|
|
|
export function buildHrLeaveOwnVM(input: BuildHrLeaveOwnInput): HrLeaveOwnVM {
|
|
const rows: HrLeaveOwnRow[] = input.rows.map((row) => ({
|
|
...row,
|
|
kindLabelKey: `hr.leave.kind.${row.kind}`,
|
|
statusLabelKey: `hr.leave.status.${row.status}`,
|
|
canWithdraw: OPEN_STATUSES.has(row.status),
|
|
canReply: row.status === "clarification",
|
|
}));
|
|
return {
|
|
status: "ready",
|
|
data: {
|
|
rows,
|
|
canCreate: input.canCreate,
|
|
newHref: input.newHref,
|
|
emptyHeadlineKey: "hr.leave.own.empty.headline",
|
|
emptyBodyKey: "hr.leave.own.empty.body",
|
|
},
|
|
};
|
|
}
|
|
|
|
/** Raw approver input row: carries `kind`/`status` for label mapping; the
|
|
* derived `kindLabelKey`/`statusLabelKey`/`hasConflict` are added by the builder. */
|
|
export interface HrLeaveApproverInputRow extends Omit<HrLeaveApproverRow, "kindLabelKey" | "statusLabelKey" | "hasConflict"> {
|
|
readonly kind: HrVacationRequestKind;
|
|
readonly status: HrLeaveStatus;
|
|
}
|
|
|
|
export interface BuildHrLeaveApproverInput {
|
|
readonly rows: readonly HrLeaveApproverInputRow[];
|
|
}
|
|
|
|
export function buildHrLeaveApproverVM(input: BuildHrLeaveApproverInput): HrLeaveApproverVM {
|
|
const rows: HrLeaveApproverRow[] = input.rows.map(({ kind, status, ...row }) => ({
|
|
...row,
|
|
kindLabelKey: `hr.leave.kind.${kind}`,
|
|
statusLabelKey: `hr.leave.status.${status}`,
|
|
hasConflict: row.conflictCount > 0,
|
|
}));
|
|
return {
|
|
status: "ready",
|
|
data: {
|
|
rows,
|
|
conflictHintKey: "hr.leave.approver.conflictHint",
|
|
emptyHeadlineKey: "hr.leave.approver.empty.headline",
|
|
emptyBodyKey: "hr.leave.approver.empty.body",
|
|
},
|
|
};
|
|
}
|