@prenta/admin 2.17.0 → 2.17.2

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 (71) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/dist/AdminRoot.d.ts.map +1 -1
  3. package/dist/AdminRoot.js +8 -0
  4. package/dist/AdminRoot.js.map +1 -1
  5. package/dist/__tests__/components/attribution-rows.test.js +12 -3
  6. package/dist/__tests__/components/attribution-rows.test.js.map +1 -1
  7. package/dist/__tests__/components/schedule-publish-dialog.render.test.d.ts +2 -0
  8. package/dist/__tests__/components/schedule-publish-dialog.render.test.d.ts.map +1 -0
  9. package/dist/__tests__/components/schedule-publish-dialog.render.test.js +78 -0
  10. package/dist/__tests__/components/schedule-publish-dialog.render.test.js.map +1 -0
  11. package/dist/__tests__/layout/shell-nav.render.test.js +106 -27
  12. package/dist/__tests__/layout/shell-nav.render.test.js.map +1 -1
  13. package/dist/__tests__/test-env-storage.test.d.ts +2 -0
  14. package/dist/__tests__/test-env-storage.test.d.ts.map +1 -0
  15. package/dist/__tests__/test-env-storage.test.js +28 -0
  16. package/dist/__tests__/test-env-storage.test.js.map +1 -0
  17. package/dist/__tests__/views/account-setup-gate.render.test.d.ts +2 -0
  18. package/dist/__tests__/views/account-setup-gate.render.test.d.ts.map +1 -0
  19. package/dist/__tests__/views/account-setup-gate.render.test.js +103 -0
  20. package/dist/__tests__/views/account-setup-gate.render.test.js.map +1 -0
  21. package/dist/__tests__/views/login-mfa.render.test.js +33 -0
  22. package/dist/__tests__/views/login-mfa.render.test.js.map +1 -1
  23. package/dist/components/SchedulePublishDialog.d.ts +7 -1
  24. package/dist/components/SchedulePublishDialog.d.ts.map +1 -1
  25. package/dist/components/SchedulePublishDialog.js +6 -5
  26. package/dist/components/SchedulePublishDialog.js.map +1 -1
  27. package/dist/layout/MobileTabBar.d.ts +7 -4
  28. package/dist/layout/MobileTabBar.d.ts.map +1 -1
  29. package/dist/layout/MobileTabBar.js +41 -17
  30. package/dist/layout/MobileTabBar.js.map +1 -1
  31. package/dist/lib/entry-attribution.d.ts.map +1 -1
  32. package/dist/lib/entry-attribution.js +6 -4
  33. package/dist/lib/entry-attribution.js.map +1 -1
  34. package/dist/prenta-admin.css +1 -1
  35. package/dist/views/AccountSetupGate.d.ts +17 -0
  36. package/dist/views/AccountSetupGate.d.ts.map +1 -0
  37. package/dist/views/AccountSetupGate.js +69 -0
  38. package/dist/views/AccountSetupGate.js.map +1 -0
  39. package/dist/views/DocumentEdit.d.ts.map +1 -1
  40. package/dist/views/DocumentEdit.js +1 -1
  41. package/dist/views/DocumentEdit.js.map +1 -1
  42. package/dist/views/Login.d.ts.map +1 -1
  43. package/dist/views/Login.js +50 -2
  44. package/dist/views/Login.js.map +1 -1
  45. package/dist/views/page-editor/PageSectionEditor.d.ts.map +1 -1
  46. package/dist/views/page-editor/PageSectionEditor.js +1 -1
  47. package/dist/views/page-editor/PageSectionEditor.js.map +1 -1
  48. package/dist/views/post-editor/PostSectionEditor.d.ts.map +1 -1
  49. package/dist/views/post-editor/PostSectionEditor.js +1 -1
  50. package/dist/views/post-editor/PostSectionEditor.js.map +1 -1
  51. package/dist/views/profile/AccountSecurity.d.ts +5 -1
  52. package/dist/views/profile/AccountSecurity.d.ts.map +1 -1
  53. package/dist/views/profile/AccountSecurity.js +2 -1
  54. package/dist/views/profile/AccountSecurity.js.map +1 -1
  55. package/package.json +6 -6
  56. package/src/AdminRoot.tsx +15 -0
  57. package/src/__tests__/components/attribution-rows.test.ts +13 -3
  58. package/src/__tests__/components/schedule-publish-dialog.render.test.tsx +100 -0
  59. package/src/__tests__/layout/shell-nav.render.test.tsx +181 -29
  60. package/src/__tests__/test-env-storage.test.ts +28 -0
  61. package/src/__tests__/views/account-setup-gate.render.test.tsx +122 -0
  62. package/src/__tests__/views/login-mfa.render.test.tsx +42 -0
  63. package/src/components/SchedulePublishDialog.tsx +15 -4
  64. package/src/layout/MobileTabBar.tsx +57 -28
  65. package/src/lib/entry-attribution.ts +6 -4
  66. package/src/views/AccountSetupGate.tsx +198 -0
  67. package/src/views/DocumentEdit.tsx +1 -0
  68. package/src/views/Login.tsx +54 -2
  69. package/src/views/page-editor/PageSectionEditor.tsx +1 -0
  70. package/src/views/post-editor/PostSectionEditor.tsx +1 -0
  71. package/src/views/profile/AccountSecurity.tsx +7 -1
