@prenta/admin 2.12.1 → 2.13.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 (63) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/AdminRoot.d.ts.map +1 -1
  3. package/dist/AdminRoot.js +3 -3
  4. package/dist/AdminRoot.js.map +1 -1
  5. package/dist/__tests__/components/attribution-rows.test.js +17 -5
  6. package/dist/__tests__/components/attribution-rows.test.js.map +1 -1
  7. package/dist/__tests__/layout/shell-nav.render.test.js +3 -1
  8. package/dist/__tests__/layout/shell-nav.render.test.js.map +1 -1
  9. package/dist/__tests__/views/form-entries.render.test.js +5 -5
  10. package/dist/__tests__/views/form-entries.render.test.js.map +1 -1
  11. package/dist/__tests__/views/form-submissions.render.test.js +3 -3
  12. package/dist/__tests__/views/form-submissions.render.test.js.map +1 -1
  13. package/dist/components/forms/ExportMenu.d.ts +7 -1
  14. package/dist/components/forms/ExportMenu.d.ts.map +1 -1
  15. package/dist/components/forms/ExportMenu.js +17 -5
  16. package/dist/components/forms/ExportMenu.js.map +1 -1
  17. package/dist/layout/nav-config.d.ts.map +1 -1
  18. package/dist/layout/nav-config.js +8 -1
  19. package/dist/layout/nav-config.js.map +1 -1
  20. package/dist/lib/entry-attribution.d.ts +33 -0
  21. package/dist/lib/entry-attribution.d.ts.map +1 -1
  22. package/dist/lib/entry-attribution.js +115 -30
  23. package/dist/lib/entry-attribution.js.map +1 -1
  24. package/dist/lib/forms-service.d.ts +38 -0
  25. package/dist/lib/forms-service.d.ts.map +1 -1
  26. package/dist/lib/forms-service.js +10 -0
  27. package/dist/lib/forms-service.js.map +1 -1
  28. package/dist/prenta-admin.css +1 -1
  29. package/dist/views/FormEntries.d.ts +4 -1
  30. package/dist/views/FormEntries.d.ts.map +1 -1
  31. package/dist/views/FormEntries.js +2 -2
  32. package/dist/views/FormEntries.js.map +1 -1
  33. package/dist/views/FormSubmissions.d.ts +3 -1
  34. package/dist/views/FormSubmissions.d.ts.map +1 -1
  35. package/dist/views/FormSubmissions.js +2 -2
  36. package/dist/views/FormSubmissions.js.map +1 -1
  37. package/dist/views/SpamFolder.d.ts +6 -1
  38. package/dist/views/SpamFolder.d.ts.map +1 -1
  39. package/dist/views/SpamFolder.js +4 -11
  40. package/dist/views/SpamFolder.js.map +1 -1
  41. package/dist/views/entries/EntriesInbox.d.ts +12 -2
  42. package/dist/views/entries/EntriesInbox.d.ts.map +1 -1
  43. package/dist/views/entries/EntriesInbox.js +820 -81
  44. package/dist/views/entries/EntriesInbox.js.map +1 -1
  45. package/dist/views/entries/inbox-format.d.ts +0 -1
  46. package/dist/views/entries/inbox-format.d.ts.map +1 -1
  47. package/dist/views/entries/inbox-format.js +0 -4
  48. package/dist/views/entries/inbox-format.js.map +1 -1
  49. package/package.json +3 -3
  50. package/src/AdminRoot.tsx +23 -3
  51. package/src/__tests__/components/attribution-rows.test.ts +19 -5
  52. package/src/__tests__/layout/shell-nav.render.test.tsx +3 -1
  53. package/src/__tests__/views/form-entries.render.test.tsx +5 -5
  54. package/src/__tests__/views/form-submissions.render.test.tsx +3 -3
  55. package/src/components/forms/ExportMenu.tsx +37 -13
  56. package/src/layout/nav-config.tsx +8 -0
  57. package/src/lib/entry-attribution.ts +155 -29
  58. package/src/lib/forms-service.ts +44 -0
  59. package/src/views/FormEntries.tsx +17 -2
  60. package/src/views/FormSubmissions.tsx +16 -2
  61. package/src/views/SpamFolder.tsx +14 -26
  62. package/src/views/entries/EntriesInbox.tsx +2119 -337
  63. package/src/views/entries/inbox-format.ts +0 -6
