Files
2026-07-08 16:15:37 +02:00

284 lines
12 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// AK-P17b Interim-UI (AD-28) — sick-leave screen composed from ~/ui (D-HR "Krank",
// archetype A2 + A4). Pure presentational: URL-driven tabs (own / office). The AU
// certificate is sensitive — never rendered; a reveal action decrypts + opens it
// on demand (route owns the fetch/open). Report / attach / close run through
// injected actions. Final Subframe optics = tracked design-nachzug.
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { FeatherPlus } from "@subframe/core";
import type { HrSickLeaveOfficeVM, HrSickLeaveOwnVM, HrSickLeaveRow } from "@hivegrid/view-models";
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
import { Button } from "~/ui/components/Button";
import { Card } from "~/ui/components/Card";
import { Dialog } from "~/ui/components/Dialog";
import { EmptyState } from "~/ui/components/EmptyState";
import { Tabs } from "~/ui/components/Tabs";
import { TextInput } from "~/ui/components/TextInput";
import { DateField } from "~/components/screens/tasks/DateField";
export type HrSickTab = "own" | "office";
export type HrSickActions = {
onReport: (input: { startDate: string; expectedReturnDate: string }) => void;
onReportFor: (input: { employeeUserId: string; startDate: string }) => void;
onAttach: (reportId: string, certificateFileId: string) => void;
onRevealCertificate: (reportId: string) => void;
onClose: (reportId: string, returnDate: string) => void;
};
export type HrSickPageProps = {
tab: HrSickTab;
canManage: boolean;
ownVm: HrSickLeaveOwnVM;
officeVm: HrSickLeaveOfficeVM;
tabHref: (tab: HrSickTab) => string;
submitting: boolean;
actions: HrSickActions;
};
type DialogState =
| { type: "report" }
| { type: "reportFor" }
| { type: "attach"; reportId: string }
| { type: "close"; reportId: string }
| null;
function readDate(el: HTMLElement | null, name: string): string {
return el?.querySelector<HTMLInputElement>(`input[name='${name}']`)?.value ?? "";
}
export function HrSickPage({ tab, canManage, ownVm, officeVm, tabHref, submitting, actions }: HrSickPageProps) {
const { t } = useTranslation();
const [dialog, setDialog] = useState<DialogState>(null);
const [text, setText] = useState("");
const tabs: HrSickTab[] = canManage ? ["own", "office"] : ["own"];
const ownRows = ownVm.data?.rows ?? [];
const officeRows = officeVm.data?.rows ?? [];
return (
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.sick">
<div className="flex flex-wrap items-start justify-between gap-4">
<div className="flex flex-col gap-0">
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("hr.sick.title")}</span>
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">{t("hr.sick.subtitle")}</span>
</div>
{tab === "own" ? (
<Button icon={<FeatherPlus />} onClick={() => setDialog({ type: "report" })} data-ui-id="ui.hr.sick.report">
{t("hr.sick.action.report")}
</Button>
) : (
<Button icon={<FeatherPlus />} onClick={() => setDialog({ type: "reportFor" })} data-ui-id="ui.hr.sick.reportFor">
{t("hr.sick.action.reportFor")}
</Button>
)}
</div>
<div data-ui-id="ui.hr.sick.tabs">
<Tabs>
{tabs.map((entry) => (
<a key={entry} href={tabHref(entry)} className="contents no-underline">
<Tabs.Item active={tab === entry}>{t(`hr.sick.tab.${entry}`)}</Tabs.Item>
</a>
))}
</Tabs>
</div>
{tab === "own" ? (
ownRows.length === 0 ? (
<div data-ui-id="ui.hr.sick.own.empty">
<EmptyState title={t("hr.sick.own.empty.headline")} body={t("hr.sick.own.empty.body")} />
</div>
) : (
<div className="flex w-full flex-col gap-3" data-ui-id="ui.hr.sick.own.list">
{ownRows.map((row) => (
<SickCard
key={row.id}
row={row}
submitting={submitting}
onReveal={() => actions.onRevealCertificate(row.id)}
onAttach={() => { setText(""); setDialog({ type: "attach", reportId: row.id }); }}
onClose={() => setDialog({ type: "close", reportId: row.id })}
/>
))}
</div>
)
) : null}
{tab === "office" ? (
officeRows.length === 0 ? (
<div data-ui-id="ui.hr.sick.office.empty">
<EmptyState title={t("hr.sick.office.empty.headline")} body={t("hr.sick.office.empty.body")} />
</div>
) : (
<div className="flex w-full flex-col gap-2" data-ui-id="ui.hr.sick.office.list">
{officeRows.map((row) => (
<Card key={row.id} data-row-id={row.id}>
<div className="flex w-full items-center justify-between gap-4">
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{row.employeeLabel}</span>
<div className="flex items-center gap-2">
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">{row.startDateIso}</span>
<BadgeFeedback farbe="subtle-neutral" size="small">
{t(row.statusLabelKey)}
</BadgeFeedback>
</div>
</div>
</Card>
))}
</div>
)
) : null}
{/* Report dialog (own or office) */}
<Dialog open={dialog?.type === "report" || dialog?.type === "reportFor"} onOpenChange={(open) => !open && setDialog(null)}>
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.sick.reportDialog">
<div className="flex w-full flex-col gap-6 p-2">
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">
{dialog?.type === "reportFor" ? t("hr.sick.action.reportFor") : t("hr.sick.action.report")}
</span>
<div className="flex w-full flex-col gap-4">
{dialog?.type === "reportFor" ? (
<TextInput label={t("hr.sick.field.employee")} showLabel fillContainer>
<TextInput.Input value={text} onChange={(e) => setText(e.target.value)} />
</TextInput>
) : null}
<div className="flex flex-wrap gap-4">
<DateField label={t("hr.sick.field.start")} name="startDate" />
{dialog?.type === "report" ? <DateField label={t("hr.sick.field.expectedReturn")} name="expectedReturnDate" /> : null}
</div>
</div>
<div className="flex justify-end gap-2">
<Button variant="neutral" onClick={() => setDialog(null)}>
{t("hr.action.cancel")}
</Button>
<Button
loading={submitting}
onClick={(event) => {
const el = (event.currentTarget as HTMLElement).closest("[data-ui-id='ui.hr.sick.reportDialog']");
const start = readDate(el as HTMLElement, "startDate");
if (!start) return;
if (dialog?.type === "reportFor") {
if (!text.trim()) return;
actions.onReportFor({ employeeUserId: text, startDate: start });
} else {
actions.onReport({ startDate: start, expectedReturnDate: readDate(el as HTMLElement, "expectedReturnDate") });
}
setDialog(null);
}}
data-ui-id="ui.hr.sick.reportDialog.submit"
>
{t("hr.action.confirm")}
</Button>
</div>
</div>
</Dialog.Content>
</Dialog>
{/* Attach certificate dialog */}
<Dialog open={dialog?.type === "attach"} onOpenChange={(open) => !open && setDialog(null)}>
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.sick.attachDialog">
<div className="flex w-full flex-col gap-6 p-2">
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("hr.sick.action.attachCertificate")}</span>
<TextInput label={t("hr.sick.field.certificateFileId")} showLabel fillContainer>
<TextInput.Input value={text} onChange={(e) => setText(e.target.value)} />
</TextInput>
<div className="flex justify-end gap-2">
<Button variant="neutral" onClick={() => setDialog(null)}>
{t("hr.action.cancel")}
</Button>
<Button
loading={submitting}
disabled={text.trim().length === 0}
onClick={() => {
if (dialog?.type === "attach") actions.onAttach(dialog.reportId, text);
setDialog(null);
}}
>
{t("hr.action.confirm")}
</Button>
</div>
</div>
</Dialog.Content>
</Dialog>
{/* Close dialog */}
<Dialog open={dialog?.type === "close"} onOpenChange={(open) => !open && setDialog(null)}>
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.sick.closeDialog">
<div className="flex w-full flex-col gap-6 p-2">
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("hr.sick.action.close")}</span>
<DateField label={t("hr.sick.field.returnDate")} name="returnDate" />
<div className="flex justify-end gap-2">
<Button variant="neutral" onClick={() => setDialog(null)}>
{t("hr.action.cancel")}
</Button>
<Button
loading={submitting}
onClick={(event) => {
const el = (event.currentTarget as HTMLElement).closest("[data-ui-id='ui.hr.sick.closeDialog']");
const ret = readDate(el as HTMLElement, "returnDate");
if (!ret || dialog?.type !== "close") return;
actions.onClose(dialog.reportId, ret);
setDialog(null);
}}
>
{t("hr.action.confirm")}
</Button>
</div>
</div>
</Dialog.Content>
</Dialog>
</div>
);
}
function SickCard({
row,
submitting,
onReveal,
onAttach,
onClose,
}: {
row: HrSickLeaveRow;
submitting: boolean;
onReveal: () => void;
onAttach: () => void;
onClose: () => void;
}) {
const { t } = useTranslation();
return (
<Card data-row-id={row.id}>
<div className="flex w-full items-center justify-between gap-4">
<div className="flex flex-col gap-1">
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
{row.startDateIso}
{row.returnDateIso ? ` – ${row.returnDateIso}` : ""}
</span>
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
{row.hasCertificate ? t("hr.sick.certificate.present") : t("hr.sick.certificate.missing")}
</span>
</div>
<div className="flex items-center gap-2">
<BadgeFeedback farbe="subtle-neutral" size="small">
{t(row.statusLabelKey)}
</BadgeFeedback>
{row.hasCertificate ? (
<Button variant="tertiary" size="small" loading={submitting} onClick={onReveal} data-ui-id="ui.hr.sick.reveal">
{t("hr.sick.action.revealCertificate")}
</Button>
) : (
<Button variant="tertiary" size="small" onClick={onAttach}>
{t("hr.sick.action.attachCertificate")}
</Button>
)}
{row.canClose ? (
<Button variant="tertiary" size="small" onClick={onClose}>
{t("hr.sick.action.close")}
</Button>
) : null}
</div>
</div>
</Card>
);
}