216 lines
10 KiB
TypeScript
216 lines
10 KiB
TypeScript
// AK-P17b Interim-UI (AD-28) — payslip administration composed from ~/ui (D-HR
|
|
// "Lohnabrechnungen verwalten", archetype A2 + A4). Pure presentational: bulk
|
|
// auto-match preview (hard/soft/none confidence) with a per-row confirm, plus the
|
|
// existing-payslips list. Match/confirm run through injected actions (route owns
|
|
// the fetcher). Final Subframe optics = tracked design-nachzug.
|
|
|
|
import { useState } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
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 { EmptyState } from "~/ui/components/EmptyState";
|
|
import { Select } from "~/ui/components/Select";
|
|
import { Table } from "~/ui/components/Table";
|
|
import { TextInput } from "~/ui/components/TextInput";
|
|
|
|
export type PayslipPreviewRow = {
|
|
fileId: string;
|
|
fileName: string;
|
|
confidence: string;
|
|
confidenceKey: string;
|
|
confidenceTone: string;
|
|
employeeUserId: string | null;
|
|
employeeLabel: string | null;
|
|
};
|
|
|
|
export type PayslipAdminRow = { id: string; employeeLabel: string; periodLabel: string; isRead: boolean };
|
|
|
|
export type PayslipMemberOption = {
|
|
userId: string;
|
|
displayName: string;
|
|
team: string | null;
|
|
roleNames: readonly string[];
|
|
};
|
|
|
|
export type HrAdminPayslipsActions = {
|
|
onMatch: (input: { periodYear: string; periodMonth: string; files: readonly File[] }) => void;
|
|
onConfirm: (input: { file: File; employeeUserId: string; periodYear: string; periodMonth: string }) => void;
|
|
};
|
|
|
|
export type HrAdminPayslipsPageProps = {
|
|
rows: readonly PayslipAdminRow[];
|
|
preview: readonly PayslipPreviewRow[];
|
|
memberOptions: readonly PayslipMemberOption[];
|
|
period: { year: string; month: string };
|
|
submitting: boolean;
|
|
errorKey: string | null;
|
|
feedbackKey: string | null;
|
|
actions: HrAdminPayslipsActions;
|
|
};
|
|
|
|
function toneFarbe(tone: string): "subtle-positive" | "subtle-warning" | "subtle-neutral" {
|
|
if (tone === "success") return "subtle-positive";
|
|
if (tone === "warning") return "subtle-warning";
|
|
return "subtle-neutral";
|
|
}
|
|
|
|
export function HrAdminPayslipsPage({ rows, preview, memberOptions, period, submitting, errorKey, feedbackKey, actions }: HrAdminPayslipsPageProps) {
|
|
const { t } = useTranslation();
|
|
const [year, setYear] = useState("");
|
|
const [month, setMonth] = useState("");
|
|
const [files, setFiles] = useState<File[]>([]);
|
|
const [matchedFiles, setMatchedFiles] = useState<File[]>([]);
|
|
const [assignees, setAssignees] = useState<Record<string, string>>({});
|
|
|
|
return (
|
|
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.admin.payslips">
|
|
<div className="flex flex-col gap-0">
|
|
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("hr.payslips.admin.title")}</span>
|
|
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">{t("hr.payslips.admin.subtitle")}</span>
|
|
</div>
|
|
|
|
{/* Bulk auto-match */}
|
|
<Card>
|
|
<div className="flex w-full flex-col gap-4" data-ui-id="ui.hr.admin.payslips.match">
|
|
<div className="flex flex-wrap gap-4">
|
|
<TextInput label={t("hr.payslips.field.year")} showLabel>
|
|
<TextInput.Input type="number" value={year} onChange={(e) => setYear(e.target.value)} />
|
|
</TextInput>
|
|
<TextInput label={t("hr.payslips.field.month")} showLabel>
|
|
<TextInput.Input type="number" value={month} onChange={(e) => setMonth(e.target.value)} />
|
|
</TextInput>
|
|
</div>
|
|
<label className="flex flex-col gap-1">
|
|
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary">{t("hr.payslips.field.filesHint")}</span>
|
|
<input
|
|
type="file"
|
|
accept="application/pdf,.pdf"
|
|
multiple
|
|
onChange={(event) => setFiles(Array.from(event.target.files ?? []))}
|
|
className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary file:mr-3 file:rounded-[4px] file:border file:border-solid file:border-border-default file:bg-transparent file:px-3 file:py-1.5 file:text-text-neutral-primary"
|
|
data-ui-id="ui.hr.admin.payslips.files"
|
|
/>
|
|
</label>
|
|
{files.length > 0 ? (
|
|
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary" data-ui-id="ui.hr.admin.payslips.files.selected">
|
|
{t("hr.payslips.upload.selected", { count: files.length })}
|
|
</span>
|
|
) : null}
|
|
{errorKey ? <Alert variant="error" description={t(errorKey)} notDismissible data-ui-id="ui.hr.admin.payslips.error" /> : null}
|
|
{submitting ? (
|
|
<Alert variant="information" description={t("hr.payslips.upload.checking")} notDismissible data-ui-id="ui.hr.admin.payslips.loading" />
|
|
) : null}
|
|
{!submitting && feedbackKey ? (
|
|
<Alert variant="success" description={t(feedbackKey)} notDismissible data-ui-id="ui.hr.admin.payslips.success" />
|
|
) : null}
|
|
<div className="flex justify-end">
|
|
<Button
|
|
variant="secondary"
|
|
loading={submitting}
|
|
disabled={!year.trim() || !month.trim() || files.length === 0}
|
|
onClick={() => {
|
|
setMatchedFiles(files);
|
|
actions.onMatch({ periodYear: year, periodMonth: month, files });
|
|
}}
|
|
data-ui-id="ui.hr.admin.payslips.match.submit"
|
|
>
|
|
{t("hr.payslips.action.match")}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</Card>
|
|
|
|
{preview.length > 0 ? (
|
|
<div className="flex w-full flex-col gap-3" data-ui-id="ui.hr.admin.payslips.preview">
|
|
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t("hr.payslips.match.title")}</span>
|
|
{preview.map((row) => (
|
|
<Card key={row.fileId} data-confidence={row.confidence}>
|
|
<div className="flex w-full flex-col gap-3">
|
|
<div className="flex items-center justify-between gap-3">
|
|
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{row.fileName}</span>
|
|
<BadgeFeedback farbe={toneFarbe(row.confidenceTone)} size="small">
|
|
{t(row.confidenceKey)}
|
|
</BadgeFeedback>
|
|
</div>
|
|
<div className="flex items-end gap-2 mobile:flex-col mobile:items-stretch">
|
|
<Select
|
|
label={t("hr.payslips.field.employee")}
|
|
showLabel
|
|
triggerAriaLabel={t("hr.payslips.field.employee")}
|
|
value={assignees[row.fileId] ?? row.employeeUserId ?? undefined}
|
|
placeholder={t("hr.payslips.field.employeePlaceholder")}
|
|
onValueChange={(employeeUserId: string) => setAssignees((current) => ({ ...current, [row.fileId]: employeeUserId }))}
|
|
className="max-w-none grow"
|
|
>
|
|
{memberOptions.map((member) => (
|
|
<Select.Item key={member.userId} value={member.userId}>
|
|
{member.displayName} · {member.team ?? t("hr.picker.noTeam")} · {member.roleNames.join(", ") || t("hr.picker.noRole")}
|
|
</Select.Item>
|
|
))}
|
|
</Select>
|
|
<Button
|
|
loading={submitting}
|
|
disabled={!(assignees[row.fileId] ?? row.employeeUserId) || !matchedFiles[Number(row.fileId)]}
|
|
onClick={() => {
|
|
const file = matchedFiles[Number(row.fileId)];
|
|
if (!file) return;
|
|
actions.onConfirm({
|
|
file,
|
|
employeeUserId: assignees[row.fileId] ?? row.employeeUserId ?? "",
|
|
periodYear: period.year,
|
|
periodMonth: period.month,
|
|
});
|
|
}}
|
|
>
|
|
{t("hr.payslips.action.assign")}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</Card>
|
|
))}
|
|
</div>
|
|
) : null}
|
|
|
|
<div className="flex w-full flex-col gap-2">
|
|
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t("hr.payslips.admin.existing")}</span>
|
|
{rows.length === 0 ? (
|
|
<div data-ui-id="ui.hr.admin.payslips.empty">
|
|
<EmptyState title={t("hr.payslips.admin.empty.headline")} body={t("hr.payslips.admin.empty.body")} />
|
|
</div>
|
|
) : (
|
|
<div className="w-full overflow-x-auto">
|
|
<Table
|
|
data-ui-id="ui.hr.admin.payslips.list"
|
|
header={
|
|
<Table.HeaderRow>
|
|
<Table.HeaderCell>{t("hr.payslips.column.employee")}</Table.HeaderCell>
|
|
<Table.HeaderCell>{t("hr.payslips.column.period")}</Table.HeaderCell>
|
|
<Table.HeaderCell>{t("hr.payslips.column.status")}</Table.HeaderCell>
|
|
</Table.HeaderRow>
|
|
}
|
|
>
|
|
{rows.map((row) => (
|
|
<Table.Row key={row.id} data-row-id={row.id}>
|
|
<Table.Cell>
|
|
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">{row.employeeLabel}</span>
|
|
</Table.Cell>
|
|
<Table.Cell>
|
|
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">{row.periodLabel}</span>
|
|
</Table.Cell>
|
|
<Table.Cell>
|
|
<BadgeFeedback farbe={row.isRead ? "subtle-positive" : "subtle-warning"} size="small">
|
|
{row.isRead ? t("hr.payslips.read") : t("hr.payslips.unread")}
|
|
</BadgeFeedback>
|
|
</Table.Cell>
|
|
</Table.Row>
|
|
))}
|
|
</Table>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|