@@ -29,6 +29,7 @@ import {
29
29
  Search as SearchIcon,
30
30
  Settings,
31
31
  ShieldX,
32
+ Star,
32
33
  TextAlignStart,
33
34
  Trash2,
34
35
  Users,
@@ -308,6 +309,12 @@ export function applyFormsNav(items: NavItem[], forms: FormsSidebarCount[]): Nav
308
309
  badge: f.unread,
309
310
  })),
310
311
  },
312
+ {
313
+ path: '/forms/entries?filter=starred',
314
+ label: 'Starred',
315
+ icon: Star,
316
+ iconSize: 14,
317
+ },
311
318
  {
312
319
  path: '/forms',
313
320
  label: 'All Forms',
@@ -321,6 +328,7 @@ export function applyFormsNav(items: NavItem[], forms: FormsSidebarCount[]): Nav
321
328
  })),
322
329
  },
323
330
  { path: '/forms/spam', label: 'Spam', icon: ShieldX, iconSize: 14 },
331
+ { path: '/forms/entries?filter=trash', label: 'Trash', icon: Trash2, iconSize: 14 },
324
332
  { path: '/forms/deliveries', label: 'SMTP Log', icon: Mail, iconSize: 14 },
325
333
  { path: '/forms/settings', label: 'Form Settings', icon: Settings, iconSize: 14 },
326
334
  ]
@@ -1,8 +1,49 @@
1
1
  import type { FormSubmission } from '@prenta/core'
2
2
 
3
+ export interface AttributionClickId {
4
+ key: string
5
+ platform: string
6
+ value: string
7
+ }
8
+
3
9
  export interface AttributionRow {
4
10
  label: string
5
11
  value: string
12
+ /** Set on the Click ID row. Empty means "None · not an ad click". */
13
+ clickIds?: AttributionClickId[]
14
+ /** Channel key for the Channel chip row. */
15
+ channelKey?: string
16
+ /** Source / Medium split for custom rendering. */
17
+ sourceMedium?: { source: string; medium: string }
18
+ /** URL for Landing page link rendering. */
19
+ href?: string
20
+ }
21
+
22
+ export interface AttributionSummary {
23
+ channelKey: string
24
+ channelLabel: string
25
+ channelFg: string
26
+ channelBg: string
27
+ source: string
28
+ medium: string
29
+ campaign: string
30
+ term: string
31
+ landingPage: string
32
+ referrer: string
33
+ device: string
34
+ ip: string
35
+ spamScore: number
36
+ clickIds: AttributionClickId[]
37
+ }
38
+
39
+ const CHANNEL_META: Record<string, { label: string; fg: string; bg: string }> = {
40
+ paid: { label: 'Paid', fg: 'var(--warn)', bg: 'var(--warn-l)' },
41
+ search_organic: { label: 'Organic search', fg: 'var(--suc)', bg: 'var(--suc-l)' },
42
+ social: { label: 'Social', fg: 'var(--info)', bg: 'var(--info-l)' },
43
+ email: { label: 'Email', fg: 'var(--acc)', bg: 'var(--acc-l)' },
44
+ ai: { label: 'AI assistant', fg: 'var(--acc)', bg: 'var(--acc-l)' },
45
+ referral: { label: 'Referral', fg: 'var(--sub)', bg: 'var(--bg)' },
46
+ direct: { label: 'Direct', fg: 'var(--sub)', bg: 'var(--bg)' },
6
47
  }
7
48
 
