Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+159
-161
@@ -5,8 +5,10 @@
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherPlus } from "@subframe/core";
|
||||
import { FeatherClipboard, FeatherPlus } from "@subframe/core";
|
||||
import type { HrRequestApproverVM, HrRequestKind, HrRequestOwnVM } from "@hivegrid/view-models";
|
||||
import type { FormDefinition } from "@hivegrid/form-widget";
|
||||
import { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageShell } from "../shared/PageShell";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Card } from "~/ui/components/Card";
|
||||
@@ -15,13 +17,17 @@ import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { Tabs } from "~/ui/components/Tabs";
|
||||
import { TextArea } from "~/ui/components/TextArea";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
import { AppLink } from "~/components/app/AppLink";
|
||||
import {
|
||||
InternalFormRenderer,
|
||||
type InternalFormValues,
|
||||
} from "~/modules/forms/internal/InternalFormRenderer";
|
||||
|
||||
export type HrRequestsTab = "own" | "approvals";
|
||||
export type HrRequestTemplateOption = { id: string; title: string; requestKind: HrRequestKind };
|
||||
export type HrRequestTemplateOption = { id: string; title: string; requestKind: HrRequestKind; definition: FormDefinition };
|
||||
|
||||
export type HrRequestsActions = {
|
||||
onSubmit: (input: { templateId: string; requestKind: string; approverUserId: string; title: string; details: string }) => void;
|
||||
onSubmit: (input: { templateId: string; values: InternalFormValues }) => void;
|
||||
onWithdraw: (requestId: string) => void;
|
||||
onApprove: (requestId: string) => void;
|
||||
onReject: (requestId: string) => void;
|
||||
@@ -34,7 +40,7 @@ export type HrRequestsPageProps = {
|
||||
ownVm: HrRequestOwnVM;
|
||||
approverVm: HrRequestApproverVM;
|
||||
templates: readonly HrRequestTemplateOption[];
|
||||
kinds: readonly HrRequestKind[];
|
||||
defaultFormDefinition: FormDefinition;
|
||||
tabHref: (tab: HrRequestsTab) => string;
|
||||
submitting: boolean;
|
||||
actions: HrRequestsActions;
|
||||
@@ -42,182 +48,174 @@ export type HrRequestsPageProps = {
|
||||
|
||||
const NO_TEMPLATE = "__none__";
|
||||
|
||||
export function HrRequestsPage({ tab, canApprove, ownVm, approverVm, templates, kinds, tabHref, submitting, actions }: HrRequestsPageProps) {
|
||||
export function HrRequestsPage({ tab, canApprove, ownVm, approverVm, templates, defaultFormDefinition, tabHref, submitting, actions }: HrRequestsPageProps) {
|
||||
const { t } = useTranslation();
|
||||
const [newOpen, setNewOpen] = useState(false);
|
||||
const [clarifyFor, setClarifyFor] = useState<string | null>(null);
|
||||
const [text, setText] = useState("");
|
||||
const [form, setForm] = useState({ templateId: NO_TEMPLATE, requestKind: kinds[0] ?? "expense", approverUserId: "", title: "", details: "" });
|
||||
const [templateId, setTemplateId] = useState(NO_TEMPLATE);
|
||||
|
||||
const tabs: HrRequestsTab[] = canApprove ? ["own", "approvals"] : ["own"];
|
||||
const ownRows = ownVm.data?.rows ?? [];
|
||||
const approverRows = approverVm.data?.rows ?? [];
|
||||
|
||||
function submitNew() {
|
||||
if (!form.title.trim()) return;
|
||||
actions.onSubmit({ ...form, templateId: form.templateId === NO_TEMPLATE ? "" : form.templateId });
|
||||
setNewOpen(false);
|
||||
setForm({ templateId: NO_TEMPLATE, requestKind: kinds[0] ?? "expense", approverUserId: "", title: "", details: "" });
|
||||
}
|
||||
const selectedTemplate =
|
||||
templateId === NO_TEMPLATE
|
||||
? null
|
||||
: templates.find((template) => template.id === templateId) ?? null;
|
||||
const activeDefinition = selectedTemplate?.definition ?? defaultFormDefinition;
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.requests">
|
||||
<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.requests.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">{t("hr.requests.subtitle")}</span>
|
||||
<PageShell uiId="ui.hr.requests">
|
||||
<PageHeader
|
||||
icon={<FeatherClipboard className={PAGE_HEADER_ICON_CLASS} />}
|
||||
title={t("hr.requests.title")}
|
||||
subtitle={t("hr.requests.subtitle")}
|
||||
actions={
|
||||
tab === "own" ? (
|
||||
<Button icon={<FeatherPlus />} onClick={() => setNewOpen(true)} data-ui-id="ui.hr.requests.new">
|
||||
{t("hr.requests.action.new")}
|
||||
</Button>
|
||||
) : undefined
|
||||
}
|
||||
/>
|
||||
<PageBody>
|
||||
<div data-ui-id="ui.hr.requests.tabs">
|
||||
<Tabs>
|
||||
{tabs.map((entry) => (
|
||||
<AppLink key={entry} href={tabHref(entry)} className="contents no-underline">
|
||||
<Tabs.Item active={tab === entry}>{t(`hr.requests.tab.${entry}`)}</Tabs.Item>
|
||||
</AppLink>
|
||||
))}
|
||||
</Tabs>
|
||||
</div>
|
||||
|
||||
{tab === "own" ? (
|
||||
<Button icon={<FeatherPlus />} onClick={() => setNewOpen(true)} data-ui-id="ui.hr.requests.new">
|
||||
{t("hr.requests.action.new")}
|
||||
</Button>
|
||||
ownRows.length === 0 ? (
|
||||
<div data-ui-id="ui.hr.requests.own.empty">
|
||||
<EmptyState title={t("hr.requests.own.empty.headline")} body={t("hr.requests.own.empty.body")} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex w-full flex-col gap-3" data-ui-id="ui.hr.requests.own.list">
|
||||
{ownRows.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">{row.title}</span>
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">{t(row.kindLabelKey)}</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<BadgeFeedback farbe="subtle-neutral" size="small">
|
||||
{t(row.statusLabelKey)}
|
||||
</BadgeFeedback>
|
||||
{row.canWithdraw ? (
|
||||
<Button variant="tertiary" size="small" loading={submitting} onClick={() => actions.onWithdraw(row.id)}>
|
||||
{t("hr.requests.action.withdraw")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div data-ui-id="ui.hr.requests.tabs">
|
||||
<Tabs>
|
||||
{tabs.map((entry) => (
|
||||
<a key={entry} href={tabHref(entry)} className="contents no-underline">
|
||||
<Tabs.Item active={tab === entry}>{t(`hr.requests.tab.${entry}`)}</Tabs.Item>
|
||||
</a>
|
||||
))}
|
||||
</Tabs>
|
||||
</div>
|
||||
|
||||
{tab === "own" ? (
|
||||
ownRows.length === 0 ? (
|
||||
<div data-ui-id="ui.hr.requests.own.empty">
|
||||
<EmptyState title={t("hr.requests.own.empty.headline")} body={t("hr.requests.own.empty.body")} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex w-full flex-col gap-3" data-ui-id="ui.hr.requests.own.list">
|
||||
{ownRows.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">{row.title}</span>
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">{t(row.kindLabelKey)}</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<BadgeFeedback farbe="subtle-neutral" size="small">
|
||||
{t(row.statusLabelKey)}
|
||||
</BadgeFeedback>
|
||||
{row.canWithdraw ? (
|
||||
<Button variant="tertiary" size="small" loading={submitting} onClick={() => actions.onWithdraw(row.id)}>
|
||||
{t("hr.requests.action.withdraw")}
|
||||
{tab === "approvals" ? (
|
||||
approverRows.length === 0 ? (
|
||||
<div data-ui-id="ui.hr.requests.approvals.empty">
|
||||
<EmptyState title={t("hr.requests.approver.empty.headline")} body={t("hr.requests.approver.empty.body")} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex w-full flex-col gap-3" data-ui-id="ui.hr.requests.approvals.list">
|
||||
{approverRows.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">{row.title}</span>
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
|
||||
{row.employeeLabel} · {t(row.kindLabelKey)}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button variant="tertiary" size="small" onClick={() => { setText(""); setClarifyFor(row.id); }}>
|
||||
{t("hr.requests.action.clarify")}
|
||||
</Button>
|
||||
) : null}
|
||||
<Button variant="destructive" size="small" loading={submitting} onClick={() => actions.onReject(row.id)}>
|
||||
{t("hr.requests.action.reject")}
|
||||
</Button>
|
||||
<Button size="small" loading={submitting} onClick={() => actions.onApprove(row.id)}>
|
||||
{t("hr.requests.action.approve")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
) : null}
|
||||
|
||||
{tab === "approvals" ? (
|
||||
approverRows.length === 0 ? (
|
||||
<div data-ui-id="ui.hr.requests.approvals.empty">
|
||||
<EmptyState title={t("hr.requests.approver.empty.headline")} body={t("hr.requests.approver.empty.body")} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex w-full flex-col gap-3" data-ui-id="ui.hr.requests.approvals.list">
|
||||
{approverRows.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">{row.title}</span>
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
|
||||
{row.employeeLabel} · {t(row.kindLabelKey)}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button variant="tertiary" size="small" onClick={() => { setText(""); setClarifyFor(row.id); }}>
|
||||
{t("hr.requests.action.clarify")}
|
||||
</Button>
|
||||
<Button variant="destructive" size="small" loading={submitting} onClick={() => actions.onReject(row.id)}>
|
||||
{t("hr.requests.action.reject")}
|
||||
</Button>
|
||||
<Button size="small" loading={submitting} onClick={() => actions.onApprove(row.id)}>
|
||||
{t("hr.requests.action.approve")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
) : null}
|
||||
|
||||
{/* New request dialog */}
|
||||
<Dialog open={newOpen} onOpenChange={setNewOpen}>
|
||||
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.requests.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.requests.action.new")}</span>
|
||||
<div className="flex w-full flex-col gap-4">
|
||||
<Select label={t("hr.requests.field.template")} showLabel value={form.templateId} onValueChange={(v: string) => setForm((s) => ({ ...s, templateId: v }))}>
|
||||
<Select.Item value={NO_TEMPLATE}>{t("hr.requests.field.noTemplate")}</Select.Item>
|
||||
{templates.map((tpl) => (
|
||||
<Select.Item key={tpl.id} value={tpl.id}>
|
||||
{tpl.title}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<Select label={t("hr.requests.field.kind")} showLabel value={form.requestKind} onValueChange={(v: string) => setForm((s) => ({ ...s, requestKind: v as HrRequestKind }))}>
|
||||
{kinds.map((kind) => (
|
||||
<Select.Item key={kind} value={kind}>
|
||||
{t(`hr.requests.kind.${kind}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<TextInput label={t("hr.requests.field.title")} showLabel fillContainer>
|
||||
<TextInput.Input value={form.title} onChange={(e) => setForm((s) => ({ ...s, title: e.target.value }))} />
|
||||
</TextInput>
|
||||
<TextInput label={t("hr.requests.field.approver")} showLabel fillContainer>
|
||||
<TextInput.Input value={form.approverUserId} onChange={(e) => setForm((s) => ({ ...s, approverUserId: e.target.value }))} />
|
||||
</TextInput>
|
||||
<TextArea label={t("hr.requests.field.details")} showLabel className="w-full">
|
||||
<TextArea.Input value={form.details} onChange={(e) => setForm((s) => ({ ...s, details: e.target.value }))} />
|
||||
</TextArea>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="neutral" onClick={() => setNewOpen(false)}>
|
||||
{t("hr.action.cancel")}
|
||||
</Button>
|
||||
<Button loading={submitting} disabled={!form.title.trim()} onClick={submitNew} data-ui-id="ui.hr.requests.newDialog.submit">
|
||||
{t("hr.requests.action.submit")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
)
|
||||
) : null}
|
||||
|
||||
{/* Clarify dialog */}
|
||||
<Dialog open={clarifyFor !== null} onOpenChange={(open) => !open && setClarifyFor(null)}>
|
||||
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.requests.clarifyDialog">
|
||||
<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.requests.action.clarify")}</span>
|
||||
<TextArea label={t("hr.requests.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={() => setClarifyFor(null)}>
|
||||
{t("hr.action.cancel")}
|
||||
</Button>
|
||||
<Button
|
||||
loading={submitting}
|
||||
disabled={text.trim().length === 0}
|
||||
onClick={() => {
|
||||
if (clarifyFor) actions.onClarify(clarifyFor, text);
|
||||
setClarifyFor(null);
|
||||
{/* New request dialog */}
|
||||
<Dialog open={newOpen} onOpenChange={setNewOpen}>
|
||||
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.requests.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.requests.action.new")}</span>
|
||||
<div className="flex w-full flex-col gap-4">
|
||||
<Select label={t("hr.requests.field.template")} showLabel value={templateId} onValueChange={setTemplateId}>
|
||||
<Select.Item value={NO_TEMPLATE}>{t("hr.requests.field.noTemplate")}</Select.Item>
|
||||
{templates.map((tpl) => (
|
||||
<Select.Item key={tpl.id} value={tpl.id}>
|
||||
{tpl.title}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
</div>
|
||||
<InternalFormRenderer
|
||||
key={templateId}
|
||||
definition={activeDefinition}
|
||||
submitting={submitting}
|
||||
uiId="ui.hr.requests.m05"
|
||||
onCancel={() => setNewOpen(false)}
|
||||
onSubmit={(values) => {
|
||||
actions.onSubmit({
|
||||
templateId: selectedTemplate?.id ?? "",
|
||||
values,
|
||||
});
|
||||
setNewOpen(false);
|
||||
setTemplateId(NO_TEMPLATE);
|
||||
}}
|
||||
>
|
||||
{t("hr.action.confirm")}
|
||||
</Button>
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
|
||||
{/* Clarify dialog */}
|
||||
<Dialog open={clarifyFor !== null} onOpenChange={(open) => !open && setClarifyFor(null)}>
|
||||
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.requests.clarifyDialog">
|
||||
<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.requests.action.clarify")}</span>
|
||||
<TextArea label={t("hr.requests.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={() => setClarifyFor(null)}>
|
||||
{t("hr.action.cancel")}
|
||||
</Button>
|
||||
<Button
|
||||
loading={submitting}
|
||||
disabled={text.trim().length === 0}
|
||||
onClick={() => {
|
||||
if (clarifyFor) actions.onClarify(clarifyFor, text);
|
||||
setClarifyFor(null);
|
||||
}}
|
||||
>
|
||||
{t("hr.action.confirm")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</PageBody>
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user