@aglyn/plugins-marketing 1.0.0-beta.143

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 (183) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +7 -0
  3. package/package.json +56 -0
  4. package/src/index.d.ts +19 -0
  5. package/src/index.js +20 -0
  6. package/src/index.js.map +1 -0
  7. package/src/lib/components/announcement-bar-card.component.d.ts +20 -0
  8. package/src/lib/components/announcement-bar-card.component.js +292 -0
  9. package/src/lib/components/announcement-bar-card.component.js.map +1 -0
  10. package/src/lib/components/campaign-composer.d.ts +84 -0
  11. package/src/lib/components/campaign-composer.js +1643 -0
  12. package/src/lib/components/campaign-composer.js.map +1 -0
  13. package/src/lib/components/campaign-conversions-card.d.ts +22 -0
  14. package/src/lib/components/campaign-conversions-card.js +642 -0
  15. package/src/lib/components/campaign-conversions-card.js.map +1 -0
  16. package/src/lib/components/campaign-detail-card.d.ts +55 -0
  17. package/src/lib/components/campaign-detail-card.js +771 -0
  18. package/src/lib/components/campaign-detail-card.js.map +1 -0
  19. package/src/lib/components/campaign-edit-drawer.d.ts +60 -0
  20. package/src/lib/components/campaign-edit-drawer.js +252 -0
  21. package/src/lib/components/campaign-edit-drawer.js.map +1 -0
  22. package/src/lib/components/campaign-email-zones.d.ts +111 -0
  23. package/src/lib/components/campaign-email-zones.js +54 -0
  24. package/src/lib/components/campaign-email-zones.js.map +1 -0
  25. package/src/lib/components/campaign-glance-card.component.d.ts +18 -0
  26. package/src/lib/components/campaign-glance-card.component.js +151 -0
  27. package/src/lib/components/campaign-glance-card.component.js.map +1 -0
  28. package/src/lib/components/campaign-members-section.d.ts +87 -0
  29. package/src/lib/components/campaign-members-section.js +499 -0
  30. package/src/lib/components/campaign-members-section.js.map +1 -0
  31. package/src/lib/components/campaign-reach-sections.d.ts +137 -0
  32. package/src/lib/components/campaign-reach-sections.js +694 -0
  33. package/src/lib/components/campaign-reach-sections.js.map +1 -0
  34. package/src/lib/components/campaign-report-card.d.ts +91 -0
  35. package/src/lib/components/campaign-report-card.js +667 -0
  36. package/src/lib/components/campaign-report-card.js.map +1 -0
  37. package/src/lib/components/campaign-test-send-drawer.d.ts +45 -0
  38. package/src/lib/components/campaign-test-send-drawer.js +238 -0
  39. package/src/lib/components/campaign-test-send-drawer.js.map +1 -0
  40. package/src/lib/components/campaigns-card.d.ts +31 -0
  41. package/src/lib/components/campaigns-card.js +667 -0
  42. package/src/lib/components/campaigns-card.js.map +1 -0
  43. package/src/lib/components/conversion-attribution.component.d.ts +62 -0
  44. package/src/lib/components/conversion-attribution.component.js +127 -0
  45. package/src/lib/components/conversion-attribution.component.js.map +1 -0
  46. package/src/lib/components/email-compose-card.d.ts +12 -0
  47. package/src/lib/components/email-compose-card.js +157 -0
  48. package/src/lib/components/email-compose-card.js.map +1 -0
  49. package/src/lib/components/email-detail.d.ts +40 -0
  50. package/src/lib/components/email-detail.js +1180 -0
  51. package/src/lib/components/email-detail.js.map +1 -0
  52. package/src/lib/components/email-edit-drawer.d.ts +54 -0
  53. package/src/lib/components/email-edit-drawer.js +172 -0
  54. package/src/lib/components/email-edit-drawer.js.map +1 -0
  55. package/src/lib/components/email-messages-widget.d.ts +22 -0
  56. package/src/lib/components/email-messages-widget.js +49 -0
  57. package/src/lib/components/email-messages-widget.js.map +1 -0
  58. package/src/lib/components/email-recipients-card.d.ts +50 -0
  59. package/src/lib/components/email-recipients-card.js +338 -0
  60. package/src/lib/components/email-recipients-card.js.map +1 -0
  61. package/src/lib/components/emails-list-card.d.ts +36 -0
  62. package/src/lib/components/emails-list-card.js +544 -0
  63. package/src/lib/components/emails-list-card.js.map +1 -0
  64. package/src/lib/components/experiment-zones.d.ts +78 -0
  65. package/src/lib/components/experiment-zones.js +65 -0
  66. package/src/lib/components/experiment-zones.js.map +1 -0
  67. package/src/lib/components/host-experiments-card.component.d.ts +17 -0
  68. package/src/lib/components/host-experiments-card.component.js +887 -0
  69. package/src/lib/components/host-experiments-card.component.js.map +1 -0
  70. package/src/lib/components/host-marketing-summary-card.component.d.ts +15 -0
  71. package/src/lib/components/host-marketing-summary-card.component.js +161 -0
  72. package/src/lib/components/host-marketing-summary-card.component.js.map +1 -0
  73. package/src/lib/components/host-overlays-card.component.d.ts +19 -0
  74. package/src/lib/components/host-overlays-card.component.js +783 -0
  75. package/src/lib/components/host-overlays-card.component.js.map +1 -0
  76. package/src/lib/components/marketing-console-page.d.ts +28 -0
  77. package/src/lib/components/marketing-console-page.js +166 -0
  78. package/src/lib/components/marketing-console-page.js.map +1 -0
  79. package/src/lib/components/marketing-console-sections.d.ts +34 -0
  80. package/src/lib/components/marketing-console-sections.js +77 -0
  81. package/src/lib/components/marketing-console-sections.js.map +1 -0
  82. package/src/lib/components/overlay-stats-row.component.d.ts +15 -0
  83. package/src/lib/components/overlay-stats-row.component.js +78 -0
  84. package/src/lib/components/overlay-stats-row.component.js.map +1 -0
  85. package/src/lib/components/popup-card.component.d.ts +18 -0
  86. package/src/lib/components/popup-card.component.js +462 -0
  87. package/src/lib/components/popup-card.component.js.map +1 -0
  88. package/src/lib/components/record-attribution-widget.d.ts +35 -0
  89. package/src/lib/components/record-attribution-widget.js +33 -0
  90. package/src/lib/components/record-attribution-widget.js.map +1 -0
  91. package/src/lib/components/site-runtime.d.ts +9 -0
  92. package/src/lib/components/site-runtime.js +1081 -0
  93. package/src/lib/components/site-runtime.js.map +1 -0
  94. package/src/lib/components/use-campaign-send-api.d.ts +35 -0
  95. package/src/lib/components/use-campaign-send-api.js +99 -0
  96. package/src/lib/components/use-campaign-send-api.js.map +1 -0
  97. package/src/lib/components/use-campaign-topic-options.d.ts +20 -0
  98. package/src/lib/components/use-campaign-topic-options.js +44 -0
  99. package/src/lib/components/use-campaign-topic-options.js.map +1 -0
  100. package/src/lib/components/use-emails-hub-path.d.ts +39 -0
  101. package/src/lib/components/use-emails-hub-path.js +70 -0
  102. package/src/lib/components/use-emails-hub-path.js.map +1 -0
  103. package/src/lib/components/use-marketing-hub-path.d.ts +21 -0
  104. package/src/lib/components/use-marketing-hub-path.js +50 -0
  105. package/src/lib/components/use-marketing-hub-path.js.map +1 -0
  106. package/src/lib/components/use-overlay-copy-editor.d.ts +79 -0
  107. package/src/lib/components/use-overlay-copy-editor.js +110 -0
  108. package/src/lib/components/use-overlay-copy-editor.js.map +1 -0
  109. package/src/lib/constants/bundle-common.d.ts +8 -0
  110. package/src/lib/constants/bundle-common.js +9 -0
  111. package/src/lib/constants/bundle-common.js.map +1 -0
  112. package/src/lib/model/campaign-membership-figures.d.ts +109 -0
  113. package/src/lib/model/campaign-membership-figures.js +113 -0
  114. package/src/lib/model/campaign-membership-figures.js.map +1 -0
  115. package/src/lib/model/compile-client-automations.d.ts +65 -0
  116. package/src/lib/model/compile-client-automations.js +95 -0
  117. package/src/lib/model/compile-client-automations.js.map +1 -0
  118. package/src/lib/model/experiments.d.ts +130 -0
  119. package/src/lib/model/experiments.js +186 -0
  120. package/src/lib/model/experiments.js.map +1 -0
  121. package/src/lib/model/index.d.ts +26 -0
  122. package/src/lib/model/index.js +26 -0
  123. package/src/lib/model/index.js.map +1 -0
  124. package/src/lib/model/marketing-record-routes.d.ts +6 -0
  125. package/src/lib/model/marketing-record-routes.js +46 -0
  126. package/src/lib/model/marketing-record-routes.js.map +1 -0
  127. package/src/lib/model/overlay-copy.d.ts +62 -0
  128. package/src/lib/model/overlay-copy.js +78 -0
  129. package/src/lib/model/overlay-copy.js.map +1 -0
  130. package/src/lib/model/overlays.d.ts +113 -0
  131. package/src/lib/model/overlays.js +93 -0
  132. package/src/lib/model/overlays.js.map +1 -0
  133. package/src/lib/model/site-contract.d.ts +100 -0
  134. package/src/lib/model/site-contract.js +23 -0
  135. package/src/lib/model/site-contract.js.map +1 -0
  136. package/src/lib/plugin.d.ts +27 -0
  137. package/src/lib/plugin.js +168 -0
  138. package/src/lib/plugin.js.map +1 -0
  139. package/src/lib/preview-props.d.ts +31 -0
  140. package/src/lib/preview-props.js +54 -0
  141. package/src/lib/preview-props.js.map +1 -0
  142. package/src/lib/server/campaign-manage.d.ts +62 -0
  143. package/src/lib/server/campaign-manage.js +829 -0
  144. package/src/lib/server/campaign-manage.js.map +1 -0
  145. package/src/lib/server/campaign-process-scheduled.d.ts +26 -0
  146. package/src/lib/server/campaign-process-scheduled.js +198 -0
  147. package/src/lib/server/campaign-process-scheduled.js.map +1 -0
  148. package/src/lib/server/campaign-recipients.d.ts +55 -0
  149. package/src/lib/server/campaign-recipients.js +219 -0
  150. package/src/lib/server/campaign-recipients.js.map +1 -0
  151. package/src/lib/server/campaign-send.d.ts +487 -0
  152. package/src/lib/server/campaign-send.js +3157 -0
  153. package/src/lib/server/campaign-send.js.map +1 -0
  154. package/src/lib/server/email-campaign-reach.d.ts +174 -0
  155. package/src/lib/server/email-campaign-reach.js +254 -0
  156. package/src/lib/server/email-campaign-reach.js.map +1 -0
  157. package/src/lib/server/email-events.d.ts +27 -0
  158. package/src/lib/server/email-events.js +714 -0
  159. package/src/lib/server/email-events.js.map +1 -0
  160. package/src/lib/server/get-client-automations.d.ts +60 -0
  161. package/src/lib/server/get-client-automations.js +87 -0
  162. package/src/lib/server/get-client-automations.js.map +1 -0
  163. package/src/lib/server/get-overlays.d.ts +28 -0
  164. package/src/lib/server/get-overlays.js +65 -0
  165. package/src/lib/server/get-overlays.js.map +1 -0
  166. package/src/lib/server/get-screen-experiments.d.ts +42 -0
  167. package/src/lib/server/get-screen-experiments.js +82 -0
  168. package/src/lib/server/get-screen-experiments.js.map +1 -0
  169. package/src/lib/server/lists-materialize.d.ts +18 -0
  170. package/src/lib/server/lists-materialize.js +130 -0
  171. package/src/lib/server/lists-materialize.js.map +1 -0
  172. package/src/lib/server/marketing-figures.d.ts +37 -0
  173. package/src/lib/server/marketing-figures.js +248 -0
  174. package/src/lib/server/marketing-figures.js.map +1 -0
  175. package/src/lib/server/site-page-enricher.d.ts +26 -0
  176. package/src/lib/server/site-page-enricher.js +210 -0
  177. package/src/lib/server/site-page-enricher.js.map +1 -0
  178. package/src/lib/server.d.ts +20 -0
  179. package/src/lib/server.js +152 -0
  180. package/src/lib/server.js.map +1 -0
  181. package/src/lib/site.d.ts +22 -0
  182. package/src/lib/site.js +48 -0
  183. package/src/lib/site.js.map +1 -0
