// WF-P8 S04 "Board-Einstellungen" — built against Davids Subframe export of // 2026-07-28 (page 0b946683-2cca-4cd4-864d-f69ed1937fdb). // // This screen is the per-board half of the admin split: S07 lists the boards, // S04 configures one. Pure/presentational — renders the server-built // BoardSettingsData and turns every mutation into a typed // onSubmit(intent, fields) the route POSTs. No useLoaderData/useFetcher, no // server imports. // // Deliberate deltas against the export: // * The export imports `@/ui/components/SettingsPage`, which the local ~/ui // kit does not ship. The section headers are rendered with the same two // lines of markup instead. // * `Table.Cell variant="align-right"` only exists in the export; locally the // variants are align-left/align-center, so right-aligned cells use a // justify-end wrapper. // * The column "Status" select offers the three real stage kinds // (offen/gewonnen/verloren). The export's free-text statuses plus "Neuen // Status eingeben …" would need a schema change that the kanban, the M01 // lost dialog and the win/loss numbers all read from — out of ticket scope. // * The export shows a per-row pencil next to always-editable inputs. The // inputs already are the edit affordance, so the row shows a save action // when it is dirty rather than a pencil that toggles nothing. // * Colour and win-% per column are kept although the export drops them: both // are live data the board and the forecast render. // * "Zugriff" has no section in the export but no other screen configures // it; dropping it here would make a shipped feature unreachable. // * The M04 successor board USED to sit at the bottom of this page for the // same reason. It was taken out on request (acceptance 2026-07-31): the // export does not show it here. Nothing else sets // `Pipeline.nachfolgePipelineId` today, so the handover cannot be // configured from the UI until it gets a new home — the write path // (`updatePipeline`) is untouched and still accepts the field. import { useEffect, useState, type CSSProperties } from "react"; import { useTranslation } from "react-i18next"; import { AppLink } from "~/components/app/AppLink"; import { DndContext, KeyboardSensor, PointerSensor, closestCenter, useSensor, useSensors, type DragEndEvent, } from "@dnd-kit/core"; import { SortableContext, arrayMove, sortableKeyboardCoordinates, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable"; import { CSS } from "@dnd-kit/utilities"; import type { BoardSettingsData, PipelineAdminItem, PipelineAdminStage } from "@hivegrid/view-models"; import { FeatherArrowRightCircle, FeatherCheck, FeatherClipboardList, FeatherGripVertical, FeatherKanban, FeatherPencil, FeatherPlus, FeatherTrash, FeatherX, } from "@subframe/core"; import { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageShell } from "../shared/PageShell"; import { Accordion } from "~/ui/components/Accordion"; import { Alert } from "~/ui/components/Alert"; import { BadgeFeedback } from "~/ui/components/BadgeFeedback"; import { Button } from "~/ui/components/Button"; import { IconButton } from "~/ui/components/IconButton"; import { Select } from "~/ui/components/Select"; import { Table } from "~/ui/components/Table"; import { TextInput } from "~/ui/components/TextInput"; import { useLocaleFormatters } from "~/locale/format"; export type BoardSettingsSubmit = (intent: string, fields: Record) => void; export type BoardSettingsPageProps = { data: BoardSettingsData; submitting: boolean; errorKey?: string | null; /** S05 detail-field template of this board. */ fieldTemplateHref: string; actions: { onSubmit: BoardSettingsSubmit }; }; const STAGE_KINDS = ["offen", "gewonnen", "verloren"] as const; const sectionTitle = "text-body-large font-body-large text-text-neutral-primary"; const sectionDescription = "text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary"; const mutedText = "text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary"; // Native rendered as a round swatch (no padded border): // it is both the colour dot the export draws and the way to change it, so the // row does not need a second control. The webkit/moz pseudo-elements strip the // default swatch padding and border. const colorSwatchClass = "h-3.5 w-3.5 shrink-0 cursor-pointer appearance-none rounded-full border-none bg-transparent p-0 [&::-webkit-color-swatch-wrapper]:p-0 [&::-webkit-color-swatch]:rounded-full [&::-webkit-color-swatch]:border-none [&::-moz-color-swatch]:rounded-full [&::-moz-color-swatch]:border-none"; function SectionHeader({ title, description }: { title: string; description: string }) { return (

{title}

