@aglyn/plugins-crm 1.0.0-beta.200 → 1.0.0-beta.201

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/package.json +13 -13
  2. package/src/lib/components/activity-list.d.ts +36 -5
  3. package/src/lib/components/activity-list.js +159 -137
  4. package/src/lib/components/activity-list.js.map +1 -1
  5. package/src/lib/components/activity-timeline.d.ts +84 -0
  6. package/src/lib/components/activity-timeline.js +224 -0
  7. package/src/lib/components/activity-timeline.js.map +1 -0
  8. package/src/lib/components/company-properties-card.js +53 -36
  9. package/src/lib/components/company-properties-card.js.map +1 -1
  10. package/src/lib/components/contact-associations-card.d.ts +3 -2
  11. package/src/lib/components/contact-associations-card.js +12 -12
  12. package/src/lib/components/contact-associations-card.js.map +1 -1
  13. package/src/lib/components/contact-detail-page.d.ts +4 -3
  14. package/src/lib/components/contact-detail-page.js +4 -10
  15. package/src/lib/components/contact-detail-page.js.map +1 -1
  16. package/src/lib/components/contact-properties-card.d.ts +21 -4
  17. package/src/lib/components/contact-properties-card.js +129 -29
  18. package/src/lib/components/contact-properties-card.js.map +1 -1
  19. package/src/lib/components/contact-timeline-card.d.ts +12 -6
  20. package/src/lib/components/contact-timeline-card.js +132 -174
  21. package/src/lib/components/contact-timeline-card.js.map +1 -1
  22. package/src/lib/components/contacts-section.js +197 -198
  23. package/src/lib/components/contacts-section.js.map +1 -1
  24. package/src/lib/components/crm-email-state-chip.js +4 -1
  25. package/src/lib/components/crm-email-state-chip.js.map +1 -1
  26. package/src/lib/components/deal-products-card.js +15 -13
  27. package/src/lib/components/deal-products-card.js.map +1 -1
  28. package/src/lib/components/deal-properties-card.js +7 -0
  29. package/src/lib/components/deal-properties-card.js.map +1 -1
  30. package/src/lib/components/deal-stage-card.js +31 -29
  31. package/src/lib/components/deal-stage-card.js.map +1 -1
  32. package/src/lib/components/deals-section.js +9 -14
  33. package/src/lib/components/deals-section.js.map +1 -1
  34. package/src/lib/components/fields-section.d.ts +4 -0
  35. package/src/lib/components/fields-section.js +368 -154
  36. package/src/lib/components/fields-section.js.map +1 -1
  37. package/src/lib/components/form-contact-fields-card.js +24 -20
  38. package/src/lib/components/form-contact-fields-card.js.map +1 -1
  39. package/src/lib/components/lead-campaigns-card.d.ts +1 -1
  40. package/src/lib/components/lead-campaigns-card.js +32 -35
  41. package/src/lib/components/lead-campaigns-card.js.map +1 -1
  42. package/src/lib/components/lead-properties-card.d.ts +14 -6
  43. package/src/lib/components/lead-properties-card.js +317 -313
  44. package/src/lib/components/lead-properties-card.js.map +1 -1
  45. package/src/lib/components/lead-surfaces-note.js +13 -2
  46. package/src/lib/components/lead-surfaces-note.js.map +1 -1
  47. package/src/lib/components/linked-deals-card.js +12 -10
  48. package/src/lib/components/linked-deals-card.js.map +1 -1
  49. package/src/lib/components/recent-activity-feed.d.ts +12 -8
  50. package/src/lib/components/recent-activity-feed.js +54 -29
  51. package/src/lib/components/recent-activity-feed.js.map +1 -1
  52. package/src/lib/components/record-activity-card.d.ts +4 -2
  53. package/src/lib/components/record-activity-card.js +29 -11
  54. package/src/lib/components/record-activity-card.js.map +1 -1
  55. package/src/lib/components/reports/activity-card.js +18 -12
  56. package/src/lib/components/reports/activity-card.js.map +1 -1
  57. package/src/lib/components/reports/lead-funnel-card.js +47 -37
  58. package/src/lib/components/reports/lead-funnel-card.js.map +1 -1
  59. package/src/lib/components/reports/pipeline-card.js +22 -16
  60. package/src/lib/components/reports/pipeline-card.js.map +1 -1
  61. package/src/lib/components/reports/report-export.d.ts +4 -11
  62. package/src/lib/components/reports/report-export.js +16 -33
  63. package/src/lib/components/reports/report-export.js.map +1 -1
  64. package/src/lib/components/reports/source-conversion-card.js +18 -12
  65. package/src/lib/components/reports/source-conversion-card.js.map +1 -1
  66. package/src/lib/components/reports/tasks-card.js +35 -25
  67. package/src/lib/components/reports/tasks-card.js.map +1 -1
  68. package/src/lib/components/tasks-section.js +23 -23
  69. package/src/lib/components/tasks-section.js.map +1 -1
  70. package/src/lib/constants/field-list-query.d.ts +23 -0
  71. package/src/lib/constants/field-list-query.js +80 -0
  72. package/src/lib/constants/field-list-query.js.map +1 -0
  73. package/src/lib/model/lead-filters.d.ts +1 -1
  74. package/src/lib/server/capture-contact.js +7 -5
  75. package/src/lib/server/capture-contact.js.map +1 -1
  76. package/src/lib/components/contact-custom-fields-card.d.ts +0 -39
  77. package/src/lib/components/contact-custom-fields-card.js +0 -204
  78. package/src/lib/components/contact-custom-fields-card.js.map +0 -1
@@ -14,18 +14,21 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */ 'use client';
17
+ import { _ as _extends } from "@swc/helpers/_/_extends";
17
18
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
18
19
  import * as Aglyn from "@aglyn/aglyn";
19
20
  import { CONTACT_SOURCE_LABELS, pluginDocsHelp } from "@aglyn/aglyn";
20
21
  import { mdiAccountCircleOutline, mdiAccountEditOutline, mdiAccountPlusOutline, mdiApi, mdiBullhornOutline, mdiCalendarCheckOutline, mdiCartOutline, mdiEmailNewsletter, mdiFileImportOutline, mdiFormSelect } from "@aglyn/shared-data-mdi";
21
22
  import { AppLink, CardDisplay, MdiIcon } from "@aglyn/shared-ui-jsx";
22
23
  import EmptyStateComponent from "@aglyn/shared-ui-jsx/components/empty-state.component";
24
+ import { ListPagination } from "@aglyn/shared-ui-jsx/components/list-pagination.component";
23
25
  import { Button, Chip, Stack, Tooltip, Typography } from "@mui/material";
24
26
  import { useParams } from "next/navigation";
25
27
  import { useCallback, useMemo, useState } from "react";
26
28
  import { contactPrimaryGroup } from "../model/contact-record.js";
27
29
  import { ActivityRow } from "./activity-list.js";
28
30
  import { useActivityScope, useActivityWindow, useCanEditActivity } from "./activity-queries.js";
31
+ import { TimelineEntry, TimelineExpandAllButton, useTimelineExpansion, useTimelinePages } from "./activity-timeline.js";
29
32
  import { CrmSuiteLockedButton } from "./crm-suite-lock.js";
30
33
  import { LogActivityDialog } from "./log-activity-dialog.js";
31
34
  import { useContactCampaignEmails } from "./use-contact-campaign-emails.js";
@@ -52,6 +55,8 @@ import { useContactCampaignEmails } from "./use-contact-campaign-emails.js";
52
55
  * contacts drawer draws it: the summary is the sentence the door wrote, the
53
56
  * path is a fact the door recorded, and a long path on the sentence's line
54
57
  * pushes out the thing the row is about.
