@aglyn/plugins-crm 1.11.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/package.json +14 -14
  2. package/src/lib/components/contact-list-columns.js +4 -3
  3. package/src/lib/components/contact-list-columns.js.map +1 -1
  4. package/src/lib/components/contact-properties-card.js +6 -2
  5. package/src/lib/components/contact-properties-card.js.map +1 -1
  6. package/src/lib/components/contacts-bulk-bar.js +16 -5
  7. package/src/lib/components/contacts-bulk-bar.js.map +1 -1
  8. package/src/lib/components/contacts-section.js +6 -13
  9. package/src/lib/components/contacts-section.js.map +1 -1
  10. package/src/lib/components/crm-record-insights-zone.js +7 -0
  11. package/src/lib/components/crm-record-insights-zone.js.map +1 -1
  12. package/src/lib/components/deal-board.d.ts +2 -0
  13. package/src/lib/components/deal-board.js +20 -11
  14. package/src/lib/components/deal-board.js.map +1 -1
  15. package/src/lib/components/deal-stage-card.js +41 -28
  16. package/src/lib/components/deal-stage-card.js.map +1 -1
  17. package/src/lib/components/deals-bulk-bar.js +20 -10
  18. package/src/lib/components/deals-bulk-bar.js.map +1 -1
  19. package/src/lib/components/deals-section.js +1 -0
  20. package/src/lib/components/deals-section.js.map +1 -1
  21. package/src/lib/components/email-capture-card.d.ts +1 -1
  22. package/src/lib/components/email-capture-card.js +2 -1
  23. package/src/lib/components/email-capture-card.js.map +1 -1
  24. package/src/lib/components/record-sharing-card.d.ts +6 -5
  25. package/src/lib/components/record-sharing-card.js +45 -30
  26. package/src/lib/components/record-sharing-card.js.map +1 -1
  27. package/src/lib/components/settings-section.d.ts +18 -11
  28. package/src/lib/components/settings-section.js +36 -19
  29. package/src/lib/components/settings-section.js.map +1 -1
  30. package/src/lib/components/sharing-rules-card.js +2 -1
  31. package/src/lib/components/sharing-rules-card.js.map +1 -1
  32. package/src/lib/components/use-org-members.d.ts +17 -10
  33. package/src/lib/components/use-org-members.js +31 -66
  34. package/src/lib/components/use-org-members.js.map +1 -1
  35. package/src/lib/declarations.d.ts +6 -2
  36. package/src/lib/declarations.js +14 -2
  37. package/src/lib/declarations.js.map +1 -1
  38. package/src/lib/hooks/use-crm-activity-logger.d.ts +2 -2
  39. package/src/lib/hooks/use-crm-activity-logger.js +2 -2
  40. package/src/lib/hooks/use-crm-activity-logger.js.map +1 -1
  41. package/src/lib/hooks/use-crm-record-names.js +59 -6
  42. package/src/lib/hooks/use-crm-record-names.js.map +1 -1
  43. package/src/lib/hooks/use-deal-stage-api.d.ts +2 -0
  44. package/src/lib/hooks/use-deal-stage-api.js +7 -2
  45. package/src/lib/hooks/use-deal-stage-api.js.map +1 -1
  46. package/src/lib/hooks/use-org-member-directory.js +49 -12
  47. package/src/lib/hooks/use-org-member-directory.js.map +1 -1
  48. package/src/lib/hooks/use-stage-move-blocked.d.ts +32 -0
  49. package/src/lib/hooks/use-stage-move-blocked.js +71 -0
  50. package/src/lib/hooks/use-stage-move-blocked.js.map +1 -0
  51. package/src/lib/model/crm-api.d.ts +1 -1
  52. package/src/lib/model/crm-api.js +1 -1
  53. package/src/lib/model/crm-api.js.map +1 -1
  54. package/src/lib/model/crm-permissions.d.ts +35 -0
  55. package/src/lib/model/crm-permissions.js +87 -0
  56. package/src/lib/model/crm-permissions.js.map +1 -0
  57. package/src/lib/model/crm-sharing.d.ts +1 -1
  58. package/src/lib/model/crm-sharing.js +1 -1
  59. package/src/lib/model/crm-sharing.js.map +1 -1
  60. package/src/lib/plugin.js +4 -5
  61. package/src/lib/plugin.js.map +1 -1
  62. package/src/lib/server/capture-contact.d.ts +3 -3
  63. package/src/lib/server/capture-contact.js +3 -3
  64. package/src/lib/server/capture-contact.js.map +1 -1
  65. package/src/lib/server/crm-setup-writers.server.d.ts +2 -3
  66. package/src/lib/server/crm-setup-writers.server.js +4 -16
  67. package/src/lib/server/crm-setup-writers.server.js.map +1 -1
  68. package/src/lib/server/crm-sharing.d.ts +5 -4
  69. package/src/lib/server/crm-sharing.js +8 -6
  70. package/src/lib/server/crm-sharing.js.map +1 -1
  71. package/src/lib/server/email-template-duplicate.js +7 -7
  72. package/src/lib/server/email-template-duplicate.js.map +1 -1
  73. package/src/lib/server/inbound-address.d.ts +9 -7
  74. package/src/lib/server/inbound-address.js +18 -15
  75. package/src/lib/server/inbound-address.js.map +1 -1
  76. package/src/lib/server/org-caller.d.ts +19 -5
  77. package/src/lib/server/org-caller.js +25 -5
  78. package/src/lib/server/org-caller.js.map +1 -1
  79. package/src/lib/server/recipe-routes.d.ts +0 -34
  80. package/src/lib/server/recipe-routes.js +11 -10
  81. package/src/lib/server/recipe-routes.js.map +1 -1
  82. package/src/lib/server/task-routes.d.ts +6 -5
  83. package/src/lib/server/task-routes.js +11 -13
  84. package/src/lib/server/task-routes.js.map +1 -1
  85. package/src/lib/server-deal-stage.d.ts +11 -6
  86. package/src/lib/server-deal-stage.js +18 -16
  87. package/src/lib/server-deal-stage.js.map +1 -1
  88. package/src/lib/server.js +16 -18
  89. package/src/lib/server.js.map +1 -1
@@ -19,6 +19,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
19
19
  import { mdiChevronRight, mdiOpenInNew, mdiThumbDownOutline, mdiTrophyOutline } from "@aglyn/shared-data-mdi";
20
20
  import { MdiIcon } from "@aglyn/shared-ui-jsx";
21
21
  import RowActionsMenu from "@aglyn/shared-ui-jsx/components/row-actions-menu.component";
22
+ import { CRM_MOVE_STAGES_REFUSAL } from "../model/crm-permissions.js";
22
23
  import { closestCorners, DndContext, DragOverlay, KeyboardSensor, PointerSensor, useDraggable, useDroppable, useSensor, useSensors } from "@dnd-kit/core";
23
24
  import { CSS } from "@dnd-kit/utilities";
24
25
  import { Box, Button, Chip, CircularProgress, Paper, Stack, TabScrollButton, Tooltip, Typography } from "@mui/material";
@@ -66,7 +67,7 @@ const stageOfColumn = (id)=>typeof id === 'string' && id.startsWith('stage:') ?
66
67
  * MUI's scrollable Tabs do — the scrollbar alone stays hidden on a trackpad
67
68
  * until the reader already knows to scroll.
68
69
  */ export function DealBoard(props) {
69
- const { pipeline, deals, won, lost, closedExpanded, onToggleClosed, labelFor, moving, onOpen, onMove, onWon, onLost, nowMs } = props;
70
+ const { pipeline, deals, won, lost, closedExpanded, onToggleClosed, labelFor, moving, onOpen, moveBlocked = false, onMove, onWon, onLost, nowMs } = props;
70
71
  const stages = useMemo(()=>openStages(pipeline), [
71
72
  pipeline
72
73
  ]);
@@ -117,6 +118,12 @@ const stageOfColumn = (id)=>typeof id === 'string' && id.startsWith('stage:') ?
117
118
  onWon,
118
119
  onLost
119
120
  ]);
121
+ const blockedItem = useMemo(()=>moveBlocked ? {
122
+ disabled: true,
123
+ disabledReason: CRM_MOVE_STAGES_REFUSAL
124
+ } : {}, [
125
+ moveBlocked
126
+ ]);
120
127
  const cardActions = useCallback((deal)=>[
121
128
  {
122
129
  key: 'open',
@@ -127,7 +134,7 @@ const stageOfColumn = (id)=>typeof id === 'string' && id.startsWith('stage:') ?
127
134
  }),
128
135
  onClick: ()=>onOpen(deal)
129
136
  },
130
- ...stages.filter((stage)=>stage.id !== deal.stageId).map((stage)=>({
137
+ ...stages.filter((stage)=>stage.id !== deal.stageId).map((stage)=>_extends({
131
138
  key: `move:${stage.id}`,
132
139
  label: `Move to ${stage.name}`,
133
140
  icon: /*#__PURE__*/ _jsx(MdiIcon, {
@@ -135,8 +142,8 @@ const stageOfColumn = (id)=>typeof id === 'string' && id.startsWith('stage:') ?
135
142
  size: 0.8
136
143
  }),
137
144
  onClick: ()=>onMove(deal, stage.id)
138
- })),
139
- {
145
+ }, blockedItem)),
146
+ _extends({
140
147
  key: 'won',
141
148
  label: 'Mark won',
142
149
  icon: /*#__PURE__*/ _jsx(MdiIcon, {
@@ -144,8 +151,8 @@ const stageOfColumn = (id)=>typeof id === 'string' && id.startsWith('stage:') ?
144
151
  size: 0.8
145
152
  }),
146
153
  onClick: ()=>onWon(deal)
147
- },
148
- {
154
+ }, blockedItem),
155
+ _extends({
149
156
  key: 'lost',
150
157
  label: 'Mark lost',
151
158
  icon: /*#__PURE__*/ _jsx(MdiIcon, {
@@ -154,13 +161,14 @@ const stageOfColumn = (id)=>typeof id === 'string' && id.startsWith('stage:') ?
154
161
  }),
155
162
  onClick: ()=>onLost(deal),
156
163
  destructive: true
157
- }
164
+ }, blockedItem)
158
165
  ], [
159
166
  stages,
160
167
  onOpen,
161
168
  onMove,
162
169
  onWon,
163
- onLost
170
+ onLost,
171
+ blockedItem
164
172
  ]);
165
173
  const renderCard = (deal)=>/*#__PURE__*/ _jsx(DealCard, {
166
174
  deal: deal,
@@ -168,6 +176,7 @@ const stageOfColumn = (id)=>typeof id === 'string' && id.startsWith('stage:') ?
168
176
  days: daysInStage(deal, nowMs),
169
177
  pending: moving.has(deal.$id),
170
178
  actions: cardActions(deal),
179
+ locked: moveBlocked,
171
180
  onOpen: ()=>onOpen(deal)
172
181
  }, deal.$id);
173
182
  const closedStages = pipeline.stages.filter((stage)=>stage.kind !== 'open');
@@ -396,20 +405,20 @@ function StageColumn(props) {
396
405
  }
397
406
  StageColumn.displayName = 'StageColumn';
