// R-P8a (P8 Projekt core) — project detail screen (WF-P8 S02), composed from // ~/ui. Pure/presentational: it renders the server-built ProjektDetailData + // ActivityStreamVM and turns every action (stammdaten inline-edit, stage move, // 24h-undo) into a single typed onSubmit(intent, fields) callback the route // POSTs. Moving into a "verloren" stage opens a real Dialog to capture the // mandatory lost reason. No useLoaderData/useFetcher, no server imports. // // This file assembles; the sections live in ./detail. It owns exactly one piece // of shared state — the stammdaten draft — because the screen has a single save // path and splitting that across sections is how a second one appears. import { useState } from "react"; import { useTranslation } from "react-i18next"; import type { ActivityStreamVM, PipelineHandoverKind, PipelineHandoverVM, ProjektDetailData } from "@hivegrid/view-models"; import { PageBody, 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 { Select } from "~/ui/components/Select"; import { APP_TIME_ZONE } from "~/locale/format"; import { ClickToCallEntryPoint, type ClickToCallEntryPointProps } from "../telephony/ClickToCallDialog"; import { CreateAppointmentDialog, CreateNoteDialog, CreateTaskDialog, UploadFileDialog, type ProjectAssigneeOption, } from "./dialogs/ProjectQuickActionDialogs"; import { PipelineHandoverDialog } from "./dialogs/PipelineHandoverDialog"; import { AdressenSection } from "./detail/AdressenSection"; import { DetailSideRail, type ProjektDetailRailDocument, type ProjektDetailRailEntry } from "./detail/DetailSideRail"; import { DetailHeader } from "./detail/DetailHeader"; import { DetailQuickActionBar } from "./detail/DetailQuickActionBar"; import { GrunddatenSection } from "./detail/GrunddatenSection"; import { KontakteSection } from "./detail/KontakteSection"; import { KwpSection } from "./detail/KwpSection"; import { PlanungSection, type ProjektDetailOwnerOption } from "./detail/PlanungSection"; import { ProjektkontaktSection } from "./detail/ProjektkontaktSection"; import { mutedText, sectionHeading, toStammdatenState, type ProjektDetailSubmit } from "./detail/detailUi"; export type { ProjektDetailOwnerOption, ProjektDetailRailDocument, ProjektDetailSubmit }; export type ProjektDetailPageActions = { onSubmit: ProjektDetailSubmit }; /** WF-P8 S02 quick-action bar + M04 wiring supplied by the route. */ export type ProjektDetailQuickActions = { /** Directory for the assignee pickers in the task/appointment modals. */ assigneeOptions: readonly ProjectAssigneeOption[]; /** True when the actor may pick "Nur Innendienst" as a note visibility. */ canChooseInternalNote: boolean; /** Chunked upload injected by the route (S02-F uploads before linking). */ uploadFile: (file: File) => Promise<{ id: string; displayName: string }>; /** * M04 payload. Present only when the project sits in the final stage of a * pipeline that declares a successor — the dialog opens automatically then, * it is never opened by a button (validated with David). */ handover?: PipelineHandoverVM | null; }; export type ProjektDetailPageProps = { data: ProjektDetailData; activity: ActivityStreamVM; ownerOptions: readonly ProjektDetailOwnerOption[]; /** Project documents for the S02 rail; hrefs are resolved by the route. */ documents?: readonly ProjektDetailRailDocument[]; backHref: string; /** * Loader-only JSON resource behind the contact search of the add-contact block. * Injected as a prop, because a UI component must not know how the route tree * is laid out. */ contactSearchHref: string; /** * Read-only rows of the five rail areas besides Dateien. Resolved by the route: * appointments and tasks come from the operations data it already loads, notes * and history from their own readers. */ railAreas?: { history: readonly ProjektDetailRailEntry[]; appointments: readonly ProjektDetailRailEntry[]; tasks: readonly ProjektDetailRailEntry[]; notes: readonly ProjektDetailRailEntry[]; activity: readonly ProjektDetailRailEntry[]; }; /** Anchor of the operations panel below, for the "manage" link of a tile. */ operationsHref?: string; submitting: boolean; errorKey?: string | null; messageKey?: string | null; language?: string; /** Optional telephony affordance; omitted when the feature or permission gate is closed. */ clickToCall?: ClickToCallEntryPointProps; /** WF-P8 S02 quick actions; omitted when the actor cannot write. */ quickActions?: ProjektDetailQuickActions; actions: ProjektDetailPageActions; }; export function ProjektDetailPage(props: ProjektDetailPageProps) { const { t, i18n } = useTranslation(); const { data } = props; const submit = props.actions.onSubmit; const dateTime = new Intl.DateTimeFormat(props.language ?? i18n.language, { timeZone: APP_TIME_ZONE, dateStyle: "medium", timeStyle: "short" }); const [stammdaten, setStammdaten] = useState(() => toStammdatenState(data)); const [lostDialogStageId, setLostDialogStageId] = useState(null); const [lostReasonId, setLostReasonId] = useState(data.lostReasons[0]?.id ?? ""); // WF-P8 S02 quick actions. `null` = no modal open. const [quickAction, setQuickAction] = useState<"note" | "task" | "appointment" | "file" | null>(null); const quickActions = props.quickActions; // Quick-action targets: the project's own contact data, else the primary // linked contact's — a project without its own mailbox still has someone to // write to, and a greyed-out button says the opposite. const primaryKontakt = data.kontakte.find((kontakt) => kontakt.primaer) ?? data.kontakte[0] ?? null; const quickActionMail = data.email ?? primaryKontakt?.email ?? null; const quickActionPhone = data.telefon ?? primaryKontakt?.telefon ?? null; const handoverVM = quickActions?.handover ?? null; // M04 is status-driven, not button-driven: it opens as soon as the loader // reports a pending handover, and closing it is an explicit dismissal. const [handoverDismissed, setHandoverDismissed] = useState(false); // Single stammdaten submit path (used by the edit banner; no duplicate logic). function saveStammdaten() { submit("updateStammdaten", { projektname: stammdaten.projektname, beschreibung: stammdaten.beschreibung, prioritaet: stammdaten.prioritaet, startDatum: stammdaten.startDatum, deadline: stammdaten.deadline, zustaendigePersonId: stammdaten.zustaendigePersonId, projektleiterId: stammdaten.projektleiterId, projekttyp: stammdaten.projekttyp, quelle: stammdaten.quelle, promotion: stammdaten.promotion, email: stammdaten.email, telefon: stammdaten.telefon, fax: stammdaten.fax, ...(data.valueVisible ? { potenziellerAuftragswert: stammdaten.potenziellerAuftragswert, auftragsvolumen: stammdaten.auftragsvolumen } : {}), }); } /** * Panel upload: file straight onto the project, without the modal. Category * and description stay with the quick action — the panel is for "put this * file on the project", the modal for filing it properly. */ async function uploadToProject(file: File) { if (!quickActions) return; const uploaded = await quickActions.uploadFile(file); submit("attachFile", { fileId: uploaded.id, kategorie: "sonstiges", beschreibung: "" }); } /** Sections report a patch; the draft itself stays here (single save path). */ function patchStammdaten(patch: Partial) { setStammdaten((s) => ({ ...s, ...patch })); } function moveToStage(stageId: string, stageKind: string) { if (stageKind === "verloren") { setLostReasonId(data.lostReasons[0]?.id ?? ""); setLostDialogStageId(stageId); return; } submit("moveStage", { targetStageId: stageId }); } function confirmLost() { if (!lostDialogStageId || !lostReasonId) return; submit("moveStage", { targetStageId: lostDialogStageId, lostReasonId }); setLostDialogStageId(null); } return ( {/* The header band runs the full width of the page; the pipeline panel is a column below it, not a strip pinned across it. */}
{props.errorKey ? (
{t(props.errorKey)}
) : null} {props.messageKey ? ( ) : null} {/* --- Won/Lost banner with 24h undo --- */} {data.outcome ? (
{t(data.outcome.kind === "gewonnen" ? "projects.outcome.won" : "projects.outcome.lost")} {data.outcome.lostReasonName ? {data.outcome.lostReasonName} : null} {data.outcome.atIso ? ( {dateTime.format(new Date(data.outcome.atIso))} ) : null} {data.outcome.canUndo ? ( ) : null}
) : null} {/* The columns are wider than a laptop's leftover width once the pipeline panel has its 340px, so the pair scrolls sideways in its own strip. Without it the overflowing column would end up behind the panel with no way to reach it. */}
{/* Two columns, as in the export: the project's own data on the left, the records it is linked to on the right. The left one is the wider of the two — it carries the label gutter plus a full-width control per row. Both have a minimum, so the pair scrolls sideways instead of squeezing the fields into unreadable stubs. They stack below 1024px. */}
{/* Above the contacts, as in the export — and only for a project that actually is bound to a KWP project. */}
{/* Sits at the end of the main column so it sticks above the content without covering the last field of the page. */} {quickActions ? ( : undefined} /> ) : null}
{/* Outside PageBody on purpose: the panel is the row's own column and sticks to the window, so it must not sit in a column that scrolls. */}
{/* --- S02 quick-action modals (A/N/T/F) --- */} {quickActions ? ( <> setQuickAction(open ? "note" : null)} submitting={props.submitting} canChooseInternal={quickActions.canChooseInternalNote} onSubmit={(intent, fields) => { submit(intent, fields); setQuickAction(null); }} /> setQuickAction(open ? "task" : null)} submitting={props.submitting} assigneeOptions={quickActions.assigneeOptions} onSubmit={(intent, fields) => { submit(intent, fields); setQuickAction(null); }} /> setQuickAction(open ? "appointment" : null)} submitting={props.submitting} assigneeOptions={quickActions.assigneeOptions} onSubmit={(intent, fields) => { submit(intent, fields); setQuickAction(null); }} /> setQuickAction(open ? "file" : null)} submitting={props.submitting} uploadFile={quickActions.uploadFile} onSubmit={(intent, fields) => { submit(intent, fields); setQuickAction(null); }} /> ) : null} {/* --- M04 pipeline handover (status-driven, no trigger button) --- */} {handoverVM ? ( setHandoverDismissed(!open)} onConfirm={(selection: readonly { kind: PipelineHandoverKind; sourceId: string }[]) => { submit("handoverProject", { selection: JSON.stringify(selection) }); setHandoverDismissed(true); }} /> ) : null} {/* --- Lost-reason dialog (mandatory when moving to a verloren stage) --- */} (open ? null : setLostDialogStageId(null))}>
{t("projects.lostDialog.title")}
); } export default ProjektDetailPage;