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

154 lines
7.5 KiB
TypeScript

// R-P9a interim UI (AD-28) — project template admin (D-P9 scope), restored
// after the admin route was dropped in the seat-billing recut.
// Pure/presentational: renders the server-built VM and turns every mutation
// into a typed onSubmit(intent, fields) callback the route POSTs. No
// useLoaderData/useFetcher, no server imports. Final Subframe optics =
// tracked design-nachzug. Modeled on LostReasonAdminPage (same admin-subpage
// chrome under /admin/pipelines).
import { useState } from "react";
import { useTranslation } from "react-i18next";
import type { ProjectTemplatesAdminScreenVM } from "@hivegrid/view-models";
import { FeatherArrowLeft, FeatherPlus } from "@subframe/core";
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";
import { AppLink } from "~/components/app/AppLink";
export type ProjectTemplatesAdminSubmit = (intent: string, fields: Record<string, string>) => void;
export type ProjectTemplatesAdminPageProps = {
vm: ProjectTemplatesAdminScreenVM;
backHref: string;
submitting: boolean;
errorKey?: string | null;
actions: { onSubmit: ProjectTemplatesAdminSubmit };
};
const mutedText = "text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary";
const NONE = "__none__";
export function ProjectTemplatesAdminPage(props: ProjectTemplatesAdminPageProps) {
const { t } = useTranslation();
const submit = props.actions.onSubmit;
const [name, setName] = useState("");
const [pipelineId, setPipelineId] = useState<string>(NONE);
const [stageId, setStageId] = useState<string>(NONE);
const pipelineOptions = props.vm.status === "ready" ? props.vm.data.pipelineOptions : [];
const stageOptions = pipelineId === NONE ? [] : (pipelineOptions.find((pipeline) => pipeline.id === pipelineId)?.stages ?? []);
return (
<div className="flex w-full flex-col items-start bg-surface-neutral-primary" data-ui-id="ui.projects.templatesAdmin">
<div className="flex w-full flex-wrap items-center justify-between gap-4 border-b border-solid border-border-default bg-surface-neutral-secondary px-6 py-4 mobile:px-4">
<div className="flex flex-col gap-0">
<span className="text-heading- font-heading- text-text-neutral-primary">{t("projects.templatesAdmin.title")}</span>
<span className={mutedText}>{t("projects.templatesAdmin.subtitle")}</span>
</div>
<AppLink href={props.backHref}>
<Button variant="tertiary" size="small" icon={<FeatherArrowLeft />}>{t("projects.lostReasonsAdmin.backToPipelines")}</Button>
</AppLink>
</div>
<div className="flex w-full max-w-4xl flex-col gap-6 px-6 py-6 mobile:px-4">
{props.errorKey ? <BadgeFeedback farbe="subtle-negative">{t(props.errorKey)}</BadgeFeedback> : null}
{props.vm.status !== "ready" ? (
<EmptyState title={t("projects.templatesAdmin.loading")} />
) : (
<>
<Card data-ui-id="ui.projects.templatesAdmin.new">
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
{t("projects.templatesAdmin.newTemplate")}
</span>
<div className="flex flex-wrap items-end gap-2">
<TextInput label={t("projects.fields.templateName")} showLabel>
<TextInput.Input value={name} onChange={(e) => setName(e.target.value)} data-ui-id="ui.projects.templatesAdmin.new.name" />
</TextInput>
<Select
value={pipelineId}
onValueChange={(value) => {
setPipelineId(value);
setStageId(NONE);
}}
triggerAriaLabel={t("projects.fields.defaultPipelineId")}
>
<Select.Item value={NONE}>{t("projects.templates.noPipeline")}</Select.Item>
{pipelineOptions.map((pipeline) => (
<Select.Item key={pipeline.id} value={pipeline.id}>{pipeline.name}</Select.Item>
))}
</Select>
<Select value={stageId} onValueChange={setStageId} disabled={pipelineId === NONE} triggerAriaLabel={t("projects.fields.defaultStageId")}>
<Select.Item value={NONE}>{t("projects.templatesAdmin.noStage")}</Select.Item>
{stageOptions.map((stage) => (
<Select.Item key={stage.id} value={stage.id}>{stage.name}</Select.Item>
))}
</Select>
<Button
icon={<FeatherPlus />}
disabled={!name.trim()}
loading={props.submitting}
onClick={() => {
submit("upsertProjectTemplate", {
name: name.trim(),
defaultPipelineId: pipelineId === NONE ? "" : pipelineId,
defaultStageId: stageId === NONE ? "" : stageId,
});
setName("");
setPipelineId(NONE);
setStageId(NONE);
}}
data-ui-id="ui.projects.templatesAdmin.new.create"
>
{t("projects.actions.saveTemplate")}
</Button>
</div>
</Card>
{props.vm.data.templates.length === 0 ? (
<div data-ui-id="ui.projects.templatesAdmin.empty">
<EmptyState title={t("projects.templatesAdmin.empty")} body={t("projects.templatesAdmin.emptyBody")} />
</div>
) : (
<Card data-ui-id="ui.projects.templatesAdmin.list">
<Table>
<Table.HeaderRow>
<Table.HeaderCell>{t("projects.fields.templateName")}</Table.HeaderCell>
<Table.HeaderCell>{t("projects.fields.pipeline")}</Table.HeaderCell>
<Table.HeaderCell>{t("projects.fields.stage")}</Table.HeaderCell>
<Table.HeaderCell>{t("projects.templatesAdmin.defaults")}</Table.HeaderCell>
</Table.HeaderRow>
{props.vm.data.templates.map((template) => (
<Table.Row key={template.id}>
<Table.Cell>
<div className="flex items-center gap-2">
<span>{template.name}</span>
{template.isDemoData ? (
<BadgeFeedback farbe="subtle-neutral" size="small">{t("projects.lostReasonsAdmin.demoBadge")}</BadgeFeedback>
) : null}
</div>
</Table.Cell>
<Table.Cell>{template.pipelineName ?? t("projects.templates.noPipeline")}</Table.Cell>
<Table.Cell>{template.stageName ?? t("projects.templatesAdmin.noStage")}</Table.Cell>
<Table.Cell>
<span className={mutedText}>
{t("projects.templatesAdmin.defaultCounts", { members: template.memberCount, tasks: template.taskCount })}
</span>
</Table.Cell>
</Table.Row>
))}
</Table>
</Card>
)}
</>
)}
</div>
</div>
);
}
export default ProjectTemplatesAdminPage;