{description}

); } type StageDraft = { name: string; stageKind: string; winProbability: string; color: string }; function draftOf(stage: PipelineAdminStage): StageDraft { return { name: stage.name, stageKind: stage.stageKind, winProbability: String(stage.winProbability), color: stage.color }; } function draftDiffers(draft: StageDraft, stage: PipelineAdminStage): boolean { return ( draft.name !== stage.name || draft.stageKind !== stage.stageKind || draft.winProbability !== String(stage.winProbability) || draft.color !== stage.color ); } /** One draggable column row. Name, kind, win-% and colour edit in place; the * save action only appears once the row actually differs from the server state, * so an untouched table has no buttons inviting a pointless write. */ function SortableStageRow({ stage, pipelineId, submit, submitting, }: { stage: PipelineAdminStage; pipelineId: string; submit: BoardSettingsSubmit; submitting: boolean; }) { const { t } = useTranslation(); const [draft, setDraft] = useState(() => draftOf(stage)); useEffect(() => { setDraft(draftOf(stage)); }, [stage]); const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: stage.id }); const style: CSSProperties = { transform: CSS.Transform.toString(transform), transition, opacity: isDragging ? 0.6 : 1 }; const idBase = `ui.projects.boardSettings.stage.${stage.id}`; const dirty = draftDiffers(draft, stage); // The export's row has Name, Status and Projektanzahl only. The win // probability is live data (forecast, board) with no other screen to edit it, // so the export's per-row pencil opens it instead of showing a fourth column. const [expanded, setExpanded] = useState(false); return ( <>
setDraft((s) => ({ ...s, color: e.target.value }))} className={colorSwatchClass} aria-label={t("projects.fields.color")} data-ui-id={`${idBase}.color`} />
setDraft((s) => ({ ...s, name: e.target.value }))} data-ui-id={`${idBase}.name`} />
{t("projects.boardSettings.columns.projectCount", { count: stage.projectCount })} } aria-label={t("projects.actions.edit")} aria-expanded={expanded} onClick={() => setExpanded((value) => !value)} data-ui-id={`${idBase}.edit`} /> {dirty ? ( } loading={submitting} disabled={!draft.name.trim()} aria-label={t("projects.actions.save")} onClick={() => submit("upsertStage", { pipelineId, stageId: stage.id, name: draft.name.trim(), stageKind: draft.stageKind, winProbability: draft.winProbability, color: draft.color, }) } data-ui-id={`${idBase}.save`} /> ) : null} } aria-label={t("projects.actions.remove")} onClick={() => submit("archiveStage", { stageId: stage.id })} data-ui-id={`${idBase}.archive`} />
{expanded ? (
{t("projects.fields.winProbability")} setDraft((s) => ({ ...s, winProbability: e.target.value }))} data-ui-id={`${idBase}.winProbability`} /> %
) : null} ); } /** Drag&drop-orderable column list. On drop it persists the whole new * top-to-bottom order via `reorderStages`; the service reassigns positions. */ function StageTable({ board, submit, submitting }: { board: PipelineAdminItem; submit: BoardSettingsSubmit; submitting: boolean }) { const { t } = useTranslation(); const [order, setOrder] = useState(() => board.stages.map((stage) => stage.id)); useEffect(() => { setOrder(board.stages.map((stage) => stage.id)); }, [board.stages]); const sensors = useSensors( useSensor(PointerSensor, { activationConstraint: { distance: 5 } }), useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }), ); const stageById = new Map(board.stages.map((stage) => [stage.id, stage])); const ordered = order.map((id) => stageById.get(id)).filter((stage): stage is PipelineAdminStage => Boolean(stage)); function handleDragEnd(event: DragEndEvent) { const { active, over } = event; if (!over || active.id === over.id) return; const oldIndex = order.indexOf(String(active.id)); const newIndex = order.indexOf(String(over.id)); if (oldIndex < 0 || newIndex < 0) return; const next = arrayMove(order, oldIndex, newIndex); setOrder(next); submit("reorderStages", { pipelineId: board.id, stageIds: JSON.stringify(next) }); } return (
{t("projects.fields.name")} {t("projects.boardSettings.columns.status")} {t("projects.boardSettings.columns.projects")} } emptyText={t("projects.boardSettings.columns.empty")} > {ordered.map((stage) => ( ))}
); } /** Create row for a new column. Resets to an empty draft after each write so the * next column can be typed right away. */ function AddStageForm({ pipelineId, submit, submitting }: { pipelineId: string; submit: BoardSettingsSubmit; submitting: boolean }) { const { t } = useTranslation(); const emptyDraft: StageDraft = { name: "", stageKind: "offen", winProbability: "0", color: "#6b7280" }; const [draft, setDraft] = useState(emptyDraft); const [open, setOpen] = useState(false); const idBase = `ui.projects.boardSettings.addStage.${pipelineId}`; if (!open) { return ( ); } return (
setDraft((s) => ({ ...s, name: e.target.value }))} data-ui-id={`${idBase}.name`} /> setDraft((s) => ({ ...s, winProbability: e.target.value }))} data-ui-id={`${idBase}.winProbability`} />
setDraft((s) => ({ ...s, color: e.target.value }))} className={`${colorSwatchClass} h-6 w-6`} aria-label={t("projects.fields.color")} data-ui-id={`${idBase}.color`} />
); } export function BoardSettingsPage(props: BoardSettingsPageProps) { const { t } = useTranslation(); const formatters = useLocaleFormatters(); const submit = props.actions.onSubmit; const board = props.data.board; const [renaming, setRenaming] = useState(false); const [name, setName] = useState(board.name); useEffect(() => { setName(board.name); setRenaming(false); }, [board.name]); /** Saves the board name and leaves the edit mode. Closing here rather than * waiting for the loader matters when the name did not actually change: * `board.name` stays the same, so the effect above never fires and the * header would sit in the input forever. */ function saveName() { const next = name.trim(); if (!next) return; submit("updatePipeline", { pipelineId: board.id, name: next }); setRenaming(false); } const metaParts = [ // The export shows a short board id ("BRD-014") next to the status. Pipeline // has no such number, so this is the real id — the value support and a // deep link actually need — rather than an invented display number. t("projects.boardSettings.meta.boardId", { id: board.id }), t(board.typHintLabelKey), t("projects.boardSettings.meta.projects", { count: board.projectCount }), board.updatedAtIso ? t("projects.boardSettings.meta.updated", { date: formatters.dateTime(board.updatedAtIso) }) : t("projects.boardSettings.meta.neverUpdated"), ]; return ( } title={ renaming ? ( setName(e.target.value)} // Enter saves, Escape drops the draft — a one-field editor // should not force the mouse onto the check mark. onKeyDown={(event) => { if (event.key === "Enter") { event.preventDefault(); saveName(); } if (event.key === "Escape") { setName(board.name); setRenaming(false); } }} data-ui-id="ui.projects.boardSettings.rename.input" /> } disabled={!name.trim()} loading={props.submitting} aria-label={t("projects.actions.save")} onClick={saveName} data-ui-id="ui.projects.boardSettings.rename.save" /> } aria-label={t("projects.actions.cancel")} onClick={() => { setName(board.name); setRenaming(false); }} /> ) : ( {board.name} } aria-label={t("projects.actions.edit")} onClick={() => setRenaming(true)} data-ui-id="ui.projects.boardSettings.rename.open" /> {t(`projects.boardSettings.status.${board.statusKey}`)} {board.isDefault ? ( {t("projects.admin.defaultBadge")} ) : null} ) } subtitle={metaParts.join(" · ")} /> {props.errorKey ? ( ) : null} {!board.valid ? ( ) : null}

{t("projects.boardSettings.detailFields.body")}

{t("projects.boardSettings.detailFields.bulletOrder")}
{t("projects.boardSettings.detailFields.bulletRights")}
{t("projects.boardSettings.detailFields.openTitle")}
{/* Same card as the sections above, but collapsed: the rules are read here far less often than the columns are edited, so the section states how many there are and opens on demand. */} {t("projects.boardSettings.access.toggle")} {t("projects.boardSettings.access.count", { count: board.accessRules.length })} } >
{board.accessRules.length === 0 ? ( {t("projects.admin.noAccessRules")} ) : ( board.accessRules.map((rule) => (
{t(rule.principalTypeLabelKey)} {rule.principalId} {rule.kannSehen ? {t("projects.admin.canSee")} : null} {rule.kannBearbeiten ? {t("projects.admin.canEdit")} : null}
)) )}
); } export default BoardSettingsPage;