Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

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

Maurice559635514132
diff --git a/client/scripts/feature-pairs.json b/client/scripts/feature-pairs.json
index 2eb12b804..bcc35dc1b 100644
--- a/client/scripts/feature-pairs.json
+++ b/client/scripts/feature-pairs.json
@@ -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"]
},
diff --git a/client/src/components/Settings/AccountDemoLock.test.tsx b/client/src/components/Settings/AccountDemoLock.test.tsx
new file mode 100644
index 000000000..5635179e6
--- /dev/null
+++ b/client/src/components/Settings/AccountDemoLock.test.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: '[email protected]' }) });
+ 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: '[email protected]', 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: '[email protected]' }) });
+ renderCards();
+ expect(screen.queryByRole('note')).not.toBeInTheDocument();
+ expect(screen.getByRole('button', { name: 'Save profile' })).toBeEnabled();
+ });
+});
diff --git a/client/src/components/Settings/AccountDemoLock.tsx b/client/src/components/Settings/AccountDemoLock.tsx
new file mode 100644
index 000000000..8b7abfcab
--- /dev/null
+++ b/client/src/components/Settings/AccountDemoLock.tsx
@@ -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>
+ );
+}
diff --git a/client/src/components/Settings/AccountTab.tsx b/client/src/components/Settings/AccountTab.tsx
index 0089d8050..d00dd6b5c 100644
--- a/client/src/components/Settings/AccountTab.tsx
+++ b/client/src/components/Settings/AccountTab.tsx
@@ -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
diff --git a/client/src/mobile/screens/settings/MSettingsAccount.tsx b/client/src/mobile/screens/settings/MSettingsAccount.tsx
index 57d0ca4cc..9e974cff2 100644
--- a/client/src/mobile/screens/settings/MSettingsAccount.tsx
+++ b/client/src/mobile/screens/settings/MSettingsAccount.tsx
@@ -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'}