// R-P7 (P7 Lead-Inbox) Interim-UI (AD-28) — incoming-leads Kanban board, composed // from ~/ui (KanbanCard) on top of the shared SortableKanbanBoard (dnd-kit). // Pure/presentational: renders the server-built LeadBoardData and turns a valid // column move into a single onSetStatus callback the route POSTs (intent // `setStatus`). Every drag funnels through requestMove so: // - a drop into "Gewonnen" (converted) is NEVER a silent flip — it points the // user at the detail page project conversion (createProjectFromQualifiedLead); // - an invalid transition (backward / from a terminal status) is rejected // client-side with a plaintext error and the card snaps back (resetToken); // - a valid move (new->qualified, ->lost) submits and the server re-validates. // No useLoaderData/useFetcher, no server imports. Final Subframe optics = tracked // design-nachzug. import { useEffect, useMemo, useState, type ReactNode } from "react"; import { useTranslation } from "react-i18next"; import { FeatherColumns, FeatherEye, FeatherList, FeatherPlus, FeatherTrendingUp } from "@subframe/core"; import type { LeadBoardData, LeadBoardStatus } from "@hivegrid/view-models"; import { BadgeFeedback } from "~/ui/components/BadgeFeedback"; import { Button } from "~/ui/components/Button"; import { EmptyState } from "~/ui/components/EmptyState"; import { KanbanCard } from "~/ui/components/KanbanCard"; import { ToggleGroup } from "~/ui/components/ToggleGroup"; import { SortableKanbanBoard, type SortableKanbanColumn } from "~/components/ui/kanban/SortableKanbanBoard"; import { useRecommendedSidebarCollapse } from "~/components/app/AppShellSidebarContext"; import { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageShell } from "../shared/PageShell"; import { FacetFilterBar, type ClientFacet } from "../shared/FacetFilterBar"; import { useLiveFilter } from "~/hooks/use-live-filter"; import { AppLink } from "~/components/app/AppLink"; export type LeadBoardActions = { onSetStatus: (leadId: string, status: LeadBoardStatus) => void; onOpenList: () => void; onNew: () => void; onSearch: (value: string) => void; onToggleSpam: (checked: boolean) => void; /** * Clears search and spam visibility in ONE navigation. Calling onSearch and * onToggleSpam back to back would not do: both derive their next params from * the same render's snapshot, so the second would resurrect what the first * dropped. */ onResetFilters: () => void; }; export type LeadBoardPageProps = { data: LeadBoardData; submitting: boolean; errorKey?: string | null; language?: string; search: string; actions: LeadBoardActions; }; type BoardCard = LeadBoardData["columns"][number]["cards"][number]; const mutedText = "text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary"; export function LeadBoardPage(props: LeadBoardPageProps) { const { t } = useTranslation(); const { data } = props; useRecommendedSidebarCollapse("leads"); // Client-side rejection feedback + snap-back trigger for the shared board. const [localError, setLocalError] = useState(null); const [convertHint, setConvertHint] = useState<{ name: string; href: string } | null>(null); const [resetToken, setResetToken] = useState(0); const [searchDraft, setSearchDraft] = useState(props.search); useEffect(() => setSearchDraft(props.search), [props.search]); // The shared bar has no Enter affordance, so the term applies debounced — // exactly as it does in the list view. useLiveFilter(searchDraft.trim(), props.search, () => props.actions.onSearch(searchDraft.trim())); const cardById = useMemo(() => { const map = new Map(); for (const column of data.columns) for (const card of column.cards) map.set(card.id, card); return map; }, [data.columns]); function snapBack() { setResetToken((token) => token + 1); // revert the optimistic drop to server truth } // Every drag-end (mouse or keyboard) funnels through here. function requestMove(leadId: string, targetStatus: LeadBoardStatus) { const card = cardById.get(leadId); if (!card || targetStatus === card.status) return; setLocalError(null); setConvertHint(null); if (targetStatus === "spam") { // Marking as spam schedules the lead for deletion — too consequential to // happen from a drag. Same stance as "Gewonnen" below. setLocalError("leads.board.error.spamViaList"); snapBack(); return; } if (targetStatus === "converted") { // "Gewonnen" means a Projekt was created from the lead — never do that // silently from a drag. Point the user at the detail page conversion. setConvertHint({ name: card.displayName, href: card.detailHref }); snapBack(); return; } if (!card.allowedTargetStatuses.includes(targetStatus)) { setLocalError("leads.board.error.invalidTransition"); snapBack(); return; } props.actions.onSetStatus(leadId, targetStatus); } function renderLeadCard(card: BoardCard, dragHandle?: ReactNode): ReactNode { return ( {card.displayName} } valueSlot={{card.ownerLabel ?? t("leads.board.card.unassigned")}} tagsSlot={
{t(card.quelleLabelKey)} {dragHandle}
} footerLeftSlot={card.contact ? {card.contact} : undefined} data-row-id={card.id} data-ui-id={`ui.leads.board.card.${card.id}`} /> ); } const boardColumns: SortableKanbanColumn[] = data.columns.map((column) => ({ id: column.status, label: t(column.labelKey), name: t(column.labelKey), badge: ( {String(column.count)} ), sumMode: "hidden", accentColor: { new: "#3B82F6", qualified: "#8B5CF6", converted: "#16A34A", lost: "#64748B", spam: "#DC2626", }[column.status], emptyContent: (
{t("leads.board.columnEmpty.title", { status: t(column.labelKey) })} {t("leads.board.columnEmpty.body")}
), cards: column.cards, })); const isEmpty = data.columns.every((column) => column.cards.length === 0); const facets: ClientFacet[] = [ { key: "visibility", label: t("leads.filter.visibility"), icon: , tone: "sand-subtle", options: [{ value: "spam", label: t("leads.filter.showSpam") }], selected: new Set(data.includeSpam ? ["spam"] : []), }, ]; return ( } title={t("leads.board.title")} subtitle={t("leads.board.subtitle")} actions={ <> {/* Labelled board/list switch, same shape as the projects boards. */} value === "list" && props.actions.onOpenList()} data-ui-id="ui.leads.board.viewToggle"> } value="board" aria-label={t("leads.viewMode.board")} data-ui-id="ui.leads.board.viewToggle.board"> {t("leads.viewMode.board")} } value="list" aria-label={t("leads.viewMode.list")} data-ui-id="ui.leads.board.viewToggle.list"> {t("leads.viewMode.list")} {data.canWrite ? ( ) : null} } /> {/* --- Filter bar: the same shared facet strip the list view wears, so switching between board and list does not change what the filter chrome looks like. The board has no status facet — its columns ARE the statuses — so it carries the search plus the Einblenden facet, which here holds spam alone. --- */} value === "spam" && props.actions.onToggleSpam(!data.includeSpam)} search={searchDraft} onSearchChange={setSearchDraft} searchPlaceholder={t("leads.filter.searchPlaceholder")} onReset={() => { setSearchDraft(""); props.actions.onResetFilters(); }} labels={{ reset: t("leads.filter.resetAll"), removeChip: t("leads.filter.removeChip") }} /> {props.errorKey ? (
{t(props.errorKey)}
) : null} {localError ? (
{t(localError)}
) : null} {convertHint ? (
{t("leads.board.convertHint", { name: convertHint.name })} {t("leads.board.convertLink")}
) : null} {/* No "saving" line here: it rode on the router's navigation state, so it also flashed for a filter toggle, and the drop is optimistic anyway. */} {data.columns.some((column) => column.truncated) ? ( {t("leads.board.truncatedHint", { count: Math.max(...data.columns.map((column) => column.loadedCount)) })} ) : null} {isEmpty ? (
) : ( columns={boardColumns} renderCard={renderLeadCard} getCardLabel={(card) => card.displayName} onCardMove={(cardId, toColumnId) => requestMove(cardId, toColumnId as LeadBoardStatus)} disabled={!data.canWrite} errorKey={props.errorKey ?? localError} resetToken={resetToken} dragHandlePlacement="inline" data-ui-id="ui.leads.board.columns" /> )}
); } export default LeadBoardPage;