// R-P8b (P8 configurable Kanban) Interim-UI (AD-28) — board route `/projects`. // Loader builds the KanbanBoardVM via the shared board helper; the screen is // composed from ~/ui. Pipeline switch + only-mine are navigation (GET query); // stage moves / bulk / quick-create POST intents. Final Subframe optics = // tracked design-nachzug. import { redirect, useActionData, useLoaderData, useNavigate, useNavigation, useSubmit, type ActionFunctionArgs, type LoaderFunctionArgs } from "react-router"; import { useTranslation } from "react-i18next"; import type { PipelineHandoverVM } from "@hivegrid/view-models"; import { EmptyState } from "~/ui/components/EmptyState"; import { getTranslations } from "~/locale/i18next.server"; import { loadProjectContext, PROJECT_READ_PERMISSIONS, projectActionErrorResponse, requireProjectPermission, requireProjectView } from "~/utils/integrations/projects/projectAccess.server"; import { PROJECTS_MODULE_KEY, projectBoardSettingsPath, projectDetailPath } from "~/utils/integrations/projects/projectRoutePaths"; import { handleKanbanIntent, kanbanIntentPermission, loadKanbanData, parseBoardFacetParams, type KanbanLoaderData, } from "~/utils/integrations/projects/projectBoardRoute.server"; import { ProjectServiceError } from "~/utils/integrations/projects/projectService.server"; import { PipelineKanbanPage } from "~/components/screens/projects/PipelineKanbanPage"; import { useBoardLiveUpdates } from "~/utils/stream/useBoardLiveUpdates"; import { useBoardFacetParams } from "~/hooks/use-board-facet-params"; import { useSaveToast } from "~/hooks/use-save-toast"; const BOARD_SUCCESS_KEYS: Record = { bulkMoveStage: "projects.toast.projectsMoved", duplicateProject: "projects.toast.projectDuplicated", archiveProject: "projects.toast.projectArchived", handoverProject: "projects.toast.handoverCompleted", moveToPipeline: "projects.toast.projectMovedToPipeline", }; type ProjectsBoardLoaderData = KanbanLoaderData | { noPipeline: true; title: string; tenantSlug: string }; export async function loader({ request, params }: LoaderFunctionArgs) { const ctx = await requireProjectView({ request, params }, PROJECT_READ_PERMISSIONS); const { t, locale } = await getTranslations(request); const url = new URL(request.url); try { const data = await loadKanbanData({ tenantSlug: params.tenant!, tenantId: ctx.tenantId, ctx, pipelineId: url.searchParams.get("pipelineId"), onlyMine: url.searchParams.get("onlyMine") === "1", includeDemoData: url.searchParams.get("demo") === "show", q: url.searchParams.get("q"), facets: parseBoardFacetParams(url.searchParams), locale, }); return Response.json(data satisfies KanbanLoaderData); } catch (error) { if (!(error instanceof ProjectServiceError) || error.messageKey !== "projects.error.pipelineRequired") throw error; return Response.json({ noPipeline: true, title: t("projects.list.title"), tenantSlug: params.tenant!, } satisfies ProjectsBoardLoaderData); } } export async function action({ request, params }: ActionFunctionArgs) { const ctx = await loadProjectContext({ request, params, requireModule: true }); const form = await request.formData(); const intent = form.get("_action")?.toString() ?? null; try { requireProjectPermission(ctx, kanbanIntentPermission(intent)); const { createdProjectId, handover } = await handleKanbanIntent({ intent, form, tenantId: ctx.tenantId, ctx }); if (createdProjectId) return redirect(projectDetailPath(params.tenant!, createdProjectId)); // `handover` is non-null only when the move just put a card into a stage // that offers M04 — the screen opens the dialog on it. return Response.json({ ok: true, intent, messageKey: intent ? BOARD_SUCCESS_KEYS[intent] : undefined, handover: handover ?? null }); } catch (error) { return projectActionErrorResponse(error); } } export default function ProjectsBoardRoute() { const { t } = useTranslation(); const data = useLoaderData(); const navigate = useNavigate(); const { setParam, toggleFacet, removeChip, setPeriodRange, resetFilters } = useBoardFacetParams(); const submit = useSubmit(); const navigation = useNavigation(); const actionData = useActionData<{ intent?: string; ok?: boolean; error?: string; messageKey?: string; handover?: PipelineHandoverVM | null }>(); const toastResult = actionData?.error || (actionData?.intent && BOARD_SUCCESS_KEYS[actionData.intent]) ? actionData : undefined; useSaveToast(toastResult); const vmData = "noPipeline" in data ? null : data.vm.status === "ready" ? data.vm.data : null; // Live board: subscribe to the pipeline SSE stream and revalidate on real // change-events (route owns data/revalidation; the screen stays pure). useBoardLiveUpdates(vmData?.sseHref, { paused: navigation.state !== "idle" }); function post(intent: string, fields: Record) { const fd = new FormData(); fd.set("_action", intent); for (const [key, value] of Object.entries(fields)) fd.set(key, value); submit(fd, { method: "post" }); } if ("noPipeline" in data || !vmData) { return (
); } return ( // Full width so the screen's page header bar sits flush like every other list screen.
navigate(detailHref), onHandover: (projectId, fromPipelineId, selection) => post("handoverProject", { projectId, fromPipelineId, selection: JSON.stringify(selection) }), onShowList: () => navigate(data.listHref), // Board settings of THIS board (S04), not the board table — the page // already knows which board it shows. onManageBoard: () => navigate(projectBoardSettingsPath(data.tenantSlug, vmData.pipelineId)), onSwitchPipeline: (pipelineId) => setParam("pipelineId", pipelineId), onToggleOnlyMine: (checked) => setParam("onlyMine", checked ? "1" : ""), onSearch: (q) => setParam("q", q), onToggleFacet: toggleFacet, onRemoveChip: removeChip, onResetFilters: resetFilters, onPeriodRangeChange: setPeriodRange, onToggleDemo: (show) => setParam("demo", show ? "show" : ""), onMove: (projectId, targetStageId, lostReasonId, notiz) => post("moveStage", { projectId, targetStageId, ...(lostReasonId ? { lostReasonId } : {}), ...(notiz ? { notiz } : {}) }), onBulkMove: (projectIds, targetStageId) => post("bulkMoveStage", { projectIds: projectIds.join(","), targetStageId }), onCreateProject: (fields) => post("createProject", { ...fields, pipelineId: data.pipelineId }), onDuplicate: (projectId) => post("duplicateProject", { projectId }), onArchive: (projectId) => post("archiveProject", { projectId }), onUndoStage: (projectId) => post("undoStage", { projectId }), onRedoStage: (projectId) => post("redoStage", { projectId }), onMoveToPipeline: (projectId, targetPipelineId) => post("moveToPipeline", { projectId, targetPipelineId }), }} />
); } export const handle = { moduleKey: PROJECTS_MODULE_KEY };