@prenta/admin 2.9.3 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (283) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/dist/AdminRoot.d.ts.map +1 -1
  3. package/dist/AdminRoot.js +5 -3
  4. package/dist/AdminRoot.js.map +1 -1
  5. package/dist/__tests__/components/attribution-rows.test.js +1 -1
  6. package/dist/__tests__/components/attribution-rows.test.js.map +1 -1
  7. package/dist/__tests__/components/date-range-picker.test.d.ts +2 -0
  8. package/dist/__tests__/components/date-range-picker.test.d.ts.map +1 -0
  9. package/dist/__tests__/components/date-range-picker.test.js +59 -0
  10. package/dist/__tests__/components/date-range-picker.test.js.map +1 -0
  11. package/dist/__tests__/components/form-build-model.test.d.ts +2 -0
  12. package/dist/__tests__/components/form-build-model.test.d.ts.map +1 -0
  13. package/dist/__tests__/components/form-build-model.test.js +162 -0
  14. package/dist/__tests__/components/form-build-model.test.js.map +1 -0
  15. package/dist/__tests__/components/form-build.test.d.ts +2 -0
  16. package/dist/__tests__/components/form-build.test.d.ts.map +1 -0
  17. package/dist/__tests__/components/form-build.test.js +120 -0
  18. package/dist/__tests__/components/form-build.test.js.map +1 -0
  19. package/dist/__tests__/components/qa-a11y.render.test.js +1 -17
  20. package/dist/__tests__/components/qa-a11y.render.test.js.map +1 -1
  21. package/dist/__tests__/lib/batch-wizard.test.js +2 -0
  22. package/dist/__tests__/lib/batch-wizard.test.js.map +1 -1
  23. package/dist/__tests__/lib/forms-settings-normalize.test.d.ts +2 -0
  24. package/dist/__tests__/lib/forms-settings-normalize.test.d.ts.map +1 -0
  25. package/dist/__tests__/lib/forms-settings-normalize.test.js +16 -0
  26. package/dist/__tests__/lib/forms-settings-normalize.test.js.map +1 -0
  27. package/dist/__tests__/lib/recaptcha.test.d.ts +2 -0
  28. package/dist/__tests__/lib/recaptcha.test.d.ts.map +1 -0
  29. package/dist/__tests__/lib/recaptcha.test.js +57 -0
  30. package/dist/__tests__/lib/recaptcha.test.js.map +1 -0
  31. package/dist/__tests__/views/dashboard.test.js +105 -30
  32. package/dist/__tests__/views/dashboard.test.js.map +1 -1
  33. package/dist/__tests__/views/form-editor.render.test.js +17 -9
  34. package/dist/__tests__/views/form-editor.render.test.js.map +1 -1
  35. package/dist/__tests__/views/form-entries.render.test.js +23 -9
  36. package/dist/__tests__/views/form-entries.render.test.js.map +1 -1
  37. package/dist/__tests__/views/form-submissions.render.test.js +13 -14
  38. package/dist/__tests__/views/form-submissions.render.test.js.map +1 -1
  39. package/dist/__tests__/views/forms-list.render.test.js +139 -16
  40. package/dist/__tests__/views/forms-list.render.test.js.map +1 -1
  41. package/dist/__tests__/views/forms-settings.fixture.d.ts +3 -0
  42. package/dist/__tests__/views/forms-settings.fixture.d.ts.map +1 -0
  43. package/dist/__tests__/views/forms-settings.fixture.js +31 -0
  44. package/dist/__tests__/views/forms-settings.fixture.js.map +1 -0
  45. package/dist/__tests__/views/forms-settings.render.test.d.ts +2 -0
  46. package/dist/__tests__/views/forms-settings.render.test.d.ts.map +1 -0
  47. package/dist/__tests__/views/forms-settings.render.test.js +226 -0
  48. package/dist/__tests__/views/forms-settings.render.test.js.map +1 -0
  49. package/dist/__tests__/views/inbox-format.test.d.ts +2 -0
  50. package/dist/__tests__/views/inbox-format.test.d.ts.map +1 -0
  51. package/dist/__tests__/views/inbox-format.test.js +47 -0
  52. package/dist/__tests__/views/inbox-format.test.js.map +1 -0
  53. package/dist/__tests__/views/jobs-wizard.render.test.js +17 -3
  54. package/dist/__tests__/views/jobs-wizard.render.test.js.map +1 -1
  55. package/dist/__tests__/views/login-captcha.render.test.d.ts +2 -0
  56. package/dist/__tests__/views/login-captcha.render.test.d.ts.map +1 -0
  57. package/dist/__tests__/views/login-captcha.render.test.js +80 -0
  58. package/dist/__tests__/views/login-captcha.render.test.js.map +1 -0
  59. package/dist/__tests__/views/onboarding-block.render.test.js +9 -7
  60. package/dist/__tests__/views/onboarding-block.render.test.js.map +1 -1
  61. package/dist/components/forms/BlocklistDialog.d.ts +19 -0
  62. package/dist/components/forms/BlocklistDialog.d.ts.map +1 -0
  63. package/dist/components/forms/BlocklistDialog.js +225 -0
  64. package/dist/components/forms/BlocklistDialog.js.map +1 -0
  65. package/dist/components/forms/ExportMenu.d.ts +3 -1
  66. package/dist/components/forms/ExportMenu.d.ts.map +1 -1
  67. package/dist/components/forms/ExportMenu.js +2 -2
  68. package/dist/components/forms/ExportMenu.js.map +1 -1
  69. package/dist/components/forms/FieldOptions.d.ts +11 -0
  70. package/dist/components/forms/FieldOptions.d.ts.map +1 -0
  71. package/dist/components/forms/FieldOptions.js +106 -0
  72. package/dist/components/forms/FieldOptions.js.map +1 -0
  73. package/dist/components/forms/FormBuild.d.ts +11 -0
  74. package/dist/components/forms/FormBuild.d.ts.map +1 -0
  75. package/dist/components/forms/FormBuild.js +299 -0
  76. package/dist/components/forms/FormBuild.js.map +1 -0
  77. package/dist/components/forms/FormsListTable.d.ts +14 -0
  78. package/dist/components/forms/FormsListTable.d.ts.map +1 -0
  79. package/dist/components/forms/FormsListTable.js +84 -0
  80. package/dist/components/forms/FormsListTable.js.map +1 -0
  81. package/dist/components/forms/form-build-model.d.ts +74 -0
  82. package/dist/components/forms/form-build-model.d.ts.map +1 -0
  83. package/dist/components/forms/form-build-model.js +297 -0
  84. package/dist/components/forms/form-build-model.js.map +1 -0
  85. package/dist/components/forms/form-build-ui.d.ts +35 -0
  86. package/dist/components/forms/form-build-ui.d.ts.map +1 -0
  87. package/dist/components/forms/form-build-ui.js +59 -0
  88. package/dist/components/forms/form-build-ui.js.map +1 -0
  89. package/dist/components/forms/primitives.d.ts +3 -22
  90. package/dist/components/forms/primitives.d.ts.map +1 -1
  91. package/dist/components/forms/primitives.js +4 -19
  92. package/dist/components/forms/primitives.js.map +1 -1
  93. package/dist/components/ui/Badge.d.ts +1 -1
  94. package/dist/components/ui/Card.d.ts +1 -1
  95. package/dist/components/ui/DateRangePicker.d.ts +7 -0
  96. package/dist/components/ui/DateRangePicker.d.ts.map +1 -0
  97. package/dist/components/ui/DateRangePicker.js +112 -0
  98. package/dist/components/ui/DateRangePicker.js.map +1 -0
  99. package/dist/components/ui/Input.d.ts +1 -1
  100. package/dist/components/ui/Segmented.d.ts +3 -1
  101. package/dist/components/ui/Segmented.d.ts.map +1 -1
  102. package/dist/components/ui/Segmented.js +3 -3
  103. package/dist/components/ui/Segmented.js.map +1 -1
  104. package/dist/components/ui/StatusBadge.d.ts +3 -2
  105. package/dist/components/ui/StatusBadge.d.ts.map +1 -1
  106. package/dist/components/ui/StatusBadge.js +9 -3
  107. package/dist/components/ui/StatusBadge.js.map +1 -1
  108. package/dist/components/ui/Toggle.d.ts +1 -1
  109. package/dist/components/ui/Toggle.d.ts.map +1 -1
  110. package/dist/components/ui/Toggle.js +3 -0
  111. package/dist/components/ui/Toggle.js.map +1 -1
  112. package/dist/components/ui/UnderlineTabs.d.ts +5 -1
  113. package/dist/components/ui/UnderlineTabs.d.ts.map +1 -1
  114. package/dist/components/ui/UnderlineTabs.js +14 -11
  115. package/dist/components/ui/UnderlineTabs.js.map +1 -1
  116. package/dist/layout/Sidebar.js +3 -1
  117. package/dist/layout/Sidebar.js.map +1 -1
  118. package/dist/lib/batch-wizard.d.ts +1 -1
  119. package/dist/lib/batch-wizard.d.ts.map +1 -1
  120. package/dist/lib/batch-wizard.js +2 -2
  121. package/dist/lib/batch-wizard.js.map +1 -1
  122. package/dist/lib/entry-attribution.d.ts +13 -0
  123. package/dist/lib/entry-attribution.d.ts.map +1 -0
  124. package/dist/lib/entry-attribution.js +81 -0
  125. package/dist/lib/entry-attribution.js.map +1 -0
  126. package/dist/lib/forms-service.d.ts +133 -0
  127. package/dist/lib/forms-service.d.ts.map +1 -1
  128. package/dist/lib/forms-service.js +119 -0
  129. package/dist/lib/forms-service.js.map +1 -1
  130. package/dist/lib/job-drawer.d.ts +1 -0
  131. package/dist/lib/job-drawer.d.ts.map +1 -1
  132. package/dist/lib/job-drawer.js +23 -1
  133. package/dist/lib/job-drawer.js.map +1 -1
  134. package/dist/lib/job-view.d.ts +6 -0
  135. package/dist/lib/job-view.d.ts.map +1 -1
  136. package/dist/lib/job-view.js +7 -0
  137. package/dist/lib/job-view.js.map +1 -1
  138. package/dist/lib/recaptcha.d.ts +8 -0
  139. package/dist/lib/recaptcha.d.ts.map +1 -0
  140. package/dist/lib/recaptcha.js +73 -0
  141. package/dist/lib/recaptcha.js.map +1 -0
  142. package/dist/prenta-admin.css +1 -1
  143. package/dist/router/admin-routes.d.ts.map +1 -1
  144. package/dist/router/admin-routes.js +1 -0
  145. package/dist/router/admin-routes.js.map +1 -1
  146. package/dist/views/Dashboard.d.ts.map +1 -1
  147. package/dist/views/Dashboard.js +438 -309
  148. package/dist/views/Dashboard.js.map +1 -1
  149. package/dist/views/FormEditor.d.ts.map +1 -1
  150. package/dist/views/FormEditor.js +68 -13
  151. package/dist/views/FormEditor.js.map +1 -1
  152. package/dist/views/FormEntries.d.ts.map +1 -1
  153. package/dist/views/FormEntries.js +4 -190
  154. package/dist/views/FormEntries.js.map +1 -1
  155. package/dist/views/FormSubmissions.d.ts +1 -1
  156. package/dist/views/FormSubmissions.d.ts.map +1 -1
  157. package/dist/views/FormSubmissions.js +6 -195
  158. package/dist/views/FormSubmissions.js.map +1 -1
  159. package/dist/views/Forms.d.ts +11 -1
  160. package/dist/views/Forms.d.ts.map +1 -1
  161. package/dist/views/Forms.js +141 -93
  162. package/dist/views/Forms.js.map +1 -1
  163. package/dist/views/FormsSettings.d.ts +6 -1
  164. package/dist/views/FormsSettings.d.ts.map +1 -1
  165. package/dist/views/FormsSettings.js +527 -30
  166. package/dist/views/FormsSettings.js.map +1 -1
  167. package/dist/views/Jobs/DrawerReview.d.ts.map +1 -1
  168. package/dist/views/Jobs/DrawerReview.js +8 -7
  169. package/dist/views/Jobs/DrawerReview.js.map +1 -1
  170. package/dist/views/Jobs/NewBatchJob.d.ts.map +1 -1
  171. package/dist/views/Jobs/NewBatchJob.js +2 -1
  172. package/dist/views/Jobs/NewBatchJob.js.map +1 -1
  173. package/dist/views/Login.d.ts.map +1 -1
  174. package/dist/views/Login.js +30 -11
  175. package/dist/views/Login.js.map +1 -1
  176. package/dist/views/SpamFolder.js +1 -1
  177. package/dist/views/SpamFolder.js.map +1 -1
  178. package/dist/views/dashboard/Delta.d.ts +7 -0
  179. package/dist/views/dashboard/Delta.d.ts.map +1 -0
  180. package/dist/views/dashboard/Delta.js +21 -0
  181. package/dist/views/dashboard/Delta.js.map +1 -0
  182. package/dist/views/dashboard/KpiCard.d.ts +22 -0
  183. package/dist/views/dashboard/KpiCard.d.ts.map +1 -0
  184. package/dist/views/dashboard/KpiCard.js +15 -0
  185. package/dist/views/dashboard/KpiCard.js.map +1 -0
  186. package/dist/views/dashboard/Sparkline.d.ts +11 -0
  187. package/dist/views/dashboard/Sparkline.d.ts.map +1 -0
  188. package/dist/views/dashboard/Sparkline.js +15 -0
  189. package/dist/views/dashboard/Sparkline.js.map +1 -0
  190. package/dist/views/dashboard/TrendChart.d.ts +8 -0
  191. package/dist/views/dashboard/TrendChart.d.ts.map +1 -0
  192. package/dist/views/dashboard/TrendChart.js +98 -0
  193. package/dist/views/dashboard/TrendChart.js.map +1 -0
  194. package/dist/views/dashboard/dashboard-date.d.ts +33 -0
  195. package/dist/views/dashboard/dashboard-date.d.ts.map +1 -0
  196. package/dist/views/dashboard/dashboard-date.js +136 -0
  197. package/dist/views/dashboard/dashboard-date.js.map +1 -0
  198. package/dist/views/entries/EntriesInbox.d.ts +8 -0
  199. package/dist/views/entries/EntriesInbox.d.ts.map +1 -0
  200. package/dist/views/entries/EntriesInbox.js +516 -0
  201. package/dist/views/entries/EntriesInbox.js.map +1 -0
  202. package/dist/views/entries/inbox-format.d.ts +27 -0
  203. package/dist/views/entries/inbox-format.d.ts.map +1 -0
  204. package/dist/views/entries/inbox-format.js +119 -0
  205. package/dist/views/entries/inbox-format.js.map +1 -0
  206. package/dist/views/settings/CaptchaStatusCard.js +2 -2
  207. package/dist/views/settings/CaptchaStatusCard.js.map +1 -1
  208. package/package.json +4 -4
  209. package/src/AdminRoot.tsx +7 -3
  210. package/src/__tests__/components/attribution-rows.test.ts +1 -1
  211. package/src/__tests__/components/date-range-picker.test.tsx +69 -0
  212. package/src/__tests__/components/form-build-model.test.ts +200 -0
  213. package/src/__tests__/components/form-build.test.tsx +157 -0
  214. package/src/__tests__/components/qa-a11y.render.test.tsx +1 -29
  215. package/src/__tests__/lib/batch-wizard.test.ts +2 -0
  216. package/src/__tests__/lib/forms-settings-normalize.test.ts +17 -0
  217. package/src/__tests__/lib/recaptcha.test.ts +63 -0
  218. package/src/__tests__/views/dashboard.test.tsx +110 -32
  219. package/src/__tests__/views/form-editor.render.test.tsx +18 -10
  220. package/src/__tests__/views/form-entries.render.test.tsx +27 -9
  221. package/src/__tests__/views/form-submissions.render.test.tsx +15 -14
  222. package/src/__tests__/views/forms-list.render.test.tsx +157 -17
  223. package/src/__tests__/views/forms-settings.fixture.ts +32 -0
  224. package/src/__tests__/views/forms-settings.render.test.tsx +274 -0
  225. package/src/__tests__/views/inbox-format.test.ts +72 -0
  226. package/src/__tests__/views/jobs-wizard.render.test.tsx +18 -3
  227. package/src/__tests__/views/login-captcha.render.test.tsx +94 -0
  228. package/src/__tests__/views/onboarding-block.render.test.tsx +9 -7
  229. package/src/components/forms/BlocklistDialog.tsx +552 -0
  230. package/src/components/forms/ExportMenu.tsx +8 -2
  231. package/src/components/forms/FieldOptions.tsx +629 -0
  232. package/src/components/forms/FormBuild.tsx +900 -0
  233. package/src/components/forms/FormsListTable.tsx +300 -0
  234. package/src/components/forms/form-build-model.ts +365 -0
  235. package/src/components/forms/form-build-ui.tsx +130 -0
  236. package/src/components/forms/primitives.tsx +6 -55
  237. package/src/components/ui/DateRangePicker.tsx +358 -0
  238. package/src/components/ui/Segmented.tsx +9 -2
  239. package/src/components/ui/StatusBadge.tsx +17 -4
  240. package/src/components/ui/Toggle.tsx +3 -0
  241. package/src/components/ui/UnderlineTabs.tsx +20 -9
  242. package/src/layout/Sidebar.tsx +4 -2
  243. package/src/lib/batch-wizard.ts +2 -2
  244. package/src/lib/entry-attribution.ts +94 -0
  245. package/src/lib/forms-service.ts +243 -0
  246. package/src/lib/job-drawer.ts +21 -1
  247. package/src/lib/job-view.ts +7 -0
  248. package/src/lib/recaptcha.ts +84 -0
  249. package/src/router/admin-routes.ts +1 -0
  250. package/src/styles/theme.css +86 -0
  251. package/src/views/Dashboard.tsx +1183 -772
  252. package/src/views/FormEditor.tsx +397 -199
  253. package/src/views/FormEntries.tsx +3 -422
  254. package/src/views/FormSubmissions.tsx +5 -411
  255. package/src/views/Forms.tsx +333 -321
  256. package/src/views/FormsSettings.tsx +1616 -73
  257. package/src/views/Jobs/DrawerReview.tsx +14 -8
  258. package/src/views/Jobs/NewBatchJob.tsx +5 -1
  259. package/src/views/Login.tsx +35 -11
  260. package/src/views/SpamFolder.tsx +2 -2
  261. package/src/views/dashboard/Delta.tsx +44 -0
  262. package/src/views/dashboard/KpiCard.tsx +98 -0
  263. package/src/views/dashboard/Sparkline.tsx +51 -0
  264. package/src/views/dashboard/TrendChart.tsx +246 -0
  265. package/src/views/dashboard/dashboard-date.ts +168 -0
  266. package/src/views/entries/EntriesInbox.tsx +1277 -0
  267. package/src/views/entries/inbox-format.ts +128 -0
  268. package/src/views/settings/CaptchaStatusCard.tsx +2 -2
  269. package/dist/components/forms/EntriesTable.d.ts +0 -29
  270. package/dist/components/forms/EntriesTable.d.ts.map +0 -1
  271. package/dist/components/forms/EntriesTable.js +0 -29
  272. package/dist/components/forms/EntriesTable.js.map +0 -1
  273. package/dist/components/forms/FormEntryDetailPane.d.ts +0 -23
  274. package/dist/components/forms/FormEntryDetailPane.d.ts.map +0 -1
  275. package/dist/components/forms/FormEntryDetailPane.js +0 -208
  276. package/dist/components/forms/FormEntryDetailPane.js.map +0 -1
  277. package/dist/components/ui/PanelSection.d.ts +0 -16
  278. package/dist/components/ui/PanelSection.d.ts.map +0 -1
  279. package/dist/components/ui/PanelSection.js +0 -15
  280. package/dist/components/ui/PanelSection.js.map +0 -1
  281. package/src/components/forms/EntriesTable.tsx +0 -207
  282. package/src/components/forms/FormEntryDetailPane.tsx +0 -402
  283. package/src/components/ui/PanelSection.tsx +0 -53
