From 4308d26cf0120024efce857c0037e35964da4b86 Mon Sep 17 00:00:00 2001 From: Tommaso Casaburi Date: Tue, 9 Jun 2026 13:01:31 +0700 Subject: [PATCH] fix(mod-queue): show empty state instead of not-allowed redirect When the account moderates no boards, render ModEmptyState on the global /mod/queue route instead of sending users to /not-allowed. --- src/__tests__/app.test.tsx | 17 ++++++++++++++--- src/app.tsx | 3 ++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/__tests__/app.test.tsx b/src/__tests__/app.test.tsx index 2a0b14b3..eecefbe1 100644 --- a/src/__tests__/app.test.tsx +++ b/src/__tests__/app.test.tsx @@ -114,6 +114,13 @@ vi.mock('../lib/utils/preload-utils', () => ({ resolveAssetUrl: (path: string) => path, })); +vi.mock('react-i18next', () => ({ + Trans: ({ components, i18nKey }: { components?: Record; i18nKey: string }) => createElement(React.Fragment, {}, i18nKey, components?.[1]), + useTranslation: () => ({ + t: (key: string) => key, + }), +})); + function makeNamedComponent(name: string) { return () => createElement('div', { 'data-testid': name }, name); } @@ -473,7 +480,7 @@ describe('App', () => { expect(container.querySelector('[data-testid="not-found-view"]')).toBeTruthy(); }); - it('allows the global mod queue only when the account moderates at least one board', async () => { + it('shows the mod empty state from the global mod queue when the account moderates no boards', async () => { testState.accountCommunityAddresses = ['music-posting.eth']; await renderApp('/mod/queue'); @@ -486,8 +493,12 @@ describe('App', () => { testState.accountCommunityAddresses = []; await renderApp('/mod/queue'); - expect(latestLocation).toBe('/not-allowed'); - expect(container.querySelector('[data-testid="not-allowed-view"]')).toBeTruthy(); + expect(latestLocation).toBe('/mod/queue'); + expect(container.textContent).toContain('not_mod_of_any_board'); + expect(container.textContent).toContain('go_to_settings_to_import_mod_account'); + expect(container.querySelector('output')?.className).toContain('modEmptyState'); + expect(container.querySelector('output a')?.getAttribute('href')).toBe('/mod/settings#account-settings'); + expect(container.querySelector('[data-testid="not-allowed-view"]')).toBeNull(); }); it('renders board archive routes and hides board form/buttons on that dedicated page', async () => { diff --git a/src/app.tsx b/src/app.tsx index e53fc89f..05c74f46 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -52,6 +52,7 @@ import PostForm from './components/post-form/post-form'; import BoardBlotter from './components/board-blotter/board-blotter'; import BoardsBar from './components/boards-bar/boards-bar'; import ExternalQuoteStatus from './components/external-quote-status/external-quote-status'; +import ModEmptyState from './components/mod-empty-state/mod-empty-state'; const AccountDataEditor = lazy(() => import('./views/account-data-editor')); const BoardsBarEditModal = lazy(() => import('./components/boards-bar-edit-modal')); @@ -265,7 +266,7 @@ const ModQueueRoute = () => { } if (!boardIdentifier) { - return accountCommunityAddresses.length > 0 ? : ; + return accountCommunityAddresses.length > 0 ? : ; } // Wait for board role metadata before enforcing access to avoid false redirects during initial load.