398
407
  function DealCard(props) {
399
- const { deal, ownerLabel, days, pending, actions, onOpen } = props;
408
+ const { deal, ownerLabel, days, pending, locked, actions, onOpen } = props;
400
409
  const { attributes, listeners, setNodeRef, transform, isDragging } = useDraggable({
401
410
  id: deal.$id,
402
411
  data: {
403
412
  deal
404
413
  },
405
- disabled: pending || deal.status !== 'open'
414
+ disabled: pending || locked || deal.status !== 'open'
406
415
  });
407
416
  return /*#__PURE__*/ _jsx(Box, _extends({
408
417
  ref: setNodeRef,
409
418
  sx: {
410
419
  transform: CSS.Translate.toString(transform),
411
420
  opacity: isDragging ? 0.3 : pending ? 0.5 : 1,
412
- cursor: deal.status === 'open' && !pending ? 'grab' : 'default',
421
+ cursor: deal.status === 'open' && !pending && !locked ? 'grab' : 'default',
413
422
  outline: 'none',
414
423
  '&:focus-visible': {
415
424
  borderRadius: 1,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/components/deal-board.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport type { CrmDealStage } from '@aglyn/aglyn'\nimport {\n mdiChevronRight,\n mdiOpenInNew,\n mdiThumbDownOutline,\n mdiTrophyOutline,\n} from '@aglyn/shared-data-mdi'\nimport { MdiIcon } from '@aglyn/shared-ui-jsx'\nimport RowActionsMenu, {\n type RowActionsMenuItem,\n} from '@aglyn/shared-ui-jsx/components/row-actions-menu.component'\nimport {\n closestCorners,\n DndContext,\n type DragEndEvent,\n DragOverlay,\n type DragStartEvent,\n KeyboardSensor,\n PointerSensor,\n useDraggable,\n useDroppable,\n useSensor,\n useSensors,\n} from '@dnd-kit/core'\nimport { CSS } from '@dnd-kit/utilities'\nimport {\n Box,\n Button,\n Chip,\n CircularProgress,\n Paper,\n Stack,\n TabScrollButton,\n Tooltip,\n Typography,\n} from '@mui/material'\nimport { useCallback, useMemo, useState } from 'react'\nimport { useScrollEdges } from '../hooks/use-scroll-edges'\nimport {\n daysInStage,\n type DealDoc,\n formatMoney,\n openStages,\n type PipelineDoc,\n} from '../model/deal-board-model'\nimport { OwnerAvatar } from './owner-avatar'\n\n/** The droppable id a stage column answers to. */\nconst columnId = (stageId: string) => `stage:${stageId}`\nconst stageOfColumn = (id: unknown) =>\n typeof id === 'string' && id.startsWith('stage:') ? id.slice('stage:'.length) : null\n\nexport interface DealBoardProps {\n pipeline: PipelineDoc\n /** Every open deal in the pipeline; the board sorts them into columns. */\n deals: readonly DealDoc[]\n /** The closed columns' rows once expanded; `null` while collapsed. */\n won: readonly DealDoc[] | null\n lost: readonly DealDoc[] | null\n closedExpanded: boolean\n onToggleClosed: () => void\n /** The owner's name for a uid, from the roster. */\n labelFor: (uid: string | undefined) => string\n /** Deals whose move is in flight — drawn dimmed, not draggable. */\n moving: ReadonlySet<string>\n onOpen: (deal: DealDoc) => void\n onMove: (deal: DealDoc, stageId: string) => void\n onWon: (deal: DealDoc) => void\n onLost: (deal: DealDoc) => void\n nowMs: number\n}\n\n/**\n * The pipeline as columns (AGL-2598): one per open stage, Won and Lost at\n * the end, cards dragged between them.\n *\n * ## Dragging is a request, not a write\n *\n * `@dnd-kit` handles the pointer; when a card is released over another\n * column the board calls `onMove`, and the SECTION calls the stage route.\n * The card is not moved locally: it dims while the request is in flight\n * and lands in its new column when the listener hears the write. An\n * optimistic move that the server refused — no permission, a stage the\n * pipeline lost meanwhile — would have to be animated back, and a card that\n * jumps back with no explanation reads as a bug in the board rather than a\n * refusal by the server, which is what it was.\n *\n * The pointer sensor needs a few pixels of travel before a drag begins, so\n * a click on the title still opens the deal and a click on the menu still\n * opens the menu. The keyboard sensor makes the same move reachable without\n * a mouse; the card menu's \"Move to\" items are the other route.\n *\n * ## Won and Lost fold away\n *\n * A closed deal is history, and a board that drew every won deal of the\n * year beside the four open stages would push the work off the screen. The\n * two closed columns start collapsed to a count-free stub and expand on\n * request, which is also when their rows are read — a collapsed column\n * costs no listener.\n *\n * ## Empty stages fold too, and the board says when there is more\n *\n * A pipeline with Salesforce's ten stages is wider than the card, and the\n * stages with deals in them were off the edge with nothing to say so. An\n * open stage with no deals folds to the same narrow stub, labelled and still\n * a drop target, so the stages that hold work get the room. When the row is\n * still wider than the card, chevrons at either end page it sideways the way\n * MUI's scrollable Tabs do — the scrollbar alone stays hidden on a trackpad\n * until the reader already knows to scroll.\n */\nexport function DealBoard(props: DealBoardProps) {\n const {\n pipeline,\n deals,\n won,\n lost,\n closedExpanded,\n onToggleClosed,\n labelFor,\n moving,\n onOpen,\n onMove,\n onWon,\n onLost,\n nowMs,\n } = props\n const stages = useMemo(() => openStages(pipeline), [pipeline])\n const edges = useScrollEdges()\n const overflowing = edges.start || edges.end\n const byStage = useMemo(() => {\n const map = new Map<string, DealDoc[]>()\n for (const stage of stages) map.set(stage.id, [])\n const orphans: DealDoc[] = []\n for (const deal of deals) {\n const column = map.get(deal.stageId)\n if (column) column.push(deal)\n else orphans.push(deal)\n }\n return { map, orphans }\n }, [stages, deals])\n\n const sensors = useSensors(\n useSensor(PointerSensor, { activationConstraint: { distance: 6 } }),\n useSensor(KeyboardSensor),\n )\n const [dragging, setDragging] = useState<DealDoc | null>(null)\n const handleDragStart = useCallback((event: DragStartEvent) => {\n setDragging((event.active.data.current?.['deal'] as DealDoc) ?? null)\n }, [])\n const handleDragEnd = useCallback(\n (event: DragEndEvent) => {\n setDragging(null)\n const deal = event.active.data.current?.['deal'] as DealDoc | undefined\n const target = stageOfColumn(event.over?.id)\n if (!deal || !target || target === deal.stageId) return\n const stage = pipeline.stages.find((entry) => entry.id === target)\n if (!stage) return\n if (stage.kind === 'won') return onWon(deal)\n if (stage.kind === 'lost') return onLost(deal)\n onMove(deal, target)\n },\n [pipeline, onMove, onWon, onLost],\n )\n\n const cardActions = useCallback(\n (deal: DealDoc): RowActionsMenuItem[] => [\n {\n key: 'open',\n label: 'Open',\n icon: <MdiIcon path={mdiOpenInNew.path} size={0.8} />,\n onClick: () => onOpen(deal),\n },\n ...stages\n .filter((stage) => stage.id !== deal.stageId)\n .map((stage) => ({\n key: `move:${stage.id}`,\n label: `Move to ${stage.name}`,\n icon: <MdiIcon path={mdiChevronRight.path} size={0.8} />,\n onClick: () => onMove(deal, stage.id),\n })),\n {\n key: 'won',\n label: 'Mark won',\n icon: <MdiIcon path={mdiTrophyOutline.path} size={0.8} />,\n onClick: () => onWon(deal),\n },\n {\n key: 'lost',\n label: 'Mark lost',\n icon: <MdiIcon path={mdiThumbDownOutline.path} size={0.8} />,\n onClick: () => onLost(deal),\n destructive: true,\n },\n ],\n [stages, onOpen, onMove, onWon, onLost],\n )\n\n const renderCard = (deal: DealDoc) => (\n <DealCard\n key={deal.$id}\n deal={deal}\n ownerLabel={labelFor(deal.ownerUid)}\n days={daysInStage(deal, nowMs)}\n pending={moving.has(deal.$id)}\n actions={cardActions(deal)}\n onOpen={() => onOpen(deal)}\n />\n )\n\n const closedStages = pipeline.stages.filter((stage) => stage.kind !== 'open')\n\n return (\n <DndContext\n sensors={sensors}\n collisionDetection={closestCorners}\n onDragStart={handleDragStart}\n onDragEnd={handleDragEnd}\n onDragCancel={() => setDragging(null)}\n >\n {/*\n The board scrolls sideways; the page does not. The columns are\n fixed-width and refuse to shrink, so the row is as wide as its\n stages — and a flex item's implicit `min-width: auto` would hand\n that width up to the card and the page rather than clip it here.\n `minWidth: 0` is what lets this box be narrower than its content,\n which is the whole condition for the scrollbar to appear on it.\n */}\n <Stack direction=\"row\" sx={{ alignItems: 'stretch', minWidth: 0, width: '100%' }}>\n {overflowing ? (\n <TabScrollButton\n direction=\"left\"\n orientation=\"horizontal\"\n disabled={!edges.start}\n onClick={() => edges.page(-1)}\n aria-label=\"Show earlier stages\"\n data-testid=\"deal-board-scroll-start\"\n />\n ) : null}\n <Box ref={edges.ref} sx={{ overflowX: 'auto', pb: 1, minWidth: 0, flex: 1 }}>\n <Stack direction=\"row\" spacing={1.5} sx={{ alignItems: 'stretch', minWidth: 'max-content' }}>\n {stages.map((stage) => (\n <StageColumn\n key={stage.id}\n stage={stage}\n folded={!byStage.map.get(stage.id)?.length}\n count={byStage.map.get(stage.id)?.length ?? 0}\n total={(byStage.map.get(stage.id) ?? []).reduce(\n (sum, deal) => sum + (Number(deal.amountCents) || 0),\n 0,\n )}\n currency={byStage.map.get(stage.id)?.[0]?.currency}\n >\n {(byStage.map.get(stage.id) ?? []).map(renderCard)}\n </StageColumn>\n ))}\n {byStage.orphans.length ? (\n <StageColumn\n stage={{\n id: '__orphans',\n name: 'No stage',\n order: Number.MAX_SAFE_INTEGER,\n probability: 0,\n kind: 'open',\n }}\n count={byStage.orphans.length}\n total={0}\n currency={undefined}\n droppable={false}\n caption=\"These deals sit in a stage the pipeline no longer has. Move them.\"\n >\n {byStage.orphans.map(renderCard)}\n </StageColumn>\n ) : null}\n {closedStages.map((stage) => {\n const rows = stage.kind === 'won' ? won : lost\n return (\n <StageColumn\n key={stage.id}\n stage={stage}\n count={rows?.length ?? null}\n total={null}\n currency={undefined}\n collapsed={!closedExpanded}\n onToggle={onToggleClosed}\n >\n {closedExpanded && rows === null ? (\n <Stack sx={{ alignItems: 'center', py: 2 }}>\n <CircularProgress size={20} />\n </Stack>\n ) : (\n (rows ?? []).map(renderCard)\n )}\n </StageColumn>\n )\n })}\n </Stack>\n </Box>\n {overflowing ? (\n <TabScrollButton\n direction=\"right\"\n orientation=\"horizontal\"\n disabled={!edges.end}\n onClick={() => edges.page(1)}\n aria-label=\"Show later stages\"\n data-testid=\"deal-board-scroll-end\"\n />\n ) : null}\n </Stack>\n <DragOverlay dropAnimation={null}>\n {dragging ? (\n <DealCardBody\n deal={dragging}\n ownerLabel={labelFor(dragging.ownerUid)}\n days={daysInStage(dragging, nowMs)}\n lifted\n />\n ) : null}\n </DragOverlay>\n </DndContext>\n )\n}\nDealBoard.displayName = 'DealBoard'\n\ninterface StageColumnProps {\n stage: CrmDealStage\n /** Cards in the column, or null while a closed column has not loaded. */\n count: number | null\n /** The column's open value in cents, or null for a closed column. */\n total: number | null\n currency: string | undefined\n droppable?: boolean\n collapsed?: boolean\n /**\n * An open stage with no deals, drawn as a narrow labelled stub — still a\n * drop target, unlike a collapsed closed column, so a deal can be dragged\n * into it.\n */\n folded?: boolean\n onToggle?: () => void\n caption?: string\n children?: React.ReactNode\n}\n\nfunction StageColumn(props: StageColumnProps) {\n const {\n stage,\n count,\n total,\n currency,\n droppable = true,\n collapsed = false,\n folded = false,\n onToggle,\n caption,\n children,\n } = props\n const { setNodeRef, isOver } = useDroppable({\n id: columnId(stage.id),\n disabled: !droppable || collapsed,\n })\n const closed = stage.kind !== 'open'\n return (\n <Paper\n ref={setNodeRef}\n variant=\"outlined\"\n sx={{\n width: collapsed || folded ? 56 : 260,\n flexShrink: 0,\n display: 'flex',\n flexDirection: 'column',\n bgcolor: isOver ? 'action.hover' : 'background.default',\n borderColor: isOver ? 'primary.main' : undefined,\n transition: (theme) => theme.transitions.create(['background-color', 'border-color', 'width']),\n minHeight: 240,\n }}\n >\n {folded && !collapsed ? (\n <Tooltip title={`${stage.name}: no deals · ${stage.probability}% likely to close`} placement=\"top\">\n <Typography\n variant=\"subtitle2\"\n color=\"text.secondary\"\n data-testid=\"deal-board-folded-stage\"\n sx={{\n flex: 1,\n writingMode: 'vertical-rl',\n textOrientation: 'mixed',\n textAlign: 'center',\n py: 2,\n alignSelf: 'center',\n }}\n >\n {stage.name}\n </Typography>\n </Tooltip>\n ) : collapsed ? (\n <Button\n onClick={onToggle}\n sx={{\n flex: 1,\n writingMode: 'vertical-rl',\n textOrientation: 'mixed',\n py: 2,\n typography: 'subtitle2',\n }}\n color={stage.kind === 'won' ? 'success' : 'inherit'}\n >\n {stage.name}\n </Button>\n ) : (\n <>\n <Stack\n direction=\"row\"\n spacing={1}\n sx={{ alignItems: 'center', px: 1.5, py: 1 }}\n >\n <Typography variant=\"subtitle2\" sx={{ flex: 1 }} noWrap>\n {stage.name}\n </Typography>\n {count !== null ? <Chip size=\"small\" label={count} /> : null}\n {closed && onToggle ? (\n <Button size=\"small\" onClick={onToggle}>\n {'Hide'}\n </Button>\n ) : null}\n </Stack>\n {!closed ? (\n <Typography variant=\"caption\" color=\"text.secondary\" sx={{ px: 1.5 }}>\n {`${stage.probability}% · ${total ? formatMoney(total, currency) : 'no value yet'}`}\n </Typography>\n ) : null}\n {caption ? (\n <Typography variant=\"caption\" color=\"warning.main\" sx={{ px: 1.5 }}>\n {caption}\n </Typography>\n ) : null}\n <Stack spacing={1} sx={{ p: 1, flex: 1 }}>\n {children}\n </Stack>\n </>\n )}\n </Paper>\n )\n}\nStageColumn.displayName = 'StageColumn'\n\ninterface DealCardProps {\n deal: DealDoc\n ownerLabel: string\n days: number\n pending: boolean\n actions: RowActionsMenuItem[]\n onOpen: () => void\n}\n\nfunction DealCard(props: DealCardProps) {\n const { deal, ownerLabel, days, pending, actions, onOpen } = props\n const { attributes, listeners, setNodeRef, transform, isDragging } = useDraggable({\n id: deal.$id,\n data: { deal },\n disabled: pending || deal.status !== 'open',\n })\n return (\n <Box\n ref={setNodeRef}\n sx={{\n transform: CSS.Translate.toString(transform),\n opacity: isDragging ? 0.3 : pending ? 0.5 : 1,\n cursor: deal.status === 'open' && !pending ? 'grab' : 'default',\n outline: 'none',\n '&:focus-visible': {\n borderRadius: 1,\n boxShadow: (theme) => `0 0 0 2px ${theme.palette.primary.main}`,\n },\n }}\n // The sensor's attributes and listeners carry no `sx`, and they come\n // AFTER it so the card's own styles are what the rule sees first.\n {...attributes}\n {...listeners}\n >\n <DealCardBody\n deal={deal}\n ownerLabel={ownerLabel}\n days={days}\n menu={<RowActionsMenu items={actions} label={deal.title} />}\n onOpen={onOpen}\n />\n </Box>\n )\n}\nDealCard.displayName = 'DealCard'\n\ninterface DealCardBodyProps {\n deal: DealDoc\n ownerLabel: string\n days: number\n menu?: React.ReactNode\n onOpen?: () => void\n lifted?: boolean\n}\n\n/**\n * What a card shows: the title, the amount, who it is with, the owner and\n * how long it has sat here. Shared by the card in its column and the copy\n * that follows the pointer, so the two cannot drift.\n */\nexport function DealCardBody(props: DealCardBodyProps) {\n const { deal, ownerLabel, days, menu, onOpen, lifted } = props\n const withWhom = [deal.contactName, deal.companyName].filter(Boolean).join(' · ')\n return (\n <Paper\n elevation={lifted ? 6 : 1}\n sx={{ p: 1.25, width: lifted ? 244 : undefined }}\n >\n <Stack direction=\"row\" spacing={0.5} sx={{ alignItems: 'flex-start' }}>\n <Typography\n variant=\"body2\"\n component={onOpen ? 'button' : 'span'}\n onClick={onOpen}\n // The title is the link into the deal, drawn as text: a button\n // element so it is focusable and announced, unstyled so it reads\n // as the card's heading rather than a control beside it.\n sx={{\n flex: 1,\n textAlign: 'left',\n font: 'inherit',\n fontWeight: 'medium',\n color: 'inherit',\n background: 'none',\n border: 0,\n p: 0,\n cursor: onOpen ? 'pointer' : 'inherit',\n '&:hover': onOpen ? { textDecoration: 'underline' } : undefined,\n }}\n >\n {deal.title || 'Untitled deal'}\n </Typography>\n {menu ? (\n <Box\n // The menu must not start a drag, and the sensor listens on the\n // whole card, so pointer-down here stops before it reaches it.\n onPointerDown={(event) => event.stopPropagation()}\n onKeyDown={(event) => event.stopPropagation()}\n sx={{ m: -0.5 }}\n >\n {menu}\n </Box>\n ) : null}\n </Stack>\n <Typography variant=\"subtitle2\" sx={{ mt: 0.5 }}>\n {typeof deal.amountCents === 'number'\n ? formatMoney(deal.amountCents, deal.currency)\n : '—'}\n </Typography>\n {withWhom ? (\n <Typography variant=\"caption\" color=\"text.secondary\" noWrap sx={{ display: 'block' }}>\n {withWhom}\n </Typography>\n ) : null}\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center', mt: 1 }}>\n <OwnerAvatar label={ownerLabel} size={22} />\n <Typography variant=\"caption\" color=\"text.secondary\" sx={{ flex: 1 }}>\n {deal.status === 'open'\n ? `${days} ${days === 1 ? 'day' : 'days'} in stage`\n : deal.status === 'won'\n ? 'Won'\n : 'Lost'}\n </Typography>\n </Stack>\n </Paper>\n )\n}\nDealCardBody.displayName = 'DealCardBody'\n\nexport default DealBoard\n"],"names":["mdiChevronRight","mdiOpenInNew","mdiThumbDownOutline","mdiTrophyOutline","MdiIcon","RowActionsMenu","closestCorners","DndContext","DragOverlay","KeyboardSensor","PointerSensor","useDraggable","useDroppable","useSensor","useSensors","CSS","Box","Button","Chip","CircularProgress","Paper","Stack","TabScrollButton","Tooltip","Typography","useCallback","useMemo","useState","useScrollEdges","daysInStage","formatMoney","openStages","OwnerAvatar","columnId","stageId","stageOfColumn","id","startsWith","slice","length","DealBoard","props","pipeline","deals","won","lost","closedExpanded","onToggleClosed","labelFor","moving","onOpen","onMove","onWon","onLost","nowMs","stages","edges","overflowing","start","end","byStage","map","Map","stage","set","orphans","deal","column","get","push","sensors","activationConstraint","distance","dragging","setDragging","handleDragStart","event","active","data","current","handleDragEnd","target","over","find","entry","kind","cardActions","key","label","icon","path","size","onClick","filter","name","destructive","renderCard","DealCard","ownerLabel","ownerUid","days","pending","has","$id","actions","closedStages","collisionDetection","onDragStart","onDragEnd","onDragCancel","direction","sx","alignItems","minWidth","width","orientation","disabled","page","aria-label","data-testid","ref","overflowX","pb","flex","spacing","StageColumn","folded","count","total","reduce","sum","Number","amountCents","currency","order","MAX_SAFE_INTEGER","probability","undefined","droppable","caption","rows","collapsed","onToggle","py","dropAnimation","DealCardBody","lifted","displayName","children","setNodeRef","isOver","closed","variant","flexShrink","display","flexDirection","bgcolor","borderColor","transition","theme","transitions","create","minHeight","title","placement","color","writingMode","textOrientation","textAlign","alignSelf","typography","px","noWrap","p","attributes","listeners","transform","isDragging","status","Translate","toString","opacity","cursor","outline","borderRadius","boxShadow","palette","primary","main","menu","items","withWhom","contactName","companyName","Boolean","join","elevation","component","font","fontWeight","background","border","textDecoration","onPointerDown","stopPropagation","onKeyDown","m","mt"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAGA,SACEA,eAAe,EACfC,YAAY,EACZC,mBAAmB,EACnBC,gBAAgB,QACX,yBAAwB;AAC/B,SAASC,OAAO,QAAQ,uBAAsB;AAC9C,OAAOC,oBAEA,6DAA4D;AACnE,SACEC,cAAc,EACdC,UAAU,EAEVC,WAAW,EAEXC,cAAc,EACdC,aAAa,EACbC,YAAY,EACZC,YAAY,EACZC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,GAAG,QAAQ,qBAAoB;AACxC,SACEC,GAAG,EACHC,MAAM,EACNC,IAAI,EACJC,gBAAgB,EAChBC,KAAK,EACLC,KAAK,EACLC,eAAe,EACfC,OAAO,EACPC,UAAU,QACL,gBAA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CAACjI,QAAUA,MAAMgI,eAAe;wBAC3C7F,IAAI;4BAAE+F,GAAG,CAAC;wBAAI;kCAEbjB;yBAED;;;0BAEN,KAACrK;gBAAWgI,SAAQ;gBAAYzC,IAAI;oBAAEgG,IAAI;gBAAI;0BAC3C,OAAO7I,KAAKkE,WAAW,KAAK,WACzBtG,YAAYoC,KAAKkE,WAAW,EAAElE,KAAKmE,QAAQ,IAC3C;;YAEL0D,yBACC,KAACvK;gBAAWgI,SAAQ;gBAAUa,OAAM;gBAAiBO,MAAM;gBAAC7D,IAAI;oBAAE2C,SAAS;gBAAQ;0BAChFqC;iBAED;0BACJ,MAAC1K;gBAAMyF,WAAU;gBAAMc,SAAS;gBAAGb,IAAI;oBAAEC,YAAY;oBAAU+F,IAAI;gBAAE;;kCACnE,KAAC/K;wBAAYwD,OAAOU;wBAAYP,MAAM;;kCACtC,KAACnE;wBAAWgI,SAAQ;wBAAUa,OAAM;wBAAiBtD,IAAI;4BAAEY,MAAM;wBAAE;kCAChEzD,KAAKgH,MAAM,KAAK,SACb,GAAG9E,KAAK,CAAC,EAAEA,SAAS,IAAI,QAAQ,OAAO,SAAS,CAAC,GACjDlC,KAAKgH,MAAM,KAAK,QACd,QACA;;;;;;AAKhB;AACAjC,aAAaE,WAAW,GAAG;AAE3B,eAAe3G,UAAS"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/components/deal-board.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport type { CrmDealStage } from '@aglyn/aglyn'\nimport {\n mdiChevronRight,\n mdiOpenInNew,\n mdiThumbDownOutline,\n mdiTrophyOutline,\n} from '@aglyn/shared-data-mdi'\nimport { MdiIcon } from '@aglyn/shared-ui-jsx'\nimport RowActionsMenu, {\n type RowActionsMenuItem,\n} from '@aglyn/shared-ui-jsx/components/row-actions-menu.component'\nimport { CRM_MOVE_STAGES_REFUSAL } from '../model/crm-permissions'\nimport {\n closestCorners,\n DndContext,\n type DragEndEvent,\n DragOverlay,\n type DragStartEvent,\n KeyboardSensor,\n PointerSensor,\n useDraggable,\n useDroppable,\n useSensor,\n useSensors,\n} from '@dnd-kit/core'\nimport { CSS } from '@dnd-kit/utilities'\nimport {\n Box,\n Button,\n Chip,\n CircularProgress,\n Paper,\n Stack,\n TabScrollButton,\n Tooltip,\n Typography,\n} from '@mui/material'\nimport { useCallback, useMemo, useState } from 'react'\nimport { useScrollEdges } from '../hooks/use-scroll-edges'\nimport {\n daysInStage,\n type DealDoc,\n formatMoney,\n openStages,\n type PipelineDoc,\n} from '../model/deal-board-model'\nimport { OwnerAvatar } from './owner-avatar'\n\n/** The droppable id a stage column answers to. */\nconst columnId = (stageId: string) => `stage:${stageId}`\nconst stageOfColumn = (id: unknown) =>\n typeof id === 'string' && id.startsWith('stage:') ? id.slice('stage:'.length) : null\n\nexport interface DealBoardProps {\n pipeline: PipelineDoc\n /** Every open deal in the pipeline; the board sorts them into columns. */\n deals: readonly DealDoc[]\n /** The closed columns' rows once expanded; `null` while collapsed. */\n won: readonly DealDoc[] | null\n lost: readonly DealDoc[] | null\n closedExpanded: boolean\n onToggleClosed: () => void\n /** The owner's name for a uid, from the roster. */\n labelFor: (uid: string | undefined) => string\n /** Deals whose move is in flight — drawn dimmed, not draggable. */\n moving: ReadonlySet<string>\n onOpen: (deal: DealDoc) => void\n /** \"Move contacts and deals between stages\" is known refused here (AGL-4047): cards stay put, and the menu says why. */\n moveBlocked?: boolean\n onMove: (deal: DealDoc, stageId: string) => void\n onWon: (deal: DealDoc) => void\n onLost: (deal: DealDoc) => void\n nowMs: number\n}\n\n/**\n * The pipeline as columns (AGL-2598): one per open stage, Won and Lost at\n * the end, cards dragged between them.\n *\n * ## Dragging is a request, not a write\n *\n * `@dnd-kit` handles the pointer; when a card is released over another\n * column the board calls `onMove`, and the SECTION calls the stage route.\n * The card is not moved locally: it dims while the request is in flight\n * and lands in its new column when the listener hears the write. An\n * optimistic move that the server refused — no permission, a stage the\n * pipeline lost meanwhile — would have to be animated back, and a card that\n * jumps back with no explanation reads as a bug in the board rather than a\n * refusal by the server, which is what it was.\n *\n * The pointer sensor needs a few pixels of travel before a drag begins, so\n * a click on the title still opens the deal and a click on the menu still\n * opens the menu. The keyboard sensor makes the same move reachable without\n * a mouse; the card menu's \"Move to\" items are the other route.\n *\n * ## Won and Lost fold away\n *\n * A closed deal is history, and a board that drew every won deal of the\n * year beside the four open stages would push the work off the screen. The\n * two closed columns start collapsed to a count-free stub and expand on\n * request, which is also when their rows are read — a collapsed column\n * costs no listener.\n *\n * ## Empty stages fold too, and the board says when there is more\n *\n * A pipeline with Salesforce's ten stages is wider than the card, and the\n * stages with deals in them were off the edge with nothing to say so. An\n * open stage with no deals folds to the same narrow stub, labelled and still\n * a drop target, so the stages that hold work get the room. When the row is\n * still wider than the card, chevrons at either end page it sideways the way\n * MUI's scrollable Tabs do — the scrollbar alone stays hidden on a trackpad\n * until the reader already knows to scroll.\n */\nexport function DealBoard(props: DealBoardProps) {\n const {\n pipeline,\n deals,\n won,\n lost,\n closedExpanded,\n onToggleClosed,\n labelFor,\n moving,\n onOpen,\n moveBlocked = false,\n onMove,\n onWon,\n onLost,\n nowMs,\n } = props\n const stages = useMemo(() => openStages(pipeline), [pipeline])\n const edges = useScrollEdges()\n const overflowing = edges.start || edges.end\n const byStage = useMemo(() => {\n const map = new Map<string, DealDoc[]>()\n for (const stage of stages) map.set(stage.id, [])\n const orphans: DealDoc[] = []\n for (const deal of deals) {\n const column = map.get(deal.stageId)\n if (column) column.push(deal)\n else orphans.push(deal)\n }\n return { map, orphans }\n }, [stages, deals])\n\n const sensors = useSensors(\n useSensor(PointerSensor, { activationConstraint: { distance: 6 } }),\n useSensor(KeyboardSensor),\n )\n const [dragging, setDragging] = useState<DealDoc | null>(null)\n const handleDragStart = useCallback((event: DragStartEvent) => {\n setDragging((event.active.data.current?.['deal'] as DealDoc) ?? null)\n }, [])\n const handleDragEnd = useCallback(\n (event: DragEndEvent) => {\n setDragging(null)\n const deal = event.active.data.current?.['deal'] as DealDoc | undefined\n const target = stageOfColumn(event.over?.id)\n if (!deal || !target || target === deal.stageId) return\n const stage = pipeline.stages.find((entry) => entry.id === target)\n if (!stage) return\n if (stage.kind === 'won') return onWon(deal)\n if (stage.kind === 'lost') return onLost(deal)\n onMove(deal, target)\n },\n [pipeline, onMove, onWon, onLost],\n )\n\n const blockedItem = useMemo(\n () => (moveBlocked ? { disabled: true, disabledReason: CRM_MOVE_STAGES_REFUSAL } : {}),\n [moveBlocked],\n )\n const cardActions = useCallback(\n (deal: DealDoc): RowActionsMenuItem[] => [\n {\n key: 'open',\n label: 'Open',\n icon: <MdiIcon path={mdiOpenInNew.path} size={0.8} />,\n onClick: () => onOpen(deal),\n },\n ...stages\n .filter((stage) => stage.id !== deal.stageId)\n .map((stage) => ({\n key: `move:${stage.id}`,\n label: `Move to ${stage.name}`,\n icon: <MdiIcon path={mdiChevronRight.path} size={0.8} />,\n onClick: () => onMove(deal, stage.id),\n ...blockedItem,\n })),\n {\n key: 'won',\n label: 'Mark won',\n icon: <MdiIcon path={mdiTrophyOutline.path} size={0.8} />,\n onClick: () => onWon(deal),\n ...blockedItem,\n },\n {\n key: 'lost',\n label: 'Mark lost',\n icon: <MdiIcon path={mdiThumbDownOutline.path} size={0.8} />,\n onClick: () => onLost(deal),\n destructive: true,\n ...blockedItem,\n },\n ],\n [stages, onOpen, onMove, onWon, onLost, blockedItem],\n )\n\n const renderCard = (deal: DealDoc) => (\n <DealCard\n key={deal.$id}\n deal={deal}\n ownerLabel={labelFor(deal.ownerUid)}\n days={daysInStage(deal, nowMs)}\n pending={moving.has(deal.$id)}\n actions={cardActions(deal)}\n locked={moveBlocked}\n onOpen={() => onOpen(deal)}\n />\n )\n\n const closedStages = pipeline.stages.filter((stage) => stage.kind !== 'open')\n\n return (\n <DndContext\n sensors={sensors}\n collisionDetection={closestCorners}\n onDragStart={handleDragStart}\n onDragEnd={handleDragEnd}\n onDragCancel={() => setDragging(null)}\n >\n {/*\n The board scrolls sideways; the page does not. The columns are\n fixed-width and refuse to shrink, so the row is as wide as its\n stages — and a flex item's implicit `min-width: auto` would hand\n that width up to the card and the page rather than clip it here.\n `minWidth: 0` is what lets this box be narrower than its content,\n which is the whole condition for the scrollbar to appear on it.\n */}\n <Stack direction=\"row\" sx={{ alignItems: 'stretch', minWidth: 0, width: '100%' }}>\n {overflowing ? (\n <TabScrollButton\n direction=\"left\"\n orientation=\"horizontal\"\n disabled={!edges.start}\n onClick={() => edges.page(-1)}\n aria-label=\"Show earlier stages\"\n data-testid=\"deal-board-scroll-start\"\n />\n ) : null}\n <Box ref={edges.ref} sx={{ overflowX: 'auto', pb: 1, minWidth: 0, flex: 1 }}>\n <Stack direction=\"row\" spacing={1.5} sx={{ alignItems: 'stretch', minWidth: 'max-content' }}>\n {stages.map((stage) => (\n <StageColumn\n key={stage.id}\n stage={stage}\n folded={!byStage.map.get(stage.id)?.length}\n count={byStage.map.get(stage.id)?.length ?? 0}\n total={(byStage.map.get(stage.id) ?? []).reduce(\n (sum, deal) => sum + (Number(deal.amountCents) || 0),\n 0,\n )}\n currency={byStage.map.get(stage.id)?.[0]?.currency}\n >\n {(byStage.map.get(stage.id) ?? []).map(renderCard)}\n </StageColumn>\n ))}\n {byStage.orphans.length ? (\n <StageColumn\n stage={{\n id: '__orphans',\n name: 'No stage',\n order: Number.MAX_SAFE_INTEGER,\n probability: 0,\n kind: 'open',\n }}\n count={byStage.orphans.length}\n total={0}\n currency={undefined}\n droppable={false}\n caption=\"These deals sit in a stage the pipeline no longer has. Move them.\"\n >\n {byStage.orphans.map(renderCard)}\n </StageColumn>\n ) : null}\n {closedStages.map((stage) => {\n const rows = stage.kind === 'won' ? won : lost\n return (\n <StageColumn\n key={stage.id}\n stage={stage}\n count={rows?.length ?? null}\n total={null}\n currency={undefined}\n collapsed={!closedExpanded}\n onToggle={onToggleClosed}\n >\n {closedExpanded && rows === null ? (\n <Stack sx={{ alignItems: 'center', py: 2 }}>\n <CircularProgress size={20} />\n </Stack>\n ) : (\n (rows ?? []).map(renderCard)\n )}\n </StageColumn>\n )\n })}\n </Stack>\n </Box>\n {overflowing ? (\n <TabScrollButton\n direction=\"right\"\n orientation=\"horizontal\"\n disabled={!edges.end}\n onClick={() => edges.page(1)}\n aria-label=\"Show later stages\"\n data-testid=\"deal-board-scroll-end\"\n />\n ) : null}\n </Stack>\n <DragOverlay dropAnimation={null}>\n {dragging ? (\n <DealCardBody\n deal={dragging}\n ownerLabel={labelFor(dragging.ownerUid)}\n days={daysInStage(dragging, nowMs)}\n lifted\n />\n ) : null}\n </DragOverlay>\n </DndContext>\n )\n}\nDealBoard.displayName = 'DealBoard'\n\ninterface StageColumnProps {\n stage: CrmDealStage\n /** Cards in the column, or null while a closed column has not loaded. */\n count: number | null\n /** The column's open value in cents, or null for a closed column. */\n total: number | null\n currency: string | undefined\n droppable?: boolean\n collapsed?: boolean\n /**\n * An open stage with no deals, drawn as a narrow labelled stub — still a\n * drop target, unlike a collapsed closed column, so a deal can be dragged\n * into it.\n */\n folded?: boolean\n onToggle?: () => void\n caption?: string\n children?: React.ReactNode\n}\n\nfunction StageColumn(props: StageColumnProps) {\n const {\n stage,\n count,\n total,\n currency,\n droppable = true,\n collapsed = false,\n folded = false,\n onToggle,\n caption,\n children,\n } = props\n const { setNodeRef, isOver } = useDroppable({\n id: columnId(stage.id),\n disabled: !droppable || collapsed,\n })\n const closed = stage.kind !== 'open'\n return (\n <Paper\n ref={setNodeRef}\n variant=\"outlined\"\n sx={{\n width: collapsed || folded ? 56 : 260,\n flexShrink: 0,\n display: 'flex',\n flexDirection: 'column',\n bgcolor: isOver ? 'action.hover' : 'background.default',\n borderColor: isOver ? 'primary.main' : undefined,\n transition: (theme) => theme.transitions.create(['background-color', 'border-color', 'width']),\n minHeight: 240,\n }}\n >\n {folded && !collapsed ? (\n <Tooltip title={`${stage.name}: no deals · ${stage.probability}% likely to close`} placement=\"top\">\n <Typography\n variant=\"subtitle2\"\n color=\"text.secondary\"\n data-testid=\"deal-board-folded-stage\"\n sx={{\n flex: 1,\n writingMode: 'vertical-rl',\n textOrientation: 'mixed',\n textAlign: 'center',\n py: 2,\n alignSelf: 'center',\n }}\n >\n {stage.name}\n </Typography>\n </Tooltip>\n ) : collapsed ? (\n <Button\n onClick={onToggle}\n sx={{\n flex: 1,\n writingMode: 'vertical-rl',\n textOrientation: 'mixed',\n py: 2,\n typography: 'subtitle2',\n }}\n color={stage.kind === 'won' ? 'success' : 'inherit'}\n >\n {stage.name}\n </Button>\n ) : (\n <>\n <Stack\n direction=\"row\"\n spacing={1}\n sx={{ alignItems: 'center', px: 1.5, py: 1 }}\n >\n <Typography variant=\"subtitle2\" sx={{ flex: 1 }} noWrap>\n {stage.name}\n </Typography>\n {count !== null ? <Chip size=\"small\" label={count} /> : null}\n {closed && onToggle ? (\n <Button size=\"small\" onClick={onToggle}>\n {'Hide'}\n </Button>\n ) : null}\n </Stack>\n {!closed ? (\n <Typography variant=\"caption\" color=\"text.secondary\" sx={{ px: 1.5 }}>\n {`${stage.probability}% · ${total ? formatMoney(total, currency) : 'no value yet'}`}\n </Typography>\n ) : null}\n {caption ? (\n <Typography variant=\"caption\" color=\"warning.main\" sx={{ px: 1.5 }}>\n {caption}\n </Typography>\n ) : null}\n <Stack spacing={1} sx={{ p: 1, flex: 1 }}>\n {children}\n </Stack>\n </>\n )}\n </Paper>\n )\n}\nStageColumn.displayName = 'StageColumn'\n\ninterface DealCardProps {\n deal: DealDoc\n ownerLabel: string\n days: number\n pending: boolean\n /** The member may not move it (AGL-4047): no drag, and its menu says why. */\n locked: boolean\n actions: RowActionsMenuItem[]\n onOpen: () => void\n}\n\nfunction DealCard(props: DealCardProps) {\n const { deal, ownerLabel, days, pending, locked, actions, onOpen } = props\n const { attributes, listeners, setNodeRef, transform, isDragging } = useDraggable({\n id: deal.$id,\n data: { deal },\n disabled: pending || locked || deal.status !== 'open',\n })\n return (\n <Box\n ref={setNodeRef}\n sx={{\n transform: CSS.Translate.toString(transform),\n opacity: isDragging ? 0.3 : pending ? 0.5 : 1,\n cursor: deal.status === 'open' && !pending && !locked ? 'grab' : 'default',\n outline: 'none',\n '&:focus-visible': {\n borderRadius: 1,\n boxShadow: (theme) => `0 0 0 2px ${theme.palette.primary.main}`,\n },\n }}\n // The sensor's attributes and listeners carry no `sx`, and they come\n // AFTER it so the card's own styles are what the rule sees first.\n {...attributes}\n {...listeners}\n >\n <DealCardBody\n deal={deal}\n ownerLabel={ownerLabel}\n days={days}\n menu={<RowActionsMenu items={actions} label={deal.title} />}\n onOpen={onOpen}\n />\n </Box>\n )\n}\nDealCard.displayName = 'DealCard'\n\ninterface DealCardBodyProps {\n deal: DealDoc\n ownerLabel: string\n days: number\n menu?: React.ReactNode\n onOpen?: () => void\n lifted?: boolean\n}\n\n/**\n * What a card shows: the title, the amount, who it is with, the owner and\n * how long it has sat here. Shared by the card in its column and the copy\n * that follows the pointer, so the two cannot drift.\n */\nexport function DealCardBody(props: DealCardBodyProps) {\n const { deal, ownerLabel, days, menu, onOpen, lifted } = props\n const withWhom = [deal.contactName, deal.companyName].filter(Boolean).join(' · ')\n return (\n <Paper\n elevation={lifted ? 6 : 1}\n sx={{ p: 1.25, width: lifted ? 244 : undefined }}\n >\n <Stack direction=\"row\" spacing={0.5} sx={{ alignItems: 'flex-start' }}>\n <Typography\n variant=\"body2\"\n component={onOpen ? 'button' : 'span'}\n onClick={onOpen}\n // The title is the link into the deal, drawn as text: a button\n // element so it is focusable and announced, unstyled so it reads\n // as the card's heading rather than a control beside it.\n sx={{\n flex: 1,\n textAlign: 'left',\n font: 'inherit',\n fontWeight: 'medium',\n color: 'inherit',\n background: 'none',\n border: 0,\n p: 0,\n cursor: onOpen ? 'pointer' : 'inherit',\n '&:hover': onOpen ? { textDecoration: 'underline' } : undefined,\n }}\n >\n {deal.title || 'Untitled deal'}\n </Typography>\n {menu ? (\n <Box\n // The menu must not start a drag, and the sensor listens on the\n // whole card, so pointer-down here stops before it reaches it.\n onPointerDown={(event) => event.stopPropagation()}\n onKeyDown={(event) => event.stopPropagation()}\n sx={{ m: -0.5 }}\n >\n {menu}\n </Box>\n ) : null}\n </Stack>\n <Typography variant=\"subtitle2\" sx={{ mt: 0.5 }}>\n {typeof deal.amountCents === 'number'\n ? formatMoney(deal.amountCents, deal.currency)\n : '—'}\n </Typography>\n {withWhom ? (\n <Typography variant=\"caption\" color=\"text.secondary\" noWrap sx={{ display: 'block' }}>\n {withWhom}\n </Typography>\n ) : null}\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center', mt: 1 }}>\n <OwnerAvatar label={ownerLabel} size={22} />\n <Typography variant=\"caption\" color=\"text.secondary\" sx={{ flex: 1 }}>\n {deal.status === 'open'\n ? `${days} ${days === 1 ? 'day' : 'days'} in stage`\n : deal.status === 'won'\n ? 'Won'\n : 'Lost'}\n </Typography>\n </Stack>\n </Paper>\n )\n}\nDealCardBody.displayName = 'DealCardBody'\n\nexport default DealBoard\n"],"names":["mdiChevronRight","mdiOpenInNew","mdiThumbDownOutline","mdiTrophyOutline","MdiIcon","RowActionsMenu","CRM_MOVE_STAGES_REFUSAL","closestCorners","DndContext","DragOverlay","KeyboardSensor","PointerSensor","useDraggable","useDroppable","useSensor","useSensors","CSS","Box","Button","Chip","CircularProgress","Paper","Stack","TabScrollButton","Tooltip","Typography","useCallback","useMemo","useState","useScrollEdges","daysInStage","formatMoney","openStages","OwnerAvatar","columnId","stageId","stageOfColumn","id","startsWith","slice","length","DealBoard","props","pipeline","deals","won","lost","closedExpanded","onToggleClosed","labelFor","moving","onOpen","moveBlocked","onMove","onWon","onLost","nowMs","stages","edges","overflowing","start","end","byStage","map","Map","stage","set","orphans","deal","column","get","push","sensors","activationConstraint","distance","dragging","setDragging","handleDragStart","event","active","data","current","handleDragEnd","target","over","find","entry","kind","blockedItem","disabled","disabledReason","cardActions","key","label","icon","path","size","onClick","filter","name","destructive","renderCard","DealCard","ownerLabel","ownerUid","days","pending","has","$id","actions","locked","closedStages","collisionDetection","onDragStart","onDragEnd","onDragCancel","direction","sx","alignItems","minWidth","width","orientation","page","aria-label","data-testid","ref","overflowX","pb","flex","spacing","StageColumn","folded","count","total","reduce","sum","Number","amountCents","currency","order","MAX_SAFE_INTEGER","probability","undefined","droppable","caption","rows","collapsed","onToggle","py","dropAnimation","DealCardBody","lifted","displayName","children","setNodeRef","isOver","closed","variant","flexShrink","display","flexDirection","bgcolor","borderColor","transition","theme","transitions","create","minHeight","title","placement","color","writingMode","textOrientation","textAlign","alignSelf","typography","px","noWrap","p","attributes","listeners","transform","isDragging","status","Translate","toString","opacity","cursor","outline","borderRadius","boxShadow","palette","primary","main","menu","items","withWhom","contactName","companyName","Boolean","join","elevation","component","font","fontWeight","background","border","textDecoration","onPointerDown","stopPropagation","onKeyDown","m","mt"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAGA,SACEA,eAAe,EACfC,YAAY,EACZC,mBAAmB,EACnBC,gBAAgB,QACX,yBAAwB;AAC/B,SAASC,OAAO,QAAQ,uBAAsB;AAC9C,OAAOC,oBAEA,6DAA4D;AACnE,SAASC,uBAAuB,QAAQ,8BAA0B;AAClE,SACEC,cAAc,EACdC,UAAU,EAEVC,WAAW,EAEXC,cAAc,EACdC,aAAa,EACbC,YAAY,EACZC,YAAY,EACZC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,GAAG,QAAQ,qBAAoB;AACxC,SACEC,GAAG,EACHC,MAAM,EACNC,IAAI,EACJC,gBAAgB,EAChBC,KAAK,EACLC,KAAK,EACLC,eAAe,EACfC,OAA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,YAAY;4BAC7B,WAAWA,SAAS;gCAAE4J,gBAAgB;4BAAY,IAAIjE;wBACxD;kCAEC1E,KAAKoG,KAAK,IAAI;;oBAEhB0B,qBACC,KAACjL;wBACC,gEAAgE;wBAChE,+DAA+D;wBAC/D+L,eAAe,CAAClI,QAAUA,MAAMmI,eAAe;wBAC/CC,WAAW,CAACpI,QAAUA,MAAMmI,eAAe;wBAC3C5F,IAAI;4BAAE8F,GAAG,CAAC;wBAAI;kCAEbjB;yBAED;;;0BAEN,KAACzK;gBAAWoI,SAAQ;gBAAYxC,IAAI;oBAAE+F,IAAI;gBAAI;0BAC3C,OAAOhJ,KAAKqE,WAAW,KAAK,WACzB1G,YAAYqC,KAAKqE,WAAW,EAAErE,KAAKsE,QAAQ,IAC3C;;YAEL0D,yBACC,KAAC3K;gBAAWoI,SAAQ;gBAAUa,OAAM;gBAAiBO,MAAM;gBAAC5D,IAAI;oBAAE0C,SAAS;gBAAQ;0BAChFqC;iBAED;0BACJ,MAAC9K;gBAAM8F,WAAU;gBAAMa,SAAS;gBAAGZ,IAAI;oBAAEC,YAAY;oBAAU8F,IAAI;gBAAE;;kCACnE,KAACnL;wBAAY4D,OAAOU;wBAAYP,MAAM;;kCACtC,KAACvE;wBAAWoI,SAAQ;wBAAUa,OAAM;wBAAiBrD,IAAI;4BAAEW,MAAM;wBAAE;kCAChE5D,KAAKmH,MAAM,KAAK,SACb,GAAG9E,KAAK,CAAC,EAAEA,SAAS,IAAI,QAAQ,OAAO,SAAS,CAAC,GACjDrC,KAAKmH,MAAM,KAAK,QACd,QACA;;;;;;AAKhB;AACAjC,aAAaE,WAAW,GAAG;AAE3B,eAAe/G,UAAS"}
@@ -18,9 +18,11 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
18
18
  import { CRM_FORECAST_CATEGORY_LABELS, dealForecastCategory, dealProbability, pluginDocsHelp } from "@aglyn/aglyn";
19
19
  import { mdiThumbDownOutline, mdiTrophyOutline } from "@aglyn/shared-data-mdi";
20
20
  import { CardDisplay, MdiIcon } from "@aglyn/shared-ui-jsx";
21
+ import { BlockedControl } from "@aglyn/shared-ui-jsx/components/blocked-control.component";
21
22
  import { useSnackbar } from "@aglyn/shared-ui-snackstack";
22
23
  import { Button, Chip, ListItemIcon, ListItemText, Menu, MenuItem, Stack, Step, StepButton, StepLabel, Stepper, TextField, Typography } from "@mui/material";
23
24
  import { useCallback, useState } from "react";
25
+ import { CRM_MOVE_STAGES_REFUSAL } from "../model/crm-permissions.js";
24
26
  import { closingStage, daysInStage, DEAL_STATUS_LABELS, openStages } from "../model/deal-board-model.js";
25
27
  import { LostReasonDialog } from "./lost-reason-dialog.js";
26
28
  /**
@@ -53,6 +55,9 @@ import { LostReasonDialog } from "./lost-reason-dialog.js";
53
55
  const activeIndex = stages.findIndex((stage)=>stage.id === deal.stageId);
54
56
  const wonName = (_ref = (_closingStage = closingStage(pipeline, 'won')) == null ? void 0 : _closingStage.name) != null ? _ref : DEAL_STATUS_LABELS.won;
55
57
  const lostName = (_ref1 = (_closingStage1 = closingStage(pipeline, 'lost')) == null ? void 0 : _closingStage1.name) != null ? _ref1 : DEAL_STATUS_LABELS.lost;
58
+ // "Move contacts and deals between stages" (AGL-4047): every control below
59
+ // stays in view, switched off, with the permission named.
60
+ const blocked = api.moveBlocked === true;
56
61
  const run = useCallback(async (request, done)=>{
57
62
  setBusy(true);
58
63
  try {
@@ -87,8 +92,8 @@ import { LostReasonDialog } from "./lost-reason-dialog.js";
87
92
  stages.map((stage, index)=>/*#__PURE__*/ _jsx(Step, {
88
93
  completed: closed || index < activeIndex,
89
94
  children: /*#__PURE__*/ _jsx(StepButton, {
90
- title: closed ? undefined : `Move here: ${stage.probability}% likely to close`,
91
- disabled: busy || closed || stage.id === deal.stageId,
95
+ title: closed ? undefined : blocked ? CRM_MOVE_STAGES_REFUSAL : `Move here: ${stage.probability}% likely to close`,
96
+ disabled: busy || closed || blocked || stage.id === deal.stageId,
92
97
  onClick: ()=>void run(()=>api.moveToStage(deal, stage.id), `Moved to ${stage.name}`),
93
98
  children: stage.name
94
99
  })
@@ -97,8 +102,8 @@ import { LostReasonDialog } from "./lost-reason-dialog.js";
97
102
  completed: deal.status === 'won',
98
103
  children: /*#__PURE__*/ _jsx(StepButton, {
99
104
  "data-testid": "deal-stage-closing-step",
100
- title: closed ? undefined : 'Close the deal as won or lost',
101
- disabled: busy || closed,
105
+ title: closed ? undefined : blocked ? CRM_MOVE_STAGES_REFUSAL : 'Close the deal as won or lost',
106
+ disabled: busy || closed || blocked,
102
107
  onClick: (event)=>setCloseMenu(event.currentTarget),
103
108
  icon: deal.status === 'won' ? /*#__PURE__*/ _jsx(MdiIcon, {
104
109
  path: mdiTrophyOutline.path,
@@ -127,29 +132,37 @@ import { LostReasonDialog } from "./lost-reason-dialog.js";
127
132
  direction: "row",
128
133
  spacing: 1,
129
134
  children: [
130
- /*#__PURE__*/ _jsx(Button, {
131
- size: "small",
132
- color: "success",
133
- variant: "outlined",
134
- disabled: busy || !pipeline,
135
- startIcon: /*#__PURE__*/ _jsx(MdiIcon, {
136
- path: mdiTrophyOutline.path,
137
- size: 0.8
138
- }),
139
- onClick: ()=>void run(()=>api.markWon(deal), 'Deal won'),
140
- children: 'Won'
135
+ /*#__PURE__*/ _jsx(BlockedControl, {
136
+ blocked: blocked,
137
+ reason: CRM_MOVE_STAGES_REFUSAL,
138
+ children: /*#__PURE__*/ _jsx(Button, {
139
+ size: "small",
140
+ color: "success",
141
+ variant: "outlined",
142
+ disabled: busy || !pipeline,
143
+ startIcon: /*#__PURE__*/ _jsx(MdiIcon, {
144
+ path: mdiTrophyOutline.path,
145
+ size: 0.8
146
+ }),
147
+ onClick: ()=>void run(()=>api.markWon(deal), 'Deal won'),
148
+ children: 'Won'
149
+ })
141
150
  }),
142
- /*#__PURE__*/ _jsx(Button, {
143
- size: "small",
144
- color: "error",
145
- variant: "outlined",
146
- disabled: busy || !pipeline,
147
- startIcon: /*#__PURE__*/ _jsx(MdiIcon, {
148
- path: mdiThumbDownOutline.path,
149
- size: 0.8
150
- }),
151
- onClick: ()=>setLosing(true),
152
- children: 'Lost'
151
+ /*#__PURE__*/ _jsx(BlockedControl, {
152
+ blocked: blocked,
153
+ reason: CRM_MOVE_STAGES_REFUSAL,
154
+ children: /*#__PURE__*/ _jsx(Button, {
155
+ size: "small",
156
+ color: "error",
157
+ variant: "outlined",
158
+ disabled: busy || !pipeline,
159
+ startIcon: /*#__PURE__*/ _jsx(MdiIcon, {
160
+ path: mdiThumbDownOutline.path,
161
+ size: 0.8
162
+ }),
163
+ onClick: ()=>setLosing(true),
164
+ children: 'Lost'
165
+ })
153
166
  })
154
167
  ]
155
168
  }) : null
@@ -192,13 +205,13 @@ import { LostReasonDialog } from "./lost-reason-dialog.js";
192
205
  size: "small",
193
206
  label: "Reopen into",
194
207
  value: "",
195
- disabled: busy,
208
+ disabled: busy || blocked,
196
209
  onChange: (event)=>{
197
210
  const stageId = event.target.value;
198
211
  if (!stageId) return;
199
212
  void run(()=>api.moveToStage(deal, stageId), 'Deal reopened');
200
213
  },
201
- helperText: "Reopening puts the deal back in an open stage and tells the automations.",
214
+ helperText: blocked ? CRM_MOVE_STAGES_REFUSAL : 'Reopening puts the deal back in an open stage and tells the automations.',
202
215
  sx: {
203
216
  maxWidth: 320
204
217
  },
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/components/deal-stage-card.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport {\n CRM_FORECAST_CATEGORY_LABELS,\n dealForecastCategory,\n dealProbability,\n pluginDocsHelp,\n} from '@aglyn/aglyn'\nimport { mdiThumbDownOutline, mdiTrophyOutline } from '@aglyn/shared-data-mdi'\nimport { CardDisplay, MdiIcon } from '@aglyn/shared-ui-jsx'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport {\n Button,\n Chip,\n ListItemIcon,\n ListItemText,\n Menu,\n MenuItem,\n Stack,\n Step,\n StepButton,\n StepLabel,\n Stepper,\n TextField,\n Typography,\n} from '@mui/material'\nimport { useCallback, useState } from 'react'\nimport { type DealStageApi } from '../hooks/use-deal-stage-api'\nimport {\n closingStage,\n daysInStage,\n DEAL_STATUS_LABELS,\n type DealDoc,\n openStages,\n type PipelineDoc,\n} from '../model/deal-board-model'\nimport { LostReasonDialog } from './lost-reason-dialog'\n\nexport interface DealStageCardProps {\n deal: DealDoc\n pipeline: PipelineDoc | null\n api: DealStageApi\n nowMs: number\n}\n\n/**\n * Where the deal is, and the controls that move it (AGL-2598).\n *\n * A path across the whole pipeline, the way Salesforce draws one: every open\n * stage — click one to move there — and then one closing step, so the stages\n * still ahead of the deal are always in view and the path ends where every\n * deal ends. The closing step reads \"Closed\" while the deal is open and asks\n * won or lost when chosen, the same two moves as the buttons in the header;\n * once the deal is closed it reads the pipeline's own name for the verdict.\n * Every move calls the stage route, never Firestore: the move is what an\n * automation listens for, and the route is the only writer that emits it.\n * Under a closed deal's path sits the verdict — when, and why — and a way\n * back: reopening is a move into an open stage, which the route emits as\n * `dealStageChanged` like any other move.\n *\n * The line under the stepper reads the deal's own probability and forecast\n * category (AGL-3516) — a move gives it the new stage's, which the route\n * stamps, and the stepper says so on hover.\n */\nexport function DealStageCard(props: DealStageCardProps) {\n const { deal, pipeline, api, nowMs } = props\n const { enqueueSnackbar } = useSnackbar()\n const [busy, setBusy] = useState(false)\n const [losing, setLosing] = useState(false)\n const [closeMenu, setCloseMenu] = useState<HTMLElement | null>(null)\n const stages = openStages(pipeline)\n const activeIndex = stages.findIndex((stage) => stage.id === deal.stageId)\n const wonName = closingStage(pipeline, 'won')?.name ?? DEAL_STATUS_LABELS.won\n const lostName = closingStage(pipeline, 'lost')?.name ?? DEAL_STATUS_LABELS.lost\n\n const run = useCallback(\n async (request: () => Promise<unknown>, done: string) => {\n setBusy(true)\n try {\n await request()\n enqueueSnackbar(done, { variant: 'success', persist: false })\n return true\n } catch (error) {\n enqueueSnackbar(\n error instanceof Error ? error.message : 'The deal could not be moved.',\n { variant: 'warning', allowDuplicate: true },\n )\n return false\n } finally {\n setBusy(false)\n }\n },\n [enqueueSnackbar],\n )\n\n const closed = deal.status !== 'open'\n const days = daysInStage(deal, nowMs)\n const current = activeIndex === -1 ? null : stages[activeIndex]\n const probability = dealProbability(deal, current)\n const forecast = CRM_FORECAST_CATEGORY_LABELS[dealForecastCategory(deal, current)]\n\n const path = (\n <Stepper nonLinear activeStep={closed ? stages.length : activeIndex} alternativeLabel>\n {stages.map((stage, index) => (\n <Step key={stage.id} completed={closed || index < activeIndex}>\n <StepButton\n title={closed ? undefined : `Move here: ${stage.probability}% likely to close`}\n disabled={busy || closed || stage.id === deal.stageId}\n onClick={() =>\n void run(() => api.moveToStage(deal, stage.id), `Moved to ${stage.name}`)\n }\n >\n {stage.name}\n </StepButton>\n </Step>\n ))}\n <Step key=\"$closed\" completed={deal.status === 'won'}>\n <StepButton\n data-testid=\"deal-stage-closing-step\"\n title={closed ? undefined : 'Close the deal as won or lost'}\n disabled={busy || closed}\n onClick={(event) => setCloseMenu(event.currentTarget)}\n icon={\n deal.status === 'won' ? (\n <MdiIcon path={mdiTrophyOutline.path} color=\"success\" fontSize=\"medium\" />\n ) : deal.status === 'lost' ? (\n <MdiIcon path={mdiThumbDownOutline.path} color=\"error\" fontSize=\"medium\" />\n ) : undefined\n }\n >\n <StepLabel error={deal.status === 'lost'}>\n {deal.status === 'won' ? wonName : deal.status === 'lost' ? lostName : 'Closed'}\n </StepLabel>\n </StepButton>\n </Step>\n </Stepper>\n )\n\n return (\n <CardDisplay\n header={'Stage'}\n help={pluginDocsHelp('deals', { anchor: '#moving-winning-and-losing' })}\n HeaderProps={{\n action: !closed ? (\n <Stack direction=\"row\" spacing={1}>\n <Button\n size=\"small\"\n color=\"success\"\n variant=\"outlined\"\n disabled={busy || !pipeline}\n startIcon={<MdiIcon path={mdiTrophyOutline.path} size={0.8} />}\n onClick={() => void run(() => api.markWon(deal), 'Deal won')}\n >\n {'Won'}\n </Button>\n <Button\n size=\"small\"\n color=\"error\"\n variant=\"outlined\"\n disabled={busy || !pipeline}\n startIcon={<MdiIcon path={mdiThumbDownOutline.path} size={0.8} />}\n onClick={() => setLosing(true)}\n >\n {'Lost'}\n </Button>\n </Stack>\n ) : null,\n }}\n contentGutterX\n contentGutterY\n >\n {!pipeline ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {\"This deal's pipeline no longer exists, so it has no stages to move through.\"}\n </Typography>\n ) : closed ? (\n <Stack spacing={1.5}>\n {path}\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Chip\n label={DEAL_STATUS_LABELS[deal.status]}\n color={deal.status === 'won' ? 'success' : 'default'}\n />\n <Typography variant=\"body2\" color=\"text.secondary\">\n {typeof deal.closedAtMs === 'number'\n ? `Closed ${new Date(deal.closedAtMs).toLocaleDateString()}`\n : 'Closed'}\n </Typography>\n </Stack>\n {deal.status === 'lost' && deal.lostReason ? (\n <Typography variant=\"body2\">{deal.lostReason}</Typography>\n ) : null}\n <TextField\n select\n size=\"small\"\n label=\"Reopen into\"\n value=\"\"\n disabled={busy}\n onChange={(event) => {\n const stageId = event.target.value\n if (!stageId) return\n void run(() => api.moveToStage(deal, stageId), 'Deal reopened')\n }}\n helperText=\"Reopening puts the deal back in an open stage and tells the automations.\"\n sx={{ maxWidth: 320 }}\n >\n <MenuItem value=\"\">{'Pick a stage'}</MenuItem>\n {stages.map((stage) => (\n <MenuItem key={stage.id} value={stage.id}>\n {stage.name}\n </MenuItem>\n ))}\n </TextField>\n </Stack>\n ) : (\n <Stack spacing={1.5}>\n {path}\n <Typography variant=\"body2\" color=\"text.secondary\" sx={{ textAlign: 'center' }}>\n {!current\n ? 'This deal sits in a stage the pipeline no longer has. Pick one above.'\n : `${days} ${days === 1 ? 'day' : 'days'} in ${current.name} · ` +\n `${probability ?? current.probability}% likely to close · ${forecast}`}\n </Typography>\n </Stack>\n )}\n <Menu anchorEl={closeMenu} open={Boolean(closeMenu)} onClose={() => setCloseMenu(null)}>\n <MenuItem\n onClick={() => {\n setCloseMenu(null)\n void run(() => api.markWon(deal), 'Deal won')\n }}\n >\n <ListItemIcon>\n <MdiIcon path={mdiTrophyOutline.path} color=\"success\" />\n </ListItemIcon>\n <ListItemText>{wonName}</ListItemText>\n </MenuItem>\n <MenuItem\n onClick={() => {\n setCloseMenu(null)\n setLosing(true)\n }}\n >\n <ListItemIcon>\n <MdiIcon path={mdiThumbDownOutline.path} color=\"error\" />\n </ListItemIcon>\n <ListItemText>{lostName}</ListItemText>\n </MenuItem>\n </Menu>\n <LostReasonDialog\n open={losing}\n dealTitle={deal.title}\n busy={busy}\n onClose={() => setLosing(false)}\n onConfirm={(reason) =>\n void run(() => api.markLost(deal, reason), 'Deal marked lost').then(\n (ok) => ok && setLosing(false),\n )\n }\n />\n </CardDisplay>\n )\n}\nDealStageCard.displayName = 'DealStageCard'\n\nexport default DealStageCard\n"],"names":["CRM_FORECAST_CATEGORY_LABELS","dealForecastCategory","dealProbability","pluginDocsHelp","mdiThumbDownOutline","mdiTrophyOutline","CardDisplay","MdiIcon","useSnackbar","Button","Chip","ListItemIcon","ListItemText","Menu","MenuItem","Stack","Step","StepButton","StepLabel","Stepper","TextField","Typography","useCallback","useState","closingStage","daysInStage","DEAL_STATUS_LABELS","openStages","LostReasonDialog","DealStageCard","props","deal","pipeline","api","nowMs","enqueueSnackbar","busy","setBusy","losing","setLosing","closeMenu","setCloseMenu","stages","activeIndex","findIndex","stage","id","stageId","wonName","name","won","lostName","lost","run","request","done","variant","persist","error","Error","message","allowDuplicate","closed","status","days","current","probability","forecast","path","nonLinear","activeStep","length","alternativeLabel","map","index","completed","title","undefined","disabled","onClick","moveToStage","data-testid","event","currentTarget","icon","color","fontSize","header","help","anchor","HeaderProps","action","direction","spacing","size","startIcon","markWon","contentGutterX","contentGutterY","sx","alignItems","label","closedAtMs","Date","toLocaleDateString","lostReason","select","value","onChange","target","helperText","maxWidth","textAlign","anchorEl","open","Boolean","onClose","dealTitle","onConfirm","reason","markLost","then","ok","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;AAEA,SACEA,4BAA4B,EAC5BC,oBAAoB,EACpBC,eAAe,EACfC,cAAc,QACT,eAAc;AACrB,SAASC,mBAAmB,EAAEC,gBAAgB,QAAQ,yBAAwB;AAC9E,SAASC,WAAW,EAAEC,OAAO,QAAQ,uBAAsB;AAC3D,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SACEC,MAAM,EACNC,IAAI,EACJC,YAAY,EACZC,YAAY,EACZC,IAAI,EACJC,QAAQ,EACRC,KAAK,EACLC,IAAI,EACJC,UAAU,EACVC,SAAS,EACTC,OAAO,EACPC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,WAAW,EAAEC,QAAQ,QAAQ,QAAO;AAE7C,SACEC,YAAY,EACZC,WAAW,EACXC,kBAAkB,EAElBC,UAAU,QAEL,+BAA2B;AAClC,SAASC,gBAAgB,QAAQ,0BAAsB;AASvD;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,SAASC,cAAcC,KAAyB;;QAQrCN,eACCA;IARjB,MAAM,EAAEO,IAAI,EAAEC,QAAQ,EAAEC,GAAG,EAAEC,KAAK,EAAE,GAAGJ;IACvC,MAAM,EAAEK,eAAe,EAAE,GAAG3B;IAC5B,MAAM,CAAC4B,MAAMC,QAAQ,GAAGd,SAAS;IACjC,MAAM,CAACe,QAAQC,UAAU,GAAGhB,SAAS;IACrC,MAAM,CAACiB,WAAWC,aAAa,GAAGlB,SAA6B;IAC/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}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/components/deal-stage-card.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport {\n CRM_FORECAST_CATEGORY_LABELS,\n dealForecastCategory,\n dealProbability,\n pluginDocsHelp,\n} from '@aglyn/aglyn'\nimport { mdiThumbDownOutline, mdiTrophyOutline } from '@aglyn/shared-data-mdi'\nimport { CardDisplay, MdiIcon } from '@aglyn/shared-ui-jsx'\nimport { BlockedControl } from '@aglyn/shared-ui-jsx/components/blocked-control.component'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport {\n Button,\n Chip,\n ListItemIcon,\n ListItemText,\n Menu,\n MenuItem,\n Stack,\n Step,\n StepButton,\n StepLabel,\n Stepper,\n TextField,\n Typography,\n} from '@mui/material'\nimport { useCallback, useState } from 'react'\nimport { type DealStageApi } from '../hooks/use-deal-stage-api'\nimport { CRM_MOVE_STAGES_REFUSAL } from '../model/crm-permissions'\nimport {\n closingStage,\n daysInStage,\n DEAL_STATUS_LABELS,\n type DealDoc,\n openStages,\n type PipelineDoc,\n} from '../model/deal-board-model'\nimport { LostReasonDialog } from './lost-reason-dialog'\n\nexport interface DealStageCardProps {\n deal: DealDoc\n pipeline: PipelineDoc | null\n api: DealStageApi\n nowMs: number\n}\n\n/**\n * Where the deal is, and the controls that move it (AGL-2598).\n *\n * A path across the whole pipeline, the way Salesforce draws one: every open\n * stage — click one to move there — and then one closing step, so the stages\n * still ahead of the deal are always in view and the path ends where every\n * deal ends. The closing step reads \"Closed\" while the deal is open and asks\n * won or lost when chosen, the same two moves as the buttons in the header;\n * once the deal is closed it reads the pipeline's own name for the verdict.\n * Every move calls the stage route, never Firestore: the move is what an\n * automation listens for, and the route is the only writer that emits it.\n * Under a closed deal's path sits the verdict — when, and why — and a way\n * back: reopening is a move into an open stage, which the route emits as\n * `dealStageChanged` like any other move.\n *\n * The line under the stepper reads the deal's own probability and forecast\n * category (AGL-3516) — a move gives it the new stage's, which the route\n * stamps, and the stepper says so on hover.\n */\nexport function DealStageCard(props: DealStageCardProps) {\n const { deal, pipeline, api, nowMs } = props\n const { enqueueSnackbar } = useSnackbar()\n const [busy, setBusy] = useState(false)\n const [losing, setLosing] = useState(false)\n const [closeMenu, setCloseMenu] = useState<HTMLElement | null>(null)\n const stages = openStages(pipeline)\n const activeIndex = stages.findIndex((stage) => stage.id === deal.stageId)\n const wonName = closingStage(pipeline, 'won')?.name ?? DEAL_STATUS_LABELS.won\n const lostName = closingStage(pipeline, 'lost')?.name ?? DEAL_STATUS_LABELS.lost\n // \"Move contacts and deals between stages\" (AGL-4047): every control below\n // stays in view, switched off, with the permission named.\n const blocked = api.moveBlocked === true\n\n const run = useCallback(\n async (request: () => Promise<unknown>, done: string) => {\n setBusy(true)\n try {\n await request()\n enqueueSnackbar(done, { variant: 'success', persist: false })\n return true\n } catch (error) {\n enqueueSnackbar(\n error instanceof Error ? error.message : 'The deal could not be moved.',\n { variant: 'warning', allowDuplicate: true },\n )\n return false\n } finally {\n setBusy(false)\n }\n },\n [enqueueSnackbar],\n )\n\n const closed = deal.status !== 'open'\n const days = daysInStage(deal, nowMs)\n const current = activeIndex === -1 ? null : stages[activeIndex]\n const probability = dealProbability(deal, current)\n const forecast = CRM_FORECAST_CATEGORY_LABELS[dealForecastCategory(deal, current)]\n\n const path = (\n <Stepper nonLinear activeStep={closed ? stages.length : activeIndex} alternativeLabel>\n {stages.map((stage, index) => (\n <Step key={stage.id} completed={closed || index < activeIndex}>\n <StepButton\n title={closed ? undefined : blocked ? CRM_MOVE_STAGES_REFUSAL : `Move here: ${stage.probability}% likely to close`}\n disabled={busy || closed || blocked || stage.id === deal.stageId}\n onClick={() =>\n void run(() => api.moveToStage(deal, stage.id), `Moved to ${stage.name}`)\n }\n >\n {stage.name}\n </StepButton>\n </Step>\n ))}\n <Step key=\"$closed\" completed={deal.status === 'won'}>\n <StepButton\n data-testid=\"deal-stage-closing-step\"\n title={closed ? undefined : blocked ? CRM_MOVE_STAGES_REFUSAL : 'Close the deal as won or lost'}\n disabled={busy || closed || blocked}\n onClick={(event) => setCloseMenu(event.currentTarget)}\n icon={\n deal.status === 'won' ? (\n <MdiIcon path={mdiTrophyOutline.path} color=\"success\" fontSize=\"medium\" />\n ) : deal.status === 'lost' ? (\n <MdiIcon path={mdiThumbDownOutline.path} color=\"error\" fontSize=\"medium\" />\n ) : undefined\n }\n >\n <StepLabel error={deal.status === 'lost'}>\n {deal.status === 'won' ? wonName : deal.status === 'lost' ? lostName : 'Closed'}\n </StepLabel>\n </StepButton>\n </Step>\n </Stepper>\n )\n\n return (\n <CardDisplay\n header={'Stage'}\n help={pluginDocsHelp('deals', { anchor: '#moving-winning-and-losing' })}\n HeaderProps={{\n action: !closed ? (\n <Stack direction=\"row\" spacing={1}>\n <BlockedControl blocked={blocked} reason={CRM_MOVE_STAGES_REFUSAL}>\n <Button\n size=\"small\"\n color=\"success\"\n variant=\"outlined\"\n disabled={busy || !pipeline}\n startIcon={<MdiIcon path={mdiTrophyOutline.path} size={0.8} />}\n onClick={() => void run(() => api.markWon(deal), 'Deal won')}\n >\n {'Won'}\n </Button>\n </BlockedControl>\n <BlockedControl blocked={blocked} reason={CRM_MOVE_STAGES_REFUSAL}>\n <Button\n size=\"small\"\n color=\"error\"\n variant=\"outlined\"\n disabled={busy || !pipeline}\n startIcon={<MdiIcon path={mdiThumbDownOutline.path} size={0.8} />}\n onClick={() => setLosing(true)}\n >\n {'Lost'}\n </Button>\n </BlockedControl>\n </Stack>\n ) : null,\n }}\n contentGutterX\n contentGutterY\n >\n {!pipeline ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {\"This deal's pipeline no longer exists, so it has no stages to move through.\"}\n </Typography>\n ) : closed ? (\n <Stack spacing={1.5}>\n {path}\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Chip\n label={DEAL_STATUS_LABELS[deal.status]}\n color={deal.status === 'won' ? 'success' : 'default'}\n />\n <Typography variant=\"body2\" color=\"text.secondary\">\n {typeof deal.closedAtMs === 'number'\n ? `Closed ${new Date(deal.closedAtMs).toLocaleDateString()}`\n : 'Closed'}\n </Typography>\n </Stack>\n {deal.status === 'lost' && deal.lostReason ? (\n <Typography variant=\"body2\">{deal.lostReason}</Typography>\n ) : null}\n <TextField\n select\n size=\"small\"\n label=\"Reopen into\"\n value=\"\"\n disabled={busy || blocked}\n onChange={(event) => {\n const stageId = event.target.value\n if (!stageId) return\n void run(() => api.moveToStage(deal, stageId), 'Deal reopened')\n }}\n helperText={blocked ? CRM_MOVE_STAGES_REFUSAL : 'Reopening puts the deal back in an open stage and tells the automations.'}\n sx={{ maxWidth: 320 }}\n >\n <MenuItem value=\"\">{'Pick a stage'}</MenuItem>\n {stages.map((stage) => (\n <MenuItem key={stage.id} value={stage.id}>\n {stage.name}\n </MenuItem>\n ))}\n </TextField>\n </Stack>\n ) : (\n <Stack spacing={1.5}>\n {path}\n <Typography variant=\"body2\" color=\"text.secondary\" sx={{ textAlign: 'center' }}>\n {!current\n ? 'This deal sits in a stage the pipeline no longer has. Pick one above.'\n : `${days} ${days === 1 ? 'day' : 'days'} in ${current.name} · ` +\n `${probability ?? current.probability}% likely to close · ${forecast}`}\n </Typography>\n </Stack>\n )}\n <Menu anchorEl={closeMenu} open={Boolean(closeMenu)} onClose={() => setCloseMenu(null)}>\n <MenuItem\n onClick={() => {\n setCloseMenu(null)\n void run(() => api.markWon(deal), 'Deal won')\n }}\n >\n <ListItemIcon>\n <MdiIcon path={mdiTrophyOutline.path} color=\"success\" />\n </ListItemIcon>\n <ListItemText>{wonName}</ListItemText>\n </MenuItem>\n <MenuItem\n onClick={() => {\n setCloseMenu(null)\n setLosing(true)\n }}\n >\n <ListItemIcon>\n <MdiIcon path={mdiThumbDownOutline.path} color=\"error\" />\n </ListItemIcon>\n <ListItemText>{lostName}</ListItemText>\n </MenuItem>\n </Menu>\n <LostReasonDialog\n open={losing}\n dealTitle={deal.title}\n busy={busy}\n onClose={() => setLosing(false)}\n onConfirm={(reason) =>\n void run(() => api.markLost(deal, reason), 'Deal marked lost').then(\n (ok) => ok && setLosing(false),\n )\n }\n />\n </CardDisplay>\n )\n}\nDealStageCard.displayName = 'DealStageCard'\n\nexport default DealStageCard\n"],"names":["CRM_FORECAST_CATEGORY_LABELS","dealForecastCategory","dealProbability","pluginDocsHelp","mdiThumbDownOutline","mdiTrophyOutline","CardDisplay","MdiIcon","BlockedControl","useSnackbar","Button","Chip","ListItemIcon","ListItemText","Menu","MenuItem","Stack","Step","StepButton","StepLabel","Stepper","TextField","Typography","useCallback","useState","CRM_MOVE_STAGES_REFUSAL","closingStage","daysInStage","DEAL_STATUS_LABELS","openStages","LostReasonDialog","DealStageCard","props","deal","pipeline","api","nowMs","enqueueSnackbar","busy","setBusy","losing","setLosing","closeMenu","setCloseMenu","stages","activeIndex","findIndex","stage","id","stageId","wonName","name","won","lostName","lost","blocked","moveBlocked","run","request","done","variant","persist","error","Error","message","allowDuplicate","closed","status","days","current","probability","forecast","path","nonLinear","activeStep","length","alternativeLabel","map","index","completed","title","undefined","disabled","onClick","moveToStage","data-testid","event","currentTarget","icon","color","fontSize","header","help","anchor","HeaderProps","action","direction","spacing","reason","size","startIcon","markWon","contentGutterX","contentGutterY","sx","alignItems","label","closedAtMs","Date","toLocaleDateString","lostReason","select","value","onChange","target","helperText","maxWidth","textAlign","anchorEl","open","Boolean","onClose","dealTitle","onConfirm","markLost","then","ok","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;AAEA,SACEA,4BAA4B,EA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sx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
36
36
  * refuse one row at a time.
37
37
  */ import { CRM_COLLECTIONS, dealStageById, crmMemberPickerLabel } from "@aglyn/aglyn";
38
38
  import { useConfirmationContext } from "@aglyn/shared-ui-jsx";
39
+ import { BlockedControl } from "@aglyn/shared-ui-jsx/components/blocked-control.component";
39
40
  import { useFirestore, useHostActivityLogger } from "@aglyn/tenant-feature-instance";
40
41
  import { Button, MenuItem, TextField, Typography } from "@mui/material";
41
42
  import { deleteField, doc } from "firebase/firestore";
@@ -46,6 +47,7 @@ import { closingStage, openStages } from "../model/deal-board-model.js";
46
47
  import { CrmBulkBarFrame, CrmBulkValueDialog, countNoun } from "./crm-bulk-bar-frame.js";
47
48
  import { CrmExportButton } from "./crm-transfer-buttons.js";
48
49
  import { CRM_DEALS_RESOURCE } from "../transfer/fields.js";
50
+ import { CRM_MOVE_STAGES_REFUSAL } from "../model/crm-permissions.js";
49
51
  import { LostReasonDialog } from "./lost-reason-dialog.js";
50
52
  import { useCrmSharingFollowUp } from "../hooks/use-crm-sharing.js";
51
53
  const NOUN = {
@@ -295,11 +297,15 @@ function DealsBulkBarBody(props) {
295
297
  ]
296
298
  }),
297
299
  children: [
298
- /*#__PURE__*/ _jsx(Button, {
299
- size: "small",
300
- disabled: busy || !scope,
301
- onClick: ()=>openAction('stage'),
302
- children: 'Set stage'
300
+ /*#__PURE__*/ _jsx(BlockedControl, {
301
+ blocked: api.moveBlocked === true,
302
+ reason: CRM_MOVE_STAGES_REFUSAL,
303
+ children: /*#__PURE__*/ _jsx(Button, {
304
+ size: "small",
305
+ disabled: busy || !scope,
306
+ onClick: ()=>openAction('stage'),
307
+ children: 'Set stage'
308
+ })
303
309
  }),
304
310
  /*#__PURE__*/ _jsx(Button, {
305
311
  size: "small",
@@ -307,11 +313,15 @@ function DealsBulkBarBody(props) {
307
313
  onClick: ()=>openAction('owner'),
308
314
  children: 'Set owner'
309
315
  }),
310
- /*#__PURE__*/ _jsx(Button, {
311
- size: "small",
312
- disabled: busy || !scope,
313
- onClick: ()=>setLosing(true),
314
- children: 'Mark lost'
316
+ /*#__PURE__*/ _jsx(BlockedControl, {
317
+ blocked: api.moveBlocked === true,
318
+ reason: CRM_MOVE_STAGES_REFUSAL,
319
+ children: /*#__PURE__*/ _jsx(Button, {
320
+ size: "small",
321
+ disabled: busy || !scope,
322
+ onClick: ()=>setLosing(true),
323
+ children: 'Mark lost'
324
+ })
315
325
  }),
316
326
  /*#__PURE__*/ _jsx(CrmExportButton, {
317
327
  resource: CRM_DEALS_RESOURCE,