8
49
  const CHANNEL_LABELS: Record<string, string> = {
@@ -15,16 +56,19 @@ const CHANNEL_LABELS: Record<string, string> = {
15
56
  direct: 'Direct',
16
57
  }
17
58
 
18
- const CLICK_ID_LABELS: Record<string, string> = {
19
- gclid: 'GCLID (Google Ads)',
20
- fbclid: 'FBCLID (Meta)',
21
- msclkid: 'MSCLKID (Microsoft)',
22
- ttclid: 'TTCLID (TikTok)',
23
- li_fat_id: 'LinkedIn click ID',
24
- dclid: 'DCLID (Display)',
25
- twclid: 'TWCLID (X Ads)',
26
- rdt_cid: 'Reddit click ID',
27
- }
59
+ /** Entries SPEC §5. gbraid and wbraid are stored on `extraIds`, not `clickIds`. */
60
+ const CLICK_ID_ORDER: ReadonlyArray<{ key: string; platform: string }> = [
61
+ { key: 'gclid', platform: 'Google Ads' },
62
+ { key: 'gbraid', platform: 'Google Ads · iOS app' },
63
+ { key: 'wbraid', platform: 'Google Ads · iOS web' },
64
+ { key: 'dclid', platform: 'Google Display & Video' },
65
+ { key: 'fbclid', platform: 'Meta' },
66
+ { key: 'msclkid', platform: 'Microsoft Ads' },
67
+ { key: 'ttclid', platform: 'TikTok' },
68
+ { key: 'li_fat_id', platform: 'LinkedIn' },
69
+ { key: 'twclid', platform: 'X' },
70
+ { key: 'rdt_cid', platform: 'Reddit' },
71
+ ]
28
72
 
29
73
  const DEVICE_LABELS: Record<string, string> = {
30
74
  desktop: 'Desktop',
@@ -50,6 +94,60 @@ function formatDateTime(iso: string): string {
50
94
  })
51
95
  }
52
96
 
