A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
feat(app): frame sign-in and sign-up steps inside the switcher
Hampus8fef837a41df
diff --git a/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountPickerShared.ts b/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountPickerShared.tsindex 0d6a26c51..6d2dfefa4 100644--- a/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountPickerShared.ts+++ b/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountPickerShared.ts@@ -1,58 +1,36 @@// SPDX-License-Identifier: AGPL-3.0-or-later-import {getAccountKey} from '@app/features/auth/state/AccountStorageKey';-import {ACTIVE_ACCOUNT_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';-import type {Account} from '@app/features/platform/state/AuthSession';-import type {MessageDescriptor} from '@lingui/core';import {msg} from '@lingui/core/macro';export const SAVED_ACCOUNTS_DESCRIPTOR = msg({message: 'Saved accounts',comment: 'Accessible label for the saved account list.',});-const SAVED_ACCOUNT_DESCRIPTOR = msg({- message: 'Saved account',- comment: 'Short status label for a saved account that is not currently active.',-});export const SESSION_EXPIRED_DESCRIPTOR = msg({message: 'Session expired',comment: 'Short status label for a saved account whose session token has expired.',});--export interface AccountPickerContext {- readonly accountKey: string;- readonly isCurrent: boolean;- readonly isExpired: boolean;-}--export type AccountPickerDisabledPredicate = (account: Account, context: AccountPickerContext) => boolean;--export function getAccountPickerContext(account: Account, currentAccountKey: string | null): AccountPickerContext {- const accountKey = getAccountKey(account);- return {- accountKey,- isCurrent: accountKey === currentAccountKey,- isExpired: account.isValid === false,- };-}--export function resolveAccountPickerDisabled(- value: boolean | AccountPickerDisabledPredicate,- account: Account,- context: AccountPickerContext,-): boolean {- if (typeof value === 'function') {- return value(account, context);- }- return value;-}--export function getAccountPickerStatusDescriptor(context: AccountPickerContext): MessageDescriptor {- if (context.isExpired) {- return SESSION_EXPIRED_DESCRIPTOR;- }- if (context.isCurrent) {- return ACTIVE_ACCOUNT_DESCRIPTOR;- }- return SAVED_ACCOUNT_DESCRIPTOR;-}+export const USE_ANOTHER_ACCOUNT_DESCRIPTOR = msg({+ message: 'Use another account',+ comment: 'Button under the saved account list that opens a sign-in form for an account that is not in the list.',+});+export const SIGN_IN_AGAIN_DESCRIPTOR = msg({+ message: 'Sign in again',+ comment:+ 'Menu item for a saved account whose session has expired, in the account list and in the account switcher. It opens the sign-in form for that account.',+});+export const CONFIRM_SIGN_OUT_DESCRIPTOR = msg({+ message: 'Sign out of {displayName}?',+ comment:+ 'Question shown inside an account row, or in the account switcher menu for one account, before signing that account out of this device. displayName is the account name.',+});+export const ACCOUNT_OPTIONS_DESCRIPTOR = msg({+ message: 'Options for {displayName}',+ comment:+ 'Accessible label for the menu of sign-in and sign-out actions for one saved account, in the account list and in the account switcher. displayName is the account name.',+});+export const SIGN_OUT_EXPIRED_ACCOUNTS_DESCRIPTOR = msg({+ message: 'Sign out of all expired accounts',+ comment:+ 'Button under the saved account list, and in the account switcher while managing accounts, that signs out every saved account whose session has expired, except the account in use. Only shown when two or more of those sessions have expired.',+});diff --git a/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountSwitcherAuthFlow.module.css b/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountSwitcherAuthFlow.module.cssindex 8c83ba247..3c3c7b676 100644--- a/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountSwitcherAuthFlow.module.css+++ b/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountSwitcherAuthFlow.module.css@@ -1,37 +1,16 @@/* SPDX-License-Identifier: AGPL-3.0-or-later */-.authCardContainer.authCardContainer {+.shell {+ display: flex;+ flex-direction: column;+ gap: var(--spacing-3);width: 100%;- min-height: 0;- flex: 0 1 auto;- padding: 0;-}--.authCard {- position: relative;- min-height: 0;+ min-width: 0;}-.authCardContent.authCardContent {- position: relative;- box-sizing: border-box;- justify-content: flex-start;- max-height: min(- calc(100dvh - 4rem - env(safe-area-inset-top, 0) - env(safe-area-inset-bottom, 0)),- var(--account-switcher-overlay-max-height, 52rem)- );- min-height: 0;- overflow: hidden;- overscroll-behavior: contain;-}--.authCarouselViewport {- width: 100%;- min-height: 0;- flex: 1 1 auto;- overflow-x: hidden;- overflow-y: auto;- overscroll-behavior: contain;+.backButton {+ align-self: flex-start;+ margin-inline-start: calc(-1 * var(--spacing-2));}.inlineLink {@@ -39,16 +18,17 @@padding: 0;border: 0;background: transparent;- color: var(--text-link);+ color: var(--text-tertiary);cursor: pointer;font: inherit;font-size: 0.875rem;line-height: 1.25rem;- text-align: left;+ text-align: start;text-decoration: none;}.inlineLink:hover {+ color: var(--text-primary);text-decoration: underline;}@@ -56,8 +36,6 @@width: 100%;}-@media (max-width: 42rem) {- .authCardContent.authCardContent {- max-height: calc(100dvh - 3rem - env(safe-area-inset-top, 0) - env(safe-area-inset-bottom, 0));- }+.untitled > form {+ margin-top: 0;}diff --git a/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountSwitcherAuthFlow.tsx b/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountSwitcherAuthFlow.tsxindex 7320a4948..4675f95bb 100644--- a/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountSwitcherAuthFlow.tsx+++ b/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountSwitcherAuthFlow.tsx@@ -4,11 +4,14 @@ import type {RuntimeConfigSnapshot} from '@app/features/app/state/InstanceSnapshimport RuntimeConfig from '@app/features/app/state/RuntimeConfig';import {usesUsernameSignIn} from '@app/features/app/utils/AccountIdentityFeatures';import * as AuthenticationCommands from '@app/features/auth/commands/AuthenticationCommands';+import {SIGN_IN_AGAIN_AS_DESCRIPTOR} from '@app/features/auth/components/accounts/AccountList';import {AccountSwitcherAuthShell} from '@app/features/auth/components/accounts/account_switcher_modal/AccountSwitcherAuthShell';import {type AccountSwitcherAuthPurpose,+ AccountSwitcherAuthPurposeType,AccountSwitcherAuthStep,getInitialRuntimeSnapshot,+ getReloginAccountLabel,} from '@app/features/auth/components/accounts/account_switcher_modal/AccountSwitcherAuthTypes';import {AccountSwitcherLoginStep} from '@app/features/auth/components/accounts/account_switcher_modal/AccountSwitcherLoginStep';import {AccountSwitcherRegisterStep} from '@app/features/auth/components/accounts/account_switcher_modal/AccountSwitcherRegisterStep';@@ -26,29 +29,71 @@ import {type AuthLayoutContextType,} from '@app/features/auth/state/AuthLayoutContext';import {AuthRuntimeTarget} from '@app/features/auth/state/AuthRuntimeTarget';+import {+ BACK_DESCRIPTOR,+ CANCEL_DESCRIPTOR,+ SIGN_IN_DESCRIPTOR,+} from '@app/features/i18n/utils/CommonMessageDescriptors';import {flxElementClassName} from '@app/lib/react';import type {GuildSplashCardAlignmentValue} from '@fluxer/constants/src/GuildConstants';import {GuildSplashCardAlignment} from '@fluxer/constants/src/GuildConstants';+import type {I18n} from '@lingui/core';+import {msg} from '@lingui/core/macro';+import {useLingui} from '@lingui/react/macro';import {observer} from 'mobx-react-lite';import type React from 'react';-import {useCallback, useLayoutEffect, useMemo, useState} from 'react';+import {useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState} from 'react';++const BACK_TO_ACCOUNTS_DESCRIPTOR = msg({+ message: 'Back to accounts',+ comment: 'Button above the sign-in form in the account switcher. It goes back to the list of saved accounts.',+});++const ENTRY_FOCUS_SELECTOR = '[data-step-focus="true"], input:not([type="hidden"]):not([disabled])';++export interface AccountSwitcherAuthFrame {+ readonly title: string;+ readonly backLabel: string;+ readonly onBack: () => void;+ readonly content: React.ReactElement;+}++export const ADD_AN_ACCOUNT_DESCRIPTOR = msg({+ message: 'Add an account',+ comment:+ 'Last tile in the account switcher grid, and the title of the step it opens, where another saved account is added by signing in or registering.',+});++function getPurposeTitle(purpose: AccountSwitcherAuthPurpose, i18n: I18n): string | null {+ if (purpose.type === AccountSwitcherAuthPurposeType.ADD) {+ return i18n._(ADD_AN_ACCOUNT_DESCRIPTOR);+ }+ const accountLabel = getReloginAccountLabel(purpose);+ if (accountLabel == null) {+ return null;+ }+ return i18n._(SIGN_IN_AGAIN_AS_DESCRIPTOR, {accountLabel});+}interface AccountSwitcherAuthFlowProps {readonly purpose: AccountSwitcherAuthPurpose;+ readonly renderFrame: ((frame: AccountSwitcherAuthFrame) => React.ReactElement) | null;readonly redirectAfterLogin: string | null;- readonly onBackToAccounts: () => void;+ readonly focusOnEntry: boolean;+ readonly exitCancels: boolean;+ readonly onExit: () => void;readonly onLoginComplete: (payload: LoginSuccessPayload) => Promise<void> | void;}-function resolveInitialRuntimeSnapshot(purpose: AccountSwitcherAuthPurpose): RuntimeConfigSnapshot | null {+function createAuthRuntimeTarget(purpose: AccountSwitcherAuthPurpose): AuthRuntimeTarget {const purposeSnapshot = getInitialRuntimeSnapshot(purpose);if (purposeSnapshot != null) {- return purposeSnapshot;+ return AuthRuntimeTarget.forFixedInstance(purposeSnapshot);}if (shouldRenderInstanceStep()) {- return null;+ return AuthRuntimeTarget.forInstanceSelection(null);}- return RuntimeConfig.getSnapshotOrNull();+ return AuthRuntimeTarget.forInstanceSelection(RuntimeConfig.getSnapshotOrNull());}function requireSelectedRuntimeSnapshot(runtimeTarget: AuthRuntimeTarget): RuntimeConfigSnapshot {@@ -82,24 +127,29 @@ function renderForgotPasswordContainer(children: React.ReactNode, isSent: booleaexport const AccountSwitcherAuthFlow = observer(function AccountSwitcherAuthFlow({purpose,+ renderFrame,redirectAfterLogin,- onBackToAccounts,+ focusOnEntry,+ exitCancels,+ onExit,onLoginComplete,}: AccountSwitcherAuthFlowProps): React.ReactElement {+ const {i18n} = useLingui();const [selectedAuthStep, setSelectedAuthStep] = useState<AccountSwitcherAuthStep>(AccountSwitcherAuthStep.LOGIN);- const [cardVariant, setCardVariant] = useState<AuthCardVariant>(AuthCardVariant.STANDARD);+ const [, setCardVariant] = useState<AuthCardVariant>(AuthCardVariant.STANDARD);const [, setContentMode] = useState<AuthLayoutContentMode>(AuthLayoutContentMode.CARD);const [, setSplashCardAlignment] = useState<GuildSplashCardAlignmentValue>(GuildSplashCardAlignment.CENTER);const [loginBackAction, setLoginBackAction] = useState<(() => void) | null>(null);+ const [stepTitle, setStepTitle] = useState<string | null>(null);const [mfaChallengePurpose, setMfaChallengePurpose] = useState<AccountSwitcherAuthPurpose | null>(null);- const authRuntimeTarget = useMemo(- () => AuthRuntimeTarget.forInstanceSelection(resolveInitialRuntimeSnapshot(purpose)),- [purpose],- );+ const authRuntimeTarget = useMemo(() => createAuthRuntimeTarget(purpose), [purpose]);+ const stepTitleChange = renderFrame == null ? null : setStepTitle;+ const purposeTitle = getPurposeTitle(purpose, i18n);const setSplashUrl = useCallback(() => {}, []);+ const setBrandSnapshot = useCallback(() => {}, []);const authLayoutContextValue = useMemo<AuthLayoutContextType>(- () => ({setSplashUrl, setCardVariant, setContentMode, setSplashCardAlignment}),- [setSplashUrl],+ () => ({setSplashUrl, setBrandSnapshot, setCardVariant, setContentMode, setSplashCardAlignment}),+ [setBrandSnapshot, setSplashUrl],);const accountRestriction = Authentication.accountRestriction;const mfaTicket = Authentication.currentMfaTicket;@@ -122,6 +172,13 @@ export const AccountSwitcherAuthFlow = observer(function AccountSwitcherAuthFlowAuthenticationCommands.clearAccountRestriction();};}, [purpose]);+ const shellRef = useRef<HTMLElement | null>(null);+ useEffect(() => {+ if (!focusOnEntry) {+ return;+ }+ shellRef.current?.querySelector<HTMLElement>(ENTRY_FOCUS_SELECTOR)?.focus();+ }, [focusOnEntry, purpose]);const showRegisterStep = useCallback(() => {setSelectedAuthStep(AccountSwitcherAuthStep.REGISTER);}, []);@@ -203,8 +260,8 @@ export const AccountSwitcherAuthFlow = observer(function AccountSwitcherAuthFlowloginBackAction();return;}- onBackToAccounts();- }, [accountRestriction, authStep, handleBackToSignIn, loginBackAction, onBackToAccounts, showLoginStep]);+ onExit();+ }, [accountRestriction, authStep, handleBackToSignIn, loginBackAction, onExit, showLoginStep]);const renderAuthStep = (): React.ReactNode => {if (accountRestriction != null) {return (@@ -212,6 +269,7 @@ export const AccountSwitcherAuthFlow = observer(function AccountSwitcherAuthFlowrestriction={accountRestriction}onBackToSignIn={handleBackToSignIn}onTryAgain={AuthenticationCommands.clearAccountRestriction}+ onStepTitleChange={stepTitleChange}data-flx="auth.accounts.account-switcher-modal.account-switcher-auth-flow.account-restriction-screen"/>);@@ -226,6 +284,7 @@ export const AccountSwitcherAuthFlow = observer(function AccountSwitcherAuthFlowchallenge={{ticket: mfaTicket, ...mfaMethods}}onSuccess={handleMfaSuccess}onCancel={handleMfaCancel}+ onStepTitleChange={stepTitleChange}data-flx="auth.accounts.account-switcher-modal.account-switcher-auth-flow.mfa-screen"/>);@@ -233,6 +292,7 @@ export const AccountSwitcherAuthFlow = observer(function AccountSwitcherAuthFlowreturn (<AccountSwitcherRegisterStepruntimeSnapshot={requireSelectedRuntimeSnapshot(authRuntimeTarget)}+ onStepTitleChange={stepTitleChange}onRegister={handleRegisterComplete}onBrowserLogin={handleBrowserLoginComplete}data-flx="auth.accounts.account-switcher-modal.account-switcher-auth-flow.register-step"@@ -245,6 +305,7 @@ export const AccountSwitcherAuthFlow = observer(function AccountSwitcherAuthFlow<RecoverAccountFormruntimeSnapshot={runtimeSnapshot}onRecovered={handleAccountRecovered}+ onStepTitleChange={stepTitleChange}data-flx="auth.accounts.account-switcher-modal.account-switcher-auth-flow.recover-account-step"/>);@@ -253,6 +314,7 @@ export const AccountSwitcherAuthFlow = observer(function AccountSwitcherAuthFlow<ForgotPasswordFormruntimeSnapshot={runtimeSnapshot}renderContainer={renderForgotPasswordContainer}+ onStepTitleChange={stepTitleChange}data-flx="auth.accounts.account-switcher-modal.account-switcher-auth-flow.forgot-password-step"/>);@@ -263,7 +325,9 @@ export const AccountSwitcherAuthFlow = observer(function AccountSwitcherAuthFlowpurpose={purpose}redirectAfterLogin={redirectAfterLogin}runtimeTarget={authRuntimeTarget}+ title={purposeTitle}onBackActionChange={handleLoginBackActionChange}+ onStepTitleChange={stepTitleChange}onForgotPassword={showForgotPasswordStep}onLoginComplete={onLoginComplete}onRegister={showRegisterStep}@@ -272,17 +336,38 @@ export const AccountSwitcherAuthFlow = observer(function AccountSwitcherAuthFlow);}};- const returnsToAccountList = authStep === AccountSwitcherAuthStep.LOGIN && loginBackAction == null;- return (- <AccountSwitcherAuthShell- cardVariant={cardVariant}- layoutContextValue={authLayoutContextValue}- step={authStep}- returnsToAccountList={returnsToAccountList}- onBack={handleBack}- data-flx="auth.accounts.account-switcher-modal.account-switcher-auth-flow.shell"- >- {renderAuthStep()}- </AccountSwitcherAuthShell>- );+ const exitsFlow = accountRestriction == null && authStep === AccountSwitcherAuthStep.LOGIN && loginBackAction == null;+ let backLabel = i18n._(BACK_DESCRIPTOR);+ if (exitsFlow) {+ backLabel = i18n._(exitCancels ? CANCEL_DESCRIPTOR : BACK_TO_ACCOUNTS_DESCRIPTOR);+ }+ if (renderFrame == null) {+ return (+ <AccountSwitcherAuthShell+ layoutContextValue={authLayoutContextValue}+ step={authStep}+ back={{label: backLabel, onBack: handleBack}}+ rootRef={shellRef}+ data-flx="auth.accounts.account-switcher-modal.account-switcher-auth-flow.shell"+ >+ {renderAuthStep()}+ </AccountSwitcherAuthShell>+ );+ }+ return renderFrame({+ title: stepTitle ?? purposeTitle ?? i18n._(SIGN_IN_DESCRIPTOR),+ backLabel,+ onBack: handleBack,+ content: (+ <AccountSwitcherAuthShell+ layoutContextValue={authLayoutContextValue}+ step={authStep}+ back={null}+ rootRef={shellRef}+ data-flx="auth.accounts.account-switcher-modal.account-switcher-auth-flow.framed-shell"+ >+ {renderAuthStep()}+ </AccountSwitcherAuthShell>+ ),+ });});diff --git a/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountSwitcherAuthShell.tsx b/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountSwitcherAuthShell.tsxindex 1aada3995..b33540ead 100644--- a/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountSwitcherAuthShell.tsx+++ b/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountSwitcherAuthShell.tsx@@ -1,70 +1,72 @@// SPDX-License-Identifier: AGPL-3.0-or-later-import {AccountSwitcherAuthBackButton} from '@app/features/auth/components/accounts/account_switcher_modal/AccountSwitcherAuthBackButton';import authStyles from '@app/features/auth/components/accounts/account_switcher_modal/AccountSwitcherAuthFlow.module.css';import {ACCOUNT_SWITCHER_AUTH_STEP_ORDER,type AccountSwitcherAuthStep,getAccountSwitcherAuthStepLabel,} from '@app/features/auth/components/accounts/account_switcher_modal/AccountSwitcherAuthTypes';-import {AuthCardContainer} from '@app/features/auth/flow/AuthCardContainer';-import {- type AuthCardVariant,- AuthLayoutContext,- type AuthLayoutContextType,-} from '@app/features/auth/state/AuthLayoutContext';+import {AuthLayoutContext, type AuthLayoutContextType} from '@app/features/auth/state/AuthLayoutContext';+import {remFromPx} from '@app/features/theme/layout/RemFromPx';+import {Button} from '@app/features/ui/button/Button';+import {ArrowLeftIcon} from '@app/features/ui/icons/DirectionalIcons';import {SteppedCarousel} from '@app/features/ui/stepped_carousel/SteppedCarousel';import {flxElementClassName} from '@app/lib/react';import {useLingui} from '@lingui/react/macro';import type React from 'react';interface AccountSwitcherAuthShellProps {- readonly cardVariant: AuthCardVariant;readonly layoutContextValue: AuthLayoutContextType;readonly step: AccountSwitcherAuthStep;- readonly returnsToAccountList: boolean;- readonly onBack: () => void;+ readonly back: {readonly label: string; readonly onBack: () => void} | null;+ readonly rootRef: React.Ref<HTMLElement>;readonly children: React.ReactNode;}export function AccountSwitcherAuthShell({- cardVariant,layoutContextValue,step,- returnsToAccountList,- onBack,+ back,+ rootRef,children,}: AccountSwitcherAuthShellProps): React.ReactElement {const {i18n} = useLingui();return (<AuthLayoutContext.Provider value={layoutContextValue}>- <AuthCardContainer- variant={cardVariant}- className={authStyles.authCardContainer}- cardClassName={authStyles.authCard}- contentClassName={authStyles.authCardContent}- data-flx="auth.accounts.account-switcher-modal.account-switcher-auth-shell.auth-card-container"+ <flx-auth-account-switcher-auth-shell+ ref={rootRef}+ className={flxElementClassName(authStyles.shell)}+ data-flx="auth.accounts.account-switcher-modal.account-switcher-auth-shell.root">- <AccountSwitcherAuthBackButton- returnsToAccountList={returnsToAccountList}- onBack={onBack}- data-flx="auth.accounts.account-switcher-modal.account-switcher-auth-shell.back-button"- />- <flx-auth-account-switcher-auth-shell-viewport- className={flxElementClassName(authStyles.authCarouselViewport)}- data-flx="auth.accounts.account-switcher-modal.account-switcher-auth-shell.viewport"- >- <SteppedCarousel- step={step}- steps={ACCOUNT_SWITCHER_AUTH_STEP_ORDER}- focusOnStepChange- ariaLabel={i18n._(getAccountSwitcherAuthStepLabel(step))}- data-flx="auth.accounts.account-switcher-modal.account-switcher-auth-shell.carousel"+ {back == null ? null : (+ <Button+ variant="ghost"+ small+ fitContent+ className={authStyles.backButton}+ leftIcon={+ <ArrowLeftIcon+ size={remFromPx(16)}+ weight="bold"+ data-flx="auth.accounts.account-switcher-modal.account-switcher-auth-shell.arrow-left-icon"+ />+ }+ onClick={back.onBack}+ data-flx="auth.accounts.account-switcher-modal.account-switcher-auth-shell.button.back">- {children}- </SteppedCarousel>- </flx-auth-account-switcher-auth-shell-viewport>- </AuthCardContainer>+ {back.label}+ </Button>+ )}+ <SteppedCarousel+ step={step}+ steps={ACCOUNT_SWITCHER_AUTH_STEP_ORDER}+ focusOnStepChange+ ariaLabel={i18n._(getAccountSwitcherAuthStepLabel(step))}+ data-flx="auth.accounts.account-switcher-modal.account-switcher-auth-shell.carousel"+ >+ {children}+ </SteppedCarousel>+ </flx-auth-account-switcher-auth-shell></AuthLayoutContext.Provider>);}diff --git a/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountSwitcherAuthTypes.ts b/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountSwitcherAuthTypes.tsindex 924396b6d..d63e0fa08 100644--- a/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountSwitcherAuthTypes.ts+++ b/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountSwitcherAuthTypes.ts@@ -21,7 +21,7 @@ export type AccountSwitcherAuthPurposeType =(typeof AccountSwitcherAuthPurposeType)[keyof typeof AccountSwitcherAuthPurposeType];export type AccountSwitcherAuthPurpose =- | {readonly type: typeof AccountSwitcherAuthPurposeType.ADD}+ | {readonly type: typeof AccountSwitcherAuthPurposeType.ADD; readonly instance: RuntimeConfigSnapshot | null}| {readonly type: typeof AccountSwitcherAuthPurposeType.RELOGIN; readonly account: Account};export const AccountSwitcherAuthStep = Object.freeze({@@ -54,14 +54,10 @@ export function getAccountSwitcherAuthStepLabel(step: AccountSwitcherAuthStep):}export function getInitialRuntimeSnapshot(purpose: AccountSwitcherAuthPurpose): RuntimeConfigSnapshot | null {- if (purpose.type !== AccountSwitcherAuthPurposeType.RELOGIN) {- return null;- }- const instance = purpose.account.instance;- if (instance == null) {- return null;+ if (purpose.type === AccountSwitcherAuthPurposeType.ADD) {+ return purpose.instance;}- return instance;+ return purpose.account.instance ?? null;}export function getReloginIdentifier(purpose: AccountSwitcherAuthPurpose): string | null {diff --git a/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountSwitcherLoginStep.tsx b/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountSwitcherLoginStep.tsxindex ffbbd2a84..df52966d4 100644--- a/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountSwitcherLoginStep.tsx+++ b/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountSwitcherLoginStep.tsx@@ -5,29 +5,24 @@ import authStyles from '@app/features/auth/components/accounts/account_switcher_import {type AccountSwitcherAuthPurpose,AccountSwitcherAuthPurposeType,- getReloginAccountLabel,getReloginIdentifier,} from '@app/features/auth/components/accounts/account_switcher_modal/AccountSwitcherAuthTypes';import {AuthLoginLayout} from '@app/features/auth/flow/AuthLoginLayout';+import type {StepTitleChangeHandler} from '@app/features/auth/flow/useReportStepTitle';import type {LoginSuccessPayload} from '@app/features/auth/state/AuthFlow';import type {AuthRuntimeTarget} from '@app/features/auth/state/AuthRuntimeTarget';import {REGISTER_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';-import {msg} from '@lingui/core/macro';import {useLingui} from '@lingui/react/macro';import type React from 'react';import {useMemo} from 'react';-const SIGN_IN_AGAIN_AS_DESCRIPTOR = msg({- message: 'Sign in again as {accountLabel}',- comment:- 'Heading shown while re-authenticating one saved account from the account switcher. Account display name is interpolated.',-});-interface AccountSwitcherLoginStepProps {readonly purpose: AccountSwitcherAuthPurpose;readonly redirectAfterLogin: string | null;readonly runtimeTarget: AuthRuntimeTarget;+ readonly title: string | null;readonly onBackActionChange: (action: (() => void) | null) => void;+ readonly onStepTitleChange: StepTitleChangeHandler | null;readonly onForgotPassword: () => void;readonly onLoginComplete: (payload: LoginSuccessPayload) => Promise<void> | void;readonly onRegister: () => void;@@ -37,7 +32,9 @@ export function AccountSwitcherLoginStep({purpose,redirectAfterLogin,runtimeTarget,+ title,onBackActionChange,+ onStepTitleChange,onForgotPassword,onLoginComplete,onRegister,@@ -55,13 +52,6 @@ export function AccountSwitcherLoginStep({),[i18n, onRegister],);- const reloginTitle = useMemo<React.ReactNode>(() => {- const accountLabel = getReloginAccountLabel(purpose);- if (accountLabel == null) {- return null;- }- return i18n._(SIGN_IN_AGAIN_AS_DESCRIPTOR, {accountLabel});- }, [i18n, purpose]);const forgotPasswordAction = useMemo(() => (<button@@ -84,16 +74,18 @@ export function AccountSwitcherLoginStep({extraTopContent={null}completeLoginRedirectPath={redirectAfterLogin}forgotPasswordAction={forgotPasswordAction}- showTitle={true}- title={reloginTitle}+ showTitle={onStepTitleChange == null}+ title={title}forceCredentials={purpose.type === AccountSwitcherAuthPurposeType.RELOGIN}initialIdentifier={getReloginIdentifier(purpose)}runtimeTarget={runtimeTarget}onBackActionChange={onBackActionChange}+ onStepTitleChange={onStepTitleChange}startWithAddAccount={purpose.type === AccountSwitcherAuthPurposeType.ADD}registerLink={registerAction}ssoRedirectPath={null}suppressInlineBackButtons={true}+ allowSsoAutoStart={false}onLoginComplete={onLoginComplete}data-flx="auth.accounts.account-switcher-modal.account-switcher-login-step.auth-login-layout"/>diff --git a/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountSwitcherRegisterStep.tsx b/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountSwitcherRegisterStep.tsxindex c5cf01e5c..8575f5675 100644--- a/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountSwitcherRegisterStep.tsx+++ b/fluxer_app/src/features/auth/components/accounts/account_switcher_modal/AccountSwitcherRegisterStep.tsx@@ -8,30 +8,44 @@ import pageStyles from '@app/features/auth/flow/AuthPageStyles.module.css';import {AuthRegisterFormCore} from '@app/features/auth/flow/AuthRegisterFormCore';import {AuthSsoPanel, isSsoLoginEnforced, resolveAuthPanelSso} from '@app/features/auth/flow/AuthSsoPanel';import {credentialRegisterFields} from '@app/features/auth/flow/RegisterFormFields';+import {type StepTitleChangeHandler, useReportStepTitle} from '@app/features/auth/flow/useReportStepTitle';import type {LoginSuccessPayload} from '@app/features/auth/state/AuthFlow';-import Theme from '@app/features/theme/state/Theme';+import ThemeProfile from '@app/features/theme/state/ThemeProfile';import {flxElementClassName} from '@app/lib/react';-import {Trans} from '@lingui/react/macro';+import {msg} from '@lingui/core/macro';+import {Trans, useLingui} from '@lingui/react/macro';import {observer} from 'mobx-react-lite';import type React from 'react';+const CREATE_AN_ACCOUNT_DESCRIPTOR = msg({+ message: 'Create an account',+ comment: 'Title of the registration step in the account switcher, used to add another saved account.',+});+interface AccountSwitcherRegisterStepProps {readonly runtimeSnapshot: RuntimeConfigSnapshot;+ readonly onStepTitleChange: StepTitleChangeHandler | null;readonly onRegister: (response: AuthenticationCommands.TokenResponse) => Promise<void>;readonly onBrowserLogin: (payload: LoginSuccessPayload) => Promise<void>;}export const AccountSwitcherRegisterStep = observer(function AccountSwitcherRegisterStep({runtimeSnapshot,+ onStepTitleChange,onRegister,onBrowserLogin,}: AccountSwitcherRegisterStepProps): React.ReactElement {+ const {i18n} = useLingui();const ssoConfig = resolveAuthPanelSso(runtimeSnapshot);- if (isSsoLoginEnforced(ssoConfig)) {+ const ssoEnforced = isSsoLoginEnforced(ssoConfig);+ useReportStepTitle(ssoEnforced ? null : onStepTitleChange, i18n._(CREATE_AN_ACCOUNT_DESCRIPTOR));+ const showTitle = onStepTitleChange == null;+ if (ssoEnforced) {return (<AuthSsoPanelruntimeSnapshot={runtimeSnapshot}onBrowserLoginSuccess={onBrowserLogin}+ onStepTitleChange={onStepTitleChange}dataFlx="auth.accounts.account-switcher-modal.account-switcher-register-step.sso-panel"data-flx="auth.accounts.account-switcher-modal.account-switcher-register-step.auth-sso-panel"/>@@ -40,14 +54,16 @@ export const AccountSwitcherRegisterStep = observer(function AccountSwitcherRegiconst usernameSignIn = usesUsernameSignIn(runtimeSnapshot.features);return (<>- <h1- className={pageStyles.title}- data-flx="auth.accounts.account-switcher-modal.account-switcher-register-step.title"- >- <Trans>Create an account</Trans>- </h1>+ {showTitle ? (+ <h1+ className={pageStyles.title}+ data-flx="auth.accounts.account-switcher-modal.account-switcher-register-step.title"+ >+ {i18n._(CREATE_AN_ACCOUNT_DESCRIPTOR)}+ </h1>+ ) : null}<flx-auth-account-switcher-register-step- className={flxElementClassName(authStyles.inlineRegisterContainer)}+ className={flxElementClassName(authStyles.inlineRegisterContainer, !showTitle && authStyles.untitled)}data-flx="auth.accounts.account-switcher-modal.account-switcher-register-step.container"><AuthRegisterFormCore@@ -58,7 +74,7 @@ export const AccountSwitcherRegisterStep = observer(function AccountSwitcherRegiruntimeSnapshot={runtimeSnapshot}onRegister={onRegister}showLegalConsent- theme={Theme.themePreference}+ theme={ThemeProfile.themePreference}data-flx="auth.accounts.account-switcher-modal.account-switcher-register-step.auth-register-form-core"/></flx-auth-account-switcher-register-step>