Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -0,0 +1,224 @@
// WF-P8 S02 "Firma oder Kontakt hinzufügen" — the block below the contact cards
// with Davids three paths.
//
// Searching and creating are two dialogs, not one form with a mode switch: the
// search needs a result list and the creation needs name fields, and putting
// both behind one control would hide half of it at any time.
//
// The search hits the loader-only `contact-search` resource of this project, so
// a keystroke costs one contact query instead of re-running the whole detail
// loader. Creation goes through the CRM service on the server side, so a project
// never becomes a second place where contacts are born.
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { FeatherBuilding2, FeatherPlus, FeatherSearch, FeatherUserPlus } from "@subframe/core";
import * as SubframeCore from "@subframe/core";
import { Button } from "~/ui/components/Button";
import { Dialog } from "~/ui/components/Dialog";
import { DropdownMenu } from "~/ui/components/DropdownMenu";
import { TextInput } from "~/ui/components/TextInput";
import { labelText, mutedText, sectionHeading, type ProjektDetailSubmit } from "./detailUi";
export type AddKontaktBlockProps = {
/** Search endpoint of this project (loader-only JSON resource). */
searchHref: string;
submitting: boolean;
submit: ProjektDetailSubmit;
};
type SearchRow = { id: string; label: string; kontaktTyp: "organisation" | "privatperson"; email: string | null };
type Mode = "search" | "person" | "company";
export function AddKontaktBlock({ searchHref, submitting, submit }: AddKontaktBlockProps) {
const { t } = useTranslation();
const [mode, setMode] = useState<Mode | null>(null);
const [query, setQuery] = useState("");
const [rows, setRows] = useState<SearchRow[]>([]);
const [searchState, setSearchState] = useState<"idle" | "loading" | "failed">("idle");
const [draft, setDraft] = useState({ vorname: "", nachname: "", orgName: "", email: "" });
// Debounced, and aborted on the next keystroke: without the abort a slow early
// response can overwrite the results of a later, narrower query.
useEffect(() => {
if (mode !== "search") return;
const controller = new AbortController();
const timer = setTimeout(() => {
setSearchState("loading");
fetch(`${searchHref}?q=${encodeURIComponent(query)}`, { signal: controller.signal })
.then((response) => (response.ok ? response.json() : Promise.reject(new Error(String(response.status)))))
.then((data: { rows: SearchRow[] }) => {
setRows(data.rows);
setSearchState("idle");
})
.catch((error: unknown) => {
if (error instanceof DOMException && error.name === "AbortError") return;
setSearchState("failed");
});
}, 250);
return () => {
controller.abort();
clearTimeout(timer);
};
}, [mode, query, searchHref]);
function close() {
setMode(null);
setQuery("");
setRows([]);
setSearchState("idle");
setDraft({ vorname: "", nachname: "", orgName: "", email: "" });
}
function link(kontaktId: string) {
submit("linkKontakt", { kontaktId });
close();
}
function create(kontaktTyp: "privatperson" | "organisation") {
submit("createKontakt", {
kontaktTyp,
vorname: draft.vorname,
nachname: draft.nachname,
orgName: draft.orgName,
email: draft.email,
});
close();
}
const createDisabled = mode === "person" ? !draft.nachname.trim() : !draft.orgName.trim();
return (
<div className="flex w-full flex-col gap-2 px-3 pb-1" data-ui-id="ui.projects.detail.contacts.add">
{/* Rule between the linked contacts and the way to add one, as in the
export: the button belongs to the tile, not to the last contact. */}
{/* Same hairline the field rows use, so the tile has one kind of rule. */}
<div className="h-px w-full flex-none bg-icon-neutral-subtle" />
{/* The export closes the tile with one dark button. The three paths stay —
they are three separate dialogs — but they hang behind that button
instead of standing next to each other in the tile. */}
<SubframeCore.DropdownMenu.Root>
<SubframeCore.DropdownMenu.Trigger asChild>
<Button className="w-3/5 justify-center mobile:w-full" size="small" icon={<FeatherPlus />} data-ui-id="ui.projects.detail.contacts.add.trigger">
{t("projects.detail.contacts.add.title")}
</Button>
</SubframeCore.DropdownMenu.Trigger>
<SubframeCore.DropdownMenu.Portal>
<SubframeCore.DropdownMenu.Content side="bottom" align="start" sideOffset={4} asChild>
<DropdownMenu>
<DropdownMenu.DropdownItem icon={<FeatherSearch />} onSelect={() => setMode("search")} data-ui-id="ui.projects.detail.contacts.add.search">
{t("projects.detail.contacts.add.search")}
</DropdownMenu.DropdownItem>
<DropdownMenu.DropdownItem icon={<FeatherUserPlus />} onSelect={() => setMode("person")} data-ui-id="ui.projects.detail.contacts.add.person">
{t("projects.detail.contacts.add.person")}
</DropdownMenu.DropdownItem>
<DropdownMenu.DropdownItem icon={<FeatherBuilding2 />} onSelect={() => setMode("company")} data-ui-id="ui.projects.detail.contacts.add.company">
{t("projects.detail.contacts.add.company")}
</DropdownMenu.DropdownItem>
</DropdownMenu>
</SubframeCore.DropdownMenu.Content>
</SubframeCore.DropdownMenu.Portal>
</SubframeCore.DropdownMenu.Root>
<Dialog open={mode === "search"} onOpenChange={(open) => (open ? null : close())}>
<Dialog.Content className="p-6" data-ui-id="ui.projects.detail.contacts.add.searchDialog">
<div className="flex w-full flex-col gap-3">
<span className={sectionHeading}>{t("projects.detail.contacts.add.search")}</span>
<TextInput label="" className="w-full" icon={<FeatherSearch />}>
<TextInput.Input
placeholder={t("projects.detail.contacts.add.searchPlaceholder")}
value={query}
onChange={(event) => setQuery(event.target.value)}
data-ui-id="ui.projects.detail.contacts.add.searchInput"
/>
</TextInput>
{searchState === "failed" ? (
<span className={mutedText} data-ui-id="ui.projects.detail.contacts.add.searchError">
{t("projects.detail.contacts.add.searchFailed")}
</span>
) : null}
{searchState !== "failed" && rows.length === 0 ? (
<span className={mutedText}>{t("projects.detail.contacts.add.searchEmpty")}</span>
) : null}
<div className="flex max-h-[280px] w-full flex-col gap-1 overflow-y-auto">
{rows.map((row) => (
<button
key={row.id}
type="button"
className="flex w-full items-center justify-between gap-3 rounded-md px-2 py-2 text-left hover:bg-surface-neutral-tertiary"
onClick={() => link(row.id)}
disabled={submitting}
data-ui-id={`ui.projects.detail.contacts.add.result.${row.id}`}
>
<span className={labelText}>{row.label}</span>
<span className={mutedText}>{row.email ?? t(`crm.kontaktTyp.${row.kontaktTyp}`)}</span>
</button>
))}
</div>
</div>
</Dialog.Content>
</Dialog>
<Dialog open={mode === "person" || mode === "company"} onOpenChange={(open) => (open ? null : close())}>
<Dialog.Content className="p-6" data-ui-id="ui.projects.detail.contacts.add.createDialog">
<div className="flex w-full flex-col gap-3">
<span className={sectionHeading}>
{mode === "company" ? t("projects.detail.contacts.add.company") : t("projects.detail.contacts.add.person")}
</span>
{mode === "company" ? (
<TextInput label={t("crm.fields.orgName")} showLabel className="w-full">
<TextInput.Input
value={draft.orgName}
onChange={(event) => setDraft((state) => ({ ...state, orgName: event.target.value }))}
data-ui-id="ui.projects.detail.contacts.add.orgName"
/>
</TextInput>
) : (
<>
<TextInput label={t("crm.fields.vorname")} showLabel className="w-full">
<TextInput.Input
value={draft.vorname}
onChange={(event) => setDraft((state) => ({ ...state, vorname: event.target.value }))}
data-ui-id="ui.projects.detail.contacts.add.vorname"
/>
</TextInput>
<TextInput label={t("crm.fields.nachname")} showLabel className="w-full">
<TextInput.Input
value={draft.nachname}
onChange={(event) => setDraft((state) => ({ ...state, nachname: event.target.value }))}
data-ui-id="ui.projects.detail.contacts.add.nachname"
/>
</TextInput>
</>
)}
<TextInput label={t("projects.fields.email")} showLabel className="w-full">
<TextInput.Input
type="email"
value={draft.email}
onChange={(event) => setDraft((state) => ({ ...state, email: event.target.value }))}
data-ui-id="ui.projects.detail.contacts.add.email"
/>
</TextInput>
<div className="flex justify-end gap-2">
<Button variant="tertiary" size="small" onClick={close}>
{t("projects.actions.cancel")}
</Button>
<Button
variant="neutral"
size="small"
icon={<FeatherPlus />}
disabled={createDisabled}
loading={submitting}
onClick={() => create(mode === "company" ? "organisation" : "privatperson")}
data-ui-id="ui.projects.detail.contacts.add.createSubmit"
>
{t("projects.actions.save")}
</Button>
</div>
</div>
</Dialog.Content>
</Dialog>
</div>
);
}
@@ -0,0 +1,283 @@
// WF-P8 S02 "Adressdaten" — built like the contacts tile: a divider-headed
// group whose rows fold, one row per address slot.
//
// The project has three address slots (`projektAdresseId`, `rechnungsAdresseId`,
// `bauherrAdresseId`). The export gates the latter two behind "separate
// Rechnungsadresse" / "separate Bauherradresse" switches, which is exactly the
// slot being set or cleared, so the switch is the FK and not a display flag.
//
// This section keeps its own draft and its own save: the slots write through
// `updateAddresses`, not through the stammdaten path, and mixing them would put
// two intents behind one button.
//
// The per-slot extras (Bauabschnitt/Zufahrt/Koordinaten on the site address,
// Empfaenger/Zahlungsziel/Rechnungs-Mail on the invoice one, Post-erwuenscht plus
// the on-site contact on the Bauherr slot, and a free-text note on each) live in
// `ProjektAdressDetail` and are edited right here — the slot they belong to is
// the only place their meaning is clear.
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { FeatherMapPin } from "@subframe/core";
import type { ProjektAdressSlot, ProjektDetailAdresse, ProjektDetailData } from "@hivegrid/view-models";
import { Accordion } from "~/ui/components/Accordion";
import { Button } from "~/ui/components/Button";
import { Switch } from "~/ui/components/Switch";
import { TextArea } from "~/ui/components/TextArea";
import { TextInput } from "~/ui/components/TextInput";
import { DetailCard, FieldRow, SectionDivider, mutedText, type ProjektDetailSubmit } from "./detailUi";
export type AdressenSectionProps = {
data: ProjektDetailData;
submitting: boolean;
submit: ProjektDetailSubmit;
};
const EMPTY: ProjektDetailAdresse = {
strasse: "",
hausnummer: "",
plz: "",
ort: "",
land: "DE",
bauabschnitt: "",
zufahrt: "",
koordinaten: "",
empfaenger: "",
zahlungsziel: "",
rechnungsEmail: "",
postErwuenscht: false,
telefon: "",
ansprechpartnerVorOrt: "",
notizen: "",
};
/**
* The slot extras from `ProjektAdressDetail`. Each slot shows only its own: a
* Zahlungsziel on the site address or a Zufahrt on the invoice address would be
* a field nobody fills.
*/
type SlotExtraKey =
| "bauabschnitt"
| "zufahrt"
| "koordinaten"
| "empfaenger"
| "zahlungsziel"
| "rechnungsEmail"
| "telefon"
| "ansprechpartnerVorOrt";
const SLOT_EXTRAS: Record<ProjektAdressSlot, { key: SlotExtraKey; labelKey: string }[]> = {
projekt: [
{ key: "bauabschnitt", labelKey: "projects.detail.addresses.section" },
{ key: "zufahrt", labelKey: "projects.detail.addresses.access" },
{ key: "koordinaten", labelKey: "projects.detail.addresses.coordinates" },
],
rechnung: [
{ key: "empfaenger", labelKey: "projects.detail.addresses.recipient" },
{ key: "zahlungsziel", labelKey: "projects.detail.addresses.paymentTerms" },
{ key: "rechnungsEmail", labelKey: "projects.detail.addresses.invoiceEmail" },
],
bauherr: [
{ key: "telefon", labelKey: "projects.fields.phone" },
{ key: "ansprechpartnerVorOrt", labelKey: "projects.detail.addresses.onSiteContact" },
],
};
/** The project address is always shown; the other two are opt-in slots. */
const SLOTS: { slot: ProjektAdressSlot; labelKey: string; optional: boolean }[] = [
{ slot: "projekt", labelKey: "projects.detail.addresses.project", optional: false },
{ slot: "rechnung", labelKey: "projects.detail.addresses.invoice", optional: true },
{ slot: "bauherr", labelKey: "projects.detail.addresses.owner", optional: true },
];
type DraftState = Record<ProjektAdressSlot, { enabled: boolean; value: ProjektDetailAdresse }>;
function toDraft(data: ProjektDetailData): DraftState {
return {
projekt: { enabled: true, value: data.adressen.projekt ?? EMPTY },
rechnung: { enabled: data.adressen.rechnung !== null, value: data.adressen.rechnung ?? EMPTY },
bauherr: { enabled: data.adressen.bauherr !== null, value: data.adressen.bauherr ?? EMPTY },
};
}
function formatAddress(address: ProjektDetailAdresse | null): string | null {
if (!address) return null;
const street = [address.strasse, address.hausnummer].filter(Boolean).join(" ");
const city = [address.plz, address.ort].filter(Boolean).join(" ");
const line = [street, city].filter(Boolean).join(", ");
return line || null;
}
export function AdressenSection({ data, submitting, submit }: AdressenSectionProps) {
const { t } = useTranslation();
const [draft, setDraft] = useState<DraftState>(() => toDraft(data));
function patch(slot: ProjektAdressSlot, part: Partial<ProjektDetailAdresse>) {
setDraft((state) => ({ ...state, [slot]: { ...state[slot], value: { ...state[slot].value, ...part } } }));
}
function toggle(slot: ProjektAdressSlot, enabled: boolean) {
setDraft((state) => ({ ...state, [slot]: { ...state[slot], enabled } }));
}
function save() {
// A disabled slot posts null, which clears the FK server-side.
const slots: Record<string, ProjektDetailAdresse | null> = {};
for (const entry of SLOTS) slots[entry.slot] = draft[entry.slot].enabled ? draft[entry.slot].value : null;
submit("updateAddresses", { slots: JSON.stringify(slots) });
}
return (
<DetailCard uiId="ui.projects.detail.addresses">
<SectionDivider icon={<FeatherMapPin />} title={t("projects.detail.section.addresses")} uiId="ui.projects.detail.section.addresses" />
{/* Same shape as the contacts tile: one foldable row per slot, name and
the address itself in the head, the fields inside. The project address
is always there, the other two hang behind their switch. */}
{SLOTS.map((entry) => {
const summary = formatAddress(data.canWrite ? draft[entry.slot].value : data.adressen[entry.slot]);
const enabled = draft[entry.slot].enabled;
// An optional slot that is switched off has no row at all — the project
// simply has one address then.
if (entry.optional && !enabled) return null;
return (
<Accordion
key={entry.slot}
variant="ghost"
className="w-full"
data-ui-id={`ui.projects.detail.addresses.${entry.slot}`}
trigger={
<div className="flex w-full items-center gap-2 px-3 py-4" data-ui-id={`ui.projects.detail.addresses.${entry.slot}.trigger`}>
<Accordion.Chevron />
<span className="flex h-9 w-9 flex-none items-center justify-center rounded-md bg-surface-neutral-tertiary text-icon-neutral-secondary">
<FeatherMapPin />
</span>
<span className="flex min-w-0 grow shrink-0 basis-0 flex-col items-start gap-0.5">
<span className="text-body-small-semibold-0 font-body-small-semibold-0 text-text-neutral-primary">{t(entry.labelKey)}</span>
<span className="w-full break-words text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
{summary ?? t("projects.detail.addresses.empty")}
</span>
</span>
</div>
}
>
<div className="flex w-full flex-col gap-2 px-3 pb-3">
{!data.canWrite ? (
<span className={mutedText}>{summary ?? t("projects.fields.none")}</span>
) : (
<AddressFields slot={entry.slot} value={draft[entry.slot].value} onChange={(part) => patch(entry.slot, part)} />
)}
{/* The two optional slots are switched on from inside the project
address — they only exist because this project needs a second
address, so that decision belongs to the first one. */}
{entry.slot === "projekt" && data.canWrite
? SLOTS.filter((other) => other.optional).map((other) => (
<FieldRow
key={other.slot}
icon={<FeatherMapPin />}
label={t(other.labelKey)}
uiId={`ui.projects.detail.addresses.${other.slot}.separate`}
>
<Switch
checked={draft[other.slot].enabled}
onCheckedChange={(checked: boolean) => toggle(other.slot, checked)}
data-ui-id={`ui.projects.detail.addresses.${other.slot}.toggle`}
/>
</FieldRow>
))
: null}
{/* Saving sits where the editing happens, at the end of the open
slot. It posts all three slots in one intent, so it says the
same thing wherever it is pressed. */}
{data.canWrite ? (
<div className="flex w-full justify-end pt-1">
<Button
variant="neutral"
size="small"
loading={submitting}
onClick={save}
data-ui-id={`ui.projects.detail.addresses.${entry.slot}.save`}
>
{t("projects.actions.save")}
</Button>
</div>
) : null}
</div>
</Accordion>
);
})}
</DetailCard>
);
}
function AddressFields({
slot,
value,
onChange,
}: {
slot: ProjektAdressSlot;
value: ProjektDetailAdresse;
onChange: (part: Partial<ProjektDetailAdresse>) => void;
}) {
const { t } = useTranslation();
const uiId = `ui.projects.detail.addresses.${slot}`;
return (
<DetailCard>
<FieldRow label={t("projects.detail.addresses.street")} uiId={`${uiId}.street`}>
<TextInput label="" className="w-full">
<TextInput.Input value={value.strasse} onChange={(e) => onChange({ strasse: e.target.value })} data-ui-id={`${uiId}.strasse`} />
</TextInput>
</FieldRow>
<FieldRow label={t("projects.detail.addresses.houseNumber")} uiId={`${uiId}.houseNumber`}>
<TextInput label="" className="w-full">
<TextInput.Input value={value.hausnummer} onChange={(e) => onChange({ hausnummer: e.target.value })} data-ui-id={`${uiId}.hausnummer`} />
</TextInput>
</FieldRow>
<FieldRow label={t("projects.detail.addresses.postalCode")} uiId={`${uiId}.postalCode`}>
<TextInput label="" className="w-full">
<TextInput.Input value={value.plz} onChange={(e) => onChange({ plz: e.target.value })} data-ui-id={`${uiId}.plz`} />
</TextInput>
</FieldRow>
<FieldRow label={t("projects.detail.addresses.city")} uiId={`${uiId}.city`}>
<TextInput label="" className="w-full">
<TextInput.Input value={value.ort} onChange={(e) => onChange({ ort: e.target.value })} data-ui-id={`${uiId}.ort`} />
</TextInput>
</FieldRow>
<FieldRow label={t("projects.detail.addresses.country")} uiId={`${uiId}.country`}>
<TextInput label="" className="w-full">
<TextInput.Input value={value.land} onChange={(e) => onChange({ land: e.target.value })} data-ui-id={`${uiId}.land`} />
</TextInput>
</FieldRow>
{SLOT_EXTRAS[slot].map((extra) => (
<FieldRow key={extra.key} label={t(extra.labelKey)} uiId={`${uiId}.${extra.key}Row`}>
<TextInput label="" className="w-full">
<TextInput.Input
value={value[extra.key]}
onChange={(e) => onChange({ [extra.key]: e.target.value })}
data-ui-id={`${uiId}.${extra.key}`}
/>
</TextInput>
</FieldRow>
))}
{slot === "bauherr" ? (
<FieldRow label={t("projects.detail.addresses.postWanted")} uiId={`${uiId}.postWantedRow`}>
<Switch
checked={value.postErwuenscht}
onCheckedChange={(checked: boolean) => onChange({ postErwuenscht: checked })}
data-ui-id={`${uiId}.postErwuenscht`}
/>
</FieldRow>
) : null}
{/* The note closes each slot, as in the export: it comments on the address
above it, so it belongs to that slot and not to the section. */}
<FieldRow label={t("projects.detail.addresses.notes")} uiId={`${uiId}.notesRow`}>
<TextArea label="" className="w-full">
<TextArea.Input
value={value.notizen}
onChange={(event) => onChange({ notizen: event.target.value })}
data-ui-id={`${uiId}.notizen`}
/>
</TextArea>
</FieldRow>
</DetailCard>
);
}
@@ -0,0 +1,75 @@
// WF-P8 S02 header — project name with the board it sits on underneath, and the
// export's three controls: the copyable project id, the way back to the board
// ("Pipeline") and the single save action.
//
// Built on the app shell's PageHeader rather than on the export's own header
// row, so the detail page keeps the same title band as every other screen; the
// export's pieces sit in the actions slot. The bar is `dense` — the S02 header
// is a one-line strip in the export, not the tall title band of a list screen.
import { useTranslation } from "react-i18next";
import { FeatherArrowLeftRight, FeatherCheck, FeatherKanbanSquare, FeatherLock } from "@subframe/core";
import type { ProjektDetailData } from "@hivegrid/view-models";
import { Button } from "~/ui/components/Button";
import { CopyToClipboardButton } from "~/ui/components/CopyToClipboardButton";
import { PageHeader } from "../../shared/PageShell";
import { AppLink } from "~/components/app/AppLink";
export type DetailHeaderProps = {
data: ProjektDetailData;
/** Back to the board this project sits on — the export's "Pipeline" button. */
backHref: string;
submitting: boolean;
/** Single save path of the whole screen; absent for a reader. */
onSave?: () => void;
};
export function DetailHeader({ data, backHref, submitting, onSave }: DetailHeaderProps) {
const { t } = useTranslation();
return (
<PageHeader
uiId="ui.projects.detail.header"
dense
title={data.projektname}
// The board reads as the line under the project name — as the export's
// pill, so it says "you are inside this pipeline" instead of looking like
// a description of the project.
subtitle={
<span className="rounded-round bg-surface-neutral-tertiary inline-flex items-center gap-1.5 px-2.5 py-1" data-ui-id="ui.projects.detail.header.board">
<FeatherKanbanSquare className="text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-icon-neutral-tertiary" />
<span className="text-body-extra-small-medium-0 font-body-extra-small-medium-0 text-text-neutral-secondary">{data.pipelineName}</span>
</span>
}
actions={
<>
<span
className="border-border-default bg-surface-neutral-tertiary flex items-center gap-2 rounded-md border border-solid px-2.5 py-1"
data-ui-id="ui.projects.detail.header.projectId"
>
<FeatherLock className="text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-icon-neutral-tertiary" />
<span className="text-body-extra-small-medium-0 font-body-extra-small-medium-0 text-text-neutral-tertiary">
{t("projects.detail.projectIdLabel")}
</span>
<span className="text-body-small-semibold-0 font-body-small-semibold-0 text-text-neutral-secondary">{data.projektNummer}</span>
<CopyToClipboardButton
clipboardText={data.projektNummer}
tooltipText={t("projects.detail.copyProjectId")}
successKey="projects.detail.toast.projectIdCopied"
data-ui-id="ui.projects.detail.header.copyProjectId"
/>
</span>
<AppLink href={backHref} data-ui-id="ui.projects.detail.header.board.link">
<Button variant="tertiary" size="small" icon={<FeatherArrowLeftRight />}>
{t("projects.actions.pipeline")}
</Button>
</AppLink>
{onSave ? (
<Button size="small" icon={<FeatherCheck />} loading={submitting} onClick={onSave} data-ui-id="ui.projects.detail.stammdaten.save">
{t("projects.actions.save")}
</Button>
) : null}
</>
}
/>
);
}
@@ -0,0 +1,75 @@
// WF-P8 S02 — "Priorität" as the export draws it: a select whose trigger and
// options are coloured badges, not a text row.
//
// Same shape as DetailStatusField (the synced Select of this kit carries no
// `selectedContent`, so a badge trigger needs the DropdownMenuSelect), but the
// value rides in the stammdaten draft — priority is saved with the rest.
import { useTranslation } from "react-i18next";
import { FeatherChevronDown } from "@subframe/core";
import * as SubframeCore from "@subframe/core";
import { Badge } from "~/ui/components/Badge";
import { DropdownMenuSelect } from "~/ui/components/DropdownMenuSelect";
import { PRIORITIES } from "./detailUi";
/** Export tones: Niedrig green, Mittel yellow, Hoch red, Kritisch violet. */
const PRIORITY_TONE: Record<string, "green-solid" | "yellow-solid" | "red-solid" | "violet-solid"> = {
niedrig: "green-solid",
normal: "yellow-solid",
hoch: "red-solid",
dringend: "violet-solid",
};
export type DetailPriorityFieldProps = {
value: string;
onChange: (prioritaet: string) => void;
/** A reader sees the badge alone — there is nothing to pick. */
readOnly?: boolean;
};
export function DetailPriorityField({ value, onChange, readOnly }: DetailPriorityFieldProps) {
const { t } = useTranslation();
const badge = (
<Badge tone={PRIORITY_TONE[value] ?? "yellow-solid"} size="small" data-ui-id="ui.projects.detail.priority.current">
{t(`projects.priority.${value}`)}
</Badge>
);
if (readOnly) return badge;
return (
<SubframeCore.DropdownMenu.Root>
<SubframeCore.DropdownMenu.Trigger asChild>
{/* Borderless like the export's filled select: the badge stands raw in
the row and only the chevron marks the far right as the handle. */}
<button
type="button"
className="flex h-8 w-full items-center justify-between gap-2 rounded-md px-1 hover:bg-surface-neutral-tertiary"
aria-label={t("projects.fields.priority")}
data-ui-id="ui.projects.detail.priority.trigger"
>
{badge}
<FeatherChevronDown className="text-body-small-regular-0 font-body-small-regular-0 text-icon-neutral-tertiary" />
</button>
</SubframeCore.DropdownMenu.Trigger>
<SubframeCore.DropdownMenu.Portal>
<SubframeCore.DropdownMenu.Content side="bottom" align="start" sideOffset={4} asChild>
<DropdownMenuSelect>
{PRIORITIES.map((prioritaet) => (
<DropdownMenuSelect.DropdownItem
key={prioritaet}
selected={prioritaet === value}
onSelect={() => onChange(prioritaet)}
data-ui-id={`ui.projects.detail.priority.${prioritaet}`}
>
<Badge tone={PRIORITY_TONE[prioritaet]} size="small">
{t(`projects.priority.${prioritaet}`)}
</Badge>
</DropdownMenuSelect.DropdownItem>
))}
</DropdownMenuSelect>
</SubframeCore.DropdownMenu.Content>
</SubframeCore.DropdownMenu.Portal>
</SubframeCore.DropdownMenu.Root>
);
}
@@ -0,0 +1,81 @@
// WF-P8 S02 — the floating quick-action bar (Anrufen, E-Mail, Termin, Aufgabe,
// Notiz, Hochladen).
//
// Two deliberate deviations from the export:
// * `sticky bottom-4` at the end of the main column, not `absolute`. The app
// shell's <main> is the scroll container, so an absolutely placed bar would
// scroll away with the content instead of staying reachable.
// * The export hides the bar on mobile. It is the only entry to the four
// quick-action modals, so hiding it there would remove the actions rather
// than the decoration.
import { useTranslation } from "react-i18next";
import { FeatherCalendarPlus, FeatherCheckSquare, FeatherMail, FeatherPhone, FeatherStickyNote, FeatherUpload } from "@subframe/core";
import { Button } from "~/ui/components/Button";
export type DetailQuickAction = "note" | "task" | "appointment" | "file";
export type DetailQuickActionBarProps = {
onOpen: (action: DetailQuickAction) => void;
/** Direct actions, not modals. Omitted when there is no number/address. */
callHref?: string | null;
mailHref?: string | null;
/** Telephony entry point of the tenant, if the feature gate is open. */
callSlot?: React.ReactNode;
};
export function DetailQuickActionBar({ onOpen, callHref, mailHref, callSlot }: DetailQuickActionBarProps) {
const { t } = useTranslation();
return (
<div className="sticky bottom-4 z-10 flex w-full justify-center" data-ui-id="ui.projects.detail.quickActions">
{/* One line, always. When the bar is wider than the column it scrolls
inside itself — wrapping turns the strip into a two-storey block that
covers the fields it floats over. `justify-start`, not `center`: a
centred overflowing flex row hides its first buttons out of reach. */}
<div className="flex max-w-full flex-nowrap items-center justify-start gap-1.5 overflow-x-auto rounded-lg border border-solid border-border-default bg-surface-neutral-secondary pl-2.5 pr-1.5 py-1.5 shadow-lg [&>*]:flex-none">
<span className="whitespace-nowrap pr-1 uppercase tracking-wide text-body-extra-small-semibold-0 font-body-extra-small-semibold-0 text-text-neutral-tertiary">
{t("projects.quickAction.barLabel")}
</span>
<div className="flex h-5 w-px flex-none items-start bg-border-default" />
{/* Anrufen and E-Mail keep their place in the row even without a target,
like in the export — a bar whose buttons move around depending on the
project is harder to use than a disabled button. Telephony, when the
tenant has it, takes over the calling slot. */}
{callSlot ?? (
<Button
variant="tertiary"
size="small"
icon={<FeatherPhone />}
disabled={!callHref}
onClick={() => callHref && window.location.assign(callHref)}
data-ui-id="ui.projects.detail.quickActions.call"
>
{t("projects.quickAction.call")}
</Button>
)}
<Button
variant="tertiary"
size="small"
icon={<FeatherMail />}
disabled={!mailHref}
onClick={() => mailHref && window.location.assign(mailHref)}
data-ui-id="ui.projects.detail.quickActions.mail"
>
{t("projects.quickAction.mail")}
</Button>
<Button variant="tertiary" size="small" icon={<FeatherCalendarPlus />} onClick={() => onOpen("appointment")} data-ui-id="ui.projects.detail.quickActions.appointment">
{t("projects.quickAction.bar.appointment")}
</Button>
<Button variant="tertiary" size="small" icon={<FeatherCheckSquare />} onClick={() => onOpen("task")} data-ui-id="ui.projects.detail.quickActions.task">
{t("projects.quickAction.bar.task")}
</Button>
<Button variant="tertiary" size="small" icon={<FeatherStickyNote />} onClick={() => onOpen("note")} data-ui-id="ui.projects.detail.quickActions.note">
{t("projects.quickAction.bar.note")}
</Button>
<Button size="small" icon={<FeatherUpload />} onClick={() => onOpen("file")} data-ui-id="ui.projects.detail.quickActions.file">
{t("projects.quickAction.bar.file")}
</Button>
</div>
</div>
);
}
@@ -0,0 +1,290 @@
// WF-P8 S02 right-hand pipeline panel: one white column that stays put while the
// editor scrolls, with the six areas (Verlauf, Termine, Dateien, Aufgaben,
// Notizen, Aktivitäten) as a button grid on top and the picked area below it —
// exactly as in the export, where Dateien is the built and preselected one.
//
// Layout: `sticky top-0 h-screen` inside the document flow (the app shell scrolls
// the document, and its icon sidebar sticks the same way). The export root is
// `h-full overflow-hidden` with an inner scroller, which the layout-boundary gate
// bans — the shell hands down no definite height, so that markup collapses the
// screen to 0px.
//
// All six areas carry content, but the five besides Dateien are read-only: the
// editors for appointments, tasks and notes live in the P9 operations panel of
// the same module, and a second editor over the same rows is how the two drift
// apart. A second view does not have that problem — the panel is the glance, the
// module is where things change. Each area therefore ends in a link to its owner.
import { useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { AppLink } from "~/components/app/AppLink";
import {
FeatherActivity,
FeatherCalendar,
FeatherCheckSquare,
FeatherClock,
FeatherFile,
FeatherPaperclip,
FeatherStickyNote,
FeatherUpload,
FeatherUploadCloud,
} from "@subframe/core";
import { Button } from "~/ui/components/Button";
import { fileTypeLabelKey } from "~/utils/files/fileTypeLabel";
import { mutedText } from "./detailUi";
/** A project document plus the file-detail URL the route resolved for it. */
export type ProjektDetailRailDocument = {
id: string;
name: string;
mimeType: string;
sizeLabel: string;
/** S02-F upload category, stored as the file link role. */
linkRole: string | null;
href: string;
};
/** One read-only line in a rail area. */
export type ProjektDetailRailEntry = { id: string; label: string; labelKey?: string | null; meta: string | null; atIso: string | null };
export type DetailSideRailProps = {
documents: readonly ProjektDetailRailDocument[];
/**
* Uploads a picked or dropped file and links it to the project. Resolves once
* the link is on its way; rejects so the panel can say that it failed.
* Omitted without write access, which also removes the button and the zone.
*/
onUpload?: (file: File) => Promise<void>;
/** Read-only rows per area, resolved by the route. */
areas: {
history: readonly ProjektDetailRailEntry[];
appointments: readonly ProjektDetailRailEntry[];
tasks: readonly ProjektDetailRailEntry[];
notes: readonly ProjektDetailRailEntry[];
activity: readonly ProjektDetailRailEntry[];
};
/** Anchor of the operations panel, so an area can point at the full list. */
operationsHref?: string;
/** Formatter injected by the page so the panel speaks the screen's locale. */
dateTime: Intl.DateTimeFormat;
};
type EntryAreaKey = "history" | "appointments" | "tasks" | "notes" | "activity";
type AreaKey = EntryAreaKey | "files";
const AREAS: { key: AreaKey; icon: React.ReactNode; labelKey: string; emptyKey: string }[] = [
{ key: "history", icon: <FeatherClock />, labelKey: "projects.detail.rail.history", emptyKey: "projects.detail.rail.historyEmpty" },
{ key: "appointments", icon: <FeatherCalendar />, labelKey: "projects.subAreas.appointments", emptyKey: "projects.detail.rail.appointmentsEmpty" },
{ key: "files", icon: <FeatherPaperclip />, labelKey: "projects.detail.rail.files", emptyKey: "projects.empty.documents.body" },
{ key: "tasks", icon: <FeatherCheckSquare />, labelKey: "projects.subAreas.tasks", emptyKey: "projects.detail.rail.tasksEmpty" },
{ key: "notes", icon: <FeatherStickyNote />, labelKey: "projects.detail.rail.notes", emptyKey: "projects.detail.rail.notesEmpty" },
{ key: "activity", icon: <FeatherActivity />, labelKey: "projects.detail.rail.activity", emptyKey: "projects.detail.activityEmpty" },
];
/** Areas whose editor lives in the operations panel get the link to it. */
const AREAS_WITH_EDITOR: ReadonlySet<AreaKey> = new Set(["appointments", "tasks"]);
export function DetailSideRail({ documents, onUpload, areas, operationsHref, dateTime }: DetailSideRailProps) {
const { t } = useTranslation();
// Dateien is the area the export opens on, and the one with an editor here.
const [active, setActive] = useState<AreaKey>("files");
const fileInputRef = useRef<HTMLInputElement>(null);
const [dragging, setDragging] = useState(false);
const [uploading, setUploading] = useState(false);
const [uploadErrorKey, setUploadErrorKey] = useState<string | null>(null);
async function upload(file: File | null | undefined) {
if (!file || !onUpload) return;
setUploading(true);
setUploadErrorKey(null);
try {
await onUpload(file);
} catch (error) {
// The upload client carries the server's own key ("type not allowed",
// "too large"), which says more than a blanket "did not work".
const key = (error as { errorKey?: unknown }).errorKey;
setUploadErrorKey(typeof key === "string" ? key : "projects.quickAction.file.uploadFailed");
} finally {
setUploading(false);
}
}
const activeArea = AREAS.find((area) => area.key === active) ?? AREAS[2];
// Grouped by upload category so the panel reads like the export's document
// groups (Angebot, Auftrag, …) instead of one flat list.
const groups = new Map<string, ProjektDetailRailDocument[]>();
for (const document of documents) {
const key = document.linkRole ?? "";
const bucket = groups.get(key);
if (bucket) bucket.push(document);
else groups.set(key, [document]);
}
return (
<aside
// From xl on the panel is the right column next to the editor: it starts
// under the page header, which spans the full width, and sticks to the
// window from there on. `top-14` is the app shell's own header bar, so a
// scrolled page parks the panel right below it. Below xl it is a plain
// block at the end of the page, because a window-height column leaves a
// narrow screen no room for the editor.
//
// The panel has no collapsed state: the areas it holds (history, files,
// tasks, notes) are what the project is worked from, so it stays open.
className="relative flex w-full flex-col border-t border-solid border-border-default bg-surface-neutral-secondary xl:sticky xl:top-14 xl:h-[calc(100dvh-3.5rem)] xl:w-[340px] xl:flex-none xl:border-l xl:border-t-0"
data-ui-id="ui.projects.detail.rail"
>
<div className="flex h-full w-full flex-col gap-4 overflow-y-auto px-4 py-4">
<span className="text-body-small-medium-0 font-body-small-medium-0 uppercase text-text-neutral-tertiary">
{t("projects.detail.rail.title")}
</span>
{/* Area picker: three per row, icon over label, as in the export. */}
<div className="grid w-full grid-cols-3 gap-2">
{AREAS.map((area) => {
const isActive = area.key === active;
return (
<button
key={area.key}
type="button"
aria-pressed={isActive}
onClick={() => setActive(area.key)}
className={`flex flex-col items-center justify-center gap-1 rounded-md border border-solid px-2 py-3 ${
isActive
? // Blue, as in the export. Not the brand tone — that one is
// near-black here and reads as "pressed", not "selected".
"border-border-information-solid bg-surface-feedback-subtle-information text-text-feedback-information"
: "border-border-default bg-surface-neutral-secondary text-text-neutral-primary hover:bg-surface-neutral-tertiary"
}`}
data-ui-id={`ui.projects.detail.rail.tab.${area.key}`}
>
<span className="flex items-center text-body-large-0 font-body-large-0">{area.icon}</span>
<span className="text-body-small-regular-0 font-body-small-regular-0">{t(area.labelKey)}</span>
</button>
);
})}
</div>
<span className="text-body-large font-body-large text-text-neutral-primary">{t(activeArea.labelKey)}</span>
{active === "files" ? (
<div className="flex w-full flex-col gap-3" data-ui-id="ui.projects.detail.rail.files">
{onUpload ? (
<>
{/* The button opens the file dialog straight away — in the panel a
file lands on the project as it is, with no modal in between.
Category and description stay with the quick action, which is
where a file gets filed rather than just attached. */}
<input
ref={fileInputRef}
type="file"
className="sr-only"
aria-label={t("projects.quickAction.file.field.file")}
onChange={(event) => {
void upload(event.target.files?.[0]);
// Same file twice in a row must fire again.
event.target.value = "";
}}
data-ui-id="ui.projects.detail.rail.fileInput"
/>
<Button
variant="tertiary"
icon={<FeatherUpload />}
loading={uploading}
onClick={() => fileInputRef.current?.click()}
className="w-full justify-center"
data-ui-id="ui.projects.detail.rail.upload"
>
{t("projects.quickAction.bar.file")}
</Button>
{/* Drop target only, deliberately not clickable: the button right
above it already opens the picker, and a zone that does both
swallows the drop gesture on a mis-click. */}
<div
onDragOver={(event) => {
event.preventDefault();
setDragging(true);
}}
onDragLeave={() => setDragging(false)}
onDrop={(event) => {
event.preventDefault();
setDragging(false);
void upload(event.dataTransfer.files?.[0]);
}}
className={`flex w-full flex-col items-center gap-1 rounded-md border border-dashed px-4 py-6 ${
dragging ? "border-border-information-solid bg-surface-feedback-subtle-information" : "border-border-default"
}`}
data-ui-id="ui.projects.detail.rail.dropzone"
>
<FeatherUploadCloud className="text-icon-neutral-tertiary" />
{/* Only the headline: the second line of the shared dropzone copy
says "or click to select", which this zone does not do. */}
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary">
{t("files.upload.dropzone.headline")}
</span>
</div>
{uploadErrorKey ? (
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-feedback-negative" data-ui-id="ui.projects.detail.rail.uploadError">
{t(uploadErrorKey)}
</span>
) : null}
</>
) : null}
{documents.length === 0 ? <span className={mutedText}>{t("projects.empty.documents.body")}</span> : null}
{[...groups.entries()].map(([linkRole, group]) => (
<div
key={linkRole || "ungrouped"}
className="flex w-full flex-col gap-1 rounded-md border border-solid border-border-default p-2"
data-ui-id={`ui.projects.detail.rail.files.group.${linkRole || "ungrouped"}`}
>
<span className="text-body-extra-small-medium-0 font-body-extra-small-medium-0 uppercase text-text-neutral-tertiary">
{linkRole || t("projects.detail.rail.uncategorised")}
</span>
{group.map((document) => (
<AppLink
key={document.id}
href={document.href}
className="flex items-center gap-2 rounded-md px-1 py-1 hover:bg-surface-neutral-tertiary"
data-ui-id={`ui.projects.detail.rail.files.${document.id}`}
>
<FeatherFile className="text-icon-neutral-tertiary" />
<div className="flex min-w-0 grow flex-col">
<span className="truncate text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-primary">{document.name}</span>
<span className="text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-text-neutral-tertiary">
{t(fileTypeLabelKey(document.mimeType))} · {document.sizeLabel}
</span>
</div>
</AppLink>
))}
</div>
))}
</div>
) : (
<div className="flex w-full flex-col gap-2" data-ui-id={`ui.projects.detail.rail.${active}`}>
{areas[active as EntryAreaKey].length === 0 ? <span className={mutedText}>{t(activeArea.emptyKey)}</span> : null}
{areas[active as EntryAreaKey].map((entry) => (
<div key={entry.id} className="flex w-full flex-col gap-0.5" data-ui-id={`ui.projects.detail.rail.${active}.${entry.id}`}>
<span className="break-words text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-primary">
{entry.labelKey ? t(entry.labelKey) : entry.label}
</span>
<span className="text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-text-neutral-tertiary">
{[entry.atIso ? dateTime.format(new Date(entry.atIso)) : null, entry.meta].filter(Boolean).join(" · ")}
</span>
</div>
))}
{operationsHref && AREAS_WITH_EDITOR.has(active) ? (
<AppLink
href={operationsHref}
className="text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-brand-brand-text-default hover:underline"
data-ui-id={`ui.projects.detail.rail.${active}.manage`}
>
{t("projects.detail.rail.manage")}
</AppLink>
) : null}
</div>
)}
</div>
</aside>
);
}
@@ -0,0 +1,98 @@
// WF-P8 S02 — "Status" as the first field of Grunddaten.
//
// The export draws a select whose options are Badges, so this uses the synced
// DropdownMenuSelect rather than the plain Select: the trigger and the items
// have to render a badge, not a text row.
//
// Changing the status is an immediate action, not part of the stammdaten draft:
// a stage move has server-side consequences (won/lost stamps, the lost reason,
// the handover) that a "save later" would misrepresent.
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { FeatherChevronDown } from "@subframe/core";
import * as SubframeCore from "@subframe/core";
import type { ProjektDetailData } from "@hivegrid/view-models";
import { Badge } from "~/ui/components/Badge";
import { DropdownMenuSelect } from "~/ui/components/DropdownMenuSelect";
/** Outcome tone of a column; the board colour rides along as a dot. */
function toneOf(stageKind: string): "green-subtle" | "red-subtle" | "neutral-subtle" {
if (stageKind === "gewonnen") return "green-subtle";
if (stageKind === "verloren") return "red-subtle";
return "neutral-subtle";
}
export type DetailStatusFieldProps = {
data: ProjektDetailData;
/** Moving into a "verloren" column needs the reason dialog, so the parent decides. */
onMoveToStage: (stageId: string, stageKind: string) => void;
};
export function DetailStatusField({ data, onMoveToStage }: DetailStatusFieldProps) {
const { t } = useTranslation();
const [search, setSearch] = useState("");
const current = data.stages.find((stage) => stage.isCurrent) ?? null;
const query = search.trim().toLowerCase();
const visible = query ? data.stages.filter((stage) => stage.name.toLowerCase().includes(query)) : data.stages;
if (!data.canChangeStage) {
return (
<Badge tone={toneOf(current?.stageKind ?? "offen")} data-ui-id="ui.projects.detail.status.current">
{current?.name ?? "—"}
</Badge>
);
}
return (
<SubframeCore.DropdownMenu.Root>
<SubframeCore.DropdownMenu.Trigger asChild>
{/* Borderless like the export's filled select: the badge stands raw in
the row and only the chevron marks the far right as the handle. */}
<button
type="button"
className="flex h-8 w-full items-center justify-between gap-2 rounded-md px-1 hover:bg-surface-neutral-tertiary"
aria-label={t("projects.detail.system.status")}
data-ui-id="ui.projects.detail.status.trigger"
>
<Badge tone={toneOf(current?.stageKind ?? "offen")} data-ui-id="ui.projects.detail.status.current">
{current?.name ?? "—"}
</Badge>
<FeatherChevronDown className="text-body-small-regular-0 font-body-small-regular-0 text-icon-neutral-tertiary" />
</button>
</SubframeCore.DropdownMenu.Trigger>
<SubframeCore.DropdownMenu.Portal>
<SubframeCore.DropdownMenu.Content side="bottom" align="start" sideOffset={4} asChild>
<DropdownMenuSelect
showSearch={data.stages.length > 6}
searchValue={search}
searchPlaceholder={t("projects.fields.search")}
onSearchChange={setSearch}
>
{visible.map((stage) => (
<DropdownMenuSelect.DropdownItem
key={stage.id}
selected={stage.isCurrent}
disabled={stage.isCurrent}
onSelect={() => onMoveToStage(stage.id, stage.stageKind)}
data-ui-id={`ui.projects.detail.stage.${stage.id}`}
>
<span className="flex items-center gap-2">
{/* The board colour of the column; the badge tone only says
whether the column is an outcome. */}
<span className="h-2 w-2 flex-none rounded-round" style={{ backgroundColor: stage.color }} />
<Badge tone={toneOf(stage.stageKind)} hideDot>
{stage.name}
</Badge>
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
{stage.winProbability}%
</span>
</span>
</DropdownMenuSelect.DropdownItem>
))}
</DropdownMenuSelect>
</SubframeCore.DropdownMenu.Content>
</SubframeCore.DropdownMenu.Portal>
</SubframeCore.DropdownMenu.Root>
);
}
@@ -0,0 +1,141 @@
// WF-P8 S02 "Grunddaten" — the export's eight fields in its order: project
// name, status, priority, source, project type, promotion and the two money
// fields.
//
// The draft state lives in the parent (single save path); this section takes a
// value and reports a patch. Status is the exception: a stage move is immediate,
// so it goes straight to the callback.
//
// Deltas from the export, both waiting on data rather than on markup:
// * Quelle, Projekttyp and Promotion are tag multi-selects there and single
// free-text columns here. There is no option catalogue behind them, so a
// picker would have nothing to offer.
// * The money fields stay `type=number` with the raw decimal. The export
// shows "42.500,00 €" in a text field, which cannot round-trip a typed
// value across locales.
import { useTranslation } from "react-i18next";
import {
FeatherBriefcase,
FeatherCircleDot,
FeatherFlag,
FeatherHeart,
FeatherLayoutGrid,
FeatherTag,
FeatherTrendingUp,
FeatherWallet,
FeatherWrench,
} from "@subframe/core";
import type { ProjektDetailData } from "@hivegrid/view-models";
import { TextInput } from "~/ui/components/TextInput";
import { DetailPriorityField } from "./DetailPriorityField";
import { DetailStatusField } from "./DetailStatusField";
import { CURRENCY_SYMBOL, DetailCard, FIELD_CONTROL_PROPS, FieldRow, SectionDivider, mutedText, type StammdatenState } from "./detailUi";
export type GrunddatenSectionProps = {
data: ProjektDetailData;
value: StammdatenState;
onChange: (patch: Partial<StammdatenState>) => void;
onMoveToStage: (stageId: string, stageKind: string) => void;
};
/**
* Money row: the raw decimal stays editable as a number, and the currency sits
* next to it — a bare "48200,00" does not say what it counts.
*/
function MoneyInput({ value, onChange, uiId }: { value: string; onChange: (value: string) => void; uiId: string }) {
return (
<span className="flex w-full items-center gap-1.5">
<TextInput {...FIELD_CONTROL_PROPS} className="h-auto w-40 max-w-none">
<TextInput.Input
variant="small"
type="number"
inputMode="decimal"
placeholder="0,00"
value={value}
onChange={(event) => onChange(event.target.value)}
data-ui-id={uiId}
/>
</TextInput>
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">{CURRENCY_SYMBOL}</span>
</span>
);
}
export function GrunddatenSection({ data, value, onChange, onMoveToStage }: GrunddatenSectionProps) {
const { t } = useTranslation();
return (
<DetailCard uiId="ui.projects.detail.stammdaten">
<SectionDivider icon={<FeatherLayoutGrid />} title={t("projects.detail.section.stammdaten")} uiId="ui.projects.detail.section.grunddaten" />
{data.canWrite ? (
<FieldRow icon={<FeatherBriefcase />} label={t("projects.detail.fieldProjectName")} uiId="ui.projects.detail.field.name">
<TextInput {...FIELD_CONTROL_PROPS}>
<TextInput.Input
variant="small"
value={value.projektname}
onChange={(e) => onChange({ projektname: e.target.value })}
data-ui-id="ui.projects.detail.name"
/>
</TextInput>
</FieldRow>
) : null}
<FieldRow icon={<FeatherCircleDot />} label={t("projects.detail.system.status")} uiId="ui.projects.detail.field.status">
<DetailStatusField data={data} onMoveToStage={onMoveToStage} />
</FieldRow>
{data.canWrite ? (
<>
<FieldRow icon={<FeatherFlag />} label={t("projects.fields.priority")} uiId="ui.projects.detail.field.priority">
<DetailPriorityField value={value.prioritaet} onChange={(prioritaet) => onChange({ prioritaet })} />
</FieldRow>
<FieldRow icon={<FeatherHeart />} label={t("projects.fields.source")} uiId="ui.projects.detail.field.source">
<TextInput {...FIELD_CONTROL_PROPS}>
<TextInput.Input variant="small" value={value.quelle} onChange={(e) => onChange({ quelle: e.target.value })} data-ui-id="ui.projects.detail.quelle" />
</TextInput>
</FieldRow>
<FieldRow icon={<FeatherWrench />} label={t("projects.fields.projectType")} uiId="ui.projects.detail.field.projectType">
<TextInput {...FIELD_CONTROL_PROPS}>
<TextInput.Input variant="small" value={value.projekttyp} onChange={(e) => onChange({ projekttyp: e.target.value })} data-ui-id="ui.projects.detail.projekttyp" />
</TextInput>
</FieldRow>
<FieldRow icon={<FeatherTag />} label={t("projects.fields.promotion")} uiId="ui.projects.detail.field.promotion">
<TextInput {...FIELD_CONTROL_PROPS}>
<TextInput.Input variant="small" value={value.promotion} onChange={(e) => onChange({ promotion: e.target.value })} data-ui-id="ui.projects.detail.promotion" />
</TextInput>
</FieldRow>
{data.valueVisible ? (
<>
<FieldRow icon={<FeatherTrendingUp />} label={t("projects.detail.fieldPotentialValue")} uiId="ui.projects.detail.field.value">
<MoneyInput
value={value.potenziellerAuftragswert}
onChange={(potenziellerAuftragswert) => onChange({ potenziellerAuftragswert })}
uiId="ui.projects.detail.value"
/>
</FieldRow>
<FieldRow icon={<FeatherWallet />} label={t("projects.fields.orderVolume")} uiId="ui.projects.detail.field.orderVolume">
<MoneyInput
value={value.auftragsvolumen}
onChange={(auftragsvolumen) => onChange({ auftragsvolumen })}
uiId="ui.projects.detail.orderVolume"
/>
</FieldRow>
</>
) : null}
</>
) : (
<>
{/* A reader gets the same rows, only without controls. */}
<FieldRow icon={<FeatherFlag />} label={t("projects.fields.priority")} uiId="ui.projects.detail.field.priority">
<DetailPriorityField value={value.prioritaet} onChange={() => {}} readOnly />
</FieldRow>
<FieldRow icon={<FeatherTrendingUp />} label={t("projects.detail.fieldPotentialValue")} uiId="ui.projects.detail.field.value">
<span className={mutedText}>{data.valueVisible ? (data.valueDisplay ?? "—") : "—"}</span>
</FieldRow>
</>
)}
</DetailCard>
);
}
@@ -0,0 +1,269 @@
// WF-P8 S02 "Kontakte" — a divider-headed tile like the other groups; only the
// contacts inside it fold. Each row shows the type icon, the name and a one-line
// summary, opens on click and carries the pencil that leads to the CRM record.
//
// The export shows a company card and two contact-person cards. That split is
// `Kontakt.kontaktTyp`, not a project field: organisations become the company
// cards, persons the Ansprechpartner cards with the `primaer` link first. The
// cards stay read-only except for the portal invitation the loader gates per
// contact — editing contact master data belongs to P6, and the card links there.
//
// Deliberately not built: "Firma/Kontakt suchen oder neu anlegen". Linking a new
// contact to a project has no intent on this route yet; recorded as an open
// point rather than invented here.
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { AppLink } from "~/components/app/AppLink";
import { FeatherBuilding2, FeatherClock, FeatherEdit2, FeatherMail, FeatherMapPin, FeatherPhone, FeatherPrinter, FeatherSmartphone, FeatherTrash2, FeatherUsers } from "@subframe/core";
import type { ProjektDetailData, ProjektDetailKontakt } from "@hivegrid/view-models";
import { Accordion } from "~/ui/components/Accordion";
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
import { Button } from "~/ui/components/Button";
import { Dialog } from "~/ui/components/Dialog";
import { DetailCard, FieldRow, SectionDivider, mutedText, sectionHeading, type ProjektDetailSubmit } from "./detailUi";
import { AddKontaktBlock } from "./AddKontaktBlock";
/** Typed numbers in the order the export lists them under the primary one. */
const TYPED_PHONES: { key: "durchwahl" | "mobil" | "fax"; labelKey: string; icon: React.ReactNode }[] = [
{ key: "durchwahl", labelKey: "projects.detail.contacts.directDial", icon: <FeatherPhone /> },
{ key: "mobil", labelKey: "projects.detail.contacts.mobile", icon: <FeatherSmartphone /> },
{ key: "fax", labelKey: "projects.fields.fax", icon: <FeatherPrinter /> },
];
export type KontakteSectionProps = {
data: ProjektDetailData;
submitting: boolean;
submit: ProjektDetailSubmit;
/** Formatter injected by the page so the whole screen speaks one locale. */
dateTime: Intl.DateTimeFormat;
/** Search endpoint for the add-contact block. */
contactSearchHref: string;
};
/** Primary link first, then the order the loader delivered. */
function primaryFirst(kontakte: readonly ProjektDetailKontakt[]): ProjektDetailKontakt[] {
return [...kontakte].sort((a, b) => Number(b.primaer) - Number(a.primaer));
}
export function KontakteSection({ data, submitting, submit, dateTime, contactSearchHref }: KontakteSectionProps) {
const { t } = useTranslation();
const firmen = primaryFirst(data.kontakte.filter((kontakt) => kontakt.kontaktTyp === "organisation"));
const personen = primaryFirst(data.kontakte.filter((kontakt) => kontakt.kontaktTyp === "privatperson"));
return (
<DetailCard uiId="ui.projects.detail.contacts">
<SectionDivider icon={<FeatherUsers />} title={t("projects.detail.section.contacts")} uiId="ui.projects.detail.section.contacts" />
{data.kontakte.length === 0 ? <span className={mutedText}>{t("projects.detail.contactsEmpty")}</span> : null}
{firmen.map((kontakt) => (
<KontaktCard
key={kontakt.id}
kontakt={kontakt}
icon={<FeatherBuilding2 />}
captionKey="projects.detail.contacts.company"
canWrite={data.canWrite}
submitting={submitting}
submit={submit}
dateTime={dateTime}
/>
))}
{personen.map((kontakt, index) => (
<KontaktCard
key={kontakt.id}
kontakt={kontakt}
icon={<FeatherUsers />}
captionKey={index === 0 ? "projects.detail.contacts.primaryPerson" : "projects.detail.contacts.otherPerson"}
canWrite={data.canWrite}
submitting={submitting}
submit={submit}
dateTime={dateTime}
/>
))}
{data.sourceLeadId ? (
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary" data-ui-id="ui.projects.detail.sourceLead">
{t("projects.detail.sourceLeadHint")}
</span>
) : null}
{/* Linking a contact is a write on the project, so the block follows the
same permission as every other editor on this screen. */}
{data.canWrite ? <AddKontaktBlock searchHref={contactSearchHref} submitting={submitting} submit={submit} /> : null}
</DetailCard>
);
}
type KontaktCardProps = {
kontakt: ProjektDetailKontakt;
icon: React.ReactNode;
captionKey: string;
/** Only a writer may drop the link between project and contact. */
canWrite: boolean;
submitting: boolean;
submit: ProjektDetailSubmit;
dateTime: Intl.DateTimeFormat;
};
/** The export's one-line summary under the name: mail / phone / address. */
function summaryOf(kontakt: ProjektDetailKontakt): string {
return [kontakt.email, kontakt.telefon, kontakt.adresseLabel].filter(Boolean).join(" / ");
}
function KontaktCard({ kontakt, icon, captionKey, canWrite, submitting, submit, dateTime }: KontaktCardProps) {
const { t } = useTranslation();
const [confirmOpen, setConfirmOpen] = useState(false);
const uiId = `ui.projects.detail.contacts.${kontakt.id}`;
const summary = summaryOf(kontakt);
return (
<Accordion
variant="ghost"
className="w-full"
data-ui-id={uiId}
data-row-id={kontakt.id}
trigger={
<div className="flex w-full items-center gap-2 px-3 py-4" data-ui-id={`${uiId}.trigger`}>
<Accordion.Chevron />
<span className="flex h-9 w-9 flex-none items-center justify-center rounded-md bg-surface-neutral-tertiary text-icon-neutral-secondary">{icon}</span>
<span className="flex min-w-0 grow shrink-0 basis-0 flex-col items-start gap-0.5">
<span className="flex flex-wrap items-center gap-1.5">
<span className="text-body-extra-small-medium-0 font-body-extra-small-medium-0 uppercase text-text-neutral-tertiary">{t(captionKey)}</span>
<span className="text-body-small-semibold-0 font-body-small-semibold-0 text-text-neutral-primary">{kontakt.label}</span>
<BadgeFeedback farbe="subtle-neutral" size="small">
{t(kontakt.rolleLabelKey)}
</BadgeFeedback>
{kontakt.primaer ? (
<BadgeFeedback farbe="subtle-brand-primary" size="small">
{t("projects.detail.primaryContact")}
</BadgeFeedback>
) : null}
</span>
{summary ? (
// Wraps instead of truncating: mail, number and address together
// never fit one line in the narrow column, and a cut-off address
// is worse than a row that grows by a line.
<span className="w-full break-words text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">{summary}</span>
) : null}
</span>
{/* The pencil goes to the record in the CRM, which is where contact
master data is edited (S02 renders it read-only). It sits inside the
trigger, so the click must not also fold the row open — and it is a
styled link rather than the kit's IconButton, because the trigger is
itself a <button> and a button inside a button is invalid markup. */}
{kontakt.detailHref ? (
<AppLink
href={kontakt.detailHref}
onClick={(event) => event.stopPropagation()}
aria-label={t("projects.detail.contacts.edit")}
className="flex h-9 w-9 flex-none items-center justify-center rounded-md border border-solid border-border-default bg-surface-neutral-secondary text-icon-neutral-secondary hover:bg-surface-neutral-tertiary"
data-ui-id={`${uiId}.open`}
>
<FeatherEdit2 />
</AppLink>
) : null}
</div>
}
>
<div className="flex w-full flex-col gap-1.5 px-3 pb-3">
<div className="flex w-full flex-wrap items-center justify-end gap-2">
{kontakt.canInviteToPortal ? (
<Button
variant="tertiary"
size="small"
loading={submitting}
onClick={() => submit("invitePortalProjectContact", { contactId: kontakt.kontaktId })}
data-ui-id={`${uiId}.portalInvite`}
>
{t("customerPortal.admin.users.invite")}
</Button>
) : null}
{canWrite ? (
<Button variant="tertiary" size="small" icon={<FeatherTrash2 />} onClick={() => setConfirmOpen(true)} data-ui-id={`${uiId}.unlink`}>
{t("projects.detail.contacts.unlink")}
</Button>
) : null}
</div>
{kontakt.email ? (
<FieldRow icon={<FeatherMail />} label={t("projects.fields.email")} uiId={`${uiId}.email`}>
<a href={`mailto:${kontakt.email}`} className={`${mutedText} hover:underline`}>
{kontakt.email}
</a>
</FieldRow>
) : null}
{kontakt.telefon ? (
<FieldRow icon={<FeatherPhone />} label={t("projects.fields.phone")} uiId={`${uiId}.telefon`}>
<a href={`tel:${kontakt.telefon}`} className={`${mutedText} hover:underline`}>
{kontakt.telefon}
</a>
</FieldRow>
) : null}
{/* The typed numbers get their own rows: a caller chooses between Durchwahl
and Mobil, and one merged phone row hides that choice. */}
{TYPED_PHONES.map((phone) => {
const value = kontakt[phone.key];
if (!value) return null;
return (
<FieldRow key={phone.key} icon={phone.icon} label={t(phone.labelKey)} uiId={`${uiId}.${phone.key}`}>
<a href={`tel:${value}`} className={`${mutedText} hover:underline`}>
{value}
</a>
</FieldRow>
);
})}
{kontakt.adresseLabel ? (
<FieldRow icon={<FeatherMapPin />} label={t("projects.detail.contacts.address")} uiId={`${uiId}.adresse`}>
<span className={mutedText}>{kontakt.adresseLabel}</span>
</FieldRow>
) : null}
{kontakt.lastContactAtIso ? (
<FieldRow icon={<FeatherClock />} label={t("projects.detail.contacts.lastContact")} uiId={`${uiId}.lastContact`}>
<span className={mutedText}>{dateTime.format(new Date(kontakt.lastContactAtIso))}</span>
</FieldRow>
) : null}
{/* Master data, read-only: the row set differs by contact type and the
loader already dropped everything unset. */}
{kontakt.stammdaten.map((row) => (
<FieldRow key={row.labelKey} label={t(row.labelKey)} uiId={`${uiId}.stammdaten.${row.labelKey.split(".").pop()}`}>
<span className={mutedText}>{row.value}</span>
</FieldRow>
))}
{/* The note runs over several lines, so it gets its own block below the
label/value rows instead of being squeezed into one. `whitespace-pre-line`
keeps the paragraphs the author typed. */}
{kontakt.notizen ? (
<div className="flex w-full flex-col gap-1 pt-1" data-ui-id={`${uiId}.notizen`}>
<span className="text-body-extra-small-semibold-0 font-body-extra-small-semibold-0 uppercase tracking-wide text-text-neutral-tertiary">
{t("projects.detail.contacts.notes")}
</span>
<span className={`${mutedText} whitespace-pre-line`}>{kontakt.notizen}</span>
</div>
) : null}
</div>
{/* Unlinking is not undoable from this screen, so it asks first. It says
plainly that only the link goes — the contact stays in the CRM. */}
<Dialog open={confirmOpen} onOpenChange={setConfirmOpen}>
<Dialog.Content className="p-6" data-ui-id={`${uiId}.unlinkDialog`}>
<div className="flex w-full max-w-[420px] flex-col gap-4">
<span className={sectionHeading}>{t("projects.detail.contacts.unlinkTitle")}</span>
<span className={mutedText}>{t("projects.detail.contacts.unlinkBody", { name: kontakt.label })}</span>
<div className="flex justify-end gap-2">
<Button variant="neutral" onClick={() => setConfirmOpen(false)} data-ui-id={`${uiId}.unlinkCancel`}>
{t("projects.actions.cancel")}
</Button>
<Button
variant="destructive"
loading={submitting}
onClick={() => {
submit("unlinkKontakt", { projektKontaktId: kontakt.id });
setConfirmOpen(false);
}}
data-ui-id={`${uiId}.unlinkConfirm`}
>
{t("projects.detail.contacts.unlink")}
</Button>
</div>
</div>
</Dialog.Content>
</Dialog>
</Accordion>
);
}
@@ -0,0 +1,99 @@
// WF-P8 S02 "KWP-Integration" — read-only, and that is the deliberate delta.
//
// The export draws the fields as inputs, but KWP is an inbound mirror: the
// module declares itself read-only and has no outbound write path, so editable
// fields here would be controls that silently drop what you type. They are drawn
// as locked value boxes instead, which is what the export's greyed-out selects
// look like anyway.
//
// The export also draws Abteilungsnummer and Sachbearbeiter. The inbound KWP
// contract carries neither, and a row that can never fill is worse than no row,
// so they are out (decided with the user on 2026-07-30). If the contract ever
// grows them, they come back here.
//
// The whole section is absent for a project without a KWP binding, which also
// covers every tenant without the capability — the panel loader returns null
// unless an AppEntityBinding ties this project to a KWP project.
import { useTranslation } from "react-i18next";
import { FeatherCircleDot, FeatherHash, FeatherLink, FeatherLock, FeatherPlug, FeatherRefreshCw } from "@subframe/core";
import type { ProjektDetailData } from "@hivegrid/view-models";
import { CopyToClipboardButton } from "~/ui/components/CopyToClipboardButton";
import { DetailCard, EMPTY_VALUE_CLASS, FieldRow, SectionDivider } from "./detailUi";
export type KwpSectionProps = {
data: ProjektDetailData;
/** Formatter injected by the page so the whole screen speaks one locale. */
dateTime: Intl.DateTimeFormat;
};
/** The "this came from KWP" marker the export puts on both ends of the rule. */
function KwpBadge({ label, hint }: { label: string; hint: string }) {
return (
// Fixed hex rather than a token: this exact grey is what the badge is meant
// to be, and no surface token carries it.
<span className="flex h-5 flex-none items-center gap-1.5 rounded-sm bg-[#505057] px-1.5" title={hint}>
<FeatherPlug className="text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-icon-neutral-on-solid" />
<span className="text-body-extra-small-semibold-0 font-body-extra-small-semibold-0 text-text-neutral-on-solid">{label}</span>
</span>
);
}
/** A mirrored value: locked box, greyed out, never an input. */
function MirroredValue({ value, trailing }: { value: string | null; trailing?: React.ReactNode }) {
return (
<span className="border-border-default bg-surface-neutral-disabled flex h-8 w-full items-center gap-2 rounded-sm border border-solid px-3">
<FeatherLock className="text-body-small-regular-0 font-body-small-regular-0 text-icon-neutral-tertiary" />
<span
className={`text-body-small-medium-0 font-body-small-medium-0 shrink-0 grow basis-0 truncate ${
value ? "text-text-neutral-secondary" : EMPTY_VALUE_CLASS
}`}
>
{value ?? "—"}
</span>
{trailing}
</span>
);
}
export function KwpSection({ data, dateTime }: KwpSectionProps) {
const { t } = useTranslation();
const kwp = data.kwp;
if (!kwp) return null;
const hint = t("projects.detail.kwp.hint");
return (
<DetailCard variant="information" uiId="ui.projects.detail.kwp">
<SectionDivider
icon={<FeatherLink />}
title={t("projects.detail.section.kwp")}
uiId="ui.projects.detail.section.kwp"
// The export marks this tile as foreign data on both ends of the rule,
// which is also the whole "read-only" story: it mirrors KWP, it does not
// own it.
leading={<KwpBadge label={t("projects.detail.kwp.badge")} hint={hint} />}
trailing={<KwpBadge label={t("projects.detail.kwp.badge")} hint={hint} />}
/>
<FieldRow icon={<FeatherHash />} label={t("projects.detail.kwp.projectNumber")} uiId="ui.projects.detail.kwp.projectNumber">
<MirroredValue
value={kwp.externalProjectNumber}
trailing={
<CopyToClipboardButton
clipboardText={kwp.externalProjectNumber}
tooltipText={t("projects.detail.kwp.copyProjectNumber")}
successKey="projects.detail.toast.kwpNumberCopied"
/>
}
/>
</FieldRow>
<FieldRow icon={<FeatherCircleDot />} label={t("projects.detail.kwp.orderStatus")} uiId="ui.projects.detail.kwp.orderStatus">
<MirroredValue value={kwp.statusLabel} />
</FieldRow>
{/* Not in the export, but it is the one thing a mirror owes its reader:
how fresh the mirrored data is. */}
<FieldRow icon={<FeatherRefreshCw />} label={t("projects.detail.kwp.lastSynced")} uiId="ui.projects.detail.kwp.lastSynced">
<MirroredValue value={kwp.lastSyncedAtIso ? dateTime.format(new Date(kwp.lastSyncedAtIso)) : null} />
</FieldRow>
</DetailCard>
);
}
@@ -0,0 +1,329 @@
// WF-P8 S02 "Planung und Verantwortliche" — dates and the people on the project.
//
// The dates stay native `<input type="date">`. The kit's DatePicker is purely
// presentational (it takes a `value` node and has no change handler), so using
// it here would trade a working, keyboard- and locale-aware control for a
// picture of one. Reported to David together with the other kit findings.
//
// Projektleiter is a project column and rides along in the stammdaten draft;
// "Zuständige Personen" and "Monteure" are `ProjektMitglied` rows, so each pick
// is an immediate addMember/removeMember intent — there is no draft that could
// hold a half-built member list.
//
// The single "Zuständig" owner select is gone: it said the same thing as
// "Zuständige Personen", only capped at one name. `Projekt.zustaendigePersonId`
// still travels with the draft untouched, so nothing this screen saves clears
// the column the board filters read.
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { FeatherFlag, FeatherHardHat, FeatherPlayCircle, FeatherTimer, FeatherUsers, FeatherWrench } from "@subframe/core";
import * as SubframeCore from "@subframe/core";
import type { ProjectMemberRole, ProjektDetailData, ProjektDetailMitglied } from "@hivegrid/view-models";
import { DropdownMenuMultiSelect } from "~/ui/components/DropdownMenuMultiSelect";
import { MultiSelect } from "~/ui/components/MultiSelect";
import { TextInput } from "~/ui/components/TextInput";
import {
DATE_INPUT_TYPE,
DetailCard,
EMPTY_VALUE_CLASS,
FIELD_CONTROL_PROPS,
FieldRow,
SectionDivider,
mutedText,
type ProjektDetailSubmit,
type StammdatenState,
} from "./detailUi";
export type ProjektDetailOwnerOption = { id: string; label: string };
export type PlanungSectionProps = {
data: ProjektDetailData;
ownerOptions: readonly ProjektDetailOwnerOption[];
value: StammdatenState;
onChange: (patch: Partial<StammdatenState>) => void;
submitting: boolean;
submit: ProjektDetailSubmit;
};
function membersOfRole(mitglieder: readonly ProjektDetailMitglied[], rolle: ProjectMemberRole): ProjektDetailMitglied[] {
return mitglieder.filter((member) => member.rolle === rolle);
}
export function PlanungSection({ data, ownerOptions, value, onChange, submitting, submit }: PlanungSectionProps) {
const { t } = useTranslation();
return (
<DetailCard uiId="ui.projects.detail.planung">
<SectionDivider icon={<FeatherTimer />} title={t("projects.detail.section.planning")} uiId="ui.projects.detail.section.planung" />
{data.canWrite ? (
<>
<FieldRow icon={<FeatherPlayCircle />} label={t("projects.fields.startDate")} uiId="ui.projects.detail.field.startDate">
<TextInput {...FIELD_CONTROL_PROPS}>
{/* An empty date input shows the browser's "tt.mm.jjjj" — that is a
placeholder and gets the placeholder tone, like every other
unset field in this card. */}
<TextInput.Input
variant="small"
type={DATE_INPUT_TYPE}
className={value.startDatum ? undefined : EMPTY_VALUE_CLASS}
value={value.startDatum}
onChange={(e) => onChange({ startDatum: e.target.value })}
/>
</TextInput>
</FieldRow>
<FieldRow icon={<FeatherFlag />} label={t("projects.fields.deadline")} uiId="ui.projects.detail.field.deadline">
<TextInput {...FIELD_CONTROL_PROPS}>
<TextInput.Input
variant="small"
type={DATE_INPUT_TYPE}
className={value.deadline ? undefined : EMPTY_VALUE_CLASS}
value={value.deadline}
onChange={(e) => onChange({ deadline: e.target.value })}
/>
</TextInput>
</FieldRow>
{/* Export order: the people who work on it, then who leads it, then
who is on site. */}
<MemberPicker
icon={<FeatherUsers />}
label={t("projects.fields.assignedPersons")}
rolle="zustaendig"
members={membersOfRole(data.mitglieder, "zustaendig")}
options={ownerOptions}
canManage={data.canManageMembers}
submitting={submitting}
submit={submit}
/>
{ownerOptions.length > 0 ? (
<LeaderPicker
value={value.projektleiterId}
onChange={(projektleiterId) => onChange({ projektleiterId })}
options={ownerOptions}
/>
) : null}
<MemberPicker
icon={<FeatherWrench />}
label={t("projects.fields.fitters")}
rolle="monteur"
members={membersOfRole(data.mitglieder, "monteur")}
options={ownerOptions}
canManage={data.canManageMembers}
submitting={submitting}
submit={submit}
/>
</>
) : (
<>
{/* A reader gets the same rows, only without controls. */}
<MemberPicker
icon={<FeatherUsers />}
label={t("projects.fields.assignedPersons")}
rolle="zustaendig"
members={membersOfRole(data.mitglieder, "zustaendig")}
options={ownerOptions}
canManage={false}
submitting={submitting}
submit={submit}
/>
<FieldRow icon={<FeatherHardHat />} label={t("projects.fields.projectLeader")} uiId="ui.projects.detail.field.projectLeader">
<span className="flex items-center gap-2">
<span className="text-icon-neutral-subtle">
<FeatherHardHat />
</span>
<span className={mutedText}>{data.projektleiterLabel ?? t("projects.fields.none")}</span>
</span>
</FieldRow>
<MemberPicker
icon={<FeatherWrench />}
label={t("projects.fields.fitters")}
rolle="monteur"
members={membersOfRole(data.mitglieder, "monteur")}
options={ownerOptions}
canManage={false}
submitting={submitting}
submit={submit}
/>
</>
)}
</DetailCard>
);
}
/**
* The single Projektleiter, drawn as the same people field as the two member
* pickers: without a pick it shows the greyed placeholder rather than an em
* dash that reads like a value.
*/
function LeaderPicker({
value,
onChange,
options,
}: {
value: string;
onChange: (userId: string) => void;
options: readonly ProjektDetailOwnerOption[];
}) {
const { t } = useTranslation();
const [search, setSearch] = useState("");
const query = search.trim().toLowerCase();
const visible = query ? options.filter((option) => option.label.toLowerCase().includes(query)) : options;
const selected = options.find((option) => option.id === value) ?? null;
return (
<FieldRow icon={<FeatherHardHat />} label={t("projects.fields.projectLeader")} uiId="ui.projects.detail.field.projectLeader">
<div className="flex w-full items-center">
<SubframeCore.DropdownMenu.Root>
<SubframeCore.DropdownMenu.Trigger asChild>
<MultiSelect
className="h-8 w-full min-w-0 max-w-none"
size="small"
variant="filled"
borderless
hasValue={Boolean(selected)}
icon={<FeatherHardHat />}
value={selected?.label ?? ""}
placeholder={t("projects.fields.selectPerson")}
label=""
aria-label={t("projects.fields.projectLeader")}
data-ui-id="ui.projects.detail.projektleiter.trigger"
/>
</SubframeCore.DropdownMenu.Trigger>
<SubframeCore.DropdownMenu.Portal>
<SubframeCore.DropdownMenu.Content side="bottom" align="start" sideOffset={4} asChild>
<DropdownMenuMultiSelect
showSearch={options.length > 6}
searchValue={search}
searchPlaceholder={t("projects.fields.search")}
onSearchChange={setSearch}
>
<DropdownMenuMultiSelect.DropdownItem
showCheckbox
selected={!selected}
onClick={() => onChange("")}
data-ui-id="ui.projects.detail.projektleiter.none"
>
{t("projects.fields.none")}
</DropdownMenuMultiSelect.DropdownItem>
{visible.map((option) => (
<DropdownMenuMultiSelect.DropdownItem
key={option.id}
showCheckbox
selected={option.id === value}
onClick={() => onChange(option.id === value ? "" : option.id)}
data-ui-id={`ui.projects.detail.projektleiter.option.${option.id}`}
>
{option.label}
</DropdownMenuMultiSelect.DropdownItem>
))}
</DropdownMenuMultiSelect>
</SubframeCore.DropdownMenu.Content>
</SubframeCore.DropdownMenu.Portal>
</SubframeCore.DropdownMenu.Root>
</div>
</FieldRow>
);
}
type MemberPickerProps = {
icon: React.ReactNode;
label: string;
rolle: ProjectMemberRole;
members: readonly ProjektDetailMitglied[];
options: readonly ProjektDetailOwnerOption[];
canManage: boolean;
submitting: boolean;
submit: ProjektDetailSubmit;
};
/**
* One people picker on top of `ProjektMitglied`, drawn as the export's people
* field: the kit's MultiSelect fills the row (icon left, the picked names,
* chevron at the far right) and opens the checkbox menu. Without
* `projects.manage_members` it degrades to the plain names rather than to a menu
* that would fail on the server.
*/
function MemberPicker({ icon, label, rolle, members, options, canManage, submitting, submit }: MemberPickerProps) {
const { t } = useTranslation();
const [search, setSearch] = useState("");
const uiId = `ui.projects.detail.members.${rolle}`;
const memberByUserId = new Map(members.map((member) => [member.userId, member]));
const query = search.trim().toLowerCase();
const visible = query ? options.filter((option) => option.label.toLowerCase().includes(query)) : options;
const names = members.map((member) => member.label).join(", ");
function toggle(userId: string) {
const existing = memberByUserId.get(userId);
if (existing) submit("removeMember", { memberId: existing.id });
else submit("addMember", { userId, rolle });
}
if (!canManage) {
return (
<FieldRow icon={icon} label={label} uiId={uiId}>
<span className="flex items-center gap-2">
<span className="text-icon-neutral-subtle">{icon}</span>
<span className={mutedText} data-ui-id={`${uiId}.value`}>
{names || t("projects.fields.none")}
</span>
</span>
</FieldRow>
);
}
return (
<FieldRow icon={icon} label={label} uiId={uiId}>
<div className="flex w-full items-center">
<SubframeCore.DropdownMenu.Root>
<SubframeCore.DropdownMenu.Trigger asChild>
{/* MultiSelect is the trigger itself: it forwards its ref and props
to its root div, so Radix can drive it without a second box. */}
<MultiSelect
className="h-8 w-full min-w-0 max-w-none"
size="small"
variant="filled"
borderless
hasValue={members.length > 0}
icon={icon}
value={names}
placeholder={t("projects.fields.selectPersons")}
label=""
aria-label={label}
aria-disabled={submitting || undefined}
data-ui-id={`${uiId}.trigger`}
/>
</SubframeCore.DropdownMenu.Trigger>
<SubframeCore.DropdownMenu.Portal>
<SubframeCore.DropdownMenu.Content side="bottom" align="start" sideOffset={4} asChild>
<DropdownMenuMultiSelect
showSearch={options.length > 6}
searchValue={search}
searchPlaceholder={t("projects.fields.search")}
onSearchChange={setSearch}
>
{visible.length === 0 ? (
<DropdownMenuMultiSelect.DropdownCustomItem>
<span className="px-1 text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
{t("projects.board.filter.noOptions")}
</span>
</DropdownMenuMultiSelect.DropdownCustomItem>
) : null}
{visible.map((option) => (
<DropdownMenuMultiSelect.DropdownItem
key={option.id}
showCheckbox
selected={memberByUserId.has(option.id)}
onClick={() => toggle(option.id)}
data-ui-id={`${uiId}.option.${option.id}`}
>
{option.label}
</DropdownMenuMultiSelect.DropdownItem>
))}
</DropdownMenuMultiSelect>
</SubframeCore.DropdownMenu.Content>
</SubframeCore.DropdownMenu.Portal>
</SubframeCore.DropdownMenu.Root>
</div>
</FieldRow>
);
}
@@ -0,0 +1,54 @@
// WF-P8 S02 "Projektkontaktdaten" — the channels of the project itself, which
// are not the same thing as the linked Kontakt records below.
import { useTranslation } from "react-i18next";
import { FeatherAtSign, FeatherMail, FeatherPhone, FeatherPrinter } from "@subframe/core";
import type { ProjektDetailData } from "@hivegrid/view-models";
import { TextInput } from "~/ui/components/TextInput";
import { DetailCard, FIELD_CONTROL_PROPS, FieldRow, SectionDivider, mutedText, type StammdatenState } from "./detailUi";
export type ProjektkontaktSectionProps = {
data: ProjektDetailData;
value: StammdatenState;
onChange: (patch: Partial<StammdatenState>) => void;
};
export function ProjektkontaktSection({ data, value, onChange }: ProjektkontaktSectionProps) {
const { t } = useTranslation();
if (!data.canWrite) {
const lines = [value.email, value.telefon, value.fax].filter(Boolean);
if (lines.length === 0) return null;
return (
<DetailCard uiId="ui.projects.detail.projectContact">
<SectionDivider icon={<FeatherAtSign />} title={t("projects.detail.section.projectContact")} uiId="ui.projects.detail.section.projectContact" />
{lines.map((line) => (
<span key={line} className={mutedText}>
{line}
</span>
))}
</DetailCard>
);
}
return (
<DetailCard uiId="ui.projects.detail.projectContact">
<SectionDivider icon={<FeatherAtSign />} title={t("projects.detail.section.projectContact")} uiId="ui.projects.detail.section.projectContact" />
<FieldRow icon={<FeatherMail />} label={t("projects.fields.email")} uiId="ui.projects.detail.field.email">
<TextInput {...FIELD_CONTROL_PROPS}>
<TextInput.Input variant="small" value={value.email} onChange={(e) => onChange({ email: e.target.value })} data-ui-id="ui.projects.detail.email" />
</TextInput>
</FieldRow>
<FieldRow icon={<FeatherPhone />} label={t("projects.fields.phone")} uiId="ui.projects.detail.field.phone">
<TextInput {...FIELD_CONTROL_PROPS}>
<TextInput.Input variant="small" value={value.telefon} onChange={(e) => onChange({ telefon: e.target.value })} data-ui-id="ui.projects.detail.telefon" />
</TextInput>
</FieldRow>
<FieldRow icon={<FeatherPrinter />} label={t("projects.fields.fax")} uiId="ui.projects.detail.field.fax">
<TextInput {...FIELD_CONTROL_PROPS}>
<TextInput.Input variant="small" value={value.fax} onChange={(e) => onChange({ fax: e.target.value })} data-ui-id="ui.projects.detail.fax" />
</TextInput>
</FieldRow>
</DetailCard>
);
}
@@ -0,0 +1,160 @@
// WF-P8 S02 — the pieces every detail section shares: typography constants,
// the editable stammdaten state and the small value helpers.
//
// Extracted so the section components below stay about their own fields rather
// than each carrying its own copy of the same three class strings.
import type { ReactNode } from "react";
import type { ProjektDetailData } from "@hivegrid/view-models";
import { Card } from "~/ui/components/Card";
/** POST a detail action with its string fields; the route builds FormData. */
export type ProjektDetailSubmit = (intent: string, fields?: Record<string, string>) => void;
export const PRIORITIES = ["niedrig", "normal", "hoch", "dringend"] as const;
/** Money on a project is EUR everywhere in v1 (EU stack, single currency). */
export const CURRENCY_SYMBOL = "€";
/** Tone of a field that holds no value yet — same grey as a placeholder. */
export const EMPTY_VALUE_CLASS = "text-text-neutral-subtle";
// TextInput.Input's typed `type` union omits "date"; the native input supports it.
export const DATE_INPUT_TYPE = "date" as unknown as "text";
export const sectionHeading = "text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary";
export const mutedText = "text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary";
export const labelText = "text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary";
/**
* The S02 tile. The export draws every group as a flat, tight card on the page
* surface — no border, no shadow, 12/8 padding — so the tiles read as one sheet
* of paper rather than as six floating panels.
*/
export function DetailCard({
children,
variant,
uiId,
}: {
children: ReactNode;
/** "information" is the KWP tile: an inbound mirror, tinted to say so. */
variant?: "information";
uiId?: string;
}) {
return (
<Card size="small" variant={variant} className="gap-2 border-none px-3 py-2 shadow-none" data-ui-id={uiId}>
{children}
</Card>
);
}
/**
* WF-P8 S02 section heading: a rule, an icon, an uppercase caption and a rule.
*
* Only "Kontakte" and "Adressdaten" are accordions in the export; the other
* four groups are divider-headed sections like this one.
*/
export function SectionDivider({
icon,
title,
uiId,
leading,
trailing,
}: {
icon: ReactNode;
title: string;
uiId?: string;
/** Badge at the far left of the rule (the KWP tile marks its origin on both ends). */
leading?: ReactNode;
/** Badge at the far right of the rule (the KWP tile marks its origin there). */
trailing?: ReactNode;
}) {
return (
<div className="flex w-full items-center gap-2" data-ui-id={uiId}>
{leading}
<div className="h-0.5 grow shrink-0 basis-0 bg-icon-neutral-subtle" />
<span className="flex items-center text-body-default-regular-150 font-body-default-regular-150 text-icon-neutral-tertiary">{icon}</span>
<span className="whitespace-nowrap text-body-small-medium-0 font-body-small-medium-0 uppercase text-text-neutral-tertiary">{title}</span>
<div className="h-0.5 grow shrink-0 basis-0 bg-icon-neutral-subtle" />
{trailing}
</div>
);
}
/**
* The repeating unit of the S02 field groups: a fixed 12rem label gutter with
* its icon, a hairline that separates label from control, and the control. Each
* row closes with a full-width hairline, which is what gives the tile its
* table-like look in the export.
*
* The gutter collapses above the control on mobile — the export keeps the two
* side by side, which leaves a 320px viewport with no room for the field.
*/
export function FieldRow({
icon,
label,
children,
uiId,
}: {
icon?: ReactNode;
label: string;
children: ReactNode;
uiId?: string;
}) {
return (
<div className="flex w-full flex-col items-center gap-1.5" data-ui-id={uiId}>
<div className="flex w-full items-center mobile:flex-col mobile:items-start mobile:gap-1">
<div className="flex h-8 w-48 flex-none items-center justify-between mobile:h-auto mobile:w-full">
<div className="flex w-48 flex-none items-center gap-2 pl-1 pr-3 mobile:w-full">
{icon ? <span className="flex items-center text-body-large-0 font-body-large-0 text-icon-neutral-primary">{icon}</span> : null}
<span className="line-clamp-2 grow shrink-0 basis-0 break-words text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-primary">
{label}
</span>
</div>
<div className="w-px flex-none self-stretch bg-icon-neutral-subtle mobile:hidden" />
</div>
<div className="flex min-w-0 grow shrink-0 basis-0 items-center px-2 py-0.5 mobile:w-full mobile:px-0">{children}</div>
</div>
<div className="h-px w-full flex-none bg-icon-neutral-subtle" />
</div>
);
}
/**
* Field chrome of the S02 tiles: the control carries no border of its own, the
* row around it already draws every line the export shows.
*/
export const FIELD_CONTROL_PROPS = {
size: "small",
variant: "filled",
borderless: true,
// `max-w-none` rather than `fillContainer`: the kit caps a field at 320px and
// only TextInput has that prop, while Select passes it straight to the DOM.
className: "h-auto w-full max-w-none",
label: "",
} as const;
export function isoToDateInput(iso: string | null): string {
return iso ? iso.slice(0, 10) : "";
}
/** Editable stammdaten form state derived from the VM (also used to reset on cancel). */
export function toStammdatenState(data: ProjektDetailData) {
return {
projektname: data.projektname,
beschreibung: data.beschreibung ?? "",
prioritaet: data.prioritaet as string,
potenziellerAuftragswert: data.value ?? "",
auftragsvolumen: data.orderVolume ?? "",
startDatum: isoToDateInput(data.startDatumIso),
deadline: isoToDateInput(data.deadlineIso),
zustaendigePersonId: data.ownerUserId ?? "",
projektleiterId: data.projektleiterId ?? "",
// WF-P8 S02 "Grunddaten" / "Projektkontaktdaten".
projekttyp: data.projekttyp ?? "",
quelle: data.quelle ?? "",
promotion: data.promotion ?? "",
email: data.email ?? "",
telefon: data.telefon ?? "",
fax: data.fax ?? "",
};
}
export type StammdatenState = ReturnType<typeof toStammdatenState>;