97
+ export function getEntryAttributionSummary(entry: FormSubmission): AttributionSummary {
98
+ const blob =
99
+ entry.attribution && typeof entry.attribution === 'object' && !Array.isArray(entry.attribution)
100
+ ? (entry.attribution as Record<string, unknown>)
101
+ : {}
102
+
103
+ const rawChannel = attrString(blob, 'channel')
104
+ const clickIds = clickIdsFor(blob)
105
+ const source = attrString(blob, 'source') || entry.utmSource || '(direct)'
106
+ const medium = attrString(blob, 'medium') || entry.utmMedium || '(none)'
107
+ const campaign = attrString(blob, 'campaign') || entry.utmCampaign || ''
108
+ const term = attrString(blob, 'term')
109
+ const channelKey =
110
+ rawChannel && CHANNEL_META[rawChannel]
111
+ ? rawChannel
112
+ : clickIds.length > 0
113
+ ? 'paid'
114
+ : source !== '(direct)' && medium === 'organic'
115
+ ? 'search_organic'
116
+ : 'direct'
117
+ const meta = CHANNEL_META[channelKey] ?? CHANNEL_META.direct!
118
+ const landingPage = attrString(blob, 'landingPage') || entry.pageUrl || '—'
119
+ const referrer = attrString(blob, 'referrer') || entry.referrer || '(none)'
120
+ const deviceType = DEVICE_LABELS[attrString(blob, 'deviceType')] ?? ''
121
+ const device = entry.userAgent || deviceType || '—'
122
+ const ip = attrString(blob, 'ip') || entry.ipAddressHash || '—'
123
+ const rawScore = blob.spamScore ?? blob.spam
124
+ const spamScore =
125
+ typeof rawScore === 'number'
126
+ ? rawScore
127
+ : entry.spamStatus === 'spam'
128
+ ? 95
129
+ : entry.spamStatus === 'suspected'
130
+ ? 80
131
+ : 0
132
+
133
+ return {
134
+ channelKey,
135
+ channelLabel: meta.label,
136
+ channelFg: meta.fg,
137
+ channelBg: meta.bg,
138
+ source,
139
+ medium,
140
+ campaign,
141
+ term,
142
+ landingPage,
143
+ referrer,
144
+ device,
145
+ ip,
146
+ spamScore,
147
+ clickIds,
148
+ }
149
+ }
150
+
53
151
  /**
54
152
  * The attribution rows for an entry. Prefers the client-captured blob
55
153
  * (channel, click IDs, first touch) and falls back to the denormalized UTM
@@ -68,27 +166,55 @@ export function buildAttributionRows(entry: FormSubmission): AttributionRow[] {
68
166
  ? `${CHANNEL_LABELS[channel] ?? channel}${referrerName ? ` · ${referrerName}` : ''}`
69
167
  : ''
70
168
 
71
- const rows: Array<{ label: string; value: string | null | undefined }> = [
72
- { label: 'Channel', value: channelLabel },
73
- { label: 'Source', value: attrString(blob, 'source') || entry.utmSource },
74
- { label: 'Medium', value: attrString(blob, 'medium') || entry.utmMedium },
75
- { label: 'Campaign', value: attrString(blob, 'campaign') || entry.utmCampaign },
76
- { label: 'Term', value: attrString(blob, 'term') },
77
- { label: 'Content', value: attrString(blob, 'content') },
78
- { label: 'Landing page', value: attrString(blob, 'landingPage') },
79
- { label: 'Page', value: entry.pageUrl },
80
- { label: 'Referrer', value: attrString(blob, 'referrer') || entry.referrer },
81
- { label: 'Device', value: DEVICE_LABELS[attrString(blob, 'deviceType')] ?? '' },
82
- { label: 'First touch', value: formatDateTime(attrString(blob, 'firstTouchAt')) },
169
+ const filled = (
170
+ rows: Array<{ label: string; value: string | null | undefined }>,
171
+ ): AttributionRow[] =>
172
+ rows.filter((r): r is AttributionRow => typeof r.value === 'string' && r.value !== '')
173
+
174
+ const present = clickIdsFor(blob)
175
+ const clickRow: AttributionRow = {
176
+ label: present.length > 1 ? 'Click IDs' : 'Click ID',
177
+ value: present.length === 0 ? 'None · not an ad click' : '',
178
+ clickIds: present,
179
+ }
180
+
181
+ return [
182
+ ...filled([
183
+ { label: 'Channel', value: channelLabel },
184
+ { label: 'Source', value: attrString(blob, 'source') || entry.utmSource },
185
+ { label: 'Medium', value: attrString(blob, 'medium') || entry.utmMedium },
186
+ { label: 'Campaign', value: attrString(blob, 'campaign') || entry.utmCampaign },
187
+ { label: 'Term', value: attrString(blob, 'term') },
188
+ { label: 'Content', value: attrString(blob, 'content') },
189
+ ]),
190
+ clickRow,
191
+ ...filled([
192
+ { label: 'Landing page', value: attrString(blob, 'landingPage') },
193
+ { label: 'Page', value: entry.pageUrl },
194
+ { label: 'Referrer', value: attrString(blob, 'referrer') || entry.referrer },
195
+ { label: 'Device', value: DEVICE_LABELS[attrString(blob, 'deviceType')] ?? '' },
196
+ { label: 'First touch', value: formatDateTime(attrString(blob, 'firstTouchAt')) },
197
+ ]),
83
198
  ]
199
+ }
84
200
 
85
- const clickIds = blob.clickIds
86
- if (clickIds && typeof clickIds === 'object' && !Array.isArray(clickIds)) {
87
- for (const [key, label] of Object.entries(CLICK_ID_LABELS)) {
88
- const value = (clickIds as Record<string, unknown>)[key]
89
- if (typeof value === 'string' && value) rows.push({ label, value })
90
- }
201
+ function clickIdsFor(blob: Record<string, unknown>): AttributionClickId[] {
202
+ const primary = asStringRecord(blob.clickIds)
203
+ const extra = asStringRecord(blob.extraIds)
204
+ const ids = asStringRecord(blob.ids)
205
+ const lines: AttributionClickId[] = []
206
+ for (const { key, platform } of CLICK_ID_ORDER) {
207
+ const value = primary[key] || extra[key] || ids[key] || ''
208
+ if (value) lines.push({ key, platform, value })
91
209
  }
210
+ return lines
211
+ }
92
212
 
93
- return rows.filter((r): r is AttributionRow => typeof r.value === 'string' && r.value !== '')
213
+ function asStringRecord(value: unknown): Record<string, string> {
214
+ if (!value || typeof value !== 'object' || Array.isArray(value)) return {}
215
+ const out: Record<string, string> = {}
216
+ for (const [key, item] of Object.entries(value)) {
217
+ if (typeof item === 'string' && item) out[key] = item
218
+ }
219
+ return out
94
220
  }
@@ -46,6 +46,32 @@ export type {
46
46
  EntryCounts,
47
47
  } from '@prenta/core'
48
48
 
49
+ export interface FormEntryNote {
50
+ authorId: string
51
+ authorName?: string
52
+ at: string
53
+ text: string
54
+ }
55
+
56
+ interface FormEntryDeleted {
57
+ at: string
58
+ by: string
59
+ byName?: string
60
+ }
61
+
62
+ interface FormEntryPartial {
63
+ step: number
64
+ of: number
65
+ stepName: string
66
+ lastAt: string
67
+ }
68
+
69
+ interface FormEntrySpamMeta {
70
+ by: 'ai' | 'keyword' | 'fast' | 'honeypot' | 'manual'
71
+ reason: string
72
+ score?: number
73
+ }
74
+
49
75
  /**
50
76
  * `cmsApi` never throws — it returns `{ error, status }` on a network/HTTP
51
77
  * failure. Read (GET) fetchers must re-surface that as a thrown error so the
@@ -354,12 +380,23 @@ export interface EntryPatch {
354
380
  unread?: boolean
355
381
  starred?: boolean
356
382
  archived?: boolean
383
+ status?: string
384
+ spamStatus?: 'clean' | 'suspected' | 'spam'
385
+ assigneeId?: string | null
386
+ assigneeName?: string | null
387
+ notes?: FormEntryNote[]
388
+ note?: { text: string; authorName?: string }
389
+ deleted?: FormEntryDeleted | null
390
+ partial?: FormEntryPartial | null
391
+ spamMeta?: FormEntrySpamMeta | null
357
392
  }
358
393
 
359
394
  function buildEntriesQuery(params: FetchFormEntriesParams): string {
360
395
  const qs = new URLSearchParams()
361
396
  if (params.search) qs.set('search', params.search)
362
397
  if (params.formId) qs.set('formId', params.formId)
398
+ if (params.folder) qs.set('folder', params.folder)
399
+ if (params.assigneeId) qs.set('assigneeId', params.assigneeId)
363
400
  if (typeof params.unread === 'boolean') qs.set('unread', String(params.unread))
364
401
  if (typeof params.starred === 'boolean') qs.set('starred', String(params.starred))
365
402
  if (typeof params.archived === 'boolean') qs.set('archived', String(params.archived))
@@ -395,6 +432,7 @@ export async function fetchEntryCounts(params: FetchFormEntriesParams = {}): Pro
395
432
  export interface EntryDetail {
396
433
  entry: FormSubmission
397
434
  fields: FormField[]
435
+ otherEntryCount?: number
398
436
  }
399
437
 
400
438
  export async function fetchEntry(id: string): Promise<EntryDetail | null> {
@@ -443,11 +481,17 @@ export async function downloadEntriesExport(
443
481
  options: {
444
482
  formId?: string
445
483
  format?: EntriesExportFormat
484
+ folder?: string
485
+ search?: string
486
+ assigneeId?: string
446
487
  } = {},
447
488
  ): Promise<{ error?: string }> {
448
489
  const format: EntriesExportFormat = options.format ?? 'csv'
449
490
  const qs = new URLSearchParams({ format })
450
491
  if (options.formId) qs.set('formId', options.formId)
492
+ if (options.folder && options.folder !== 'all') qs.set('folder', options.folder)
493
+ if (options.search?.trim()) qs.set('search', options.search.trim())
494
+ if (options.assigneeId) qs.set('assigneeId', options.assigneeId)
451
495
 
452
496
  let res: Response
453
497
  try {
@@ -7,8 +7,23 @@ import { EntriesInbox } from './entries/EntriesInbox.js'
7
7
 
8
8
  export interface FormEntriesProps {
9
9
  onNavigate?: (path: string) => void
10
+ currentPath?: string
11
+ currentUserId?: string
12
+ currentUserName?: string
10
13
  }
11
14
 
12
- export function FormEntries({ onNavigate }: FormEntriesProps) {
13
- return <EntriesInbox onNavigate={onNavigate} />
15
+ export function FormEntries({
16
+ onNavigate,
17
+ currentPath,
18
+ currentUserId,
19
+ currentUserName,
20
+ }: FormEntriesProps) {
21
+ return (
22
+ <EntriesInbox
23
+ onNavigate={onNavigate}
24
+ currentPath={currentPath}
25
+ currentUserId={currentUserId}
26
+ currentUserName={currentUserName}
27
+ />
28
+ )
14
29
  }
@@ -9,8 +9,22 @@ import { EntriesInbox } from './entries/EntriesInbox.js'
9
9
  export interface FormSubmissionsProps {
10
10
  formId: string
11
11
  onNavigate?: (path: string) => void
12
+ currentUserId?: string
13
+ currentUserName?: string
12
14
  }
13
15
 
14
- export function FormSubmissions({ formId, onNavigate }: FormSubmissionsProps) {
15
- return <EntriesInbox formId={formId} onNavigate={onNavigate} />
16
+ export function FormSubmissions({
17
+ formId,
18
+ onNavigate,
19
+ currentUserId,
20
+ currentUserName,
21
+ }: FormSubmissionsProps) {
22
+ return (
23
+ <EntriesInbox
24
+ formId={formId}
25
+ onNavigate={onNavigate}
26
+ currentUserId={currentUserId}
27
+ currentUserName={currentUserName}
28
+ />
29
+ )
16
30
  }
@@ -1,32 +1,20 @@
1
1
  'use client'
2
2
 
3
- import { Breadcrumb } from '../components/ui/Breadcrumb.js'
4
- import { PageHeader } from '../components/ui/PageHeader.js'
5
- import { EmptyState } from '../components/ui/EmptyState.js'
6
- import { ShieldAlert } from 'lucide-react'
3
+ import { EntriesInbox } from './entries/EntriesInbox.js'
7
4
 
8
- export function SpamFolder() {
5
+ export interface SpamFolderProps {
6
+ onNavigate?: (path: string) => void
7
+ currentUserId?: string
8
+ currentUserName?: string
9
+ }
10
+
11
+ export function SpamFolder({ onNavigate, currentUserId, currentUserName }: SpamFolderProps) {
9
12
  return (
10
- <div className="flex flex-col gap-6 p-6">
11
- <PageHeader
12
- flush
13
- title="Spam"
14
- subtitle="Entries caught by the blocklist stay out of the inbox."
15
- breadcrumb={
16
- <Breadcrumb
17
- items={[
18
- { label: 'Dashboard', path: '/' },
19
- { label: 'Forms', path: '/forms' },
20
- { label: 'Spam' },
21
- ]}
22
- />
23
- }
24
- />
25
- <EmptyState
26
- icon={<ShieldAlert size={24} aria-hidden />}
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
- />
30
- </div>
13
+ <EntriesInbox
14
+ initialFilter="spam"
15
+ onNavigate={onNavigate}
16
+ currentUserId={currentUserId}
17
+ currentUserName={currentUserName}
18
+ />
31
19
  )
32
20
  }