refactor(demo): the account tab and its phone screen share one demo lock

Both views had grown the same lock line in front of the same settings destructuring, which made the two a copy.
This commit is contained in:
Maurice
2026-10-24 23:22:10 +00:00
parent 9c83386655
commit 5596355141
5 changed files with 74 additions and 13 deletions
+2 -3
View File
@@ -665,21 +665,20 @@
"feature": "Settings / Demo account locks",
"hooks": ["src/components/Demo/useDemoLock.ts"],
"desktop": [
"src/components/Settings/AccountTab.tsx",
"src/components/Settings/AccountDemoLock.tsx",
"src/components/Settings/DisplaySettingsTab.tsx",
"src/components/Settings/IntegrationsTab.tsx",
"src/components/Settings/ai/AiConnectionSection.tsx"
],
"mobile": [
"src/mobile/screens/settings/MAiConnectionSection.tsx",
"src/mobile/screens/settings/MSettingsAccount.tsx",
"src/mobile/screens/settings/MSettingsGeneral.tsx",
"src/mobile/screens/settings/MSettingsMcp.tsx"
]
},
{
"feature": "Settings / Account",
"hooks": ["src/components/Settings/useAccountSettings.ts"],
"hooks": ["src/components/Settings/AccountDemoLock.tsx", "src/components/Settings/useAccountSettings.ts"],
"desktop": ["src/components/Settings/AccountTab.tsx"],
"mobile": ["src/mobile/screens/settings/MSettingsAccount.tsx"]
},
@@ -0,0 +1,43 @@
import { beforeEach, describe, expect, it } from 'vitest';
import { buildUser } from '../../../tests/helpers/factories';
import { render, screen } from '../../../tests/helpers/render';
import { resetAllStores, seedStore } from '../../../tests/helpers/store';
import { useAuthStore } from '../../store/authStore';
import AccountDemoLock from './AccountDemoLock';
beforeEach(() => resetAllStores());
function renderCards() {
return render(
<AccountDemoLock>
<button type="button">Save profile</button>
</AccountDemoLock>
);
}
describe('AccountDemoLock', () => {
it('FE-COMP-ACCOUNTDEMOLOCK-001: the shared demo account sees its cards under the lock, with the reason', () => {
seedStore(useAuthStore, { demoMode: true, user: buildUser({ email: 'demo@trek.app' }) });
const { container } = renderCards();
expect(screen.getByRole('note')).toHaveTextContent('The shared demo account cannot be changed.');
expect(screen.queryByRole('button', { name: 'Save profile' })).not.toBeInTheDocument();
expect(container.querySelector('[data-demo-lock] [inert]')).toContainElement(
screen.getByRole('button', { hidden: true, name: 'Save profile' })
);
});
it('FE-COMP-ACCOUNTDEMOLOCK-002: the admin of a demo instance gets the cards as they are', () => {
seedStore(useAuthStore, { demoMode: true, user: buildUser({ email: 'admin@trek.app', role: 'admin' }) });
const { container } = renderCards();
expect(screen.queryByRole('note')).not.toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Save profile' })).toBeEnabled();
expect(container.querySelector('[data-demo-lock]')).toBeNull();
});
it('FE-COMP-ACCOUNTDEMOLOCK-003: the demo address on an instance that is not a demo is left alone', () => {
seedStore(useAuthStore, { demoMode: false, user: buildUser({ email: 'demo@trek.app' }) });
renderCards();
expect(screen.queryByRole('note')).not.toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Save profile' })).toBeEnabled();
});
});
@@ -0,0 +1,23 @@
import type { ReactNode } from 'react';
import { useTranslation } from '../../i18n';
import DemoLock from '../Demo/DemoLock';
import { useDemoAccountLock } from '../Demo/useDemoLock';
/**
* The account cards under the demo lock, on the desktop tab and the phone
* screen alike. Every visitor of a demo instance signs in as the one shared
* demo account, so its profile, password, two factor setup and passkeys stay
* on view but out of reach, while the admin of a demo instance and every
* account of a real one get the cards as they are. Both views wrap their
* cards in this, so whom the lock holds and the reason it gives are written
* once.
*/
export default function AccountDemoLock({ children }: { children: ReactNode }) {
const { t } = useTranslation();
const locked = useDemoAccountLock();
return (
<DemoLock locked={locked} reason={t('demo.lock.account')}>
{children}
</DemoLock>
);
}
@@ -12,8 +12,7 @@ import {
SETTINGS_BUTTON, SETTINGS_BUTTON_DANGER, SETTINGS_BUTTON_PRIMARY, SettingRow, SettingRows, SettingsHint, StatusPill,
} from './settingsKit'
import { stripTrailingSlashes, useAccountSettings } from './useAccountSettings'
import DemoLock from '../Demo/DemoLock'
import { useDemoAccountLock } from '../Demo/useDemoLock'
import AccountDemoLock from './AccountDemoLock'
/** The small turning ring a button shows while its request is on the way. */
const SPINNER = 'h-3.5 w-3.5 flex-none animate-spin rounded-full border-2 border-current border-t-transparent'
@@ -24,7 +23,6 @@ const EYEBROW = 'm-0 font-geist font-bold uppercase tracking-[.08em] text-conten
export default function AccountTab(): React.ReactElement {
const { t } = useTranslation()
const blockedLabelId = useId()
const demoLocked = useDemoAccountLock()
const {
user,
demoMode,
@@ -75,7 +73,7 @@ export default function AccountTab(): React.ReactElement {
return (
<>
{/* The shared demo account: everything here is shown, nothing can be changed. */}
<DemoLock locked={demoLocked} reason={t('demo.lock.account')}>
<AccountDemoLock>
<Section title={t('settings.account')} icon={User}>
{/* Who is signed in: the picture with its two actions, the role and the SSO link. */}
<div className="flex items-center gap-4 rounded-[14px] border border-edge-faint bg-surface-card px-4 py-3.5">
@@ -364,7 +362,7 @@ export default function AccountTab(): React.ReactElement {
{/* Passkeys */}
<PasskeysSection demoMode={demoMode} />
</DemoLock>
</AccountDemoLock>
{/* Delete Account Blocked */}
<DialogShell
@@ -22,8 +22,7 @@ import MConfirmSheet from './MConfirmSheet'
import PasswordChecklist from '../../../components/shared/PasswordChecklist'
import { fmtDate, usePasskeys } from '../../../components/Settings/usePasskeys'
import { stripTrailingSlashes, useAccountSettings } from '../../../components/Settings/useAccountSettings'
import DemoLock from '../../../components/Demo/DemoLock'
import { useDemoAccountLock } from '../../../components/Demo/useDemoLock'
import AccountDemoLock from '../../../components/Settings/AccountDemoLock'
/**
* "Account" section — AccountTab parity: profile + avatar, password change,
@@ -31,7 +30,6 @@ import { useDemoAccountLock } from '../../../components/Demo/useDemoLock'
*/
export default function MSettingsAccount() {
const { t } = useTranslation()
const demoLocked = useDemoAccountLock()
const {
user,
demoMode,
@@ -82,7 +80,7 @@ export default function MSettingsAccount() {
return (
<>
{/* The shared demo account: everything here is shown, nothing can be changed. */}
<DemoLock locked={demoLocked} reason={t('demo.lock.account')}>
<AccountDemoLock>
{/* ── Profile ─────────────────────────────────────────────── */}
<MSetCard title={t('settings.account')} icon={User}>
<div className="mb-4 flex items-center gap-4">
@@ -293,7 +291,7 @@ export default function MSettingsAccount() {
</MSetCard>
<MPasskeysCard demoMode={demoMode} />
</DemoLock>
</AccountDemoLock>
<MConfirmSheet
open={showDeleteConfirm === 'blocked'}