@@ -257,7 +257,177 @@ describe('Forms third level', () => {
257
257
  })
258
258
 
259
259
  describe('MobileTabBar', () => {
260
- it('shows one tab per kit destination plus More, and leaves extras to the drawer', () => {
260
+ const fullNav = () =>
261
+ applyFormsNav(
262
+ buildNavItems({
263
+ collections: {
264
+ pages: { slug: 'pages', type: 'page' },
265
+ blog: { slug: 'blog', type: 'post' },
266
+ faqs: { slug: 'faqs', labels: { plural: 'FAQs' } },
267
+ team: { slug: 'team', admin: { group: 'People' } },
268
+ },
269
+ _pluginNavItems: [{ label: 'Redirects', path: '/redirects' }],
270
+ }),
271
+ [
272
+ { formId: 'f1', name: 'Contact Us', slug: 'contact-us', status: 'active', unread: 3 },
273
+ ] as never,
274
+ )
275
+
276
+ const barLabels = (bar: HTMLElement) =>
277
+ within(bar)
278
+ .getAllByRole('button')
279
+ .map((b) => b.textContent)
280
+
281
+ it('shows four tabs and pins More last, with no sideways scroller (#1200)', () => {
282
+ render(
283
+ <MobileTabBar
284
+ items={fullNav()}
285
+ currentPath="/"
286
+ onNavigate={vi.fn()}
287
+ onMore={vi.fn()}
288
+ moreOpen={false}
289
+ />,
290
+ )
291
+ const bar = screen.getByRole('navigation', { name: 'Tab bar' })
292
+ const labels = barLabels(bar)
293
+ expect(labels.length).toBeLessThanOrEqual(5)
294
+ expect(labels).toEqual(['Dashboard', 'Pages', 'Posts', 'Appearance', 'More3'])
295
+ expect(labels.at(-1)).toMatch(/^More/)
296
+ // Nothing in the bar scrolls or hides its scrollbar.
297
+ for (const el of [bar, ...bar.querySelectorAll<HTMLElement>('*')]) {
298
+ expect(el.className).not.toMatch(/overflow-x-(auto|scroll)|scrollbar/)
299
+ }
300
+ })
301
+
302
+ it.each([
303
+ ['/media', 'Media'],
304
+ ['/forms/entries', 'Forms'],
305
+ ['/seo?tab=audit', 'SEO'],
306
+ ['/script-tags', 'Script Tags'],
307
+ ['/jobs', 'Jobs'],
308
+ ['/settings?tab=security', 'Settings'],
309
+ ['/faqs/abc', 'FAQs'],
310
+ ['/team', 'team'],
311
+ ['/redirects', 'Redirects'],
312
+ ])('marks More active on %s, a page behind More', (currentPath) => {
313
+ render(
314
+ <MobileTabBar
315
+ items={fullNav()}
316
+ currentPath={currentPath}
317
+ onNavigate={vi.fn()}
318
+ onMore={vi.fn()}
319
+ moreOpen={false}
320
+ />,
321
+ )
322
+ const bar = screen.getByRole('navigation', { name: 'Tab bar' })
323
+ const more = within(bar).getByRole('button', { name: /^More/ })
324
+ expect(more.getAttribute('aria-current')).toBe('page')
325
+ expect(more.className).toContain('bg-acc-l')
326
+ expect(
327
+ within(bar)
328
+ .getAllByRole('button')
329
+ .filter((b) => b.hasAttribute('aria-current')),
330
+ ).toEqual([more])
331
+ })
332
+
333
+ it('totals the unread badges of destinations behind More on More', () => {
334
+ const items = fullNav()
335
+ const withSeoBadge = items.map((item) => (item.label === 'SEO' ? { ...item, badge: 2 } : item))
336
+ const { rerender } = render(
337
+ <MobileTabBar
338
+ items={items}
339
+ currentPath="/"
340
+ onNavigate={vi.fn()}
341
+ onMore={vi.fn()}
342
+ moreOpen={false}
343
+ />,
344
+ )
345
+ const bar = screen.getByRole('navigation', { name: 'Tab bar' })
346
+ // Forms (3 unread) sits behind More, so More carries its count.
347
+ expect(within(bar).getByRole('button', { name: /^More/ }).textContent).toBe('More3')
348
+ expect(within(bar).getByLabelText('3 unread')).toBeTruthy()
349
+ rerender(
350
+ <MobileTabBar
351
+ items={withSeoBadge}
352
+ currentPath="/"
353
+ onNavigate={vi.fn()}
354
+ onMore={vi.fn()}
355
+ moreOpen={false}
356
+ />,
357
+ )
358
+ expect(within(bar).getByLabelText('5 unread')).toBeTruthy()
359
+ })
360
+
361
+ it('shows no More badge when nothing behind More is unread', () => {
362
+ render(
363
+ <MobileTabBar
364
+ items={buildNavItems({ collections: { pages: { slug: 'pages', type: 'page' } } })}
365
+ currentPath="/"
366
+ onNavigate={vi.fn()}
367
+ onMore={vi.fn()}
368
+ moreOpen={false}
369
+ />,
370
+ )
371
+ const bar = screen.getByRole('navigation', { name: 'Tab bar' })
372
+ expect(within(bar).getByRole('button', { name: 'More' }).textContent).toBe('More')
373
+ expect(within(bar).queryByLabelText(/unread/)).toBeNull()
374
+ })
375
+
376
+ it('leaves More inactive on a page that has its own tab', () => {
377
+ render(
378
+ <MobileTabBar
379
+ items={fullNav()}
380
+ currentPath="/posts/types"
381
+ onNavigate={vi.fn()}
382
+ onMore={vi.fn()}
383
+ moreOpen={false}
384
+ />,
385
+ )
386
+ const bar = screen.getByRole('navigation', { name: 'Tab bar' })
387
+ expect(within(bar).getByRole('button', { name: /^More/ }).hasAttribute('aria-current')).toBe(
388
+ false,
389
+ )
390
+ expect(within(bar).getByRole('button', { name: 'Posts' }).getAttribute('aria-current')).toBe(
391
+ 'page',
392
+ )
393
+ })
394
+
395
+ it('reaches every nav destination from the bar or the drawer behind More', async () => {
396
+ stubWidth(390)
397
+ const config = {
398
+ collections: {
399
+ pages: { slug: 'pages', type: 'page' },
400
+ blog: { slug: 'blog', type: 'post' },
401
+ faqs: { slug: 'faqs', labels: { plural: 'FAQs' } },
402
+ team: { slug: 'team', admin: { group: 'People' } },
403
+ },
404
+ _pluginNavItems: [{ label: 'Redirects', path: '/redirects' }],
405
+ }
406
+ render(
407
+ <Layout config={config} session={null} currentPath="/" onNavigate={vi.fn()}>
408
+ Body
409
+ </Layout>,
410
+ )
411
+ const bar = await screen.findByRole('navigation', { name: 'Tab bar' })
412
+ const inBar = barLabels(bar)
413
+ fireEvent.click(within(bar).getByRole('button', { name: /^More/ }))
414
+ const drawer = await screen.findByRole('dialog', { name: 'Navigation' })
415
+ const drawerText = drawer.textContent ?? ''
416
+ const destinations = buildNavItems(config).map((item) => item.label)
417
+ expect(destinations).toEqual(
418
+ expect.arrayContaining(['Media', 'Forms', 'SEO', 'Jobs', 'Settings', 'FAQs', 'Redirects']),
419
+ )
420
+ for (const label of destinations) {
421
+ const reachable = inBar.includes(label) || drawerText.includes(label)
422
+ expect(reachable, `${label} is in neither the bar nor the drawer`).toBe(true)
423
+ }
424
+ // Everything the bar leaves out is in the drawer.
425
+ for (const label of destinations.filter((l) => !inBar.includes(l))) {
426
+ expect(within(drawer).getAllByText(label).length).toBeGreaterThan(0)
427
+ }
428
+ })
429
+
430
+ it('marks the active tab and opens the drawer from More', () => {
261
431
  const items = applyFormsNav(
262
432
  buildNavItems({
263
433
  collections: {
@@ -275,38 +445,20 @@ describe('MobileTabBar', () => {
275
445
  render(
276
446
  <MobileTabBar
277
447
  items={items}
278
- currentPath="/forms/entries"
448
+ currentPath="/pages/trash"
279
449
  onNavigate={onNavigate}
280
450
  onMore={onMore}
281
451
  moreOpen={false}
282
452
  />,
283
453
  )
284
454
  const bar = screen.getByRole('navigation', { name: 'Tab bar' })
285
- const tabs = within(bar)
286
- .getAllByRole('button')
287
- .map((b) => b.textContent)
288
- expect(tabs).toEqual([
289
- 'Dashboard',
290
- 'Pages',
291
- 'Posts',
292
- 'Appearance',
293
- 'Media',
294
- 'Forms3',
295
- 'SEO',
296
- 'Script Tags',
297
- 'Jobs',
298
- 'Settings',
299
- 'More',
300
- ])
301
455
  // A child page marks its parent tab.
302
- expect(
303
- within(bar)
304
- .getByRole('button', { name: /^Forms/ })
305
- .getAttribute('aria-current'),
306
- ).toBe('page')
456
+ expect(within(bar).getByRole('button', { name: 'Pages' }).getAttribute('aria-current')).toBe(
457
+ 'page',
458
+ )
307
459
  fireEvent.click(within(bar).getByRole('button', { name: 'Pages' }))
308
460
  expect(onNavigate).toHaveBeenCalledWith('/pages')
309
- const more = within(bar).getByRole('button', { name: 'More' })
461
+ const more = within(bar).getByRole('button', { name: /^More/ })
310
462
  expect(more.getAttribute('aria-expanded')).toBe('false')
311
463
  fireEvent.click(more)
312
464
  expect(onMore).toHaveBeenCalledOnce()
@@ -500,7 +652,7 @@ describe('P-02 review fixes', () => {
500
652
  expect(tab.className).toContain('min-h-11')
501
653
  expect(tab.className).toContain('min-w-[60px]')
502
654
  }
503
- expect(within(bar).getByRole('button', { name: 'More' }).getAttribute('aria-controls')).toBe(
655
+ expect(within(bar).getByRole('button', { name: /^More/ }).getAttribute('aria-controls')).toBe(
504
656
  'drawer',
505
657
  )
506
658
  // Below every overlay layer, and clear of the home indicator.
@@ -532,7 +684,7 @@ describe('P-02 review fixes', () => {
532
684
  </AdminShell>
533
685
  )
534
686
  const { rerender } = render(shell(false))
535
- const more = await screen.findByRole('button', { name: 'More' })
687
+ const more = await screen.findByRole('button', { name: /^More/ })
536
688
  expect(screen.queryByRole('dialog')).toBeNull()
537
689
  more.focus()
538
690
 
@@ -584,7 +736,7 @@ describe('P-02 review fixes', () => {
584
736
  </Layout>,
585
737
  )
586
738
  const bar = await screen.findByRole('navigation', { name: 'Tab bar' })
587
- const more = within(bar).getByRole('button', { name: 'More' })
739
+ const more = within(bar).getByRole('button', { name: /^More/ })
588
740
  expect(more.getAttribute('aria-controls')).toBe(DRAWER_ID)
589
741
  more.focus()
590
742
  fireEvent.click(more)
@@ -742,14 +894,14 @@ describe('P-02 third review', () => {
742
894
  </Layout>,
743
895
  )
744
896
  const bar = await screen.findByRole('navigation', { name: 'Tab bar' })
745
- fireEvent.click(within(bar).getByRole('button', { name: 'More' }))
897
+ fireEvent.click(within(bar).getByRole('button', { name: /^More/ }))
746
898
  await screen.findByRole('dialog', { name: 'Navigation' })
747
899
  resize(1280)
748
900
  expect(screen.queryByRole('dialog')).toBeNull()
749
901
  resize(600)
750
902
  const again = await screen.findByRole('navigation', { name: 'Tab bar' })
751
903
  expect(screen.queryByRole('dialog')).toBeNull()
752
- expect(within(again).getByRole('button', { name: 'More' }).getAttribute('aria-expanded')).toBe(
904
+ expect(within(again).getByRole('button', { name: /^More/ }).getAttribute('aria-expanded')).toBe(
753
905
  'false',
754
906
  )
755
907
  })
@@ -0,0 +1,28 @@
1
+ // @vitest-environment happy-dom
2
+ /**
3
+ * Guard for the test environment, not for product code.
4
+ *
5
+ * On Node 25+, Node's own `localStorage` global (undefined unless the process
6
+ * gets --localstorage-file) shadows happy-dom's Storage, so every storage test
7
+ * silently runs against nothing. vitest.config.ts turns Node's implementation
8
+ * off with `execArgv: ['--no-experimental-webstorage']`. If that stops
9
+ * working, this file fails first, instead of a storage test passing for the
10
+ * wrong reason or failing somewhere unrelated.
11
+ */
12
+ import { describe, expect, it } from 'vitest'
13
+
14
+ describe.each([
15
+ ['localStorage', () => globalThis.localStorage],
16
+ ['sessionStorage', () => globalThis.sessionStorage],
17
+ ] as const)('%s in a happy-dom test', (name, getStorage) => {
18
+ it('is happy-dom’s working Storage', () => {
19
+ const storage = getStorage()
20
+ expect(storage).toBeDefined()
21
+ expect(storage).toBe(window[name])
22
+ storage.setItem('prenta:test-env-guard', 'ok')
23
+ expect(storage.getItem('prenta:test-env-guard')).toBe('ok')
24
+ expect(storage.length).toBeGreaterThan(0)
25
+ storage.removeItem('prenta:test-env-guard')
26
+ expect(storage.getItem('prenta:test-env-guard')).toBeNull()
27
+ })
28
+ })
@@ -0,0 +1,122 @@
1
+ // @vitest-environment happy-dom
2
+ import { afterEach, describe, expect, it, vi } from 'vitest'
3
+ import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
4
+
5
+ let passwordError: string | null = null
6
+ const cmsApi = vi.fn(async (path: string, _init?: RequestInit) => {
7
+ if (path === '/auth/password' && passwordError) return { error: passwordError, status: 401 }
8
+ if (path === '/auth/me') return { data: { totpEnabled: false }, status: 200 }
9
+ return { data: { docs: [] }, status: 200 }
10
+ })
11
+ vi.mock('../../lib/api.js', () => ({
12
+ cmsApi: (path: string, init?: RequestInit) => cmsApi(path, init),
13
+ ensureCsrfToken: vi.fn(async () => undefined),
14
+ setApiBase: vi.fn(),
15
+ getApiBase: () => '',
16
+ }))
17
+
18
+ const storage = new Map<string, string>()
19
+ vi.stubGlobal('localStorage', {
20
+ getItem: (key: string) => storage.get(key) ?? null,
21
+ setItem: (key: string, value: string) => void storage.set(key, String(value)),
22
+ removeItem: (key: string) => void storage.delete(key),
23
+ clear: () => storage.clear(),
24
+ })
25
+
26
+ const { AdminRoot } = await import('../../AdminRoot.js')
27
+ const { AccountSetupGate } = await import('../../views/AccountSetupGate.js')
28
+
29
+ afterEach(() => {
30
+ cleanup()
31
+ cmsApi.mockClear()
32
+ passwordError = null
33
+ window.history.replaceState({}, '', '/')
34
+ })
35
+
36
+ const user = (restricted?: string) => ({
37
+ user: {
38
+ id: 'u1',
39
+ email: 'flagged@site.test',
40
+ role: 'ADMIN',
41
+ ...(restricted ? { restricted } : {}),
42
+ },
43
+ })
44
+
45
+ describe('AdminRoot with a restricted session (#1254)', () => {
46
+ it('shows only the change-password step for password_reset', async () => {
47
+ render(<AdminRoot config={{}} session={user('password_reset')} initialPath="/" />)
48
+ expect(await screen.findByRole('heading', { name: 'Change your password' })).toBeTruthy()
49
+ expect(screen.queryByRole('navigation', { name: 'Breadcrumb' })).toBeNull()
50
+ })
51
+
52
+ it('shows the MFA setup step for mfa_setup', async () => {
53
+ render(<AdminRoot config={{}} session={user('mfa_setup')} initialPath="/" />)
54
+ expect(
55
+ await screen.findByRole('heading', { name: 'Set up two-factor authentication' }),
56
+ ).toBeTruthy()
57
+ })
58
+
59
+ it('renders the normal admin for an unrestricted session', async () => {
60
+ render(<AdminRoot config={{}} session={user()} initialPath="/" />)
61
+ await waitFor(() =>
62
+ expect(screen.queryByRole('heading', { name: 'Change your password' })).toBeNull(),
63
+ )
64
+ })
65
+ })
66
+
67
+ describe('AccountSetupGate change-password form', () => {
68
+ it('posts the passwords to /auth/password and completes', async () => {
69
+ const onComplete = vi.fn()
70
+ render(
71
+ <AccountSetupGate restriction="password_reset" onComplete={onComplete} onLogout={vi.fn()} />,
72
+ )
73
+ fireEvent.change(screen.getByLabelText('Current password'), { target: { value: 'old-pass' } })
74
+ fireEvent.change(screen.getByLabelText('New password'), {
75
+ target: { value: 'New-Strong-Passw0rd' },
76
+ })
77
+ fireEvent.change(screen.getByLabelText('Confirm new password'), {
78
+ target: { value: 'New-Strong-Passw0rd' },
79
+ })
80
+ fireEvent.click(screen.getByRole('button', { name: 'Change password' }))
81
+
82
+ await waitFor(() => expect(onComplete).toHaveBeenCalledOnce())
83
+ const call = cmsApi.mock.calls.find(([p]) => p === '/auth/password')!
84
+ expect(JSON.parse(String(call[1]!.body))).toEqual({
85
+ currentPassword: 'old-pass',
86
+ newPassword: 'New-Strong-Passw0rd',
87
+ })
88
+ })
89
+
90
+ it('refuses mismatched new passwords without calling the API', async () => {
91
+ const onComplete = vi.fn()
92
+ render(
93
+ <AccountSetupGate restriction="password_reset" onComplete={onComplete} onLogout={vi.fn()} />,
94
+ )
95
+ fireEvent.change(screen.getByLabelText('Current password'), { target: { value: 'old-pass' } })
96
+ fireEvent.change(screen.getByLabelText('New password'), { target: { value: 'one-password' } })
97
+ fireEvent.change(screen.getByLabelText('Confirm new password'), {
98
+ target: { value: 'two-password' },
99
+ })
100
+ fireEvent.click(screen.getByRole('button', { name: 'Change password' }))
101
+
102
+ expect(await screen.findByText('The new passwords do not match.')).toBeTruthy()
103
+ expect(cmsApi.mock.calls.some(([p]) => p === '/auth/password')).toBe(false)
104
+ expect(onComplete).not.toHaveBeenCalled()
105
+ })
106
+
107
+ it('shows the server error and stays on the step', async () => {
108
+ passwordError = 'Current password is incorrect.'
109
+ const onComplete = vi.fn()
110
+ render(
111
+ <AccountSetupGate restriction="password_reset" onComplete={onComplete} onLogout={vi.fn()} />,
112
+ )
113
+ fireEvent.change(screen.getByLabelText('Current password'), { target: { value: 'wrong' } })
114
+ fireEvent.change(screen.getByLabelText('New password'), { target: { value: 'Abcdefgh1234' } })
115
+ fireEvent.change(screen.getByLabelText('Confirm new password'), {
116
+ target: { value: 'Abcdefgh1234' },
117
+ })
118
+ fireEvent.click(screen.getByRole('button', { name: 'Change password' }))
119
+ expect(await screen.findByText('Current password is incorrect.')).toBeTruthy()
120
+ expect(onComplete).not.toHaveBeenCalled()
121
+ })
122
+ })
@@ -93,3 +93,45 @@ describe('Login — MFA challenge', () => {
93
93
  expect(screen.queryByText('Two-factor authentication')).toBeNull()
94
94
  })
95
95
  })
96
+
97
+ describe('Login — arriving from an OAuth callback (#1251)', () => {
98
+ it('opens the code step on ?mfa=totp and verifies with the cookie-held token', async () => {
99
+ window.history.replaceState(null, '', '/admin?mfa=totp')
100
+ const onLogin = vi.fn()
101
+ const onVerifyTotp = vi.fn(async () => ({ success: true }))
102
+
103
+ render(<Login onLogin={onLogin} onVerifyTotp={onVerifyTotp} />)
104
+
105
+ await screen.findByText('Two-factor authentication')
106
+ expect(window.location.search).toBe('')
107
+
108
+ fireEvent.change(screen.getByLabelText('Authentication code'), { target: { value: '123456' } })
109
+ fireEvent.click(screen.getByRole('button', { name: 'Verify' }))
110
+
111
+ // Empty token: the server reads the HttpOnly prenta_mfa_pending cookie.
112
+ await waitFor(() => expect(onVerifyTotp).toHaveBeenCalledWith('', '123456'))
113
+ expect(onLogin).not.toHaveBeenCalled()
114
+ })
115
+
116
+ it('shows a known account-state error from ?error=', async () => {
117
+ window.history.replaceState(null, '', '/admin?error=Account%20is%20suspended')
118
+ render(<Login onLogin={vi.fn()} />)
119
+ await screen.findByText('Account is suspended')
120
+ expect(window.location.search).toBe('')
121
+ })
122
+
123
+ it('shows the fixed "no account" instruction from the callback', async () => {
124
+ const msg =
125
+ 'No account found for this email. Ask an administrator to invite you before signing in with OAuth.'
126
+ window.history.replaceState(null, '', `/admin?error=${encodeURIComponent(msg)}`)
127
+ render(<Login onLogin={vi.fn()} />)
128
+ await screen.findByText(msg)
129
+ })
130
+
131
+ it('replaces any other ?error= text with a generic line', async () => {
132
+ window.history.replaceState(null, '', '/admin?error=Call%20555-0100%20to%20unlock')
133
+ render(<Login onLogin={vi.fn()} />)
134
+ await screen.findByText('Sign-in with that provider did not complete. Try again.')
135
+ expect(screen.queryByText(/555-0100/)).toBeNull()
136
+ })
137
+ })
@@ -10,6 +10,12 @@ import { adminPortalContainer } from '../lib/portal-container.js'
10
10
  export interface SchedulePublishDialogProps {
11
11
  collectionSlug: string
12
12
  documentId: string
13
+ /**
14
+ * The document's current status. A live (PUBLISHED) document has nothing
15
+ * to publish, and the server refuses a publish time for it, so the dialog
16
+ * leaves the publish time empty and disabled and ticks the unpublish option.
17
+ */
18
+ status?: string
13
19
  /** Existing scheduled publish time, if any. */
14
20
  scheduledAt?: string | null
15
21
  /** Existing scheduled unpublish time, if any. */
@@ -47,6 +53,7 @@ function defaultScheduleTime(): string {
47
53
  export function SchedulePublishDialog({
48
54
  collectionSlug,
49
55
  documentId,
56
+ status,
50
57
  scheduledAt,
51
58
  scheduledUnpublishAt,
52
59
  open,
@@ -62,13 +69,16 @@ export function SchedulePublishDialog({
62
69
  const unpublishAtId = useId()
63
70
 
64
71
  const hasExistingSchedule = Boolean(scheduledAt || scheduledUnpublishAt)
72
+ const live = status === 'PUBLISHED'
65
73
 
66
74
  useEffect(() => {
67
75
  if (!open) return
68
- setPublishAt(scheduledAt ? toLocalDateTimeInput(scheduledAt) : defaultScheduleTime())
76
+ setPublishAt(
77
+ live ? '' : scheduledAt ? toLocalDateTimeInput(scheduledAt) : defaultScheduleTime(),
78
+ )
69
79
  setUnpublishAt(scheduledUnpublishAt ? toLocalDateTimeInput(scheduledUnpublishAt) : '')
70
- setIncludeUnpublish(Boolean(scheduledUnpublishAt))
71
- }, [open, scheduledAt, scheduledUnpublishAt])
80
+ setIncludeUnpublish(live || Boolean(scheduledUnpublishAt))
81
+ }, [open, live, scheduledAt, scheduledUnpublishAt])
72
82
 
73
83
  async function handleSave() {
74
84
  if (!publishAt && !(includeUnpublish && unpublishAt)) {
@@ -174,9 +184,10 @@ export function SchedulePublishDialog({
174
184
  id={publishAtId}
175
185
  type="datetime-local"
176
186
  value={publishAt}
187
+ disabled={live}
177
188
  onChange={(e) => setPublishAt(e.target.value)}
178
189
  min={toLocalDateTimeInput(new Date(Date.now() + 60 * 1000))}
179
- className="border-input bg-background text-foreground focus:border-ring focus:ring-ring w-full rounded-md border py-2 pr-3 pl-9 text-sm focus:ring-1 focus:outline-none"
190
+ className="border-input bg-background text-foreground focus:border-ring focus:ring-ring w-full rounded-md border py-2 pr-3 pl-9 text-sm focus:ring-1 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50"
180
191
  />
181
192
  </div>
182
193
  <p className="text-muted-foreground text-xs">
@@ -14,17 +14,51 @@ export interface MobileTabBarProps {
14
14
  drawerId?: string
15
15
  }
16
16
 
17
+ /**
18
+ * Tabs shown before More. Four plus More fit a 320px screen with every tab at
19
+ * the kit's 60px minimum, so the bar never scrolls sideways (issue #1200).
20
+ */
21
+ const PRIMARY_TAB_COUNT = 4
22
+
17
23
  // Kit tab (SHELL.md §2): icon over a 9px label, at least 60px wide. 44px tall
18
- // so every tab clears the touch target minimum.
24
+ // so every tab clears the touch target minimum. Tabs share the bar's width.
19
25
  const TAB =
20
- 'rounded-7 relative flex min-h-11 min-w-[60px] shrink-0 cursor-pointer flex-col items-center justify-center gap-[3px] border-0 px-1 py-1.5'
26
+ 'rounded-7 relative flex min-h-11 min-w-[60px] flex-1 basis-0 cursor-pointer flex-col items-center justify-center gap-[3px] border-0 px-1 py-1.5'
27
+
28
+ const TAB_ACTIVE =
29
+ 'bg-acc-l text-acc font-[550] forced-colors:outline-2 forced-colors:-outline-offset-2 forced-colors:outline-solid'
30
+ const TAB_IDLE = 'text-sub bg-transparent font-[450]'
31
+
32
+ /** Unread count at the icon's top right; nothing when there is none. */
33
+ function TabBadge({ count }: { count: number | undefined }) {
34
+ if (!count || count <= 0) return null
35
+ return (
36
+ <span
37
+ className="rounded-pill bg-err text-badge text-acc-on absolute top-0.5 left-[calc(50%+4px)] flex h-4 min-w-4 items-center justify-center px-1 leading-none font-bold tabular-nums"
38
+ aria-label={`${count} unread`}
39
+ >
40
+ {count > 99 ? '99+' : count}
41
+ </span>
42
+ )
43
+ }
44
+
45
+ function isTabActive(item: NavItem, currentPath: string): boolean {
46
+ return item.children?.length
47
+ ? isPathActive(currentPath, item.path) ||
48
+ hasActiveDescendant(item.children, currentPath) ||
49
+ currentPath.split(/[?#]/)[0]!.startsWith(item.path + '/')
50
+ : isPathActive(currentPath, item.path)
51
+ }
21
52
 
22
53
  /**
23
54
  * Mobile nav (≤768px, SHELL.md §2 and CONFLICTS.md §2 "mobile nav"): a fixed
24
- * 56px bottom bar that scrolls sideways, one tab per kit destination (icon over
25
- * a 9px label). Collection and plugin entries, sub-pages and Settings tabs
26
- * stay in the drawer, opened from the last tab, "More". It sits below every
27
- * overlay layer (`--z-tabbar`), so sheets and dialogs cover it.
55
+ * 56px bottom bar with the first four kit destinations (icon over a 9px
56
+ * label) and a last "More" tab, pinned, that opens the drawer. The drawer
57
+ * lists every destination, so the kit destinations past the first four,
58
+ * collection and plugin entries, sub-pages and Settings tabs are all reached
59
+ * from More, which shows as active while the current page is one of them and
60
+ * carries the total of their unread badges. It sits below every overlay layer
61
+ * (`--z-tabbar`), so sheets and dialogs cover it.
28
62
  */
29
63
  export function MobileTabBar({
30
64
  items,
@@ -34,20 +68,24 @@ export function MobileTabBar({
34
68
  moreOpen,
35
69
  drawerId,
36
70
  }: MobileTabBarProps) {
37
- const tabs = items.filter((item) => !item.extra)
71
+ const tabs = items.filter((item) => !item.extra).slice(0, PRIMARY_TAB_COUNT)
72
+ const hidden = items.filter((item) => !tabs.includes(item))
73
+ const tabActive = tabs.map((item) => isTabActive(item, currentPath))
74
+ const moreActive =
75
+ !tabActive.some(Boolean) && hidden.some((item) => isTabActive(item, currentPath))
76
+ // Unread counts of the destinations behind More (Forms entries, say), so a
77
+ // badge never disappears into the drawer. A top-level badge already totals
78
+ // its children's.
79
+ const moreBadge = hidden.reduce((sum, item) => sum + Math.max(item.badge ?? 0, 0), 0)
38
80
 
39
81
  return (
40
82
  <nav
41
83
  aria-label="Tab bar"
42
84
  className="bg-sb border-bdr shadow-tabbar fixed right-0 bottom-0 left-0 z-[var(--z-tabbar)] flex h-[calc(var(--tabbar-h)+env(safe-area-inset-bottom))] items-start border-t pb-[env(safe-area-inset-bottom)]"
43
85
  >
44
- <div className="flex h-[var(--tabbar-h)] w-full [scrollbar-width:none] flex-row items-center gap-0.5 overflow-x-auto overflow-y-hidden px-2 [&::-webkit-scrollbar]:hidden">
45
- {tabs.map((item) => {
46
- const active = item.children?.length
47
- ? isPathActive(currentPath, item.path) ||
48
- hasActiveDescendant(item.children, currentPath) ||
49
- currentPath.split(/[?#]/)[0]!.startsWith(item.path + '/')
50
- : isPathActive(currentPath, item.path)
86
+ <div className="flex h-[var(--tabbar-h)] w-full flex-row items-center px-2">
87
+ {tabs.map((item, index) => {
88
+ const active = tabActive[index]
51
89
  const Icon = item.icon
52
90
  return (
53
91
  <button
@@ -55,24 +93,13 @@ export function MobileTabBar({
55
93
  type="button"
56
94
  onClick={() => onNavigate(item.path)}
57
95
  aria-current={active ? 'page' : undefined}
58
- className={`${TAB} ${
59
- active
60
- ? 'bg-acc-l text-acc font-[550] forced-colors:outline-2 forced-colors:-outline-offset-2 forced-colors:outline-solid'
61
- : 'text-sub bg-transparent font-[450]'
62
- }`}
96
+ className={`${TAB} ${active ? TAB_ACTIVE : TAB_IDLE}`}
63
97
  >
64
98
  <Icon className="h-4 w-4 shrink-0" size={16} strokeWidth={1.75} aria-hidden />
65
99
  <span className="text-tab leading-[normal] tracking-[0.2px] whitespace-nowrap">
66
100
  {item.label}
67
101
  </span>
68
- {item.badge && item.badge > 0 ? (
69
- <span
70
- className="rounded-pill bg-err text-badge text-acc-on absolute top-0.5 left-[calc(50%+4px)] flex h-4 min-w-4 items-center justify-center px-1 leading-none font-bold tabular-nums"
71
- aria-label={`${item.badge} unread`}
72
- >
73
- {item.badge > 99 ? '99+' : item.badge}
74
- </span>
75
- ) : null}
102
+ <TabBadge count={item.badge} />
76
103
  </button>
77
104
  )
78
105
  })}
@@ -81,10 +108,12 @@ export function MobileTabBar({
81
108
  onClick={onMore}
82
109
  aria-expanded={moreOpen}
83
110
  aria-controls={drawerId}
84
- className={`${TAB} text-sub bg-transparent font-[450]`}
111
+ aria-current={moreActive ? 'page' : undefined}
112
+ className={`${TAB} ${moreActive ? TAB_ACTIVE : TAB_IDLE}`}
85
113
  >
86
114
  <Ellipsis className="h-4 w-4 shrink-0" strokeWidth={1.75} aria-hidden />
87
115
  <span className="text-tab leading-[normal] tracking-[0.2px] whitespace-nowrap">More</span>
116
+ <TabBadge count={moreBadge} />
88
117
  </button>
89
118
  </div>
90
119
  </nav>
@@ -115,8 +115,10 @@ export function getEntryAttributionSummary(entry: FormSubmission): AttributionSu
115
115
  ? 'search_organic'
116
116
  : 'direct'
117
117
  const meta = CHANNEL_META[channelKey] ?? CHANNEL_META.direct!
118
- const landingPage = attrString(blob, 'landingPage') || entry.pageUrl || '—'
119
- const referrer = attrString(blob, 'referrer') || entry.referrer || '(none)'
118
+ // `entry.referrer` is the request's Referer: the page the form was posted
119
+ // from, never the visitor's referrer (#1241). It can only stand in for the page.
120
+ const landingPage = attrString(blob, 'landingPage') || entry.pageUrl || entry.referrer || '—'
121
+ const referrer = attrString(blob, 'referrer') || '(none)'
120
122
  const deviceType = DEVICE_LABELS[attrString(blob, 'deviceType')] ?? ''
121
123
  const device = entry.userAgent || deviceType || '—'
122
124
  const ip = attrString(blob, 'ip') || entry.ipAddressHash || '—'
@@ -190,8 +192,8 @@ export function buildAttributionRows(entry: FormSubmission): AttributionRow[] {
190
192
  clickRow,
191
193
  ...filled([
192
194
  { label: 'Landing page', value: attrString(blob, 'landingPage') },
193
- { label: 'Page', value: entry.pageUrl },
194
- { label: 'Referrer', value: attrString(blob, 'referrer') || entry.referrer },
195
+ { label: 'Page', value: entry.pageUrl || entry.referrer },
196
+ { label: 'Referrer', value: attrString(blob, 'referrer') },
195
197
  { label: 'Device', value: DEVICE_LABELS[attrString(blob, 'deviceType')] ?? '' },
196
198
  { label: 'First touch', value: formatDateTime(attrString(blob, 'firstTouchAt')) },
197
199
  ]),