@prenta/admin 2.12.1 → 2.14.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 (79) hide show
  1. package/CHANGELOG.md +19 -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/__tests__/views/media-browser.render.test.js +7 -7
  14. package/dist/__tests__/views/media-browser.render.test.js.map +1 -1
  15. package/dist/components/FolderTree.d.ts +4 -2
  16. package/dist/components/FolderTree.d.ts.map +1 -1
  17. package/dist/components/FolderTree.js +4 -2
  18. package/dist/components/FolderTree.js.map +1 -1
  19. package/dist/components/forms/ExportMenu.d.ts +7 -1
  20. package/dist/components/forms/ExportMenu.d.ts.map +1 -1
  21. package/dist/components/forms/ExportMenu.js +17 -5
  22. package/dist/components/forms/ExportMenu.js.map +1 -1
  23. package/dist/layout/nav-config.d.ts.map +1 -1
  24. package/dist/layout/nav-config.js +8 -1
  25. package/dist/layout/nav-config.js.map +1 -1
  26. package/dist/lib/entry-attribution.d.ts +33 -0
  27. package/dist/lib/entry-attribution.d.ts.map +1 -1
  28. package/dist/lib/entry-attribution.js +115 -30
  29. package/dist/lib/entry-attribution.js.map +1 -1
  30. package/dist/lib/forms-service.d.ts +38 -0
  31. package/dist/lib/forms-service.d.ts.map +1 -1
  32. package/dist/lib/forms-service.js +10 -0
  33. package/dist/lib/forms-service.js.map +1 -1
  34. package/dist/lib/page-editor-service.d.ts.map +1 -1
  35. package/dist/lib/page-editor-service.js +3 -0
  36. package/dist/lib/page-editor-service.js.map +1 -1
  37. package/dist/prenta-admin.css +1 -1
  38. package/dist/views/FormEntries.d.ts +4 -1
  39. package/dist/views/FormEntries.d.ts.map +1 -1
  40. package/dist/views/FormEntries.js +2 -2
  41. package/dist/views/FormEntries.js.map +1 -1
  42. package/dist/views/FormSubmissions.d.ts +3 -1
  43. package/dist/views/FormSubmissions.d.ts.map +1 -1
  44. package/dist/views/FormSubmissions.js +2 -2
  45. package/dist/views/FormSubmissions.js.map +1 -1
  46. package/dist/views/MediaBrowser.d.ts.map +1 -1
  47. package/dist/views/MediaBrowser.js +83 -18
  48. package/dist/views/MediaBrowser.js.map +1 -1
  49. package/dist/views/SpamFolder.d.ts +6 -1
  50. package/dist/views/SpamFolder.d.ts.map +1 -1
  51. package/dist/views/SpamFolder.js +4 -11
  52. package/dist/views/SpamFolder.js.map +1 -1
  53. package/dist/views/entries/EntriesInbox.d.ts +12 -2
  54. package/dist/views/entries/EntriesInbox.d.ts.map +1 -1
  55. package/dist/views/entries/EntriesInbox.js +820 -81
  56. package/dist/views/entries/EntriesInbox.js.map +1 -1
  57. package/dist/views/entries/inbox-format.d.ts +0 -1
  58. package/dist/views/entries/inbox-format.d.ts.map +1 -1
  59. package/dist/views/entries/inbox-format.js +0 -4
  60. package/dist/views/entries/inbox-format.js.map +1 -1
  61. package/package.json +3 -3
  62. package/src/AdminRoot.tsx +23 -3
  63. package/src/__tests__/components/attribution-rows.test.ts +19 -5
  64. package/src/__tests__/layout/shell-nav.render.test.tsx +3 -1
  65. package/src/__tests__/views/form-entries.render.test.tsx +5 -5
  66. package/src/__tests__/views/form-submissions.render.test.tsx +3 -3
  67. package/src/__tests__/views/media-browser.render.test.tsx +7 -7
  68. package/src/components/FolderTree.tsx +20 -1
  69. package/src/components/forms/ExportMenu.tsx +37 -13
  70. package/src/layout/nav-config.tsx +8 -0
  71. package/src/lib/entry-attribution.ts +155 -29
  72. package/src/lib/forms-service.ts +44 -0
  73. package/src/lib/page-editor-service.ts +3 -0
  74. package/src/views/FormEntries.tsx +17 -2
  75. package/src/views/FormSubmissions.tsx +16 -2
  76. package/src/views/MediaBrowser.tsx +106 -24
  77. package/src/views/SpamFolder.tsx +14 -26
  78. package/src/views/entries/EntriesInbox.tsx +2119 -337
  79. package/src/views/entries/inbox-format.ts +0 -6