58
+ *
59
+ * Everything it holds fits the collapsed row, so it has nothing to open.
55
60
  */ function CapturedRow(props) {
56
61
  var _CONTACT_SOURCE_LABELS_source, _interaction_summary, _Aglyn_INTERACTION_LINK_LABELS_source;
57
62
  const { interaction, nowMs, href } = props;
@@ -59,78 +64,50 @@ import { useContactCampaignEmails } from "./use-contact-campaign-emails.js";
59
64
  const label = (_CONTACT_SOURCE_LABELS_source = CONTACT_SOURCE_LABELS[source]) != null ? _CONTACT_SOURCE_LABELS_source : String(source);
60
65
  const icon = SOURCE_ICONS[source];
61
66
  const when = new Date(interaction.atMs);
62
- return /*#__PURE__*/ _jsxs(Stack, {
63
- direction: "row",
64
- spacing: 1.5,
65
- sx: {
66
- alignItems: 'flex-start'
67
- },
68
- children: [
69
- /*#__PURE__*/ _jsx(Stack, {
70
- sx: {
71
- color: 'text.secondary',
72
- pt: 0.25,
73
- fontSize: (theme)=>theme.typography.h6.fontSize
74
- },
75
- children: /*#__PURE__*/ _jsx(MdiIcon, {
76
- path: icon == null ? void 0 : icon.path
67
+ return /*#__PURE__*/ _jsx(TimelineEntry, {
68
+ icon: /*#__PURE__*/ _jsx(MdiIcon, {
69
+ path: icon == null ? void 0 : icon.path
70
+ }),
71
+ chips: /*#__PURE__*/ _jsxs(_Fragment, {
72
+ children: [
73
+ /*#__PURE__*/ _jsx(Chip, {
74
+ label: label,
75
+ size: "small"
76
+ }),
77
+ /*#__PURE__*/ _jsx(Chip, {
78
+ label: "Captured",
79
+ size: "small",
80
+ variant: "outlined"
77
81
  })
78
- }),
79
- /*#__PURE__*/ _jsxs(Stack, {
80
- spacing: 0.5,
81
- sx: {
82
- flex: 1,
83
- minWidth: 0
84
- },
85
- children: [
86
- /*#__PURE__*/ _jsxs(Stack, {
87
- direction: "row",
88
- spacing: 1,
89
- sx: {
90
- alignItems: 'center',
91
- flexWrap: 'wrap',
92
- rowGap: 0.5
93
- },
94
- children: [
95
- /*#__PURE__*/ _jsx(Chip, {
96
- label: label,
97
- size: "small"
98
- }),
99
- /*#__PURE__*/ _jsx(Chip, {
100
- label: "Captured",
101
- size: "small",
102
- variant: "outlined"
103
- })
104
- ]
105
- }),
106
- /*#__PURE__*/ _jsx(Typography, {
107
- variant: "body2",
108
- children: (_interaction_summary = interaction.summary) != null ? _interaction_summary : label
109
- }),
110
- /*#__PURE__*/ _jsx(Tooltip, {
111
- title: when.toLocaleString(),
112
- children: /*#__PURE__*/ _jsx(Typography, {
113
- variant: "caption",
114
- color: "text.secondary",
115
- sx: {
116
- alignSelf: 'flex-start'
117
- },
118
- children: interaction.path ? `${Aglyn.activityTimeLabel(interaction.atMs, nowMs)} · ${interaction.path}` : Aglyn.activityTimeLabel(interaction.atMs, nowMs)
119
- })
120
- }),
121
- href ? /*#__PURE__*/ _jsx(Typography, {
82
+ ]
83
+ }),
84
+ title: (_interaction_summary = interaction.summary) != null ? _interaction_summary : label,
85
+ meta: /*#__PURE__*/ _jsxs(Stack, {
86
+ direction: "row",
87
+ spacing: 1,
88
+ sx: {
89
+ alignItems: 'baseline',
90
+ flexWrap: 'wrap',
91
+ rowGap: 0.25
92
+ },
93
+ children: [
94
+ /*#__PURE__*/ _jsx(Tooltip, {
95
+ title: when.toLocaleString(),
96
+ children: /*#__PURE__*/ _jsx(Typography, {
122
97
  variant: "caption",
123
- sx: {
124
- alignSelf: 'flex-start'
125
- },
126
- children: /*#__PURE__*/ _jsx(AppLink, {
127
- href: href,
128
- children: (_Aglyn_INTERACTION_LINK_LABELS_source = Aglyn.INTERACTION_LINK_LABELS[source]) != null ? _Aglyn_INTERACTION_LINK_LABELS_source : 'Open'
129
- })
130
- }) : null
131
- ]
132
- })
133
- ]
98
+ color: "text.secondary",
99
+ children: interaction.path ? `${Aglyn.activityTimeLabel(interaction.atMs, nowMs)} · ${interaction.path}` : Aglyn.activityTimeLabel(interaction.atMs, nowMs)
100
+ })
101
+ }),
102
+ href ? /*#__PURE__*/ _jsx(Typography, {
103
+ variant: "caption",
104
+ children: /*#__PURE__*/ _jsx(AppLink, {
105
+ href: href,
106
+ children: (_Aglyn_INTERACTION_LINK_LABELS_source = Aglyn.INTERACTION_LINK_LABELS[source]) != null ? _Aglyn_INTERACTION_LINK_LABELS_source : 'Open'
107
+ })
108
+ }) : null
109
+ ]
110
+ })
134
111
  });
135
112
  }
136
113
  CapturedRow.displayName = 'CapturedRow';
@@ -144,80 +121,52 @@ CapturedRow.displayName = 'CapturedRow';
144
121
  * the others say "Captured" and "Logged". The name links to the email's own
145
122
  * report when the page can address it; an email the team has deleted, or
146
123
  * one a sibling site sent, keeps its name and loses the link.
124
+ *
125
+ * The delivery line stays on the collapsed row beside the name, so it has
126
+ * nothing to open.
147
127
  */ function CampaignEmailRow(props) {
148
128
  var _ref, _email_campaignName;
149
129
  const { email, href, nowMs } = props;
150
130
  const name = (_ref = (_email_campaignName = email.campaignName) != null ? _email_campaignName : email.subject) != null ? _ref : 'Campaign email';
151
131
  const summary = Aglyn.campaignEmailSummary(email).join(' · ');
152
132
  const when = new Date(email.sentAtMs);
153
- return /*#__PURE__*/ _jsxs(Stack, {
154
- direction: "row",
155
- spacing: 1.5,
156
- sx: {
157
- alignItems: 'flex-start'
158
- },
159
- children: [
160
- /*#__PURE__*/ _jsx(Stack, {
161
- sx: {
162
- color: 'text.secondary',
163
- pt: 0.25,
164
- fontSize: (theme)=>theme.typography.h6.fontSize
165
- },
166
- children: /*#__PURE__*/ _jsx(MdiIcon, {
167
- path: mdiBullhornOutline.path
133
+ return /*#__PURE__*/ _jsx(TimelineEntry, {
134
+ icon: /*#__PURE__*/ _jsx(MdiIcon, {
135
+ path: mdiBullhornOutline.path
136
+ }),
137
+ chips: /*#__PURE__*/ _jsxs(_Fragment, {
138
+ children: [
139
+ /*#__PURE__*/ _jsx(Chip, {
140
+ label: "Campaign",
141
+ size: "small"
142
+ }),
143
+ /*#__PURE__*/ _jsx(Chip, {
144
+ label: "Sent",
145
+ size: "small",
146
+ variant: "outlined"
168
147
  })
169
- }),
170
- /*#__PURE__*/ _jsxs(Stack, {
171
- spacing: 0.5,
148
+ ]
149
+ }),
150
+ title: /*#__PURE__*/ _jsxs(_Fragment, {
151
+ children: [
152
+ href ? /*#__PURE__*/ _jsx(AppLink, {
153
+ href: href,
154
+ children: name
155
+ }) : name,
156
+ ` · ${summary}`
157
+ ]
158
+ }),
159
+ meta: /*#__PURE__*/ _jsx(Tooltip, {
160
+ title: when.toLocaleString(),
161
+ children: /*#__PURE__*/ _jsx(Typography, {
162
+ variant: "caption",
163
+ color: "text.secondary",
172
164
  sx: {
173
- flex: 1,
174
- minWidth: 0
165
+ alignSelf: 'flex-start'
175
166
  },
176
- children: [
177
- /*#__PURE__*/ _jsxs(Stack, {
178
- direction: "row",
179
- spacing: 1,
180
- sx: {
181
- alignItems: 'center',
182
- flexWrap: 'wrap',
183
- rowGap: 0.5
184
- },
185
- children: [
186
- /*#__PURE__*/ _jsx(Chip, {
187
- label: "Campaign",
188
- size: "small"
189
- }),
190
- /*#__PURE__*/ _jsx(Chip, {
191
- label: "Sent",
192
- size: "small",
193
- variant: "outlined"
194
- })
195
- ]
196
- }),
197
- /*#__PURE__*/ _jsxs(Typography, {
198
- variant: "body2",
199
- children: [
200
- href ? /*#__PURE__*/ _jsx(AppLink, {
201
- href: href,
202
- children: name
203
- }) : name,
204
- ` · ${summary}`
205
- ]
206
- }),
207
- /*#__PURE__*/ _jsx(Tooltip, {
208
- title: when.toLocaleString(),
209
- children: /*#__PURE__*/ _jsx(Typography, {
210
- variant: "caption",
211
- color: "text.secondary",
212
- sx: {
213
- alignSelf: 'flex-start'
214
- },
215
- children: email.subject && email.subject !== name ? `${Aglyn.activityTimeLabel(email.sentAtMs, nowMs)} · ${email.subject}` : Aglyn.activityTimeLabel(email.sentAtMs, nowMs)
216
- })
217
- })
218
- ]
167
+ children: email.subject && email.subject !== name ? `${Aglyn.activityTimeLabel(email.sentAtMs, nowMs)} · ${email.subject}` : Aglyn.activityTimeLabel(email.sentAtMs, nowMs)
219
168
  })
220
- ]
169
+ })
221
170
  });
222
171
  }
223
172
  CampaignEmailRow.displayName = 'CampaignEmailRow';
@@ -247,12 +196,18 @@ CampaignEmailRow.displayName = 'CampaignEmailRow';
247
196
  * — THIS group's facet, filtered to the sites the group may see, the same
248
197
  * projection the contacts list makes — and costs no read. The logged side is
249
198
  * the bounded listener every activity surface uses, filtered to this
250
- * contact, with a foot for the next hundred. The campaign side is one
251
- * request to `crm/contact-email-history`, which reads down this person's
252
- * own delivery log, capped, and never a campaign's recipients. The facet's
253
- * history is capped at fifty by the platform, so past the window the stream
254
- * is the logged side alone; the foot says as much by asking for "more
255
- * activity" rather than "more history".
199
+ * contact, a hundred at a time. The campaign side is one request to
200
+ * `crm/contact-email-history`, which reads down this person's own delivery
201
+ * log, capped, and never a campaign's recipients. The facet's history is
202
+ * capped at fifty by the platform, so past the window the stream is the
203
+ * logged side alone.
204
+ *
205
+ * ## How it reads
206
+ *
207
+ * Every entry is a collapsed row that opens in place, paged by the
208
+ * console's footer over the merged stream; a page turned past the logged
209
+ * window widens it by the next hundred. **Expand all** and **Log activity**
210
+ * sit in the card header, and edit and delete stay on the entry they act on.
256
211
  */ export function ContactTimelineCard(props) {
257
212
  const { hostId, org, contactId, contact, campaignHref, suiteLocked = false } = props;
258
213
  const scope = useActivityScope(hostId, org);
@@ -334,6 +289,24 @@ CampaignEmailRow.displayName = 'CampaignEmailRow';
334
289
  size: "small",
335
290
  variant: "outlined"
336
291
  }), []);
292
+ const expansion = useTimelineExpansion();
293
+ const pages = useTimelinePages(entries.length, {
294
+ hasMore: activities.hasMore,
295
+ showMore: activities.showMore,
296
+ loading: activities.status === 'loading'
297
+ });
298
+ const logButton = suiteLocked ? /*#__PURE__*/ _jsx(CrmSuiteLockedButton, {
299
+ variant: "contained",
300
+ color: "primary",
301
+ children: 'Log activity'
302
+ }) : /*#__PURE__*/ _jsx(Button, {
303
+ size: "small",
304
+ variant: "contained",
305
+ color: "primary",
306
+ onClick: openNew,
307
+ disabled: !activities.ready,
308
+ children: 'Log activity'
309
+ });
337
310
  return /*#__PURE__*/ _jsxs(_Fragment, {
338
311
  children: [
339
312
  /*#__PURE__*/ _jsx(CardDisplay, {
@@ -341,18 +314,19 @@ CampaignEmailRow.displayName = 'CampaignEmailRow';
341
314
  help: pluginDocsHelp('contactActivities', {
342
315
  anchor: '#four-kinds-of-history'
343
316
  }),
344
- actions: suiteLocked ? /*#__PURE__*/ _jsx(CrmSuiteLockedButton, {
345
- variant: "contained",
346
- color: "primary",
347
- children: 'Log activity'
348
- }) : /*#__PURE__*/ _jsx(Button, {
349
- size: "small",
350
- variant: "contained",
351
- color: "primary",
352
- onClick: openNew,
353
- disabled: !activities.ready,
354
- children: 'Log activity'
355
- }),
317
+ HeaderProps: {
318
+ action: /*#__PURE__*/ _jsxs(Stack, {
319
+ direction: "row",
320
+ spacing: 1,
321
+ children: [
322
+ /*#__PURE__*/ _jsx(TimelineExpandAllButton, {
323
+ expansion: expansion,
324
+ disabled: !entries.length
325
+ }),
326
+ logButton
327
+ ]
328
+ })
329
+ },
356
330
  contentGutterX: true,
357
331
  contentGutterY: true,
358
332
  children: /*#__PURE__*/ _jsxs(Stack, {
@@ -380,19 +354,8 @@ CampaignEmailRow.displayName = 'CampaignEmailRow';
380
354
  compact: true,
381
355
  label: 'No history yet',
382
356
  description: 'What this person does on the site, the campaigns they are sent, and what you log about them, shows here.',
383
- action: suiteLocked ? /*#__PURE__*/ _jsx(CrmSuiteLockedButton, {
384
- variant: "contained",
385
- color: "primary",
386
- children: 'Log activity'
387
- }) : /*#__PURE__*/ _jsx(Button, {
388
- size: "small",
389
- variant: "contained",
390
- color: "primary",
391
- onClick: openNew,
392
- disabled: !activities.ready,
393
- children: 'Log activity'
394
- })
395
- }) : entries.map((entry)=>entry.kind === 'captured' ? /*#__PURE__*/ _jsx(CapturedRow, {
357
+ action: logButton
358
+ }) : pages.slice(entries).map((entry)=>entry.kind === 'captured' ? /*#__PURE__*/ _jsx(CapturedRow, {
396
359
  interaction: entry.interaction,
397
360
  nowMs: nowMs,
398
361
  href: interactionHref(entry.interaction)
@@ -406,16 +369,11 @@ CampaignEmailRow.displayName = 'CampaignEmailRow';
406
369
  onEdit: openEdit,
407
370
  subject: loggedChip,
408
371
  nowMs: nowMs,
409
- editable: !suiteLocked && canEdit(entry.activity)
372
+ editable: !suiteLocked && canEdit(entry.activity),
373
+ expanded: expansion.isExpanded(entry.key),
374
+ onToggle: ()=>expansion.toggle(entry.key)
410
375
  }, entry.key)),
411
- activities.hasMore ? /*#__PURE__*/ _jsx(Button, {
412
- size: "small",
413
- onClick: activities.showMore,
414
- sx: {
415
- alignSelf: 'flex-start'
416
- },
417
- children: 'Show more activity'
418
- }) : null
376
+ entries.length ? /*#__PURE__*/ _jsx(ListPagination, _extends({}, pages.footer)) : null
419
377
  ]
420
378
  })
421
379
  }),
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/components/contact-timeline-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 * as Aglyn from '@aglyn/aglyn'\nimport type {\n ContactCampaignEmail,\n ContactInteraction,\n ContactSource,\n CrmActivityRow,\n} from '@aglyn/aglyn'\nimport { CONTACT_SOURCE_LABELS, pluginDocsHelp } from '@aglyn/aglyn'\nimport {\n mdiAccountCircleOutline,\n mdiAccountEditOutline,\n mdiAccountPlusOutline,\n mdiApi,\n mdiBullhornOutline,\n mdiCalendarCheckOutline,\n mdiCartOutline,\n mdiEmailNewsletter,\n mdiFileImportOutline,\n mdiFormSelect,\n} from '@aglyn/shared-data-mdi'\nimport { AppLink, CardDisplay, MdiIcon } from '@aglyn/shared-ui-jsx'\nimport EmptyStateComponent from '@aglyn/shared-ui-jsx/components/empty-state.component'\nimport { Button, Chip, Stack, Tooltip, Typography } from '@mui/material'\nimport { useParams } from 'next/navigation'\nimport { useCallback, useMemo, useState } from 'react'\nimport { contactPrimaryGroup } from '../model/contact-record'\nimport { ActivityRow } from './activity-list'\nimport {\n type ActivityRecordLink,\n type CrmOrg,\n useActivityScope,\n useActivityWindow,\n useCanEditActivity,\n} from './activity-queries'\nimport { CrmSuiteLockedButton } from './crm-suite-lock'\nimport { LogActivityDialog } from './log-activity-dialog'\nimport { useContactCampaignEmails } from './use-contact-campaign-emails'\n\n/**\n * One glyph per capture door. Typed against the source union so a door added\n * to it cannot render as the placeholder glyph.\n */\nconst SOURCE_ICONS: Record<ContactSource, { path: string }> = {\n form: mdiFormSelect,\n member: mdiAccountPlusOutline,\n order: mdiCartOutline,\n booking: mdiCalendarCheckOutline,\n newsletter: mdiEmailNewsletter,\n api: mdiApi,\n manual: mdiAccountEditOutline,\n import: mdiFileImportOutline,\n account: mdiAccountCircleOutline,\n}\n\n/**\n * One thing the platform recorded: the door it came through, what the door\n * wrote, when, and the page the person was on.\n *\n * Read-only by nature — nobody logged it, so nobody edits it. The entry\n * point sits beside the timestamp rather than in the summary, the way the\n * contacts drawer draws it: the summary is the sentence the door wrote, the\n * path is a fact the door recorded, and a long path on the sentence's line\n * pushes out the thing the row is about.\n */\nfunction CapturedRow(props: {\n interaction: ContactInteraction\n nowMs: number\n /** The console page the door's record is read on, when it left one. */\n href: string | null\n}) {\n const { interaction, nowMs, href } = props\n const source = interaction.type\n const label = CONTACT_SOURCE_LABELS[source] ?? String(source)\n const icon = SOURCE_ICONS[source]\n const when = new Date(interaction.atMs)\n return (\n <Stack direction=\"row\" spacing={1.5} sx={{ alignItems: 'flex-start' }}>\n <Stack\n sx={{\n color: 'text.secondary',\n pt: 0.25,\n fontSize: (theme) => theme.typography.h6.fontSize,\n }}\n >\n <MdiIcon path={icon?.path} />\n </Stack>\n <Stack spacing={0.5} sx={{ flex: 1, minWidth: 0 }}>\n <Stack\n direction=\"row\"\n spacing={1}\n sx={{ alignItems: 'center', flexWrap: 'wrap', rowGap: 0.5 }}\n >\n <Chip label={label} size=\"small\" />\n <Chip label=\"Captured\" size=\"small\" variant=\"outlined\" />\n </Stack>\n <Typography variant=\"body2\">\n {interaction.summary ?? label}\n </Typography>\n <Tooltip title={when.toLocaleString()}>\n <Typography\n variant=\"caption\"\n color=\"text.secondary\"\n sx={{ alignSelf: 'flex-start' }}\n >\n {interaction.path\n ? `${Aglyn.activityTimeLabel(interaction.atMs, nowMs)} · ${interaction.path}`\n : Aglyn.activityTimeLabel(interaction.atMs, nowMs)}\n </Typography>\n </Tooltip>\n {/*\n The record the door left, where the console reads it (AGL-2622):\n the submission in the Inbox reader, the order in its dialog. A door\n that left nothing to open — a newsletter opt-in, an import — has no\n link, and the caption above is the whole entry.\n */}\n {href ? (\n <Typography variant=\"caption\" sx={{ alignSelf: 'flex-start' }}>\n <AppLink href={href}>\n {Aglyn.INTERACTION_LINK_LABELS[source] ?? 'Open'}\n </AppLink>\n </Typography>\n ) : null}\n </Stack>\n </Stack>\n )\n}\nCapturedRow.displayName = 'CapturedRow'\n\n/**\n * One campaign email the platform sent this person (AGL-2616): which email,\n * and what became of it — `sent · delivered · opened ×2 · clicked`.\n *\n * Read-only like a captured row, and drawn apart from BOTH the captured and\n * the logged rows: its glyph is the campaign's, never the envelope a logged\n * `email` activity carries, and its chips say \"Campaign\" and \"Sent\" where\n * the others say \"Captured\" and \"Logged\". The name links to the email's own\n * report when the page can address it; an email the team has deleted, or\n * one a sibling site sent, keeps its name and loses the link.\n */\nfunction CampaignEmailRow(props: {\n email: ContactCampaignEmail\n href: string | null\n nowMs: number\n}) {\n const { email, href, nowMs } = props\n const name = email.campaignName ?? email.subject ?? 'Campaign email'\n const summary = Aglyn.campaignEmailSummary(email).join(' · ')\n const when = new Date(email.sentAtMs)\n return (\n <Stack direction=\"row\" spacing={1.5} sx={{ alignItems: 'flex-start' }}>\n <Stack\n sx={{\n color: 'text.secondary',\n pt: 0.25,\n fontSize: (theme) => theme.typography.h6.fontSize,\n }}\n >\n <MdiIcon path={mdiBullhornOutline.path} />\n </Stack>\n <Stack spacing={0.5} sx={{ flex: 1, minWidth: 0 }}>\n <Stack\n direction=\"row\"\n spacing={1}\n sx={{ alignItems: 'center', flexWrap: 'wrap', rowGap: 0.5 }}\n >\n <Chip label=\"Campaign\" size=\"small\" />\n <Chip label=\"Sent\" size=\"small\" variant=\"outlined\" />\n </Stack>\n <Typography variant=\"body2\">\n {href ? <AppLink href={href}>{name}</AppLink> : name}\n {` · ${summary}`}\n </Typography>\n <Tooltip title={when.toLocaleString()}>\n <Typography\n variant=\"caption\"\n color=\"text.secondary\"\n sx={{ alignSelf: 'flex-start' }}\n >\n {email.subject && email.subject !== name\n ? `${Aglyn.activityTimeLabel(email.sentAtMs, nowMs)} · ${email.subject}`\n : Aglyn.activityTimeLabel(email.sentAtMs, nowMs)}\n </Typography>\n </Tooltip>\n </Stack>\n </Stack>\n )\n}\nCampaignEmailRow.displayName = 'CampaignEmailRow'\n\nexport interface ContactTimelineCardProps {\n /** The site the record is read under, or `null` at the organization level. */\n hostId: string | null\n org: CrmOrg\n contactId: string\n /**\n * The RAW contact document, as the page's listener hands it back. The card\n * resolves the viewing group and reads that group's facet itself, so a\n * page cannot hand it another holder's timeline by flattening the row\n * through the wrong group.\n */\n contact: Record<string, unknown> | null | undefined\n /**\n * Where a campaign entry links to — the email's report — or `null` for\n * one the page cannot address. Handed in rather than built here because\n * the report lives on another surface whose path is the MOUNT's to know:\n * a site's record page reaches its own Emails hub, an org-level mount\n * holds the org's site list and can reach every site's. No builder means\n * no links, never a guessed one.\n */\n campaignHref?: (email: ContactCampaignEmail) => string | null\n /**\n * The org's plan lacks the CRM (AGL-2788), which the shell mounts no CRM\n * page for (AGL-2851). The history still draws; logging an activity stands\n * locked, and one already logged cannot be edited.\n */\n suiteLocked?: boolean\n}\n\n/**\n * A person's whole history in one newest-first stream (AGL-2600): what the\n * platform CAPTURED — a form, an order, a booking, a sign-up — what a person\n * LOGGED beside it — a call, an email, a meeting, a note — and, since\n * AGL-2616, the campaign mail the platform SENT them and what became of it.\n *\n * ## Why one stream\n *\n * The histories answer one question, \"what has happened with this person\",\n * and a page showing them as separate lists asks the reader to interleave\n * them by eye. The merge is `mergeContactTimeline`, pure and specced: newest\n * first, stable at a tie, an undated entry last, a campaign at the instant\n * it was sent.\n *\n * Each entry says which it is. A captured entry carries the door's label and\n * a \"Captured\" chip and offers no controls; a logged entry carries its kind\n * and a \"Logged\" chip, and its author may edit or delete it; a campaign\n * entry carries \"Campaign\" and \"Sent\", links to the email's report, and is\n * nobody's to edit.\n *\n * ## What is read\n *\n * The captured side comes off the contact document the page already holds\n * — THIS group's facet, filtered to the sites the group may see, the same\n * projection the contacts list makes — and costs no read. The logged side is\n * the bounded listener every activity surface uses, filtered to this\n * contact, with a foot for the next hundred. The campaign side is one\n * request to `crm/contact-email-history`, which reads down this person's\n * own delivery log, capped, and never a campaign's recipients. The facet's\n * history is capped at fifty by the platform, so past the window the stream\n * is the logged side alone; the foot says as much by asking for \"more\n * activity\" rather than \"more history\".\n */\nexport function ContactTimelineCard(props: ContactTimelineCardProps) {\n const { hostId, org, contactId, contact, campaignHref, suiteLocked = false } = props\n const scope = useActivityScope(hostId, org)\n /*\n * THIS holder's captured history, and only the visits this group may see.\n * A read off the top of the document, or of another group's facet, would\n * be another business's records — the disclosure the facet shape ended.\n * At the organization level (AGL-2630) the holder is the person's own\n * primary one, the group the record page reads the profile through.\n */\n const consentGroup = useMemo(\n () =>\n scope.consentGroup ??\n contactPrimaryGroup(contact, (org ?? null) as Record<string, unknown> | null),\n [scope.consentGroup, contact, org],\n )\n const interactions = useMemo(() => {\n const facet = Aglyn.readContactFacet(contact, consentGroup.groupId)\n return Aglyn.interactionsForGroup(facet.interactions, consentGroup.hostIds)\n }, [contact, consentGroup])\n const link = useMemo<ActivityRecordLink>(() => ({ contactId }), [contactId])\n const activities = useActivityWindow(scope, link)\n /*\n * Where a captured entry's record is READ (AGL-2622). The site console's\n * two route params are already in the URL this page is on, so the link is\n * built from them rather than from two document reads per timeline. Only\n * an interaction on THIS site links: a sibling site's order is that\n * site's record, read on that site's console, and a link built with this\n * site's segment would 404 or — worse — open the wrong site's row under\n * the same id. An interaction with no site recorded predates the stamp\n * and is left unlinked rather than guessed at. Off a site — the org-level\n * mount — there is no segment to build with, and nothing links.\n */\n const params = useParams<{ orgSlug?: string; host?: string }>()\n const siteContext = useMemo(\n () =>\n params?.orgSlug && params?.host\n ? { orgSlug: String(params.orgSlug), host: String(params.host) }\n : null,\n [params?.orgSlug, params?.host],\n )\n const interactionHref = useCallback(\n (interaction: ContactInteraction): string | null =>\n siteContext && interaction.hostId === hostId\n ? Aglyn.contactInteractionHref(interaction, siteContext)\n : null,\n [siteContext, hostId],\n )\n // The campaign history is asked of a site: the mounted one, or the holder's.\n const campaigns = useContactCampaignEmails(\n hostId ?? (consentGroup.hostId || null),\n contactId,\n )\n // One member read for the whole stream, however many rows it has.\n const canEdit = useCanEditActivity(scope.orgId)\n const entries = useMemo(\n () =>\n Aglyn.mergeContactTimeline(interactions, activities.rows, campaigns.emails),\n [interactions, activities.rows, campaigns.emails],\n )\n // One clock for every row of one paint, so two rows logged a second apart\n // cannot read \"just now\" and \"1 min ago\" from being rendered across a\n // minute boundary.\n const nowMs = Date.now()\n\n const [dialogOpen, setDialogOpen] = useState(false)\n const [editing, setEditing] = useState<CrmActivityRow | null>(null)\n const openNew = useCallback(() => {\n setEditing(null)\n setDialogOpen(true)\n }, [])\n const openEdit = useCallback((activity: CrmActivityRow) => {\n setEditing(activity)\n setDialogOpen(true)\n }, [])\n const close = useCallback(() => setDialogOpen(false), [])\n\n const loggedChip = useMemo(\n () => <Chip label=\"Logged\" size=\"small\" variant=\"outlined\" />,\n [],\n )\n\n return (\n <>\n <CardDisplay\n header={'Timeline'}\n help={pluginDocsHelp('contactActivities', { anchor: '#four-kinds-of-history' })}\n actions={\n suiteLocked ? (\n <CrmSuiteLockedButton variant=\"contained\" color=\"primary\">\n {'Log activity'}\n </CrmSuiteLockedButton>\n ) : (\n <Button\n size=\"small\"\n variant=\"contained\"\n color=\"primary\"\n onClick={openNew}\n disabled={!activities.ready}\n >\n {'Log activity'}\n </Button>\n )\n }\n contentGutterX\n contentGutterY\n >\n <Stack spacing={2}>\n {activities.status === 'error' ? (\n <Typography variant=\"body2\" color=\"error\">\n {'Logged activity could not be loaded; what follows is what the platform captured.'}\n </Typography>\n ) : null}\n {campaigns.status === 'error' || campaigns.lookupFailed ? (\n // \"Unknown\", not \"none\": an empty campaign history and one that\n // could not be read lead a reader to opposite conclusions.\n <Typography variant=\"body2\" color=\"error\">\n {'Campaign email could not be loaded; the stream below may be missing the mail this person was sent.'}\n </Typography>\n ) : null}\n {entries.length === 0 ? (\n campaigns.status === 'loading' ? (\n // The campaign history is one request on mount; an empty state\n // before it answers would read as \"none\" for a person who was mailed.\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Loading…'}\n </Typography>\n ) : (\n <EmptyStateComponent\n compact\n label={'No history yet'}\n description={'What this person does on the site, the campaigns they are sent, and what you log about them, shows here.'}\n action={\n suiteLocked ? (\n <CrmSuiteLockedButton variant=\"contained\" color=\"primary\">\n {'Log activity'}\n </CrmSuiteLockedButton>\n ) : (\n <Button\n size=\"small\"\n variant=\"contained\"\n color=\"primary\"\n onClick={openNew}\n disabled={!activities.ready}\n >\n {'Log activity'}\n </Button>\n )\n }\n />\n )\n ) : (\n entries.map((entry) =>\n entry.kind === 'captured' ? (\n <CapturedRow\n key={entry.key}\n interaction={entry.interaction}\n nowMs={nowMs}\n href={interactionHref(entry.interaction)}\n />\n ) : entry.kind === 'campaign' ? (\n <CampaignEmailRow\n key={entry.key}\n email={entry.email}\n href={campaignHref ? campaignHref(entry.email) : null}\n nowMs={nowMs}\n />\n ) : (\n <ActivityRow\n key={entry.key}\n activity={entry.activity}\n scope={scope}\n onEdit={openEdit}\n subject={loggedChip}\n nowMs={nowMs}\n editable={!suiteLocked && canEdit(entry.activity)}\n />\n ),\n )\n )}\n {activities.hasMore ? (\n <Button\n size=\"small\"\n onClick={activities.showMore}\n sx={{ alignSelf: 'flex-start' }}\n >\n {'Show more activity'}\n </Button>\n ) : null}\n </Stack>\n </CardDisplay>\n <LogActivityDialog\n open={dialogOpen}\n onClose={close}\n scope={scope}\n link={link}\n activity={editing}\n />\n </>\n )\n}\nContactTimelineCard.displayName = 'ContactTimelineCard'\n\nexport default ContactTimelineCard\n"],"names":["Aglyn","CONTACT_SOURCE_LABELS","pluginDocsHelp","mdiAccountCircleOutline","mdiAccountEditOutline","mdiAccountPlusOutline","mdiApi","mdiBullhornOutline","mdiCalendarCheckOutline","mdiCartOutline","mdiEmailNewsletter","mdiFileImportOutline","mdiFormSelect","AppLink","CardDisplay","MdiIcon","EmptyStateComponent","Button","Chip","Stack","Tooltip","Typography","useParams","useCallback","useMemo","useState","contactPrimaryGroup","ActivityRow","useActivityScope","useActivityWindow","useCanEditActivity","CrmSuiteLockedButton","LogActivityDialog","useContactCampaignEmails","SOURCE_ICONS","form","member","order","booking","newsletter","api","manual","import","account","CapturedRow","props","interaction","nowMs","href","source","type","label","String","icon","when","Date","atMs","direction","spacing","sx","alignItems","color","pt","fontSize","theme","typography","h6","path","flex","minWidth","flexWrap","rowGap","size","variant","summary","title","toLocaleString","alignSelf","activityTimeLabel","INTERACTION_LINK_LABELS","displayName","CampaignEmailRow","email","name","campaignName","subject","campaignEmailSummary","join","sentAtMs","ContactTimelineCard","hostId","org","contactId","contact","campaignHref","suiteLocked","scope","consentGroup","interactions","facet","readContactFacet","groupId","interactionsForGroup","hostIds","link","activities","params","siteContext","orgSlug","host","interactionHref","contactInteractionHref","campaigns","canEdit","orgId","entries","mergeContactTimeline","rows","emails","now","dialogOpen","setDialogOpen","editing","setEditing","openNew","openEdit","activity","close","loggedChip","header","help","anchor","actions","onClick","disabled","ready","contentGutterX","contentGutterY","status","lookupFailed","length","compact","description","action","map","entry","kind","key","onEdit","editable","hasMore","showMore","open","onClose"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;AAEA,YAAYA,WAAW,eAAc;AAOrC,SAASC,qBAAqB,EAAEC,cAAc,QAAQ,eAAc;AACpE,SACEC,uBAAuB,EACvBC,qBAAqB,EACrBC,qBAAqB,EACrBC,MAAM,EACNC,kBAAkB,EAClBC,uBAAuB,EACvBC,cAAc,EACdC,kBAAkB,EAClBC,oBAAoB,EACpBC,aAAa,QACR,yBAAwB;AAC/B,SAASC,OAAO,EAAEC,WAAW,EAAEC,OAAO,QAAQ,uBAAsB;AACpE,OAAOC,yBAAyB,wDAAuD;AACvF,SAASC,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAEC,OAAO,EAAEC,UAAU,QAAQ,gBAAe;AACxE,SAASC,SAAS,QAAQ,kBAAiB;AAC3C,SAASC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AACtD,SAASC,mBAAmB,QAAQ,6BAAyB;AAC7D,SAASC,WAAW,QAAQ,qBAAiB;AAC7C,SAGEC,gBAAgB,EAChBC,iBAAiB,EACjBC,kBAAkB,QACb,wBAAoB;AAC3B,SAASC,oBAAoB,QAAQ,sBAAkB;AACvD,SAASC,iBAAiB,QAAQ,2BAAuB;AACzD,SAASC,wBAAwB,QAAQ,mCAA+B;AAExE;;;CAGC,GACD,MAAMC,eAAwD;IAC5DC,MAAMvB;IACNwB,QAAQ/B;IACRgC,OAAO5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PC,MAAM8D,gBAAgBmC,MAAMnG,WAAW;+BAHlCmG,MAAME,GAAG,IAKdF,MAAMC,IAAI,KAAK,2BACjB,KAACjE;gCAECC,OAAO+D,MAAM/D,KAAK;gCAClBlC,MAAM8C,eAAeA,aAAamD,MAAM/D,KAAK,IAAI;gCACjDnC,OAAOA;+BAHFkG,MAAME,GAAG,kBAMhB,KAACxH;gCAECmG,UAAUmB,MAAMnB,QAAQ;gCACxB9B,OAAOA;gCACPoD,QAAQvB;gCACRxC,SAAS2C;gCACTjF,OAAOA;gCACPsG,UAAU,CAACtD,eAAekB,QAAQgC,MAAMnB,QAAQ;+BAN3CmB,MAAME,GAAG;wBAWrB1C,WAAW6C,OAAO,iBACjB,KAACrI;4BACCuD,MAAK;4BACL6D,SAAS5B,WAAW8C,QAAQ;4BAC5B5F,IAAI;gCAAEkB,WAAW;4BAAa;sCAE7B;6BAED;;;;0BAGR,KAAC7C;gBACCwH,MAAMhC;gBACNiC,SAAS1B;gBACT/B,OAAOA;gBACPQ,MAAMA;gBACNsB,UAAUJ;;;;AAIlB;AACAjC,oBAAoBT,WAAW,GAAG;AAElC,eAAeS,oBAAmB"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/components/contact-timeline-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 * as Aglyn from '@aglyn/aglyn'\nimport type {\n ContactCampaignEmail,\n ContactInteraction,\n ContactSource,\n CrmActivityRow,\n} from '@aglyn/aglyn'\nimport { CONTACT_SOURCE_LABELS, pluginDocsHelp } from '@aglyn/aglyn'\nimport {\n mdiAccountCircleOutline,\n mdiAccountEditOutline,\n mdiAccountPlusOutline,\n mdiApi,\n mdiBullhornOutline,\n mdiCalendarCheckOutline,\n mdiCartOutline,\n mdiEmailNewsletter,\n mdiFileImportOutline,\n mdiFormSelect,\n} from '@aglyn/shared-data-mdi'\nimport { AppLink, CardDisplay, MdiIcon } from '@aglyn/shared-ui-jsx'\nimport EmptyStateComponent from '@aglyn/shared-ui-jsx/components/empty-state.component'\nimport { ListPagination } from '@aglyn/shared-ui-jsx/components/list-pagination.component'\nimport { Button, Chip, Stack, Tooltip, Typography } from '@mui/material'\nimport { useParams } from 'next/navigation'\nimport { useCallback, useMemo, useState } from 'react'\nimport { contactPrimaryGroup } from '../model/contact-record'\nimport { ActivityRow } from './activity-list'\nimport {\n type ActivityRecordLink,\n type CrmOrg,\n useActivityScope,\n useActivityWindow,\n useCanEditActivity,\n} from './activity-queries'\nimport {\n TimelineEntry,\n TimelineExpandAllButton,\n useTimelineExpansion,\n useTimelinePages,\n} from './activity-timeline'\nimport { CrmSuiteLockedButton } from './crm-suite-lock'\nimport { LogActivityDialog } from './log-activity-dialog'\nimport { useContactCampaignEmails } from './use-contact-campaign-emails'\n\n/**\n * One glyph per capture door. Typed against the source union so a door added\n * to it cannot render as the placeholder glyph.\n */\nconst SOURCE_ICONS: Record<ContactSource, { path: string }> = {\n form: mdiFormSelect,\n member: mdiAccountPlusOutline,\n order: mdiCartOutline,\n booking: mdiCalendarCheckOutline,\n newsletter: mdiEmailNewsletter,\n api: mdiApi,\n manual: mdiAccountEditOutline,\n import: mdiFileImportOutline,\n account: mdiAccountCircleOutline,\n}\n\n/**\n * One thing the platform recorded: the door it came through, what the door\n * wrote, when, and the page the person was on.\n *\n * Read-only by nature — nobody logged it, so nobody edits it. The entry\n * point sits beside the timestamp rather than in the summary, the way the\n * contacts drawer draws it: the summary is the sentence the door wrote, the\n * path is a fact the door recorded, and a long path on the sentence's line\n * pushes out the thing the row is about.\n *\n * Everything it holds fits the collapsed row, so it has nothing to open.\n */\nfunction CapturedRow(props: {\n interaction: ContactInteraction\n nowMs: number\n /** The console page the door's record is read on, when it left one. */\n href: string | null\n}) {\n const { interaction, nowMs, href } = props\n const source = interaction.type\n const label = CONTACT_SOURCE_LABELS[source] ?? String(source)\n const icon = SOURCE_ICONS[source]\n const when = new Date(interaction.atMs)\n return (\n <TimelineEntry\n icon={<MdiIcon path={icon?.path} />}\n chips={\n <>\n <Chip label={label} size=\"small\" />\n <Chip label=\"Captured\" size=\"small\" variant=\"outlined\" />\n </>\n }\n title={interaction.summary ?? label}\n meta={\n <Stack\n direction=\"row\"\n spacing={1}\n sx={{ alignItems: 'baseline', flexWrap: 'wrap', rowGap: 0.25 }}\n >\n <Tooltip title={when.toLocaleString()}>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {interaction.path\n ? `${Aglyn.activityTimeLabel(interaction.atMs, nowMs)} · ${interaction.path}`\n : Aglyn.activityTimeLabel(interaction.atMs, nowMs)}\n </Typography>\n </Tooltip>\n {/*\n The record the door left, where the console reads it (AGL-2622):\n the submission in the Inbox reader, the order in its dialog. A door\n that left nothing to open — a newsletter opt-in, an import — has no\n link, and the caption is the whole entry.\n */}\n {href ? (\n <Typography variant=\"caption\">\n <AppLink href={href}>\n {Aglyn.INTERACTION_LINK_LABELS[source] ?? 'Open'}\n </AppLink>\n </Typography>\n ) : null}\n </Stack>\n }\n />\n )\n}\nCapturedRow.displayName = 'CapturedRow'\n\n/**\n * One campaign email the platform sent this person (AGL-2616): which email,\n * and what became of it — `sent · delivered · opened ×2 · clicked`.\n *\n * Read-only like a captured row, and drawn apart from BOTH the captured and\n * the logged rows: its glyph is the campaign's, never the envelope a logged\n * `email` activity carries, and its chips say \"Campaign\" and \"Sent\" where\n * the others say \"Captured\" and \"Logged\". The name links to the email's own\n * report when the page can address it; an email the team has deleted, or\n * one a sibling site sent, keeps its name and loses the link.\n *\n * The delivery line stays on the collapsed row beside the name, so it has\n * nothing to open.\n */\nfunction CampaignEmailRow(props: {\n email: ContactCampaignEmail\n href: string | null\n nowMs: number\n}) {\n const { email, href, nowMs } = props\n const name = email.campaignName ?? email.subject ?? 'Campaign email'\n const summary = Aglyn.campaignEmailSummary(email).join(' · ')\n const when = new Date(email.sentAtMs)\n return (\n <TimelineEntry\n icon={<MdiIcon path={mdiBullhornOutline.path} />}\n chips={\n <>\n <Chip label=\"Campaign\" size=\"small\" />\n <Chip label=\"Sent\" size=\"small\" variant=\"outlined\" />\n </>\n }\n title={\n <>\n {href ? <AppLink href={href}>{name}</AppLink> : name}\n {` · ${summary}`}\n </>\n }\n meta={\n <Tooltip title={when.toLocaleString()}>\n <Typography\n variant=\"caption\"\n color=\"text.secondary\"\n sx={{ alignSelf: 'flex-start' }}\n >\n {email.subject && email.subject !== name\n ? `${Aglyn.activityTimeLabel(email.sentAtMs, nowMs)} · ${email.subject}`\n : Aglyn.activityTimeLabel(email.sentAtMs, nowMs)}\n </Typography>\n </Tooltip>\n }\n />\n )\n}\nCampaignEmailRow.displayName = 'CampaignEmailRow'\n\nexport interface ContactTimelineCardProps {\n /** The site the record is read under, or `null` at the organization level. */\n hostId: string | null\n org: CrmOrg\n contactId: string\n /**\n * The RAW contact document, as the page's listener hands it back. The card\n * resolves the viewing group and reads that group's facet itself, so a\n * page cannot hand it another holder's timeline by flattening the row\n * through the wrong group.\n */\n contact: Record<string, unknown> | null | undefined\n /**\n * Where a campaign entry links to — the email's report — or `null` for\n * one the page cannot address. Handed in rather than built here because\n * the report lives on another surface whose path is the MOUNT's to know:\n * a site's record page reaches its own Emails hub, an org-level mount\n * holds the org's site list and can reach every site's. No builder means\n * no links, never a guessed one.\n */\n campaignHref?: (email: ContactCampaignEmail) => string | null\n /**\n * The org's plan lacks the CRM (AGL-2788), which the shell mounts no CRM\n * page for (AGL-2851). The history still draws; logging an activity stands\n * locked, and one already logged cannot be edited.\n */\n suiteLocked?: boolean\n}\n\n/**\n * A person's whole history in one newest-first stream (AGL-2600): what the\n * platform CAPTURED — a form, an order, a booking, a sign-up — what a person\n * LOGGED beside it — a call, an email, a meeting, a note — and, since\n * AGL-2616, the campaign mail the platform SENT them and what became of it.\n *\n * ## Why one stream\n *\n * The histories answer one question, \"what has happened with this person\",\n * and a page showing them as separate lists asks the reader to interleave\n * them by eye. The merge is `mergeContactTimeline`, pure and specced: newest\n * first, stable at a tie, an undated entry last, a campaign at the instant\n * it was sent.\n *\n * Each entry says which it is. A captured entry carries the door's label and\n * a \"Captured\" chip and offers no controls; a logged entry carries its kind\n * and a \"Logged\" chip, and its author may edit or delete it; a campaign\n * entry carries \"Campaign\" and \"Sent\", links to the email's report, and is\n * nobody's to edit.\n *\n * ## What is read\n *\n * The captured side comes off the contact document the page already holds\n * — THIS group's facet, filtered to the sites the group may see, the same\n * projection the contacts list makes — and costs no read. The logged side is\n * the bounded listener every activity surface uses, filtered to this\n * contact, a hundred at a time. The campaign side is one request to\n * `crm/contact-email-history`, which reads down this person's own delivery\n * log, capped, and never a campaign's recipients. The facet's history is\n * capped at fifty by the platform, so past the window the stream is the\n * logged side alone.\n *\n * ## How it reads\n *\n * Every entry is a collapsed row that opens in place, paged by the\n * console's footer over the merged stream; a page turned past the logged\n * window widens it by the next hundred. **Expand all** and **Log activity**\n * sit in the card header, and edit and delete stay on the entry they act on.\n */\nexport function ContactTimelineCard(props: ContactTimelineCardProps) {\n const { hostId, org, contactId, contact, campaignHref, suiteLocked = false } = props\n const scope = useActivityScope(hostId, org)\n /*\n * THIS holder's captured history, and only the visits this group may see.\n * A read off the top of the document, or of another group's facet, would\n * be another business's records — the disclosure the facet shape ended.\n * At the organization level (AGL-2630) the holder is the person's own\n * primary one, the group the record page reads the profile through.\n */\n const consentGroup = useMemo(\n () =>\n scope.consentGroup ??\n contactPrimaryGroup(contact, (org ?? null) as Record<string, unknown> | null),\n [scope.consentGroup, contact, org],\n )\n const interactions = useMemo(() => {\n const facet = Aglyn.readContactFacet(contact, consentGroup.groupId)\n return Aglyn.interactionsForGroup(facet.interactions, consentGroup.hostIds)\n }, [contact, consentGroup])\n const link = useMemo<ActivityRecordLink>(() => ({ contactId }), [contactId])\n const activities = useActivityWindow(scope, link)\n /*\n * Where a captured entry's record is READ (AGL-2622). The site console's\n * two route params are already in the URL this page is on, so the link is\n * built from them rather than from two document reads per timeline. Only\n * an interaction on THIS site links: a sibling site's order is that\n * site's record, read on that site's console, and a link built with this\n * site's segment would 404 or — worse — open the wrong site's row under\n * the same id. An interaction with no site recorded predates the stamp\n * and is left unlinked rather than guessed at. Off a site — the org-level\n * mount — there is no segment to build with, and nothing links.\n */\n const params = useParams<{ orgSlug?: string; host?: string }>()\n const siteContext = useMemo(\n () =>\n params?.orgSlug && params?.host\n ? { orgSlug: String(params.orgSlug), host: String(params.host) }\n : null,\n [params?.orgSlug, params?.host],\n )\n const interactionHref = useCallback(\n (interaction: ContactInteraction): string | null =>\n siteContext && interaction.hostId === hostId\n ? Aglyn.contactInteractionHref(interaction, siteContext)\n : null,\n [siteContext, hostId],\n )\n // The campaign history is asked of a site: the mounted one, or the holder's.\n const campaigns = useContactCampaignEmails(\n hostId ?? (consentGroup.hostId || null),\n contactId,\n )\n // One member read for the whole stream, however many rows it has.\n const canEdit = useCanEditActivity(scope.orgId)\n const entries = useMemo(\n () =>\n Aglyn.mergeContactTimeline(interactions, activities.rows, campaigns.emails),\n [interactions, activities.rows, campaigns.emails],\n )\n // One clock for every row of one paint, so two rows logged a second apart\n // cannot read \"just now\" and \"1 min ago\" from being rendered across a\n // minute boundary.\n const nowMs = Date.now()\n\n const [dialogOpen, setDialogOpen] = useState(false)\n const [editing, setEditing] = useState<CrmActivityRow | null>(null)\n const openNew = useCallback(() => {\n setEditing(null)\n setDialogOpen(true)\n }, [])\n const openEdit = useCallback((activity: CrmActivityRow) => {\n setEditing(activity)\n setDialogOpen(true)\n }, [])\n const close = useCallback(() => setDialogOpen(false), [])\n\n const loggedChip = useMemo(\n () => <Chip label=\"Logged\" size=\"small\" variant=\"outlined\" />,\n [],\n )\n const expansion = useTimelineExpansion()\n const pages = useTimelinePages(entries.length, {\n hasMore: activities.hasMore,\n showMore: activities.showMore,\n loading: activities.status === 'loading',\n })\n const logButton = suiteLocked ? (\n <CrmSuiteLockedButton variant=\"contained\" color=\"primary\">\n {'Log activity'}\n </CrmSuiteLockedButton>\n ) : (\n <Button\n size=\"small\"\n variant=\"contained\"\n color=\"primary\"\n onClick={openNew}\n disabled={!activities.ready}\n >\n {'Log activity'}\n </Button>\n )\n\n return (\n <>\n <CardDisplay\n header={'Timeline'}\n help={pluginDocsHelp('contactActivities', { anchor: '#four-kinds-of-history' })}\n HeaderProps={{\n action: (\n <Stack direction=\"row\" spacing={1}>\n <TimelineExpandAllButton expansion={expansion} disabled={!entries.length} />\n {logButton}\n </Stack>\n ),\n }}\n contentGutterX\n contentGutterY\n >\n <Stack spacing={2}>\n {activities.status === 'error' ? (\n <Typography variant=\"body2\" color=\"error\">\n {'Logged activity could not be loaded; what follows is what the platform captured.'}\n </Typography>\n ) : null}\n {campaigns.status === 'error' || campaigns.lookupFailed ? (\n // \"Unknown\", not \"none\": an empty campaign history and one that\n // could not be read lead a reader to opposite conclusions.\n <Typography variant=\"body2\" color=\"error\">\n {'Campaign email could not be loaded; the stream below may be missing the mail this person was sent.'}\n </Typography>\n ) : null}\n {entries.length === 0 ? (\n campaigns.status === 'loading' ? (\n // The campaign history is one request on mount; an empty state\n // before it answers would read as \"none\" for a person who was mailed.\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Loading…'}\n </Typography>\n ) : (\n <EmptyStateComponent\n compact\n label={'No history yet'}\n description={'What this person does on the site, the campaigns they are sent, and what you log about them, shows here.'}\n action={logButton}\n />\n )\n ) : (\n pages.slice(entries).map((entry) =>\n entry.kind === 'captured' ? (\n <CapturedRow\n key={entry.key}\n interaction={entry.interaction}\n nowMs={nowMs}\n href={interactionHref(entry.interaction)}\n />\n ) : entry.kind === 'campaign' ? (\n <CampaignEmailRow\n key={entry.key}\n email={entry.email}\n href={campaignHref ? campaignHref(entry.email) : null}\n nowMs={nowMs}\n />\n ) : (\n <ActivityRow\n key={entry.key}\n activity={entry.activity}\n scope={scope}\n onEdit={openEdit}\n subject={loggedChip}\n nowMs={nowMs}\n editable={!suiteLocked && canEdit(entry.activity)}\n expanded={expansion.isExpanded(entry.key)}\n onToggle={() => expansion.toggle(entry.key)}\n />\n ),\n )\n )}\n {entries.length ? <ListPagination {...pages.footer} /> : null}\n </Stack>\n </CardDisplay>\n <LogActivityDialog\n open={dialogOpen}\n onClose={close}\n scope={scope}\n link={link}\n activity={editing}\n />\n </>\n )\n}\nContactTimelineCard.displayName = 'ContactTimelineCard'\n\nexport default ContactTimelineCard\n"],"names":["Aglyn","CONTACT_SOURCE_LABELS","pluginDocsHelp","mdiAccountCircleOutline","mdiAccountEditOutline","mdiAccountPlusOutline","mdiApi","mdiBullhornOutline","mdiCalendarCheckOutline","mdiCartOutline","mdiEmailNewsletter","mdiFileImportOutline","mdiFormSelect","AppLink","CardDisplay","MdiIcon","EmptyStateComponent","ListPagination","Button","Chip","Stack","Tooltip","Typography","useParams","useCallback","useMemo","useState","contactPrimaryGroup","ActivityRow","useActivityScope","useActivityWindow","useCanEditActivity","TimelineEntry","TimelineExpandAllButton","useTimelineExpansion","useTimelinePages","CrmSuiteLockedButton","LogActivityDialog","useContactCampaignEmails","SOURCE_ICONS","form","member","order","booking","newsletter","api","manual","import","account","CapturedRow","props","interaction","nowMs","href","source","type","label","String","icon","when","Date","atMs","path","chips","size","variant","title","summary","meta","direction","spacing","sx","alignItems","flexWrap","rowGap","toLocaleString","color","activityTimeLabel","INTERACTION_LINK_LABELS","displayName","CampaignEmailRow","email","name","campaignName","subject","campaignEmailSummary","join","sentAtMs","alignSelf","ContactTimelineCard","hostId","org","contactId","contact","campaignHref","suiteLocked","scope","consentGroup","interactions","facet","readContactFacet","groupId","interactionsForGroup","hostIds","link","activities","params","siteContext","orgSlug","host","interactionHref","contactInteractionHref","campaigns","canEdit","orgId","entries","mergeContactTimeline","rows","emails","now","dialogOpen","setDialogOpen","editing","setEditing","openNew","openEdit","activity","close","loggedChip","expansion","pages","length","hasMore","showMore","loading","status","logButton","onClick","disabled","ready","header","help","anchor","HeaderProps","action","contentGutterX","contentGutterY","lookupFailed","compact","description","slice","map","entry","kind","key","onEdit","editable","expanded","isExpanded","onToggle","toggle","footer","open","onClose"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,YAAYA,WAAW,eAAc;AAOrC,SAASC,qBAAqB,EAAEC,cAAc,QAAQ,eAAc;AACpE,SACEC,uBAAuB,EACvBC,qBAAqB,EACrBC,qBAAqB,EACrBC,MAAM,EACNC,kBAAkB,EAClBC,uBAAuB,EACvBC,cAAc,EACdC,kBAAkB,EAClBC,oBAAoB,EACpBC,aAAa,QACR,yBAAwB;AAC/B,SAASC,OAAO,EAAEC,WAAW,EAAEC,OAAO,QAAQ,uBAAsB;AACpE,OAAOC,yBAAyB,wDAAuD;AACvF,SAASC,cAAc,QAAQ,4DAA2D;AAC1F,SAASC,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAEC,OAAO,EAAEC,UAAU,QAAQ,gBAAe;AACxE,SAASC,SAAS,QAAQ,kBAAiB;AAC3C,SAASC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AACtD,SAASC,mBAAmB,QAAQ,6BAAyB;AAC7D,SAASC,WAAW,QAAQ,qBAAiB;AAC7C,SAGEC,gBAAgB,EAChBC,iBAAiB,EACjBC,kBAAkB,QACb,wBAAoB;AAC3B,SACEC,aAAa,EACbC,uBAAuB,EACvBC,oBAAoB,EACpBC,gBAAgB,QACX,yBAAqB;AAC5B,SAASC,oBAAoB,QAAQ,sBAAkB;AACvD,SAASC,iBAAiB,QAAQ,2BAAuB;AACzD,SAASC,wBAAwB,QAAQ,mCAA+B;AAExE;;;CAGC,GACD,MAAMC,eAAwD;IAC5DC,MAAM5B;IACN6B,QAAQpC;IACRqC,OAAOjC;IACPkC,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