171 lines
7.3 KiB
TypeScript
171 lines
7.3 KiB
TypeScript
// AK-P17a Interim-UI (AD-28) — locations screen composed from ~/ui (D-HR
|
|
// "Standorte", archetype A2 + A5 create modal). Pure presentational: renders the
|
|
// server-built HrLocationListVM; admin create/set-default/archive run through the
|
|
// injected actions (route owns the fetcher). The create form uses a real Dialog
|
|
// (DialogLayout -> Dialog -> Dialog.Content), never a Card fake. Final Subframe
|
|
// optics = tracked design-nachzug.
|
|
|
|
import { useState } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { AppLink } from "~/components/app/AppLink";
|
|
import { FeatherGlobe, FeatherPlus } from "@subframe/core";
|
|
import type { HrLocationListVM } from "@hivegrid/view-models";
|
|
import { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageShell } from "../shared/PageShell";
|
|
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
|
import { Button } from "~/ui/components/Button";
|
|
import { Checkbox } from "~/ui/components/Checkbox";
|
|
import { Dialog } from "~/ui/components/Dialog";
|
|
import { EmptyState } from "~/ui/components/EmptyState";
|
|
import { Table } from "~/ui/components/Table";
|
|
import { TextInput } from "~/ui/components/TextInput";
|
|
|
|
export type HrLocationsActions = {
|
|
onCreate: (input: { name: string; city: string; isDefault: boolean }) => void;
|
|
onSetDefault: (locationId: string) => void;
|
|
onArchive: (locationId: string) => void;
|
|
};
|
|
|
|
export type HrLocationsPageProps = {
|
|
vm: HrLocationListVM;
|
|
submitting: boolean;
|
|
actions: HrLocationsActions;
|
|
};
|
|
|
|
export function HrLocationsPage({ vm, submitting, actions }: HrLocationsPageProps) {
|
|
const { t } = useTranslation();
|
|
const [createOpen, setCreateOpen] = useState(false);
|
|
const [name, setName] = useState("");
|
|
const [city, setCity] = useState("");
|
|
const [isDefault, setIsDefault] = useState(false);
|
|
|
|
if (vm.status !== "ready" || !vm.data) {
|
|
return (
|
|
<PageShell uiId="ui.hr.locations">
|
|
<PageHeader
|
|
icon={<FeatherGlobe className={PAGE_HEADER_ICON_CLASS} />}
|
|
title={t("hr.locations.title")}
|
|
subtitle={t("hr.locations.subtitle")}
|
|
/>
|
|
<PageBody>{null}</PageBody>
|
|
</PageShell>
|
|
);
|
|
}
|
|
|
|
const { rows, canManage, emptyHeadlineKey, emptyBodyKey } = vm.data;
|
|
|
|
function submitCreate() {
|
|
actions.onCreate({ name, city, isDefault });
|
|
setCreateOpen(false);
|
|
setName("");
|
|
setCity("");
|
|
setIsDefault(false);
|
|
}
|
|
|
|
return (
|
|
<PageShell uiId="ui.hr.locations">
|
|
<PageHeader
|
|
icon={<FeatherGlobe className={PAGE_HEADER_ICON_CLASS} />}
|
|
title={t("hr.locations.title")}
|
|
subtitle={t("hr.locations.subtitle")}
|
|
actions={
|
|
canManage ? (
|
|
<Button icon={<FeatherPlus />} onClick={() => setCreateOpen(true)} data-ui-id="ui.hr.locations.new">
|
|
{t("hr.locations.action.new")}
|
|
</Button>
|
|
) : undefined
|
|
}
|
|
/>
|
|
<PageBody>
|
|
{rows.length === 0 ? (
|
|
<div data-ui-id="ui.hr.locations.empty">
|
|
<EmptyState title={t(emptyHeadlineKey)} body={t(emptyBodyKey)} />
|
|
</div>
|
|
) : (
|
|
<div className="w-full overflow-x-auto">
|
|
<Table
|
|
data-ui-id="ui.hr.locations.table"
|
|
header={
|
|
<Table.HeaderRow>
|
|
<Table.HeaderCell>{t("hr.locations.column.name")}</Table.HeaderCell>
|
|
<Table.HeaderCell>{t("hr.locations.column.city")}</Table.HeaderCell>
|
|
<Table.HeaderCell>{t("hr.locations.column.employees")}</Table.HeaderCell>
|
|
{canManage ? <Table.HeaderCell> </Table.HeaderCell> : null}
|
|
</Table.HeaderRow>
|
|
}
|
|
>
|
|
{rows.map((row) => (
|
|
<Table.Row key={row.id} data-row-id={row.id} data-default={row.isDefault}>
|
|
<Table.Cell>
|
|
<div className="flex items-center gap-2">
|
|
<AppLink
|
|
href={row.detailHref}
|
|
className="text-body-default-medium-0 font-body-default-medium-0 text-text-feedback-link-default"
|
|
>
|
|
{row.name}
|
|
</AppLink>
|
|
{row.isDefault ? (
|
|
<BadgeFeedback farbe="subtle-neutral" size="small">
|
|
{t("hr.locations.default")}
|
|
</BadgeFeedback>
|
|
) : null}
|
|
</div>
|
|
</Table.Cell>
|
|
<Table.Cell>
|
|
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
|
{row.city ?? "—"}
|
|
</span>
|
|
</Table.Cell>
|
|
<Table.Cell>
|
|
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
|
{row.employeeCount}
|
|
</span>
|
|
</Table.Cell>
|
|
{canManage ? (
|
|
<Table.Cell>
|
|
<div className="flex items-center justify-end gap-2">
|
|
{!row.isDefault ? (
|
|
<Button variant="tertiary" size="small" onClick={() => actions.onSetDefault(row.id)}>
|
|
{t("hr.locations.action.setDefault")}
|
|
</Button>
|
|
) : null}
|
|
<Button variant="tertiary" size="small" onClick={() => actions.onArchive(row.id)}>
|
|
{t("hr.locations.action.archive")}
|
|
</Button>
|
|
</div>
|
|
</Table.Cell>
|
|
) : null}
|
|
</Table.Row>
|
|
))}
|
|
</Table>
|
|
</div>
|
|
)}
|
|
|
|
<Dialog open={createOpen} onOpenChange={setCreateOpen}>
|
|
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.locations.create">
|
|
<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.locations.create.title")}</span>
|
|
<div className="flex w-full flex-col gap-4">
|
|
<TextInput label={t("hr.locations.field.name")} showLabel fillContainer>
|
|
<TextInput.Input value={name} onChange={(event) => setName(event.target.value)} data-ui-id="ui.hr.locations.create.name" />
|
|
</TextInput>
|
|
<TextInput label={t("hr.locations.field.city")} showLabel fillContainer>
|
|
<TextInput.Input value={city} onChange={(event) => setCity(event.target.value)} data-ui-id="ui.hr.locations.create.city" />
|
|
</TextInput>
|
|
<Checkbox label={t("hr.locations.field.isDefault")} checked={isDefault} onCheckedChange={(checked: boolean) => setIsDefault(checked)} />
|
|
</div>
|
|
<div className="flex justify-end gap-2">
|
|
<Button variant="neutral" onClick={() => setCreateOpen(false)}>
|
|
{t("hr.action.cancel")}
|
|
</Button>
|
|
<Button loading={submitting} disabled={name.trim().length === 0} onClick={submitCreate} data-ui-id="ui.hr.locations.create.submit">
|
|
{t("hr.locations.create.submit")}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</Dialog.Content>
|
|
</Dialog>
|
|
</PageBody>
|
|
</PageShell>
|
|
);
|
|
}
|