Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/components/screens/hr/HrLeavePage.tsx
T

283 lines
11 KiB
TypeScript
Raw 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) — leave/vacation screen composed from ~/ui (D-HR
// "Urlaub", archetype A2 + A4/A5). Pure presentational: URL-driven tabs (own /
// approvals / team); new request + reply + clarify run through injected actions
// (route owns the fetcher). Overlap conflicts surface as an inline warning. Final
// Subframe optics = tracked design-nachzug.
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { FeatherCalendar, FeatherPlus } from "@subframe/core";
import type { HrLeaveApproverVM, HrLeaveOwnVM } from "@hivegrid/view-models";
import type { FormDefinition } from "@hivegrid/form-widget";
import { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageShell } from "../shared/PageShell";
import { Alert } from "~/ui/components/Alert";
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 { TextArea } from "~/ui/components/TextArea";
import { AppLink } from "~/components/app/AppLink";
import {
InternalFormRenderer,
type InternalFormValues,
} from "~/modules/forms/internal/InternalFormRenderer";
export type HrLeaveTab = "own" | "approvals" | "team";
export type HrLeaveTeamAbsence = { id: string; employeeLabel: string; source: string; kind: string; startIso: string; endIso: string };
export type HrLeaveActions = {
onSubmit: (values: InternalFormValues) => void;
onWithdraw: (requestId: string) => void;
onReply: (requestId: string, reply: string) => void;
onApprove: (requestId: string) => void;
onReject: (requestId: string) => void;
onClarify: (requestId: string, question: string) => void;
};
export type HrLeavePageProps = {
tab: HrLeaveTab;
canApprove: boolean;
ownVm: HrLeaveOwnVM;
approverVm: HrLeaveApproverVM;
team: readonly HrLeaveTeamAbsence[];
formDefinition: FormDefinition;
tabHref: (tab: HrLeaveTab) => string;
submitting: boolean;
actions: HrLeaveActions;
};
type DialogState =
| { type: "new" }
| { type: "reply"; requestId: string }
| { type: "clarify"; requestId: string }
| null;
export function HrLeavePage({ tab, canApprove, ownVm, approverVm, team, formDefinition, tabHref, submitting, actions }: HrLeavePageProps) {
const { t } = useTranslation();
const [dialog, setDialog] = useState<DialogState>(null);
const [text, setText] = useState("");
const tabs: HrLeaveTab[] = canApprove ? ["own", "approvals", "team"] : ["own", "team"];
return (
<PageShell uiId="ui.hr.leave">
<PageHeader
icon={<FeatherCalendar className={PAGE_HEADER_ICON_CLASS} />}
title={t("hr.leave.title")}
subtitle={t("hr.leave.subtitle")}
actions={
tab === "own" && ownVm.data?.canCreate ? (
<Button icon={<FeatherPlus />} onClick={() => setDialog({ type: "new" })} data-ui-id="ui.hr.leave.new">
{t("hr.leave.action.new")}
</Button>
) : undefined
}
/>
<PageBody>
<div data-ui-id="ui.hr.leave.tabs">
<Tabs>
{tabs.map((entry) => (
<AppLink key={entry} href={tabHref(entry)} className="contents no-underline">
<Tabs.Item active={tab === entry}>{t(`hr.leave.tab.${entry === "approvals" ? "approvals" : entry}`)}</Tabs.Item>
</AppLink>
))}
</Tabs>
</div>
{tab === "own" ? (
<OwnList vm={ownVm} submitting={submitting} onWithdraw={actions.onWithdraw} onReply={(id) => { setText(""); setDialog({ type: "reply", requestId: id }); }} />
) : null}
{tab === "approvals" ? (
<ApproverList
vm={approverVm}
submitting={submitting}
onApprove={actions.onApprove}
onReject={actions.onReject}
onClarify={(id) => { setText(""); setDialog({ type: "clarify", requestId: id }); }}
/>
) : null}
{tab === "team" ? <TeamList team={team} /> : null}
{/* New request dialog */}
<Dialog open={dialog?.type === "new"} onOpenChange={(open) => !open && setDialog(null)}>
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.leave.newDialog">
<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.leave.action.new")}</span>
<InternalFormRenderer
definition={formDefinition}
submitting={submitting}
uiId="ui.hr.leave.m05"
onCancel={() => setDialog(null)}
onSubmit={(values) => {
actions.onSubmit(values);
setDialog(null);
}}
/>
</div>
</Dialog.Content>
</Dialog>
{/* Reply / clarify text dialog */}
<Dialog open={dialog?.type === "reply" || dialog?.type === "clarify"} onOpenChange={(open) => !open && setDialog(null)}>
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.leave.textDialog">
<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 === "reply" ? t("hr.leave.action.reply") : t("hr.leave.action.clarify")}
</span>
<TextArea label={dialog?.type === "reply" ? t("hr.leave.field.reply") : t("hr.leave.field.question")} showLabel className="w-full">
<TextArea.Input value={text} onChange={(e) => setText(e.target.value)} />
</TextArea>
<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 === "reply") actions.onReply(dialog.requestId, text);
if (dialog?.type === "clarify") actions.onClarify(dialog.requestId, text);
setDialog(null);
}}
>
{t("hr.action.confirm")}
</Button>
</div>
</div>
</Dialog.Content>
</Dialog>
</PageBody>
</PageShell>
);
}
function OwnList({ vm, submitting, onWithdraw, onReply }: { vm: HrLeaveOwnVM; submitting: boolean; onWithdraw: (id: string) => void; onReply: (id: string) => void }) {
const { t } = useTranslation();
if (vm.status !== "ready" || !vm.data) return null;
const { rows } = vm.data;
if (rows.length === 0) {
return (
<div data-ui-id="ui.hr.leave.own.empty">
<EmptyState title={t("hr.leave.own.empty.headline")} body={t("hr.leave.own.empty.body")} />
</div>
);
}
return (
<div className="flex w-full flex-col gap-3" data-ui-id="ui.hr.leave.own.list">
{rows.map((row) => (
<Card key={row.id} 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">{t(row.kindLabelKey)}</span>
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
{row.startDateIso} – {row.endDateIso}
</span>
</div>
<div className="flex items-center gap-2">
<BadgeFeedback farbe="subtle-neutral" size="small">
{t(row.statusLabelKey)}
</BadgeFeedback>
{row.canReply ? (
<Button variant="tertiary" size="small" onClick={() => onReply(row.id)}>
{t("hr.leave.action.reply")}
</Button>
) : null}
{row.canWithdraw ? (
<Button variant="tertiary" size="small" loading={submitting} onClick={() => onWithdraw(row.id)}>
{t("hr.leave.action.withdraw")}
</Button>
) : null}
</div>
</div>
</Card>
))}
</div>
);
}
function ApproverList({
vm,
submitting,
onApprove,
onReject,
onClarify,
}: {
vm: HrLeaveApproverVM;
submitting: boolean;
onApprove: (id: string) => void;
onReject: (id: string) => void;
onClarify: (id: string) => void;
}) {
const { t } = useTranslation();
if (vm.status !== "ready" || !vm.data) return null;
const { rows, conflictHintKey } = vm.data;
if (rows.length === 0) {
return (
<div data-ui-id="ui.hr.leave.approvals.empty">
<EmptyState title={t("hr.leave.approver.empty.headline")} body={t("hr.leave.approver.empty.body")} />
</div>
);
}
return (
<div className="flex w-full flex-col gap-3" data-ui-id="ui.hr.leave.approvals.list">
{rows.map((row) => (
<Card key={row.id} data-row-id={row.id} data-conflict={row.hasConflict}>
<div className="flex w-full flex-col gap-3">
<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.employeeLabel}</span>
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
{t(row.kindLabelKey)} · {row.startDateIso} – {row.endDateIso}
</span>
</div>
<div className="flex items-center gap-2">
<Button variant="tertiary" size="small" onClick={() => onClarify(row.id)}>
{t("hr.leave.action.clarify")}
</Button>
<Button variant="destructive" size="small" loading={submitting} onClick={() => onReject(row.id)}>
{t("hr.leave.action.reject")}
</Button>
<Button size="small" loading={submitting} onClick={() => onApprove(row.id)}>
{t("hr.leave.action.approve")}
</Button>
</div>
</div>
{row.hasConflict ? (
<Alert variant="warning" title={t(conflictHintKey, { count: row.conflictCount })} data-ui-id="ui.hr.leave.conflict" />
) : null}
</div>
</Card>
))}
</div>
);
}
function TeamList({ team }: { team: readonly HrLeaveTeamAbsence[] }) {
const { t } = useTranslation();
if (team.length === 0) {
return (
<div data-ui-id="ui.hr.leave.team.empty">
<EmptyState title={t("hr.leave.team.empty.headline")} body={t("hr.leave.team.empty.body")} />
</div>
);
}
return (
<div className="flex w-full flex-col gap-2" data-ui-id="ui.hr.leave.team.list">
{team.map((entry) => (
<Card key={`${entry.source}-${entry.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">{entry.employeeLabel}</span>
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
{t(`hr.leave.absence.${entry.source}`)} · {entry.startIso} – {entry.endIso}
</span>
</div>
</Card>
))}
</div>
);
}