@@ -22,13 +22,17 @@ import {
22
22
  ChevronDown,
23
23
  ChevronLeft,
24
24
  ChevronRight,
25
+ Clock,
25
26
  Copy,
26
27
  Globe,
27
28
  Inbox,
28
29
  Mail,
30
+ MessageSquare,
29
31
  Phone,
32
+ RotateCcw,
30
33
  Rows3,
31
34
  Search,
35
+ ShieldX,
32
36
  Star,
33
37
  Trash2,
34
38
  X,
@@ -47,18 +51,26 @@ import {
47
51
  type EntryCounts,
48
52
  type EntryPatch,
49
53
  type FetchFormEntriesParams,
54
+ type FormEntryNote,
50
55
  type FormListItem,
56
+ type FormsSettingsDocument,
51
57
  } from '../../lib/forms-service.js'
58
+ import {
59
+ BlocklistDialog,
60
+ type BlocklistKind,
61
+ type BlocklistValue,
62
+ } from '../../components/forms/BlocklistDialog.js'
63
+ import { cmsApi } from '../../lib/api.js'
52
64
  import { emitFormsChanged, onFormsChanged } from '../../lib/forms-events.js'
53
- import { buildAttributionRows } from '../../lib/entry-attribution.js'
65
+ import { getEntryAttributionSummary, type AttributionClickId } from '../../lib/entry-attribution.js'
54
66
  import { Breadcrumb } from '../../components/ui/Breadcrumb.js'
55
67
  import { ConfirmDialog } from '../../components/ui/ConfirmDialog.js'
68
+ import { Modal } from '../../components/ui/Modal.js'
56
69
  import { ExportMenu } from '../../components/forms/ExportMenu.js'
57
70
  import {
58
71
  avatarColor,
59
72
  entryIdLabel,
60
73
  entryPreview,
61
- fieldIsWide,
62
74
  fullEntryTime,
63
75
  groupEntries,
64
76
  initials,
@@ -66,32 +78,184 @@ import {
66
78
  senderName,
67
79
  } from './inbox-format.js'
68
80
 
69
- export type InboxFilter = 'all' | 'unread' | 'mine' | 'starred' | 'partial' | 'archived' | 'spam'
81
+ export type InboxFilter =
82
+ | 'all'
83
+ | 'unread'
84
+ | 'mine'
85
+ | 'starred'
86
+ | 'partial'
87
+ | 'archived'
88
+ | 'spam'
89
+ | 'trash'
70
90
 
71
- // The kit's Mine and Partial chips are left out until assignees (F-25) and
72
- // partial entries (F-24) are stored; shown now, they would always read 0.
73
- const FILTERS: { id: InboxFilter; label: string }[] = [
91
+ /** Inbox views. Folders other than Inbox replace this with Back to Inbox. */
92
+ const VIEWS: { id: InboxFilter; label: string }[] = [
74
93
  { id: 'all', label: 'All' },
75
94
  { id: 'unread', label: 'Unread' },
95
+ { id: 'mine', label: 'Mine' },
96
+ ]
97
+
98
+ const FOLDERS: { id: InboxFilter; label: string }[] = [
99
+ { id: 'all', label: 'Inbox' },
76
100
  { id: 'starred', label: 'Starred' },
77
101
  { id: 'archived', label: 'Archived' },
102
+ { id: 'partial', label: 'Partial' },
78
103
  { id: 'spam', label: 'Spam' },
104
+ { id: 'trash', label: 'Trash' },
79
105
  ]
80
106
 
81
- const QUERY_FILTERS = new Set<string>(FILTERS.map((filter) => filter.id))
107
+ const FOLDER_ICON = {
108
+ all: Inbox,
109
+ starred: Star,
110
+ archived: Archive,
111
+ partial: Clock,
112
+ spam: ShieldX,
113
+ trash: Trash2,
114
+ } as const
115
+
116
+ const QUERY_FILTERS = new Set<string>([
117
+ ...VIEWS.map((filter) => filter.id),
118
+ ...FOLDERS.map((filter) => filter.id),
119
+ ])
82
120
  const RAIL_KEY = 'prenta.inbox.railw'
83
121
  const RAIL_MIN = 300
84
122
  const RAIL_MAX = 620
85
- const RAIL_DEFAULT = 320
123
+ const RAIL_DEFAULT = 384
86
124
  const PAGE_SIZE = 100
87
125
 
126
+ const PIPE_STATUSES = [
127
+ { id: 'new', label: 'New', fg: 'var(--acc)', bg: 'var(--acc-l)' },
128
+ { id: 'contacted', label: 'Contacted', fg: 'var(--info)', bg: 'var(--info-l)' },
129
+ { id: 'qualified', label: 'Qualified', fg: 'var(--warn)', bg: 'var(--warn-l)' },
130
+ { id: 'won', label: 'Won', fg: 'var(--suc)', bg: 'var(--suc-l)' },
131
+ { id: 'lost', label: 'Lost', fg: 'var(--sub)', bg: 'var(--bg)' },
132
+ ] as const
133
+
134
+ function pipeOf(status?: string | null) {
135
+ return PIPE_STATUSES.find((item) => item.id === status) ?? PIPE_STATUSES[0]
136
+ }
137
+
138
+ const FORM_BADGE_COLORS: Record<string, { bg: string; fg: string }> = {
139
+ 'free-rfp': { bg: 'var(--acc-l)', fg: 'var(--acc)' },
140
+ 'seo-audit': { bg: 'var(--info-l)', fg: 'var(--info)' },
141
+ 'ad-audit': { bg: 'var(--suc-l)', fg: 'var(--suc)' },
142
+ 'contact-us': { bg: 'var(--warn-l)', fg: 'var(--warn)' },
143
+ 'free-proposal': { bg: 'var(--bg)', fg: 'var(--sub)' },
144
+ }
145
+
146
+ const BADGE_PALETTE: ReadonlyArray<{ bg: string; fg: string }> = [
147
+ { bg: 'var(--acc-l)', fg: 'var(--acc)' },
148
+ { bg: 'var(--info-l)', fg: 'var(--info)' },
149
+ { bg: 'var(--suc-l)', fg: 'var(--suc)' },
150
+ { bg: 'var(--warn-l)', fg: 'var(--warn)' },
151
+ ]
152
+
153
+ function formBadgeStyle(slug?: string | null): { bg: string; fg: string } {
154
+ if (!slug) return BADGE_PALETTE[0]!
155
+ const known = FORM_BADGE_COLORS[slug]
156
+ if (known) return known
157
+ const hash = [...slug].reduce((acc, ch) => acc + ch.charCodeAt(0), 0)
158
+ return BADGE_PALETTE[hash % BADGE_PALETTE.length]!
159
+ }
160
+
161
+ const FALLBACK_FIELD_LABELS: Record<string, string> = {
162
+ first_name: 'First Name',
163
+ last_name: 'Last Name',
164
+ full_name: 'Full Name',
165
+ name: 'Name',
166
+ business: 'Business Name',
167
+ company: 'Company',
168
+ website: 'Website URL',
169
+ phone: 'Phone',
170
+ email: 'Email',
171
+ services: 'Services Interested In',
172
+ description: 'Brief Description of Your Project',
173
+ budget: 'Budget Range',
174
+ timeline: 'Timeline',
175
+ message: 'Message',
176
+ monthly_spend: 'Current Monthly Spend',
177
+ platforms: 'Ad Platforms',
178
+ goal: 'Primary Goal',
179
+ source: 'Source',
180
+ }
181
+
182
+ function humanizeFieldKey(key: string): string {
183
+ const known = FALLBACK_FIELD_LABELS[key]
184
+ if (known) return known
185
+ return key.replace(/[-_]+/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase())
186
+ }
187
+
188
+ const LONG_MESSAGE_FIELDS = new Set(['description', 'message', 'services', 'platforms', 'goal'])
189
+
190
+ const FREE_EMAIL_DOMAINS = new Set([
191
+ 'gmail.com',
192
+ 'yahoo.com',
193
+ 'outlook.com',
194
+ 'hotmail.com',
195
+ 'icloud.com',
196
+ 'aol.com',
197
+ 'proton.me',
198
+ 'protonmail.com',
199
+ 'live.com',
200
+ 'msn.com',
201
+ 'mail.ru',
202
+ ])
203
+
204
+ const SPAM_BY_LABELS: Record<string, string> = {
205
+ ai: 'AI review',
206
+ keyword: 'Keyword filter',
207
+ fast: 'Too fast',
208
+ honeypot: 'Honeypot',
209
+ manual: 'Spam',
210
+ }
211
+
212
+ const DAY_MS = 86_400_000
213
+
214
+ function daysLeftInTrash(deletedAt?: string | null): number {
215
+ if (!deletedAt) return 30
216
+ return Math.max(0, 30 - Math.floor((Date.now() - new Date(deletedAt).getTime()) / DAY_MS))
217
+ }
218
+
219
+ const NON_INPUT_FIELD_SET = new Set([
220
+ 'richtext',
221
+ 'divider',
222
+ 'honeypot',
223
+ 'heading',
224
+ 'content',
225
+ 'pagebreak',
226
+ ])
227
+
228
+ function formatFieldDisplay(_key: string, raw: string, field?: FormField): string {
229
+ if (!raw) return ''
230
+ if (field?.options && field.options.length > 0) {
231
+ const parts = raw.split(/,\s*/)
232
+ const mapped = parts.map((part) => {
233
+ const opt = field.options?.find((o) => o.value === part || o.label === part)
234
+ return opt ? opt.label : part
235
+ })
236
+ return mapped.join(', ')
237
+ }
238
+ return raw
239
+ }
240
+
241
+ export interface TeamMember {
242
+ id: string
243
+ name: string
244
+ email?: string
245
+ }
246
+
88
247
  export interface EntriesInboxProps {
89
248
  /** Lock the inbox to one form. All Entries leaves this unset. */
90
249
  formId?: string
250
+ /** Optional initial filter override (e.g. 'spam' when mounted on `/forms/spam`). */
251
+ initialFilter?: InboxFilter
252
+ currentPath?: string
91
253
  onNavigate?: (path: string) => void
254
+ currentUserId?: string
255
+ currentUserName?: string
92
256
  }
93
257
 
94
- function filterParams(filter: InboxFilter): Partial<FetchFormEntriesParams> | null {
258
+ function filterParams(filter: InboxFilter, assigneeId?: string): Partial<FetchFormEntriesParams> {
95
259
  switch (filter) {
96
260
  case 'unread':
97
261
  return { unread: true }
@@ -101,9 +265,12 @@ function filterParams(filter: InboxFilter): Partial<FetchFormEntriesParams> | nu
101
265
  return { archived: true }
102
266
  case 'spam':
103
267
  return { spamStatus: 'spam' }
104
- case 'mine':
268
+ case 'trash':
269
+ return { folder: 'trash' }
105
270
  case 'partial':
106
- return null
271
+ return { folder: 'partial' }
272
+ case 'mine':
273
+ return { folder: 'mine', ...(assigneeId ? { assigneeId } : {}) }
107
274
  default:
108
275
  return {}
109
276
  }
@@ -127,13 +294,25 @@ function displayValue(value: unknown): string {
127
294
  return String(value)
128
295
  }
129
296
 
130
- export function EntriesInbox({ formId, onNavigate }: EntriesInboxProps) {
297
+ export function EntriesInbox({
298
+ formId,
299
+ initialFilter,
300
+ currentPath,
301
+ onNavigate,
302
+ currentUserId,
303
+ currentUserName,
304
+ }: EntriesInboxProps) {
131
305
  const searchId = useId()
132
306
  const listRef = useRef<HTMLDivElement>(null)
133
307
  const searchRef = useRef<HTMLInputElement>(null)
134
- const initial = formId ? { form: formId, filter: 'all' as InboxFilter } : readQuery()
308
+ const initial = formId
309
+ ? { form: formId, filter: (initialFilter ?? 'all') as InboxFilter }
310
+ : initialFilter
311
+ ? { ...readQuery(), filter: initialFilter }
312
+ : readQuery()
135
313
 
136
314
  const [forms, setForms] = useState<FormListItem[]>([])
315
+ const [team, setTeam] = useState<TeamMember[]>([])
137
316
  const [lockedName, setLockedName] = useState('')
138
317
  const [entries, setEntries] = useState<FormSubmission[]>([])
139
318
  const [total, setTotal] = useState(0)
@@ -150,15 +329,214 @@ export function EntriesInbox({ formId, onNavigate }: EntriesInboxProps) {
150
329
  const [dragging, setDragging] = useState(false)
151
330
  const [narrow, setNarrow] = useState(false)
152
331
  const [confirmDelete, setConfirmDelete] = useState<string[] | null>(null)
332
+ const [emptyTrashOpen, setEmptyTrashOpen] = useState(false)
333
+ const [blocklistTab, setBlocklistTab] = useState<BlocklistKind | null>(null)
334
+ const [formsSettingsDoc, setFormsSettingsDoc] = useState<FormsSettingsDocument | null>(null)
335
+ const [blocked, setBlocked] = useState<BlocklistValue>({ words: [], domains: [] })
336
+ const [toastMsg, setToastMsg] = useState('')
337
+ const [toastUndo, setToastUndo] = useState<(() => void) | null>(null)
338
+ const toastTimerRef = useRef<number>(0)
153
339
 
154
340
  const scopedFormId = formId ?? (formFilter === 'all' ? undefined : formFilter)
155
- const unsupported = filter === 'mine' || filter === 'partial'
341
+ const unsupported = false
342
+
343
+ useEffect(() => {
344
+ let cancelled = false
345
+ void cmsApi<FormsSettingsDocument>('/globals/formsSettings')
346
+ .then((res) => {
347
+ if (cancelled || !res.data) return
348
+ setFormsSettingsDoc(res.data)
349
+ if (res.data.spam?.blocklist) {
350
+ setBlocked({
351
+ words: Array.isArray(res.data.spam.blocklist.words)
352
+ ? res.data.spam.blocklist.words
353
+ : [],
354
+ domains: Array.isArray(res.data.spam.blocklist.domains)
355
+ ? res.data.spam.blocklist.domains
356
+ : [],
357
+ })
358
+ }
359
+ })
360
+ .catch(() => {})
361
+ return () => {
362
+ cancelled = true
363
+ }
364
+ }, [])
365
+
366
+ const showUndoToast = useCallback((message: string, undo?: () => void) => {
367
+ window.clearTimeout(toastTimerRef.current)
368
+ setToastMsg(message)
369
+ setToastUndo(() => undo ?? null)
370
+ toastTimerRef.current = window.setTimeout(
371
+ () => {
372
+ setToastMsg('')
373
+ setToastUndo(null)
374
+ },
375
+ undo ? 6000 : 1800,
376
+ )
377
+ }, [])
378
+
379
+ const handleBlocklistChange = useCallback(
380
+ async (next: BlocklistValue): Promise<boolean> => {
381
+ const prev = blocked
382
+ setBlocked(next)
383
+ const baseDoc: FormsSettingsDocument = formsSettingsDoc ?? {
384
+ spam: {
385
+ honeypot: true,
386
+ captchaScope: 'all',
387
+ rateLimit: { max: 5, window: '10m' },
388
+ minSeconds: 3,
389
+ action: 'quarantine',
390
+ blocklist: next,
391
+ ai: {
392
+ on: false,
393
+ strictness: 'balanced',
394
+ holdNotifications: true,
395
+ learnFromCorrections: true,
396
+ },
397
+ },
398
+ defaults: {
399
+ recipients: [],
400
+ replyToSubmitter: true,
401
+ successMessage: 'Thanks — we got your message.',
402
+ confirmationEmail: false,
403
+ },
404
+ retention: {
405
+ entryDays: null,
406
+ spamDays: 30,
407
+ archivedDays: null,
408
+ deliveryLogDays: 90,
409
+ ipStorage: 'anon',
410
+ deleteFilesWithEntry: true,
411
+ },
412
+ attribution: {
413
+ record: true,
414
+ requireConsent: false,
415
+ firstTouchDays: 30,
416
+ lastTouchHours: 24,
417
+ },
418
+ updatedAt: '',
419
+ updatedBy: '',
420
+ }
421
+ const updatedDoc: FormsSettingsDocument = {
422
+ ...baseDoc,
423
+ spam: { ...baseDoc.spam, blocklist: next },
424
+ }
425
+ const res = await cmsApi<FormsSettingsDocument>('/globals/formsSettings', {
426
+ method: 'PUT',
427
+ body: JSON.stringify(updatedDoc),
428
+ })
429
+ if (res.error) {
430
+ setBlocked(prev)
431
+ toast.error(res.error)
432
+ return false
433
+ }
434
+ setFormsSettingsDoc(res.data ?? updatedDoc)
435
+ return true
436
+ },
437
+ [blocked, formsSettingsDoc],
438
+ )
439
+
440
+ const handleBlockDomain = useCallback(
441
+ async (domain: string) => {
442
+ const normalized = domain.trim().toLowerCase()
443
+ if (!normalized || FREE_EMAIL_DOMAINS.has(normalized)) return
444
+ if (blocked.domains.some((d) => d.term === normalized)) return
445
+ const next: BlocklistValue = {
446
+ ...blocked,
447
+ domains: [
448
+ {
449
+ term: normalized,
450
+ addedAt: new Date().toISOString(),
451
+ source: 'spam',
452
+ hits30d: 0,
453
+ lastHitAt: null,
454
+ },
455
+ ...blocked.domains,
456
+ ],
457
+ }
458
+ const ok = await handleBlocklistChange(next)
459
+ if (ok) showUndoToast(`${normalized} added to blocked domains`)
460
+ },
461
+ [blocked, handleBlocklistChange, showUndoToast],
462
+ )
463
+
464
+ useEffect(() => {
465
+ if (formId || initialFilter || !currentPath) return
466
+ const qIndex = currentPath.indexOf('?')
467
+ const params = new URLSearchParams(qIndex >= 0 ? currentPath.slice(qIndex + 1) : '')
468
+ const rawFilter = params.get('filter') ?? ''
469
+ const nextFilter: InboxFilter = QUERY_FILTERS.has(rawFilter)
470
+ ? (rawFilter as InboxFilter)
471
+ : 'all'
472
+ setFilter((prev) => (prev === nextFilter ? prev : nextFilter))
473
+ const rawForm = params.get('form') || 'all'
474
+ if (rawForm === 'all') {
475
+ setFormFilter('all')
476
+ } else if (forms.length > 0) {
477
+ const match = forms.find((f) => f.id === rawForm || f.slug === rawForm)
478
+ if (match) setFormFilter(match.id)
479
+ }
480
+ }, [currentPath, formId, initialFilter, forms])
481
+
482
+ useEffect(() => {
483
+ let cancelled = false
484
+ const parseList = (raw: unknown): TeamMember[] => {
485
+ const list = Array.isArray(raw)
486
+ ? raw
487
+ : raw && typeof raw === 'object' && Array.isArray((raw as { users?: unknown }).users)
488
+ ? ((raw as { users: unknown[] }).users ?? [])
489
+ : []
490
+ return list
491
+ .filter((u): u is { id: string; name?: string; email?: string } =>
492
+ Boolean(u && typeof (u as { id?: unknown }).id === 'string'),
493
+ )
494
+ .map((u) => ({
495
+ id: u.id,
496
+ name: (u.name && u.name.trim()) || u.email || u.id,
497
+ email: u.email,
498
+ }))
499
+ }
500
+ void cmsApi<unknown>('/users?pageSize=200')
501
+ .then(async (res) => {
502
+ if (cancelled) return
503
+ const mapped = res.data ? parseList(res.data) : []
504
+ if (mapped.length > 0) {
505
+ setTeam(mapped)
506
+ return
507
+ }
508
+ const fallback = await cmsApi<unknown>('/users/search?q=%40')
509
+ if (cancelled || !fallback.data) return
510
+ const searched = parseList(fallback.data)
511
+ if (searched.length > 0) setTeam(searched)
512
+ })
513
+ .catch(() => {})
514
+ return () => {
515
+ cancelled = true
516
+ }
517
+ }, [])
518
+
519
+ const effectiveTeam = useMemo<TeamMember[]>(() => {
520
+ const map = new Map<string, TeamMember>()
521
+ for (const member of team) map.set(member.id, member)
522
+ if (currentUserId && !map.has(currentUserId)) {
523
+ map.set(currentUserId, { id: currentUserId, name: currentUserName || 'You' })
524
+ }
525
+ for (const entry of entries) {
526
+ const aId = entry.assigneeId
527
+ const aName = (entry as FormSubmission & { assigneeName?: string | null }).assigneeName
528
+ if (aId && !map.has(aId)) {
529
+ map.set(aId, { id: aId, name: aName || aId })
530
+ }
531
+ }
532
+ return [...map.values()]
533
+ }, [team, currentUserId, currentUserName, entries])
156
534
 
157
535
  useEffect(() => {
158
536
  try {
159
537
  const stored = Number(globalThis.localStorage?.getItem(RAIL_KEY))
160
538
  // 384 was the first default. A saved copy of that width keeps the entry pane narrow.
161
- if (stored >= RAIL_MIN && stored <= RAIL_MAX && stored !== 384) setRailW(stored)
539
+ if (stored >= RAIL_MIN && stored <= RAIL_MAX) setRailW(stored)
162
540
  } catch {
163
541
  // Storage can be missing in a headless document.
164
542
  }
@@ -215,14 +593,7 @@ export function EntriesInbox({ formId, onNavigate }: EntriesInboxProps) {
215
593
  const load = useCallback(async () => {
216
594
  setLoading(true)
217
595
  setError(null)
218
- const params = filterParams(filter)
219
- if (!params) {
220
- setEntries([])
221
- setTotal(0)
222
- setChecked(new Set())
223
- setLoading(false)
224
- return
225
- }
596
+ const params = filterParams(filter, currentUserId)
226
597
  try {
227
598
  const collected: FormSubmission[] = []
228
599
  const seen = new Set<string>()
@@ -257,13 +628,16 @@ export function EntriesInbox({ formId, onNavigate }: EntriesInboxProps) {
257
628
  } finally {
258
629
  setLoading(false)
259
630
  }
260
- }, [filter, scopedFormId, search])
631
+ }, [filter, scopedFormId, search, currentUserId])
261
632
 
262
633
  const loadCounts = useCallback(() => {
263
- void fetchEntryCounts({ formId: scopedFormId })
634
+ void fetchEntryCounts({
635
+ formId: scopedFormId,
636
+ ...(currentUserId ? { assigneeId: currentUserId } : {}),
637
+ })
264
638
  .then(setCounts)
265
639
  .catch(() => {})
266
- }, [scopedFormId])
640
+ }, [scopedFormId, currentUserId])
267
641
 
268
642
  useEffect(() => {
269
643
  void load()
@@ -283,18 +657,90 @@ export function EntriesInbox({ formId, onNavigate }: EntriesInboxProps) {
283
657
  )
284
658
 
285
659
  const selectedForm = forms.find((form) => form.id === formFilter)
660
+ const folder = filter === 'unread' || filter === 'mine' ? 'all' : filter
661
+ const FolderIcon = FOLDER_ICON[folder]
286
662
  const title =
287
663
  filter === 'spam'
288
664
  ? 'Spam'
289
665
  : filter === 'partial'
290
666
  ? 'Partial entries'
291
- : formId
292
- ? lockedName || 'Entries'
293
- : selectedForm?.name || 'All Entries'
667
+ : filter === 'starred'
668
+ ? 'Starred'
669
+ : filter === 'archived'
670
+ ? 'Archived'
671
+ : filter === 'trash'
672
+ ? 'Trash'
673
+ : formId
674
+ ? lockedName || 'Entries'
675
+ : selectedForm?.name || 'All Entries'
676
+
677
+ const trashCount = useMemo(() => {
678
+ const local = entries.filter(
679
+ (entry) => Boolean(entry.deleted) && entry.spamStatus !== 'spam',
680
+ ).length
681
+ return typeof counts?.trash === 'number' && counts.trash > 0 ? counts.trash : local
682
+ }, [entries, counts?.trash])
683
+
684
+ const partialCount = useMemo(() => {
685
+ const local = entries.filter(
686
+ (entry) => Boolean(entry.partial) && !entry.deleted && entry.spamStatus !== 'spam',
687
+ ).length
688
+ return typeof counts?.partial === 'number' && counts.partial > 0 ? counts.partial : local
689
+ }, [entries, counts?.partial])
690
+
691
+ const mineCount = useMemo(() => {
692
+ const me = currentUserId || 'self'
693
+ const local = entries.filter(
694
+ (entry) =>
695
+ !entry.deleted &&
696
+ !entry.partial &&
697
+ entry.assigneeId === me &&
698
+ entry.status !== 'won' &&
699
+ entry.status !== 'lost' &&
700
+ !entry.archived &&
701
+ entry.spamStatus !== 'spam',
702
+ ).length
703
+ return typeof counts?.mine === 'number' && counts.mine > 0 ? counts.mine : local
704
+ }, [entries, currentUserId, counts?.mine])
705
+
706
+ const visibleEntries = useMemo(() => {
707
+ if (filter === 'trash') {
708
+ return entries
709
+ .filter((entry) => Boolean(entry.deleted) && entry.spamStatus !== 'spam')
710
+ .sort(
711
+ (a, b) =>
712
+ new Date(b.deleted?.at ?? b.submittedAt).getTime() -
713
+ new Date(a.deleted?.at ?? a.submittedAt).getTime(),
714
+ )
715
+ }
716
+ const live = entries.filter((entry) => !entry.deleted)
717
+ if (filter === 'partial') {
718
+ return live.filter((entry) => Boolean(entry.partial) && entry.spamStatus !== 'spam')
719
+ }
720
+ if (filter === 'spam') {
721
+ return live.filter((entry) => entry.spamStatus === 'spam')
722
+ }
723
+ const nonPartial = live.filter((entry) => !entry.partial)
724
+ if (filter === 'mine') {
725
+ const me = currentUserId || 'self'
726
+ return nonPartial.filter(
727
+ (entry) =>
728
+ entry.assigneeId === me &&
729
+ entry.status !== 'won' &&
730
+ entry.status !== 'lost' &&
731
+ !entry.archived &&
732
+ entry.spamStatus !== 'spam',
733
+ )
734
+ }
735
+ return nonPartial
736
+ }, [entries, filter, currentUserId])
294
737
 
295
- const groups = useMemo(() => groupEntries(entries), [entries])
296
- const active = entries.find((entry) => entry.id === activeId) ?? null
297
- const unreadInList = entries.filter((entry) => entry.unread).length
738
+ const groups = useMemo(() => groupEntries(visibleEntries), [visibleEntries])
739
+ const active =
740
+ visibleEntries.find((entry) => entry.id === activeId) ??
741
+ entries.find((entry) => entry.id === activeId) ??
742
+ null
743
+ const unreadInList = visibleEntries.filter((entry) => entry.unread).length
298
744
 
299
745
  function pickFilter(next: InboxFilter) {
300
746
  setFilter(next)
@@ -308,29 +754,138 @@ export function EntriesInbox({ formId, onNavigate }: EntriesInboxProps) {
308
754
  writeQuery(filter, next)
309
755
  }
310
756
 
311
- const patchOne = useCallback(async (id: string, patch: EntryPatch, message?: string) => {
312
- const res = await updateEntry(id, patch)
313
- if (res.error) {
314
- toast.error(res.error)
315
- return
757
+ const patchOne = useCallback(
758
+ async (
759
+ id: string,
760
+ patch: EntryPatch,
761
+ message?: string,
762
+ undoPatch?: EntryPatch,
763
+ clearSelectionOnApply?: boolean,
764
+ ) => {
765
+ const prevActive = activeId
766
+ setEntries((current) =>
767
+ current.map((entry) => (entry.id === id ? { ...entry, ...patch } : entry)),
768
+ )
769
+ if (clearSelectionOnApply && activeId === id) setActiveId(null)
770
+ const res = await updateEntry(id, patch)
771
+ if (res.error) {
772
+ toast.error(res.error)
773
+ void load()
774
+ return
775
+ }
776
+ if (res.data) {
777
+ setEntries((current) =>
778
+ current.map((entry) => (entry.id === id ? { ...entry, ...res.data, ...patch } : entry)),
779
+ )
780
+ }
781
+ if (message) {
782
+ if (undoPatch) {
783
+ showUndoToast(message, () => {
784
+ void (async () => {
785
+ const undoRes = await updateEntry(id, undoPatch)
786
+ if (undoRes.error) {
787
+ toast.error(undoRes.error)
788
+ void load()
789
+ return
790
+ }
791
+ setEntries((current) =>
792
+ current.map((entry) => (entry.id === id ? { ...entry, ...undoPatch } : entry)),
793
+ )
794
+ setActiveId(prevActive)
795
+ showUndoToast('Undone')
796
+ emitFormsChanged()
797
+ })()
798
+ })
799
+ } else {
800
+ showUndoToast(message)
801
+ }
802
+ }
803
+ emitFormsChanged()
804
+ },
805
+ [activeId, load, showUndoToast],
806
+ )
807
+
808
+ const handleTrashOrDelete = useCallback(
809
+ async (id: string) => {
810
+ const target = entries.find((e) => e.id === id)
811
+ if (!target) return
812
+ if (target.spamStatus === 'spam' || target.deleted) {
813
+ setConfirmDelete([id])
814
+ return
815
+ }
816
+ const deletedPayload = {
817
+ at: new Date().toISOString(),
818
+ by: currentUserId || 'self',
819
+ byName: currentUserName || 'You',
820
+ }
821
+ await patchOne(id, { deleted: deletedPayload }, 'Moved to Trash', { deleted: null }, true)
822
+ },
823
+ [entries, currentUserId, currentUserName, patchOne],
824
+ )
825
+
826
+ const handleRestore = useCallback(
827
+ async (id: string) => {
828
+ const target = entries.find((e) => e.id === id)
829
+ if (!target) return
830
+ const prevDeleted = target.deleted ?? null
831
+ await patchOne(
832
+ id,
833
+ { deleted: null },
834
+ target.archived ? 'Restored to Archived' : 'Restored to Inbox',
835
+ { deleted: prevDeleted },
836
+ true,
837
+ )
838
+ },
839
+ [entries, patchOne],
840
+ )
841
+
842
+ const handleEmptyTrash = useCallback(async () => {
843
+ const trashedIds = visibleEntries
844
+ .filter((e) => Boolean(e.deleted) && e.spamStatus !== 'spam')
845
+ .map((e) => e.id)
846
+ setEmptyTrashOpen(false)
847
+ if (trashedIds.length === 0) return
848
+ const results = await Promise.allSettled(trashedIds.map((id) => deleteEntry(id)))
849
+ const failed = results.filter((r) => r.status === 'rejected' || r.value.error).length
850
+ const deletedCount = trashedIds.length - failed
851
+ setActiveId(null)
852
+ if (failed > 0) {
853
+ toast.error(`${failed} of ${trashedIds.length} could not be deleted`)
854
+ } else if (deletedCount > 0) {
855
+ showUndoToast(`${deletedCount} ${deletedCount === 1 ? 'entry' : 'entries'} deleted forever`)
316
856
  }
317
- setEntries((current) =>
318
- current.map((entry) => (entry.id === id ? { ...entry, ...patch } : entry)),
319
- )
320
- if (message) toast.success(message)
321
857
  emitFormsChanged()
322
- }, [])
858
+ }, [visibleEntries, showUndoToast])
859
+
860
+ const handleEmptySpam = useCallback(async () => {
861
+ const spamIds = visibleEntries.filter((e) => e.spamStatus === 'spam').map((e) => e.id)
862
+ if (spamIds.length === 0) return
863
+ const results = await Promise.allSettled(spamIds.map((id) => deleteEntry(id)))
864
+ const failed = results.filter((r) => r.status === 'rejected' || r.value.error).length
865
+ const deletedCount = spamIds.length - failed
866
+ setActiveId(null)
867
+ if (failed > 0) {
868
+ toast.error(`${failed} of ${spamIds.length} could not be deleted`)
869
+ } else if (deletedCount > 0) {
870
+ showUndoToast(`${deletedCount} spam ${deletedCount === 1 ? 'entry' : 'entries'} deleted`)
871
+ }
872
+ emitFormsChanged()
873
+ }, [visibleEntries, showUndoToast])
323
874
 
324
875
  function openEntry(id: string) {
325
876
  setActiveId(id)
326
- const entry = entries.find((item) => item.id === id)
877
+ const entry =
878
+ visibleEntries.find((item) => item.id === id) ?? entries.find((item) => item.id === id)
327
879
  if (entry?.unread) void patchOne(id, { unread: false })
328
880
  }
329
881
 
330
882
  function move(delta: number) {
331
- if (entries.length === 0) return
332
- const index = entries.findIndex((entry) => entry.id === activeId)
333
- const next = entries[Math.min(entries.length - 1, Math.max(0, index + delta))]
883
+ if (visibleEntries.length === 0) return
884
+ const index = visibleEntries.findIndex((entry) => entry.id === activeId)
885
+ const next =
886
+ visibleEntries[
887
+ index < 0 ? 0 : Math.min(visibleEntries.length - 1, Math.max(0, index + delta))
888
+ ]
334
889
  if (!next) return
335
890
  openEntry(next.id)
336
891
  const list = listRef.current
@@ -372,18 +927,19 @@ export function EntriesInbox({ formId, onNavigate }: EntriesInboxProps) {
372
927
  event.preventDefault()
373
928
  move(-1)
374
929
  } else if (key === 's' && activeId) {
375
- const entry = entries.find((item) => item.id === activeId)
376
- if (entry) void patchOne(entry.id, { starred: !entry.starred })
930
+ const entry = visibleEntries.find((item) => item.id === activeId)
931
+ if (entry && !entry.deleted) void patchOne(entry.id, { starred: !entry.starred })
377
932
  } else if (key === 'u' && activeId) {
378
- const entry = entries.find((item) => item.id === activeId)
933
+ const entry = visibleEntries.find((item) => item.id === activeId)
379
934
  if (entry) void patchOne(entry.id, { unread: !entry.unread })
380
935
  } else if (key === 'e' && activeId) {
381
- const entry = entries.find((item) => item.id === activeId)
382
- if (entry) {
936
+ const entry = visibleEntries.find((item) => item.id === activeId)
937
+ if (entry && !entry.deleted && entry.spamStatus !== 'spam') {
383
938
  void patchOne(
384
939
  entry.id,
385
940
  { archived: !entry.archived },
386
- entry.archived ? 'Unarchived' : 'Archived',
941
+ entry.archived ? 'Moved to inbox' : 'Archived',
942
+ { archived: entry.archived },
387
943
  )
388
944
  }
389
945
  }
@@ -418,10 +974,71 @@ export function EntriesInbox({ formId, onNavigate }: EntriesInboxProps) {
418
974
  window.addEventListener('pointerup', stop)
419
975
  }
420
976
 
977
+ const moveIdsToTrash = useCallback(
978
+ async (ids: string[]) => {
979
+ const deletedPayload = {
980
+ at: new Date().toISOString(),
981
+ by: currentUserId || 'self',
982
+ byName: currentUserName || 'You',
983
+ }
984
+ const results = await Promise.allSettled(
985
+ ids.map(async (id) => ({ id, res: await updateEntry(id, { deleted: deletedPayload }) })),
986
+ )
987
+ const succeededIds = results
988
+ .filter(
989
+ (r): r is PromiseFulfilledResult<{ id: string; res: { error?: string } }> =>
990
+ r.status === 'fulfilled' && !r.value.res.error,
991
+ )
992
+ .map((r) => r.value.id)
993
+ const failedCount = ids.length - succeededIds.length
994
+ setChecked(new Set())
995
+ if (activeId && succeededIds.includes(activeId)) setActiveId(null)
996
+ if (failedCount > 0) {
997
+ toast.error(`${failedCount} of ${ids.length} could not be moved to Trash`)
998
+ }
999
+ if (succeededIds.length > 0) {
1000
+ showUndoToast(
1001
+ succeededIds.length === 1
1002
+ ? 'Moved to Trash'
1003
+ : `${succeededIds.length} entries moved to Trash`,
1004
+ () => {
1005
+ void (async () => {
1006
+ const undoResults = await Promise.allSettled(
1007
+ succeededIds.map((id) => updateEntry(id, { deleted: null })),
1008
+ )
1009
+ const undoFailed = undoResults.filter(
1010
+ (r) => r.status === 'rejected' || r.value.error,
1011
+ ).length
1012
+ if (undoFailed > 0) {
1013
+ toast.error(`${undoFailed} of ${succeededIds.length} could not be restored`)
1014
+ } else {
1015
+ showUndoToast('Undone')
1016
+ }
1017
+ emitFormsChanged()
1018
+ })()
1019
+ },
1020
+ )
1021
+ }
1022
+ emitFormsChanged()
1023
+ },
1024
+ [activeId, currentUserId, currentUserName, showUndoToast],
1025
+ )
1026
+
421
1027
  async function confirmAndDelete() {
422
1028
  const ids = confirmDelete ?? []
423
1029
  setConfirmDelete(null)
424
1030
  if (ids.length === 0) return
1031
+ const isPermanent =
1032
+ filter === 'trash' ||
1033
+ filter === 'spam' ||
1034
+ ids.every((id) => {
1035
+ const target = entries.find((e) => e.id === id)
1036
+ return Boolean(target?.deleted || target?.spamStatus === 'spam')
1037
+ })
1038
+ if (!isPermanent) {
1039
+ await moveIdsToTrash(ids)
1040
+ return
1041
+ }
425
1042
  if (ids.length === 1) {
426
1043
  const res = await deleteEntry(ids[0]!)
427
1044
  if (res.error) toast.error(res.error)
@@ -434,6 +1051,7 @@ export function EntriesInbox({ formId, onNavigate }: EntriesInboxProps) {
434
1051
  if (failed > 0) toast.error(`${failed} of ${ids.length} could not be deleted`)
435
1052
  else toast.success(`${ids.length} entries deleted`)
436
1053
  }
1054
+ setChecked(new Set())
437
1055
  if (activeId && ids.includes(activeId)) setActiveId(null)
438
1056
  emitFormsChanged()
439
1057
  }
@@ -443,10 +1061,36 @@ export function EntriesInbox({ formId, onNavigate }: EntriesInboxProps) {
443
1061
  if (ids.length === 0) return
444
1062
  const res = await bulkUpdateEntries(ids, patch)
445
1063
  if (res.error) toast.error(res.error)
446
- else toast.success(message)
1064
+ else showUndoToast(message)
1065
+ setChecked(new Set())
1066
+ emitFormsChanged()
1067
+ }
1068
+
1069
+ async function bulkRestore() {
1070
+ const ids = [...checked]
1071
+ if (ids.length === 0) return
1072
+ const results = await Promise.allSettled(ids.map((id) => updateEntry(id, { deleted: null })))
1073
+ const failed = results.filter((r) => r.status === 'rejected' || r.value.error).length
1074
+ const restoredCount = ids.length - failed
1075
+ setChecked(new Set())
1076
+ if (failed > 0) {
1077
+ toast.error(`${failed} of ${ids.length} could not be restored`)
1078
+ } else if (restoredCount > 0) {
1079
+ showUndoToast(`${restoredCount} ${restoredCount === 1 ? 'entry' : 'entries'} updated`)
1080
+ }
447
1081
  emitFormsChanged()
448
1082
  }
449
1083
 
1084
+ async function bulkDelete() {
1085
+ const ids = [...checked]
1086
+ if (ids.length === 0) return
1087
+ if (filter === 'trash' || filter === 'spam' || ids.length > 10) {
1088
+ setConfirmDelete(ids)
1089
+ return
1090
+ }
1091
+ await moveIdsToTrash(ids)
1092
+ }
1093
+
450
1094
  const showList = !narrow || !activeId
451
1095
  const showDetail = !narrow || !!activeId
452
1096
 
@@ -464,7 +1108,7 @@ export function EntriesInbox({ formId, onNavigate }: EntriesInboxProps) {
464
1108
  <h1 className="text-txt m-0 text-[21px] font-bold tracking-[-0.5px] whitespace-nowrap">
465
1109
  {title}
466
1110
  </h1>
467
- {counts && filter !== 'spam' && filter !== 'partial' ? (
1111
+ {counts && filter !== 'spam' && filter !== 'partial' && filter !== 'trash' ? (
468
1112
  <div className="flex flex-wrap items-center gap-1.5">
469
1113
  <span className="border-bdr bg-bg text-sub inline-flex items-center gap-[5px] rounded-[6px] border px-[9px] py-1 text-[11.5px]">
470
1114
  <b className="text-txt font-bold tabular-nums">{counts.total}</b> total
@@ -499,6 +1143,7 @@ export function EntriesInbox({ formId, onNavigate }: EntriesInboxProps) {
499
1143
  : 'border-bdr bg-bg text-sub hover:border-acc-m hover:text-acc'
500
1144
  }`}
501
1145
  >
1146
+ <Star size={11} aria-hidden className="text-warn -mr-0.5 fill-current" />
502
1147
  <b
503
1148
  className={`font-bold tabular-nums ${filter === 'starred' ? 'text-acc' : 'text-txt'}`}
504
1149
  >
@@ -509,11 +1154,72 @@ export function EntriesInbox({ formId, onNavigate }: EntriesInboxProps) {
509
1154
  ) : null}
510
1155
  </div>
511
1156
  ) : null}
1157
+ {filter === 'starred' ? (
1158
+ <span className="text-sub text-[12.5px]">
1159
+ Shared with your team · includes archived entries
1160
+ </span>
1161
+ ) : null}
512
1162
  {filter === 'spam' && counts ? (
513
- <span className="border-bdr bg-bg text-sub inline-flex items-center rounded-[6px] border px-[9px] py-1 text-[11.5px]">
514
- <b className="text-txt font-bold tabular-nums">{total}</b>&nbsp;in spam
1163
+ <>
1164
+ <span className="border-bdr bg-bg text-sub inline-flex items-center rounded-[6px] border px-[9px] py-1 text-[11.5px]">
1165
+ <b className="text-txt font-bold tabular-nums">{visibleEntries.length}</b>&nbsp;in
1166
+ spam
1167
+ </span>
1168
+ {visibleEntries.length > 0 ? (
1169
+ <div className="text-sub flex flex-wrap items-center gap-3 text-[12.5px]">
1170
+ <span>Kept for 30 days, then deleted.</span>
1171
+ <button
1172
+ type="button"
1173
+ onClick={() => setBlocklistTab('words')}
1174
+ className="text-sub hover:bg-acc-l hover:text-acc rounded-[7px] px-[9px] py-1.5 text-[12.5px]"
1175
+ >
1176
+ Blocked words &amp; domains
1177
+ </button>
1178
+ <button
1179
+ type="button"
1180
+ onClick={() => onNavigate?.('/forms/settings')}
1181
+ className="text-acc font-medium hover:underline"
1182
+ >
1183
+ Spam settings
1184
+ </button>
1185
+ <button
1186
+ type="button"
1187
+ onClick={() => void handleEmptySpam()}
1188
+ className="border-bdr bg-card text-txt hover:border-acc-m hover:bg-acc-l hover:text-acc inline-flex items-center gap-1.5 rounded-[8px] border px-3 py-1.5 text-[13px]"
1189
+ >
1190
+ <Trash2 size={13} aria-hidden />
1191
+ Empty spam
1192
+ </button>
1193
+ </div>
1194
+ ) : null}
1195
+ </>
1196
+ ) : null}
1197
+ {filter === 'partial' ? (
1198
+ <span className="border-bdr bg-bg text-sub inline-flex items-center gap-1 rounded-[6px] border px-[9px] py-1 text-[11.5px]">
1199
+ <b className="text-txt font-bold tabular-nums">{partialCount}</b> didn’t finish · kept
1200
+ 30 days
515
1201
  </span>
516
1202
  ) : null}
1203
+ {filter === 'trash' ? (
1204
+ <>
1205
+ <span className="border-bdr bg-bg text-sub inline-flex items-center gap-1 rounded-[6px] border px-[9px] py-1 text-[11.5px]">
1206
+ <b className="text-txt font-bold tabular-nums">{trashCount}</b> in trash
1207
+ </span>
1208
+ <div className="text-sub flex flex-wrap items-center gap-3 text-[12.5px]">
1209
+ <span>Deleted entries are kept for 30 days, then removed for good.</span>
1210
+ {trashCount > 0 ? (
1211
+ <button
1212
+ type="button"
1213
+ onClick={() => setEmptyTrashOpen(true)}
1214
+ className="border-bdr bg-card text-txt hover:border-acc-m hover:bg-acc-l hover:text-acc inline-flex items-center gap-1.5 rounded-[8px] border px-3 py-1.5 text-[13px]"
1215
+ >
1216
+ <Trash2 size={13} aria-hidden />
1217
+ Empty trash
1218
+ </button>
1219
+ ) : null}
1220
+ </div>
1221
+ </>
1222
+ ) : null}
517
1223
  <div className="ml-auto flex items-center gap-[7px]">
518
1224
  {formId ? null : (
519
1225
  <select
@@ -532,7 +1238,10 @@ export function EntriesInbox({ formId, onNavigate }: EntriesInboxProps) {
532
1238
  )}
533
1239
  <ExportMenu
534
1240
  formId={scopedFormId}
535
- disabled={counts !== null && counts.total === 0}
1241
+ folder={filter}
1242
+ search={search}
1243
+ assigneeId={currentUserId}
1244
+ disabled={counts !== null && counts.total === 0 && visibleEntries.length === 0}
536
1245
  triggerClassName="inbox-header-control"
537
1246
  />
538
1247
  </div>
@@ -542,27 +1251,50 @@ export function EntriesInbox({ formId, onNavigate }: EntriesInboxProps) {
542
1251
  {checked.size > 0 ? (
543
1252
  <div className="border-acc-m bg-acc-l flex shrink-0 items-center gap-2 border-b px-6 py-[7px]">
544
1253
  <b className="text-acc text-[13px]">{checked.size} selected</b>
545
- <button
546
- type="button"
547
- className="btn-ghost text-sub hover:text-acc rounded-[7px] px-[9px] py-1.5 text-[12.5px]"
548
- onClick={() => void bulk({ unread: false }, 'Marked read')}
549
- >
550
- Mark read
551
- </button>
552
- <button
553
- type="button"
554
- className="text-sub hover:text-acc rounded-[7px] px-[9px] py-1.5 text-[12.5px]"
555
- onClick={() => void bulk({ archived: true }, 'Archived')}
556
- >
557
- Archive
558
- </button>
559
- <button
560
- type="button"
561
- className="text-err rounded-[7px] px-[9px] py-1.5 text-[12.5px]"
562
- onClick={() => setConfirmDelete([...checked])}
563
- >
564
- Delete
565
- </button>
1254
+ {filter === 'trash' ? (
1255
+ <>
1256
+ <button
1257
+ type="button"
1258
+ className="text-sub hover:text-acc inline-flex items-center gap-1 rounded-[7px] px-[9px] py-1.5 text-[12.5px]"
1259
+ onClick={() => void bulkRestore()}
1260
+ >
1261
+ <RotateCcw size={13} aria-hidden />
1262
+ Restore
1263
+ </button>
1264
+ <button
1265
+ type="button"
1266
+ className="text-err inline-flex items-center gap-1 rounded-[7px] px-[9px] py-1.5 text-[12.5px]"
1267
+ onClick={() => void bulkDelete()}
1268
+ >
1269
+ <Trash2 size={13} aria-hidden />
1270
+ Delete forever
1271
+ </button>
1272
+ </>
1273
+ ) : (
1274
+ <>
1275
+ <button
1276
+ type="button"
1277
+ className="btn-ghost text-sub hover:text-acc rounded-[7px] px-[9px] py-1.5 text-[12.5px]"
1278
+ onClick={() => void bulk({ unread: false }, 'Marked read')}
1279
+ >
1280
+ Mark read
1281
+ </button>
1282
+ <button
1283
+ type="button"
1284
+ className="text-sub hover:text-acc rounded-[7px] px-[9px] py-1.5 text-[12.5px]"
1285
+ onClick={() => void bulk({ archived: true }, 'Archived')}
1286
+ >
1287
+ Archive
1288
+ </button>
1289
+ <button
1290
+ type="button"
1291
+ className="text-err rounded-[7px] px-[9px] py-1.5 text-[12.5px]"
1292
+ onClick={() => void bulkDelete()}
1293
+ >
1294
+ {filter === 'spam' ? 'Delete forever' : 'Delete'}
1295
+ </button>
1296
+ </>
1297
+ )}
566
1298
  <button
567
1299
  type="button"
568
1300
  className="text-sub ml-auto rounded-[7px] px-[9px] py-1.5 text-[12.5px]"
@@ -601,43 +1333,94 @@ export function EntriesInbox({ formId, onNavigate }: EntriesInboxProps) {
601
1333
  </button>
602
1334
  ) : null}
603
1335
  </div>
604
- <div className="flex items-center gap-2">
605
- <div
606
- className="border-bdr bg-bg flex min-w-0 flex-1 gap-0.5 overflow-x-auto rounded-[8px] border p-0.5"
607
- role="group"
608
- aria-label="Filter entries"
609
- >
610
- {FILTERS.map((item) => {
611
- const count =
612
- item.id === 'all'
613
- ? counts?.total
614
- : item.id === 'unread'
615
- ? counts?.unread
1336
+ <div className="flex items-center gap-1.5">
1337
+ <label className="border-bdr bg-card text-txt focus-within:outline-acc inline-flex h-[30px] shrink-0 cursor-pointer items-center gap-1.5 rounded-[8px] border px-[9px] text-[12.5px] font-semibold focus-within:outline focus-within:outline-offset-1">
1338
+ <FolderIcon size={14} className="text-sub shrink-0" aria-hidden />
1339
+ <select
1340
+ aria-label="Folder"
1341
+ value={folder}
1342
+ onChange={(event) => {
1343
+ pickFilter(event.target.value as InboxFilter)
1344
+ setActiveId(null)
1345
+ setChecked(new Set())
1346
+ }}
1347
+ className="cursor-pointer appearance-none border-0 bg-transparent pr-0.5 font-[inherit] text-inherit focus:outline-none"
1348
+ >
1349
+ {FOLDERS.map((item) => {
1350
+ const count =
1351
+ item.id === 'all'
1352
+ ? counts?.total
616
1353
  : item.id === 'starred'
617
1354
  ? counts?.starred
618
- : undefined
619
- const on = filter === item.id
620
- return (
621
- <button
622
- key={item.id}
623
- type="button"
624
- aria-pressed={on}
625
- aria-label={item.label}
626
- onClick={() => pickFilter(item.id)}
627
- className={`flex flex-1 items-center justify-center gap-1 rounded-[6px] px-1.5 py-1 text-[11.5px] whitespace-nowrap ${
628
- on
629
- ? 'bg-card text-acc shadow-shd font-semibold'
630
- : 'text-sub hover:text-acc font-medium'
631
- }`}
632
- >
633
- {item.label}
634
- {count && count > 0 ? (
635
- <span className="text-[10px] tabular-nums">{count}</span>
636
- ) : null}
637
- </button>
638
- )
639
- })}
640
- </div>
1355
+ : item.id === 'archived'
1356
+ ? counts?.archived
1357
+ : item.id === 'spam'
1358
+ ? counts?.spam
1359
+ : item.id === 'partial'
1360
+ ? partialCount
1361
+ : item.id === 'trash'
1362
+ ? trashCount
1363
+ : undefined
1364
+ return (
1365
+ <option key={item.id} value={item.id}>
1366
+ {item.label}
1367
+ {count && count > 0 ? ` (${count})` : ''}
1368
+ </option>
1369
+ )
1370
+ })}
1371
+ </select>
1372
+ <ChevronDown size={13} className="text-faint pointer-events-none" aria-hidden />
1373
+ </label>
1374
+ {folder === 'all' ? (
1375
+ <div
1376
+ className="border-bdr bg-bg flex min-w-0 flex-1 gap-0.5 overflow-x-auto rounded-[8px] border p-0.5"
1377
+ role="group"
1378
+ aria-label="Filter entries"
1379
+ >
1380
+ {VIEWS.map((item) => {
1381
+ const count =
1382
+ item.id === 'all'
1383
+ ? counts?.total
1384
+ : item.id === 'unread'
1385
+ ? counts?.unread
1386
+ : item.id === 'mine'
1387
+ ? mineCount
1388
+ : undefined
1389
+ const on = filter === item.id
1390
+ return (
1391
+ <button
1392
+ key={item.id}
1393
+ type="button"
1394
+ aria-pressed={on}
1395
+ aria-label={item.label}
1396
+ onClick={() => pickFilter(item.id)}
1397
+ className={`flex flex-1 items-center justify-center gap-1 rounded-[6px] px-1.5 py-1 text-[11.5px] whitespace-nowrap ${
1398
+ on
1399
+ ? 'bg-card text-acc shadow-shd font-semibold'
1400
+ : 'text-sub hover:text-acc font-medium'
1401
+ }`}
1402
+ >
1403
+ {item.label}
1404
+ {count && count > 0 ? (
1405
+ <span className="text-[10px] tabular-nums">{count}</span>
1406
+ ) : null}
1407
+ </button>
1408
+ )
1409
+ })}
1410
+ </div>
1411
+ ) : (
1412
+ <button
1413
+ type="button"
1414
+ onClick={() => {
1415
+ pickFilter('all')
1416
+ setActiveId(null)
1417
+ }}
1418
+ className="text-acc focus-visible:outline-acc inline-flex h-[30px] flex-1 items-center gap-1 rounded-[6px] px-1 text-[12.5px] font-medium hover:underline focus-visible:outline focus-visible:outline-offset-1"
1419
+ >
1420
+ <ChevronLeft size={13} aria-hidden />
1421
+ Back to Inbox
1422
+ </button>
1423
+ )}
641
1424
  <button
642
1425
  type="button"
643
1426
  aria-pressed={compact}
@@ -671,7 +1454,7 @@ export function EntriesInbox({ formId, onNavigate }: EntriesInboxProps) {
671
1454
  />
672
1455
  ))}
673
1456
  </div>
674
- ) : entries.length === 0 ? (
1457
+ ) : visibleEntries.length === 0 ? (
675
1458
  <div className="text-faint flex h-full flex-col items-center justify-center px-8 text-center">
676
1459
  <div className="bg-acc-l text-acc mb-3 flex size-14 items-center justify-center rounded-[14px]">
677
1460
  <Inbox size={26} aria-hidden />
@@ -680,7 +1463,13 @@ export function EntriesInbox({ formId, onNavigate }: EntriesInboxProps) {
680
1463
  <p className="mt-1 max-w-[320px] text-[13px] leading-[1.6]">
681
1464
  {search.trim()
682
1465
  ? `No entries match “${search.trim()}”.`
683
- : 'No entries match this filter yet.'}
1466
+ : filter === 'trash'
1467
+ ? 'Trash is empty. Deleted entries stay here for 30 days.'
1468
+ : filter === 'starred'
1469
+ ? 'Star an entry (S) to keep it here, even after you archive it.'
1470
+ : filter === 'partial'
1471
+ ? 'This folder is not available yet.'
1472
+ : 'No entries match this filter yet.'}
684
1473
  </p>
685
1474
  </div>
686
1475
  ) : (
@@ -700,6 +1489,7 @@ export function EntriesInbox({ formId, onNavigate }: EntriesInboxProps) {
700
1489
  checked={checked.has(entry.id)}
701
1490
  compact={compact}
702
1491
  showForm={!formId && formFilter === 'all'}
1492
+ team={effectiveTeam}
703
1493
  onOpen={() => openEntry(entry.id)}
704
1494
  onCheck={() =>
705
1495
  setChecked((current) => {
@@ -718,8 +1508,11 @@ export function EntriesInbox({ formId, onNavigate }: EntriesInboxProps) {
718
1508
  </div>
719
1509
  <div className="border-bdr text-faint flex shrink-0 items-center gap-2 border-t px-3 py-[7px] text-[11px]">
720
1510
  <span>
721
- Showing <b className="text-sub font-semibold tabular-nums">{entries.length}</b> of{' '}
722
- <b className="text-sub font-semibold tabular-nums">{unsupported ? 0 : total}</b>
1511
+ Showing{' '}
1512
+ <b className="text-sub font-semibold tabular-nums">{visibleEntries.length}</b> of{' '}
1513
+ <b className="text-sub font-semibold tabular-nums">
1514
+ {unsupported ? 0 : (counts?.total ?? total)}
1515
+ </b>
723
1516
  </span>
724
1517
  <span className="ml-auto">
725
1518
  {unreadInList > 0 ? (
@@ -781,19 +1574,30 @@ export function EntriesInbox({ formId, onNavigate }: EntriesInboxProps) {
781
1574
 
782
1575
  {showDetail ? (
783
1576
  <div
784
- className="bg-bg min-h-0 min-w-0 flex-1 overflow-y-auto"
1577
+ className="bg-bg @container min-h-0 min-w-0 flex-1 overflow-x-hidden overflow-y-auto"
785
1578
  role="region"
786
1579
  aria-label="Entry details"
787
1580
  >
788
1581
  {active ? (
789
1582
  <EntryDetail
790
1583
  entry={active}
791
- list={entries}
1584
+ list={visibleEntries}
792
1585
  narrow={narrow}
1586
+ team={effectiveTeam}
1587
+ currentUserId={currentUserId || 'self'}
1588
+ currentUserName={currentUserName || 'You'}
1589
+ blocked={blocked}
793
1590
  onClose={() => setActiveId(null)}
794
1591
  onOpen={openEntry}
795
1592
  onPatch={patchOne}
796
- onDelete={(id) => setConfirmDelete([id])}
1593
+ onDelete={(id) => void handleTrashOrDelete(id)}
1594
+ onRestore={(id) => void handleRestore(id)}
1595
+ onBlockDomain={handleBlockDomain}
1596
+ onManageBlocklist={(kind) => setBlocklistTab(kind)}
1597
+ onFindEmail={(emailAddr) => {
1598
+ pickFilter('all')
1599
+ setSearch(emailAddr)
1600
+ }}
797
1601
  />
798
1602
  ) : (
799
1603
  <div className="flex h-full flex-col items-center justify-center px-8 text-center">
@@ -859,6 +1663,48 @@ export function EntriesInbox({ formId, onNavigate }: EntriesInboxProps) {
859
1663
  confirmLabel="Delete"
860
1664
  destructive
861
1665
  />
1666
+
1667
+ {emptyTrashOpen ? (
1668
+ <EmptyTrashDialog
1669
+ count={trashCount}
1670
+ onClose={() => setEmptyTrashOpen(false)}
1671
+ onConfirm={() => void handleEmptyTrash()}
1672
+ />
1673
+ ) : null}
1674
+
1675
+ {blocklistTab !== null ? (
1676
+ <BlocklistDialog
1677
+ open
1678
+ initialTab={blocklistTab}
1679
+ value={blocked}
1680
+ onChange={(next) => void handleBlocklistChange(next)}
1681
+ onClose={() => setBlocklistTab(null)}
1682
+ />
1683
+ ) : null}
1684
+
1685
+ <div role="status" aria-live="polite" className="sr-only">
1686
+ {toastMsg}
1687
+ </div>
1688
+ {toastMsg ? (
1689
+ <div
1690
+ className={`bg-txt text-sb shadow-shd2 fixed bottom-6 left-1/2 z-[200] -translate-x-1/2 rounded-[8px] text-[13px] font-medium ${
1691
+ toastUndo
1692
+ ? 'pointer-events-auto flex items-center gap-3.5 py-[7px] pr-2 pl-[18px]'
1693
+ : 'pointer-events-none px-[18px] py-[9px]'
1694
+ }`}
1695
+ >
1696
+ <span aria-hidden="true">{toastMsg}</span>
1697
+ {toastUndo ? (
1698
+ <button
1699
+ type="button"
1700
+ onClick={toastUndo}
1701
+ className="text-acc-m min-h-[28px] cursor-pointer rounded-[6px] border-0 bg-transparent px-2 py-1 font-[inherit] font-medium hover:opacity-85 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-current"
1702
+ >
1703
+ Undo
1704
+ </button>
1705
+ ) : null}
1706
+ </div>
1707
+ ) : null}
862
1708
  </div>
863
1709
  )
864
1710
  }
@@ -869,6 +1715,7 @@ function EntryRow({
869
1715
  checked,
870
1716
  compact,
871
1717
  showForm,
1718
+ team,
872
1719
  onOpen,
873
1720
  onCheck,
874
1721
  onStar,
@@ -878,12 +1725,15 @@ function EntryRow({
878
1725
  checked: boolean
879
1726
  compact: boolean
880
1727
  showForm: boolean
1728
+ team: TeamMember[]
881
1729
  onOpen: () => void
882
1730
  onCheck: () => void
883
1731
  onStar: () => void
884
1732
  }) {
885
1733
  const name = senderName(entry)
886
1734
  const preview = entryPreview(entry)
1735
+ const assignee = entry.assigneeId ? team.find((t) => t.id === entry.assigneeId) : undefined
1736
+ const noteCount = entry.notes?.length ?? 0
887
1737
  return (
888
1738
  <div
889
1739
  data-entry={entry.id}
@@ -924,7 +1774,7 @@ function EntryRow({
924
1774
  {compact ? null : (
925
1775
  <span
926
1776
  className="relative flex size-8 items-center justify-center rounded-full text-[12px] font-bold"
927
- style={{ background: avatarColor(name), color: '#fff' }}
1777
+ style={{ background: avatarColor(name), color: 'var(--on-acc)' }}
928
1778
  >
929
1779
  {initials(name)}
930
1780
  {entry.unread ? (
@@ -953,36 +1803,100 @@ function EntryRow({
953
1803
  </p>
954
1804
  <div className="mt-[3px] flex items-center gap-1.5">
955
1805
  {showForm && entry.formName ? (
956
- <span className="bg-acc-l text-acc rounded-[5px] px-[7px] py-0.5 text-[10px] font-semibold whitespace-nowrap">
1806
+ <span
1807
+ className="rounded-[5px] px-[7px] py-0.5 text-[10px] font-semibold whitespace-nowrap"
1808
+ style={{
1809
+ background: formBadgeStyle(entry.formSlug).bg,
1810
+ color: formBadgeStyle(entry.formSlug).fg,
1811
+ }}
1812
+ >
957
1813
  {entry.formName}
958
1814
  </span>
959
1815
  ) : null}
960
1816
  {entry.spamStatus === 'spam' ? (
961
1817
  <span className="bg-err-l text-err rounded-[5px] px-[7px] py-0.5 text-[10px] font-semibold">
962
- Spam
1818
+ {entry.spamMeta?.by ? (SPAM_BY_LABELS[entry.spamMeta.by] ?? 'Spam') : 'Spam'}
963
1819
  </span>
964
1820
  ) : entry.spamStatus === 'suspected' ? (
965
1821
  <span className="bg-err-l text-err rounded-[5px] px-[7px] py-0.5 text-[10px] font-semibold">
966
1822
  Likely spam
967
1823
  </span>
968
1824
  ) : null}
1825
+ {entry.deleted
1826
+ ? (() => {
1827
+ const d = daysLeftInTrash(entry.deleted.at)
1828
+ const [fg, bg] =
1829
+ d <= 3
1830
+ ? ['var(--err)', 'var(--err-l)']
1831
+ : d <= 7
1832
+ ? ['var(--warn)', 'var(--warn-l)']
1833
+ : ['var(--sub)', 'var(--bg)']
1834
+ return (
1835
+ <span
1836
+ className="rounded-[5px] border px-[7px] py-0.5 text-[10px] font-semibold whitespace-nowrap"
1837
+ style={{
1838
+ color: fg,
1839
+ background: bg,
1840
+ borderColor: `color-mix(in srgb, ${fg} 22%, transparent)`,
1841
+ }}
1842
+ >
1843
+ {d === 0 ? 'Removes today' : `Removes in ${d} ${d === 1 ? 'day' : 'days'}`}
1844
+ </span>
1845
+ )
1846
+ })()
1847
+ : null}
969
1848
  {entry.archived ? (
970
- <span className="border-bdr text-faint rounded-[5px] border px-[7px] py-0.5 text-[10px] font-semibold">
1849
+ <span className="border-bdr bg-bg text-faint rounded-[5px] border px-[7px] py-0.5 text-[10px] font-semibold">
971
1850
  Archived
972
1851
  </span>
973
1852
  ) : null}
974
- <button
975
- type="button"
976
- aria-pressed={entry.starred}
977
- aria-label={entry.starred ? 'Unstar' : 'Star'}
978
- onClick={(event) => {
979
- event.stopPropagation()
980
- onStar()
981
- }}
982
- className={`ml-auto flex size-6 items-center justify-center ${entry.starred ? 'text-warn' : 'text-faint hover:text-warn'}`}
983
- >
984
- <Star size={14} aria-hidden className={entry.starred ? 'fill-current' : ''} />
985
- </button>
1853
+ {entry.partial ? (
1854
+ <span className="bg-warn-l text-warn rounded-[5px] px-[7px] py-0.5 text-[10px] font-semibold whitespace-nowrap">
1855
+ {`Stopped at step ${entry.partial.step} of ${entry.partial.of}`}
1856
+ </span>
1857
+ ) : entry.spamStatus !== 'spam' && entry.status && entry.status !== 'new' ? (
1858
+ <span
1859
+ className="rounded-[5px] px-[7px] py-0.5 text-[10px] font-semibold whitespace-nowrap"
1860
+ style={{
1861
+ background: pipeOf(entry.status).bg,
1862
+ color: pipeOf(entry.status).fg,
1863
+ }}
1864
+ >
1865
+ {pipeOf(entry.status).label}
1866
+ </span>
1867
+ ) : null}
1868
+ {entry.spamStatus !== 'spam' && !entry.partial && noteCount > 0 ? (
1869
+ <span
1870
+ className="text-sub inline-flex items-center gap-[3px] text-[10.5px] font-semibold"
1871
+ title={`${noteCount} ${noteCount === 1 ? 'note' : 'notes'}`}
1872
+ >
1873
+ <MessageSquare size={11} aria-hidden />
1874
+ {noteCount}
1875
+ </span>
1876
+ ) : null}
1877
+ {entry.spamStatus !== 'spam' && !entry.partial && assignee ? (
1878
+ <span
1879
+ className="inline-flex size-[18px] shrink-0 items-center justify-center rounded-full text-[8px] font-bold tracking-[-0.2px]"
1880
+ style={{ background: avatarColor(assignee.name), color: 'var(--on-acc)' }}
1881
+ title={assignee.name}
1882
+ >
1883
+ {initials(assignee.name)}
1884
+ </span>
1885
+ ) : null}
1886
+ {!entry.deleted ? (
1887
+ <button
1888
+ type="button"
1889
+ aria-pressed={entry.starred}
1890
+ aria-label={entry.starred ? 'Unstar' : 'Star'}
1891
+ onClick={(event) => {
1892
+ event.stopPropagation()
1893
+ onStar()
1894
+ }}
1895
+ className={`ml-auto flex size-6 items-center justify-center ${entry.starred ? 'text-warn' : 'text-faint hover:text-warn'}`}
1896
+ >
1897
+ <Star size={14} aria-hidden className={entry.starred ? 'fill-current' : ''} />
1898
+ </button>
1899
+ ) : null}
986
1900
  </div>
987
1901
  </div>
988
1902
  </div>
@@ -993,285 +1907,1153 @@ function EntryDetail({
993
1907
  entry,
994
1908
  list,
995
1909
  narrow,
1910
+ team,
1911
+ currentUserId,
1912
+ currentUserName,
1913
+ blocked,
996
1914
  onClose,
997
1915
  onOpen,
998
1916
  onPatch,
999
1917
  onDelete,
1918
+ onRestore,
1919
+ onBlockDomain,
1920
+ onManageBlocklist,
1921
+ onFindEmail,
1000
1922
  }: {
1001
1923
  entry: FormSubmission
1002
1924
  list: FormSubmission[]
1003
1925
  narrow: boolean
1926
+ team: TeamMember[]
1927
+ currentUserId: string
1928
+ currentUserName: string
1929
+ blocked: BlocklistValue
1004
1930
  onClose: () => void
1005
1931
  onOpen: (id: string) => void
1006
- onPatch: (id: string, patch: EntryPatch, message?: string) => void
1932
+ onPatch: (
1933
+ id: string,
1934
+ patch: EntryPatch,
1935
+ message?: string,
1936
+ undoPatch?: EntryPatch,
1937
+ clearSelectionOnApply?: boolean,
1938
+ ) => void
1007
1939
  onDelete: (id: string) => void
1940
+ onRestore: (id: string) => void
1941
+ onBlockDomain: (domain: string) => void | Promise<void>
1942
+ onManageBlocklist: (kind: BlocklistKind) => void
1943
+ onFindEmail: (email: string) => void
1008
1944
  }) {
1009
1945
  const [fields, setFields] = useState<FormField[]>([])
1946
+ const [otherCount, setOtherCount] = useState<number>(entry.otherEntryCount ?? 0)
1010
1947
  const [metaOpen, setMetaOpen] = useState(true)
1948
+ const [showEmpty, setShowEmpty] = useState(false)
1949
+ const [noteText, setNoteText] = useState('')
1950
+ const notes = entry.notes ?? []
1011
1951
  const index = list.findIndex((item) => item.id === entry.id)
1012
1952
  const name = senderName(entry)
1013
1953
  const email = entry.senderEmail || ''
1014
1954
  const phone = entry.senderPhone || ''
1015
1955
  const website = typeof entry.data.website === 'string' ? entry.data.website : ''
1016
1956
  const formLabel = entry.formName || 'Form'
1957
+ const formColor = formBadgeStyle(entry.formSlug)
1958
+ const attr = getEntryAttributionSummary(entry)
1959
+ const pipe = pipeOf(entry.status)
1960
+ const assignee = entry.assigneeId ? team.find((t) => t.id === entry.assigneeId) : undefined
1961
+ const emailDomain = (email.split('@')[1] ?? '').trim().toLowerCase()
1962
+ const isFreeDomain = Boolean(emailDomain && FREE_EMAIL_DOMAINS.has(emailDomain))
1963
+ const isDomainBlocked = Boolean(
1964
+ emailDomain && blocked.domains.some((d) => d.term === emailDomain),
1965
+ )
1017
1966
 
1018
1967
  useEffect(() => {
1968
+ setShowEmpty(false)
1969
+ setNoteText('')
1970
+ setOtherCount(entry.otherEntryCount ?? 0)
1019
1971
  let cancelled = false
1020
1972
  void fetchEntry(entry.id).then((detail) => {
1021
- if (!cancelled) setFields(detail?.fields ?? [])
1973
+ if (!cancelled && detail) {
1974
+ setFields(detail.fields ?? [])
1975
+ if (typeof detail.otherEntryCount === 'number') setOtherCount(detail.otherEntryCount)
1976
+ else if (typeof detail.entry?.otherEntryCount === 'number') {
1977
+ setOtherCount(detail.entry.otherEntryCount)
1978
+ }
1979
+ }
1022
1980
  })
1023
1981
  return () => {
1024
1982
  cancelled = true
1025
1983
  }
1026
- }, [entry.id])
1984
+ }, [entry.id, entry.otherEntryCount])
1985
+
1986
+ const fieldMap = useMemo(() => new Map(fields.map((f) => [f.key, f])), [fields])
1987
+
1988
+ const present = useMemo(() => {
1989
+ const inputFields = fields.filter((field) => !NON_INPUT_FIELD_SET.has(field.type))
1990
+ if (inputFields.length > 0) {
1991
+ const schemaRows = inputFields.map((field) => ({
1992
+ key: field.key,
1993
+ label: field.label || humanizeFieldKey(field.key),
1994
+ }))
1995
+ const schemaKeys = new Set(schemaRows.map((r) => r.key))
1996
+ const extraRows = Object.keys(entry.data)
1997
+ .filter((key) => !schemaKeys.has(key) && entry.data[key] !== undefined)
1998
+ .map((key) => ({ key, label: humanizeFieldKey(key) }))
1999
+ return [...schemaRows, ...extraRows]
2000
+ }
2001
+ return Object.keys(entry.data)
2002
+ .filter((key) => entry.data[key] !== undefined)
2003
+ .map((key) => ({ key, label: humanizeFieldKey(key) }))
2004
+ }, [fields, entry.data])
2005
+
2006
+ const msgEntry = useMemo(() => {
2007
+ const direct = present.find(
2008
+ ({ key }) => (key === 'message' || key === 'description') && displayValue(entry.data[key]),
2009
+ )
2010
+ if (direct) return direct
2011
+ const longFilled = present
2012
+ .filter(({ key }) => LONG_MESSAGE_FIELDS.has(key) && displayValue(entry.data[key]).length > 0)
2013
+ .sort(
2014
+ (a, b) => displayValue(entry.data[b.key]).length - displayValue(entry.data[a.key]).length,
2015
+ )
2016
+ if (longFilled[0]) return longFilled[0]
2017
+ return present.find(({ key }) => displayValue(entry.data[key]).length > 70) ?? null
2018
+ }, [present, entry.data])
1027
2019
 
1028
- const ordered = fields.length
1029
- ? fields.map((field) => ({ key: field.key, label: field.label || field.key }))
1030
- : Object.keys(entry.data).map((key) => ({ key, label: key }))
2020
+ const submissionRows = useMemo(
2021
+ () => present.filter(({ key }) => key !== msgEntry?.key),
2022
+ [present, msgEntry],
2023
+ )
2024
+ const filledRows = useMemo(
2025
+ () => submissionRows.filter(({ key }) => Boolean(displayValue(entry.data[key]))),
2026
+ [submissionRows, entry.data],
2027
+ )
2028
+ const emptyRows = useMemo(
2029
+ () => submissionRows.filter(({ key }) => !displayValue(entry.data[key])),
2030
+ [submissionRows, entry.data],
2031
+ )
2032
+ const answeredCount = useMemo(
2033
+ () => present.filter(({ key }) => Boolean(displayValue(entry.data[key]))).length,
2034
+ [present, entry.data],
2035
+ )
2036
+
2037
+ const firstName =
2038
+ (typeof entry.data.first_name === 'string' && entry.data.first_name.trim()) ||
2039
+ name.split(/\s+/)[0] ||
2040
+ ''
2041
+ const msgText = msgEntry ? displayValue(entry.data[msgEntry.key]) : ''
2042
+ const mailHref = email
2043
+ ? `mailto:${email}?subject=${encodeURIComponent(`Re: your ${formLabel} request`)}&body=${encodeURIComponent(
2044
+ `Hi ${firstName},\n\n\n\n—\nOn ${fullEntryTime(entry.submittedAt)} you wrote:\n${msgText
2045
+ .split('\n')
2046
+ .map((line) => `> ${line}`)
2047
+ .join('\n')}`,
2048
+ )}`
2049
+ : undefined
1031
2050
 
1032
2051
  function copyAll() {
1033
- const lines = ordered
1034
- .map(({ key, label }) => `${label}: ${displayValue(entry.data[key]) || '—'}`)
2052
+ const lines = present
2053
+ .map(
2054
+ ({ key, label }) =>
2055
+ `${label}: ${formatFieldDisplay(key, displayValue(entry.data[key]), fieldMap.get(key)) || '—'}`,
2056
+ )
1035
2057
  .join('\n')
1036
2058
  void navigator.clipboard?.writeText(lines)
1037
2059
  toast.success('Copied all fields')
1038
2060
  }
1039
2061
 
2062
+ function copyValue(value: string) {
2063
+ void navigator.clipboard?.writeText(value)
2064
+ toast.success('Copied')
2065
+ }
2066
+
2067
+ function addNote() {
2068
+ const trimmed = noteText.trim()
2069
+ if (!trimmed) return
2070
+ const nextNotes: FormEntryNote[] = [
2071
+ ...notes,
2072
+ {
2073
+ authorId: currentUserId,
2074
+ authorName: currentUserName,
2075
+ at: new Date().toISOString(),
2076
+ text: trimmed,
2077
+ },
2078
+ ]
2079
+ setNoteText('')
2080
+ onPatch(
2081
+ entry.id,
2082
+ { note: { text: trimmed, authorName: currentUserName }, notes: nextNotes },
2083
+ 'Note added',
2084
+ )
2085
+ }
2086
+
1040
2087
  const iconBtn =
1041
- 'text-sub hover:bg-acc-l hover:text-acc flex size-[30px] items-center justify-center rounded-[8px] disabled:opacity-30'
2088
+ 'text-sub hover:bg-acc-l hover:text-acc flex size-8 items-center justify-center rounded-[8px] disabled:opacity-30'
2089
+ const toolbarBtn =
2090
+ 'text-sub hover:bg-acc-l hover:text-acc inline-flex items-center gap-[5px] rounded-[7px] px-[9px] py-1.5 text-[12.5px] font-medium whitespace-nowrap @[0px]:max-[640px]:p-[7px]'
1042
2091
 
1043
2092
  return (
1044
- <div className="mx-auto max-w-[820px] px-6 py-5 pb-10 max-[900px]:px-3.5">
1045
- <article className="border-bdr bg-card shadow-shd mb-3.5 overflow-hidden rounded-[10px] border">
1046
- <div className="border-bdr flex items-start gap-3.5 border-b px-5 py-[18px]">
1047
- {narrow ? (
1048
- <button type="button" className={iconBtn} aria-label="Back to list" onClick={onClose}>
1049
- <ChevronLeft size={18} aria-hidden />
2093
+ <div className="min-h-full">
2094
+ {/* Sticky toolbar */}
2095
+ <div
2096
+ role="toolbar"
2097
+ aria-label="Entry actions"
2098
+ className="border-bdr sticky top-0 z-[5] flex min-h-[52px] items-center gap-0.5 border-b bg-[color-mix(in_srgb,var(--card)_94%,transparent)] px-4 py-2 backdrop-blur-[8px]"
2099
+ >
2100
+ {narrow ? (
2101
+ <button type="button" className={iconBtn} aria-label="Back to list" onClick={onClose}>
2102
+ <ChevronLeft size={18} aria-hidden />
2103
+ </button>
2104
+ ) : null}
2105
+ {entry.deleted ? (
2106
+ <>
2107
+ <button
2108
+ type="button"
2109
+ className="bg-acc mr-1 inline-flex items-center gap-1.5 rounded-[8px] px-[13px] py-[7px] text-[13px] font-medium text-[var(--on-acc)]"
2110
+ onClick={() => onRestore(entry.id)}
2111
+ >
2112
+ <RotateCcw size={14} aria-hidden />
2113
+ <span>Restore</span>
1050
2114
  </button>
1051
- ) : null}
1052
- <span
1053
- className="flex size-12 shrink-0 items-center justify-center rounded-[12px] text-[17px] font-bold"
1054
- style={{ background: avatarColor(name), color: '#fff' }}
1055
- >
1056
- {initials(name)}
1057
- </span>
1058
- <div className="min-w-0 flex-1">
1059
- <h2 className="text-txt m-0 text-[19px] leading-[1.2] font-bold tracking-[-0.3px]">
1060
- {name}
1061
- </h2>
1062
- <div className="mt-1.5 flex flex-wrap items-center gap-x-3.5 gap-y-1.5 text-[13px]">
1063
- {email ? (
1064
- <a className="text-acc inline-flex items-center gap-[5px]" href={`mailto:${email}`}>
1065
- <Mail size={13} aria-hidden />
1066
- {email}
1067
- </a>
1068
- ) : null}
1069
- {phone ? (
1070
- <a
1071
- className="text-acc inline-flex items-center gap-[5px]"
1072
- href={`tel:${phone.replace(/[^\d+]/g, '')}`}
1073
- >
1074
- <Phone size={13} aria-hidden />
1075
- {phone}
1076
- </a>
1077
- ) : null}
1078
- {website ? (
1079
- <a
1080
- className="text-acc inline-flex items-center gap-[5px]"
1081
- href={website}
1082
- target="_blank"
1083
- rel="noopener noreferrer"
1084
- >
1085
- <Globe size={13} aria-hidden />
1086
- {website.replace(/^https?:\/\//, '').replace(/\/$/, '')}
1087
- </a>
1088
- ) : null}
1089
- </div>
1090
- <div className="mt-[9px] flex flex-wrap items-center gap-1.5">
1091
- <span className="bg-acc-l text-acc rounded-[5px] px-[7px] py-0.5 text-[10px] font-semibold">
1092
- {formLabel}
1093
- </span>
1094
- <span
1095
- className={`rounded-[5px] px-2 py-[3px] text-[11px] font-semibold ${entry.unread ? 'bg-acc-l text-acc' : 'border-bdr bg-bg text-sub border'}`}
2115
+ <button type="button" className={toolbarBtn} title="Copy all fields" onClick={copyAll}>
2116
+ <Copy size={14} aria-hidden />
2117
+ <span className="max-[640px]:sr-only">Copy all</span>
2118
+ </button>
2119
+ <span className="flex-1" />
2120
+ <button
2121
+ type="button"
2122
+ title="Delete forever"
2123
+ className="text-sub hover:bg-err-l hover:text-err inline-flex items-center gap-[5px] rounded-[7px] px-[9px] py-1.5 text-[12.5px] font-medium whitespace-nowrap"
2124
+ onClick={() => onDelete(entry.id)}
2125
+ >
2126
+ <Trash2 size={14} aria-hidden />
2127
+ <span className="max-[640px]:sr-only">Delete forever</span>
2128
+ </button>
2129
+ </>
2130
+ ) : entry.partial ? (
2131
+ <>
2132
+ {email ? (
2133
+ <a
2134
+ href={`mailto:${email}?subject=${encodeURIComponent(`Finish your ${formLabel} request`)}&body=${encodeURIComponent(
2135
+ `Hi ${firstName},\n\nLooks like you didn’t get to finish. Pick up where you left off here: /${entry.formSlug ?? ''}/?resume=${entry.id}`,
2136
+ )}`}
2137
+ className="bg-acc mr-1 inline-flex items-center gap-1.5 rounded-[8px] px-[13px] py-[7px] text-[13px] font-medium text-[var(--on-acc)] no-underline"
1096
2138
  >
1097
- {entry.unread ? 'Unread' : 'Read'}
1098
- </span>
1099
- {entry.starred ? (
1100
- <span className="bg-warn-l text-warn inline-flex items-center gap-1 rounded-[5px] px-2 py-[3px] text-[11px] font-semibold">
1101
- <Star size={11} aria-hidden className="fill-current" /> Starred
1102
- </span>
1103
- ) : null}
1104
- {entry.archived ? (
1105
- <span className="border-bdr text-faint rounded-[5px] border px-2 py-[3px] text-[11px] font-semibold">
1106
- Archived
1107
- </span>
1108
- ) : null}
1109
- <span className="text-faint text-[12px]">{fullEntryTime(entry.submittedAt)}</span>
1110
- </div>
1111
- </div>
1112
- <div className="flex shrink-0 items-center">
2139
+ <Mail size={14} aria-hidden />
2140
+ <span>Email link to finish</span>
2141
+ </a>
2142
+ ) : null}
1113
2143
  <button
1114
2144
  type="button"
1115
- className={iconBtn}
1116
- aria-label="Previous entry"
1117
- disabled={index <= 0}
1118
- onClick={() => index > 0 && list[index - 1] && onOpen(list[index - 1]!.id)}
2145
+ className={toolbarBtn}
2146
+ title="Treat as entry"
2147
+ onClick={() =>
2148
+ onPatch(entry.id, { partial: null }, 'Moved to All entries', {
2149
+ partial: entry.partial,
2150
+ })
2151
+ }
1119
2152
  >
1120
- <ChevronLeft size={15} aria-hidden />
2153
+ <Check size={14} aria-hidden />
2154
+ <span className="max-[640px]:sr-only">Treat as entry</span>
1121
2155
  </button>
2156
+ <span className="flex-1" />
1122
2157
  <button
1123
2158
  type="button"
1124
- className={iconBtn}
1125
- aria-label="Next entry"
1126
- disabled={index < 0 || index >= list.length - 1}
1127
- onClick={() => list[index + 1] && onOpen(list[index + 1]!.id)}
2159
+ title="Delete"
2160
+ className="text-sub hover:bg-err-l hover:text-err inline-flex items-center gap-[5px] rounded-[7px] px-[9px] py-1.5 text-[12.5px] font-medium whitespace-nowrap"
2161
+ onClick={() => onDelete(entry.id)}
1128
2162
  >
1129
- <ChevronRight size={15} aria-hidden />
2163
+ <Trash2 size={14} aria-hidden />
2164
+ <span className="max-[640px]:sr-only">Delete</span>
1130
2165
  </button>
1131
- {narrow ? null : (
1132
- <button type="button" className={iconBtn} aria-label="Close entry" onClick={onClose}>
1133
- <X size={15} aria-hidden />
2166
+ </>
2167
+ ) : entry.spamStatus === 'spam' ? (
2168
+ <>
2169
+ <button
2170
+ type="button"
2171
+ className="bg-acc mr-1 inline-flex items-center gap-1.5 rounded-[8px] px-[13px] py-[7px] text-[13px] font-medium text-[var(--on-acc)]"
2172
+ onClick={() =>
2173
+ onPatch(
2174
+ entry.id,
2175
+ { spamStatus: 'clean', spamMeta: null },
2176
+ 'Moved to inbox · we’ll learn from this',
2177
+ { spamStatus: 'spam', spamMeta: entry.spamMeta },
2178
+ true,
2179
+ )
2180
+ }
2181
+ >
2182
+ <Check size={14} aria-hidden />
2183
+ <span>Not spam</span>
2184
+ </button>
2185
+ {emailDomain ? (
2186
+ <button
2187
+ type="button"
2188
+ disabled={isFreeDomain || isDomainBlocked}
2189
+ title={
2190
+ isFreeDomain
2191
+ ? `${emailDomain} is a free email provider and can’t be blocked`
2192
+ : isDomainBlocked
2193
+ ? 'Already blocked'
2194
+ : 'Future entries from this domain go straight to Spam'
2195
+ }
2196
+ className={`${toolbarBtn} disabled:cursor-not-allowed disabled:opacity-45`}
2197
+ onClick={() => onBlockDomain(emailDomain)}
2198
+ >
2199
+ <ShieldX size={14} aria-hidden />
2200
+ <span className="max-[640px]:sr-only">
2201
+ {isDomainBlocked ? 'Domain blocked' : `Block ${emailDomain}`}
2202
+ </span>
1134
2203
  </button>
1135
- )}
1136
- </div>
1137
- </div>
1138
- <div className="bg-bg flex flex-wrap items-center gap-1.5 px-5 py-2.5">
1139
- {email ? (
1140
- <a
1141
- className="bg-acc inline-flex items-center gap-1.5 rounded-[8px] px-[15px] py-2 text-[13px] font-medium text-[var(--on-acc)]"
1142
- href={`mailto:${email}?subject=${encodeURIComponent(`Re: your ${formLabel} submission`)}`}
2204
+ ) : null}
2205
+ <button
2206
+ type="button"
2207
+ className={toolbarBtn}
2208
+ title="Block a word"
2209
+ onClick={() => onManageBlocklist('words')}
1143
2210
  >
1144
- Reply
1145
- </a>
1146
- ) : null}
1147
- <Ghost
1148
- onClick={() =>
1149
- onPatch(
1150
- entry.id,
1151
- { unread: !entry.unread },
1152
- entry.unread ? 'Marked read' : 'Marked unread',
1153
- )
1154
- }
1155
- >
1156
- {entry.unread ? 'Mark read' : 'Mark unread'}
1157
- </Ghost>
1158
- <Ghost onClick={() => onPatch(entry.id, { starred: !entry.starred })}>
1159
- <Star size={13} aria-hidden className={entry.starred ? 'text-warn fill-current' : ''} />
1160
- {entry.starred ? 'Unstar' : 'Star'}
1161
- </Ghost>
1162
- <Ghost onClick={copyAll}>
1163
- <Copy size={13} aria-hidden /> Copy all
1164
- </Ghost>
1165
- <Ghost
1166
- onClick={() =>
1167
- onPatch(
1168
- entry.id,
1169
- { archived: !entry.archived },
1170
- entry.archived ? 'Unarchived' : 'Archived',
1171
- )
1172
- }
2211
+ <span className="max-[640px]:sr-only">Block a word…</span>
2212
+ </button>
2213
+ <button type="button" className={toolbarBtn} title="Copy all" onClick={copyAll}>
2214
+ <Copy size={14} aria-hidden />
2215
+ <span className="max-[640px]:sr-only">Copy all</span>
2216
+ </button>
2217
+ <span className="flex-1" />
2218
+ <button
2219
+ type="button"
2220
+ title="Delete forever"
2221
+ className="text-sub hover:bg-err-l hover:text-err inline-flex items-center gap-[5px] rounded-[7px] px-[9px] py-1.5 text-[12.5px] font-medium whitespace-nowrap"
2222
+ onClick={() => onDelete(entry.id)}
2223
+ >
2224
+ <Trash2 size={14} aria-hidden />
2225
+ <span className="max-[640px]:sr-only">Delete forever</span>
2226
+ </button>
2227
+ </>
2228
+ ) : (
2229
+ <>
2230
+ <button
2231
+ type="button"
2232
+ className={toolbarBtn}
2233
+ title={entry.unread ? 'Mark read (U)' : 'Mark unread (U)'}
2234
+ onClick={() =>
2235
+ onPatch(
2236
+ entry.id,
2237
+ { unread: !entry.unread },
2238
+ entry.unread ? 'Marked read' : 'Marked unread',
2239
+ )
2240
+ }
2241
+ >
2242
+ {entry.unread ? <Check size={14} aria-hidden /> : <Mail size={14} aria-hidden />}
2243
+ <span className="max-[640px]:sr-only">
2244
+ {entry.unread ? 'Mark read' : 'Mark unread'}
2245
+ </span>
2246
+ </button>
2247
+ <button
2248
+ type="button"
2249
+ aria-pressed={entry.starred}
2250
+ title={entry.starred ? 'Unstar (S)' : 'Star (S)'}
2251
+ className={`${toolbarBtn} ${entry.starred ? 'text-warn' : ''}`}
2252
+ onClick={() => onPatch(entry.id, { starred: !entry.starred })}
2253
+ >
2254
+ <Star size={14} aria-hidden className={entry.starred ? 'fill-current' : ''} />
2255
+ <span className="max-[640px]:sr-only">{entry.starred ? 'Starred' : 'Star'}</span>
2256
+ </button>
2257
+ <button
2258
+ type="button"
2259
+ className={toolbarBtn}
2260
+ title={entry.archived ? 'Unarchive (E)' : 'Archive (E)'}
2261
+ onClick={() =>
2262
+ onPatch(
2263
+ entry.id,
2264
+ { archived: !entry.archived },
2265
+ entry.archived ? 'Moved to inbox' : 'Archived',
2266
+ { archived: entry.archived },
2267
+ )
2268
+ }
2269
+ >
2270
+ <Archive size={14} aria-hidden />
2271
+ <span className="max-[640px]:sr-only">
2272
+ {entry.archived ? 'Unarchive' : 'Archive'}
2273
+ </span>
2274
+ </button>
2275
+ <button type="button" className={toolbarBtn} title="Copy all fields" onClick={copyAll}>
2276
+ <Copy size={14} aria-hidden />
2277
+ <span className="max-[640px]:sr-only">Copy all</span>
2278
+ </button>
2279
+ <span className="flex-1" />
2280
+ <button
2281
+ type="button"
2282
+ className={toolbarBtn}
2283
+ title="Mark as spam"
2284
+ onClick={() =>
2285
+ onPatch(
2286
+ entry.id,
2287
+ {
2288
+ spamStatus: 'spam',
2289
+ spamMeta: { by: 'manual', reason: 'Marked as spam by you.' },
2290
+ },
2291
+ 'Moved to Spam',
2292
+ { spamStatus: entry.spamStatus, spamMeta: null },
2293
+ true,
2294
+ )
2295
+ }
2296
+ >
2297
+ <ShieldX size={14} aria-hidden />
2298
+ <span className="max-[640px]:sr-only">Spam</span>
2299
+ </button>
2300
+ <button
2301
+ type="button"
2302
+ title="Delete"
2303
+ className="text-sub hover:bg-err-l hover:text-err inline-flex items-center gap-[5px] rounded-[7px] px-[9px] py-1.5 text-[12.5px] font-medium whitespace-nowrap"
2304
+ onClick={() => onDelete(entry.id)}
2305
+ >
2306
+ <Trash2 size={14} aria-hidden />
2307
+ <span className="max-[640px]:sr-only">Delete</span>
2308
+ </button>
2309
+ </>
2310
+ )}
2311
+ <span className="bg-bdr mx-2 h-5 w-px shrink-0" />
2312
+ <button
2313
+ type="button"
2314
+ className={iconBtn}
2315
+ title="Previous (K)"
2316
+ aria-label="Previous entry"
2317
+ disabled={index <= 0}
2318
+ onClick={() => index > 0 && list[index - 1] && onOpen(list[index - 1]!.id)}
2319
+ >
2320
+ <ChevronLeft size={15} aria-hidden />
2321
+ </button>
2322
+ {index >= 0 ? (
2323
+ <span
2324
+ aria-live="polite"
2325
+ className="text-faint mx-1 text-[12px] whitespace-nowrap tabular-nums max-[640px]:sr-only"
1173
2326
  >
1174
- <Archive size={13} aria-hidden /> {entry.archived ? 'Unarchive' : 'Archive'}
1175
- </Ghost>
2327
+ Entry {index + 1} of {list.length}
2328
+ </span>
2329
+ ) : null}
2330
+ <button
2331
+ type="button"
2332
+ className={iconBtn}
2333
+ title="Next (J)"
2334
+ aria-label="Next entry"
2335
+ disabled={index < 0 || index >= list.length - 1}
2336
+ onClick={() => list[index + 1] && onOpen(list[index + 1]!.id)}
2337
+ >
2338
+ <ChevronRight size={15} aria-hidden />
2339
+ </button>
2340
+ {narrow ? null : (
1176
2341
  <button
1177
2342
  type="button"
1178
- className="text-err hover:bg-err-l ml-auto inline-flex items-center gap-[5px] rounded-[7px] px-[9px] py-1.5 text-[12.5px]"
1179
- onClick={() => onDelete(entry.id)}
2343
+ className={iconBtn}
2344
+ title="Close (Esc)"
2345
+ aria-label="Close entry"
2346
+ onClick={onClose}
1180
2347
  >
1181
- <Trash2 size={13} aria-hidden /> Delete
2348
+ <X size={15} aria-hidden />
1182
2349
  </button>
1183
- </div>
1184
- </article>
2350
+ )}
2351
+ </div>
1185
2352
 
1186
- <article className="border-bdr bg-card shadow-shd mb-3.5 overflow-hidden rounded-[10px] border">
1187
- <div className="border-bdr text-faint flex items-center px-5 py-[11px] text-[11px] font-bold tracking-[0.6px] uppercase">
1188
- Submission
1189
- <span className="ml-auto text-[11.5px] font-semibold tracking-normal normal-case">
1190
- {ordered.length} fields
1191
- </span>
1192
- </div>
1193
- <div className="grid grid-cols-1 gap-x-5 gap-y-3.5 p-4 px-5 min-[620px]:grid-cols-2">
1194
- {ordered.map(({ key, label }) => {
1195
- const value = displayValue(entry.data[key])
1196
- return (
1197
- <div
1198
- key={key}
1199
- className={`group ${fieldIsWide(key, value) ? 'min-[620px]:col-span-2' : ''}`}
1200
- >
1201
- <div className="text-faint mb-[5px] flex items-center gap-1.5 text-[10.5px] font-bold tracking-[0.5px] uppercase">
1202
- {label}
1203
- {value ? (
1204
- <button
1205
- type="button"
1206
- aria-label={`Copy ${label}`}
1207
- className="text-faint hover:text-acc hidden group-hover:inline-flex"
1208
- onClick={() => {
1209
- void navigator.clipboard?.writeText(value)
1210
- toast.success('Copied')
1211
- }}
2353
+ {/* Hybrid white top band: hero + message */}
2354
+ <div className="border-bdr bg-card border-b">
2355
+ <div className="mx-auto max-w-[860px] px-8 pt-7 pb-[30px] max-[900px]:px-4 max-[900px]:pt-5 max-[900px]:pb-6 @[1240px]:max-w-[1180px]">
2356
+ <div className={`flex items-start gap-4 max-[640px]:flex-wrap ${msgEntry ? 'mb-6' : ''}`}>
2357
+ <span
2358
+ className="flex size-[52px] shrink-0 items-center justify-center rounded-full text-[18px] font-bold"
2359
+ style={{ background: avatarColor(name), color: 'var(--on-acc)' }}
2360
+ >
2361
+ {initials(name)}
2362
+ </span>
2363
+ <div className="min-w-0 flex-1">
2364
+ <h2 className="text-txt m-0 text-[22px] leading-[1.2] font-bold tracking-[-0.4px] break-words">
2365
+ {name}
2366
+ </h2>
2367
+ <div className="text-faint mt-1.5 flex flex-wrap items-center gap-x-2 gap-y-1.5 text-[12.5px]">
2368
+ <span
2369
+ className="rounded-[5px] px-[7px] py-0.5 text-[10px] font-semibold whitespace-nowrap"
2370
+ style={{ background: formColor.bg, color: formColor.fg }}
2371
+ >
2372
+ {formLabel}
2373
+ </span>
2374
+ {entry.unread ? (
2375
+ <span className="bg-acc-l text-acc rounded-[5px] px-2 py-[3px] text-[11px] font-semibold">
2376
+ Unread
2377
+ </span>
2378
+ ) : null}
2379
+ {entry.starred ? (
2380
+ <span className="bg-warn-l text-warn inline-flex items-center gap-1 rounded-[5px] px-2 py-[3px] text-[11px] font-semibold">
2381
+ <Star size={11} aria-hidden className="fill-current" /> Starred
2382
+ </span>
2383
+ ) : null}
2384
+ {entry.archived ? (
2385
+ <span className="border-bdr bg-bg text-faint rounded-[5px] border px-2 py-[3px] text-[11px] font-semibold">
2386
+ Archived
2387
+ </span>
2388
+ ) : null}
2389
+ <span>{fullEntryTime(entry.submittedAt)}</span>
2390
+ {otherCount > 0 && email ? (
2391
+ <button
2392
+ type="button"
2393
+ onClick={() => onFindEmail(email)}
2394
+ className="text-acc decoration-acc-m hover:decoration-acc cursor-pointer border-0 bg-transparent p-0 text-[12.5px] font-semibold whitespace-nowrap underline underline-offset-2"
2395
+ >
2396
+ {otherCount} other {otherCount === 1 ? 'entry' : 'entries'} from this person
2397
+ </button>
2398
+ ) : null}
2399
+ </div>
2400
+
2401
+ {/* Source line */}
2402
+ <div className="text-sub mt-2 flex min-w-0 items-center gap-2 text-[12.5px]">
2403
+ <span
2404
+ className="inline-flex shrink-0 items-center rounded-[5px] px-2 py-[3px] text-[11px] font-semibold"
2405
+ style={{ color: attr.channelFg, background: attr.channelBg }}
2406
+ >
2407
+ {attr.channelLabel}
2408
+ </span>
2409
+ <span className="min-w-0 truncate">
2410
+ <b className="text-txt font-semibold">{attr.source}</b> / {attr.medium}
2411
+ {attr.campaign ? ` · ${attr.campaign}` : ''}
2412
+ </span>
2413
+ </div>
2414
+
2415
+ {/* Contact pills */}
2416
+ {email || phone || website ? (
2417
+ <div className="mt-3 flex flex-wrap gap-1.5">
2418
+ {email ? (
2419
+ <a
2420
+ href={mailHref}
2421
+ title="Email with their message quoted"
2422
+ className="border-bdr bg-card text-txt hover:border-acc-m hover:bg-acc-l hover:text-acc inline-flex max-w-full items-center gap-1.5 truncate rounded-full border px-[11px] py-[5px] text-[12.5px] no-underline"
1212
2423
  >
1213
- <Copy size={11} aria-hidden />
1214
- </button>
2424
+ <Mail size={13} aria-hidden className="text-faint shrink-0" />
2425
+ {email}
2426
+ </a>
2427
+ ) : null}
2428
+ {phone ? (
2429
+ <a
2430
+ href={`tel:${phone.replace(/[^\d+]/g, '')}`}
2431
+ className="border-bdr bg-card text-txt hover:border-acc-m hover:bg-acc-l hover:text-acc inline-flex max-w-full items-center gap-1.5 truncate rounded-full border px-[11px] py-[5px] text-[12.5px] no-underline"
2432
+ >
2433
+ <Phone size={13} aria-hidden className="text-faint shrink-0" />
2434
+ {phone}
2435
+ </a>
2436
+ ) : null}
2437
+ {website ? (
2438
+ <a
2439
+ href={website}
2440
+ target="_blank"
2441
+ rel="noopener noreferrer"
2442
+ className="border-bdr bg-card text-txt hover:border-acc-m hover:bg-acc-l hover:text-acc inline-flex max-w-full items-center gap-1.5 truncate rounded-full border px-[11px] py-[5px] text-[12.5px] no-underline"
2443
+ >
2444
+ <Globe size={13} aria-hidden className="text-faint shrink-0" />
2445
+ {website.replace(/^https?:\/\//, '').replace(/\/$/, '')}
2446
+ </a>
1215
2447
  ) : null}
1216
2448
  </div>
1217
- <div
1218
- className={`rounded-[8px] px-3 py-[9px] text-[14px] leading-[1.6] break-words whitespace-pre-wrap ${value ? 'border-bdr bg-bg text-txt border' : 'text-faint border-bdr border border-dashed italic'}`}
2449
+ ) : null}
2450
+ </div>
2451
+
2452
+ {/* Right side: status and assignee pill-selects */}
2453
+ {entry.spamStatus !== 'spam' && !entry.partial && !entry.deleted ? (
2454
+ <div className="flex shrink-0 flex-col items-end gap-2 max-[640px]:w-full max-[640px]:flex-row max-[640px]:justify-start max-[640px]:pl-[68px]">
2455
+ <label
2456
+ className="focus-within:outline-acc inline-flex cursor-pointer items-center gap-[7px] rounded-full border px-2.5 py-1 text-[12.5px] font-semibold focus-within:outline focus-within:outline-offset-2"
2457
+ style={{
2458
+ color: pipe.fg,
2459
+ background: pipe.bg,
2460
+ borderColor: `color-mix(in srgb, ${pipe.fg} 30%, transparent)`,
2461
+ }}
1219
2462
  >
1220
- {value || 'Not provided'}
2463
+ <i className="size-[7px] rounded-full" style={{ background: pipe.fg }} />
2464
+ <select
2465
+ aria-label="Status"
2466
+ value={pipe.id}
2467
+ onChange={(event) => {
2468
+ const next = pipeOf(event.target.value)
2469
+ onPatch(entry.id, { status: next.id }, `Status: ${next.label}`)
2470
+ }}
2471
+ className="cursor-pointer appearance-none border-0 bg-transparent pr-0.5 font-[inherit] text-inherit focus:outline-none"
2472
+ >
2473
+ {PIPE_STATUSES.map((item) => (
2474
+ <option key={item.id} value={item.id}>
2475
+ {item.label}
2476
+ </option>
2477
+ ))}
2478
+ </select>
2479
+ <ChevronDown size={13} aria-hidden />
2480
+ </label>
2481
+ <label className="border-bdr bg-card text-sub focus-within:outline-acc inline-flex cursor-pointer items-center gap-[7px] rounded-full border py-[3px] pr-2.5 pl-[3px] focus-within:outline focus-within:outline-offset-2">
2482
+ {assignee ? (
2483
+ <span
2484
+ className="inline-flex size-[22px] shrink-0 items-center justify-center rounded-full text-[9.5px] font-bold tracking-[-0.2px]"
2485
+ style={{ background: avatarColor(assignee.name), color: 'var(--on-acc)' }}
2486
+ title={assignee.name}
2487
+ >
2488
+ {initials(assignee.name)}
2489
+ </span>
2490
+ ) : (
2491
+ <span
2492
+ className="border-bdr bg-bg text-faint inline-flex size-[22px] shrink-0 items-center justify-center rounded-full border border-dashed text-[10px] font-bold"
2493
+ title="Unassigned"
2494
+ >
2495
+ ?
2496
+ </span>
2497
+ )}
2498
+ <select
2499
+ aria-label="Assigned to"
2500
+ value={entry.assigneeId ?? ''}
2501
+ onChange={(event) => {
2502
+ const nextId = event.target.value || null
2503
+ const target = nextId ? team.find((t) => t.id === nextId) : undefined
2504
+ onPatch(
2505
+ entry.id,
2506
+ { assigneeId: nextId, assigneeName: target?.name ?? null },
2507
+ target ? `Assigned to ${target.name}` : 'Unassigned',
2508
+ )
2509
+ }}
2510
+ className="text-txt cursor-pointer appearance-none border-0 bg-transparent pr-0.5 font-[inherit] text-[12.5px] font-semibold focus:outline-none"
2511
+ >
2512
+ <option value="">Unassigned</option>
2513
+ {team.map((member) => (
2514
+ <option key={member.id} value={member.id}>
2515
+ {member.name}
2516
+ {member.id === currentUserId ? ' (you)' : ''}
2517
+ </option>
2518
+ ))}
2519
+ </select>
2520
+ <ChevronDown size={13} aria-hidden />
2521
+ </label>
2522
+ </div>
2523
+ ) : null}
2524
+ </div>
2525
+
2526
+ {/* Trash / Partial / Spam banners */}
2527
+ {entry.deleted
2528
+ ? (() => {
2529
+ const d = daysLeftInTrash(entry.deleted.at)
2530
+ const deletedBy =
2531
+ entry.deleted.by === currentUserId || entry.deleted.by === 'self'
2532
+ ? 'you'
2533
+ : team.find((t) => t.id === entry.deleted?.by)?.name ||
2534
+ entry.deleted.byName ||
2535
+ 'a team member'
2536
+ return (
2537
+ <div
2538
+ role="note"
2539
+ className="border-bdr bg-bg text-sub mb-3 flex items-start gap-2.5 rounded-[10px] border px-3.5 py-[11px] text-[13px]"
2540
+ >
2541
+ <Trash2 size={16} aria-hidden className="mt-px shrink-0" />
2542
+ <div>
2543
+ <b className="text-txt mb-0.5 block text-[13px]">
2544
+ In Trash · deleted by {deletedBy} on {fullEntryTime(entry.deleted.at)}
2545
+ </b>
2546
+ <span>
2547
+ {d === 0
2548
+ ? 'Removed for good today.'
2549
+ : `Removed for good in ${d} ${d === 1 ? 'day' : 'days'}.`}{' '}
2550
+ Restore puts it back in {entry.archived ? 'Archived' : 'the inbox'} with its
2551
+ status, notes and assignee.
2552
+ </span>
2553
+ </div>
2554
+ </div>
2555
+ )
2556
+ })()
2557
+ : null}
2558
+ {entry.partial ? (
2559
+ <div
2560
+ role="note"
2561
+ className="bg-warn-l text-warn mb-3 flex items-start gap-2.5 rounded-[10px] border px-3.5 py-[11px] text-[12.5px] leading-[1.5]"
2562
+ style={{ borderColor: 'color-mix(in srgb, var(--warn) 28%, transparent)' }}
2563
+ >
2564
+ <Clock size={16} aria-hidden className="mt-px shrink-0" />
2565
+ <div>
2566
+ <b className="block text-[13px]">{`Didn’t finish · stopped at step ${entry.partial.step} of ${entry.partial.of}: ${entry.partial.stepName}`}</b>
2567
+ <span className="text-txt block">{`Last active ${fullEntryTime(entry.partial.lastAt)}. Saved automatically because this form keeps partial entries. No notification was sent.`}</span>
2568
+ <div className="mt-2 flex max-w-[220px] gap-1" aria-hidden="true">
2569
+ {Array.from({ length: entry.partial.of }).map((_, idx) => (
2570
+ <i
2571
+ key={idx}
2572
+ className="h-[5px] flex-1 rounded-full"
2573
+ style={{
2574
+ background:
2575
+ idx < (entry.partial?.step ?? 1) - 1
2576
+ ? 'var(--warn)'
2577
+ : idx === (entry.partial?.step ?? 1) - 1
2578
+ ? 'repeating-linear-gradient(90deg, var(--warn) 0 4px, transparent 4px 7px)'
2579
+ : 'color-mix(in srgb, var(--warn) 20%, var(--card))',
2580
+ }}
2581
+ />
2582
+ ))}
1221
2583
  </div>
1222
2584
  </div>
1223
- )
1224
- })}
2585
+ </div>
2586
+ ) : null}
2587
+ {entry.spamStatus === 'spam' ? (
2588
+ <div
2589
+ role="note"
2590
+ className="bg-err-l text-err mb-3 flex items-start gap-2.5 rounded-[10px] border px-3.5 py-[11px] text-[12.5px] leading-[1.5]"
2591
+ style={{ borderColor: 'color-mix(in srgb, var(--err) 25%, transparent)' }}
2592
+ >
2593
+ <ShieldX size={16} aria-hidden className="mt-px shrink-0" />
2594
+ <div>
2595
+ <b className="flex flex-wrap items-center gap-2 text-[13px]">
2596
+ Marked as spam ·{' '}
2597
+ {entry.spamMeta?.by && entry.spamMeta.by !== 'manual'
2598
+ ? (SPAM_BY_LABELS[entry.spamMeta.by] ?? 'You')
2599
+ : 'You'}
2600
+ {entry.spamMeta?.score ? (
2601
+ <span
2602
+ className="bg-card text-err rounded-full border px-[7px] text-[11px] font-semibold whitespace-nowrap"
2603
+ style={{ borderColor: 'color-mix(in srgb, var(--err) 25%, transparent)' }}
2604
+ >
2605
+ {entry.spamMeta.score}% confidence
2606
+ </span>
2607
+ ) : null}
2608
+ </b>
2609
+ <span className="text-txt block">
2610
+ {`${entry.spamMeta?.reason ?? 'Marked as spam by you.'} No notification email was sent.`}
2611
+ </span>
2612
+ </div>
2613
+ </div>
2614
+ ) : null}
2615
+
2616
+ {/* Message block on hybrid white band */}
2617
+ {msgEntry ? (
2618
+ <section className="group" aria-labelledby="d-msg-l">
2619
+ <div className="text-faint mb-2 flex items-center gap-2 text-[12px] font-semibold">
2620
+ <span id="d-msg-l">{msgEntry.label}</span>
2621
+ <button
2622
+ type="button"
2623
+ title={`Copy ${msgEntry.label}`}
2624
+ aria-label={`Copy ${msgEntry.label}`}
2625
+ onClick={() => copyValue(msgText)}
2626
+ className="text-faint hover:bg-acc-l hover:text-acc ml-auto inline-flex size-6 items-center justify-center rounded-[6px] opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100 focus-visible:opacity-100"
2627
+ >
2628
+ <Copy size={13} aria-hidden />
2629
+ </button>
2630
+ </div>
2631
+ <div
2632
+ dir="auto"
2633
+ className="text-txt max-w-[68ch] text-[15.5px] leading-[1.7] break-words whitespace-pre-wrap @[1240px]:max-w-[75ch]"
2634
+ >
2635
+ {formatFieldDisplay(msgEntry.key, msgText, fieldMap.get(msgEntry.key))}
2636
+ </div>
2637
+ </section>
2638
+ ) : null}
1225
2639
  </div>
1226
- </article>
2640
+ </div>
1227
2641
 
1228
- <article className="border-bdr bg-card shadow-shd overflow-hidden rounded-[10px] border">
1229
- <button
1230
- type="button"
1231
- className="border-bdr text-faint hover:text-acc flex w-full items-center px-5 py-[11px] text-left text-[11px] font-bold tracking-[0.6px] uppercase"
1232
- aria-expanded={metaOpen}
1233
- onClick={() => setMetaOpen((open) => !open)}
1234
- >
1235
- Attribution & technical
1236
- <span className="ml-auto inline-flex items-center gap-1.5 text-[11.5px] font-semibold tracking-normal normal-case">
1237
- <ChevronDown size={14} aria-hidden className={metaOpen ? 'rotate-180' : ''} />
1238
- </span>
1239
- </button>
1240
- {metaOpen ? (
1241
- <dl className="grid grid-cols-1 gap-[9px] px-5 py-3.5 min-[620px]:grid-cols-2">
1242
- <Meta label="Submitted" value={fullEntryTime(entry.submittedAt)} />
1243
- <Meta label="Form" value={formLabel} />
1244
- {buildAttributionRows(entry).map((row) => (
1245
- <Meta key={row.label} label={row.label} value={row.value} />
1246
- ))}
1247
- <Meta label="User agent" value={entry.userAgent || '—'} />
1248
- <Meta label="Entry ID" value={entryIdLabel(entry)} mono />
2642
+ {/* Grey body area: cards */}
2643
+ <div className="mx-auto max-w-[860px] px-8 pt-[22px] pb-12 max-[900px]:px-4 max-[900px]:pt-4 max-[900px]:pb-10 @[1240px]:grid @[1240px]:max-w-[1180px] @[1240px]:grid-cols-[minmax(0,1fr)_400px] @[1240px]:items-start @[1240px]:gap-x-5">
2644
+ {/* Submission card */}
2645
+ <article className="border-bdr bg-card shadow-shd mb-3.5 overflow-hidden rounded-[10px] border @[1240px]:col-start-1">
2646
+ <h3 className="border-bdr text-faint m-0 flex items-center gap-2 border-b px-5 py-3 text-[11px] font-bold tracking-[0.6px] uppercase">
2647
+ Submission
2648
+ <span className="ml-auto text-[11.5px] font-semibold tracking-normal normal-case">
2649
+ {answeredCount} of {present.length} answered
2650
+ </span>
2651
+ </h3>
2652
+ <dl className="divide-bdr m-0 divide-y">
2653
+ {filledRows.map(({ key, label }) => {
2654
+ const raw = displayValue(entry.data[key])
2655
+ const formatted = formatFieldDisplay(key, raw, fieldMap.get(key))
2656
+ return (
2657
+ <DetailRow key={key} label={label} copyText={formatted} onCopy={copyValue}>
2658
+ {formatted}
2659
+ </DetailRow>
2660
+ )
2661
+ })}
2662
+ {showEmpty
2663
+ ? emptyRows.map(({ key, label }) => (
2664
+ <div
2665
+ key={key}
2666
+ className="grid grid-cols-[minmax(110px,32%)_minmax(0,1fr)] items-baseline gap-x-4 gap-y-1 px-5 py-[11px] max-[520px]:grid-cols-1"
2667
+ >
2668
+ <dt className="text-sub text-[12.5px] leading-[1.5] font-medium">{label}</dt>
2669
+ <dd className="text-faint m-0 text-[14px] leading-[1.55]">Not answered</dd>
2670
+ </div>
2671
+ ))
2672
+ : null}
1249
2673
  </dl>
2674
+ {emptyRows.length > 0 ? (
2675
+ <button
2676
+ type="button"
2677
+ aria-expanded={showEmpty}
2678
+ onClick={() => setShowEmpty((v) => !v)}
2679
+ className="border-bdr text-acc hover:bg-acc-l block w-full cursor-pointer border-0 border-t bg-transparent px-5 py-2.5 text-left text-[12.5px] font-medium"
2680
+ >
2681
+ {showEmpty
2682
+ ? 'Hide empty fields'
2683
+ : `Show ${emptyRows.length} empty ${emptyRows.length === 1 ? 'field' : 'fields'}`}
2684
+ </button>
2685
+ ) : null}
2686
+ </article>
2687
+
2688
+ {/* Team notes card */}
2689
+ {entry.spamStatus !== 'spam' && !entry.partial ? (
2690
+ <article className="border-bdr bg-card shadow-shd mb-3.5 overflow-hidden rounded-[10px] border @[1240px]:col-start-1">
2691
+ <h3 className="border-bdr text-faint m-0 flex items-center gap-2 border-b px-5 py-3 text-[11px] font-bold tracking-[0.6px] uppercase">
2692
+ Team notes
2693
+ <span className="ml-auto text-[11.5px] font-semibold tracking-normal normal-case">
2694
+ {notes.length} {notes.length === 1 ? 'note' : 'notes'}
2695
+ </span>
2696
+ </h3>
2697
+ <div className="flex flex-col gap-3.5 px-5 pt-3.5 pb-4">
2698
+ {notes.map((n, idx) => {
2699
+ const author =
2700
+ team.find((t) => t.id === n.authorId)?.name ||
2701
+ n.authorName ||
2702
+ n.authorId ||
2703
+ 'Team'
2704
+ return (
2705
+ <div key={idx} className="flex gap-2.5">
2706
+ <span
2707
+ className="flex size-[26px] shrink-0 items-center justify-center rounded-full text-[11px] font-bold"
2708
+ style={{ background: avatarColor(author), color: 'var(--on-acc)' }}
2709
+ >
2710
+ {initials(author)}
2711
+ </span>
2712
+ <div className="min-w-0 flex-1">
2713
+ <div className="flex items-baseline gap-2 text-[12.5px]">
2714
+ <b className="text-txt font-semibold">{author}</b>
2715
+ <span className="text-faint text-[11.5px]">{fullEntryTime(n.at)}</span>
2716
+ </div>
2717
+ <div className="text-txt mt-0.5 text-[13px] leading-[1.5] whitespace-pre-wrap">
2718
+ {n.text}
2719
+ </div>
2720
+ </div>
2721
+ </div>
2722
+ )
2723
+ })}
2724
+ {notes.length === 0 ? (
2725
+ <div className="text-faint text-[12.5px]">
2726
+ No notes yet. Notes are only visible to your team.
2727
+ </div>
2728
+ ) : null}
2729
+ <div className="border-bdr flex gap-2.5 border-t pt-3">
2730
+ <span
2731
+ className="flex size-[26px] shrink-0 items-center justify-center rounded-full text-[11px] font-bold"
2732
+ style={{ background: avatarColor(currentUserName), color: 'var(--on-acc)' }}
2733
+ >
2734
+ {initials(currentUserName)}
2735
+ </span>
2736
+ <div className="min-w-0 flex-1">
2737
+ <textarea
2738
+ rows={2}
2739
+ value={noteText}
2740
+ placeholder="Add a note for your team…"
2741
+ aria-label="Add a note"
2742
+ onChange={(e) => setNoteText(e.target.value)}
2743
+ onKeyDown={(e) => {
2744
+ if (e.key === 'Enter' && (e.metaKey || e.ctrlKey) && noteText.trim()) {
2745
+ e.preventDefault()
2746
+ addNote()
2747
+ }
2748
+ }}
2749
+ className="border-bdr bg-card text-txt focus-visible:outline-acc min-h-[58px] w-full resize-y rounded-[9px] border px-2.5 py-2 text-[13px] leading-[1.45] focus-visible:outline focus-visible:outline-offset-2"
2750
+ />
2751
+ <div className="text-faint mt-1.5 flex items-center gap-2.5 text-[11.5px]">
2752
+ <span className="flex-1">⌘ Enter to save · only visible to your team</span>
2753
+ <button
2754
+ type="button"
2755
+ disabled={!noteText.trim()}
2756
+ onClick={addNote}
2757
+ className="bg-acc inline-flex items-center gap-1.5 rounded-[8px] px-[15px] py-2 text-[13px] font-medium text-[var(--on-acc)] disabled:cursor-not-allowed disabled:opacity-45"
2758
+ >
2759
+ Add note
2760
+ </button>
2761
+ </div>
2762
+ </div>
2763
+ </div>
2764
+ </div>
2765
+ </article>
1250
2766
  ) : null}
1251
- </article>
2767
+
2768
+ {/* Attribution & technical card */}
2769
+ <article className="border-bdr bg-card shadow-shd mb-3.5 overflow-hidden rounded-[10px] border @[1240px]:sticky @[1240px]:top-[68px] @[1240px]:col-start-2 @[1240px]:row-span-2 @[1240px]:row-start-1">
2770
+ <h3 className="m-0">
2771
+ <button
2772
+ type="button"
2773
+ aria-expanded={metaOpen}
2774
+ aria-controls="d-attr"
2775
+ onClick={() => setMetaOpen((open) => !open)}
2776
+ className={`border-bdr text-faint hover:text-acc flex w-full cursor-pointer items-center gap-2 bg-transparent px-5 py-3 text-left text-[11px] font-bold tracking-[0.6px] uppercase ${
2777
+ metaOpen ? 'border-b' : ''
2778
+ }`}
2779
+ >
2780
+ Attribution & technical
2781
+ <span className="ml-auto inline-flex items-center gap-1.5 text-[11.5px] font-semibold tracking-normal normal-case">
2782
+ {attr.spamScore >= 80 ? (
2783
+ <span className="bg-err-l text-err rounded-[5px] px-[7px] py-0.5 text-[10px] font-semibold">
2784
+ Spam {attr.spamScore}
2785
+ </span>
2786
+ ) : (
2787
+ <span className="text-faint">Spam score {attr.spamScore}</span>
2788
+ )}
2789
+ <ChevronDown
2790
+ size={14}
2791
+ aria-hidden
2792
+ className={`transition-transform ${metaOpen ? 'rotate-180' : ''}`}
2793
+ />
2794
+ </span>
2795
+ </button>
2796
+ </h3>
2797
+ {metaOpen ? (
2798
+ <dl id="d-attr" className="divide-bdr m-0 divide-y">
2799
+ <DetailRow label="Channel" compact>
2800
+ <span
2801
+ className="inline-flex items-center rounded-[5px] border px-2 py-[3px] text-[11px] font-semibold"
2802
+ style={{
2803
+ color: attr.channelFg,
2804
+ background: attr.channelBg,
2805
+ borderColor: `color-mix(in srgb, ${attr.channelFg} 22%, transparent)`,
2806
+ }}
2807
+ >
2808
+ {attr.channelLabel}
2809
+ </span>
2810
+ </DetailRow>
2811
+ <DetailRow
2812
+ label="Source / Medium"
2813
+ compact
2814
+ copyText={`${attr.source} / ${attr.medium}`}
2815
+ onCopy={copyValue}
2816
+ >
2817
+ <b className="text-txt font-semibold">
2818
+ {attr.source} <span className="text-faint font-normal">/</span> {attr.medium}
2819
+ </b>
2820
+ </DetailRow>
2821
+ {attr.campaign ? (
2822
+ <DetailRow label="Campaign" compact copyText={attr.campaign} onCopy={copyValue}>
2823
+ {attr.campaign}
2824
+ </DetailRow>
2825
+ ) : null}
2826
+ {attr.term ? (
2827
+ <DetailRow label="Keyword" compact copyText={attr.term} onCopy={copyValue}>
2828
+ {attr.term}
2829
+ </DetailRow>
2830
+ ) : null}
2831
+ <ClickIdRow ids={attr.clickIds} onCopy={copyValue} />
2832
+ <DetailRow
2833
+ label="Landing page"
2834
+ compact
2835
+ copyText={attr.landingPage !== '—' ? attr.landingPage : undefined}
2836
+ onCopy={copyValue}
2837
+ >
2838
+ {attr.landingPage !== '—' ? (
2839
+ <a
2840
+ href={attr.landingPage}
2841
+ target="_blank"
2842
+ rel="noopener noreferrer"
2843
+ className="text-acc hover:underline"
2844
+ >
2845
+ {attr.landingPage}
2846
+ </a>
2847
+ ) : (
2848
+ '—'
2849
+ )}
2850
+ </DetailRow>
2851
+ <DetailRow label="Referrer" compact copyText={attr.referrer} onCopy={copyValue}>
2852
+ {attr.referrer}
2853
+ </DetailRow>
2854
+ <DetailRow label="Device" compact copyText={attr.device} onCopy={copyValue} clamp>
2855
+ {attr.device}
2856
+ </DetailRow>
2857
+ <DetailRow
2858
+ label="IP address"
2859
+ compact
2860
+ mono
2861
+ copyText={attr.ip !== '—' ? attr.ip : undefined}
2862
+ onCopy={copyValue}
2863
+ >
2864
+ {attr.ip}
2865
+ </DetailRow>
2866
+ <DetailRow
2867
+ label="Submitted"
2868
+ compact
2869
+ copyText={fullEntryTime(entry.submittedAt)}
2870
+ onCopy={copyValue}
2871
+ >
2872
+ {fullEntryTime(entry.submittedAt)}
2873
+ </DetailRow>
2874
+ <DetailRow label="Form" compact copyText={formLabel} onCopy={copyValue}>
2875
+ {formLabel}
2876
+ </DetailRow>
2877
+ <DetailRow
2878
+ label="Entry ID"
2879
+ compact
2880
+ mono
2881
+ copyText={entryIdLabel(entry)}
2882
+ onCopy={copyValue}
2883
+ >
2884
+ {entryIdLabel(entry)}
2885
+ </DetailRow>
2886
+ </dl>
2887
+ ) : null}
2888
+ </article>
2889
+ </div>
1252
2890
  </div>
1253
2891
  )
1254
2892
  }
1255
2893
 
1256
- function Ghost({ children, onClick }: { children: ReactNode; onClick: () => void }) {
2894
+ function DetailRow({
2895
+ label,
2896
+ children,
2897
+ copyText,
2898
+ onCopy,
2899
+ compact,
2900
+ mono,
2901
+ clamp,
2902
+ }: {
2903
+ label: string
2904
+ children: ReactNode
2905
+ copyText?: string
2906
+ onCopy?: (value: string) => void
2907
+ compact?: boolean
2908
+ mono?: boolean
2909
+ clamp?: boolean
2910
+ }) {
1257
2911
  return (
1258
- <button
1259
- type="button"
1260
- onClick={onClick}
1261
- className="text-sub hover:bg-acc-l hover:text-acc inline-flex items-center gap-[5px] rounded-[7px] px-[9px] py-1.5 text-[12.5px]"
2912
+ <div
2913
+ className={`group grid items-baseline gap-x-4 gap-y-1 px-5 hover:bg-[color-mix(in_srgb,var(--bg)_60%,transparent)] max-[520px]:grid-cols-1 ${
2914
+ compact
2915
+ ? 'grid-cols-[minmax(110px,32%)_minmax(0,1fr)] py-[9px] @[1240px]:grid-cols-[118px_minmax(0,1fr)]'
2916
+ : 'grid-cols-[minmax(110px,32%)_minmax(0,1fr)] py-[11px]'
2917
+ }`}
1262
2918
  >
1263
- {children}
1264
- </button>
2919
+ <dt className="text-sub text-[12.5px] leading-[1.5] font-medium">{label}</dt>
2920
+ <dd
2921
+ className={`m-0 flex min-w-0 items-start gap-2 leading-[1.55] ${
2922
+ compact ? 'text-sub text-[13px]' : 'text-txt text-[14px]'
2923
+ }`}
2924
+ >
2925
+ <span
2926
+ dir="auto"
2927
+ className={`min-w-0 flex-1 break-words ${
2928
+ clamp ? 'line-clamp-2 whitespace-normal' : 'whitespace-pre-wrap'
2929
+ } ${mono ? 'font-mono text-[12px]' : ''}`}
2930
+ >
2931
+ {children}
2932
+ </span>
2933
+ {copyText && onCopy ? (
2934
+ <button
2935
+ type="button"
2936
+ title={`Copy ${label}`}
2937
+ aria-label={`Copy ${label}`}
2938
+ onClick={() => onCopy(copyText)}
2939
+ className="text-faint hover:bg-acc-l hover:text-acc -my-0.5 inline-flex size-6 shrink-0 items-center justify-center rounded-[6px] opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100 focus-visible:opacity-100"
2940
+ >
2941
+ <Copy size={13} aria-hidden />
2942
+ </button>
2943
+ ) : null}
2944
+ </dd>
2945
+ </div>
1265
2946
  )
1266
2947
  }
1267
2948
 
1268
- function Meta({ label, value, mono }: { label: string; value: string; mono?: boolean }) {
2949
+ function ClickIdRow({
2950
+ ids,
2951
+ onCopy,
2952
+ }: {
2953
+ ids: AttributionClickId[]
2954
+ onCopy: (value: string) => void
2955
+ }) {
2956
+ const label = ids.length > 1 ? 'Click IDs' : 'Click ID'
2957
+ if (ids.length === 0) {
2958
+ return (
2959
+ <DetailRow label={label} compact>
2960
+ <span className="text-faint">None · not an ad click</span>
2961
+ </DetailRow>
2962
+ )
2963
+ }
1269
2964
  return (
1270
- <div className="flex min-w-0 items-baseline gap-2.5 text-[12.5px]">
1271
- <dt className="text-faint w-24 shrink-0">{label}</dt>
1272
- <dd className={`text-sub min-w-0 break-all ${mono ? 'font-mono text-[11.5px]' : ''}`}>
1273
- {value}
2965
+ <div className="grid grid-cols-[minmax(110px,32%)_minmax(0,1fr)] items-baseline gap-x-4 gap-y-1 px-5 py-[9px] max-[520px]:grid-cols-1 @[1240px]:grid-cols-[118px_minmax(0,1fr)]">
2966
+ <dt className="text-sub text-[12.5px] leading-[1.5] font-medium">{label}</dt>
2967
+ <dd className="text-sub m-0 min-w-0 text-[13px]">
2968
+ <div className="flex min-w-0 flex-col gap-1.5">
2969
+ {ids.map((id) => (
2970
+ <div
2971
+ key={id.key}
2972
+ className="grid min-w-0 grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-2.5 max-[520px]:grid-cols-[minmax(0,1fr)_auto]"
2973
+ >
2974
+ <span className="inline-flex items-center gap-1.5 text-[12px] whitespace-nowrap max-[520px]:col-span-full">
2975
+ <b className="text-txt font-semibold">{id.platform}</b>
2976
+ <code className="border-bdr bg-bg text-sub rounded-[4px] border px-[5px] font-mono text-[10.5px]">
2977
+ {id.key}
2978
+ </code>
2979
+ </span>
2980
+ <span className="text-sub min-w-0 truncate font-mono text-[11.5px]" title={id.value}>
2981
+ {id.value}
2982
+ </span>
2983
+ <button
2984
+ type="button"
2985
+ title={`Copy ${id.key}`}
2986
+ aria-label={`Copy ${id.key}`}
2987
+ onClick={() => onCopy(id.value)}
2988
+ className="text-faint hover:bg-acc-l hover:text-acc inline-flex size-6 items-center justify-center rounded-[5px]"
2989
+ >
2990
+ <Copy size={12} aria-hidden />
2991
+ </button>
2992
+ </div>
2993
+ ))}
2994
+ </div>
1274
2995
  </dd>
1275
2996
  </div>
1276
2997
  )
1277
2998
  }
2999
+
3000
+ function EmptyTrashDialog({
3001
+ count,
3002
+ onClose,
3003
+ onConfirm,
3004
+ }: {
3005
+ count: number
3006
+ onClose: () => void
3007
+ onConfirm: () => void
3008
+ }) {
3009
+ const [value, setValue] = useState('')
3010
+ const inputRef = useRef<HTMLInputElement>(null)
3011
+
3012
+ return (
3013
+ <Modal
3014
+ open
3015
+ onClose={onClose}
3016
+ title="Empty trash?"
3017
+ initialFocusRef={inputRef}
3018
+ actions={
3019
+ <>
3020
+ <button
3021
+ type="button"
3022
+ onClick={onClose}
3023
+ className="border-bdr bg-card text-txt hover:border-acc-m hover:bg-acc-l hover:text-acc inline-flex items-center gap-1.5 rounded-[8px] border px-3 py-[7px] text-[13px]"
3024
+ >
3025
+ Cancel
3026
+ </button>
3027
+ <button
3028
+ type="button"
3029
+ disabled={value !== 'DELETE'}
3030
+ onClick={onConfirm}
3031
+ className="bg-err text-destructive-foreground inline-flex h-8 cursor-pointer items-center gap-1.5 rounded-[8px] border-0 px-3.5 text-[13px] font-medium disabled:cursor-not-allowed disabled:opacity-45"
3032
+ >
3033
+ <Trash2 size={14} aria-hidden />
3034
+ Delete forever
3035
+ </button>
3036
+ </>
3037
+ }
3038
+ >
3039
+ <p className="text-sub m-0 mb-4 text-[13.5px] leading-[1.55]">
3040
+ {count} {count === 1 ? 'entry' : 'entries'} will be deleted forever, including notes and
3041
+ attribution. This can’t be undone.
3042
+ </p>
3043
+ <label htmlFor="et-i" className="text-sub mb-1.5 block text-[12.5px] font-medium">
3044
+ Type <b className="text-txt font-mono">DELETE</b> to confirm
3045
+ </label>
3046
+ <input
3047
+ id="et-i"
3048
+ ref={inputRef}
3049
+ value={value}
3050
+ onChange={(event) => setValue(event.target.value)}
3051
+ autoComplete="off"
3052
+ onKeyDown={(event) => {
3053
+ if (event.key === 'Enter' && value === 'DELETE') onConfirm()
3054
+ }}
3055
+ className="border-bdr bg-card text-txt focus:border-acc focus:outline-acc box-border h-9 w-full rounded-[8px] border px-2.5 font-[inherit] text-[14px] focus:outline focus:outline-offset-1"
3056
+ />
3057
+ </Modal>
3058
+ )
3059
+ }