@aglyn/plugins-crm 1.5.0 → 1.6.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/add-to-list-dialog.js +7 -3
- package/src/lib/components/add-to-list-dialog.js.map +1 -1
- package/src/lib/components/company-contact-roles-card.d.ts +3 -0
- package/src/lib/components/company-contact-roles-card.js +4 -2
- package/src/lib/components/company-contact-roles-card.js.map +1 -1
- package/src/lib/components/company-detail-page.js +5 -3
- package/src/lib/components/company-detail-page.js.map +1 -1
- package/src/lib/components/company-edit-drawer.d.ts +3 -0
- package/src/lib/components/company-edit-drawer.js +2 -1
- package/src/lib/components/company-edit-drawer.js.map +1 -1
- package/src/lib/components/company-properties-card.d.ts +3 -0
- package/src/lib/components/company-properties-card.js.map +1 -1
- package/src/lib/components/contact-associations-card.d.ts +3 -0
- package/src/lib/components/contact-associations-card.js +3 -1
- package/src/lib/components/contact-associations-card.js.map +1 -1
- package/src/lib/components/contact-detail-page.js +5 -3
- package/src/lib/components/contact-detail-page.js.map +1 -1
- package/src/lib/components/contact-properties-card.d.ts +3 -0
- package/src/lib/components/contact-properties-card.js +3 -1
- package/src/lib/components/contact-properties-card.js.map +1 -1
- package/src/lib/components/deal-contact-roles-card.d.ts +3 -0
- package/src/lib/components/deal-contact-roles-card.js +4 -2
- package/src/lib/components/deal-contact-roles-card.js.map +1 -1
- package/src/lib/components/deal-detail-page.js +7 -4
- package/src/lib/components/deal-detail-page.js.map +1 -1
- package/src/lib/components/deal-edit-drawer.d.ts +3 -0
- package/src/lib/components/deal-edit-drawer.js +4 -2
- package/src/lib/components/deal-edit-drawer.js.map +1 -1
- package/src/lib/components/deal-products-card.d.ts +3 -0
- package/src/lib/components/deal-products-card.js +4 -2
- package/src/lib/components/deal-products-card.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/fields-section.js +7 -3
- package/src/lib/components/fields-section.js.map +1 -1
- package/src/lib/components/lead-campaigns-card.d.ts +3 -1
- package/src/lib/components/lead-campaigns-card.js +3 -2
- package/src/lib/components/lead-campaigns-card.js.map +1 -1
- package/src/lib/components/lead-detail-page.js +3 -1
- package/src/lib/components/lead-detail-page.js.map +1 -1
- package/src/lib/components/lead-properties-card.d.ts +3 -1
- package/src/lib/components/lead-properties-card.js +3 -2
- package/src/lib/components/lead-properties-card.js.map +1 -1
- package/src/lib/components/picklist-values-card.js +4 -2
- package/src/lib/components/picklist-values-card.js.map +1 -1
- package/src/lib/components/pipeline-stages-dialog.d.ts +3 -0
- package/src/lib/components/pipeline-stages-dialog.js +43 -14
- package/src/lib/components/pipeline-stages-dialog.js.map +1 -1
- package/src/lib/components/pipelines-dialog.d.ts +3 -0
- package/src/lib/components/pipelines-dialog.js +5 -2
- package/src/lib/components/pipelines-dialog.js.map +1 -1
- package/src/lib/components/record-tasks-card.js +3 -2
- package/src/lib/components/record-tasks-card.js.map +1 -1
- package/src/lib/components/task-edit-drawer.d.ts +2 -0
- package/src/lib/components/task-edit-drawer.js +2 -1
- package/src/lib/components/task-edit-drawer.js.map +1 -1
- package/src/lib/components/tasks-section.js +3 -2
- package/src/lib/components/tasks-section.js.map +1 -1
- package/src/lib/hooks/use-contact-field-definitions.d.ts +3 -0
- package/src/lib/hooks/use-contact-field-definitions.js +3 -2
- package/src/lib/hooks/use-contact-field-definitions.js.map +1 -1
- package/src/lib/hooks/use-crm-picklist.d.ts +3 -0
- package/src/lib/hooks/use-crm-picklist.js +5 -3
- package/src/lib/hooks/use-crm-picklist.js.map +1 -1
- package/src/lib/hooks/use-crm-tasks.d.ts +3 -0
- package/src/lib/hooks/use-crm-tasks.js +3 -1
- package/src/lib/hooks/use-crm-tasks.js.map +1 -1
- package/src/lib/hooks/use-lead-source-picklist.js +5 -3
- package/src/lib/hooks/use-lead-source-picklist.js.map +1 -1
- package/src/lib/hooks/use-lead-status-picklist.js +5 -3
- package/src/lib/hooks/use-lead-status-picklist.js.map +1 -1
- package/src/lib/hooks/use-pipeline.d.ts +3 -0
- package/src/lib/hooks/use-pipeline.js +3 -1
- package/src/lib/hooks/use-pipeline.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aglyn/plugins-crm",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://aglyn.com",
|
|
6
6
|
"repository": {
|
|
@@ -25,19 +25,19 @@
|
|
|
25
25
|
"./package.json": "./package.json"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aglyn/aglyn": "1.
|
|
29
|
-
"@aglyn/shared-data-enums": "1.
|
|
30
|
-
"@aglyn/shared-data-mdi": "1.
|
|
31
|
-
"@aglyn/shared-ui-jsx": "1.
|
|
32
|
-
"@aglyn/shared-ui-next": "1.
|
|
33
|
-
"@aglyn/shared-ui-snackstack": "1.
|
|
34
|
-
"@aglyn/shared-util-email": "1.
|
|
35
|
-
"@aglyn/shared-util-http": "1.
|
|
36
|
-
"@aglyn/shared-util-timestamp": "1.
|
|
37
|
-
"@aglyn/shared-util-tools": "1.
|
|
38
|
-
"@aglyn/tenant-data-admin": "1.
|
|
39
|
-
"@aglyn/tenant-feature-instance": "1.
|
|
40
|
-
"@aglyn/tenant-runtime": "1.
|
|
28
|
+
"@aglyn/aglyn": "1.6.0",
|
|
29
|
+
"@aglyn/shared-data-enums": "1.6.0",
|
|
30
|
+
"@aglyn/shared-data-mdi": "1.6.0",
|
|
31
|
+
"@aglyn/shared-ui-jsx": "1.6.0",
|
|
32
|
+
"@aglyn/shared-ui-next": "1.6.0",
|
|
33
|
+
"@aglyn/shared-ui-snackstack": "1.6.0",
|
|
34
|
+
"@aglyn/shared-util-email": "1.6.0",
|
|
35
|
+
"@aglyn/shared-util-http": "1.6.0",
|
|
36
|
+
"@aglyn/shared-util-timestamp": "1.6.0",
|
|
37
|
+
"@aglyn/shared-util-tools": "1.6.0",
|
|
38
|
+
"@aglyn/tenant-data-admin": "1.6.0",
|
|
39
|
+
"@aglyn/tenant-feature-instance": "1.6.0",
|
|
40
|
+
"@aglyn/tenant-runtime": "1.6.0",
|
|
41
41
|
"@dnd-kit/core": "^6.3.1",
|
|
42
42
|
"@dnd-kit/utilities": "^3.2.2",
|
|
43
43
|
"@swc/helpers": "0.5.23",
|
|
@@ -93,14 +93,18 @@ export function AddToListDialog(props) {
|
|
|
93
93
|
/*
|
|
94
94
|
* A preview belongs to the list and the addresses it was run for. Change
|
|
95
95
|
* either and the count on screen — and the attestation offered under it —
|
|
96
|
-
* would be about a different set, so both go.
|
|
97
|
-
|
|
96
|
+
* would be about a different set, so both go. Keyed on the addresses
|
|
97
|
+
* themselves: both openers hand over a new array on every render, the
|
|
98
|
+
* record page's on each snapshot of the contact, a metadata-only one
|
|
99
|
+
* included, and that unticked the attestation under the reader.
|
|
100
|
+
*/ const addressesKey = addresses.join('\n');
|
|
101
|
+
useEffect(()=>{
|
|
98
102
|
setPreview(null);
|
|
99
103
|
setAttested(false);
|
|
100
104
|
setResults(null);
|
|
101
105
|
}, [
|
|
102
106
|
listId,
|
|
103
|
-
|
|
107
|
+
addressesKey
|
|
104
108
|
]);
|
|
105
109
|
const post = useCallback(async (route, body)=>{
|
|
106
110
|
const response = await authorizedFetch(user, `/api/email/${route}`, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/components/add-to-list-dialog.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 * Put people from the CRM onto an email audience (AGL-2603).\n *\n * ## The same door the Emails console uses\n *\n * A list membership carries the consent basis that says why this person may\n * be mailed, and the rules make its create API-only for exactly that reason:\n * a client that could write one could mint a consent record by pressing a\n * button. So this dialog does not write a membership. It calls the two\n * routes the audience page's own add form calls — `email/list-members-preview`\n * to say, per address, what adding them would do, and `email/list-members-add`\n * to do it — with the same body and the same single attestation over the\n * count the operator was shown. Whoever is refused there is refused here, for\n * the same reason, in the same words.\n *\n * ## Check, then add\n *\n * The attestation is a statement about people, so the people are counted in\n * front of the operator before the checkbox exists: how many already opted\n * in, how many have nothing on record, how many cannot be added at all. The\n * routes take a hundred addresses a call, so a large selection is sent in\n * hundreds and the verdicts are summed — the number on screen is the whole\n * selection's, not the first page's.\n *\n * ## The audiences are a bounded lookup\n *\n * Fifty by name, the window the Emails console's own pickers use. A list is\n * org-shared, readable by an org-wide member and by nobody else, and the\n * route refuses a caller who is not one — so a collaborator scoped to one\n * site sees the listen refused and a sentence saying who manages audiences,\n * rather than an empty picker.\n */\n\nimport { authorizedFetch } from '@aglyn/shared-util-http/authorized-token'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport {\n Alert,\n Button,\n Checkbox,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n FormControlLabel,\n MenuItem,\n Stack,\n TextField,\n Typography,\n} from '@mui/material'\nimport { collection, limit, orderBy, query } from 'firebase/firestore'\nimport { useCallback, useEffect, useMemo, useState } from 'react'\nimport {\n useFirestore,\n useFirestoreCollection,\n useUser,\n} from '@aglyn/tenant-feature-instance'\n\n/**\n * How many addresses one call to the membership routes takes — their\n * `readAddresses` cap. Named here because a request over it is refused\n * whole, and a refusal of the whole selection reads as nobody being addable.\n */\nexport const LIST_MEMBER_REQUEST_CHUNK = 100\n\n/** The audience picker's window; the Emails console's own pickers use it. */\nexport const AUDIENCE_PICKER_LIMIT = 50\n\n/** What `email/list-members-preview` answers for one address. */\ninterface AddressVerdict {\n input: string\n email: string | null\n refusal: string | null\n requiresAttestation: boolean\n summary: string\n}\n\n/** The preview, summed over every chunk sent. */\ninterface Preview {\n verdicts: AddressVerdict[]\n optedIn: number\n needAttestation: number\n refused: number\n}\n\n/** What one address's outcome was, after the add. */\ninterface AddResult {\n input: string\n email: string | null\n enrolled: boolean\n error?: string\n}\n\ninterface AudienceRow {\n $id: string\n name?: string\n kind?: 'manual' | 'dynamic'\n}\n\nexport interface AddToListDialogProps {\n open: boolean\n onClose: () => void\n hostId: string\n /** `['orgs', orgId]`, or `null` while the org is still being resolved. */\n scope: readonly [string, string] | null\n /** The people to add — a selection's addresses, or one person's. */\n emails: readonly string[]\n /** Called once with how many were enrolled, when at least one was. */\n onAdded?: (added: number) => void\n}\n\n/** The addresses, deduplicated the way the route will deduplicate them. */\nconst distinctAddresses = (emails: readonly string[]): string[] => [\n ...new Set(\n emails.map((email) => String(email ?? '').trim().toLowerCase()).filter(Boolean),\n ),\n]\n\nconst chunk = <T,>(items: readonly T[], size: number): T[][] => {\n const chunks: T[][] = []\n for (let start = 0; start < items.length; start += size) {\n chunks.push(items.slice(start, start + size))\n }\n return chunks\n}\n\nexport function AddToListDialog(props: AddToListDialogProps) {\n const { open, onClose, hostId, scope, emails, onAdded } = props\n const firestore = useFirestore()\n const { data: user } = useUser()\n const { enqueueSnackbar } = useSnackbar()\n\n const addresses = useMemo(() => distinctAddresses(emails), [emails])\n\n const { data: audienceRows, status: audiencesStatus } =\n useFirestoreCollection<AudienceRow>(\n () =>\n open && scope\n ? query(\n collection(firestore, scope[0], scope[1], 'lists'),\n orderBy('name'),\n limit(AUDIENCE_PICKER_LIMIT),\n )\n : null,\n [firestore, scope, open],\n { idField: '$id' },\n )\n const audiences = audienceRows ?? []\n\n const [listId, setListId] = useState('')\n const [preview, setPreview] = useState<Preview | null>(null)\n const [attested, setAttested] = useState(false)\n const [results, setResults] = useState<AddResult[] | null>(null)\n const [busy, setBusy] = useState(false)\n\n /*\n * A preview belongs to the list and the addresses it was run for. Change\n * either and the count on screen — and the attestation offered under it —\n * would be about a different set, so both go.\n */\n useEffect(() => {\n setPreview(null)\n setAttested(false)\n setResults(null)\n }, [listId, addresses])\n\n const post = useCallback(\n async (route: string, body: Record<string, unknown>) => {\n const response = await authorizedFetch(user, `/api/email/${route}`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ hostId, listId, ...body }),\n })\n const payload = await response.json().catch(() => ({}))\n return { ok: response.ok, payload }\n },\n [user, hostId, listId],\n )\n\n const handleCheck = useCallback(async () => {\n if (busy || !listId || !addresses.length) return\n setBusy(true)\n try {\n const summed: Preview = {\n verdicts: [],\n optedIn: 0,\n needAttestation: 0,\n refused: 0,\n }\n for (const batch of chunk(addresses, LIST_MEMBER_REQUEST_CHUNK)) {\n const { ok, payload } = await post('list-members-preview', {\n emails: batch,\n })\n if (!ok) {\n return void enqueueSnackbar(\n payload?.error ?? 'The addresses could not be checked.',\n { variant: 'warning', allowDuplicate: true },\n )\n }\n const page = payload as Preview\n summed.verdicts.push(...(page.verdicts ?? []))\n summed.optedIn += Number(page.optedIn ?? 0)\n summed.needAttestation += Number(page.needAttestation ?? 0)\n summed.refused += Number(page.refused ?? 0)\n }\n setPreview(summed)\n } catch {\n enqueueSnackbar('The addresses could not be checked.', {\n variant: 'warning',\n allowDuplicate: true,\n })\n } finally {\n setBusy(false)\n }\n }, [busy, listId, addresses, post, enqueueSnackbar])\n\n const handleAdd = useCallback(async () => {\n if (busy || !preview) return\n setBusy(true)\n try {\n const all: AddResult[] = []\n for (const batch of chunk(addresses, LIST_MEMBER_REQUEST_CHUNK)) {\n const { ok, payload } = await post('list-members-add', {\n emails: batch,\n // The operator's assertion, applied per address by the route to\n // the people who need it; a stored opt-in keeps its own basis.\n attestConsent: attested,\n })\n if (!ok) {\n return void enqueueSnackbar(\n payload?.error ?? 'Nobody was added to the list',\n { variant: 'warning', allowDuplicate: true },\n )\n }\n all.push(...((payload?.results ?? []) as AddResult[]))\n }\n const added = all.filter((result) => result.enrolled).length\n setResults(all)\n setPreview(null)\n if (added) onAdded?.(added)\n enqueueSnackbar(\n added === 1 ? 'One person added' : `${added} people added`,\n { variant: added ? 'success' : 'warning', persist: false },\n )\n } catch {\n enqueueSnackbar('Nobody was added to the list', {\n variant: 'warning',\n allowDuplicate: true,\n })\n } finally {\n setBusy(false)\n }\n }, [busy, preview, addresses, attested, post, enqueueSnackbar, onAdded])\n\n const enrollable = preview ? preview.optedIn + preview.needAttestation : 0\n const chosen = audiences.find((row) => row.$id === listId)\n\n return (\n <Dialog open={open} onClose={busy ? undefined : onClose} fullWidth maxWidth=\"sm\">\n <DialogTitle>\n {addresses.length === 1\n ? 'Add to an audience'\n : `Add ${addresses.length} people to an audience`}\n </DialogTitle>\n <DialogContent>\n <Stack spacing={2} sx={{ pt: 1 }}>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Every address is checked against its consent record and both ' +\n 'suppression lists before anyone is added — the same check the ' +\n \"audience's own page runs.\"}\n </Typography>\n {audiencesStatus === 'error' ? (\n <Alert severity=\"warning\">\n {'Audiences are managed by members with access to every site ' +\n 'in the workspace. Ask one of them to add these people.'}\n </Alert>\n ) : (\n <TextField\n select\n size=\"small\"\n label=\"Audience\"\n value={listId}\n onChange={(event) => setListId(event.target.value)}\n disabled={busy}\n helperText={\n chosen?.kind === 'dynamic'\n ? 'A live audience. Whoever you add stays, whether or not the rule matches them.'\n : audiences.length\n ? undefined\n : 'No audiences yet — create one under Emails.'\n }\n >\n {audiences.map((row) => (\n <MenuItem key={row.$id} value={row.$id}>\n {row.name ?? row.$id}\n </MenuItem>\n ))}\n </TextField>\n )}\n {preview ? (\n <Stack spacing={1}>\n <Alert severity={enrollable ? 'info' : 'warning'}>\n {[\n preview.optedIn ? `${preview.optedIn} already opted in` : '',\n preview.needAttestation\n ? `${preview.needAttestation} with no opt-in on record`\n : '',\n preview.refused ? `${preview.refused} cannot be added at all` : '',\n ]\n .filter(Boolean)\n .join(' · ')}\n </Alert>\n {/*\n The hard refusals only, by address. An address that merely\n needs the attestation is not a refusal, and listing it here\n would put the people the checkbox is about under a heading\n that says they cannot be added.\n */}\n {preview.verdicts\n .filter((verdict) => verdict.refusal)\n .map((verdict) => (\n <Typography\n key={verdict.input}\n variant=\"caption\"\n color=\"text.secondary\"\n >\n {`${verdict.input} — ${verdict.summary}`}\n </Typography>\n ))}\n {preview.needAttestation ? (\n <FormControlLabel\n control={\n <Checkbox\n checked={attested}\n onChange={(event) => setAttested(event.target.checked)}\n />\n }\n label={\n <Typography variant=\"body2\">\n {'I have permission to send marketing email to the ' +\n `${preview.needAttestation} ` +\n `${preview.needAttestation === 1 ? 'person' : 'people'} ` +\n 'with no opt-in on record. This is recorded against my ' +\n 'account, with the date.'}\n </Typography>\n }\n />\n ) : null}\n </Stack>\n ) : null}\n {results?.length ? (\n <Stack spacing={0.5}>\n {results\n .filter((result) => !result.enrolled)\n .map((result) => (\n <Typography\n key={result.input}\n variant=\"caption\"\n color=\"text.secondary\"\n >\n {`${result.input} — not added. ${result.error ?? ''}`}\n </Typography>\n ))}\n </Stack>\n ) : null}\n </Stack>\n </DialogContent>\n <DialogActions>\n <Button onClick={onClose} disabled={busy}>\n {results ? 'Done' : 'Cancel'}\n </Button>\n {preview ? (\n <Button\n variant=\"contained\"\n disabled={\n busy || !enrollable || (preview.needAttestation > 0 && !attested)\n }\n onClick={() => void handleAdd()}\n >\n {busy ? 'Adding…' : `Add ${enrollable}`}\n </Button>\n ) : (\n <Button\n variant=\"contained\"\n disabled={busy || !listId || !addresses.length || Boolean(results)}\n onClick={() => void handleCheck()}\n >\n {busy ? 'Checking…' : 'Check'}\n </Button>\n )}\n </DialogActions>\n </Dialog>\n )\n}\nAddToListDialog.displayName = 'AddToListDialog'\n\nexport default AddToListDialog\n"],"names":["authorizedFetch","useSnackbar","Alert","Button","Checkbox","Dialog","DialogActions","DialogContent","DialogTitle","FormControlLabel","MenuItem","Stack","TextField","Typography","collection","limit","orderBy","query","useCallback","useEffect","useMemo","useState","useFirestore","useFirestoreCollection","useUser","LIST_MEMBER_REQUEST_CHUNK","AUDIENCE_PICKER_LIMIT","distinctAddresses","emails","Set","map","email","String","trim","toLowerCase","filter","Boolean","chunk","items","size","chunks","start","length","push","slice","AddToListDialog","props","open","onClose","hostId","scope","onAdded","firestore","data","user","enqueueSnackbar","addresses","audienceRows","status","audiencesStatus","idField","audiences","listId","setListId","preview","setPreview","attested","setAttested","results","setResults","busy","setBusy","post","route","body","response","method","headers","JSON","stringify","payload","json","catch","ok","handleCheck","summed","verdicts","optedIn","needAttestation","refused","batch","page","error","variant","allowDuplicate","Number","handleAdd","all","attestConsent","added","result","enrolled","persist","enrollable","chosen","find","row","$id","undefined","fullWidth","maxWidth","spacing","sx","pt","color","severity","select","label","value","onChange","event","target","disabled","helperText","kind","name","join","verdict","refusal","input","summary","control","checked","onClick","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BC,GAED,SAASA,eAAe,QAAQ,2CAA0C;AAC1E,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SACEC,KAAK,EACLC,MAAM,EACNC,QAAQ,EACRC,MAAM,EACNC,aAAa,EACbC,aAAa,EACbC,WAAW,EACXC,gBAAgB,EAChBC,QAAQ,EACRC,KAAK,EACLC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,UAAU,EAAEC,KAAK,EAAEC,OAAO,EAAEC,KAAK,QAAQ,qBAAoB;AACtE,SAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AACjE,SACEC,YAAY,EACZC,sBAAsB,EACtBC,OAAO,QACF,iCAAgC;AAEvC;;;;CAIC,GACD,OAAO,MAAMC,4BAA4B,IAAG;AAE5C,2EAA2E,GAC3E,OAAO,MAAMC,wBAAwB,GAAE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AErBJ,wBACC,KAAC7D;wBACC0F,SAAQ;wBACR6B,UACEpD,QAAQ,CAACiC,cAAevC,QAAQwB,eAAe,GAAG,KAAK,CAACtB;wBAE1DmE,SAAS,IAAM,KAAKrC;kCAEnB1B,OAAO,YAAY,CAAC,IAAI,EAAEiC,YAAY;uCAGzC,KAACpG;wBACC0F,SAAQ;wBACR6B,UAAUpD,QAAQ,CAACR,UAAU,CAACN,UAAUd,MAAM,IAAIN,QAAQgC;wBAC1DiE,SAAS,IAAM,KAAKjD;kCAEnBd,OAAO,cAAc;;;;;;AAMlC;AACAzB,gBAAgByF,WAAW,GAAG;AAE9B,eAAezF,gBAAe"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/components/add-to-list-dialog.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 * Put people from the CRM onto an email audience (AGL-2603).\n *\n * ## The same door the Emails console uses\n *\n * A list membership carries the consent basis that says why this person may\n * be mailed, and the rules make its create API-only for exactly that reason:\n * a client that could write one could mint a consent record by pressing a\n * button. So this dialog does not write a membership. It calls the two\n * routes the audience page's own add form calls — `email/list-members-preview`\n * to say, per address, what adding them would do, and `email/list-members-add`\n * to do it — with the same body and the same single attestation over the\n * count the operator was shown. Whoever is refused there is refused here, for\n * the same reason, in the same words.\n *\n * ## Check, then add\n *\n * The attestation is a statement about people, so the people are counted in\n * front of the operator before the checkbox exists: how many already opted\n * in, how many have nothing on record, how many cannot be added at all. The\n * routes take a hundred addresses a call, so a large selection is sent in\n * hundreds and the verdicts are summed — the number on screen is the whole\n * selection's, not the first page's.\n *\n * ## The audiences are a bounded lookup\n *\n * Fifty by name, the window the Emails console's own pickers use. A list is\n * org-shared, readable by an org-wide member and by nobody else, and the\n * route refuses a caller who is not one — so a collaborator scoped to one\n * site sees the listen refused and a sentence saying who manages audiences,\n * rather than an empty picker.\n */\n\nimport { authorizedFetch } from '@aglyn/shared-util-http/authorized-token'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport {\n Alert,\n Button,\n Checkbox,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n FormControlLabel,\n MenuItem,\n Stack,\n TextField,\n Typography,\n} from '@mui/material'\nimport { collection, limit, orderBy, query } from 'firebase/firestore'\nimport { useCallback, useEffect, useMemo, useState } from 'react'\nimport {\n useFirestore,\n useFirestoreCollection,\n useUser,\n} from '@aglyn/tenant-feature-instance'\n\n/**\n * How many addresses one call to the membership routes takes — their\n * `readAddresses` cap. Named here because a request over it is refused\n * whole, and a refusal of the whole selection reads as nobody being addable.\n */\nexport const LIST_MEMBER_REQUEST_CHUNK = 100\n\n/** The audience picker's window; the Emails console's own pickers use it. */\nexport const AUDIENCE_PICKER_LIMIT = 50\n\n/** What `email/list-members-preview` answers for one address. */\ninterface AddressVerdict {\n input: string\n email: string | null\n refusal: string | null\n requiresAttestation: boolean\n summary: string\n}\n\n/** The preview, summed over every chunk sent. */\ninterface Preview {\n verdicts: AddressVerdict[]\n optedIn: number\n needAttestation: number\n refused: number\n}\n\n/** What one address's outcome was, after the add. */\ninterface AddResult {\n input: string\n email: string | null\n enrolled: boolean\n error?: string\n}\n\ninterface AudienceRow {\n $id: string\n name?: string\n kind?: 'manual' | 'dynamic'\n}\n\nexport interface AddToListDialogProps {\n open: boolean\n onClose: () => void\n hostId: string\n /** `['orgs', orgId]`, or `null` while the org is still being resolved. */\n scope: readonly [string, string] | null\n /** The people to add — a selection's addresses, or one person's. */\n emails: readonly string[]\n /** Called once with how many were enrolled, when at least one was. */\n onAdded?: (added: number) => void\n}\n\n/** The addresses, deduplicated the way the route will deduplicate them. */\nconst distinctAddresses = (emails: readonly string[]): string[] => [\n ...new Set(\n emails.map((email) => String(email ?? '').trim().toLowerCase()).filter(Boolean),\n ),\n]\n\nconst chunk = <T,>(items: readonly T[], size: number): T[][] => {\n const chunks: T[][] = []\n for (let start = 0; start < items.length; start += size) {\n chunks.push(items.slice(start, start + size))\n }\n return chunks\n}\n\nexport function AddToListDialog(props: AddToListDialogProps) {\n const { open, onClose, hostId, scope, emails, onAdded } = props\n const firestore = useFirestore()\n const { data: user } = useUser()\n const { enqueueSnackbar } = useSnackbar()\n\n const addresses = useMemo(() => distinctAddresses(emails), [emails])\n\n const { data: audienceRows, status: audiencesStatus } =\n useFirestoreCollection<AudienceRow>(\n () =>\n open && scope\n ? query(\n collection(firestore, scope[0], scope[1], 'lists'),\n orderBy('name'),\n limit(AUDIENCE_PICKER_LIMIT),\n )\n : null,\n [firestore, scope, open],\n { idField: '$id' },\n )\n const audiences = audienceRows ?? []\n\n const [listId, setListId] = useState('')\n const [preview, setPreview] = useState<Preview | null>(null)\n const [attested, setAttested] = useState(false)\n const [results, setResults] = useState<AddResult[] | null>(null)\n const [busy, setBusy] = useState(false)\n\n /*\n * A preview belongs to the list and the addresses it was run for. Change\n * either and the count on screen — and the attestation offered under it —\n * would be about a different set, so both go. Keyed on the addresses\n * themselves: both openers hand over a new array on every render, the\n * record page's on each snapshot of the contact, a metadata-only one\n * included, and that unticked the attestation under the reader.\n */\n const addressesKey = addresses.join('\\n')\n useEffect(() => {\n setPreview(null)\n setAttested(false)\n setResults(null)\n }, [listId, addressesKey])\n\n const post = useCallback(\n async (route: string, body: Record<string, unknown>) => {\n const response = await authorizedFetch(user, `/api/email/${route}`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ hostId, listId, ...body }),\n })\n const payload = await response.json().catch(() => ({}))\n return { ok: response.ok, payload }\n },\n [user, hostId, listId],\n )\n\n const handleCheck = useCallback(async () => {\n if (busy || !listId || !addresses.length) return\n setBusy(true)\n try {\n const summed: Preview = {\n verdicts: [],\n optedIn: 0,\n needAttestation: 0,\n refused: 0,\n }\n for (const batch of chunk(addresses, LIST_MEMBER_REQUEST_CHUNK)) {\n const { ok, payload } = await post('list-members-preview', {\n emails: batch,\n })\n if (!ok) {\n return void enqueueSnackbar(\n payload?.error ?? 'The addresses could not be checked.',\n { variant: 'warning', allowDuplicate: true },\n )\n }\n const page = payload as Preview\n summed.verdicts.push(...(page.verdicts ?? []))\n summed.optedIn += Number(page.optedIn ?? 0)\n summed.needAttestation += Number(page.needAttestation ?? 0)\n summed.refused += Number(page.refused ?? 0)\n }\n setPreview(summed)\n } catch {\n enqueueSnackbar('The addresses could not be checked.', {\n variant: 'warning',\n allowDuplicate: true,\n })\n } finally {\n setBusy(false)\n }\n }, [busy, listId, addresses, post, enqueueSnackbar])\n\n const handleAdd = useCallback(async () => {\n if (busy || !preview) return\n setBusy(true)\n try {\n const all: AddResult[] = []\n for (const batch of chunk(addresses, LIST_MEMBER_REQUEST_CHUNK)) {\n const { ok, payload } = await post('list-members-add', {\n emails: batch,\n // The operator's assertion, applied per address by the route to\n // the people who need it; a stored opt-in keeps its own basis.\n attestConsent: attested,\n })\n if (!ok) {\n return void enqueueSnackbar(\n payload?.error ?? 'Nobody was added to the list',\n { variant: 'warning', allowDuplicate: true },\n )\n }\n all.push(...((payload?.results ?? []) as AddResult[]))\n }\n const added = all.filter((result) => result.enrolled).length\n setResults(all)\n setPreview(null)\n if (added) onAdded?.(added)\n enqueueSnackbar(\n added === 1 ? 'One person added' : `${added} people added`,\n { variant: added ? 'success' : 'warning', persist: false },\n )\n } catch {\n enqueueSnackbar('Nobody was added to the list', {\n variant: 'warning',\n allowDuplicate: true,\n })\n } finally {\n setBusy(false)\n }\n }, [busy, preview, addresses, attested, post, enqueueSnackbar, onAdded])\n\n const enrollable = preview ? preview.optedIn + preview.needAttestation : 0\n const chosen = audiences.find((row) => row.$id === listId)\n\n return (\n <Dialog open={open} onClose={busy ? undefined : onClose} fullWidth maxWidth=\"sm\">\n <DialogTitle>\n {addresses.length === 1\n ? 'Add to an audience'\n : `Add ${addresses.length} people to an audience`}\n </DialogTitle>\n <DialogContent>\n <Stack spacing={2} sx={{ pt: 1 }}>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Every address is checked against its consent record and both ' +\n 'suppression lists before anyone is added — the same check the ' +\n \"audience's own page runs.\"}\n </Typography>\n {audiencesStatus === 'error' ? (\n <Alert severity=\"warning\">\n {'Audiences are managed by members with access to every site ' +\n 'in the workspace. Ask one of them to add these people.'}\n </Alert>\n ) : (\n <TextField\n select\n size=\"small\"\n label=\"Audience\"\n value={listId}\n onChange={(event) => setListId(event.target.value)}\n disabled={busy}\n helperText={\n chosen?.kind === 'dynamic'\n ? 'A live audience. Whoever you add stays, whether or not the rule matches them.'\n : audiences.length\n ? undefined\n : 'No audiences yet — create one under Emails.'\n }\n >\n {audiences.map((row) => (\n <MenuItem key={row.$id} value={row.$id}>\n {row.name ?? row.$id}\n </MenuItem>\n ))}\n </TextField>\n )}\n {preview ? (\n <Stack spacing={1}>\n <Alert severity={enrollable ? 'info' : 'warning'}>\n {[\n preview.optedIn ? `${preview.optedIn} already opted in` : '',\n preview.needAttestation\n ? `${preview.needAttestation} with no opt-in on record`\n : '',\n preview.refused ? `${preview.refused} cannot be added at all` : '',\n ]\n .filter(Boolean)\n .join(' · ')}\n </Alert>\n {/*\n The hard refusals only, by address. An address that merely\n needs the attestation is not a refusal, and listing it here\n would put the people the checkbox is about under a heading\n that says they cannot be added.\n */}\n {preview.verdicts\n .filter((verdict) => verdict.refusal)\n .map((verdict) => (\n <Typography\n key={verdict.input}\n variant=\"caption\"\n color=\"text.secondary\"\n >\n {`${verdict.input} — ${verdict.summary}`}\n </Typography>\n ))}\n {preview.needAttestation ? (\n <FormControlLabel\n control={\n <Checkbox\n checked={attested}\n onChange={(event) => setAttested(event.target.checked)}\n />\n }\n label={\n <Typography variant=\"body2\">\n {'I have permission to send marketing email to the ' +\n `${preview.needAttestation} ` +\n `${preview.needAttestation === 1 ? 'person' : 'people'} ` +\n 'with no opt-in on record. This is recorded against my ' +\n 'account, with the date.'}\n </Typography>\n }\n />\n ) : null}\n </Stack>\n ) : null}\n {results?.length ? (\n <Stack spacing={0.5}>\n {results\n .filter((result) => !result.enrolled)\n .map((result) => (\n <Typography\n key={result.input}\n variant=\"caption\"\n color=\"text.secondary\"\n >\n {`${result.input} — not added. ${result.error ?? ''}`}\n </Typography>\n ))}\n </Stack>\n ) : null}\n </Stack>\n </DialogContent>\n <DialogActions>\n <Button onClick={onClose} disabled={busy}>\n {results ? 'Done' : 'Cancel'}\n </Button>\n {preview ? (\n <Button\n variant=\"contained\"\n disabled={\n busy || !enrollable || (preview.needAttestation > 0 && !attested)\n }\n onClick={() => void handleAdd()}\n >\n {busy ? 'Adding…' : `Add ${enrollable}`}\n </Button>\n ) : (\n <Button\n variant=\"contained\"\n disabled={busy || !listId || !addresses.length || Boolean(results)}\n onClick={() => void handleCheck()}\n >\n {busy ? 'Checking…' : 'Check'}\n </Button>\n )}\n </DialogActions>\n </Dialog>\n )\n}\nAddToListDialog.displayName = 'AddToListDialog'\n\nexport default AddToListDialog\n"],"names":["authorizedFetch","useSnackbar","Alert","Button","Checkbox","Dialog","DialogActions","DialogContent","DialogTitle","FormControlLabel","MenuItem","Stack","TextField","Typography","collection","limit","orderBy","query","useCallback","useEffect","useMemo","useState","useFirestore","useFirestoreCollection","useUser","LIST_MEMBER_REQUEST_CHUNK","AUDIENCE_PICKER_LIMIT","distinctAddresses","emails","Set","map","email","String","trim","toLowerCase","filter","Boolean","chunk","items","size","chunks","start","length","push","slice","AddToListDialog","props","open","onClose","hostId","scope","onAdded","firestore","data","user","enqueueSnackbar","addresses","audienceRows","status","audiencesStatus","idField","audiences","listId","setListId","preview","setPreview","attested","setAttested","results","setResults","busy","setBusy","addressesKey","join","post","route","body","response","method","headers","JSON","stringify","payload","json","catch","ok","handleCheck","summed","verdicts","optedIn","needAttestation","refused","batch","page","error","variant","allowDuplicate","Number","handleAdd","all","attestConsent","added","result","enrolled","persist","enrollable","chosen","find","row","$id","undefined","fullWidth","maxWidth","spacing","sx","pt","color","severity","select","label","value","onChange","event","target","disabled","helperText","kind","name","verdict","refusal","input","summary","control","checked","onClick","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BC,GAED,SAASA,eAAe,QAAQ,2CAA0C;AAC1E,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SACEC,KAAK,EACLC,MAAM,EACNC,QAAQ,EACRC,MAAM,EACNC,aAAa,EACbC,aAAa,EACbC,WAAW,EACXC,gBAAgB,EAChBC,QAAQ,EACRC,KAAK,EACLC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,UAAU,EAAEC,KAAK,EAAEC,OAAO,EAAEC,KAAK,QAAQ,qBAAoB;AACtE,SAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AACjE,SACEC,YAAY,EACZC,sBAAsB,EACtBC,OAAO,QACF,iCAAgC;AAEvC;;;;CAIC,GACD,OAAO,MAAMC,4BAA4B,IAAG;AAE5C,2EAA2E,GAC3E,OAAO,MAAMC,wBAAwB,GAAE;AA6CvC,yEAAyE,GACzE,MAAMC,oBAAoB,CAACC,SAAwC;WAC9D,IAAIC,IACLD,OAAOE,GAAG,CAAC,CAACC,QAAUC,OAAOD,gBAAAA,QAAS,IAAIE,IAAI,GAAGC,WAAW,IAAIC,MAAM,CAACC;KAE1E;AAED,MAAMC,QAAQ,CAAKC,OAAqBC;IACtC,MAAMC,SAAgB,EAAE;IACxB,IAAK,IAAIC,QAAQ,GAAGA,QAAQH,MAAMI,MAAM,EAAED,SAASF,KAAM;QACvDC,OAAOG,IAAI,CAACL,MAAMM,KAAK,CAACH,OAAOA,QAAQF;IACzC;I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EnBhB,OAAO,cAAc;;;;;;AAMlC;AACAzB,gBAAgB0F,WAAW,GAAG;AAE9B,eAAe1F,gBAAe"}
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
+
import { type ListenHandle } from '@aglyn/tenant-feature-instance';
|
|
17
18
|
import { type CrmOrgDoc } from '../hooks/use-crm-scope';
|
|
18
19
|
import type { CrmRoutes } from '../model/crm-routes';
|
|
19
20
|
export interface CompanyContactRolesCardProps {
|
|
@@ -28,6 +29,8 @@ export interface CompanyContactRolesCardProps {
|
|
|
28
29
|
/** The listener's verdict on the company, for the stale-seed guard. */
|
|
29
30
|
fromCache: boolean;
|
|
30
31
|
unreadable: boolean;
|
|
32
|
+
/** The company's listener, so a save waits on that read alone (AGL-4135). */
|
|
33
|
+
listen?: ListenHandle | null;
|
|
31
34
|
}
|
|
32
35
|
/**
|
|
33
36
|
* Salesforce's Account Contact Roles (AGL-4122): who at a company plays which
|
|
@@ -33,7 +33,7 @@ import { ContactRolesEditor } from "./contact-roles-editor.js";
|
|
|
33
33
|
*/ export function CompanyContactRolesCard(props) {
|
|
34
34
|
var _ref;
|
|
35
35
|
var _scope_consentGroup;
|
|
36
|
-
const { companyId, company, hostId, org, routes, fromCache, unreadable } = props;
|
|
36
|
+
const { companyId, company, hostId, org, routes, fromCache, unreadable, listen } = props;
|
|
37
37
|
const firestore = useFirestore();
|
|
38
38
|
const { enqueueSnackbar } = useSnackbar();
|
|
39
39
|
const scope = useCrmScope({
|
|
@@ -71,7 +71,8 @@ import { ContactRolesEditor } from "./contact-roles-editor.js";
|
|
|
71
71
|
const written = await writeGuardedBySeed({
|
|
72
72
|
subject: 'company',
|
|
73
73
|
unreadable,
|
|
74
|
-
fromCache
|
|
74
|
+
fromCache,
|
|
75
|
+
listen
|
|
75
76
|
}, async ()=>{
|
|
76
77
|
await updateDoc(doc(firestore, 'orgs', scope.orgId, CRM_COLLECTIONS.companies, companyId), {
|
|
77
78
|
contactRoles: verdict.contactRoles,
|
|
@@ -108,6 +109,7 @@ import { ContactRolesEditor } from "./contact-roles-editor.js";
|
|
|
108
109
|
roleList.picklist,
|
|
109
110
|
unreadable,
|
|
110
111
|
fromCache,
|
|
112
|
+
listen,
|
|
111
113
|
firestore,
|
|
112
114
|
companyId,
|
|
113
115
|
enqueueSnackbar
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/components/company-contact-roles-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\n'use client'\n\nimport {\n CRM_COLLECTIONS,\n type CrmDealContactRole,\n pluginDocsHelp,\n} from '@aglyn/aglyn'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/components/company-contact-roles-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\n'use client'\n\nimport {\n CRM_COLLECTIONS,\n type CrmDealContactRole,\n pluginDocsHelp,\n} from '@aglyn/aglyn'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport {\n useFirestore,\n writeGuardedBySeed,\n type ListenHandle,\n} from '@aglyn/tenant-feature-instance'\nimport { doc, updateDoc } from 'firebase/firestore'\nimport { useCallback, useMemo, useState } from 'react'\nimport { useCrmPicklist } from '../hooks/use-crm-picklist'\nimport { useCrmRecordNames } from '../hooks/use-crm-record-names'\nimport { type CrmOrgDoc, useCrmScope } from '../hooks/use-crm-scope'\nimport type { CrmRoutes } from '../model/crm-routes'\nimport { companyContactRolesOf, companyContactRolesSave } from '../model/deal-contact-roles'\nimport { ContactRolesEditor } from './contact-roles-editor'\n\nexport interface CompanyContactRolesCardProps {\n companyId: string\n company: { contactRoles?: unknown }\n /** The site the page is read under, or `null` at the organization level. */\n hostId: string | null\n org: CrmOrgDoc\n routes: CrmRoutes\n /** The listener's verdict on the company, for the stale-seed guard. */\n fromCache: boolean\n unreadable: boolean\n /** The company's listener, so a save waits on that read alone (AGL-4135). */\n listen?: ListenHandle | null\n}\n\n/**\n * Salesforce's Account Contact Roles (AGL-4122): who at a company plays which\n * part, and who the Primary is. Separate from the roles on a deal, as there: a\n * person's part in the company is a fact about the account, and their part in\n * one deal can differ. The same list of roles serves both.\n */\nexport function CompanyContactRolesCard(props: CompanyContactRolesCardProps) {\n const { companyId, company, hostId, org, routes, fromCache, unreadable, listen } = props\n const firestore = useFirestore()\n const { enqueueSnackbar } = useSnackbar()\n const scope = useCrmScope({ hostId, org })\n const groupId = scope.consentGroup?.groupId ?? null\n const roles = useMemo(() => companyContactRolesOf(company), [company])\n const roleList = useCrmPicklist('opportunityContactRole', scope.orgId)\n const nameOf = useCrmRecordNames({\n orgId: scope.orgId,\n groupId,\n org: (org ?? null) as Record<string, unknown> | null,\n records: roles.map((row) => ({ kind: 'contact' as const, id: row.contactId })),\n })\n const [busy, setBusy] = useState(false)\n const [adding, setAdding] = useState(false)\n\n const save = useCallback(\n async (next: CrmDealContactRole[], done: string) => {\n if (!scope.orgId) return false\n const verdict = companyContactRolesSave(company, next, roleList.picklist)\n if (verdict.ok === false) {\n enqueueSnackbar(verdict.error, { variant: 'warning', persist: false })\n return false\n }\n setBusy(true)\n try {\n const written = await writeGuardedBySeed(\n { subject: 'company', unreadable, fromCache, listen },\n async () => {\n await updateDoc(\n doc(firestore, 'orgs', scope.orgId as string, CRM_COLLECTIONS.companies, companyId),\n {\n contactRoles: verdict.contactRoles,\n contactRoleContactIds: verdict.contactRoleContactIds,\n contactRoleKeys: verdict.contactRoleKeys,\n updatedAt: new Date(),\n },\n )\n },\n )\n if (!written.ok) {\n enqueueSnackbar(written.message, { variant: 'warning', persist: false })\n return false\n }\n enqueueSnackbar(done, { variant: 'success', persist: false })\n return true\n } catch (error) {\n console.error(error)\n enqueueSnackbar('An error has occurred', { variant: 'error', allowDuplicate: true })\n return false\n } finally {\n setBusy(false)\n }\n },\n [\n scope.orgId,\n company,\n roleList.picklist,\n unreadable,\n fromCache,\n listen,\n firestore,\n companyId,\n enqueueSnackbar,\n ],\n )\n\n return (\n <ContactRolesEditor\n noun=\"company\"\n roles={roles}\n busy={busy}\n adding={adding}\n onAddingChange={setAdding}\n ready={Boolean(scope.orgId)}\n hostId={hostId}\n org={org}\n routes={routes}\n picklist={roleList.picklist}\n nameOf={nameOf}\n help={pluginDocsHelp('companies', { anchor: '#contact-roles' })}\n emptyDescription=\"Name who at the company plays which part, one of them Primary.\"\n save={save}\n />\n )\n}\nCompanyContactRolesCard.displayName = 'CompanyContactRolesCard'\n\nexport default CompanyContactRolesCard\n"],"names":["CRM_COLLECTIONS","pluginDocsHelp","useSnackbar","useFirestore","writeGuardedBySeed","doc","updateDoc","useCallback","useMemo","useState","useCrmPicklist","useCrmRecordNames","useCrmScope","companyContactRolesOf","companyContactRolesSave","ContactRolesEditor","CompanyContactRolesCard","props","scope","companyId","company","hostId","org","routes","fromCache","unreadable","listen","firestore","enqueueSnackbar","groupId","consentGroup","roles","roleList","orgId","nameOf","records","map","row","kind","id","contactId","busy","setBusy","adding","setAdding","save","next","done","verdict","picklist","ok","error","variant","persist","written","subject","companies","contactRoles","contactRoleContactIds","contactRoleKeys","updatedAt","Date","message","console","allowDuplicate","noun","onAddingChange","ready","Boolean","help","anchor","emptyDescription","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;AAEA,SACEA,eAAe,EAEfC,cAAc,QACT,eAAc;AACrB,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SACEC,YAAY,EACZC,kBAAkB,QAEb,iCAAgC;AACvC,SAASC,GAAG,EAAEC,SAAS,QAAQ,qBAAoB;AACnD,SAASC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AACtD,SAASC,cAAc,QAAQ,+BAA2B;AAC1D,SAASC,iBAAiB,QAAQ,mCAA+B;AACjE,SAAyBC,WAAW,QAAQ,4BAAwB;AAEpE,SAASC,qBAAqB,EAAEC,uBAAuB,QAAQ,iCAA6B;AAC5F,SAASC,kBAAkB,QAAQ,4BAAwB;AAgB3D;;;;;CAKC,GACD,OAAO,SAASC,wBAAwBC,KAAmC;;QAKzDC;IAJhB,MAAM,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,GAAG,EAAEC,MAAM,EAAEC,SAAS,EAAEC,UAAU,EAAEC,MAAM,EAAE,GAAGT;IACnF,MAAMU,YAAYxB;IAClB,MAAM,EAAEyB,eAAe,EAAE,GAAG1B;IAC5B,MAAMgB,QAAQN,YAAY;QAAES;QAAQC;IAAI;IACxC,MAAMO,mBAAUX,sBAAAA,MAAMY,YAAY,qBAAlBZ,oBAAoBW,OAAO,mBAAI;IAC/C,MAAME,QAAQvB,QAAQ,IAAMK,sBAAsBO,UAAU;QAACA;KAAQ;IACrE,MAAMY,WAAWtB,eAAe,0BAA0BQ,MAAMe,KAAK;IACrE,MAAMC,SAASvB,kBAAkB;QAC/BsB,OAAOf,MAAMe,KAAK;QAClBJ;QACAP,GAAG,EAAGA,cAAAA,MAAO;QACba,SAASJ,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AD;QACAE;QACAC;QACAR;QACAS;KACD;IAGH,qBACE,KAACb;QACCkD,MAAK;QACLlC,OAAOA;QACPU,MAAMA;QACNE,QAAQA;QACRuB,gBAAgBtB;QAChBuB,OAAOC,QAAQlD,MAAMe,KAAK;QAC1BZ,QAAQA;QACRC,KAAKA;QACLC,QAAQA;QACR0B,UAAUjB,SAASiB,QAAQ;QAC3Bf,QAAQA;QACRmC,MAAMpE,eAAe,aAAa;YAAEqE,QAAQ;QAAiB;QAC7DC,kBAAiB;QACjB1B,MAAMA;;AAGZ;AACA7B,wBAAwBwD,WAAW,GAAG;AAEtC,eAAexD,wBAAuB"}
|
|
@@ -62,7 +62,7 @@ import { CrmRecordInsightsZone } from "./crm-record-insights-zone.js";
|
|
|
62
62
|
});
|
|
63
63
|
const { scope, orgId } = crmScope;
|
|
64
64
|
const members = useOrgMemberOptions(orgId);
|
|
65
|
-
const { data: company, status, fromCache } = useFirestoreDoc(()=>scope ? doc(firestore, scope[0], scope[1], CRM_COLLECTIONS.companies, id) : null, [
|
|
65
|
+
const { data: company, status, fromCache, listen } = useFirestoreDoc(()=>scope ? doc(firestore, scope[0], scope[1], CRM_COLLECTIONS.companies, id) : null, [
|
|
66
66
|
firestore,
|
|
67
67
|
scope,
|
|
68
68
|
id
|
|
@@ -105,7 +105,8 @@ import { CrmRecordInsightsZone } from "./crm-record-insights-zone.js";
|
|
|
105
105
|
}),
|
|
106
106
|
seed: {
|
|
107
107
|
fromCache,
|
|
108
|
-
unreadable: status === 'error'
|
|
108
|
+
unreadable: status === 'error',
|
|
109
|
+
listen
|
|
109
110
|
},
|
|
110
111
|
hostId: hostId,
|
|
111
112
|
org: org,
|
|
@@ -138,7 +139,8 @@ import { CrmRecordInsightsZone } from "./crm-record-insights-zone.js";
|
|
|
138
139
|
org: org,
|
|
139
140
|
routes: routes,
|
|
140
141
|
fromCache: fromCache,
|
|
141
|
-
unreadable: status === 'error'
|
|
142
|
+
unreadable: status === 'error',
|
|
143
|
+
listen: listen
|
|
142
144
|
}),
|
|
143
145
|
/*#__PURE__*/ _jsx(CompanyDealsCard, {
|
|
144
146
|
hostId: hostId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/components/company-detail-page.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 { CRM_COLLECTIONS, type CrmCompany } from '@aglyn/aglyn'\nimport { useFirestore, useFirestoreDoc } from '@aglyn/tenant-feature-instance'\nimport { Stack, Typography } from '@mui/material'\nimport { doc } from 'firebase/firestore'\nimport { useRouter } from 'next/navigation'\nimport { useCallback } from 'react'\nimport { CrmCreateSiteDefault } from '../hooks/use-crm-org-mount'\nimport { useCrmScope } from '../hooks/use-crm-scope'\nimport { useOrgMemberOptions } from '../hooks/use-org-member-options'\nimport { type CrmDetailPageProps, crmRoutes } from '../model/crm-routes'\nimport CompanyContactRolesCard from './company-contact-roles-card'\nimport CompanyContactsCard from './company-contacts-card'\nimport CompanyDealsCard from './company-deals-card'\nimport { CrmRecordHeader } from './crm-record-header'\nimport { RecordActivityCard } from './record-activity-card'\nimport RecordFilesCard from './record-files-card'\nimport { RecordTasksCard } from './record-tasks-card'\nimport CompanyPropertiesCard, { COMPANY_PAGE_HELP } from './company-properties-card'\nimport { RecordSharingCard } from './record-sharing-card'\nimport { CrmRecordInsightsZone } from './crm-record-insights-zone'\n\n/**\n * `/crm/companies/{companyId}` — one organization (AGL-2597).\n *\n * The record behind a row of the Companies section: its properties, its\n * people, and — as the rest of the CRM lands — its deals, its open tasks\n * and the activity logged against it. Each of those is a card in a file of\n * its own, so the agent shipping deals replaces one file and touches nothing\n * here; this page reads the ONE document every card is about and hands it\n * down.\n *\n * A route rather than a drawer because a company is what a deal, a task and\n * a contact all point at, and a link that opens a drawer on top of a list is\n * not a link anybody can paste.\n */\nexport function CompanyDetailPage(props: CrmDetailPageProps) {\n const { id, basePath, hostId, org } = props\n const routes = crmRoutes(basePath)\n const router = useRouter()\n const firestore = useFirestore()\n const crmScope = useCrmScope({ hostId, org })\n const { scope, orgId } = crmScope\n const members = useOrgMemberOptions(orgId)\n\n const {\n data: company,\n status,\n fromCache,\n } = useFirestoreDoc<CrmCompany>(\n () =>\n scope\n ? doc(firestore, scope[0], scope[1], CRM_COLLECTIONS.companies, id)\n : null,\n [firestore, scope, id],\n )\n\n const onDeleted = useCallback(\n () => router.push(routes.section('companies')),\n [router, routes],\n )\n\n if (!company) {\n /*\n * Loading and MISSING are different answers. A company that cannot be\n * read is a different situation from an empty one, and reading `status`\n * rather than the absence of data is what stops the refusal being\n * flashed on every arrival, before the org scope has resolved.\n */\n const settled = Boolean(scope) && status !== 'loading'\n return (\n <CrmRecordHeader\n kind=\"Company\"\n title={undefined}\n help={COMPANY_PAGE_HELP}\n backHref={routes.section('companies')}\n backLabel=\"Back to companies\"\n loading={!settled}\n >\n {settled ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'This company could not be loaded. It may have been deleted.'}\n </Typography>\n ) : null}\n </CrmRecordHeader>\n )\n }\n\n return (\n // A create opened from this page — a task, an activity — files under\n // the company's own site unless the reader says otherwise (AGL-2630).\n <CrmCreateSiteDefault hostId={company.hostId ?? null}>\n {/* The properties card is the record's lead card: it publishes the\n page heading and the trail, so the cards under it say what they\n hold rather than repeating the name. */}\n <Stack spacing={2}>\n <CompanyPropertiesCard\n company={{ ...company, $id: id }}\n seed={{ fromCache, unreadable: status === 'error' }}\n hostId={hostId}\n org={org}\n crmScope={crmScope}\n members={members}\n routes={routes}\n onDeleted={onDeleted}\n />\n {/* What an assistant proposes about the company (AGL-2917). */}\n <CrmRecordInsightsZone\n hostId={hostId}\n org={org as Record<string, unknown> | undefined}\n kind=\"company\"\n recordId={id}\n name={String(company.name ?? '')}\n taskLink={{ companyId: id }}\n />\n <CompanyContactsCard\n companyId={id}\n companyName={String(company.name ?? '')}\n crmScope={crmScope}\n org={org as Record<string, unknown> | undefined}\n routes={routes}\n />\n <CompanyContactRolesCard\n companyId={id}\n company={company}\n hostId={hostId}\n org={org}\n routes={routes}\n fromCache={fromCache}\n unreadable={status === 'error'}\n />\n <CompanyDealsCard\n hostId={hostId}\n org={org}\n basePath={basePath}\n companyId={id}\n companyName={String(company.name ?? '')}\n />\n <RecordTasksCard hostId={hostId} org={org} basePath={basePath} companyId={id} />\n <RecordFilesCard\n scope={scope}\n collection={CRM_COLLECTIONS.companies}\n recordId={id}\n mediaIds={company.mediaIds}\n topic=\"companies\"\n />\n {/* Where the company is visible and why, and a manager's share (AGL-3336). */}\n <RecordSharingCard\n object=\"companies\"\n id={id}\n record={company as unknown as Record<string, unknown>}\n hostId={hostId ?? null}\n orgId={orgId}\n org={org}\n viewingHostIds={crmScope.consentGroup?.hostIds}\n />\n <RecordActivityCard hostId={hostId} org={org} companyId={id} basePath={basePath} />\n </Stack>\n </CrmCreateSiteDefault>\n )\n}\nCompanyDetailPage.displayName = 'CompanyDetailPage'\n\nexport default CompanyDetailPage\n"],"names":["CRM_COLLECTIONS","useFirestore","useFirestoreDoc","Stack","Typography","doc","useRouter","useCallback","CrmCreateSiteDefault","useCrmScope","useOrgMemberOptions","crmRoutes","CompanyContactRolesCard","CompanyContactsCard","CompanyDealsCard","CrmRecordHeader","RecordActivityCard","RecordFilesCard","RecordTasksCard","CompanyPropertiesCard","COMPANY_PAGE_HELP","RecordSharingCard","CrmRecordInsightsZone","CompanyDetailPage","props","company","crmScope","id","basePath","hostId","org","routes","router","firestore","scope","orgId","members","data","status","fromCache","companies","onDeleted","push","section","settled","Boolean","kind","title","undefined","help","backHref","backLabel","loading","variant","color","spacing","$id","seed","unreadable","recordId","name","String","taskLink","companyId","companyName","collection","mediaIds","topic","object","record","viewingHostIds","consentGroup","hostIds","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SAASA,eAAe,QAAyB,eAAc;AAC/D,SAASC,YAAY,EAAEC,eAAe,QAAQ,iCAAgC;AAC9E,SAASC,KAAK,EAAEC,UAAU,QAAQ,gBAAe;AACjD,SAASC,GAAG,QAAQ,qBAAoB;AACxC,SAASC,SAAS,QAAQ,kBAAiB;AAC3C,SAASC,WAAW,QAAQ,QAAO;AACnC,SAASC,oBAAoB,QAAQ,gCAA4B;AACjE,SAASC,WAAW,QAAQ,4BAAwB;AACpD,SAASC,mBAAmB,QAAQ,qCAAiC;AACrE,SAAkCC,SAAS,QAAQ,yBAAqB;AACxE,OAAOC,6BAA6B,kCAA8B;AAClE,OAAOC,yBAAyB,6BAAyB;AACzD,OAAOC,sBAAsB,0BAAsB;AACnD,SAASC,eAAe,QAAQ,yBAAqB;AACrD,SAASC,kBAAkB,QAAQ,4BAAwB;AAC3D,OAAOC,qBAAqB,yBAAqB;AACjD,SAASC,eAAe,QAAQ,yBAAqB;AACrD,OAAOC,yBAAyBC,iBAAiB,QAAQ,+BAA2B;AACpF,SAASC,iBAAiB,QAAQ,2BAAuB;AACzD,SAASC,qBAAqB,QAAQ,gCAA4B;AAElE;;;;;;;;;;;;;CAaC,GACD,OAAO,SAASC,kBAAkBC,KAAyB;QAuDzBC,iBAqBXA,eAKOA,gBAmBAA;QAkBJC;IArHxB,MAAM,EAAEC,EAAE,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,GAAG,EAAE,GAAGN;IACtC,MAAMO,SAASpB,UAAUiB;IACzB,MAAMI,SAAS1B;IACf,MAAM2B,YAAYhC;IAClB,MAAMyB,WAAWjB,YAAY;QAAEoB;QAAQC;IAAI;IAC3C,MAAM,EAAEI,KAAK,EAAEC,KAAK,EAAE,GAAGT;I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C,IAAI,YAAZnC,iBAAgB;oBACpCC,UAAUA;oBACVI,KAAKA;oBACLC,QAAQA;;8BAEV,KAACnB;oBACCmD,WAAWpC;oBACXF,SAASA;oBACTI,QAAQA;oBACRC,KAAKA;oBACLC,QAAQA;oBACRQ,WAAWA;oBACXmB,YAAYpB,WAAW;;8BAEzB,KAACxB;oBACCe,QAAQA;oBACRC,KAAKA;oBACLF,UAAUA;oBACVmC,WAAWpC;oBACXqC,aAAaH,QAAOpC,iBAAAA,QAAQmC,IAAI,YAAZnC,iBAAgB;;8BAEtC,KAACP;oBAAgBW,QAAQA;oBAAQC,KAAKA;oBAAKF,UAAUA;oBAAUmC,WAAWpC;;8BAC1E,KAACV;oBACCiB,OAAOA;oBACP+B,YAAYjE,gBAAgBwC,SAAS;oBACrCmB,UAAUhC;oBACVuC,UAAUzC,QAAQyC,QAAQ;oBAC1BC,OAAM;;8BAGR,KAAC9C;oBACC+C,QAAO;oBACPzC,IAAIA;oBACJ0C,QAAQ5C;oBACRI,MAAM,EAAEA,iBAAAA,SAAU;oBAClBM,OAAOA;oBACPL,KAAKA;oBACLwC,cAAc,GAAE5C,yBAAAA,SAAS6C,YAAY,qBAArB7C,uBAAuB8C,OAAO;;8BAEhD,KAACxD;oBAAmBa,QAAQA;oBAAQC,KAAKA;oBAAKiC,WAAWpC;oBAAIC,UAAUA;;;;;AAI/E;AACAL,kBAAkBkD,WAAW,GAAG;AAEhC,eAAelD,kBAAiB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/components/company-detail-page.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 { CRM_COLLECTIONS, type CrmCompany } from '@aglyn/aglyn'\nimport { useFirestore, useFirestoreDoc } from '@aglyn/tenant-feature-instance'\nimport { Stack, Typography } from '@mui/material'\nimport { doc } from 'firebase/firestore'\nimport { useRouter } from 'next/navigation'\nimport { useCallback } from 'react'\nimport { CrmCreateSiteDefault } from '../hooks/use-crm-org-mount'\nimport { useCrmScope } from '../hooks/use-crm-scope'\nimport { useOrgMemberOptions } from '../hooks/use-org-member-options'\nimport { type CrmDetailPageProps, crmRoutes } from '../model/crm-routes'\nimport CompanyContactRolesCard from './company-contact-roles-card'\nimport CompanyContactsCard from './company-contacts-card'\nimport CompanyDealsCard from './company-deals-card'\nimport { CrmRecordHeader } from './crm-record-header'\nimport { RecordActivityCard } from './record-activity-card'\nimport RecordFilesCard from './record-files-card'\nimport { RecordTasksCard } from './record-tasks-card'\nimport CompanyPropertiesCard, { COMPANY_PAGE_HELP } from './company-properties-card'\nimport { RecordSharingCard } from './record-sharing-card'\nimport { CrmRecordInsightsZone } from './crm-record-insights-zone'\n\n/**\n * `/crm/companies/{companyId}` — one organization (AGL-2597).\n *\n * The record behind a row of the Companies section: its properties, its\n * people, and — as the rest of the CRM lands — its deals, its open tasks\n * and the activity logged against it. Each of those is a card in a file of\n * its own, so the agent shipping deals replaces one file and touches nothing\n * here; this page reads the ONE document every card is about and hands it\n * down.\n *\n * A route rather than a drawer because a company is what a deal, a task and\n * a contact all point at, and a link that opens a drawer on top of a list is\n * not a link anybody can paste.\n */\nexport function CompanyDetailPage(props: CrmDetailPageProps) {\n const { id, basePath, hostId, org } = props\n const routes = crmRoutes(basePath)\n const router = useRouter()\n const firestore = useFirestore()\n const crmScope = useCrmScope({ hostId, org })\n const { scope, orgId } = crmScope\n const members = useOrgMemberOptions(orgId)\n\n const {\n data: company,\n status,\n fromCache,\n listen,\n } = useFirestoreDoc<CrmCompany>(\n () =>\n scope\n ? doc(firestore, scope[0], scope[1], CRM_COLLECTIONS.companies, id)\n : null,\n [firestore, scope, id],\n )\n\n const onDeleted = useCallback(\n () => router.push(routes.section('companies')),\n [router, routes],\n )\n\n if (!company) {\n /*\n * Loading and MISSING are different answers. A company that cannot be\n * read is a different situation from an empty one, and reading `status`\n * rather than the absence of data is what stops the refusal being\n * flashed on every arrival, before the org scope has resolved.\n */\n const settled = Boolean(scope) && status !== 'loading'\n return (\n <CrmRecordHeader\n kind=\"Company\"\n title={undefined}\n help={COMPANY_PAGE_HELP}\n backHref={routes.section('companies')}\n backLabel=\"Back to companies\"\n loading={!settled}\n >\n {settled ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'This company could not be loaded. It may have been deleted.'}\n </Typography>\n ) : null}\n </CrmRecordHeader>\n )\n }\n\n return (\n // A create opened from this page — a task, an activity — files under\n // the company's own site unless the reader says otherwise (AGL-2630).\n <CrmCreateSiteDefault hostId={company.hostId ?? null}>\n {/* The properties card is the record's lead card: it publishes the\n page heading and the trail, so the cards under it say what they\n hold rather than repeating the name. */}\n <Stack spacing={2}>\n <CompanyPropertiesCard\n company={{ ...company, $id: id }}\n seed={{ fromCache, unreadable: status === 'error', listen }}\n hostId={hostId}\n org={org}\n crmScope={crmScope}\n members={members}\n routes={routes}\n onDeleted={onDeleted}\n />\n {/* What an assistant proposes about the company (AGL-2917). */}\n <CrmRecordInsightsZone\n hostId={hostId}\n org={org as Record<string, unknown> | undefined}\n kind=\"company\"\n recordId={id}\n name={String(company.name ?? '')}\n taskLink={{ companyId: id }}\n />\n <CompanyContactsCard\n companyId={id}\n companyName={String(company.name ?? '')}\n crmScope={crmScope}\n org={org as Record<string, unknown> | undefined}\n routes={routes}\n />\n <CompanyContactRolesCard\n companyId={id}\n company={company}\n hostId={hostId}\n org={org}\n routes={routes}\n fromCache={fromCache}\n unreadable={status === 'error'}\n listen={listen}\n />\n <CompanyDealsCard\n hostId={hostId}\n org={org}\n basePath={basePath}\n companyId={id}\n companyName={String(company.name ?? '')}\n />\n <RecordTasksCard hostId={hostId} org={org} basePath={basePath} companyId={id} />\n <RecordFilesCard\n scope={scope}\n collection={CRM_COLLECTIONS.companies}\n recordId={id}\n mediaIds={company.mediaIds}\n topic=\"companies\"\n />\n {/* Where the company is visible and why, and a manager's share (AGL-3336). */}\n <RecordSharingCard\n object=\"companies\"\n id={id}\n record={company as unknown as Record<string, unknown>}\n hostId={hostId ?? null}\n orgId={orgId}\n org={org}\n viewingHostIds={crmScope.consentGroup?.hostIds}\n />\n <RecordActivityCard hostId={hostId} org={org} companyId={id} basePath={basePath} />\n </Stack>\n </CrmCreateSiteDefault>\n )\n}\nCompanyDetailPage.displayName = 'CompanyDetailPage'\n\nexport default CompanyDetailPage\n"],"names":["CRM_COLLECTIONS","useFirestore","useFirestoreDoc","Stack","Typography","doc","useRouter","useCallback","CrmCreateSiteDefault","useCrmScope","useOrgMemberOptions","crmRoutes","CompanyContactRolesCard","CompanyContactsCard","CompanyDealsCard","CrmRecordHeader","RecordActivityCard","RecordFilesCard","RecordTasksCard","CompanyPropertiesCard","COMPANY_PAGE_HELP","RecordSharingCard","CrmRecordInsightsZone","CompanyDetailPage","props","company","crmScope","id","basePath","hostId","org","routes","router","firestore","scope","orgId","members","data","status","fromCache","listen","companies","onDeleted","push","section","settled","Boolean","kind","title","undefined","help","backHref","backLabel","loading","variant","color","spacing","$id","seed","unreadable","recordId","name","String","taskLink","companyId","companyName","collection","mediaIds","topic","object","record","viewingHostIds","consentGroup","hostIds","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SAASA,eAAe,QAAyB,eAAc;AAC/D,SAASC,YAAY,EAAEC,eAAe,QAAQ,iCAAgC;AAC9E,SAASC,KAAK,EAAEC,UAAU,QAAQ,gBAAe;AACjD,SAASC,GAAG,QAAQ,qBAAoB;AACxC,SAASC,SAAS,QAAQ,kBAAiB;AAC3C,SAASC,WAAW,QAAQ,QAAO;AACnC,SAASC,oBAAoB,QAAQ,gC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AQC,KAAKA;oBAAKF,UAAUA;oBAAUoC,WAAWrC;;8BAC1E,KAACV;oBACCiB,OAAOA;oBACPgC,YAAYlE,gBAAgByC,SAAS;oBACrCmB,UAAUjC;oBACVwC,UAAU1C,QAAQ0C,QAAQ;oBAC1BC,OAAM;;8BAGR,KAAC/C;oBACCgD,QAAO;oBACP1C,IAAIA;oBACJ2C,QAAQ7C;oBACRI,MAAM,EAAEA,iBAAAA,SAAU;oBAClBM,OAAOA;oBACPL,KAAKA;oBACLyC,cAAc,GAAE7C,yBAAAA,SAAS8C,YAAY,qBAArB9C,uBAAuB+C,OAAO;;8BAEhD,KAACzD;oBAAmBa,QAAQA;oBAAQC,KAAKA;oBAAKkC,WAAWrC;oBAAIC,UAAUA;;;;;AAI/E;AACAL,kBAAkBmD,WAAW,GAAG;AAEhC,eAAenD,kBAAiB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type AglynOrgBilling, type CrmCompany } from '@aglyn/aglyn';
|
|
2
|
+
import { type ListenHandle } from '@aglyn/tenant-feature-instance';
|
|
2
3
|
import type { OrgMemberOptions } from '../hooks/use-org-member-options';
|
|
3
4
|
export interface CompanyEditDrawerProps {
|
|
4
5
|
open: boolean;
|
|
@@ -33,6 +34,8 @@ export interface CompanyEditDrawerProps {
|
|
|
33
34
|
seed?: {
|
|
34
35
|
fromCache: boolean;
|
|
35
36
|
unreadable: boolean;
|
|
37
|
+
/** The company's listener, so a save waits on that read alone (AGL-4135). */
|
|
38
|
+
listen?: ListenHandle | null;
|
|
36
39
|
};
|
|
37
40
|
/**
|
|
38
41
|
* The team, for the owner picker.
|
|
@@ -250,7 +250,8 @@ const ADDRESS_FIELDS = [
|
|
|
250
250
|
const verdict = await writeGuardedBySeed({
|
|
251
251
|
subject: 'company',
|
|
252
252
|
unreadable: (_ref1 = seed == null ? void 0 : seed.unreadable) != null ? _ref1 : false,
|
|
253
|
-
fromCache: (_ref2 = seed == null ? void 0 : seed.fromCache) != null ? _ref2 : false
|
|
253
|
+
fromCache: (_ref2 = seed == null ? void 0 : seed.fromCache) != null ? _ref2 : false,
|
|
254
|
+
listen: seed == null ? void 0 : seed.listen
|
|
254
255
|
}, async ()=>{
|
|
255
256
|
const cleared = Object.fromEntries(result.cleared.map((field)=>[
|
|
256
257
|
field,
|