123 lines
4.1 KiB
TypeScript
123 lines
4.1 KiB
TypeScript
import type { VMState } from "../index.js";
|
|
|
|
/**
|
|
* HR request view-models (AK-P17b). Pure functions. Own list, approver list and
|
|
* the template picker. Mirrors the leave VM shape (status-derived action flags,
|
|
* kind/status → i18n keys). No React, no Prisma, no app imports.
|
|
*/
|
|
|
|
export type HrRequestKind = "expense" | "hardware" | "training" | "reference";
|
|
export type HrRequestStatus = "submitted" | "clarification" | "approved" | "rejected" | "withdrawn";
|
|
|
|
const OPEN: ReadonlySet<HrRequestStatus> = new Set<HrRequestStatus>(["submitted", "clarification"]);
|
|
|
|
export interface HrRequestRow {
|
|
readonly id: string;
|
|
readonly title: string;
|
|
readonly kind: HrRequestKind;
|
|
readonly kindLabelKey: string;
|
|
readonly status: HrRequestStatus;
|
|
readonly statusLabelKey: string;
|
|
readonly createdIso: string;
|
|
readonly detailHref: string;
|
|
readonly canWithdraw: boolean;
|
|
}
|
|
|
|
export interface HrRequestOwnData {
|
|
readonly rows: readonly HrRequestRow[];
|
|
readonly newHref: string;
|
|
readonly emptyHeadlineKey: string;
|
|
readonly emptyBodyKey: string;
|
|
}
|
|
|
|
export type HrRequestOwnVM = VMState<HrRequestOwnData>;
|
|
|
|
export interface HrRequestApproverRow {
|
|
readonly id: string;
|
|
readonly title: string;
|
|
readonly employeeLabel: string;
|
|
readonly kindLabelKey: string;
|
|
readonly statusLabelKey: string;
|
|
readonly createdIso: string;
|
|
readonly detailHref: string;
|
|
}
|
|
|
|
export interface HrRequestApproverData {
|
|
readonly rows: readonly HrRequestApproverRow[];
|
|
readonly emptyHeadlineKey: string;
|
|
readonly emptyBodyKey: string;
|
|
}
|
|
|
|
export type HrRequestApproverVM = VMState<HrRequestApproverData>;
|
|
|
|
export interface HrRequestTemplateRow {
|
|
readonly id: string;
|
|
readonly title: string;
|
|
readonly kind: HrRequestKind;
|
|
readonly kindLabelKey: string;
|
|
readonly description: string | null;
|
|
readonly isActive: boolean;
|
|
readonly editHref: string;
|
|
}
|
|
|
|
export interface HrRequestTemplateListData {
|
|
readonly rows: readonly HrRequestTemplateRow[];
|
|
readonly createHref: string;
|
|
readonly emptyHeadlineKey: string;
|
|
readonly emptyBodyKey: string;
|
|
}
|
|
|
|
export type HrRequestTemplateListVM = VMState<HrRequestTemplateListData>;
|
|
|
|
interface OwnInputRow {
|
|
readonly id: string;
|
|
readonly title: string;
|
|
readonly kind: HrRequestKind;
|
|
readonly status: HrRequestStatus;
|
|
readonly createdIso: string;
|
|
readonly detailHref: string;
|
|
}
|
|
|
|
export function buildHrRequestOwnVM(input: { rows: readonly OwnInputRow[]; newHref: string }): HrRequestOwnVM {
|
|
const rows: HrRequestRow[] = input.rows.map((row) => ({
|
|
...row,
|
|
kindLabelKey: `hr.requests.kind.${row.kind}`,
|
|
statusLabelKey: `hr.requests.status.${row.status}`,
|
|
canWithdraw: OPEN.has(row.status),
|
|
}));
|
|
return { status: "ready", data: { rows, newHref: input.newHref, emptyHeadlineKey: "hr.requests.own.empty.headline", emptyBodyKey: "hr.requests.own.empty.body" } };
|
|
}
|
|
|
|
interface ApproverInputRow {
|
|
readonly id: string;
|
|
readonly title: string;
|
|
readonly employeeLabel: string;
|
|
readonly kind: HrRequestKind;
|
|
readonly status: HrRequestStatus;
|
|
readonly createdIso: string;
|
|
readonly detailHref: string;
|
|
}
|
|
|
|
export function buildHrRequestApproverVM(input: { rows: readonly ApproverInputRow[] }): HrRequestApproverVM {
|
|
const rows: HrRequestApproverRow[] = input.rows.map(({ kind, status, ...row }) => ({
|
|
...row,
|
|
kindLabelKey: `hr.requests.kind.${kind}`,
|
|
statusLabelKey: `hr.requests.status.${status}`,
|
|
}));
|
|
return { status: "ready", data: { rows, emptyHeadlineKey: "hr.requests.approver.empty.headline", emptyBodyKey: "hr.requests.approver.empty.body" } };
|
|
}
|
|
|
|
interface TemplateInputRow {
|
|
readonly id: string;
|
|
readonly title: string;
|
|
readonly kind: HrRequestKind;
|
|
readonly description: string | null;
|
|
readonly isActive: boolean;
|
|
readonly editHref: string;
|
|
}
|
|
|
|
export function buildHrRequestTemplateListVM(input: { rows: readonly TemplateInputRow[]; createHref: string }): HrRequestTemplateListVM {
|
|
const rows: HrRequestTemplateRow[] = input.rows.map((row) => ({ ...row, kindLabelKey: `hr.requests.kind.${row.kind}` }));
|
|
return { status: "ready", data: { rows, createHref: input.createHref, emptyHeadlineKey: "hr.requests.templates.empty.headline", emptyBodyKey: "hr.requests.templates.empty.body" } };
|
|
}
|