@@ -4,7 +4,7 @@ import { useEffect, useRef, useState, type ReactNode } from 'react'
4
4
  import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
5
5
  import type { JobReviewItem } from '@prenta/core'
6
6
  import { Button } from '../../components/ui/Button.js'
7
- import { charLimit, linkParts } from '../../lib/job-drawer.js'
7
+ import { charLimit, linkParts, mediaReviewLabel } from '../../lib/job-drawer.js'
8
8
  import type { OnApprove, ReviewAction } from '../../lib/jobs-service.js'
9
9
  import { BusyButton } from './BusyButton.js'
10
10
  import { DrawerEmpty } from './DrawerResults.js'
@@ -13,8 +13,6 @@ import type { ReviewItems } from './useReviewItems.js'
13
13
 
14
14
  /** A link suggestion's field. It can't be edited (the server answers 400). */
15
15
  const LINK_FIELD = 'body'
16
- /** Image alt text has no draft or published state, so its Approve has no choice. */
17
- const ALT_FIELD = 'altText'
18
16
 
19
17
  /** The drawer's per-change state: the request out, and the last outcome to show. */
20
18
  export interface ReviewItemState {
@@ -28,7 +26,8 @@ const MENU_ITEM =
28
26
  /**
29
27
  * Approve, with the choice of what approving does: "Save as draft" (which
30
28
  * reads "Keep current status" on a published document, where it leaves the
31
- * change in review) or "Publish" (CONFLICTS.md §4). Alt text has no choice.
29
+ * change in review) or "Publish" (CONFLICTS.md §4). Media fields have no choice:
30
+ * an image has no draft.
32
31
  */
33
32
  function ApproveButton({
34
33
  label,
@@ -151,6 +150,8 @@ function ReviewCard({
151
150
  locked,
152
151
  }: ItemProps) {
153
152
  const link = item.field === LINK_FIELD
153
+ const fieldLabel = mediaReviewLabel(item.field)
154
+ const decorative = item.field === 'isDecorative'
154
155
  const editing = draft !== undefined && item.status === 'pending'
155
156
  const suggested = editing ? draft : (item.editedAfter ?? item.after)
156
157
  const limit = charLimit(item.field)
@@ -167,7 +168,7 @@ function ReviewCard({
167
168
  label={label}
168
169
  busy={busy === 'approve'}
169
170
  disabled={blocked}
170
- choice={item.field !== ALT_FIELD}
171
+ choice={fieldLabel === null}
171
172
  published={published}
172
173
  onApprove={approve}
173
174
  />
@@ -184,6 +185,11 @@ function ReviewCard({
184
185
  } ${item.status === 'rejected' ? 'opacity-60' : ''}`}
185
186
  >
186
187
  <div className="bg-bg text-sm2 text-txt flex items-center gap-2 px-3 py-[9px] font-semibold">
188
+ {fieldLabel ? (
189
+ <span className="text-micro text-sub flex-none font-bold whitespace-nowrap">
190
+ {fieldLabel}
191
+ </span>
192
+ ) : null}
187
193
  <span className="min-w-0 flex-1 truncate">{item.documentTitle}</span>
188
194
  <code className="text-micro text-faint max-w-[45%] truncate font-mono font-normal">
189
195
  {item.url}
@@ -202,7 +208,7 @@ function ReviewCard({
202
208
  <div className="bg-bdr grid grid-cols-2 gap-px max-[560px]:grid-cols-1">
203
209
  <div className="bg-card text-sm2 text-txt min-w-0 px-3 py-[9px] leading-[1.5] break-words">
204
210
  <DiffLabel label="Current">
205
- {link ? null : <span>{item.before.length || ''}</span>}
211
+ {link || decorative ? null : <span>{item.before.length || ''}</span>}
206
212
  </DiffLabel>
207
213
  <div className={item.before ? 'text-sub' : 'text-faint italic'}>
208
214
  {item.before || 'Empty'}
@@ -210,7 +216,7 @@ function ReviewCard({
210
216
  </div>
211
217
  <div className="bg-card text-sm2 text-txt min-w-0 px-3 py-[9px] leading-[1.5] break-words">
212
218
  <DiffLabel label="Suggested">
213
- {link ? null : (
219
+ {link || decorative ? null : (
214
220
  <span className={limit !== null && suggested.length > limit ? 'text-err' : ''}>
215
221
  {suggested.length}
216
222
  </span>
@@ -293,7 +299,7 @@ function ReviewCard({
293
299
  >
294
300
  Reject
295
301
  </BusyButton>
296
- {link ? null : (
302
+ {link || decorative ? null : (
297
303
  <Button
298
304
  variant="secondary"
299
305
  size="sm"
@@ -25,6 +25,7 @@ import {
25
25
  type BatchSelection,
26
26
  } from '../../lib/batch-wizard.js'
27
27
  import { JOB_OPS } from '../../lib/job-view.js'
28
+ import { mediaReviewLabel } from '../../lib/job-drawer.js'
28
29
  import { createBatchAiJob, estimateBatchAi, previewBatchAi } from '../../lib/jobs-service.js'
29
30
  import { adminPortalContainer } from '../../lib/portal-container.js'
30
31
  import { BusyButton } from './BusyButton.js'
@@ -841,7 +842,10 @@ function PreviewList({
841
842
  key={`${item.documentId}|${i}`}
842
843
  className="rounded-9 border-bdr text-sm2 text-txt border px-3 py-[9px] leading-[1.5] break-words"
843
844
  >
844
- <small className="text-hint text-faint mb-0.5 block">{item.title}</small>
845
+ <small className="text-hint text-faint mb-0.5 block">
846
+ {item.field ? `${mediaReviewLabel(item.field) ?? item.field} · ` : null}
847
+ {item.title}
848
+ </small>
845
849
  {operation === 'links' ? <LinkLine after={item.after} /> : item.after}
846
850
  </li>
847
851
  ))}
@@ -139,7 +139,9 @@ function OAuthIcon({ provider }: { provider: string }) {
139
139
  function useCaptchaScript(provider: string | undefined, siteKey: string | null | undefined) {
140
140
  const [loaded, setLoaded] = useState(false)
141
141
 
142
- useState(() => {
142
+ // An effect, not a state initializer: the captcha config can arrive after
143
+ // the first render, and the script must load then.
144
+ useEffect(() => {
143
145
  if (typeof window === 'undefined' || !siteKey) return
144
146
 
145
147
  if (provider === 'recaptcha') {
@@ -149,7 +151,7 @@ function useCaptchaScript(provider: string | undefined, siteKey: string | null |
149
151
  return
150
152
  }
151
153
  const script = document.createElement('script')
152
- script.src = `https://www.google.com/recaptcha/api.js?render=${siteKey}`
154
+ script.src = `https://www.google.com/recaptcha/api.js?render=${encodeURIComponent(siteKey)}`
153
155
  script.async = true
154
156
  script.onload = () => setLoaded(true)
155
157
  document.head.appendChild(script)
@@ -165,14 +167,35 @@ function useCaptchaScript(provider: string | undefined, siteKey: string | null |
165
167
  script.onload = () => setLoaded(true)
166
168
  document.head.appendChild(script)
167
169
  }
168
- })
170
+ }, [provider, siteKey])
169
171
 
170
172
  return loaded
171
173
  }
172
174
 
175
+ const CAPTCHA_TOKEN_TIMEOUT_MS = 8_000
176
+
177
+ /** Resolves '' when the token doesn't arrive in time or the fetch fails. */
178
+ function withTimeout(promise: Promise<string>, ms: number): Promise<string> {
179
+ let timer: ReturnType<typeof setTimeout> | undefined
180
+ const timeout = new Promise<string>((resolve) => {
181
+ timer = setTimeout(() => resolve(''), ms)
182
+ })
183
+ return Promise.race([promise.catch(() => ''), timeout]).finally(() => clearTimeout(timer))
184
+ }
185
+
186
+ /** The provider's global once its script has loaded (it may still be loading at submit). */
187
+ async function waitForGlobal(name: 'grecaptcha' | 'turnstile'): Promise<any> {
188
+ const deadline = Date.now() + CAPTCHA_TOKEN_TIMEOUT_MS
189
+ for (;;) {
190
+ const value = (window as any)[name]
191
+ if (value || Date.now() >= deadline) return value
192
+ await new Promise((resolve) => setTimeout(resolve, 100))
193
+ }
194
+ }
195
+
173
196
  async function getCaptchaToken(provider: string, siteKey: string, action: string): Promise<string> {
174
197
  if (provider === 'recaptcha') {
175
- const grecaptcha = (window as any).grecaptcha
198
+ const grecaptcha = await waitForGlobal('grecaptcha')
176
199
  if (!grecaptcha) return ''
177
200
  return new Promise((resolve) => {
178
201
  grecaptcha.ready(() => {
@@ -185,7 +208,7 @@ async function getCaptchaToken(provider: string, siteKey: string, action: string
185
208
  }
186
209
 
187
210
  if (provider === 'turnstile') {
188
- const turnstile = (window as any).turnstile
211
+ const turnstile = await waitForGlobal('turnstile')
189
212
  if (!turnstile) return ''
190
213
  return new Promise((resolve) => {
191
214
  const container = document.createElement('div')
@@ -281,14 +304,15 @@ export function Login({
281
304
  setSubmitting(true)
282
305
 
283
306
  try {
307
+ // The server decides whether a token is required; a key that doesn't load
308
+ // on this domain must not block sign-in from the browser.
284
309
  let captchaToken: string | undefined
285
310
  if (captchaConfig?.provider && captchaConfig.provider !== 'none' && captchaConfig.siteKey) {
286
- captchaToken = await getCaptchaToken(captchaConfig.provider, captchaConfig.siteKey, 'login')
287
- if (!captchaToken) {
288
- setError('CAPTCHA verification failed. Please try again.')
289
- setSubmitting(false)
290
- return
291
- }
311
+ captchaToken =
312
+ (await withTimeout(
313
+ getCaptchaToken(captchaConfig.provider, captchaConfig.siteKey, 'login'),
314
+ CAPTCHA_TOKEN_TIMEOUT_MS,
315
+ )) || undefined
292
316
  }
293
317
 
294
318
  const result = await onLogin(email.trim(), password, captchaToken)
@@ -24,8 +24,8 @@ export function SpamFolder() {
24
24
  />
25
25
  <EmptyState
26
26
  icon={<ShieldAlert size={24} aria-hidden />}
27
- title="Spam folder is empty"
28
- description="Not spam restores an entry and sends a held notification once."
27
+ title="The spam folder isn't ready yet"
28
+ description="Caught entries are in All Entries under the Spam filter. Restoring one as not spam comes with this folder."
29
29
  />
30
30
  </div>
31
31
  )
@@ -0,0 +1,44 @@
1
+ import { ChevronDown, ChevronUp } from 'lucide-react'
2
+
3
+ export function deltaPercent(cur: number, prev: number): number | null {
4
+ return prev === 0 ? null : ((cur - prev) / prev) * 100
5
+ }
6
+
7
+ export function Delta({
8
+ cur,
9
+ prev,
10
+ invert = false,
11
+ }: {
12
+ cur: number
13
+ prev: number
14
+ invert?: boolean
15
+ }) {
16
+ const pct = deltaPercent(cur, prev)
17
+ if (pct === null) {
18
+ return (
19
+ <span className="inline-flex items-center gap-[3px] rounded-[5px] border border-[var(--bdr)] bg-[var(--bg)] px-[6px] py-[2px] text-[11.5px] font-bold whitespace-nowrap text-[var(--sub)] tabular-nums">
20
+ new
21
+ </span>
22
+ )
23
+ }
24
+ const flat = Math.abs(pct) < 0.5
25
+ const good = invert ? pct < 0 : pct > 0
26
+ const className = flat
27
+ ? 'border border-[var(--bdr)] bg-[var(--bg)] text-[var(--sub)]'
28
+ : good
29
+ ? 'bg-[var(--suc-l)] text-[var(--suc)]'
30
+ : 'bg-[var(--err-l)] text-[var(--err)]'
31
+ return (
32
+ <span
33
+ className={`inline-flex items-center gap-[3px] rounded-[5px] px-[6px] py-[2px] text-[11.5px] font-bold whitespace-nowrap tabular-nums ${className}`}
34
+ >
35
+ {!flat &&
36
+ (pct > 0 ? (
37
+ <ChevronUp size={11} strokeWidth={2.5} aria-hidden />
38
+ ) : (
39
+ <ChevronDown size={11} strokeWidth={2.5} aria-hidden />
40
+ ))}
41
+ {`${pct > 0 ? '+' : ''}${pct.toFixed(1)}%`}
42
+ </span>
43
+ )
44
+ }
@@ -0,0 +1,98 @@
1
+ import type { LucideIcon } from 'lucide-react'
2
+ import { Delta } from './Delta.js'
3
+ import { Sparkline, type SparkPoint } from './Sparkline.js'
4
+
5
+ export interface KpiCardProps {
6
+ label: string
7
+ icon: LucideIcon
8
+ value: string
9
+ unit?: string
10
+ cur: number | null
11
+ prev: number | null
12
+ prevLabel: string
13
+ compare: boolean
14
+ series?: SparkPoint[] | null
15
+ compareSeries?: SparkPoint[] | null
16
+ selected?: boolean
17
+ selectable: boolean
18
+ unavailable?: boolean
19
+ onSelect?: () => void
20
+ onConnect?: () => void
21
+ spanClass?: string
22
+ }
23
+
24
+ export function KpiCard({
25
+ label,
26
+ icon: Icon,
27
+ value,
28
+ unit,
29
+ cur,
30
+ prev,
31
+ prevLabel,
32
+ compare,
33
+ series,
34
+ compareSeries,
35
+ selected = false,
36
+ selectable,
37
+ unavailable = false,
38
+ onSelect,
39
+ onConnect,
40
+ spanClass = '',
41
+ }: KpiCardProps) {
42
+ const content = (
43
+ <>
44
+ <div className="flex items-center gap-[6px] text-[11.5px] font-semibold tracking-[0.2px] text-[var(--sub)]">
45
+ <Icon size={13} className="text-[var(--muted)]" aria-hidden />
46
+ {label}
47
+ </div>
48
+ <div className="mt-[7px] text-[29px] leading-[1.1] font-bold tracking-[-1px] text-[var(--txt)] tabular-nums">
49
+ {value}
50
+ {unit ? (
51
+ <small className="ml-[2px] text-[15px] font-semibold tracking-normal text-[var(--sub)]">
52
+ {unit}
53
+ </small>
54
+ ) : null}
55
+ </div>
56
+ <div className="mt-[6px] flex items-end gap-[10px]">
57
+ {unavailable ? (
58
+ <button
59
+ type="button"
60
+ onClick={(event) => {
61
+ event.stopPropagation()
62
+ onConnect?.()
63
+ }}
64
+ className="text-[11px] font-semibold text-[var(--acc)] hover:underline"
65
+ >
66
+ Connect analytics
67
+ </button>
68
+ ) : (
69
+ <div>
70
+ {compare && cur !== null && prev !== null ? <Delta cur={cur} prev={prev} /> : null}
71
+ <div className="text-[11px] leading-[1.5] text-[var(--sub)] tabular-nums">
72
+ {compare ? `from ${prevLabel}` : 'no comparison'}
73
+ </div>
74
+ </div>
75
+ )}
76
+ {series ? <Sparkline cur={series} prev={compare ? compareSeries : null} /> : null}
77
+ </div>
78
+ </>
79
+ )
80
+
81
+ const className = `rounded-[10px] border bg-[var(--card)] p-[14px_15px_10px] text-left shadow-[var(--shd)] transition ${spanClass} ${
82
+ selected ? 'border-[var(--acc)] shadow-[0_0_0_3px_var(--acc-l)]' : 'border-[var(--bdr)]'
83
+ } ${selectable ? 'hover:-translate-y-px hover:border-[var(--acc-m)] hover:shadow-[var(--shd2)]' : ''}`
84
+
85
+ if (!selectable) {
86
+ return <div className={className}>{content}</div>
87
+ }
88
+ return (
89
+ <button
90
+ type="button"
91
+ aria-pressed={selected}
92
+ onClick={onSelect}
93
+ className={`${className} cursor-pointer`}
94
+ >
95
+ {content}
96
+ </button>
97
+ )
98
+ }
@@ -0,0 +1,51 @@
1
+ export interface SparkPoint {
2
+ date: string
3
+ v: number
4
+ }
5
+
6
+ export function Sparkline({
7
+ cur,
8
+ prev,
9
+ width = 76,
10
+ height = 30,
11
+ }: {
12
+ cur: SparkPoint[]
13
+ prev?: SparkPoint[] | null
14
+ width?: number
15
+ height?: number
16
+ }) {
17
+ const all = [...cur.map((point) => point.v), ...(prev ? prev.map((point) => point.v) : [])]
18
+ const max = Math.max(...all, 1)
19
+ const min = Math.min(...all, 0)
20
+ const path = (points: SparkPoint[]) =>
21
+ points
22
+ .map((point, index) => {
23
+ const x = (index / Math.max(points.length - 1, 1)) * width
24
+ const y = height - ((point.v - min) / (max - min || 1)) * (height - 4) - 2
25
+ return `${index ? 'L' : 'M'}${x.toFixed(1)} ${y.toFixed(1)}`
26
+ })
27
+ .join(' ')
28
+
29
+ return (
30
+ <svg width={width} height={height} className="ml-auto shrink-0" aria-hidden="true">
31
+ {prev ? (
32
+ <path
33
+ d={path(prev)}
34
+ fill="none"
35
+ stroke="var(--muted)"
36
+ strokeWidth="1.5"
37
+ strokeDasharray="3 2.5"
38
+ opacity=".8"
39
+ />
40
+ ) : null}
41
+ <path
42
+ d={path(cur)}
43
+ fill="none"
44
+ stroke="var(--acc)"
45
+ strokeWidth="2"
46
+ strokeLinecap="round"
47
+ strokeLinejoin="round"
48
+ />
49
+ </svg>
50
+ )
51
+ }
@@ -0,0 +1,246 @@
1
+ 'use client'
2
+
3
+ import { useEffect, useRef, useState } from 'react'
4
+ import { formatDay } from './dashboard-date.js'
5
+ import { Delta } from './Delta.js'
6
+ import type { SparkPoint } from './Sparkline.js'
7
+
8
+ const HEIGHT = 244
9
+ const PL = 46
10
+ const PR = 14
11
+ const PT = 12
12
+ const PB = 26
13
+
14
+ function niceStep(value: number): number {
15
+ const power = Math.pow(10, Math.floor(Math.log10(value || 1)))
16
+ for (const multiplier of [1, 2, 2.5, 5, 10]) {
17
+ if (value <= multiplier * power) return multiplier * power
18
+ }
19
+ return 10 * power
20
+ }
21
+
22
+ function tickLabel(value: number): string {
23
+ if (value >= 1000) return `${(value / 1000).toFixed(1).replace(/\.0$/, '')}k`
24
+ if (Number.isInteger(value)) return String(value)
25
+ return value.toFixed(2).replace(/0$/, '')
26
+ }
27
+
28
+ function tooltipDate(key: string): string {
29
+ return new Date(`${key}T12:00:00.000Z`).toLocaleDateString('en-US', {
30
+ weekday: 'short',
31
+ month: 'short',
32
+ day: 'numeric',
33
+ timeZone: 'UTC',
34
+ })
35
+ }
36
+
37
+ export function TrendChart({
38
+ cur,
39
+ prev,
40
+ format,
41
+ ariaLabel,
42
+ }: {
43
+ cur: SparkPoint[]
44
+ prev: SparkPoint[] | null
45
+ format: (value: number) => string
46
+ ariaLabel: string
47
+ }) {
48
+ const wrapRef = useRef<HTMLDivElement>(null)
49
+ const [width, setWidth] = useState(760)
50
+ const [highlight, setHighlight] = useState<number | null>(null)
51
+
52
+ useEffect(() => {
53
+ const element = wrapRef.current
54
+ if (!element) return
55
+ const measure = () => setWidth(Math.max(320, element.clientWidth - 16))
56
+ measure()
57
+ let observer: ResizeObserver | undefined
58
+ if (typeof ResizeObserver !== 'undefined') {
59
+ observer = new ResizeObserver(measure)
60
+ observer.observe(element)
61
+ }
62
+ window.addEventListener('resize', measure)
63
+ const timer = setTimeout(measure, 60)
64
+ return () => {
65
+ observer?.disconnect()
66
+ window.removeEventListener('resize', measure)
67
+ clearTimeout(timer)
68
+ }
69
+ }, [])
70
+
71
+ const innerWidth = width - PL - PR
72
+ const innerHeight = HEIGHT - PT - PB
73
+ const all = [...cur.map((point) => point.v), ...(prev ? prev.map((point) => point.v) : [])]
74
+ const rawMax = Math.max(...all, 1)
75
+ const tick = niceStep(rawMax / 4)
76
+ const max = tick * 4
77
+ const x = (index: number) => PL + (index / Math.max(cur.length - 1, 1)) * innerWidth
78
+ const y = (value: number) => PT + innerHeight - (value / max) * innerHeight
79
+ const line = (points: SparkPoint[]) =>
80
+ points
81
+ .map((point, index) => `${index ? 'L' : 'M'}${x(index).toFixed(1)} ${y(point.v).toFixed(1)}`)
82
+ .join(' ')
83
+ const area = cur.length
84
+ ? `${line(cur)} L${x(cur.length - 1).toFixed(1)} ${PT + innerHeight} L${PL} ${PT + innerHeight} Z`
85
+ : ''
86
+ const ticks = [0, 1, 2, 3, 4].map((index) => tick * index)
87
+ const labelEvery = Math.max(1, Math.ceil(cur.length / 7))
88
+ const highlighted = highlight !== null ? cur[highlight] : undefined
89
+
90
+ const onMove = (event: React.MouseEvent<SVGSVGElement>) => {
91
+ const rect = event.currentTarget.getBoundingClientRect()
92
+ const index = Math.round(((event.clientX - rect.left - PL) / innerWidth) * (cur.length - 1))
93
+ setHighlight(index >= 0 && index < cur.length ? index : null)
94
+ }
95
+
96
+ const onKeyDown = (event: React.KeyboardEvent<SVGSVGElement>) => {
97
+ if (event.key === 'Escape') {
98
+ setHighlight(null)
99
+ return
100
+ }
101
+ if (event.key !== 'ArrowLeft' && event.key !== 'ArrowRight') return
102
+ event.preventDefault()
103
+ setHighlight((current) => {
104
+ const base = current ?? cur.length - 1
105
+ const next = event.key === 'ArrowLeft' ? base - 1 : base + 1
106
+ return Math.min(cur.length - 1, Math.max(0, next))
107
+ })
108
+ }
109
+
110
+ return (
111
+ <div className="relative px-2 pt-[14px] pb-1" ref={wrapRef}>
112
+ <svg
113
+ width={width}
114
+ height={HEIGHT}
115
+ onMouseMove={onMove}
116
+ onMouseLeave={() => setHighlight(null)}
117
+ onKeyDown={onKeyDown}
118
+ tabIndex={0}
119
+ role="img"
120
+ aria-label={ariaLabel}
121
+ className="block cursor-crosshair outline-none focus-visible:ring-2 focus-visible:ring-[var(--acc)]"
122
+ >
123
+ <defs>
124
+ <linearGradient id="dashboard-chart-fill" x1="0" y1="0" x2="0" y2="1">
125
+ <stop offset="0%" stopColor="var(--acc)" stopOpacity=".22" />
126
+ <stop offset="100%" stopColor="var(--acc)" stopOpacity="0" />
127
+ </linearGradient>
128
+ </defs>
129
+ {ticks.map((tickValue) => (
130
+ <g key={tickValue}>
131
+ <line
132
+ x1={PL}
133
+ y1={y(tickValue)}
134
+ x2={width - PR}
135
+ y2={y(tickValue)}
136
+ stroke="var(--bdr)"
137
+ strokeWidth="1"
138
+ />
139
+ <text
140
+ x={PL - 9}
141
+ y={y(tickValue) + 3.5}
142
+ textAnchor="end"
143
+ fontSize="10"
144
+ fill="var(--sub)"
145
+ >
146
+ {tickLabel(tickValue)}
147
+ </text>
148
+ </g>
149
+ ))}
150
+ {cur.map((point, index) =>
151
+ index % labelEvery === 0 || index === cur.length - 1 ? (
152
+ <text
153
+ key={point.date}
154
+ x={x(index)}
155
+ y={HEIGHT - 8}
156
+ textAnchor="middle"
157
+ fontSize="10"
158
+ fill="var(--sub)"
159
+ >
160
+ {formatDay(point.date)}
161
+ </text>
162
+ ) : null,
163
+ )}
164
+ {area ? <path d={area} fill="url(#dashboard-chart-fill)" /> : null}
165
+ {prev ? (
166
+ <path
167
+ d={line(prev)}
168
+ fill="none"
169
+ stroke="var(--muted)"
170
+ strokeWidth="1.75"
171
+ strokeDasharray="4 3.5"
172
+ />
173
+ ) : null}
174
+ {cur.length ? (
175
+ <path
176
+ d={line(cur)}
177
+ fill="none"
178
+ stroke="var(--acc)"
179
+ strokeWidth="2.25"
180
+ strokeLinecap="round"
181
+ strokeLinejoin="round"
182
+ />
183
+ ) : null}
184
+ {highlight !== null && highlighted ? (
185
+ <g>
186
+ <line
187
+ x1={x(highlight)}
188
+ y1={PT}
189
+ x2={x(highlight)}
190
+ y2={PT + innerHeight}
191
+ stroke="var(--acc-m)"
192
+ strokeWidth="1"
193
+ />
194
+ {prev?.[highlight] ? (
195
+ <circle
196
+ cx={x(highlight)}
197
+ cy={y(prev[highlight]!.v)}
198
+ r="3.5"
199
+ fill="var(--card)"
200
+ stroke="var(--muted)"
201
+ strokeWidth="1.75"
202
+ />
203
+ ) : null}
204
+ <circle
205
+ cx={x(highlight)}
206
+ cy={y(highlighted.v)}
207
+ r="4.5"
208
+ fill="var(--card)"
209
+ stroke="var(--acc)"
210
+ strokeWidth="2.5"
211
+ />
212
+ </g>
213
+ ) : null}
214
+ </svg>
215
+
216
+ {highlight !== null && highlighted ? (
217
+ <div
218
+ className="pointer-events-none absolute z-[5] min-w-[132px] rounded-[8px] bg-[var(--txt)] px-[10px] py-2 text-[11.5px] leading-[1.55] text-[var(--sb)] shadow-[var(--shd2)]"
219
+ style={{
220
+ left: Math.min(Math.max(x(highlight) - 66, 4), Math.max(width - 140, 4)),
221
+ top: Math.max(y(highlighted.v) - 72, 4),
222
+ }}
223
+ >
224
+ <b className="mb-1 block text-[12.5px]">{tooltipDate(highlighted.date)}</b>
225
+ <div className="flex items-center gap-[6px]">
226
+ <i className="h-[2.5px] w-[9px] rounded-[2px] bg-[var(--acc)]" aria-hidden />
227
+ This period
228
+ <span className="ml-auto font-bold">{format(highlighted.v)}</span>
229
+ </div>
230
+ {prev?.[highlight] ? (
231
+ <>
232
+ <div className="flex items-center gap-[6px]">
233
+ <i className="h-[2.5px] w-[9px] rounded-[2px] bg-[var(--muted)]" aria-hidden />
234
+ {formatDay(prev[highlight]!.date)}
235
+ <span className="ml-auto font-bold">{format(prev[highlight]!.v)}</span>
236
+ </div>
237
+ <div className="mt-[3px]">
238
+ <Delta cur={highlighted.v} prev={prev[highlight]!.v} />
239
+ </div>
240
+ </>
241
+ ) : null}
242
+ </div>
243
+ ) : null}
244
+ </div>
245
+ )
246
+ }