548 lines
26 KiB
TypeScript
548 lines
26 KiB
TypeScript
// WF-P8 S06 "Verlust-Gründe" — rebuilt against Davids Subframe export of
|
|
// 2026-07-28 (page 3c95e1e1-728b-460c-996f-5a641c971dfe) plus the local
|
|
// wireframe doc.
|
|
//
|
|
// Pure/presentational: renders the server-built LostReasonAdminData and turns
|
|
// create/edit/archive/reactivate into a typed onSubmit(intent, fields) the
|
|
// route POSTs. Search and the status facet are client-side (the list is a
|
|
// handful of rows). No useLoaderData/useFetcher and no server imports.
|
|
//
|
|
// Deliberate deltas against the export:
|
|
// * "Verlauf ansehen" has no screen behind it and is left out rather than
|
|
// shipped as a dead menu entry.
|
|
// * The export's DropdownMenuSelect is not in the local ~/ui kit; the row
|
|
// actions use the synced DropdownMenu, which is the same interaction.
|
|
|
|
import { useMemo, useState, type ChangeEvent } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import type { LostReasonAdminData, LostReasonRowVM } from "@hivegrid/view-models";
|
|
import {
|
|
FeatherAlignLeft,
|
|
FeatherArchive,
|
|
FeatherCircleDot,
|
|
FeatherClock,
|
|
FeatherFilter,
|
|
FeatherFolderKanban,
|
|
FeatherMoreHorizontal,
|
|
FeatherPencil,
|
|
FeatherPlus,
|
|
FeatherThumbsDown,
|
|
FeatherTrendingDown,
|
|
FeatherTrendingUp,
|
|
FeatherUndo2,
|
|
} from "@subframe/core";
|
|
import * as SubframeCore from "@subframe/core";
|
|
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 { Dialog } from "~/ui/components/Dialog";
|
|
import { DropdownMenu } from "~/ui/components/DropdownMenu";
|
|
import { EmptyState } from "~/ui/components/EmptyState";
|
|
import { IconButton } from "~/ui/components/IconButton";
|
|
import { SearchInput } from "~/ui/components/SearchInput";
|
|
import { Select } from "~/ui/components/Select";
|
|
import { Table } from "~/ui/components/Table";
|
|
import { Tag_Label } from "~/ui/components/Tag_Label";
|
|
import { TextArea } from "~/ui/components/TextArea";
|
|
import { TextInput } from "~/ui/components/TextInput";
|
|
import { useLocaleFormatters } from "~/locale/format";
|
|
|
|
export type LostReasonAdminSubmit = (intent: string, fields: Record<string, string>) => void;
|
|
export type LostReasonAdminPageProps = {
|
|
data: LostReasonAdminData;
|
|
submitting: boolean;
|
|
errorKey?: string | null;
|
|
actions: { onSubmit: LostReasonAdminSubmit };
|
|
};
|
|
|
|
export type LostReasonStatusFilter = "all" | "active" | "archived";
|
|
|
|
const insightLabel =
|
|
"text-body-extra-small-medium-150 font-body-extra-small-medium-150 uppercase tracking-wide text-text-neutral-tertiary";
|
|
|
|
/** Client-side filter, exported so the rule can be tested without the Radix widget. */
|
|
export function filterLostReasons(
|
|
reasons: readonly LostReasonRowVM[],
|
|
filters: { search: string; status: LostReasonStatusFilter }
|
|
): readonly LostReasonRowVM[] {
|
|
const q = filters.search.trim().toLowerCase();
|
|
return reasons.filter((reason) => {
|
|
if (filters.status === "active" && reason.archived) return false;
|
|
if (filters.status === "archived" && !reason.archived) return false;
|
|
if (!q) return true;
|
|
return [reason.name, reason.beschreibung, reason.kategorie].some((field) => field?.toLowerCase().includes(q));
|
|
});
|
|
}
|
|
|
|
export function LostReasonAdminPage(props: LostReasonAdminPageProps) {
|
|
const { t } = useTranslation();
|
|
const { number, dateTime } = useLocaleFormatters();
|
|
const submit = props.actions.onSubmit;
|
|
const { data } = props;
|
|
|
|
const [search, setSearch] = useState("");
|
|
const [status, setStatus] = useState<LostReasonStatusFilter>("all");
|
|
const [createOpen, setCreateOpen] = useState(false);
|
|
const [draft, setDraft] = useState({ name: "", beschreibung: "", kategorie: "" });
|
|
const [editing, setEditing] = useState<string | null>(null);
|
|
|
|
const rows = useMemo(() => filterLostReasons(data.reasons, { search, status }), [data.reasons, search, status]);
|
|
|
|
function resetDraft() {
|
|
setDraft({ name: "", beschreibung: "", kategorie: "" });
|
|
setCreateOpen(false);
|
|
}
|
|
|
|
return (
|
|
<PageShell uiId="ui.projects.lostReasons" className="bg-surface-neutral-primary">
|
|
<PageHeader
|
|
icon={<FeatherThumbsDown className={PAGE_HEADER_ICON_CLASS} />}
|
|
title={t("projects.lostReasonsAdmin.title")}
|
|
subtitle={t("projects.lostReasonsAdmin.subtitle")}
|
|
actions={
|
|
/* Loss picture of the last 30 days, straight from the stage-change
|
|
history — the whole point of maintaining reasons. Both compartments
|
|
always render: a missing comparison is itself an answer, and a card
|
|
that changes width between tenants reads as a broken header. */
|
|
<div
|
|
className="flex items-center gap-3 rounded-md border border-solid border-border-default bg-surface-neutral-primary px-4 py-2.5 mobile:hidden"
|
|
data-ui-id="ui.projects.lostReasons.insights"
|
|
>
|
|
<div className="flex flex-col items-start gap-0.5">
|
|
<span className={insightLabel}>{t("projects.lostReasonsAdmin.insights.topReason")}</span>
|
|
<span className="text-body-default-semibold-150 font-body-default-semibold-150 text-text-neutral-primary">
|
|
{data.insights.topReasonName ?? t("projects.lostReasonsAdmin.insights.noLosses")}
|
|
</span>
|
|
</div>
|
|
<div className="flex h-8 w-px flex-none flex-col items-center bg-border-default" />
|
|
<div className="flex flex-col items-start gap-0.5">
|
|
<span className={insightLabel}>{t("projects.lostReasonsAdmin.insights.monthComparison")}</span>
|
|
{data.insights.changePercent === null ? (
|
|
<span
|
|
className="text-body-default-semibold-150 font-body-default-semibold-150 text-text-neutral-tertiary"
|
|
data-ui-id="ui.projects.lostReasons.insights.change"
|
|
>
|
|
{t("projects.lostReasonsAdmin.insights.noComparison")}
|
|
</span>
|
|
) : (
|
|
<div className="flex items-center gap-1">
|
|
{data.insights.changeIsWorse ? (
|
|
<FeatherTrendingUp className="text-body-small-regular-0 text-icon-feedback-negative" aria-hidden />
|
|
) : (
|
|
<FeatherTrendingDown className="text-body-small-regular-0 text-icon-feedback-positive" aria-hidden />
|
|
)}
|
|
<span
|
|
className={`text-body-default-semibold-150 font-body-default-semibold-150 ${
|
|
data.insights.changeIsWorse ? "text-text-feedback-negative" : "text-text-feedback-positive"
|
|
}`}
|
|
data-ui-id="ui.projects.lostReasons.insights.change"
|
|
>
|
|
{t("projects.lostReasonsAdmin.insights.changeValue", {
|
|
value: `${data.insights.changePercent > 0 ? "+" : ""}${number(data.insights.changePercent)}`,
|
|
})}
|
|
</span>
|
|
<span className="text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-text-neutral-tertiary">
|
|
{t("projects.lostReasonsAdmin.insights.versusPreviousMonth")}
|
|
</span>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
}
|
|
/>
|
|
|
|
<PageBody>
|
|
<div className="flex w-full flex-col gap-5">
|
|
{props.errorKey ? <BadgeFeedback farbe="subtle-negative">{t(props.errorKey)}</BadgeFeedback> : null}
|
|
|
|
<Alert
|
|
variant="information"
|
|
notDismissible
|
|
title={t("projects.lostReasonsAdmin.archiveNotice.title")}
|
|
description={t("projects.lostReasonsAdmin.archiveNotice.body")}
|
|
textSize="small"
|
|
/>
|
|
|
|
{/* Search and status facet as one bordered bar, as in the export. The
|
|
add action sits at its right end: the export draws no button at all,
|
|
but reasons have to come from somewhere, and the header card is the
|
|
loss picture, not a place for controls. */}
|
|
<div className="flex w-full flex-col items-start gap-3">
|
|
<div
|
|
className="flex w-full items-center gap-2 rounded-lg border border-solid border-border-default bg-surface-neutral-secondary px-3 py-2 shadow-sm mobile:flex-col mobile:items-stretch"
|
|
data-ui-id="ui.projects.lostReasons.filter"
|
|
>
|
|
<SearchInput
|
|
// The bar itself is the bordered surface, so the field must not
|
|
// draw a second focus ring inside it.
|
|
className="h-8 grow shrink-0 basis-0 [&_label]:!shadow-none"
|
|
size="small"
|
|
borderless
|
|
// No `noPadding`: our SearchInput ties that to `w-auto`, which
|
|
// beats the fill and leaves the field at its minimum width.
|
|
fillContainer
|
|
hideShortcut
|
|
placeholder={t("projects.lostReasonsAdmin.searchPlaceholder")}
|
|
value={search}
|
|
onChange={(event: ChangeEvent<HTMLInputElement>) => setSearch(event.target.value)}
|
|
data-ui-id="ui.projects.lostReasons.filter.search"
|
|
/>
|
|
<div className="h-5 w-px flex-none bg-border-default mobile:hidden" />
|
|
<div className="flex items-center gap-2 mobile:w-full mobile:flex-none">
|
|
<FeatherFilter className="flex-none text-body-small-regular-0 font-body-small-regular-0 text-icon-neutral-tertiary" aria-hidden />
|
|
<span className="whitespace-nowrap text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary">
|
|
{t("projects.lostReasonsAdmin.statusLabel")}
|
|
</span>
|
|
<Select
|
|
size="small"
|
|
variant="filled"
|
|
borderless
|
|
className="h-8 w-36 flex-none mobile:w-full"
|
|
triggerAriaLabel={t("projects.lostReasonsAdmin.statusLabel")}
|
|
value={status}
|
|
onValueChange={(value) => setStatus(value as LostReasonStatusFilter)}
|
|
data-ui-id="ui.projects.lostReasons.filter.status"
|
|
>
|
|
<Select.Item value="all">{t("projects.lostReasonsAdmin.status.all")}</Select.Item>
|
|
<Select.Item value="active">{t("projects.lostReasonsAdmin.status.active")}</Select.Item>
|
|
<Select.Item value="archived">{t("projects.lostReasonsAdmin.status.archived")}</Select.Item>
|
|
</Select>
|
|
</div>
|
|
{data.canAdmin ? (
|
|
<>
|
|
<div className="h-5 w-px flex-none bg-border-default mobile:hidden" />
|
|
<Button
|
|
size="small"
|
|
className="flex-none"
|
|
icon={<FeatherPlus />}
|
|
onClick={() => setCreateOpen((open) => !open)}
|
|
data-ui-id="ui.projects.lostReasons.new.toggle"
|
|
>
|
|
{t("projects.actions.addLostReason")}
|
|
</Button>
|
|
</>
|
|
) : null}
|
|
</div>
|
|
<div className="flex w-full items-center justify-end mobile:justify-start">
|
|
<span className="text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-text-neutral-tertiary" data-ui-id="ui.projects.lostReasons.count">
|
|
{t("projects.lostReasonsAdmin.countLine", {
|
|
total: number(data.totalCount),
|
|
templates: number(data.templateCount),
|
|
own: number(data.ownCount),
|
|
})}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Creating a reason is a short, self-contained form. As an inline card
|
|
it pushed the whole table down; as a dialog the list stays put. */}
|
|
<Dialog open={createOpen && data.canAdmin} onOpenChange={(open) => (open ? setCreateOpen(true) : resetDraft())}>
|
|
<Dialog.Content className="p-6" data-ui-id="ui.projects.lostReasons.new">
|
|
<div className="flex w-full flex-col gap-4" style={{ minWidth: 480 }}>
|
|
<div className="flex items-center gap-2">
|
|
<FeatherThumbsDown className="text-body-large font-body-large text-icon-neutral-tertiary" aria-hidden />
|
|
<span className="text-body-large font-body-large text-text-neutral-primary">{t("projects.lostReasonsAdmin.newReason")}</span>
|
|
</div>
|
|
<div className="grid w-full items-end gap-3 sm:grid-cols-2">
|
|
<TextInput className="w-full" fillContainer showLabel label={t("projects.fields.name")}>
|
|
<TextInput.Input
|
|
autoFocus
|
|
value={draft.name}
|
|
onChange={(event) => setDraft((current) => ({ ...current, name: event.target.value }))}
|
|
data-ui-id="ui.projects.lostReasons.new.name"
|
|
/>
|
|
</TextInput>
|
|
<TextInput className="w-full" fillContainer showLabel label={t("projects.lostReasonsAdmin.fields.category")}>
|
|
<TextInput.Input
|
|
value={draft.kategorie}
|
|
onChange={(event) => setDraft((current) => ({ ...current, kategorie: event.target.value }))}
|
|
data-ui-id="ui.projects.lostReasons.new.kategorie"
|
|
/>
|
|
</TextInput>
|
|
</div>
|
|
<TextArea className="w-full max-w-none" showLabel label={t("projects.lostReasonsAdmin.fields.description")}>
|
|
<TextArea.Input
|
|
value={draft.beschreibung}
|
|
onChange={(event) => setDraft((current) => ({ ...current, beschreibung: event.target.value }))}
|
|
data-ui-id="ui.projects.lostReasons.new.beschreibung"
|
|
/>
|
|
</TextArea>
|
|
<div className="flex w-full items-center justify-end gap-2">
|
|
<Button variant="tertiary" onClick={resetDraft} data-ui-id="ui.projects.lostReasons.new.cancel">
|
|
{t("projects.actions.cancel")}
|
|
</Button>
|
|
<Button
|
|
icon={<FeatherPlus />}
|
|
disabled={!draft.name.trim()}
|
|
loading={props.submitting}
|
|
onClick={() => {
|
|
submit("upsertLostReason", {
|
|
name: draft.name.trim(),
|
|
beschreibung: draft.beschreibung.trim(),
|
|
kategorie: draft.kategorie.trim(),
|
|
});
|
|
resetDraft();
|
|
}}
|
|
data-ui-id="ui.projects.lostReasons.new.create"
|
|
>
|
|
{t("projects.actions.addLostReason")}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</Dialog.Content>
|
|
</Dialog>
|
|
|
|
{data.reasons.length === 0 ? (
|
|
<div data-ui-id="ui.projects.lostReasons.empty">
|
|
<EmptyState title={t("projects.lostReasonsAdmin.empty")} />
|
|
</div>
|
|
) : rows.length === 0 ? (
|
|
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-tertiary" data-ui-id="ui.projects.lostReasons.noMatches">
|
|
{t("projects.lostReasonsAdmin.noMatches")}
|
|
</span>
|
|
) : (
|
|
<div className="w-full overflow-x-auto rounded-lg border border-solid border-border-default shadow-sm" data-ui-id="ui.projects.lostReasons.list">
|
|
<Table
|
|
header={
|
|
<Table.HeaderRow className="bg-surface-neutral-tertiary">
|
|
<Table.HeaderCell icon={<FeatherThumbsDown />}>{t("projects.lostReasonsAdmin.columns.reason")}</Table.HeaderCell>
|
|
<Table.HeaderCell icon={<FeatherAlignLeft />}>{t("projects.lostReasonsAdmin.columns.description")}</Table.HeaderCell>
|
|
<Table.HeaderCell icon={<FeatherFolderKanban />}>{t("projects.lostReasonsAdmin.columns.projects")}</Table.HeaderCell>
|
|
<Table.HeaderCell icon={<FeatherCircleDot />}>{t("projects.lostReasonsAdmin.columns.status")}</Table.HeaderCell>
|
|
<Table.HeaderCell icon={<FeatherClock />}>{t("projects.lostReasonsAdmin.columns.lastUsed")}</Table.HeaderCell>
|
|
{/* The row menu needs no heading — the export leaves it blank
|
|
rather than labelling a column of three dots. */}
|
|
<Table.HeaderCell />
|
|
</Table.HeaderRow>
|
|
}
|
|
>
|
|
{rows.map((reason) =>
|
|
editing === reason.id ? (
|
|
<LostReasonEditRow
|
|
key={reason.id}
|
|
reason={reason}
|
|
submit={submit}
|
|
submitting={props.submitting}
|
|
onDone={() => setEditing(null)}
|
|
/>
|
|
) : (
|
|
<LostReasonRow
|
|
key={reason.id}
|
|
reason={reason}
|
|
canAdmin={data.canAdmin}
|
|
submit={submit}
|
|
onEdit={() => setEditing(reason.id)}
|
|
formatDateTime={dateTime}
|
|
formatNumber={number}
|
|
/>
|
|
)
|
|
)}
|
|
</Table>
|
|
</div>
|
|
)}
|
|
|
|
<span className="text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-text-neutral-tertiary" data-ui-id="ui.projects.lostReasons.footer">
|
|
{t("projects.lostReasonsAdmin.footerLine", {
|
|
total: number(data.totalCount),
|
|
projects: number(data.assignedProjectCount),
|
|
})}
|
|
</span>
|
|
</div>
|
|
</PageBody>
|
|
</PageShell>
|
|
);
|
|
}
|
|
|
|
function LostReasonRow({
|
|
reason,
|
|
canAdmin,
|
|
submit,
|
|
onEdit,
|
|
formatDateTime,
|
|
formatNumber,
|
|
}: {
|
|
reason: LostReasonRowVM;
|
|
canAdmin: boolean;
|
|
submit: LostReasonAdminSubmit;
|
|
onEdit: () => void;
|
|
formatDateTime: (value: string) => string;
|
|
formatNumber: (value: number) => string;
|
|
}) {
|
|
const { t } = useTranslation();
|
|
const muted = reason.archived ? "text-text-neutral-tertiary" : "text-text-neutral-primary";
|
|
return (
|
|
<Table.Row className={reason.archived ? "bg-surface-neutral-tertiary" : undefined} data-row-id={reason.id}>
|
|
<Table.Cell>
|
|
<div className="flex items-center gap-2">
|
|
<span className={`whitespace-nowrap text-body-small-medium-0 font-body-small-medium-0 ${muted}`}>{reason.name}</span>
|
|
<Tag_Label tone={reason.istVorlage ? "sky-subtle" : "neutral-subtle"} noAction size="small">
|
|
{t(reason.istVorlage ? "projects.lostReasonsAdmin.origin.template" : "projects.lostReasonsAdmin.origin.own")}
|
|
</Tag_Label>
|
|
{reason.isDemoData ? (
|
|
<BadgeFeedback farbe="subtle-neutral" size="small">{t("projects.lostReasonsAdmin.demoBadge")}</BadgeFeedback>
|
|
) : null}
|
|
</div>
|
|
</Table.Cell>
|
|
<Table.Cell>
|
|
<div className="flex flex-col items-start gap-0.5">
|
|
{reason.beschreibung ? (
|
|
<span className="line-clamp-2 max-w-[280px] text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary">
|
|
{reason.beschreibung}
|
|
</span>
|
|
) : null}
|
|
{reason.kategorie ? (
|
|
<span className="text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-text-neutral-tertiary">
|
|
{t("projects.lostReasonsAdmin.categoryPrefix", { category: reason.kategorie })}
|
|
</span>
|
|
) : null}
|
|
</div>
|
|
</Table.Cell>
|
|
<Table.Cell>
|
|
<span className={`whitespace-nowrap text-body-small-medium-0 font-body-small-medium-0 ${muted}`} data-ui-id={`ui.projects.lostReasons.row.${reason.id}.projects`}>
|
|
{t("projects.lostReasonsAdmin.projectCount", { count: reason.projectCount, formatted: formatNumber(reason.projectCount) })}
|
|
</span>
|
|
</Table.Cell>
|
|
<Table.Cell>
|
|
<BadgeFeedback farbe={reason.archived ? "subtle-neutral" : "subtle-positive"} size="small">
|
|
{t(reason.archived ? "projects.lostReasonsAdmin.status.archived" : "projects.lostReasonsAdmin.status.active")}
|
|
</BadgeFeedback>
|
|
</Table.Cell>
|
|
<Table.Cell>
|
|
<span className="whitespace-nowrap text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
|
|
{reason.lastUsedIso ? formatDateTime(reason.lastUsedIso) : t("projects.lostReasonsAdmin.neverUsed")}
|
|
</span>
|
|
</Table.Cell>
|
|
<Table.Cell>
|
|
{canAdmin ? (
|
|
<div className="flex w-full items-center justify-end gap-1">
|
|
<SubframeCore.DropdownMenu.Root>
|
|
<SubframeCore.DropdownMenu.Trigger asChild>
|
|
<IconButton
|
|
variant="ghost"
|
|
size="small"
|
|
icon={<FeatherMoreHorizontal />}
|
|
aria-label={t("projects.lostReasonsAdmin.columns.actions")}
|
|
data-ui-id={`ui.projects.lostReasons.row.${reason.id}.menu`}
|
|
/>
|
|
</SubframeCore.DropdownMenu.Trigger>
|
|
<SubframeCore.DropdownMenu.Portal>
|
|
<SubframeCore.DropdownMenu.Content side="bottom" align="end" sideOffset={4} asChild>
|
|
<DropdownMenu>
|
|
<DropdownMenu.DropdownItem
|
|
icon={<FeatherPencil />}
|
|
onSelect={onEdit}
|
|
data-ui-id={`ui.projects.lostReasons.row.${reason.id}.edit`}
|
|
>
|
|
{t("projects.actions.edit")}
|
|
</DropdownMenu.DropdownItem>
|
|
<DropdownMenu.DropdownDivider />
|
|
{reason.canArchive ? (
|
|
<DropdownMenu.DropdownItem
|
|
className="text-text-feedback-negative"
|
|
icon={<FeatherArchive />}
|
|
onSelect={() => submit("archiveLostReason", { reasonId: reason.id })}
|
|
data-ui-id={`ui.projects.lostReasons.row.${reason.id}.archive`}
|
|
>
|
|
{t("projects.actions.archive")}
|
|
</DropdownMenu.DropdownItem>
|
|
) : (
|
|
<DropdownMenu.DropdownItem
|
|
icon={<FeatherUndo2 />}
|
|
onSelect={() => submit("reactivateLostReason", { reasonId: reason.id })}
|
|
data-ui-id={`ui.projects.lostReasons.row.${reason.id}.reactivate`}
|
|
>
|
|
{t("projects.actions.reactivate")}
|
|
</DropdownMenu.DropdownItem>
|
|
)}
|
|
</DropdownMenu>
|
|
</SubframeCore.DropdownMenu.Content>
|
|
</SubframeCore.DropdownMenu.Portal>
|
|
</SubframeCore.DropdownMenu.Root>
|
|
</div>
|
|
) : null}
|
|
</Table.Cell>
|
|
</Table.Row>
|
|
);
|
|
}
|
|
|
|
/** Inline edit row — name, category and description in place of the read row. */
|
|
function LostReasonEditRow({
|
|
reason,
|
|
submit,
|
|
submitting,
|
|
onDone,
|
|
}: {
|
|
reason: LostReasonRowVM;
|
|
submit: LostReasonAdminSubmit;
|
|
submitting: boolean;
|
|
onDone: () => void;
|
|
}) {
|
|
const { t } = useTranslation();
|
|
const [draft, setDraft] = useState({
|
|
name: reason.name,
|
|
beschreibung: reason.beschreibung ?? "",
|
|
kategorie: reason.kategorie ?? "",
|
|
});
|
|
return (
|
|
<Table.Row data-row-id={reason.id}>
|
|
<Table.Cell>
|
|
<TextInput className="w-full" data-ui-id={`ui.projects.lostReasons.row.${reason.id}.nameInput`}>
|
|
<TextInput.Input value={draft.name} onChange={(event) => setDraft((current) => ({ ...current, name: event.target.value }))} />
|
|
</TextInput>
|
|
</Table.Cell>
|
|
<Table.Cell>
|
|
<div className="flex w-full flex-col gap-2">
|
|
<TextInput className="w-full">
|
|
<TextInput.Input
|
|
placeholder={t("projects.lostReasonsAdmin.fields.description")}
|
|
value={draft.beschreibung}
|
|
onChange={(event) => setDraft((current) => ({ ...current, beschreibung: event.target.value }))}
|
|
data-ui-id={`ui.projects.lostReasons.row.${reason.id}.beschreibungInput`}
|
|
/>
|
|
</TextInput>
|
|
<TextInput className="w-full">
|
|
<TextInput.Input
|
|
placeholder={t("projects.lostReasonsAdmin.fields.category")}
|
|
value={draft.kategorie}
|
|
onChange={(event) => setDraft((current) => ({ ...current, kategorie: event.target.value }))}
|
|
data-ui-id={`ui.projects.lostReasons.row.${reason.id}.kategorieInput`}
|
|
/>
|
|
</TextInput>
|
|
</div>
|
|
</Table.Cell>
|
|
<Table.Cell />
|
|
<Table.Cell />
|
|
<Table.Cell />
|
|
<Table.Cell>
|
|
<div className="flex w-full items-center justify-end gap-2">
|
|
<Button variant="tertiary" size="small" onClick={onDone} data-ui-id={`ui.projects.lostReasons.row.${reason.id}.cancel`}>
|
|
{t("projects.actions.cancel")}
|
|
</Button>
|
|
<Button
|
|
variant="neutral"
|
|
size="small"
|
|
disabled={!draft.name.trim()}
|
|
loading={submitting}
|
|
onClick={() => {
|
|
submit("upsertLostReason", {
|
|
reasonId: reason.id,
|
|
name: draft.name.trim(),
|
|
beschreibung: draft.beschreibung.trim(),
|
|
kategorie: draft.kategorie.trim(),
|
|
position: String(reason.position),
|
|
});
|
|
onDone();
|
|
}}
|
|
data-ui-id={`ui.projects.lostReasons.row.${reason.id}.save`}
|
|
>
|
|
{t("projects.actions.save")}
|
|
</Button>
|
|
</div>
|
|
</Table.Cell>
|
|
</Table.Row>
|
|
);
|
|
}
|
|
|
|
export default LostReasonAdminPage;
|