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.
TypeScript budget-trackercollaborativedockeritinerarymcp-serveroffline-firstopen-sourceopenstreetmappacking-listpwareal-timeself-hostedselfhostedtraveltravel-apptravel-journaltravel-plannertripitwanderlog
refactor(login): both sign-in screens take their headings and labels from loginModel
Mauriced4595269b52a
diff --git a/client/scripts/size-baseline.json b/client/scripts/size-baseline.jsonindex 087a460a3..9364b4d39 100644--- a/client/scripts/size-baseline.json+++ b/client/scripts/size-baseline.json@@ -18,7 +18,7 @@"src/index.css": 1636,"src/mobile/screens/admin/MAdminPluginsPanel.tsx": 1503,"src/pages/JourneyDetailPage.test.tsx": 3886,- "src/pages/LoginPage.tsx": 1294,+ "src/pages/LoginPage.tsx": 1273,"src/pages/TripPlannerPage.tsx": 1127,"src/pages/atlas/useAtlas.ts": 1207,"src/pages/tripPlanner/useTripPlanner.roadtrip.test.tsx": 3518,diff --git a/client/src/pages/LoginPage.tsx b/client/src/pages/LoginPage.tsxindex eddf02e46..6b60238b9 100644--- a/client/src/pages/LoginPage.tsx+++ b/client/src/pages/LoginPage.tsx@@ -17,6 +17,7 @@ import { SUPPORTED_LANGUAGES, useTranslation } from '../i18n';import { IDP_LOGIN_URL, useLogin } from './login/useLogin';import LoginWorld from './login/LoginWorld';import AppLogin from './login/AppLogin';+import { heading as headingOf, submitLabel } from './login/loginModel';import MfaCodeStep from './login/MfaCodeStep';import { LANGUAGE_CORNER_CLASS } from './login/languageCorner';import PasswordChecklist from '../components/shared/PasswordChecklist';@@ -91,6 +92,8 @@ export default function LoginPage(): React.ReactElement {handleDemoLogin, handleSubmit, handlePasskeyLogin, handleSsoClick,} = login;+ const step = { mode, mfaStep, passwordChangeStep, hasUsers: !!appConfig?.has_users };+ const heading = headingOf(step, t);const oidcButtonShown = !!(appConfig?.oidc_configured && appConfig?.oidc_login && !oidcOnly);const passkeyAvailable = !!(appConfig?.passkey_login &&@@ -229,8 +232,7 @@ export default function LoginPage(): React.ReactElement {);}- // Inside the iOS and Android app: the screen that continues the app's own- // address screen, on the same hook. The browser keeps the page below.+ // In the app: the screen continuing its address screen (login/AppLogin.tsx).if (nativeApp) return <AppLogin login={login} />;return (@@ -582,26 +584,10 @@ export default function LoginPage(): React.ReactElement {color: '#111827',}}>- {passwordChangeStep- ? t('login.setNewPassword')- : mode === 'login' && mfaStep- ? t('login.mfaTitle')- : mode === 'register'- ? !appConfig?.has_users- ? t('login.createAdmin')- : t('login.createAccount')- : t('login.title')}+ {heading.title}</h2><p style={{ margin: '0 0 28px', fontSize: 'calc(13.5px * var(--fs-scale-body, 1))', color: '#9ca3af' }}>- {passwordChangeStep- ? t('login.setNewPasswordHint')- : mode === 'login' && mfaStep- ? t('login.mfaSubtitle')- : mode === 'register'- ? !appConfig?.has_users- ? t('login.createAdminHint')- : t('login.createAccountHint')- : t('login.subtitle')}+ {heading.subtitle}</p><form onSubmit={handleSubmit} style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>@@ -1020,24 +1006,12 @@ export default function LoginPage(): React.ReactElement {animation: 'spin 0.7s linear infinite',}}/>- {passwordChangeStep- ? t('settings.updatePassword')- : mode === 'register'- ? t('login.creating')- : mode === 'login' && mfaStep- ? t('login.mfaVerify')- : t('login.signingIn')}+ {submitLabel(step, true, t)}</>) : (<><Plane size={16} />- {passwordChangeStep- ? t('settings.updatePassword')- : mode === 'register'- ? t('login.createAccount')- : mode === 'login' && mfaStep- ? t('login.mfaVerify')- : t('login.signIn')}+ {submitLabel(step, false, t)}</>)}</button>diff --git a/client/src/pages/login/AppLogin.tsx b/client/src/pages/login/AppLogin.tsxindex a66dd1d5d..41a093a5d 100644--- a/client/src/pages/login/AppLogin.tsx+++ b/client/src/pages/login/AppLogin.tsx@@ -6,7 +6,7 @@ import PasswordChecklist from '../../components/shared/PasswordChecklist';import { useTranslation } from '../../i18n';import { lightStatusBarIcons } from '../../native/appBoot';import './appLogin.css';-import { headingKeys, oidcLoginHref, oidcOnlyHref, submitKey, type LoginStep } from './loginModel';+import { heading as headingOf, oidcLoginHref, oidcOnlyHref, submitLabel, type LoginStep } from './loginModel';import { mfaCodeInputProps } from './MfaCodeStep';import { IDP_LOGIN_URL, type useLogin } from './useLogin';@@ -163,22 +163,22 @@ function stepOf(login: Login): LoginStep {function Credentials({ login }: { login: Login }) {const { t } = useTranslation();const step = stepOf(login);- const heading = headingKeys(step);+ const heading = headingOf(step, t);const onMfa = login.mode === 'login' && login.mfaStep && !login.passwordChangeStep;const onAccount = !(login.mode === 'login' && login.mfaStep) && !login.passwordChangeStep;return (<><form className="al-form" onSubmit={login.handleSubmit}>- <h1 className="al-title">{t(heading.title)}</h1>+ <h1 className="al-title">{heading.title}</h1>{/* The plain sign-in needs no line under its heading; the other steps say what they ask for. */}- {heading.subtitle !== 'login.subtitle' && <p className="al-sub">{t(heading.subtitle)}</p>}+ {!heading.plain && <p className="al-sub">{heading.subtitle}</p>}<Notices login={login} />{login.passwordChangeStep && <NewPassword login={login} />}{onMfa && <MfaCode login={login} />}{onAccount && <Account login={login} />}<button type="submit" className="al-cta" disabled={login.isLoading}>{login.isLoading && <span className="al-spin" aria-hidden="true" />}- {t(submitKey(step, login.isLoading))}+ {submitLabel(step, login.isLoading, t)}</button></form><OtherWays login={login} />diff --git a/client/src/pages/login/loginModel.test.ts b/client/src/pages/login/loginModel.test.tsindex 6f671da87..54c27fe7c 100644--- a/client/src/pages/login/loginModel.test.ts+++ b/client/src/pages/login/loginModel.test.ts@@ -1,6 +1,9 @@// FE-LOGIN-MODEL-001 to FE-LOGIN-MODEL-004import { describe, expect, it } from 'vitest';-import { headingKeys, oidcLoginHref, oidcOnlyHref, submitKey, type LoginStep } from './loginModel';+import { heading, oidcLoginHref, oidcOnlyHref, submitLabel, type LoginStep } from './loginModel';++/** Returns the key itself, so the assertions read the keys. */+const t = (key: string) => key;const step = (overrides: Partial<LoginStep> = {}): LoginStep => ({mode: 'login',@@ -12,20 +15,20 @@ const step = (overrides: Partial<LoginStep> = {}): LoginStep => ({describe('loginModel', () => {it('FE-LOGIN-MODEL-001: names each step of the sign-in', () => {- expect(headingKeys(step())).toEqual({ title: 'login.title', subtitle: 'login.subtitle' });- expect(headingKeys(step({ mfaStep: true })).title).toBe('login.mfaTitle');- expect(headingKeys(step({ passwordChangeStep: true, mfaStep: true })).title).toBe('login.setNewPassword');- expect(headingKeys(step({ mode: 'register' })).title).toBe('login.createAccount');- expect(headingKeys(step({ mode: 'register', hasUsers: false })).title).toBe('login.createAdmin');+ expect(heading(step(), t)).toEqual({ title: 'login.title', subtitle: 'login.subtitle', plain: true });+ expect(heading(step({ mfaStep: true }), t).title).toBe('login.mfaTitle');+ expect(heading(step({ passwordChangeStep: true, mfaStep: true }), t).title).toBe('login.setNewPassword');+ expect(heading(step({ mode: 'register' }), t).title).toBe('login.createAccount');+ expect(heading(step({ mode: 'register', hasUsers: false }), t).title).toBe('login.createAdmin');});it('FE-LOGIN-MODEL-002: labels the submit button for the step and while it runs', () => {- expect(submitKey(step(), false)).toBe('login.signIn');- expect(submitKey(step(), true)).toBe('login.signingIn');- expect(submitKey(step({ mfaStep: true }), true)).toBe('login.mfaVerify');- expect(submitKey(step({ mode: 'register' }), false)).toBe('login.createAccount');- expect(submitKey(step({ mode: 'register' }), true)).toBe('login.creating');- expect(submitKey(step({ passwordChangeStep: true }), true)).toBe('settings.updatePassword');+ expect(submitLabel(step(), false, t)).toBe('login.signIn');+ expect(submitLabel(step(), true, t)).toBe('login.signingIn');+ expect(submitLabel(step({ mfaStep: true }), true, t)).toBe('login.mfaVerify');+ expect(submitLabel(step({ mode: 'register' }), false, t)).toBe('login.createAccount');+ expect(submitLabel(step({ mode: 'register' }), true, t)).toBe('login.creating');+ expect(submitLabel(step({ passwordChangeStep: true }), true, t)).toBe('settings.updatePassword');});it('FE-LOGIN-MODEL-003: carries the invite and the remember-me choice to SSO, only when signing in', () => {diff --git a/client/src/pages/login/loginModel.ts b/client/src/pages/login/loginModel.tsindex 9ebfdd501..806744ef1 100644--- a/client/src/pages/login/loginModel.ts+++ b/client/src/pages/login/loginModel.ts@@ -11,24 +11,34 @@ export interface LoginStep {hasUsers: boolean;}-/** The heading and the line under it, as translation keys. */-export function headingKeys(step: LoginStep): { title: string; subtitle: string } {- if (step.passwordChangeStep) return { title: 'login.setNewPassword', subtitle: 'login.setNewPasswordHint' };- if (step.mode === 'login' && step.mfaStep) return { title: 'login.mfaTitle', subtitle: 'login.mfaSubtitle' };+type Translate = (key: string) => string;++/**+ * The heading and the line under it. `plain` is the plain sign-in, whose line+ * the app's screen leaves out. Translated here, with the keys written out, so+ * the i18n key check sees every one of them.+ */+export function heading(step: LoginStep, t: Translate): { title: string; subtitle: string; plain: boolean } {+ if (step.passwordChangeStep) {+ return { title: t('login.setNewPassword'), subtitle: t('login.setNewPasswordHint'), plain: false };+ }+ if (step.mode === 'login' && step.mfaStep) {+ return { title: t('login.mfaTitle'), subtitle: t('login.mfaSubtitle'), plain: false };+ }if (step.mode === 'register') {return step.hasUsers- ? { title: 'login.createAccount', subtitle: 'login.createAccountHint' }- : { title: 'login.createAdmin', subtitle: 'login.createAdminHint' };+ ? { title: t('login.createAccount'), subtitle: t('login.createAccountHint'), plain: false }+ : { title: t('login.createAdmin'), subtitle: t('login.createAdminHint'), plain: false };}- return { title: 'login.title', subtitle: 'login.subtitle' };+ return { title: t('login.title'), subtitle: t('login.subtitle'), plain: true };}-/** The submit button's label, as a translation key; another while the request runs. */-export function submitKey(step: LoginStep, loading: boolean): string {- if (step.passwordChangeStep) return 'settings.updatePassword';- if (step.mode === 'register') return loading ? 'login.creating' : 'login.createAccount';- if (step.mfaStep) return 'login.mfaVerify';- return loading ? 'login.signingIn' : 'login.signIn';+/** The submit button's label; another while the request runs. */+export function submitLabel(step: LoginStep, loading: boolean, t: Translate): string {+ if (step.passwordChangeStep) return t('settings.updatePassword');+ if (step.mode === 'register') return loading ? t('login.creating') : t('login.createAccount');+ if (step.mfaStep) return t('login.mfaVerify');+ return loading ? t('login.signingIn') : t('login.signIn');}/**