@aglyn/plugins-crm 1.11.0 → 1.13.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.
- package/package.json +14 -14
- package/src/lib/components/contact-list-columns.js +4 -3
- package/src/lib/components/contact-list-columns.js.map +1 -1
- package/src/lib/components/contact-properties-card.js +6 -2
- package/src/lib/components/contact-properties-card.js.map +1 -1
- package/src/lib/components/contacts-bulk-bar.js +16 -5
- package/src/lib/components/contacts-bulk-bar.js.map +1 -1
- package/src/lib/components/contacts-section.js +6 -13
- package/src/lib/components/contacts-section.js.map +1 -1
- package/src/lib/components/crm-record-insights-zone.js +7 -0
- package/src/lib/components/crm-record-insights-zone.js.map +1 -1
- package/src/lib/components/crm-send-email-dialog.js +1 -1
- package/src/lib/components/crm-send-email-dialog.js.map +1 -1
- package/src/lib/components/deal-board.d.ts +2 -0
- package/src/lib/components/deal-board.js +20 -11
- package/src/lib/components/deal-board.js.map +1 -1
- package/src/lib/components/deal-stage-card.js +41 -28
- package/src/lib/components/deal-stage-card.js.map +1 -1
- package/src/lib/components/deals-bulk-bar.js +20 -10
- package/src/lib/components/deals-bulk-bar.js.map +1 -1
- package/src/lib/components/deals-section.js +1 -0
- package/src/lib/components/deals-section.js.map +1 -1
- package/src/lib/components/email-capture-card.d.ts +1 -1
- package/src/lib/components/email-capture-card.js +2 -1
- package/src/lib/components/email-capture-card.js.map +1 -1
- package/src/lib/components/record-sharing-card.d.ts +6 -5
- package/src/lib/components/record-sharing-card.js +45 -30
- package/src/lib/components/record-sharing-card.js.map +1 -1
- package/src/lib/components/settings-section.d.ts +18 -11
- package/src/lib/components/settings-section.js +36 -19
- package/src/lib/components/settings-section.js.map +1 -1
- package/src/lib/components/sharing-rules-card.js +2 -1
- package/src/lib/components/sharing-rules-card.js.map +1 -1
- package/src/lib/components/use-org-members.d.ts +17 -10
- package/src/lib/components/use-org-members.js +31 -66
- package/src/lib/components/use-org-members.js.map +1 -1
- package/src/lib/declarations.d.ts +6 -2
- package/src/lib/declarations.js +14 -2
- package/src/lib/declarations.js.map +1 -1
- package/src/lib/declarations.server.js +16 -0
- package/src/lib/declarations.server.js.map +1 -1
- package/src/lib/hooks/use-crm-activity-logger.d.ts +2 -2
- package/src/lib/hooks/use-crm-activity-logger.js +2 -2
- package/src/lib/hooks/use-crm-activity-logger.js.map +1 -1
- package/src/lib/hooks/use-crm-record-names.js +59 -6
- package/src/lib/hooks/use-crm-record-names.js.map +1 -1
- package/src/lib/hooks/use-deal-stage-api.d.ts +2 -0
- package/src/lib/hooks/use-deal-stage-api.js +7 -2
- package/src/lib/hooks/use-deal-stage-api.js.map +1 -1
- package/src/lib/hooks/use-org-member-directory.js +49 -12
- package/src/lib/hooks/use-org-member-directory.js.map +1 -1
- package/src/lib/hooks/use-stage-move-blocked.d.ts +32 -0
- package/src/lib/hooks/use-stage-move-blocked.js +71 -0
- package/src/lib/hooks/use-stage-move-blocked.js.map +1 -0
- package/src/lib/model/crm-api.d.ts +1 -1
- package/src/lib/model/crm-api.js +1 -1
- package/src/lib/model/crm-api.js.map +1 -1
- package/src/lib/model/crm-permissions.d.ts +35 -0
- package/src/lib/model/crm-permissions.js +87 -0
- package/src/lib/model/crm-permissions.js.map +1 -0
- package/src/lib/model/crm-sharing.d.ts +1 -1
- package/src/lib/model/crm-sharing.js +1 -1
- package/src/lib/model/crm-sharing.js.map +1 -1
- package/src/lib/plugin.js +4 -5
- package/src/lib/plugin.js.map +1 -1
- package/src/lib/server/capture-contact.d.ts +3 -3
- package/src/lib/server/capture-contact.js +3 -3
- package/src/lib/server/capture-contact.js.map +1 -1
- package/src/lib/server/crm-setup-writers.server.d.ts +2 -3
- package/src/lib/server/crm-setup-writers.server.js +4 -16
- package/src/lib/server/crm-setup-writers.server.js.map +1 -1
- package/src/lib/server/crm-sharing.d.ts +5 -4
- package/src/lib/server/crm-sharing.js +8 -6
- package/src/lib/server/crm-sharing.js.map +1 -1
- package/src/lib/server/email-template-duplicate.js +7 -7
- package/src/lib/server/email-template-duplicate.js.map +1 -1
- package/src/lib/server/inbound-address.d.ts +9 -7
- package/src/lib/server/inbound-address.js +18 -15
- package/src/lib/server/inbound-address.js.map +1 -1
- package/src/lib/server/org-caller.d.ts +19 -5
- package/src/lib/server/org-caller.js +25 -5
- package/src/lib/server/org-caller.js.map +1 -1
- package/src/lib/server/recipe-routes.d.ts +0 -34
- package/src/lib/server/recipe-routes.js +11 -10
- package/src/lib/server/recipe-routes.js.map +1 -1
- package/src/lib/server/scope-sharing-patch.d.ts +22 -0
- package/src/lib/server/scope-sharing-patch.js +25 -0
- package/src/lib/server/scope-sharing-patch.js.map +1 -0
- package/src/lib/server/task-routes.d.ts +6 -5
- package/src/lib/server/task-routes.js +11 -13
- package/src/lib/server/task-routes.js.map +1 -1
- package/src/lib/server-deal-stage.d.ts +11 -6
- package/src/lib/server-deal-stage.js +18 -16
- package/src/lib/server-deal-stage.js.map +1 -1
- package/src/lib/server.js +16 -18
- package/src/lib/server.js.map +1 -1
|
@@ -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(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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:
|
|
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,GAAG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BAAoBE,IAAI,CACjE,CAACC,KAAOA,MAAMnF,UAAU;;;;AAMpC;AACAV,cAAc8F,WAAW,GAAG;AAE5B,eAAe9F,cAAa"}
|
|
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","anch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ACC,KAAOA,MAAMrF,UAAU;;;;AAMpC;AACAV,cAAcgG,WAAW,GAAG;AAE5B,eAAehG,cAAa"}
|
|
@@ -36,6 +36,7 @@ import { jsx as _jsx, 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(
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
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(
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
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,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/components/deals-bulk-bar.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\n/**\n * The bar over the deals table, for whatever rows are ticked (AGL-2621).\n *\n * Move them to a stage, mark them lost, hand them to an owner, take them\n * into a spreadsheet, or delete them. The owner and the delete are\n * document writes and go through the shared runner in batches; the stage\n * and the loss go through `crm/deal-stage`, ONE REQUEST PER DEAL, because\n * a stage change is what an automation listens for and only the route\n * emits the event — a batch that wrote `stageId` would move forty deals\n * and tell no workflow. Each refusal carries the route's own sentence,\n * named by the deal.\n *\n * ## Set stage needs one pipeline\n *\n * A stage belongs to a pipeline, and a selection that spans two has no\n * one list of stages to offer. The dialog says so rather than offering the\n * first pipeline's stages to a deal in the second, which the route would\n * refuse one row at a time.\n */\n\nimport { CRM_COLLECTIONS, dealStageById, crmMemberPickerLabel } from '@aglyn/aglyn'\nimport { useConfirmationContext } from '@aglyn/shared-ui-jsx'\nimport { useFirestore, useHostActivityLogger } from '@aglyn/tenant-feature-instance'\nimport { Button, MenuItem, TextField, Typography } from '@mui/material'\nimport { deleteField, doc } from 'firebase/firestore'\nimport { useCallback, useMemo, useState } from 'react'\nimport { useCrmBulkApply } from '../hooks/use-crm-bulk-apply'\nimport type { DealStageApi } from '../hooks/use-deal-stage-api'\nimport type { OrgMemberDirectory } from '../hooks/use-org-member-directory'\nimport {\n type CrmBulkPlan,\n type CrmBulkWrite,\n crmBulkWriters,\n runCrmBulkCalls,\n runCrmBulkWrites,\n} from '../model/crm-bulk-writes'\nimport {\n type DealDoc,\n type PipelineDoc,\n closingStage,\n openStages,\n} from '../model/deal-board-model'\nimport {\n type CrmBulkNoun,\n CrmBulkBarFrame,\n CrmBulkValueDialog,\n countNoun,\n} from './crm-bulk-bar-frame'\nimport { CrmExportButton } from './crm-transfer-buttons'\nimport { CRM_DEALS_RESOURCE } from '../transfer/fields'\nimport { LostReasonDialog } from './lost-reason-dialog'\nimport { useCrmSharingFollowUp } from '../hooks/use-crm-sharing'\n\nexport interface DealsBulkBarProps {\n /**\n * The site whose activity feed the bar's acts are logged in, or `null`\n * at the organization level (AGL-2630), where the selection spans sites\n * and the org's feed takes one line for the action instead (AGL-2634);\n * a stage move runs as the org there and is logged per deal by the route.\n */\n hostId: string | null\n /** `['orgs', orgId]`, or `null` while the org is unresolved. */\n scope: readonly ['orgs', string] | null\n rows: readonly DealDoc[]\n selected: readonly string[]\n onSelectedChange: (ids: string[]) => void\n /** The pipeline a deal's `pipelineId` names, for the stage list. */\n pipelineById: (id: string | undefined) => PipelineDoc | null\n /** The section's roster — already read for the Owner column. */\n roster: OrgMemberDirectory\n /** The one door a stage change goes through. */\n api: DealStageApi\n}\n\nconst NOUN: CrmBulkNoun = { singular: 'deal', plural: 'deals' }\n\ntype PendingAction = 'stage' | 'owner'\n\nconst ACTION_TITLES: Record<PendingAction, string> = {\n stage: 'Set the stage',\n owner: 'Set the owner',\n}\n\n/** The label a report lists a deal under. */\nconst labelOf = (deal: DealDoc): string => deal.title || 'Untitled deal'\n\nexport function DealsBulkBar(props: DealsBulkBarProps) {\n if (!props.selected.length) return null\n return <DealsBulkBarBody {...props} />\n}\nDealsBulkBar.displayName = 'DealsBulkBar'\n\nfunction DealsBulkBarBody(props: DealsBulkBarProps) {\n const { hostId, scope, rows, selected, onSelectedChange, pipelineById, roster, api } =\n props\n const firestore = useFirestore()\n const { confirm } = useConfirmationContext()\n const followUpSharing = useCrmSharingFollowUp(hostId ?? null, scope?.[1] ?? null)\n const logActivity = useHostActivityLogger(hostId ?? undefined)\n const { busy, report, apply, dismissReport } = useCrmBulkApply({ recordKind: 'deal' })\n\n const selectedRows = useMemo(() => {\n const chosen = new Set(selected)\n return rows.filter((row) => chosen.has(row.$id))\n }, [rows, selected])\n\n /*\n * The one pipeline the selection is in, or `null` when it spans more\n * than one — in which case Set stage has no list to offer.\n */\n const pipeline = useMemo(() => {\n const ids = new Set(selectedRows.map((deal) => String(deal.pipelineId ?? '')))\n return ids.size === 1 ? pipelineById([...ids][0]) : null\n }, [selectedRows, pipelineById])\n const stages = useMemo(() => {\n if (!pipeline) return []\n const won = closingStage(pipeline, 'won')\n return [...openStages(pipeline), ...(won ? [won] : [])]\n }, [pipeline])\n\n const [pending, setPending] = useState<PendingAction | null>(null)\n const [value, setValue] = useState('')\n const [losing, setLosing] = useState(false)\n\n const writers = useMemo(\n () =>\n crmBulkWriters(firestore, (id) =>\n doc(firestore, scope?.[0] ?? 'orgs', scope?.[1] ?? '', CRM_COLLECTIONS.deals, id),\n ),\n [firestore, scope],\n )\n\n const openAction = (action: PendingAction) => {\n setValue('')\n setPending(action)\n }\n\n const runPlan = useCallback(\n (plan: CrmBulkPlan, done: (count: number) => string) =>\n apply({\n attempted: plan.writes.length,\n skipped: plan.skipped,\n job: async () => {\n const outcome = await runCrmBulkWrites(writers, plan.writes, (write) => write.label)\n // A client-direct write owes the sharing rules a re-evaluation (AGL-3336).\n followUpSharing(\n 'deals',\n plan.writes.filter((write) => write.kind === 'update').map((write) => write.id),\n )\n return outcome\n },\n done,\n }),\n [apply, writers, followUpSharing],\n )\n\n /** One route request per deal, in order, named by title. */\n const runCalls = useCallback(\n (call: (deal: DealDoc) => Promise<unknown>, done: (count: number) => string) =>\n apply({\n attempted: selectedRows.length,\n skipped: [],\n job: () => runCrmBulkCalls(selectedRows, labelOf, call),\n done,\n // The stage route writes the org's line per deal (AGL-2634).\n loggedByRoute: true,\n }),\n [apply, selectedRows],\n )\n\n const handleApply = useCallback(async () => {\n if (!pending || !scope) return\n const action = pending\n setPending(null)\n if (action === 'stage') {\n const stage = dealStageById(pipeline, value)\n if (!stage) return\n await runCalls(\n (deal) => api.moveToStage(deal, stage.id),\n (count) => `Moved ${countNoun(count, NOUN)} to ${stage.name}`,\n )\n return\n }\n const nowMs = Date.now()\n const writes: CrmBulkWrite[] = selectedRows.map((deal) => ({\n id: deal.$id,\n label: labelOf(deal),\n kind: 'update',\n data: {\n ownerUid: value ? value : deleteField(),\n updatedAt: new Date(nowMs),\n },\n }))\n await runPlan({ writes, skipped: [] }, (count) => `Owner set on ${countNoun(count, NOUN)}`)\n }, [pending, scope, value, pipeline, selectedRows, api, runCalls, runPlan])\n\n const handleLost = useCallback(\n async (reason: string) => {\n setLosing(false)\n await runCalls(\n (deal) => api.markLost(deal, reason),\n (count) => `Marked ${countNoun(count, NOUN)} lost`,\n )\n },\n [api, runCalls],\n )\n\n const handleDelete = useCallback(async () => {\n if (!scope || !selectedRows.length) return\n const count = selectedRows.length\n const confirmed = await confirm({\n title: count === 1 ? 'Delete this deal?' : `Delete ${count} deals?`,\n description:\n `${count === 1 ? 'It is' : 'They are'} removed from the pipeline along ` +\n 'with their notes. The contacts and the companies they name are not ' +\n 'touched.',\n confirmationText: count === 1 ? 'Delete deal' : 'Delete deals',\n confirmationButtonProps: { color: 'error' },\n })\n // `confirm` resolves with no value and REJECTS on cancel.\n .then(() => true)\n .catch(() => false)\n if (!confirmed) return\n const writes: CrmBulkWrite[] = selectedRows.map((deal) => ({\n id: deal.$id,\n label: labelOf(deal),\n kind: 'delete',\n }))\n const outcome = await runPlan(\n { writes, skipped: [] },\n (done) => `Deleted ${countNoun(done, NOUN)}`,\n )\n // One line per deal that went, as its own page would write.\n const refused = new Set(outcome.refused.map((row) => row.label))\n for (const deal of selectedRows) {\n if (!refused.has(labelOf(deal))) {\n logActivity('Deleted deal', { type: 'deal', id: deal.$id, name: deal.title })\n }\n }\n onSelectedChange(\n selectedRows.filter((deal) => refused.has(labelOf(deal))).map((deal) => deal.$id),\n )\n }, [scope, selectedRows, confirm, runPlan, logActivity, onSelectedChange])\n\n return (\n <CrmBulkBarFrame\n count={selected.length}\n noun={NOUN}\n busy={busy}\n onClear={() => onSelectedChange([])}\n report={report}\n onDismissReport={dismissReport}\n extras={\n <>\n <CrmBulkValueDialog\n open={pending !== null}\n title={pending ? ACTION_TITLES[pending] : ''}\n count={selected.length}\n noun={NOUN}\n busy={busy}\n canApply={pending === 'owner' || Boolean(value)}\n onClose={() => setPending(null)}\n onApply={() => void handleApply()}\n >\n {pending === 'stage' ? (\n pipeline ? (\n <TextField\n select\n size=\"small\"\n label=\"Stage\"\n value={value}\n onChange={(event) => setValue(event.target.value)}\n helperText={`${pipeline.name} — each move fires its event, as a drag does`}\n >\n {stages.map((stage) => (\n <MenuItem key={stage.id} value={stage.id}>\n {stage.name}\n </MenuItem>\n ))}\n </TextField>\n ) : (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'The selected deals are in different pipelines, so there is ' +\n 'no one list of stages to move them to. Select deals from ' +\n 'one pipeline.'}\n </Typography>\n )\n ) : pending === 'owner' ? (\n <TextField\n select\n size=\"small\"\n label=\"Owner\"\n value={value}\n onChange={(event) => setValue(event.target.value)}\n disabled={roster.loading}\n error={Boolean(roster.error)}\n helperText={roster.error ?? (roster.loading ? 'Loading the team…' : undefined)}\n >\n <MenuItem value=\"\">{'Nobody — clear the owner'}</MenuItem>\n {roster.members.map((member) => (\n <MenuItem key={member.uid} value={member.uid}>\n {crmMemberPickerLabel(member)}\n </MenuItem>\n ))}\n </TextField>\n ) : null}\n </CrmBulkValueDialog>\n <LostReasonDialog\n open={losing}\n dealTitle={selectedRows[0]?.title ?? ''}\n count={selectedRows.length}\n busy={busy}\n onClose={() => setLosing(false)}\n onConfirm={(reason) => void handleLost(reason)}\n />\n </>\n }\n >\n <Button size=\"small\" disabled={busy || !scope} onClick={() => openAction('stage')}>\n {'Set stage'}\n </Button>\n <Button size=\"small\" disabled={busy || !scope} onClick={() => openAction('owner')}>\n {'Set owner'}\n </Button>\n <Button size=\"small\" disabled={busy || !scope} onClick={() => setLosing(true)}>\n {'Mark lost'}\n </Button>\n {/* The selection through the export dialog: every field, chosen (AGL-3528). */}\n <CrmExportButton\n resource={CRM_DEALS_RESOURCE}\n hostId={hostId}\n selection={selectedRows.map((row) => row.$id)}\n disabled={busy}\n />\n <Button\n size=\"small\"\n color=\"error\"\n disabled={busy || !scope}\n onClick={() => void handleDelete()}\n >\n {'Delete'}\n </Button>\n </CrmBulkBarFrame>\n )\n}\nDealsBulkBarBody.displayName = 'DealsBulkBarBody'\n\nexport default DealsBulkBar\n"],"names":["CRM_COLLECTIONS","dealStageById","crmMemberPickerLabel","useConfirmationContext","useFirestore","useHostActivityLogger","Button","MenuItem","TextField","Typography","deleteField","doc","useCallback","useMemo","useState","useCrmBulkApply","crmBulkWriters","runCrmBulkCalls","runCrmBulkWrites","closingStage","openStages","CrmBulkBarFrame","CrmBulkValueDialog","countNoun","CrmExportButton","CRM_DEALS_RESOURCE","LostReasonDialog","useCrmSharingFollowUp","NOUN","singular","plural","ACTION_TITLES","stage","owner","labelOf","deal","title","DealsBulkBar","props","selected","length","DealsBulkBarBody","displayName","roster","selectedRows","hostId","scope","rows","onSelectedChange","pipelineById","api","firestore","confirm","followUpSharing","logActivity","undefined","busy","report","apply","dismissReport","recordKind","chosen","Set","filter","row","has","$id","pipeline","ids","map","String","pipelineId","size","stages","won","pending","setPending","value","setValue","losing","setLosing","writers","id","deals","openAction","action","runPlan","plan","done","attempted","writes","skipped","job","outcome","write","label","kind","runCalls","call","loggedByRoute","handleApply","moveToStage","count","name","nowMs","Date","now","data","ownerUid","updatedAt","handleLost","reason","markLost","handleDelete","confirmed","description","confirmationText","confirmationButtonProps","color","then","catch","refused","type","noun","onClear","onDismissReport","extras","open","canApply","Boolean","onClose","onApply","select","onChange","event","target","helperText","variant","disabled","loading","error","members","member","uid","dealTitle","onConfirm","onClick","resource","selection"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA;;;;;;;;;;;;;;;;;;CAkBC,GAED,SAASA,eAAe,EAAEC,aAAa,EAAEC,oBAAoB,QAAQ,eAAc;AACnF,SAASC,sBAAsB,QAAQ,uBAAsB;AAC7D,SAASC,YAAY,EAAEC,qBAAqB,QAAQ,iCAAgC;AACpF,SAASC,MAAM,EAAEC,QAAQ,EAAEC,SAAS,EAAEC,UAAU,QAAQ,gBAAe;AACvE,SAASC,WAAW,EAAEC,GAAG,QAAQ,qBAAoB;AACrD,SAASC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AACtD,SAASC,eAAe,QAAQ,iCAA6B;AAG7D,SAGEC,cAAc,EACdC,eAAe,EACfC,gBAAgB,QACX,8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"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/components/deals-bulk-bar.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\n/**\n * The bar over the deals table, for whatever rows are ticked (AGL-2621).\n *\n * Move them to a stage, mark them lost, hand them to an owner, take them\n * into a spreadsheet, or delete them. The owner and the delete are\n * document writes and go through the shared runner in batches; the stage\n * and the loss go through `crm/deal-stage`, ONE REQUEST PER DEAL, because\n * a stage change is what an automation listens for and only the route\n * emits the event — a batch that wrote `stageId` would move forty deals\n * and tell no workflow. Each refusal carries the route's own sentence,\n * named by the deal.\n *\n * ## Set stage needs one pipeline\n *\n * A stage belongs to a pipeline, and a selection that spans two has no\n * one list of stages to offer. The dialog says so rather than offering the\n * first pipeline's stages to a deal in the second, which the route would\n * refuse one row at a time.\n */\n\nimport { CRM_COLLECTIONS, dealStageById, crmMemberPickerLabel } from '@aglyn/aglyn'\nimport { useConfirmationContext } from '@aglyn/shared-ui-jsx'\nimport { BlockedControl } from '@aglyn/shared-ui-jsx/components/blocked-control.component'\nimport { useFirestore, useHostActivityLogger } from '@aglyn/tenant-feature-instance'\nimport { Button, MenuItem, TextField, Typography } from '@mui/material'\nimport { deleteField, doc } from 'firebase/firestore'\nimport { useCallback, useMemo, useState } from 'react'\nimport { useCrmBulkApply } from '../hooks/use-crm-bulk-apply'\nimport type { DealStageApi } from '../hooks/use-deal-stage-api'\nimport type { OrgMemberDirectory } from '../hooks/use-org-member-directory'\nimport {\n type CrmBulkPlan,\n type CrmBulkWrite,\n crmBulkWriters,\n runCrmBulkCalls,\n runCrmBulkWrites,\n} from '../model/crm-bulk-writes'\nimport {\n type DealDoc,\n type PipelineDoc,\n closingStage,\n openStages,\n} from '../model/deal-board-model'\nimport {\n type CrmBulkNoun,\n CrmBulkBarFrame,\n CrmBulkValueDialog,\n countNoun,\n} from './crm-bulk-bar-frame'\nimport { CrmExportButton } from './crm-transfer-buttons'\nimport { CRM_DEALS_RESOURCE } from '../transfer/fields'\nimport { CRM_MOVE_STAGES_REFUSAL } from '../model/crm-permissions'\nimport { LostReasonDialog } from './lost-reason-dialog'\nimport { useCrmSharingFollowUp } from '../hooks/use-crm-sharing'\n\nexport interface DealsBulkBarProps {\n /**\n * The site whose activity feed the bar's acts are logged in, or `null`\n * at the organization level (AGL-2630), where the selection spans sites\n * and the org's feed takes one line for the action instead (AGL-2634);\n * a stage move runs as the org there and is logged per deal by the route.\n */\n hostId: string | null\n /** `['orgs', orgId]`, or `null` while the org is unresolved. */\n scope: readonly ['orgs', string] | null\n rows: readonly DealDoc[]\n selected: readonly string[]\n onSelectedChange: (ids: string[]) => void\n /** The pipeline a deal's `pipelineId` names, for the stage list. */\n pipelineById: (id: string | undefined) => PipelineDoc | null\n /** The section's roster — already read for the Owner column. */\n roster: OrgMemberDirectory\n /** The one door a stage change goes through. */\n api: DealStageApi\n}\n\nconst NOUN: CrmBulkNoun = { singular: 'deal', plural: 'deals' }\n\ntype PendingAction = 'stage' | 'owner'\n\nconst ACTION_TITLES: Record<PendingAction, string> = {\n stage: 'Set the stage',\n owner: 'Set the owner',\n}\n\n/** The label a report lists a deal under. */\nconst labelOf = (deal: DealDoc): string => deal.title || 'Untitled deal'\n\nexport function DealsBulkBar(props: DealsBulkBarProps) {\n if (!props.selected.length) return null\n return <DealsBulkBarBody {...props} />\n}\nDealsBulkBar.displayName = 'DealsBulkBar'\n\nfunction DealsBulkBarBody(props: DealsBulkBarProps) {\n const { hostId, scope, rows, selected, onSelectedChange, pipelineById, roster, api } =\n props\n const firestore = useFirestore()\n const { confirm } = useConfirmationContext()\n const followUpSharing = useCrmSharingFollowUp(hostId ?? null, scope?.[1] ?? null)\n const logActivity = useHostActivityLogger(hostId ?? undefined)\n const { busy, report, apply, dismissReport } = useCrmBulkApply({ recordKind: 'deal' })\n\n const selectedRows = useMemo(() => {\n const chosen = new Set(selected)\n return rows.filter((row) => chosen.has(row.$id))\n }, [rows, selected])\n\n /*\n * The one pipeline the selection is in, or `null` when it spans more\n * than one — in which case Set stage has no list to offer.\n */\n const pipeline = useMemo(() => {\n const ids = new Set(selectedRows.map((deal) => String(deal.pipelineId ?? '')))\n return ids.size === 1 ? pipelineById([...ids][0]) : null\n }, [selectedRows, pipelineById])\n const stages = useMemo(() => {\n if (!pipeline) return []\n const won = closingStage(pipeline, 'won')\n return [...openStages(pipeline), ...(won ? [won] : [])]\n }, [pipeline])\n\n const [pending, setPending] = useState<PendingAction | null>(null)\n const [value, setValue] = useState('')\n const [losing, setLosing] = useState(false)\n\n const writers = useMemo(\n () =>\n crmBulkWriters(firestore, (id) =>\n doc(firestore, scope?.[0] ?? 'orgs', scope?.[1] ?? '', CRM_COLLECTIONS.deals, id),\n ),\n [firestore, scope],\n )\n\n const openAction = (action: PendingAction) => {\n setValue('')\n setPending(action)\n }\n\n const runPlan = useCallback(\n (plan: CrmBulkPlan, done: (count: number) => string) =>\n apply({\n attempted: plan.writes.length,\n skipped: plan.skipped,\n job: async () => {\n const outcome = await runCrmBulkWrites(writers, plan.writes, (write) => write.label)\n // A client-direct write owes the sharing rules a re-evaluation (AGL-3336).\n followUpSharing(\n 'deals',\n plan.writes.filter((write) => write.kind === 'update').map((write) => write.id),\n )\n return outcome\n },\n done,\n }),\n [apply, writers, followUpSharing],\n )\n\n /** One route request per deal, in order, named by title. */\n const runCalls = useCallback(\n (call: (deal: DealDoc) => Promise<unknown>, done: (count: number) => string) =>\n apply({\n attempted: selectedRows.length,\n skipped: [],\n job: () => runCrmBulkCalls(selectedRows, labelOf, call),\n done,\n // The stage route writes the org's line per deal (AGL-2634).\n loggedByRoute: true,\n }),\n [apply, selectedRows],\n )\n\n const handleApply = useCallback(async () => {\n if (!pending || !scope) return\n const action = pending\n setPending(null)\n if (action === 'stage') {\n const stage = dealStageById(pipeline, value)\n if (!stage) return\n await runCalls(\n (deal) => api.moveToStage(deal, stage.id),\n (count) => `Moved ${countNoun(count, NOUN)} to ${stage.name}`,\n )\n return\n }\n const nowMs = Date.now()\n const writes: CrmBulkWrite[] = selectedRows.map((deal) => ({\n id: deal.$id,\n label: labelOf(deal),\n kind: 'update',\n data: {\n ownerUid: value ? value : deleteField(),\n updatedAt: new Date(nowMs),\n },\n }))\n await runPlan({ writes, skipped: [] }, (count) => `Owner set on ${countNoun(count, NOUN)}`)\n }, [pending, scope, value, pipeline, selectedRows, api, runCalls, runPlan])\n\n const handleLost = useCallback(\n async (reason: string) => {\n setLosing(false)\n await runCalls(\n (deal) => api.markLost(deal, reason),\n (count) => `Marked ${countNoun(count, NOUN)} lost`,\n )\n },\n [api, runCalls],\n )\n\n const handleDelete = useCallback(async () => {\n if (!scope || !selectedRows.length) return\n const count = selectedRows.length\n const confirmed = await confirm({\n title: count === 1 ? 'Delete this deal?' : `Delete ${count} deals?`,\n description:\n `${count === 1 ? 'It is' : 'They are'} removed from the pipeline along ` +\n 'with their notes. The contacts and the companies they name are not ' +\n 'touched.',\n confirmationText: count === 1 ? 'Delete deal' : 'Delete deals',\n confirmationButtonProps: { color: 'error' },\n })\n // `confirm` resolves with no value and REJECTS on cancel.\n .then(() => true)\n .catch(() => false)\n if (!confirmed) return\n const writes: CrmBulkWrite[] = selectedRows.map((deal) => ({\n id: deal.$id,\n label: labelOf(deal),\n kind: 'delete',\n }))\n const outcome = await runPlan(\n { writes, skipped: [] },\n (done) => `Deleted ${countNoun(done, NOUN)}`,\n )\n // One line per deal that went, as its own page would write.\n const refused = new Set(outcome.refused.map((row) => row.label))\n for (const deal of selectedRows) {\n if (!refused.has(labelOf(deal))) {\n logActivity('Deleted deal', { type: 'deal', id: deal.$id, name: deal.title })\n }\n }\n onSelectedChange(\n selectedRows.filter((deal) => refused.has(labelOf(deal))).map((deal) => deal.$id),\n )\n }, [scope, selectedRows, confirm, runPlan, logActivity, onSelectedChange])\n\n return (\n <CrmBulkBarFrame\n count={selected.length}\n noun={NOUN}\n busy={busy}\n onClear={() => onSelectedChange([])}\n report={report}\n onDismissReport={dismissReport}\n extras={\n <>\n <CrmBulkValueDialog\n open={pending !== null}\n title={pending ? ACTION_TITLES[pending] : ''}\n count={selected.length}\n noun={NOUN}\n busy={busy}\n canApply={pending === 'owner' || Boolean(value)}\n onClose={() => setPending(null)}\n onApply={() => void handleApply()}\n >\n {pending === 'stage' ? (\n pipeline ? (\n <TextField\n select\n size=\"small\"\n label=\"Stage\"\n value={value}\n onChange={(event) => setValue(event.target.value)}\n helperText={`${pipeline.name} — each move fires its event, as a drag does`}\n >\n {stages.map((stage) => (\n <MenuItem key={stage.id} value={stage.id}>\n {stage.name}\n </MenuItem>\n ))}\n </TextField>\n ) : (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'The selected deals are in different pipelines, so there is ' +\n 'no one list of stages to move them to. Select deals from ' +\n 'one pipeline.'}\n </Typography>\n )\n ) : pending === 'owner' ? (\n <TextField\n select\n size=\"small\"\n label=\"Owner\"\n value={value}\n onChange={(event) => setValue(event.target.value)}\n disabled={roster.loading}\n error={Boolean(roster.error)}\n helperText={roster.error ?? (roster.loading ? 'Loading the team…' : undefined)}\n >\n <MenuItem value=\"\">{'Nobody — clear the owner'}</MenuItem>\n {roster.members.map((member) => (\n <MenuItem key={member.uid} value={member.uid}>\n {crmMemberPickerLabel(member)}\n </MenuItem>\n ))}\n </TextField>\n ) : null}\n </CrmBulkValueDialog>\n <LostReasonDialog\n open={losing}\n dealTitle={selectedRows[0]?.title ?? ''}\n count={selectedRows.length}\n busy={busy}\n onClose={() => setLosing(false)}\n onConfirm={(reason) => void handleLost(reason)}\n />\n </>\n }\n >\n <BlockedControl blocked={api.moveBlocked === true} reason={CRM_MOVE_STAGES_REFUSAL}>\n <Button size=\"small\" disabled={busy || !scope} onClick={() => openAction('stage')}>\n {'Set stage'}\n </Button>\n </BlockedControl>\n <Button size=\"small\" disabled={busy || !scope} onClick={() => openAction('owner')}>\n {'Set owner'}\n </Button>\n <BlockedControl blocked={api.moveBlocked === true} reason={CRM_MOVE_STAGES_REFUSAL}>\n <Button size=\"small\" disabled={busy || !scope} onClick={() => setLosing(true)}>\n {'Mark lost'}\n </Button>\n </BlockedControl>\n {/* The selection through the export dialog: every field, chosen (AGL-3528). */}\n <CrmExportButton\n resource={CRM_DEALS_RESOURCE}\n hostId={hostId}\n selection={selectedRows.map((row) => row.$id)}\n disabled={busy}\n />\n <Button\n size=\"small\"\n color=\"error\"\n disabled={busy || !scope}\n onClick={() => void handleDelete()}\n >\n {'Delete'}\n </Button>\n </CrmBulkBarFrame>\n )\n}\nDealsBulkBarBody.displayName = 'DealsBulkBarBody'\n\nexport default DealsBulkBar\n"],"names":["CRM_COLLECTIONS","dealStageById","crmMemberPickerLabel","useConfirmationContext","BlockedControl","useFirestore","useHostActivityLogger","Button","MenuItem","TextField","Typography","deleteField","doc","useCallback","useMemo","useState","useCrmBulkApply","crmBulkWriters","runCrmBulkCalls","runCrmBulkWrites","closingStage","openStages","CrmBulkBarFrame","CrmBulkValueDialog","countNoun","CrmExportButton","CRM_DEALS_RESOURCE","CRM_MOVE_STAGES_REFUSAL","LostReasonDialog","useCrmSharingFollowUp","NOUN","singular","plural","ACTION_TITLES","stage","owner","labelOf","deal","title","DealsBulkBar","props","selected","length","DealsBulkBarBody","displayName","roster","selectedRows","hostId","scope","rows","onSelectedChange","pipelineById","api","firestore","confirm","followUpSharing","logActivity","undefined","busy","report","apply","dismissReport","recordKind","chosen","Set","filter","row","has","$id","pipeline","ids","map","String","pipelineId","size","stages","won","pending","setPending","value","setValue","losing","setLosing","writers","id","deals","openAction","action","runPlan","plan","done","attempted","writes","skipped","job","outcome","write","label","kind","runCalls","call","loggedByRoute","handleApply","moveToStage","count","name","nowMs","Date","now","data","ownerUid","updatedAt","handleLost","reason","markLost","handleDelete","confirmed","description","confirmationText","confirmationButtonProps","color","then","catch","refused","type","noun","onClear","onDismissReport","extras","open","canApply","Boolean","onClose","onApply","select","onChange","event","target","helperText","variant","disabled","loading","error","members","member","uid","dealTitle","onConfirm","blocked","moveBlocked","onClick","resource","selection"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA;;;;;;;;;;;;;;;;;;CAkBC,GAED,SAASA,eAAe,EAAEC,aAAa,EAAEC,oBAAoB,QAAQ,eAAc;AACnF,SAASC,sBAAsB,QAAQ,uBAAsB;AAC7D,SAASC,cAAc,QAAQ,4DAA2D;AAC1F,SAASC,YAAY,EAAEC,qBAAqB,QAAQ,iCAAgC;AACpF,SAASC,MAAM,EAAEC,QAAQ,EAAEC,SAAS,EAAEC,UAAU,QAAQ,gBAAe;AACvE,SAASC,WAAW,EAAEC,GAAG,QAAQ,qBAAoB;AACrD,SAASC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AACtD,SAASC,eAAe,QAAQ,iCAA6B;AAG7D,SAGEC,cAAc,EACdC,eAAe,EACfC,gBAAgB,QACX,8BAA0B;AACjC,SAGEC,YAAY,EACZC,UAAU,QACL,+BAA2B;AAClC,SAEEC,eAAe,EACfC,kBAAkB,EAClBC,SAAS,QACJ,0BAAsB;AAC7B,SAASC,eAAe,QAAQ,4BAAwB;AACxD,SAASC,kBAAkB,QAAQ,wBAAoB;AACvD,SAASC,uBAAuB,QAAQ,8BAA0B;AAClE,SAASC,gBAAgB,QAAQ,0BAAsB;AACvD,SAASC,qBAAqB,QAAQ,8BAA0B;AAuBhE,MAAMC,OAAoB;IAAEC,UAAU;IAAQC,QAAQ;AAAQ;AAI9D,MAAMC,gBAA+C;IACnDC,OAAO;IACPC,OAAO;AACT;AAEA,2CAA2C,GAC3C,MAAMC,UAAU,CAACC,OAA0BA,KAAKC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