@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,1180 @@
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, Fragment as _Fragment } from "react/jsx-runtime";
19
+ import { PageHeaderRecord, pluginDocsHelp } from "@aglyn/aglyn";
20
+ import { mdiCalendarClockOutline, mdiCloseCircleOutline, mdiDeleteOutline, mdiPencilOutline } from "@aglyn/shared-data-mdi";
21
+ import { AppLink, CardDisplay, MdiIcon, useConfirmationContext } from "@aglyn/shared-ui-jsx";
22
+ import RowActionsMenu from "@aglyn/shared-ui-jsx/components/row-actions-menu.component";
23
+ import { ScrollTable } from "@aglyn/shared-ui-jsx/components/scroll-table.component";
24
+ import { useSnackbar } from "@aglyn/shared-ui-snackstack";
25
+ import { useFirestore, useFirestoreDoc } from "@aglyn/tenant-feature-instance";
26
+ import { Alert, Button, Chip, Divider, Stack, TableBody, TableCell, TableHead, TableRow, Typography } from "@mui/material";
27
+ import { doc } from "firebase/firestore";
28
+ import { useRouter } from "next/navigation";
29
+ import { useCallback, useMemo, useState } from "react";
30
+ import { campaignLinkReport, campaignReport } from "@aglyn/shared-ui-email-campaigns/model/campaign-report";
31
+ import { campaignSendDisplay, CAMPAIGN_SEND_CONTAINER_FIELD } from "@aglyn/shared-ui-email-campaigns/model/campaign-container";
32
+ import { emailAudienceLabel, emailIsUnsent, emailSendTimeMs, emailSentAs } from "@aglyn/shared-ui-email-campaigns/model/email-record";
33
+ import { emailPlainTextState } from "@aglyn/aglyn/app-utils/recipient-email-render";
34
+ import { useMarketingHubPath } from "./use-marketing-hub-path.js";
35
+ import { CampaignDesignPreview as EmailDesignPreview } from "./campaign-email-zones.js";
36
+ import EmailEditDrawer from "./email-edit-drawer.js";
37
+ import EmailRecipientsCard from "./email-recipients-card.js";
38
+ import { Figure, percent, RateRow, Section } from "@aglyn/shared-ui-email-campaigns/components/report-figures";
39
+ import { useCampaignManageApi, useCampaignSendApi } from "./use-campaign-send-api.js";
40
+ const previewDocsHelp = pluginDocsHelp('emailCampaigns', {
41
+ anchor: '#the-campaign-report',
42
+ excerpt: 'The email as an inbox receives it, drawn by the same renderer the send ' + 'path uses. Merge tokens are left standing — a real send fills them from ' + 'each recipient.'
43
+ });
44
+ const emailDocsHelp = pluginDocsHelp('emailCampaigns', {
45
+ anchor: '#the-campaign-report',
46
+ excerpt: 'One email: what it looked like, who it went to, what was delivered, ' + 'and which links were followed — each rate over the population it is ' + 'measured against.'
47
+ });
48
+ /**
49
+ * ONE MESSAGE: what it looked like, where it went, and what it did.
50
+ *
51
+ * ## The template it was built from, drawn as it stands NOW
52
+ *
53
+ * The preview renders the template's CURRENT version, because the HTML that
54
+ * was actually mailed is not stored — it is rendered per recipient at send
55
+ * time, with that recipient's merge values in it, and keeping a copy per
56
+ * message would be a copy of the whole email per address. So a message sent
57
+ * before its template was last edited previews as the template is today, and
58
+ * the frame says so rather than letting a reader take it for a record of what
59
+ * went out.
60
+ *
61
+ * ## Every rate names its denominator
62
+ *
63
+ * The arithmetic is `campaign-report.ts` — the same pure module the campaign
64
+ * report reads — so open rate over `delivered` and click rate over `delivered`
65
+ * are computed once, carry their own denominator labels, and come back `null`
66
+ * rather than 0% when they cannot honestly be taken. Nothing on this screen
67
+ * divides anything.
68
+ *
69
+ * ## What this page reads
70
+ *
71
+ * Four documents: the message, its link rollup, the template screen and the
72
+ * template's version. None of them grows with the size of the send. The
73
+ * recipient list is the one read that does, and it is its own card with its
74
+ * own request.
75
+ */ export function EmailDetail(props) {
76
+ var _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _sentAs_fromName, _sentAs_replyTo, _ref7, _ref8;
77
+ const { hostId, emailId, basePath } = props;
78
+ // The sibling hub: a campaign's page belongs to the Marketing console.
79
+ const marketingHub = useMarketingHubPath();
80
+ const firestore = useFirestore();
81
+ const { data: email, status } = useFirestoreDoc(()=>doc(firestore, 'hosts', hostId, 'campaigns', emailId), [
82
+ firestore,
83
+ hostId,
84
+ emailId
85
+ ]);
86
+ const notFound = status !== 'loading' && !email;
87
+ /*
88
+ * The link rollup, its own document rather than a field on the message.
89
+ *
90
+ * A map of destinations grows with the content, and the message document is
91
+ * read by the list, the glance widget and the send path; putting an
92
+ * unbounded map on it would make every one of those reads larger.
93
+ */ const { data: links } = useFirestoreDoc(()=>doc(firestore, 'hosts', hostId, 'campaigns', emailId, 'reports', 'links'), [
94
+ firestore,
95
+ hostId,
96
+ emailId
97
+ ]);
98
+ const templateScreenId = email == null ? void 0 : email.templateScreenId;
99
+ const { data: template } = useFirestoreDoc(()=>templateScreenId ? doc(firestore, 'hosts', hostId, 'screens', templateScreenId) : null, [
100
+ firestore,
101
+ hostId,
102
+ templateScreenId
103
+ ]);
104
+ const templateVersionId = template == null ? void 0 : template.versionId;
105
+ const { data: templateVersion } = useFirestoreDoc(()=>templateScreenId && templateVersionId ? doc(firestore, 'hosts', hostId, 'screens', templateScreenId, 'versions', templateVersionId) : null, [
106
+ firestore,
107
+ hostId,
108
+ templateScreenId,
109
+ templateVersionId
110
+ ]);
111
+ /**
112
+ * A hand-written plain-text version that no longer describes the design.
113
+ *
114
+ * Said HERE and not only in the composer, because an email can be scheduled
115
+ * and then have its design edited — after which nobody opens the composer
116
+ * again, and the send goes out with a styled half and a text half that
117
+ * disagree. This page is where somebody looks at a scheduled email, so it is
118
+ * where the fact has to be readable.
119
+ *
120
+ * Only while the email is unsent. On a sent one the text part that went out
121
+ * is history; the design moving afterwards is expected and is what the
122
+ * preview's own note already says.
123
+ */ const plainTextState = emailPlainTextState({
124
+ plainText: String((_ref = email == null ? void 0 : email.plainText) != null ? _ref : ''),
125
+ plainTextVersionId: String((_ref1 = email == null ? void 0 : email.plainTextVersionId) != null ? _ref1 : '')
126
+ }, template == null ? void 0 : template.versionId);
127
+ const report = useMemo(()=>campaignReport(email == null ? void 0 : email.stats), [
128
+ email
129
+ ]);
130
+ const linkReport = useMemo(()=>campaignLinkReport(links), [
131
+ links
132
+ ]);
133
+ const subject = String((email == null ? void 0 : email.subject) || 'Untitled email');
134
+ /*
135
+ * The composed body, kept on the send document. A message written without
136
+ * a template still has a rendered HTML part in the inbox, so this is what
137
+ * the preview draws for one.
138
+ */ const composedBody = String((_ref2 = email == null ? void 0 : email.body) != null ? _ref2 : '');
139
+ const sendTimeMs = email ? emailSendTimeMs(email) : 0;
140
+ const state = String((_ref3 = email == null ? void 0 : email.status) != null ? _ref3 : '');
141
+ /** What this email is doing, which the stored status alone cannot say. */ const display = campaignSendDisplay(email);
142
+ /**
143
+ * Part way through an audience larger than one batch.
144
+ *
145
+ * Stored as `scheduled` — the state the processor claims to resume it — so
146
+ * every control below that keyed on `scheduled` alone was offering an
147
+ * action about an email that is already going out.
148
+ */ const midFlight = display.state === 'sending';
149
+ /**
150
+ * This email has not gone to anybody yet.
151
+ *
152
+ * Everything below the state table is a REPORT, and an unsent email has
153
+ * nothing to report — no `stats` at all. Drawing the figures anyway would
154
+ * fill the page with zeros and a delivery rate of 0%, which is the reading
155
+ * "this reached nobody" rather than "this has not been sent", and those are
156
+ * different facts about an email.
157
+ */ const unsent = emailIsUnsent(email);
158
+ /** The merchant's own name for this email, where one was given. */ const displayName = String((_ref4 = email == null ? void 0 : email.displayName) != null ? _ref4 : '');
159
+ /**
160
+ * How many times this email has been sent, and when the last one was.
161
+ *
162
+ * A message written before an email could be sent twice carries neither, and
163
+ * one send is what an absent count means — not zero.
164
+ */ const sendCount = Number((_ref5 = email == null ? void 0 : email.sendCount) != null ? _ref5 : 1) || 1;
165
+ const lastSentMs = (email == null ? void 0 : email.lastSentAt) ? emailSendTimeMs({
166
+ sentAt: email.lastSentAt
167
+ }) : 0;
168
+ /**
169
+ * The sender this message actually left with, as the SEND recorded it.
170
+ *
171
+ * Read, never composed. The site's sending identity is a setting: a
172
+ * merchant who verifies a new domain in November has not changed what went
173
+ * out in March, and resolving the identity here would answer "what would
174
+ * this send as today" on a page whose whole subject is a message that
175
+ * already went. Exactly the rule the list name beside it follows.
176
+ */ const sentAs = emailSentAs(email);
177
+ /*
178
+ * The campaign this message belongs to.
179
+ *
180
+ * `emailCampaignId` — {@link CAMPAIGN_SEND_CONTAINER_FIELD} — is the one
181
+ * linkage, and it is deliberately not spelled `campaignId`: on a message
182
+ * document that name already means the message's OWN id, which is what the
183
+ * report route addresses and what every delivered unsubscribe footer
184
+ * carries as `cid=`.
185
+ *
186
+ * The fallback is the migration. A message written before campaigns grouped
187
+ * anything names no container, and its own id IS the campaign the URL
188
+ * resolves — the campaign detail route answers an id it does not recognize
189
+ * as a container with that message's own report.
190
+ */ const campaignId = String((_ref6 = email == null ? void 0 : email[CAMPAIGN_SEND_CONTAINER_FIELD]) != null ? _ref6 : emailId);
191
+ /*==========================================
192
+ * SENDING THIS EMAIL TO MORE PEOPLE.
193
+ *
194
+ * The whole control is a confirmation and one POST. Every decision it looks
195
+ * like it is making — who is left, who is suppressed, whether there is
196
+ * allowance and hourly room — is made by the send path, which is also the
197
+ * path the original send took; asking any of it here would be a second set
198
+ * of rules to disagree with the first.
199
+ *
200
+ * Two requests rather than one, and the first is a READ. `dryRun` runs the
201
+ * whole resolution and writes nothing, so the confirmation can say how many
202
+ * people this would reach before the merchant agrees to it. A send is the
203
+ * one action on this page that cannot be taken back, and "Send to more
204
+ * recipients?" with no number in it is a button nobody can answer honestly.
205
+ *=========================================*/ const campaignSendApi = useCampaignSendApi(hostId);
206
+ const { confirm } = useConfirmationContext();
207
+ const { enqueueSnackbar } = useSnackbar();
208
+ const [sendingMore, setSendingMore] = useState(false);
209
+ const handleSendToMore = useCallback(async ()=>{
210
+ if (sendingMore) return;
211
+ setSendingMore(true);
212
+ try {
213
+ var _ref, _ref1, _ref2;
214
+ var _counted_payload, _counted_payload1, _result_payload;
215
+ const counted = await campaignSendApi({
216
+ action: 'followUp',
217
+ campaignId: emailId,
218
+ dryRun: true
219
+ });
220
+ if (!counted.response.ok) {
221
+ var _ref3;
222
+ var _counted_payload2;
223
+ return void enqueueSnackbar((_ref3 = (_counted_payload2 = counted.payload) == null ? void 0 : _counted_payload2.error) != null ? _ref3 : 'This email cannot be sent again', {
224
+ variant: 'warning',
225
+ allowDuplicate: true
226
+ });
227
+ }
228
+ const reaching = Number((_ref = (_counted_payload = counted.payload) == null ? void 0 : _counted_payload.sendable) != null ? _ref : 0);
229
+ const already = Number((_ref1 = (_counted_payload1 = counted.payload) == null ? void 0 : _counted_payload1.alreadyReached) != null ? _ref1 : 0);
230
+ if (!reaching) {
231
+ return void enqueueSnackbar('Everyone in this audience already has this email', {
232
+ variant: 'info',
233
+ persist: false
234
+ });
235
+ }
236
+ const agreed = await confirm({
237
+ title: 'Send this email to more people?',
238
+ description: `This sends the same email to ${reaching.toLocaleString()} more ` + `${reaching === 1 ? 'person' : 'people'} in the same audience. ` + `The ${already.toLocaleString()} who already received it are not ` + 'sent it again, and its report adds the new figures to the ones ' + 'it already holds.',
239
+ confirmationText: 'Send'
240
+ }).then(()=>true).catch(()=>false);
241
+ if (!agreed) return;
242
+ const result = await campaignSendApi({
243
+ action: 'followUp',
244
+ campaignId: emailId
245
+ });
246
+ if (!result.response.ok) {
247
+ var _ref4;
248
+ var _result_payload1;
249
+ return void enqueueSnackbar((_ref4 = (_result_payload1 = result.payload) == null ? void 0 : _result_payload1.error) != null ? _ref4 : 'Send failed', {
250
+ variant: 'warning',
251
+ allowDuplicate: true
252
+ });
253
+ }
254
+ enqueueSnackbar(`Sent to ${Number((_ref2 = (_result_payload = result.payload) == null ? void 0 : _result_payload.sent) != null ? _ref2 : 0).toLocaleString()} more ` + 'recipients', {
255
+ variant: 'success',
256
+ persist: false
257
+ });
258
+ } catch (error) {
259
+ console.error(error);
260
+ enqueueSnackbar('Send failed', {
261
+ variant: 'error',
262
+ allowDuplicate: true
263
+ });
264
+ } finally{
265
+ setSendingMore(false);
266
+ }
267
+ }, [
268
+ campaignSendApi,
269
+ confirm,
270
+ emailId,
271
+ enqueueSnackbar,
272
+ sendingMore
273
+ ]);
274
+ /*==========================================
275
+ * THE LIFECYCLE ACTIONS.
276
+ *
277
+ * Every one of them is one POST to the same route the composer and the
278
+ * scheduled processor use. None of them decides anything: whether an email
279
+ * may be sent now, rescheduled or canceled is decided by the route against
280
+ * the record's stored `status`, so the rules live in one place and the
281
+ * header's job is only to offer the ones that apply.
282
+ *
283
+ * The copy is deliberately NOT sent with any of them. `sendNow` reads the
284
+ * whole message off the record — a request that could also carry a subject
285
+ * and a body would be a way to put arbitrary copy on an existing send id
286
+ * and mail it under that id's unsubscribe scope.
287
+ *=========================================*/ const [busy, setBusy] = useState('');
288
+ const [editing, setEditing] = useState(null);
289
+ /** One POST, one snackbar, one busy flag — the shape all four share. */ const runAction = useCallback(async (key, request, success, failure)=>{
290
+ if (busy) return false;
291
+ setBusy(key);
292
+ try {
293
+ const { response, payload } = await campaignSendApi(_extends({
294
+ campaignId: emailId
295
+ }, request));
296
+ if (!response.ok) {
297
+ var _ref;
298
+ enqueueSnackbar((_ref = payload == null ? void 0 : payload.error) != null ? _ref : failure, {
299
+ variant: 'warning',
300
+ allowDuplicate: true
301
+ });
302
+ return false;
303
+ }
304
+ enqueueSnackbar(success(payload), {
305
+ variant: 'success',
306
+ persist: false
307
+ });
308
+ return true;
309
+ } catch (error) {
310
+ console.error(error);
311
+ enqueueSnackbar(failure, {
312
+ variant: 'error',
313
+ allowDuplicate: true
314
+ });
315
+ return false;
316
+ } finally{
317
+ setBusy('');
318
+ }
319
+ }, [
320
+ busy,
321
+ campaignSendApi,
322
+ emailId,
323
+ enqueueSnackbar
324
+ ]);
325
+ const handleSendNow = useCallback(async ()=>{
326
+ /*
327
+ * Counted before it is offered, the same two-request shape the follow-up
328
+ * uses: `dryRun` runs the whole resolution and writes nothing, so the
329
+ * confirmation can name how many people this reaches. "Send this now?"
330
+ * with no number in it is a question nobody can answer honestly, and this
331
+ * is the action on the page that cannot be taken back.
332
+ */ if (busy) return;
333
+ setBusy('sendNow');
334
+ /*
335
+ * `null` for "the count did not happen", which is not the same answer as
336
+ * zero — zero is a real reach that the confirmation would go on to
337
+ * describe, and the failure branches below return rather than reaching it.
338
+ */ let reaching = null;
339
+ try {
340
+ const counted = await campaignSendApi({
341
+ action: 'sendNow',
342
+ campaignId: emailId,
343
+ dryRun: true
344
+ });
345
+ if (counted.response.ok) {
346
+ var _ref, _ref1;
347
+ var _counted_payload, _counted_payload1;
348
+ reaching = Number((_ref = (_ref1 = (_counted_payload = counted.payload) == null ? void 0 : _counted_payload.sendable) != null ? _ref1 : (_counted_payload1 = counted.payload) == null ? void 0 : _counted_payload1.sent) != null ? _ref : 0);
349
+ } else {
350
+ var _ref2;
351
+ var _counted_payload2;
352
+ enqueueSnackbar((_ref2 = (_counted_payload2 = counted.payload) == null ? void 0 : _counted_payload2.error) != null ? _ref2 : 'This email cannot be sent', {
353
+ variant: 'warning',
354
+ allowDuplicate: true
355
+ });
356
+ }
357
+ } catch (error) {
358
+ console.error(error);
359
+ enqueueSnackbar('Send failed', {
360
+ variant: 'error',
361
+ allowDuplicate: true
362
+ });
363
+ }
364
+ setBusy('');
365
+ if (reaching === null) return;
366
+ const agreed = await confirm({
367
+ title: 'Send this email now?',
368
+ description: `This sends it to ${reaching.toLocaleString()} ` + `${reaching === 1 ? 'person' : 'people'} straight away` + (state === 'scheduled' ? ', instead of at the time it is scheduled for. ' : '. ') + 'It cannot be taken back once it goes.',
369
+ confirmationText: 'Send now'
370
+ }).then(()=>true).catch(()=>false);
371
+ if (!agreed) return;
372
+ await runAction('sendNow', {
373
+ action: 'sendNow'
374
+ }, (payload)=>{
375
+ var _ref;
376
+ return `Sent to ${Number((_ref = payload == null ? void 0 : payload.sent) != null ? _ref : 0).toLocaleString()} recipients`;
377
+ }, 'Send failed');
378
+ }, [
379
+ busy,
380
+ campaignSendApi,
381
+ confirm,
382
+ emailId,
383
+ enqueueSnackbar,
384
+ runAction,
385
+ state
386
+ ]);
387
+ /*==========================================
388
+ * STOPPING A SEND, WHICH NOW MEANS TWO DIFFERENT THINGS.
389
+ *
390
+ * `cancel` acts on `scheduled`, and an email delivering an audience larger
391
+ * than one batch is stored as `scheduled` between runs — so the control
392
+ * that withdraws a campaign before it goes also stops one that is half
393
+ * delivered, with no change to the route. That is a real capability, and a
394
+ * merchant watching a send go wrong needs to be told which of the two they
395
+ * are about to do: nothing has been mailed, or two thousand people already
396
+ * have it and are keeping it.
397
+ *=========================================*/ const handleCancel = useCallback(async ()=>{
398
+ const reached = display.progress.reached;
399
+ const left = display.progress.remaining;
400
+ const agreed = await confirm({
401
+ title: midFlight ? 'Stop sending this email?' : 'Cancel this scheduled email?',
402
+ description: midFlight ? `It has reached ${reached.toLocaleString()} ` + `${reached === 1 ? 'person' : 'people'} so far, and stopping it ` + `leaves ${left.toLocaleString()} unaddressed. What has already ` + 'gone out cannot be taken back — those messages stay in inboxes ' + 'and keep their unsubscribe links. The email and its report are ' + 'kept, but a stopped send cannot be resumed; reaching the rest ' + 'means composing a new email.' : 'It will not be sent at the time it is scheduled for. The email ' + 'and everything written on it are kept, but a canceled email ' + 'cannot be put back on the schedule — you would compose a new one.',
403
+ confirmationText: midFlight ? 'Stop sending' : 'Cancel send'
404
+ }).then(()=>true).catch(()=>false);
405
+ if (!agreed) return;
406
+ await runAction('cancel', {
407
+ action: 'cancel'
408
+ }, ()=>midFlight ? 'This email has stopped sending' : 'This email will not be sent', 'This email could not be canceled');
409
+ }, [
410
+ confirm,
411
+ display.progress,
412
+ midFlight,
413
+ runAction
414
+ ]);
415
+ const handleReschedule = useCallback(async (values)=>{
416
+ const done = await runAction('schedule', {
417
+ action: 'schedule',
418
+ sendAtMs: values.sendAtMs
419
+ }, ()=>{
420
+ var _values_sendAtMs;
421
+ return `Scheduled for ${new Date(Number((_values_sendAtMs = values.sendAtMs) != null ? _values_sendAtMs : 0)).toLocaleString()}`;
422
+ }, 'This email could not be scheduled');
423
+ if (done) setEditing(null);
424
+ }, [
425
+ runAction
426
+ ]);
427
+ /*==========================================
428
+ * DISCARDING A DRAFT, WHICH IS THE ONE REMOVAL THIS PAGE HAS.
429
+ *
430
+ * Only ever offered on a `draft`, and refused again by the route inside the
431
+ * transaction that deletes — the state on screen is a snapshot, and
432
+ * `sendNow` claims a draft by moving it to `sending` in a transaction of
433
+ * its own, so a check made only here could remove a record the send path
434
+ * was mailing from.
435
+ *
436
+ * A sent email is never discardable from anywhere. Its report is what a
437
+ * merchant answers a complaint with, and its id is inside the HMAC of every
438
+ * unsubscribe link it delivered; a scheduled one is withdrawn with Cancel,
439
+ * which keeps the record and takes it off the clock.
440
+ *
441
+ * The reader is sent back to the list afterwards rather than left on the
442
+ * page of a record that no longer exists — which would render the "could
443
+ * not be loaded" branch and read as a failure.
444
+ *=========================================*/ const manageApi = useCampaignManageApi(hostId);
445
+ const router = useRouter();
446
+ const handleDiscard = useCallback(async ()=>{
447
+ const agreed = await confirm({
448
+ title: 'Discard this draft?',
449
+ description: 'This email 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.',
450
+ confirmationText: 'Discard'
451
+ }).then(()=>true).catch(()=>false);
452
+ if (!agreed) return;
453
+ if (busy) return;
454
+ setBusy('discard');
455
+ try {
456
+ const { response, payload } = await manageApi({
457
+ action: 'discardEmail',
458
+ campaignId: emailId
459
+ });
460
+ if (!response.ok) {
461
+ var _ref;
462
+ return void enqueueSnackbar((_ref = payload == null ? void 0 : payload.error) != null ? _ref : 'This draft could not be discarded', {
463
+ variant: 'warning',
464
+ allowDuplicate: true
465
+ });
466
+ }
467
+ enqueueSnackbar('Draft discarded', {
468
+ variant: 'success',
469
+ persist: false
470
+ });
471
+ router.push(`${basePath}/messages`);
472
+ } catch (error) {
473
+ console.error(error);
474
+ enqueueSnackbar('This draft could not be discarded', {
475
+ variant: 'error',
476
+ allowDuplicate: true
477
+ });
478
+ } finally{
479
+ setBusy('');
480
+ }
481
+ }, [
482
+ basePath,
483
+ busy,
484
+ confirm,
485
+ emailId,
486
+ enqueueSnackbar,
487
+ manageApi,
488
+ router
489
+ ]);
490
+ const handleRename = useCallback(async (values)=>{
491
+ const done = await runAction('update', {
492
+ action: 'update',
493
+ displayName: values.displayName
494
+ }, ()=>'Name updated', 'The name could not be updated');
495
+ if (done) setEditing(null);
496
+ }, [
497
+ runAction
498
+ ]);
499
+ /*==========================================
500
+ * THE HEADER, IN THREE REGISTERS.
501
+ *
502
+ * Navigation reads as navigation — a naked link button, because that is
503
+ * what it is and a reader should be able to tell without clicking. The
504
+ * PRIMARY action of the state is the one contained button, so there is
505
+ * exactly one on the page and it is the thing a merchant came to do.
506
+ * Everything else goes in the overflow, and the two irreversible entries in
507
+ * there are marked `destructive` so they carry the error color rather than
508
+ * sitting in the list looking like "Rename".
509
+ *
510
+ * `RowActionsMenu` is named for table rows and its rendering is not: it is
511
+ * a kebab `IconButton` and a `Menu` whose items support `onClick`,
512
+ * `destructive`, `disabled` and `disabledReason` — exactly what a card
513
+ * header's overflow needs. Reusing it is what keeps the menu on this page
514
+ * behaving like every other overflow menu in the console.
515
+ *=========================================*/ const scheduled = state === 'scheduled';
516
+ const draft = state === 'draft';
517
+ const sending = state === 'sending';
518
+ const overflowItems = [
519
+ {
520
+ key: 'rename',
521
+ label: 'Edit details',
522
+ icon: /*#__PURE__*/ _jsx(MdiIcon, {
523
+ path: mdiPencilOutline.path,
524
+ size: 0.8
525
+ }),
526
+ onClick: ()=>setEditing('details')
527
+ },
528
+ /*
529
+ Rescheduling an email that is ALREADY GOING OUT is not a thing to
530
+ offer: its remaining batches are due when the sender said, and moving
531
+ `sendAtMs` under the processor mid-campaign changes when the rest of a
532
+ delivery happens rather than when it starts.
533
+ */ ...(draft || scheduled) && !midFlight ? [
534
+ {
535
+ key: 'schedule',
536
+ label: scheduled ? 'Reschedule' : 'Schedule',
537
+ icon: /*#__PURE__*/ _jsx(MdiIcon, {
538
+ path: mdiCalendarClockOutline.path,
539
+ size: 0.8
540
+ }),
541
+ onClick: ()=>setEditing('schedule')
542
+ }
543
+ ] : [],
544
+ ...scheduled && !midFlight ? [
545
+ {
546
+ key: 'cancel',
547
+ label: 'Cancel send',
548
+ icon: /*#__PURE__*/ _jsx(MdiIcon, {
549
+ path: mdiCloseCircleOutline.path,
550
+ size: 0.8
551
+ }),
552
+ destructive: true,
553
+ disabled: Boolean(busy),
554
+ disabledReason: 'Another action on this email is still running',
555
+ onClick: ()=>void handleCancel()
556
+ }
557
+ ] : [],
558
+ /*
559
+ Discard is offered ONLY on a draft, and it is hidden rather than
560
+ disabled everywhere else — the opposite of how this menu treats
561
+ `Reschedule`, and deliberately.
562
+
563
+ A disabled control tells a reader that the action exists for this
564
+ record and is momentarily unavailable. There is no state in which a
565
+ sent email becomes discardable, so showing the entry greyed out on one
566
+ would be an offer this product will never honor, sitting under the
567
+ report it is promising to destroy.
568
+ */ ...draft ? [
569
+ {
570
+ key: 'discard',
571
+ label: 'Discard draft',
572
+ icon: /*#__PURE__*/ _jsx(MdiIcon, {
573
+ path: mdiDeleteOutline.path,
574
+ size: 0.8
575
+ }),
576
+ destructive: true,
577
+ disabled: Boolean(busy),
578
+ disabledReason: 'Another action on this email is still running',
579
+ onClick: ()=>void handleDiscard()
580
+ }
581
+ ] : []
582
+ ];
583
+ /*
584
+ * The one contained button, and what it is per state.
585
+ *
586
+ * `draft` and `scheduled` share it: the email has not gone out, so the act
587
+ * is to make it go. A `sent` email's is the follow-up. A `canceled` one has
588
+ * no primary act at all — it was withdrawn deliberately, and offering a way
589
+ * to un-withdraw it would be a resurrect path this model does not have —
590
+ * and neither does one that is mid-send.
591
+ */ const primaryAction = (draft || scheduled) && !midFlight ? /*#__PURE__*/ _jsx(Button, {
592
+ size: "small",
593
+ variant: "contained",
594
+ disabled: Boolean(busy),
595
+ onClick: ()=>void handleSendNow(),
596
+ children: busy === 'sendNow' ? 'Checking…' : 'Send now'
597
+ }) : midFlight ? /*
598
+ A CAMPAIGN THAT IS ALREADY GOING OUT HAS ONE ACT: STOPPING IT.
599
+
600
+ "Send now" is withheld rather than disabled, and the reason is not
601
+ cosmetic — `sendNow` re-resolves the WHOLE audience and mails it, with
602
+ no subtraction of anyone already reached, so pressing it on an email
603
+ between batches sends a second copy to every person who has had the
604
+ first. Withholding it leaves exactly one primary action, and it is the
605
+ one a merchant watching a send go wrong actually wants.
606
+ */ /*#__PURE__*/ _jsx(Button, {
607
+ size: "small",
608
+ variant: "contained",
609
+ color: "error",
610
+ disabled: Boolean(busy),
611
+ onClick: ()=>void handleCancel(),
612
+ children: 'Stop sending'
613
+ }) : state === 'sent' ? /*#__PURE__*/ _jsx(Button, {
614
+ size: "small",
615
+ variant: "contained",
616
+ disabled: sendingMore,
617
+ onClick: ()=>void handleSendToMore(),
618
+ children: sendingMore ? 'Checking…' : 'Send to more recipients'
619
+ }) : null;
620
+ /**
621
+ * WHERE THIS EMAIL IS WRITTEN, which is no longer this page.
622
+ *
623
+ * A page cannot both be "what this email did" and "write this email" — the
624
+ * first is a report the reader scrolls, the second is a form with one
625
+ * irreversible button — so the composer is its own route and this is the
626
+ * link to it. Naked, because navigation should read as navigation; the one
627
+ * CONTAINED button on this page stays the primary act of the state.
628
+ *
629
+ * Offered only while the copy can still be changed. An email part way
630
+ * through a send is stored as `scheduled`, so `midFlight` is what keeps the
631
+ * link off a message that is already reaching inboxes — the same distinction
632
+ * "Send now" is withheld on.
633
+ */ const editHref = `${basePath}/messages/${emailId}/edit`;
634
+ const headerActions = /*#__PURE__*/ _jsxs(Stack, {
635
+ direction: "row",
636
+ spacing: 1,
637
+ sx: {
638
+ alignItems: 'center'
639
+ },
640
+ children: [
641
+ /*#__PURE__*/ _jsx(Button, _extends({
642
+ component: AppLink
643
+ }, {
644
+ componentVariant: 'naked',
645
+ nativeButton: false
646
+ }, {
647
+ href: `${basePath}/messages`,
648
+ size: "small",
649
+ color: "primary",
650
+ children: 'All messages'
651
+ })),
652
+ (draft || scheduled) && !midFlight ? /*#__PURE__*/ _jsx(Button, _extends({
653
+ component: AppLink
654
+ }, {
655
+ componentVariant: 'naked',
656
+ nativeButton: false
657
+ }, {
658
+ href: editHref,
659
+ size: "small",
660
+ color: "primary",
661
+ children: 'Write this email'
662
+ })) : null,
663
+ templateScreenId ? /*#__PURE__*/ _jsx(Button, _extends({
664
+ component: AppLink
665
+ }, {
666
+ componentVariant: 'naked',
667
+ nativeButton: false
668
+ }, {
669
+ href: `${basePath}/templates/${templateScreenId}`,
670
+ size: "small",
671
+ color: "primary",
672
+ children: 'Open template'
673
+ })) : null,
674
+ primaryAction,
675
+ /*#__PURE__*/ _jsx(RowActionsMenu, {
676
+ label: subject,
677
+ items: overflowItems
678
+ })
679
+ ]
680
+ });
681
+ if (notFound) {
682
+ return /*#__PURE__*/ _jsx(CardDisplay, {
683
+ header: 'Email',
684
+ help: emailDocsHelp,
685
+ contentGutterX: true,
686
+ contentGutterY: true,
687
+ HeaderProps: {
688
+ action: headerActions
689
+ },
690
+ children: /*#__PURE__*/ _jsx(Typography, {
691
+ variant: "body2",
692
+ color: "text.secondary",
693
+ children: 'This email could not be loaded. It may have been deleted.'
694
+ })
695
+ });
696
+ }
697
+ return /*#__PURE__*/ _jsxs(Stack, {
698
+ spacing: 3,
699
+ children: [
700
+ /*#__PURE__*/ _jsx(PageHeaderRecord, {
701
+ title: email ? subject : undefined
702
+ }),
703
+ /*#__PURE__*/ _jsx(CardDisplay, {
704
+ header: 'Email',
705
+ help: emailDocsHelp,
706
+ contentGutterX: true,
707
+ contentGutterY: true,
708
+ HeaderProps: {
709
+ action: headerActions
710
+ },
711
+ children: /*#__PURE__*/ _jsxs(Stack, {
712
+ spacing: 3,
713
+ children: [
714
+ report.caveats.map((caveat)=>/*#__PURE__*/ _jsx(Alert, {
715
+ severity: "info",
716
+ children: caveat.message
717
+ }, caveat.id)),
718
+ unsent && plainTextState.stale ? /*#__PURE__*/ _jsx(Alert, {
719
+ severity: "warning",
720
+ children: 'The design has been edited since this email’s plain-text ' + 'version was written, so the two halves may no longer say the ' + 'same thing. Nothing has overwritten what was written — open ' + 'this email to read it, or take the design’s text instead.'
721
+ }) : null,
722
+ /*#__PURE__*/ _jsx(Divider, {}),
723
+ /*#__PURE__*/ _jsxs(Section, {
724
+ title: "Where this went",
725
+ children: [
726
+ /*#__PURE__*/ _jsx(ScrollTable, {
727
+ size: "small",
728
+ children: /*#__PURE__*/ _jsxs(TableBody, {
729
+ children: [
730
+ /*#__PURE__*/ _jsxs(TableRow, {
731
+ children: [
732
+ /*#__PURE__*/ _jsx(TableCell, {
733
+ children: 'State'
734
+ }),
735
+ /*#__PURE__*/ _jsx(TableCell, {
736
+ align: "right",
737
+ children: /*#__PURE__*/ _jsx(Chip, {
738
+ size: "small",
739
+ color: display.state === 'sending' ? 'info' : display.state === 'stopped' ? 'warning' : undefined,
740
+ label: display.label
741
+ })
742
+ })
743
+ ]
744
+ }),
745
+ midFlight ? /*#__PURE__*/ _jsxs(TableRow, {
746
+ children: [
747
+ /*#__PURE__*/ _jsx(TableCell, {
748
+ children: 'Next batch'
749
+ }),
750
+ /*#__PURE__*/ _jsx(TableCell, {
751
+ align: "right",
752
+ children: `${display.progress.remaining.toLocaleString()} still ` + 'to reach, ' + (display.progress.nextAtMs ? `next run ${new Date(display.progress.nextAtMs).toLocaleString()}` : 'next run due')
753
+ })
754
+ ]
755
+ }) : null,
756
+ /*#__PURE__*/ _jsxs(TableRow, {
757
+ children: [
758
+ /*#__PURE__*/ _jsx(TableCell, {
759
+ children: state === 'sent' ? 'Sent' : 'Scheduled for'
760
+ }),
761
+ /*#__PURE__*/ _jsx(TableCell, {
762
+ align: "right",
763
+ children: sendTimeMs ? new Date(sendTimeMs).toLocaleString() : 'not recorded'
764
+ })
765
+ ]
766
+ }),
767
+ sendCount > 1 ? /*#__PURE__*/ _jsxs(TableRow, {
768
+ children: [
769
+ /*#__PURE__*/ _jsx(TableCell, {
770
+ children: 'Sends'
771
+ }),
772
+ /*#__PURE__*/ _jsx(TableCell, {
773
+ align: "right",
774
+ children: `${sendCount.toLocaleString()}, most recently ` + (lastSentMs ? new Date(lastSentMs).toLocaleString() : 'not recorded')
775
+ })
776
+ ]
777
+ }) : null,
778
+ displayName ? /*#__PURE__*/ _jsxs(TableRow, {
779
+ children: [
780
+ /*#__PURE__*/ _jsx(TableCell, {
781
+ children: 'Name'
782
+ }),
783
+ /*#__PURE__*/ _jsx(TableCell, {
784
+ align: "right",
785
+ children: displayName
786
+ })
787
+ ]
788
+ }) : null,
789
+ /*#__PURE__*/ _jsxs(TableRow, {
790
+ children: [
791
+ /*#__PURE__*/ _jsx(TableCell, {
792
+ children: 'Sent as'
793
+ }),
794
+ /*#__PURE__*/ _jsx(TableCell, {
795
+ align: "right",
796
+ children: sentAs.recorded ? /*#__PURE__*/ _jsx(Typography, {
797
+ variant: "body2",
798
+ sx: {
799
+ fontFamily: 'monospace'
800
+ },
801
+ children: sentAs.from
802
+ }) : /*#__PURE__*/ _jsx(Typography, {
803
+ variant: "body2",
804
+ color: "text.secondary",
805
+ children: unsent ? 'not sent yet' : 'not recorded'
806
+ })
807
+ })
808
+ ]
809
+ }),
810
+ sentAs.recorded ? /*#__PURE__*/ _jsxs(TableRow, {
811
+ children: [
812
+ /*#__PURE__*/ _jsx(TableCell, {
813
+ children: 'From name'
814
+ }),
815
+ /*#__PURE__*/ _jsx(TableCell, {
816
+ align: "right",
817
+ children: (_sentAs_fromName = sentAs.fromName) != null ? _sentAs_fromName : /*#__PURE__*/ _jsx(Typography, {
818
+ variant: "body2",
819
+ color: "text.secondary",
820
+ children: 'The address on its own'
821
+ })
822
+ })
823
+ ]
824
+ }) : null,
825
+ sentAs.recorded ? /*#__PURE__*/ _jsxs(TableRow, {
826
+ children: [
827
+ /*#__PURE__*/ _jsx(TableCell, {
828
+ children: 'Reply-to'
829
+ }),
830
+ /*#__PURE__*/ _jsx(TableCell, {
831
+ align: "right",
832
+ children: (_sentAs_replyTo = sentAs.replyTo) != null ? _sentAs_replyTo : /*#__PURE__*/ _jsx(Typography, {
833
+ variant: "body2",
834
+ color: "text.secondary",
835
+ children: 'The sending address'
836
+ })
837
+ })
838
+ ]
839
+ }) : null,
840
+ /*#__PURE__*/ _jsxs(TableRow, {
841
+ children: [
842
+ /*#__PURE__*/ _jsx(TableCell, {
843
+ children: 'Campaign'
844
+ }),
845
+ /*#__PURE__*/ _jsx(TableCell, {
846
+ align: "right",
847
+ children: marketingHub ? /*#__PURE__*/ _jsx(AppLink, {
848
+ href: `${marketingHub}/campaigns/${campaignId}`,
849
+ children: 'Open the campaign'
850
+ }) : 'Open the campaign'
851
+ })
852
+ ]
853
+ }),
854
+ /*#__PURE__*/ _jsxs(TableRow, {
855
+ children: [
856
+ /*#__PURE__*/ _jsx(TableCell, {
857
+ children: 'List'
858
+ }),
859
+ /*#__PURE__*/ _jsx(TableCell, {
860
+ align: "right",
861
+ children: emailAudienceLabel(email)
862
+ })
863
+ ]
864
+ }),
865
+ /*#__PURE__*/ _jsxs(TableRow, {
866
+ children: [
867
+ /*#__PURE__*/ _jsx(TableCell, {
868
+ children: 'Template'
869
+ }),
870
+ /*#__PURE__*/ _jsx(TableCell, {
871
+ align: "right",
872
+ children: templateScreenId ? /*#__PURE__*/ _jsx(AppLink, {
873
+ href: `${basePath}/templates/${templateScreenId}`,
874
+ children: (_ref7 = template == null ? void 0 : template.displayName) != null ? _ref7 : 'Untitled template'
875
+ }) : /*#__PURE__*/ _jsx(Typography, {
876
+ variant: "body2",
877
+ color: "text.secondary",
878
+ children: 'Written as plain text in the composer'
879
+ })
880
+ })
881
+ ]
882
+ })
883
+ ]
884
+ })
885
+ }),
886
+ /*#__PURE__*/ _jsx(Typography, {
887
+ variant: "caption",
888
+ color: "text.secondary",
889
+ children: 'The list and the sender are recorded as they were when this ' + 'email was sent, not as this site is configured now.'
890
+ })
891
+ ]
892
+ }),
893
+ /*#__PURE__*/ _jsx(Divider, {}),
894
+ unsent ? /*#__PURE__*/ _jsx(Section, {
895
+ title: "Delivery",
896
+ children: /*#__PURE__*/ _jsx(Typography, {
897
+ variant: "body2",
898
+ color: "text.secondary",
899
+ children: sending ? 'This email is being sent right now. Its figures appear ' + 'here once the send finishes.' : draft ? 'This email has not been sent, so there is nothing to ' + 'report yet. Write this email — the link is in the ' + 'header — then send it or put it on the schedule.' : 'This email has not been sent yet. Its figures appear ' + 'here once it goes out.'
900
+ })
901
+ }) : /*#__PURE__*/ _jsxs(_Fragment, {
902
+ children: [
903
+ /*#__PURE__*/ _jsx(Section, {
904
+ title: "Delivery",
905
+ children: /*#__PURE__*/ _jsxs(Stack, {
906
+ direction: "row",
907
+ spacing: 4,
908
+ useFlexGap: true,
909
+ sx: {
910
+ flexWrap: 'wrap'
911
+ },
912
+ children: [
913
+ /*#__PURE__*/ _jsx(Figure, {
914
+ label: "Addressed",
915
+ value: report.recipients,
916
+ note: "after the per-send cap"
917
+ }),
918
+ /*#__PURE__*/ _jsx(Figure, {
919
+ label: "Sent",
920
+ value: report.sent,
921
+ note: "accepted by the provider"
922
+ }),
923
+ /*#__PURE__*/ _jsx(Figure, {
924
+ label: "Delivered",
925
+ value: report.delivered,
926
+ note: "accepted by the receiving server"
927
+ }),
928
+ /*#__PURE__*/ _jsx(Figure, {
929
+ label: "Bounced",
930
+ value: report.bounced,
931
+ note: "of sent"
932
+ }),
933
+ /*#__PURE__*/ _jsx(Figure, {
934
+ label: "Marked as spam",
935
+ value: report.complained,
936
+ note: "of delivered"
937
+ })
938
+ ]
939
+ })
940
+ }),
941
+ /*#__PURE__*/ _jsx(Divider, {}),
942
+ /*#__PURE__*/ _jsx(Section, {
943
+ title: "Engagement",
944
+ children: /*#__PURE__*/ _jsxs(Stack, {
945
+ direction: "row",
946
+ spacing: 4,
947
+ useFlexGap: true,
948
+ sx: {
949
+ flexWrap: 'wrap'
950
+ },
951
+ children: [
952
+ /*#__PURE__*/ _jsx(Figure, {
953
+ label: "Opens",
954
+ value: report.opens,
955
+ note: "every open, repeats included"
956
+ }),
957
+ /*#__PURE__*/ _jsx(Figure, {
958
+ label: "Readers who opened",
959
+ value: report.uniqueOpens,
960
+ note: "distinct recipients"
961
+ }),
962
+ /*#__PURE__*/ _jsx(Figure, {
963
+ label: "Clicks",
964
+ value: report.clicks,
965
+ note: "every click, repeats included"
966
+ }),
967
+ /*#__PURE__*/ _jsx(Figure, {
968
+ label: "Readers who clicked",
969
+ value: report.uniqueClicks,
970
+ note: "distinct recipients"
971
+ }),
972
+ /*#__PURE__*/ _jsx(Figure, {
973
+ label: "Unsubscribed",
974
+ value: report.unsubscribes,
975
+ note: "through this email's link"
976
+ })
977
+ ]
978
+ })
979
+ }),
980
+ /*#__PURE__*/ _jsx(Divider, {}),
981
+ /*#__PURE__*/ _jsx(Section, {
982
+ title: "Rates",
983
+ children: /*#__PURE__*/ _jsxs(Stack, {
984
+ spacing: 1,
985
+ children: [
986
+ /*#__PURE__*/ _jsx(RateRow, {
987
+ label: "Delivery rate",
988
+ rate: report.rates.delivery
989
+ }),
990
+ /*#__PURE__*/ _jsx(RateRow, {
991
+ label: "Open rate",
992
+ rate: report.rates.open
993
+ }),
994
+ /*#__PURE__*/ _jsx(RateRow, {
995
+ label: "Click rate",
996
+ rate: report.rates.click
997
+ }),
998
+ /*#__PURE__*/ _jsx(RateRow, {
999
+ label: "Click-to-open rate",
1000
+ rate: report.rates.clickToOpen
1001
+ }),
1002
+ /*#__PURE__*/ _jsx(RateRow, {
1003
+ label: "Bounce rate",
1004
+ rate: report.rates.bounce
1005
+ }),
1006
+ /*#__PURE__*/ _jsx(RateRow, {
1007
+ label: "Complaint rate",
1008
+ rate: report.rates.complaint
1009
+ }),
1010
+ /*#__PURE__*/ _jsx(RateRow, {
1011
+ label: "Unsubscribe rate",
1012
+ rate: report.rates.unsubscribe
1013
+ })
1014
+ ]
1015
+ })
1016
+ }),
1017
+ report.populations.length ? /*#__PURE__*/ _jsxs(_Fragment, {
1018
+ children: [
1019
+ /*#__PURE__*/ _jsx(Divider, {}),
1020
+ /*#__PURE__*/ _jsxs(Section, {
1021
+ title: "Who this was allowed to reach",
1022
+ children: [
1023
+ /*#__PURE__*/ _jsx(Typography, {
1024
+ variant: "body2",
1025
+ color: "text.secondary",
1026
+ children: 'Measured when this email was sent, and stored as it was ' + 'then. These figures describe the send, not the audience ' + 'as it stands today.'
1027
+ }),
1028
+ /*#__PURE__*/ _jsx(ScrollTable, {
1029
+ size: "small",
1030
+ children: /*#__PURE__*/ _jsx(TableBody, {
1031
+ children: report.populations.map((population)=>/*#__PURE__*/ _jsxs(TableRow, {
1032
+ children: [
1033
+ /*#__PURE__*/ _jsx(TableCell, {
1034
+ children: population.label
1035
+ }),
1036
+ /*#__PURE__*/ _jsx(TableCell, {
1037
+ align: "right",
1038
+ sx: {
1039
+ fontWeight: 'bold'
1040
+ },
1041
+ children: population.count.toLocaleString()
1042
+ }),
1043
+ /*#__PURE__*/ _jsx(TableCell, {
1044
+ align: "right",
1045
+ children: /*#__PURE__*/ _jsx(Typography, {
1046
+ variant: "caption",
1047
+ color: "text.secondary",
1048
+ children: `of ${population.of.toLocaleString()} ${population.ofLabel}`
1049
+ })
1050
+ })
1051
+ ]
1052
+ }, population.id))
1053
+ })
1054
+ })
1055
+ ]
1056
+ })
1057
+ ]
1058
+ }) : null,
1059
+ /*#__PURE__*/ _jsx(Divider, {}),
1060
+ /*#__PURE__*/ _jsx(Section, {
1061
+ title: "Links",
1062
+ children: linkReport.rows.length ? /*#__PURE__*/ _jsxs(_Fragment, {
1063
+ children: [
1064
+ /*#__PURE__*/ _jsxs(ScrollTable, {
1065
+ size: "small",
1066
+ children: [
1067
+ /*#__PURE__*/ _jsx(TableHead, {
1068
+ children: /*#__PURE__*/ _jsxs(TableRow, {
1069
+ children: [
1070
+ /*#__PURE__*/ _jsx(TableCell, {
1071
+ children: 'Destination'
1072
+ }),
1073
+ /*#__PURE__*/ _jsx(TableCell, {
1074
+ align: "right",
1075
+ children: 'Clicks'
1076
+ }),
1077
+ /*#__PURE__*/ _jsx(TableCell, {
1078
+ align: "right",
1079
+ children: 'Share'
1080
+ })
1081
+ ]
1082
+ })
1083
+ }),
1084
+ /*#__PURE__*/ _jsx(TableBody, {
1085
+ children: linkReport.rows.map((row)=>/*#__PURE__*/ _jsxs(TableRow, {
1086
+ children: [
1087
+ /*#__PURE__*/ _jsx(TableCell, {
1088
+ sx: {
1089
+ wordBreak: 'break-all'
1090
+ },
1091
+ children: row.url
1092
+ }),
1093
+ /*#__PURE__*/ _jsx(TableCell, {
1094
+ align: "right",
1095
+ sx: {
1096
+ fontWeight: 'bold'
1097
+ },
1098
+ children: row.clicks.toLocaleString()
1099
+ }),
1100
+ /*#__PURE__*/ _jsx(TableCell, {
1101
+ align: "right",
1102
+ children: row.share ? `${percent(row.share.value)} of ${row.share.denominator.toLocaleString()} ${row.share.denominatorLabel}` : '—'
1103
+ })
1104
+ ]
1105
+ }, row.url))
1106
+ })
1107
+ ]
1108
+ }),
1109
+ /*#__PURE__*/ _jsx(Typography, {
1110
+ variant: "caption",
1111
+ color: "text.secondary",
1112
+ children: 'Counted by address and path — query strings are dropped, ' + 'so two links to the same page with different tracking ' + 'parameters count as one row.'
1113
+ }),
1114
+ linkReport.unattributedClicks ? /*#__PURE__*/ _jsx(Typography, {
1115
+ variant: "caption",
1116
+ color: "text.secondary",
1117
+ children: `${linkReport.unattributedClicks.toLocaleString()} clicks ` + 'arrived without a destination and are not in this table.'
1118
+ }) : null,
1119
+ linkReport.overflowClicks ? /*#__PURE__*/ _jsx(Alert, {
1120
+ severity: "info",
1121
+ children: 'This email has more distinct destinations than the ' + `rollup keeps. ${linkReport.overflowClicks.toLocaleString()} ` + 'clicks landed on links past that limit and are counted ' + 'in the click total above but not in this table.'
1122
+ }) : null
1123
+ ]
1124
+ }) : /*#__PURE__*/ _jsx(Typography, {
1125
+ variant: "body2",
1126
+ color: "text.secondary",
1127
+ children: report.clicks ? 'Clicks were recorded for this email, but none of them ' + 'carried a destination, so there is nothing to break down ' + 'by link.' : 'No link clicks have been recorded for this email.'
1128
+ })
1129
+ })
1130
+ ]
1131
+ })
1132
+ ]
1133
+ })
1134
+ }),
1135
+ /*#__PURE__*/ _jsx(EmailRecipientsCard, {
1136
+ hostId: hostId,
1137
+ emailId: emailId
1138
+ }),
1139
+ /*#__PURE__*/ _jsx(CardDisplay, {
1140
+ header: 'Preview',
1141
+ help: previewDocsHelp,
1142
+ contentGutterX: true,
1143
+ contentGutterY: true,
1144
+ children: templateScreenId ? /*#__PURE__*/ _jsx(EmailDesignPreview, {
1145
+ hostId: hostId,
1146
+ nodes: templateVersion == null ? void 0 : templateVersion.nodes,
1147
+ loading: template === undefined || templateVersion === undefined,
1148
+ subject: subject,
1149
+ preheader: String((_ref8 = template == null ? void 0 : template.emailPreheader) != null ? _ref8 : ''),
1150
+ emptyMessage: 'The template this email was built from is empty or has ' + 'been deleted, so there is nothing to draw.',
1151
+ note: 'The template as it stands today. The mail itself is ' + 'rendered per recipient at send time and not kept, so a ' + 'template edited since this went out previews as it is now.'
1152
+ }) : /*#__PURE__*/ _jsx(EmailDesignPreview, {
1153
+ hostId: hostId,
1154
+ nodes: undefined,
1155
+ text: composedBody,
1156
+ loading: email === undefined,
1157
+ subject: subject,
1158
+ emptyMessage: 'This email carries no body, so there is nothing to draw.',
1159
+ note: 'Written as plain text in the composer. Merge tokens are ' + 'left standing here — the mail itself resolves them per ' + 'recipient at send time and is not kept.'
1160
+ })
1161
+ }),
1162
+ /*#__PURE__*/ _jsx(EmailEditDrawer, {
1163
+ open: editing !== null,
1164
+ onClose: ()=>setEditing(null),
1165
+ field: editing === 'schedule' ? 'schedule' : 'details',
1166
+ title: editing === 'schedule' ? scheduled ? 'Reschedule this email' : 'Schedule this email' : 'Edit details',
1167
+ submitLabel: editing === 'schedule' ? scheduled ? 'Reschedule' : 'Schedule' : 'Save',
1168
+ displayName: displayName,
1169
+ sendAtMs: scheduled ? sendTimeMs : 0,
1170
+ busy: Boolean(busy),
1171
+ note: editing === 'schedule' ? 'The email goes out at this time. You can send it sooner, or ' + 'cancel it, from this page.' : unsent ? 'The name is for finding this email in your own lists. The ' + 'subject and the message are written on this email’s own ' + 'compose page.' : 'This email has been sent, so its subject, message and ' + 'audience describe mail that is already in inboxes and can ' + 'no longer be changed. Its name is yours and stays editable.',
1172
+ onSubmit: (values)=>void (editing === 'schedule' ? handleReschedule(values) : handleRename(values))
1173
+ })
1174
+ ]
1175
+ });
1176
+ }
1177
+ EmailDetail.displayName = 'EmailDetail';
1178
+ export default EmailDetail;
1179
+
1180
+ //# sourceMappingURL=email-detail.js.map