@@ -0,0 +1,544 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ 'use client';
17
+ import { _ as _extends } from "@swc/helpers/_/_extends";
18
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
19
+ import { pluginDocsHelp } from "@aglyn/aglyn";
20
+ import { mdiBullhornOutline, mdiContentCopy, mdiDeleteOutline, mdiEyeOutline, mdiPaletteOutline } from "@aglyn/shared-data-mdi";
21
+ import { AppLink, CardDisplay, MdiIcon, useConfirmationContext } from "@aglyn/shared-ui-jsx";
22
+ import { ListRowActions, ListTable, listActionsColumn } from "@aglyn/shared-ui-jsx/components/list-table.component";
23
+ import { TABLE_ROW_HEIGHT } from "@aglyn/shared-ui-jsx/const/table-pagination";
24
+ import { CreateArtifactDrawer } from "@aglyn/shared-ui-jsx-forms";
25
+ import { useSnackbar } from "@aglyn/shared-ui-snackstack";
26
+ import { ceilingedWindow, collectionCeiling } from "@aglyn/tenant-feature-instance/hooks/host-collection-queries";
27
+ import { DUPLICATE_MENU_LABEL, useDuplicateResource, useFirestore, useFirestoreCollection } from "@aglyn/tenant-feature-instance";
28
+ import { Alert, Button, Chip, Stack, Typography } from "@mui/material";
29
+ import { collection } from "firebase/firestore";
30
+ import { useRouter } from "next/navigation";
31
+ import { useCallback, useMemo, useState } from "react";
32
+ import { campaignSendDisplay, CAMPAIGN_SEND_CONTAINER_FIELD } from "@aglyn/shared-ui-email-campaigns/model/campaign-container";
33
+ import { emailListTimeMs, emailSendTimeMs } from "@aglyn/shared-ui-email-campaigns/model/email-record";
34
+ import { useCampaignManageApi, useCampaignSendApi } from "./use-campaign-send-api.js";
35
+ import { useMarketingHubPath } from "./use-marketing-hub-path.js";
36
+ /** How many messages one read of this list covers. */ const EMAIL_CEILING = 30;
37
+ /** How many campaigns the create drawer offers to file a new email under. */ const CONTAINER_CEILING = 50;
38
+ /**
39
+ * Why discard is refused, keyed by the state that refuses it.
40
+ *
41
+ * The KEYS are persisted status values written by the send path. Each line
42
+ * says what to do instead, because "you cannot" on its own leaves a merchant
43
+ * with an email they wanted rid of and no next step — and for a scheduled one
44
+ * the next step is a different act with a different consequence, so naming it
45
+ * is the difference between withdrawing mail and losing the record of it.
46
+ *
47
+ * A state absent from here falls through to the generic refusal rather than
48
+ * being flattened into one of these: a state this list cannot name is worth
49
+ * seeing.
50
+ */ const DISCARD_REFUSAL = {
51
+ sent: 'This email has been sent. Its report and its unsubscribe links have to go on resolving.',
52
+ scheduled: 'Cancel the send first — cancelling takes it off the clock and keeps the email.',
53
+ sending: 'This email is being sent right now.',
54
+ canceled: 'A canceled email is kept as the record that it was withdrawn.'
55
+ };
56
+ /**
57
+ * The chip color for one display state.
58
+ *
59
+ * `sending` is the one worth a color: an email part way through an audience
60
+ * larger than one batch is doing something right now, and a merchant scanning
61
+ * the list for what needs attention should find it without reading. The rest
62
+ * are neutral, because a finished send and a draft are not events.
63
+ */ const STATE_COLOR = {
64
+ sending: 'info',
65
+ stopped: 'warning'
66
+ };
67
+ const emailsDocsHelp = pluginDocsHelp('emailCampaigns', {
68
+ anchor: '#opens--clicks',
69
+ excerpt: 'Every message this site has sent or has scheduled, each with its own ' + 'report: what was delivered, who opened it, and which links they followed.'
70
+ });
71
+ /**
72
+ * EVERY MESSAGE, AS AGAINST EVERY CAMPAIGN.
73
+ *
74
+ * A campaign groups messages; this is the messages. The two are different
75
+ * questions — "how did the spring promotion do" and "what went out on the
76
+ * 14th, and to whom" — and they were previously the same list because a
77
+ * campaign document WAS a single send.
78
+ *
79
+ * ## Ordered in the browser, deliberately
80
+ *
81
+ * No SEND date is on every message: a sent one carries `sentAt` and a
82
+ * scheduled one carries `sendAtMs`, written by two different branches of the
83
+ * send path, and a draft carries neither — so `orderBy` on either would not
84
+ * mis-sort this list, it would DROP half of it. `collectionCeiling` reads a
85
+ * bounded window in document-id order and probes one past the ceiling, so the
86
+ * rows are sorted here and the reader is told when there are more.
87
+ *
88
+ * Every writer stamps a `createdAtMs`, which is the field this list could be
89
+ * ordered on in Firestore. Moving it there is a query change with the same
90
+ * hazard as the two above — `orderBy` drops a document missing the field —
91
+ * so it needs the corpus proven to carry one, not just the writers.
92
+ *
93
+ * The page is therefore a SLICE of a window this card already holds, not a
94
+ * query: paging an id-ordered walk and re-sorting each page by date would run
95
+ * in one order within a page and another across them.
96
+ */ export function EmailsListCard(props) {
97
+ const { hostId, basePath } = props;
98
+ const firestore = useFirestore();
99
+ // The sibling hub: a campaign's page belongs to the Marketing console.
100
+ const marketingHub = useMarketingHubPath();
101
+ const router = useRouter();
102
+ const { data: emailDocs } = useFirestoreCollection(()=>collectionCeiling(collection(firestore, 'hosts', hostId, 'campaigns'), EMAIL_CEILING), [
103
+ firestore,
104
+ hostId
105
+ ], {
106
+ idField: '$id'
107
+ });
108
+ const { rows: readEmails, truncated } = ceilingedWindow(emailDocs, EMAIL_CEILING);
109
+ /*
110
+ * Newest first on the time each message SITS at — its send time where it
111
+ * has one, its creation where it does not.
112
+ *
113
+ * A draft has neither `sentAt` nor `sendAtMs`, so sorting on the send time
114
+ * alone gave every draft the key 0 and filed the email a merchant is in the
115
+ * middle of writing at the very bottom of the list, behind whatever paging
116
+ * it has. `emailListTimeMs` is the same ordering with that one gap closed;
117
+ * a SENT message still orders by when it went out, never by when it was
118
+ * drafted.
119
+ */ const emails = useMemo(()=>[
120
+ ...readEmails
121
+ ].sort((a, b)=>emailListTimeMs(b) - emailListTimeMs(a)), [
122
+ readEmails
123
+ ]);
124
+ const emailHref = (email)=>`${basePath}/messages/${email.$id}`;
125
+ const { confirm } = useConfirmationContext();
126
+ const { enqueueSnackbar } = useSnackbar();
127
+ // Duplicate (AGL-2936): a new draft with the message and its design, and
128
+ // nobody to send to until the person chooses — through the manage door,
129
+ // which is the plugin's own.
130
+ const manageForCopy = useCampaignManageApi(hostId);
131
+ const duplicate = useDuplicateResource({
132
+ hostId,
133
+ perform: async ({ sourceId, name, attemptKey })=>{
134
+ var _ref, _payload_name;
135
+ const { response, payload } = await manageForCopy({
136
+ action: 'duplicate',
137
+ campaignId: sourceId,
138
+ name,
139
+ attemptKey
140
+ });
141
+ if (!response.ok) throw new Error((_ref = payload == null ? void 0 : payload.error) != null ? _ref : 'Duplicate failed');
142
+ return {
143
+ id: String(payload.emailId),
144
+ versionId: null,
145
+ name: String((_payload_name = payload.name) != null ? _payload_name : name)
146
+ };
147
+ },
148
+ onDuplicated: (_kind, copy)=>enqueueSnackbar(`Duplicated as “${copy.name}” — a draft with no audience yet`, {
149
+ variant: 'success'
150
+ })
151
+ });
152
+ const manageApi = useCampaignManageApi(hostId);
153
+ /** The email a discard is in flight for, so its row menu can say so. */ const [discardingId, setDiscardingId] = useState('');
154
+ /*==========================================
155
+ * THROWING AWAY A DRAFT.
156
+ *
157
+ * The one removal this surface has, and it is deliberately the narrowest
158
+ * one: an email that was never sent, whose record nobody outside the
159
+ * console has ever seen. Everything else on this list is evidence — a sent
160
+ * message's report is what a merchant answers a complaint with, and its id
161
+ * is inside the HMAC of every unsubscribe footer it delivered — and a
162
+ * scheduled one is withdrawn with Cancel, which keeps the record and takes
163
+ * it off the clock.
164
+ *
165
+ * The menu already refuses anything but a draft, and so does the route.
166
+ * That is not belt and braces: the state on screen is a snapshot that can
167
+ * be seconds old, and the record can be claimed by `sendNow` in between.
168
+ * The route's refusal is the one that decides, inside the transaction that
169
+ * does the delete.
170
+ *=========================================*/ const handleDiscard = useCallback(async (email)=>{
171
+ var _ref;
172
+ if (discardingId) return;
173
+ const id = String((_ref = email == null ? void 0 : email.$id) != null ? _ref : '');
174
+ const name = String((email == null ? void 0 : email.subject) || (email == null ? void 0 : email.displayName) || 'this draft');
175
+ const agreed = await confirm({
176
+ title: 'Discard this draft?',
177
+ description: `${name} has not been sent to anybody, and discarding it removes ` + 'it for good — the subject, the message and everything else ' + 'written on it. There is no undo.',
178
+ confirmationText: 'Discard'
179
+ }).then(()=>true).catch(()=>false);
180
+ if (!agreed) return;
181
+ setDiscardingId(id);
182
+ try {
183
+ const { response, payload } = await manageApi({
184
+ action: 'discardEmail',
185
+ campaignId: id
186
+ });
187
+ if (!response.ok) {
188
+ var _ref1;
189
+ return void enqueueSnackbar((_ref1 = payload == null ? void 0 : payload.error) != null ? _ref1 : 'This draft could not be discarded', {
190
+ variant: 'warning',
191
+ allowDuplicate: true
192
+ });
193
+ }
194
+ enqueueSnackbar('Draft discarded', {
195
+ variant: 'success',
196
+ persist: false
197
+ });
198
+ } catch (error) {
199
+ console.error(error);
200
+ enqueueSnackbar('This draft could not be discarded', {
201
+ variant: 'error',
202
+ allowDuplicate: true
203
+ });
204
+ } finally{
205
+ setDiscardingId('');
206
+ }
207
+ }, [
208
+ confirm,
209
+ discardingId,
210
+ enqueueSnackbar,
211
+ manageApi
212
+ ]);
213
+ /**
214
+ * What a message can be opened INTO, from the list.
215
+ *
216
+ * All three are places the message's own report already links to, moved one
217
+ * screen earlier: the report itself, the campaign it belongs to, and the
218
+ * template it was rendered from. A message need have neither of the last
219
+ * two — one sent before campaigns grouped anything names no container, and
220
+ * one composed inline was built from no template — so those entries are
221
+ * shown DISABLED with the reason rather than hidden. A control that
222
+ * disappears and a control that does not apply look identical, and only one
223
+ * of them tells the reader which case they are in.
224
+ *
225
+ * DISCARD is the fourth entry and is offered on the same terms: a draft can
226
+ * be thrown away, and nothing else can. It stays visible on a sent or
227
+ * scheduled message carrying the reason it is refused, because that is the
228
+ * honest answer to “how do I get rid of this” — and the route refuses it
229
+ * too, so the menu is describing a rule rather than being one.
230
+ */ const rowActions = (email)=>{
231
+ var _ref, _ref1, _ref2, _DISCARD_REFUSAL_state;
232
+ const containerId = String((_ref = email == null ? void 0 : email[CAMPAIGN_SEND_CONTAINER_FIELD]) != null ? _ref : '');
233
+ const templateScreenId = String((_ref1 = email == null ? void 0 : email.templateScreenId) != null ? _ref1 : '');
234
+ const state = String((_ref2 = email == null ? void 0 : email.status) != null ? _ref2 : '');
235
+ return [
236
+ {
237
+ key: 'details',
238
+ label: 'Open report',
239
+ icon: /*#__PURE__*/ _jsx(MdiIcon, {
240
+ path: mdiEyeOutline.path,
241
+ size: 0.8
242
+ }),
243
+ href: emailHref(email)
244
+ },
245
+ {
246
+ key: 'campaign',
247
+ label: 'Open its campaign',
248
+ icon: /*#__PURE__*/ _jsx(MdiIcon, {
249
+ path: mdiBullhornOutline.path,
250
+ size: 0.8
251
+ }),
252
+ // The campaign's page belongs to the Marketing console, so this one
253
+ // href is built from the sibling hub rather than this surface's own.
254
+ href: containerId && marketingHub ? `${marketingHub}/campaigns/${containerId}` : undefined,
255
+ disabled: !containerId || !marketingHub,
256
+ disabledReason: containerId ? 'This site’s console URL has not resolved yet' : 'Sent before campaigns grouped their emails, so it belongs to none'
257
+ },
258
+ {
259
+ key: 'template',
260
+ label: 'Open its template',
261
+ icon: /*#__PURE__*/ _jsx(MdiIcon, {
262
+ path: mdiPaletteOutline.path,
263
+ size: 0.8
264
+ }),
265
+ href: templateScreenId ? `${basePath}/templates/${templateScreenId}` : undefined,
266
+ disabled: !templateScreenId,
267
+ disabledReason: 'This message was not built from a template'
268
+ },
269
+ {
270
+ key: 'duplicate',
271
+ label: DUPLICATE_MENU_LABEL,
272
+ icon: /*#__PURE__*/ _jsx(MdiIcon, {
273
+ path: mdiContentCopy.path,
274
+ size: 0.8
275
+ }),
276
+ onClick: ()=>{
277
+ var _ref, _ref1;
278
+ return duplicate.request('campaign', {
279
+ id: String(email.$id),
280
+ name: String((_ref = (_ref1 = email == null ? void 0 : email.displayName) != null ? _ref1 : email == null ? void 0 : email.subject) != null ? _ref : '')
281
+ });
282
+ }
283
+ },
284
+ {
285
+ key: 'discard',
286
+ label: 'Discard draft',
287
+ icon: /*#__PURE__*/ _jsx(MdiIcon, {
288
+ path: mdiDeleteOutline.path,
289
+ size: 0.8
290
+ }),
291
+ destructive: true,
292
+ disabled: state !== 'draft' || Boolean(discardingId),
293
+ disabledReason: (_DISCARD_REFUSAL_state = DISCARD_REFUSAL[state]) != null ? _DISCARD_REFUSAL_state : 'Only a draft can be discarded',
294
+ onClick: ()=>void handleDiscard(email)
295
+ }
296
+ ];
297
+ };
298
+ const [createOpen, setCreateOpen] = useState(false);
299
+ const [creating, setCreating] = useState(false);
300
+ const campaignSendApi = useCampaignSendApi(hostId);
301
+ /*
302
+ * The campaigns a new email may be filed under, read only while the drawer
303
+ * is OPEN.
304
+ *
305
+ * A null query opens no listener, so the list costs what it always did until
306
+ * somebody asks to write something. Mounting this unconditionally would put
307
+ * a second collection read on every reader who came to look at the table,
308
+ * which is the cost the whole surface is routed to avoid.
309
+ */ const { data: campaignDocs } = useFirestoreCollection(()=>createOpen ? collectionCeiling(collection(firestore, 'hosts', hostId, 'emailCampaigns'), CONTAINER_CEILING) : null, [
310
+ firestore,
311
+ hostId,
312
+ createOpen
313
+ ], {
314
+ idField: '$id'
315
+ });
316
+ const campaignOptions = useMemo(()=>[
317
+ ...campaignDocs != null ? campaignDocs : []
318
+ ].map((campaign)=>({
319
+ value: String(campaign.$id),
320
+ label: String(campaign.name || 'Untitled campaign')
321
+ })).sort((a, b)=>a.label.localeCompare(b.label)), [
322
+ campaignDocs
323
+ ]);
324
+ /*==========================================
325
+ * CREATE, THEN GO TO THE EMAIL'S OWN PAGE.
326
+ *
327
+ * The drawer collects only what it takes to MINT the record — the friendly
328
+ * name, and the campaign it belongs to. Everything else about the email is
329
+ * written on the email's own page, which is where a record is edited
330
+ * throughout this console: a list page carries no form.
331
+ *
332
+ * The record is real from this moment: `/marketing/campaigns/{id}` resolves,
333
+ * the row appears in the table below as a Draft, and the id it is created
334
+ * under is the id it keeps when it is eventually sent. It costs nothing to
335
+ * exist — the route reserves no allowance and moves no meter for a draft,
336
+ * and the scheduled processor only ever picks up `scheduled`.
337
+ *=========================================*/ const handleCreate = useCallback(async (values)=>{
338
+ if (creating) return;
339
+ setCreating(true);
340
+ try {
341
+ var _values_displayName;
342
+ const { response, payload } = await campaignSendApi(_extends({
343
+ action: 'draft',
344
+ displayName: String((_values_displayName = values.displayName) != null ? _values_displayName : '').trim()
345
+ }, values.emailCampaignId ? {
346
+ emailCampaignId: String(values.emailCampaignId)
347
+ } : {}));
348
+ if (!response.ok || !(payload == null ? void 0 : payload.campaignId)) {
349
+ var _ref;
350
+ return void enqueueSnackbar((_ref = payload == null ? void 0 : payload.error) != null ? _ref : 'This email could not be created', {
351
+ variant: 'warning',
352
+ allowDuplicate: true
353
+ });
354
+ }
355
+ setCreateOpen(false);
356
+ /*
357
+ * Straight to where it is WRITTEN. The drawer collected the name and
358
+ * the campaign; the record now exists and holds nothing else, so the
359
+ * next thing to do with it is compose it — and its own page is a
360
+ * report of a send that has not happened.
361
+ */ router.push(`${basePath}/messages/${payload.campaignId}/edit`);
362
+ } catch (error) {
363
+ console.error(error);
364
+ enqueueSnackbar('This email could not be created', {
365
+ variant: 'error',
366
+ allowDuplicate: true
367
+ });
368
+ } finally{
369
+ setCreating(false);
370
+ }
371
+ }, [
372
+ basePath,
373
+ campaignSendApi,
374
+ creating,
375
+ enqueueSnackbar,
376
+ router
377
+ ]);
378
+ /*
379
+ * One row per message, in the order above; the whole window is in hand, so
380
+ * the grid pages it. The subject is a link AND the row opens the report: a
381
+ * click handler cannot be middle-clicked or opened in a new tab.
382
+ */ const columns = [
383
+ {
384
+ field: 'subject',
385
+ headerName: 'Subject',
386
+ flex: 1,
387
+ minWidth: 220,
388
+ valueGetter: (_value, row)=>row.subject || 'Untitled email',
389
+ renderCell: ({ row, value })=>/*#__PURE__*/ _jsx(AppLink, {
390
+ href: emailHref(row),
391
+ // The row's own handler would fire too and push the same route
392
+ // twice — one history entry per back press.
393
+ onClick: (event)=>event.stopPropagation(),
394
+ children: value
395
+ })
396
+ },
397
+ {
398
+ /*
399
+ * WHAT THIS EMAIL IS DOING, not what field it stores.
400
+ *
401
+ * An email delivering an audience larger than one batch is written back
402
+ * as `scheduled` between runs, so a chip rendering the status said
403
+ * "Scheduled" about a send that had already reached five hundred people.
404
+ * The derivation reads the counters beside the status and says which of
405
+ * the two it is.
406
+ */ field: 'state',
407
+ headerName: 'State',
408
+ width: 150,
409
+ valueGetter: (_value, row)=>campaignSendDisplay(row).label,
410
+ renderCell: ({ row })=>{
411
+ const display = campaignSendDisplay(row);
412
+ return /*#__PURE__*/ _jsx(Chip, {
413
+ size: "small",
414
+ color: STATE_COLOR[display.state],
415
+ label: display.label
416
+ });
417
+ }
418
+ },
419
+ {
420
+ field: 'when',
421
+ headerName: 'When',
422
+ width: 190,
423
+ // Sorted on the time the list is ordered by, so a draft sorts by its
424
+ // creation rather than as the oldest thing on the page.
425
+ valueGetter: (_value, row)=>emailListTimeMs(row),
426
+ renderCell: ({ row })=>{
427
+ const at = emailSendTimeMs(row);
428
+ return at ? new Date(at).toLocaleString() : '—';
429
+ }
430
+ },
431
+ ...[
432
+ [
433
+ 'recipients',
434
+ 'Addressed'
435
+ ],
436
+ [
437
+ 'opens',
438
+ 'Opens'
439
+ ],
440
+ [
441
+ 'clicks',
442
+ 'Clicks'
443
+ ]
444
+ ].map(([stat, headerName])=>({
445
+ field: stat,
446
+ headerName,
447
+ type: 'number',
448
+ align: 'right',
449
+ headerAlign: 'right',
450
+ width: 110,
451
+ valueGetter: (_value, row)=>{
452
+ var _ref;
453
+ var _row_stats;
454
+ return Number((_ref = (_row_stats = row.stats) == null ? void 0 : _row_stats[stat]) != null ? _ref : 0);
455
+ },
456
+ valueFormatter: (value)=>value.toLocaleString()
457
+ })),
458
+ listActionsColumn((row)=>/*#__PURE__*/ _jsx(ListRowActions, {
459
+ label: String(row.subject || 'Untitled email'),
460
+ items: rowActions(row)
461
+ }), {
462
+ width: 72
463
+ })
464
+ ];
465
+ return /*#__PURE__*/ _jsxs(CardDisplay, {
466
+ header: 'Messages',
467
+ help: emailsDocsHelp,
468
+ HeaderProps: {
469
+ action: /*#__PURE__*/ _jsx(Button, {
470
+ size: "small",
471
+ variant: "contained",
472
+ onClick: ()=>setCreateOpen(true),
473
+ children: 'New email'
474
+ })
475
+ },
476
+ contentGutterX: true,
477
+ contentGutterY: true,
478
+ children: [
479
+ duplicate.dialog,
480
+ /*#__PURE__*/ _jsxs(Stack, {
481
+ spacing: 2,
482
+ children: [
483
+ emails.length === 0 ? /*#__PURE__*/ _jsxs(Stack, {
484
+ spacing: 2,
485
+ sx: {
486
+ alignItems: 'flex-start'
487
+ },
488
+ children: [
489
+ /*#__PURE__*/ _jsx(Typography, {
490
+ variant: "body2",
491
+ color: "text.secondary",
492
+ children: 'Nothing has been sent or scheduled yet. Write one here, or ' + 'from a campaign, and it appears in this list with its own ' + 'report.'
493
+ }),
494
+ /*#__PURE__*/ _jsx(Button, {
495
+ variant: "contained",
496
+ onClick: ()=>setCreateOpen(true),
497
+ children: 'New email'
498
+ })
499
+ ]
500
+ }) : /*#__PURE__*/ _jsx(ListTable, {
501
+ "aria-label": "Messages",
502
+ rows: emails,
503
+ columns: columns,
504
+ rowHeight: TABLE_ROW_HEIGHT,
505
+ onOpen: (_id, row)=>router.push(emailHref(row))
506
+ }),
507
+ truncated ? /*#__PURE__*/ _jsx(Alert, {
508
+ severity: "info",
509
+ children: `Showing ${EMAIL_CEILING} messages. This site has sent or ` + 'scheduled more than that, and the rest are not in this list.'
510
+ }) : null
511
+ ]
512
+ }),
513
+ /*#__PURE__*/ _jsx(CreateArtifactDrawer, {
514
+ open: createOpen,
515
+ onClose: ()=>setCreateOpen(false),
516
+ title: "New email",
517
+ submitLabel: creating ? 'Creating…' : 'Start writing',
518
+ includeDescription: false,
519
+ onSubmit: handleCreate,
520
+ extraFields: [
521
+ {
522
+ component: 'select',
523
+ name: 'emailCampaignId',
524
+ label: 'Campaign',
525
+ initialValue: '',
526
+ helperText: 'Leave this as a single send unless the email belongs with ' + 'others',
527
+ disableDefaultOption: true,
528
+ options: [
529
+ {
530
+ value: '',
531
+ label: 'Single send — not part of a campaign'
532
+ },
533
+ ...campaignOptions
534
+ ]
535
+ }
536
+ ]
537
+ })
538
+ ]
539
+ });
540
+ }
541
+ EmailsListCard.displayName = 'EmailsListCard';
542
+ export default EmailsListCard;
543
+
544
+ //# sourceMappingURL=emails-list-card.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/marketing/src/lib/components/emails-list-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 { pluginDocsHelp } from '@aglyn/aglyn'\nimport {\n mdiBullhornOutline,\n mdiContentCopy,\n mdiDeleteOutline,\n mdiEyeOutline,\n mdiPaletteOutline,\n} from '@aglyn/shared-data-mdi'\nimport {\n AppLink,\n CardDisplay,\n MdiIcon,\n useConfirmationContext,\n} from '@aglyn/shared-ui-jsx'\nimport {\n ListRowActions,\n ListTable,\n listActionsColumn,\n} from '@aglyn/shared-ui-jsx/components/list-table.component'\nimport type { RowActionsMenuItem } from '@aglyn/shared-ui-jsx/components/row-actions-menu.component'\nimport { TABLE_ROW_HEIGHT } from '@aglyn/shared-ui-jsx/const/table-pagination'\nimport { CreateArtifactDrawer } from '@aglyn/shared-ui-jsx-forms'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport {\n ceilingedWindow,\n collectionCeiling,\n} from '@aglyn/tenant-feature-instance/hooks/host-collection-queries'\nimport {\n DUPLICATE_MENU_LABEL,\n useDuplicateResource,\n useFirestore,\n useFirestoreCollection,\n} from '@aglyn/tenant-feature-instance'\nimport { Alert, Button, Chip, Stack, Typography } from '@mui/material'\nimport type { GridColDef } from '@mui/x-data-grid'\nimport { collection } from 'firebase/firestore'\nimport { useRouter } from 'next/navigation'\nimport { useCallback, useMemo, useState } from 'react'\nimport {\n campaignSendDisplay,\n CAMPAIGN_SEND_CONTAINER_FIELD,\n type CampaignSendDisplayState,\n} from '@aglyn/shared-ui-email-campaigns/model/campaign-container'\nimport {\n emailListTimeMs,\n emailSendTimeMs,\n} from '@aglyn/shared-ui-email-campaigns/model/email-record'\nimport {\n useCampaignManageApi,\n useCampaignSendApi,\n} from './use-campaign-send-api'\nimport { useMarketingHubPath } from './use-marketing-hub-path'\n\n/** How many messages one read of this list covers. */\nconst EMAIL_CEILING = 30\n\n/** How many campaigns the create drawer offers to file a new email under. */\nconst CONTAINER_CEILING = 50\n\n/**\n * Why discard is refused, keyed by the state that refuses it.\n *\n * The KEYS are persisted status values written by the send path. Each line\n * says what to do instead, because \"you cannot\" on its own leaves a merchant\n * with an email they wanted rid of and no next step — and for a scheduled one\n * the next step is a different act with a different consequence, so naming it\n * is the difference between withdrawing mail and losing the record of it.\n *\n * A state absent from here falls through to the generic refusal rather than\n * being flattened into one of these: a state this list cannot name is worth\n * seeing.\n */\nconst DISCARD_REFUSAL: Record<string, string> = {\n sent: 'This email has been sent. Its report and its unsubscribe links have to go on resolving.',\n scheduled: 'Cancel the send first — cancelling takes it off the clock and keeps the email.',\n sending: 'This email is being sent right now.',\n canceled: 'A canceled email is kept as the record that it was withdrawn.',\n}\n\n/**\n * The chip color for one display state.\n *\n * `sending` is the one worth a color: an email part way through an audience\n * larger than one batch is doing something right now, and a merchant scanning\n * the list for what needs attention should find it without reading. The rest\n * are neutral, because a finished send and a draft are not events.\n */\nconst STATE_COLOR: Partial<\n Record<CampaignSendDisplayState, 'info' | 'warning'>\n> = {\n sending: 'info',\n stopped: 'warning',\n}\n\nconst emailsDocsHelp = pluginDocsHelp('emailCampaigns', {\n anchor: '#opens--clicks',\n excerpt:\n 'Every message this site has sent or has scheduled, each with its own ' +\n 'report: what was delivered, who opened it, and which links they followed.',\n})\n\nexport interface EmailsListCardProps {\n hostId: string\n /** The emails hub URL, so a row can link to the message's own page. */\n basePath: string\n}\n\n/**\n * EVERY MESSAGE, AS AGAINST EVERY CAMPAIGN.\n *\n * A campaign groups messages; this is the messages. The two are different\n * questions — \"how did the spring promotion do\" and \"what went out on the\n * 14th, and to whom\" — and they were previously the same list because a\n * campaign document WAS a single send.\n *\n * ## Ordered in the browser, deliberately\n *\n * No SEND date is on every message: a sent one carries `sentAt` and a\n * scheduled one carries `sendAtMs`, written by two different branches of the\n * send path, and a draft carries neither — so `orderBy` on either would not\n * mis-sort this list, it would DROP half of it. `collectionCeiling` reads a\n * bounded window in document-id order and probes one past the ceiling, so the\n * rows are sorted here and the reader is told when there are more.\n *\n * Every writer stamps a `createdAtMs`, which is the field this list could be\n * ordered on in Firestore. Moving it there is a query change with the same\n * hazard as the two above — `orderBy` drops a document missing the field —\n * so it needs the corpus proven to carry one, not just the writers.\n *\n * The page is therefore a SLICE of a window this card already holds, not a\n * query: paging an id-ordered walk and re-sorting each page by date would run\n * in one order within a page and another across them.\n */\nexport function EmailsListCard(props: EmailsListCardProps) {\n const { hostId, basePath } = props\n const firestore = useFirestore()\n // The sibling hub: a campaign's page belongs to the Marketing console.\n const marketingHub = useMarketingHubPath()\n const router = useRouter()\n\n const { data: emailDocs } = useFirestoreCollection<any>(\n () =>\n collectionCeiling(\n collection(firestore, 'hosts', hostId, 'campaigns'),\n EMAIL_CEILING,\n ),\n [firestore, hostId],\n { idField: '$id' },\n )\n const { rows: readEmails, truncated } = ceilingedWindow<any>(\n emailDocs,\n EMAIL_CEILING,\n )\n /*\n * Newest first on the time each message SITS at — its send time where it\n * has one, its creation where it does not.\n *\n * A draft has neither `sentAt` nor `sendAtMs`, so sorting on the send time\n * alone gave every draft the key 0 and filed the email a merchant is in the\n * middle of writing at the very bottom of the list, behind whatever paging\n * it has. `emailListTimeMs` is the same ordering with that one gap closed;\n * a SENT message still orders by when it went out, never by when it was\n * drafted.\n */\n const emails = useMemo(\n () =>\n [...readEmails].sort(\n (a: any, b: any) => emailListTimeMs(b) - emailListTimeMs(a),\n ),\n [readEmails],\n )\n\n const emailHref = (email: any) => `${basePath}/messages/${email.$id}`\n\n const { confirm } = useConfirmationContext()\n const { enqueueSnackbar } = useSnackbar()\n // Duplicate (AGL-2936): a new draft with the message and its design, and\n // nobody to send to until the person chooses — through the manage door,\n // which is the plugin's own.\n const manageForCopy = useCampaignManageApi(hostId)\n const duplicate = useDuplicateResource({\n hostId,\n perform: async ({ sourceId, name, attemptKey }) => {\n const { response, payload } = await manageForCopy({\n action: 'duplicate',\n campaignId: sourceId,\n name,\n attemptKey,\n })\n if (!response.ok) throw new Error(payload?.error ?? 'Duplicate failed')\n return {\n id: String(payload.emailId),\n versionId: null,\n name: String(payload.name ?? name),\n }\n },\n onDuplicated: (_kind, copy) =>\n enqueueSnackbar(`Duplicated as “${copy.name}” — a draft with no audience yet`, {\n variant: 'success',\n }),\n })\n const manageApi = useCampaignManageApi(hostId)\n /** The email a discard is in flight for, so its row menu can say so. */\n const [discardingId, setDiscardingId] = useState('')\n\n /*==========================================\n * THROWING AWAY A DRAFT.\n *\n * The one removal this surface has, and it is deliberately the narrowest\n * one: an email that was never sent, whose record nobody outside the\n * console has ever seen. Everything else on this list is evidence — a sent\n * message's report is what a merchant answers a complaint with, and its id\n * is inside the HMAC of every unsubscribe footer it delivered — and a\n * scheduled one is withdrawn with Cancel, which keeps the record and takes\n * it off the clock.\n *\n * The menu already refuses anything but a draft, and so does the route.\n * That is not belt and braces: the state on screen is a snapshot that can\n * be seconds old, and the record can be claimed by `sendNow` in between.\n * The route's refusal is the one that decides, inside the transaction that\n * does the delete.\n *=========================================*/\n const handleDiscard = useCallback(\n async (email: any) => {\n if (discardingId) return\n const id = String(email?.$id ?? '')\n const name = String(email?.subject || email?.displayName || 'this draft')\n const agreed = await confirm({\n title: 'Discard this draft?',\n description:\n `${name} has not been sent to anybody, and discarding it removes ` +\n 'it for good — the subject, the message and everything else ' +\n 'written on it. There is no undo.',\n confirmationText: 'Discard',\n })\n .then(() => true)\n .catch(() => false)\n if (!agreed) return\n setDiscardingId(id)\n try {\n const { response, payload } = await manageApi({\n action: 'discardEmail',\n campaignId: id,\n })\n if (!response.ok) {\n return void enqueueSnackbar(\n payload?.error ?? 'This draft could not be discarded',\n { variant: 'warning', allowDuplicate: true },\n )\n }\n enqueueSnackbar('Draft discarded', {\n variant: 'success',\n persist: false,\n })\n } catch (error) {\n console.error(error)\n enqueueSnackbar('This draft could not be discarded', {\n variant: 'error',\n allowDuplicate: true,\n })\n } finally {\n setDiscardingId('')\n }\n },\n [confirm, discardingId, enqueueSnackbar, manageApi],\n )\n\n /**\n * What a message can be opened INTO, from the list.\n *\n * All three are places the message's own report already links to, moved one\n * screen earlier: the report itself, the campaign it belongs to, and the\n * template it was rendered from. A message need have neither of the last\n * two — one sent before campaigns grouped anything names no container, and\n * one composed inline was built from no template — so those entries are\n * shown DISABLED with the reason rather than hidden. A control that\n * disappears and a control that does not apply look identical, and only one\n * of them tells the reader which case they are in.\n *\n * DISCARD is the fourth entry and is offered on the same terms: a draft can\n * be thrown away, and nothing else can. It stays visible on a sent or\n * scheduled message carrying the reason it is refused, because that is the\n * honest answer to “how do I get rid of this” — and the route refuses it\n * too, so the menu is describing a rule rather than being one.\n */\n const rowActions = (email: any): RowActionsMenuItem[] => {\n const containerId = String(email?.[CAMPAIGN_SEND_CONTAINER_FIELD] ?? '')\n const templateScreenId = String(email?.templateScreenId ?? '')\n const state = String(email?.status ?? '')\n return [\n {\n key: 'details',\n label: 'Open report',\n icon: <MdiIcon path={mdiEyeOutline.path} size={0.8} />,\n href: emailHref(email),\n },\n {\n key: 'campaign',\n label: 'Open its campaign',\n icon: <MdiIcon path={mdiBullhornOutline.path} size={0.8} />,\n // The campaign's page belongs to the Marketing console, so this one\n // href is built from the sibling hub rather than this surface's own.\n href:\n containerId && marketingHub\n ? `${marketingHub}/campaigns/${containerId}`\n : undefined,\n disabled: !containerId || !marketingHub,\n disabledReason: containerId\n ? 'This site’s console URL has not resolved yet'\n : 'Sent before campaigns grouped their emails, so it belongs to none',\n },\n {\n key: 'template',\n label: 'Open its template',\n icon: <MdiIcon path={mdiPaletteOutline.path} size={0.8} />,\n href: templateScreenId\n ? `${basePath}/templates/${templateScreenId}`\n : undefined,\n disabled: !templateScreenId,\n disabledReason: 'This message was not built from a template',\n },\n {\n key: 'duplicate',\n label: DUPLICATE_MENU_LABEL,\n icon: <MdiIcon path={mdiContentCopy.path} size={0.8} />,\n onClick: () =>\n duplicate.request('campaign', {\n id: String(email.$id),\n name: String(email?.displayName ?? email?.subject ?? ''),\n }),\n },\n {\n key: 'discard',\n label: 'Discard draft',\n icon: <MdiIcon path={mdiDeleteOutline.path} size={0.8} />,\n destructive: true,\n disabled: state !== 'draft' || Boolean(discardingId),\n disabledReason: DISCARD_REFUSAL[state] ?? 'Only a draft can be discarded',\n onClick: () => void handleDiscard(email),\n },\n ]\n }\n\n const [createOpen, setCreateOpen] = useState(false)\n const [creating, setCreating] = useState(false)\n const campaignSendApi = useCampaignSendApi(hostId)\n\n /*\n * The campaigns a new email may be filed under, read only while the drawer\n * is OPEN.\n *\n * A null query opens no listener, so the list costs what it always did until\n * somebody asks to write something. Mounting this unconditionally would put\n * a second collection read on every reader who came to look at the table,\n * which is the cost the whole surface is routed to avoid.\n */\n const { data: campaignDocs } = useFirestoreCollection<any>(\n () =>\n createOpen\n ? collectionCeiling(\n collection(firestore, 'hosts', hostId, 'emailCampaigns'),\n CONTAINER_CEILING,\n )\n : null,\n [firestore, hostId, createOpen],\n { idField: '$id' },\n )\n const campaignOptions = useMemo(\n () =>\n [...(campaignDocs ?? [])]\n .map((campaign: any) => ({\n value: String(campaign.$id),\n label: String(campaign.name || 'Untitled campaign'),\n }))\n .sort((a, b) => a.label.localeCompare(b.label)),\n [campaignDocs],\n )\n\n /*==========================================\n * CREATE, THEN GO TO THE EMAIL'S OWN PAGE.\n *\n * The drawer collects only what it takes to MINT the record — the friendly\n * name, and the campaign it belongs to. Everything else about the email is\n * written on the email's own page, which is where a record is edited\n * throughout this console: a list page carries no form.\n *\n * The record is real from this moment: `/marketing/campaigns/{id}` resolves,\n * the row appears in the table below as a Draft, and the id it is created\n * under is the id it keeps when it is eventually sent. It costs nothing to\n * exist — the route reserves no allowance and moves no meter for a draft,\n * and the scheduled processor only ever picks up `scheduled`.\n *=========================================*/\n const handleCreate = useCallback(\n async (values: Record<string, any>) => {\n if (creating) return\n setCreating(true)\n try {\n const { response, payload } = await campaignSendApi({\n action: 'draft',\n displayName: String(values.displayName ?? '').trim(),\n ...(values.emailCampaignId\n ? { emailCampaignId: String(values.emailCampaignId) }\n : {}),\n })\n if (!response.ok || !payload?.campaignId) {\n return void enqueueSnackbar(\n payload?.error ?? 'This email could not be created',\n { variant: 'warning', allowDuplicate: true },\n )\n }\n setCreateOpen(false)\n /*\n * Straight to where it is WRITTEN. The drawer collected the name and\n * the campaign; the record now exists and holds nothing else, so the\n * next thing to do with it is compose it — and its own page is a\n * report of a send that has not happened.\n */\n router.push(`${basePath}/messages/${payload.campaignId}/edit`)\n } catch (error) {\n console.error(error)\n enqueueSnackbar('This email could not be created', {\n variant: 'error',\n allowDuplicate: true,\n })\n } finally {\n setCreating(false)\n }\n },\n [basePath, campaignSendApi, creating, enqueueSnackbar, router],\n )\n\n /*\n * One row per message, in the order above; the whole window is in hand, so\n * the grid pages it. The subject is a link AND the row opens the report: a\n * click handler cannot be middle-clicked or opened in a new tab.\n */\n const columns: GridColDef[] = [\n {\n field: 'subject',\n headerName: 'Subject',\n flex: 1,\n minWidth: 220,\n valueGetter: (_value, row) => row.subject || 'Untitled email',\n renderCell: ({ row, value }) => (\n <AppLink\n href={emailHref(row)}\n // The row's own handler would fire too and push the same route\n // twice — one history entry per back press.\n onClick={(event: { stopPropagation: () => void }) =>\n event.stopPropagation()\n }\n >\n {value}\n </AppLink>\n ),\n },\n {\n /*\n * WHAT THIS EMAIL IS DOING, not what field it stores.\n *\n * An email delivering an audience larger than one batch is written back\n * as `scheduled` between runs, so a chip rendering the status said\n * \"Scheduled\" about a send that had already reached five hundred people.\n * The derivation reads the counters beside the status and says which of\n * the two it is.\n */\n field: 'state',\n headerName: 'State',\n width: 150,\n valueGetter: (_value, row) => campaignSendDisplay(row).label,\n renderCell: ({ row }) => {\n const display = campaignSendDisplay(row)\n return (\n <Chip\n size=\"small\"\n color={STATE_COLOR[display.state]}\n label={display.label}\n />\n )\n },\n },\n {\n field: 'when',\n headerName: 'When',\n width: 190,\n // Sorted on the time the list is ordered by, so a draft sorts by its\n // creation rather than as the oldest thing on the page.\n valueGetter: (_value, row) => emailListTimeMs(row),\n renderCell: ({ row }) => {\n const at = emailSendTimeMs(row)\n return at ? new Date(at).toLocaleString() : '—'\n },\n },\n ...(\n [\n ['recipients', 'Addressed'],\n ['opens', 'Opens'],\n ['clicks', 'Clicks'],\n ] as const\n ).map(\n ([stat, headerName]): GridColDef => ({\n field: stat,\n headerName,\n type: 'number',\n align: 'right',\n headerAlign: 'right',\n width: 110,\n valueGetter: (_value, row) => Number(row.stats?.[stat] ?? 0),\n valueFormatter: (value: number) => value.toLocaleString(),\n }),\n ),\n listActionsColumn(\n (row) => (\n <ListRowActions\n label={String(row.subject || 'Untitled email')}\n items={rowActions(row)}\n />\n ),\n { width: 72 },\n ),\n ]\n\n return (\n <CardDisplay\n header={'Messages'}\n help={emailsDocsHelp}\n HeaderProps={{\n action: (\n <Button\n size=\"small\"\n variant=\"contained\"\n onClick={() => setCreateOpen(true)}\n >\n {'New email'}\n </Button>\n ),\n }}\n contentGutterX\n contentGutterY\n >\n {duplicate.dialog}\n <Stack spacing={2}>\n {emails.length === 0 ? (\n <Stack spacing={2} sx={{ alignItems: 'flex-start' }}>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Nothing has been sent or scheduled yet. Write one here, or ' +\n 'from a campaign, and it appears in this list with its own ' +\n 'report.'}\n </Typography>\n <Button variant=\"contained\" onClick={() => setCreateOpen(true)}>\n {'New email'}\n </Button>\n </Stack>\n ) : (\n <ListTable\n aria-label=\"Messages\"\n rows={emails}\n columns={columns}\n rowHeight={TABLE_ROW_HEIGHT}\n onOpen={(_id, row) => router.push(emailHref(row))}\n />\n )}\n {truncated ? (\n <Alert severity=\"info\">\n {`Showing ${EMAIL_CEILING} messages. This site has sent or ` +\n 'scheduled more than that, and the rest are not in this list.'}\n </Alert>\n ) : null}\n </Stack>\n {/*\n AN EMAIL WRITTEN HERE BELONGS TO A CAMPAIGN, OR TO NO CAMPAIGN.\n\n The second is a real answer and not a gap in the model. A send with no\n container is what the product has always had — every message that\n predates campaigns is one — and `campaignListRows` adopts each of them\n as a campaign of one at read time, which is the \"Single send\" chip on\n the campaigns table. So composing from this list mints nothing, files\n nothing, and requires nobody to invent a campaign first: it leaves the\n container empty, and the send that results is presented the way every\n containerless send already is.\n\n Offering the campaigns anyway is what stops the opposite mistake — a\n merchant who DOES have a spring campaign writing its third email into\n a single send that never joins the rollup.\n */}\n <CreateArtifactDrawer\n open={createOpen}\n onClose={() => setCreateOpen(false)}\n title=\"New email\"\n submitLabel={creating ? 'Creating…' : 'Start writing'}\n includeDescription={false}\n onSubmit={handleCreate}\n extraFields={[\n {\n component: 'select',\n name: 'emailCampaignId',\n label: 'Campaign',\n initialValue: '',\n helperText:\n 'Leave this as a single send unless the email belongs with ' +\n 'others',\n disableDefaultOption: true,\n options: [\n { value: '', label: 'Single send — not part of a campaign' },\n ...campaignOptions,\n ],\n },\n ]}\n />\n </CardDisplay>\n )\n}\nEmailsListCard.displayName = 'EmailsListCard'\n\nexport default EmailsListCard\n"],"names":["pluginDocsHelp","mdiBullhornOutline","mdiContentCopy","mdiDeleteOutline","mdiEyeOutline","mdiPaletteOutline","AppLink","CardDisplay","MdiIcon","useConfirmationContext","ListRowActions","ListTable","listActionsColumn","TABLE_ROW_HEIGHT","CreateArtifactDrawer","useSnackbar","ceilingedWindow","collectionCeiling","DUPLICATE_MENU_LABEL","useDuplicateResource","useFirestore","useFirestoreCollection","Alert","Button","Chip","Stack","Typography","collection","useRouter","useCallback","useMemo","useState","campaignSendDisplay","CAMPAIGN_SEND_CONTAINER_FIELD","emailListTimeMs","emailSendTimeMs","useCampaignManageApi","useCampaignSendApi","useMarketingHubPath","EMAIL_CEILING","CONTAINER_CEILING","DISCARD_REFUSAL","sent","scheduled","sending","canceled","STATE_COLOR","stopped","emailsDocsHelp","anchor","excerpt","EmailsListCard","props","hostId","basePath","firestore","marketingHub","router","data","emailDocs","idField","rows","readEmails","truncated","emails","sort","a","b","emailHref","email","$id","confirm","enqueueSnackbar","manageForCopy","duplicate","perform","sourceId","name","attemptKey","payload","response","action","campaignId","ok","Error","error","id","String","emailId","versionId","onDuplicated","_kind","copy","variant","manageApi","discardingId","setDiscardingId","handleDiscard","subject","displayName","agreed","title","description","confirmationText","then","catch","allowDuplicate","persist","console","rowActions","containerId","templateScreenId","state","status","key","label","icon","path","size","href","undefined","disabled","disabledReason","onClick","request","destructive","Boolean","createOpen","setCreateOpen","creating","setCreating","campaignSendApi","campaignDocs","campaignOptions","map","campaign","value","localeCompare","handleCreate","values","trim","emailCampaignId","push","columns","field","headerName","flex","minWidth","valueGetter","_value","row","renderCell","event","stopPropagation","width","display","color","at","Date","toLocaleString","stat","type","align","headerAlign","Number","stats","valueFormatter","items","header","help","HeaderProps","contentGutterX","contentGutterY","dialog","spacing","length","sx","alignItems","aria-label","rowHeight","onOpen","_id","severity","open","onClose","submitLabel","includeDescription","onSubmit","extraFields","component","initialValue","helperText","disableDefaultOption","options"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SAASA,cAAc,QAAQ,eAAc;AAC7C,SACEC,kBAAkB,EAClBC,cAAc,EACdC,gBAAgB,EAChBC,aAAa,EACbC,iBAAiB,QACZ,yBAAwB;AAC/B,SACEC,OAAO,EACPC,WAAW,EACXC,OAAO,EACPC,sBAAsB,QACjB,uBAAsB;AAC7B,SACEC,cAAc,EACdC,SAAS,EACTC,iBAAiB,QACZ,uDAAsD;AAE7D,SAASC,gBAAgB,QAAQ,8CAA6C;AAC9E,SAASC,oBAAoB,QAAQ,6BAA4B;AACjE,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SACEC,eAAe,EACfC,iBAAiB,QACZ,+DAA8D;AACrE,SACEC,oBAAoB,EACpBC,oBAAoB,EACpBC,YAAY,EACZC,sBAAsB,QACjB,iCAAgC;AACvC,SAASC,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAEC,UAAU,QAAQ,gBAAe;AAEtE,SAASC,UAAU,QAAQ,qBAAoB;AAC/C,SAASC,SAAS,QAAQ,kBAAiB;AAC3C,SAASC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AACtD,SACEC,mBAAmB,EACnBC,6BAA6B,QAExB,4DAA2D;AAClE,SACEC,eAAe,EACfC,eAAe,QACV,sDAAqD;AAC5D,SACEC,oBAAoB,EACpBC,kBAAkB,QACb,6BAAyB;AAChC,SAASC,mBAAmB,QAAQ,8BAA0B;AAE9D,oDAAoD,GACpD,MAAMC,gBAAgB;AAEtB,2EAA2E,GAC3E,MAAMC,oBAAoB;AAE1B;;;;;;;;;;;;CAYC,GACD,MAAMC,kBAA0C;IAC9CC,MAAM;IACNC,WAAW;IACXC,SAAS;IACTC,UAAU;AACZ;AAEA;;;;;;;CAOC,GACD,MAAMC,cAEF;IACFF,SAAS;IACTG,SAAS;AACX;AAEA,MAAMC,iBA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