A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
feat(app): soften unclaimed prompts and add email code entry
Hampusb23722f47d47
diff --git a/fluxer_app/src/features/app/components/alerts/DmActionErrorModal.tsx b/fluxer_app/src/features/app/components/alerts/DmActionErrorModal.tsxindex 07feede67..0908836b1 100644--- a/fluxer_app/src/features/app/components/alerts/DmActionErrorModal.tsx+++ b/fluxer_app/src/features/app/components/alerts/DmActionErrorModal.tsx@@ -7,6 +7,7 @@ import {RATE_LIMITED_ERROR_TITLE_DESCRIPTOR,} from '@app/features/app/components/alerts/CommonErrorModalDescriptors';import {GenericErrorModal} from '@app/features/app/components/alerts/GenericErrorModal';+import {promptForAccountTier} from '@app/features/auth/utils/AccountTierPrompt';import {failureCode, failureMessage} from '@app/features/platform/utils/ResponseInspection';import * as ModalCommands from '@app/features/ui/commands/ModalCommands';import {modal} from '@app/features/ui/commands/ModalCommands';@@ -42,11 +43,11 @@ const CLAIM_ACCOUNT_MESSAGE_DESCRIPTOR = msg({comment: 'Body of the error modal shown when an unclaimed account tries to start a DM.',});const VERIFY_EMAIL_TITLE_DESCRIPTOR = msg({- message: 'Verify your email',+ message: 'Confirm your email',comment: 'Title of the error modal shown when an unverified account tries to start a DM.',});const VERIFY_EMAIL_MESSAGE_DESCRIPTOR = msg({- message: 'You need to verify your email address before you can start a direct message.',+ message: 'You need to confirm your email address before you can start a direct message.',comment: 'Body of the error modal shown when an unverified account tries to start a DM.',});const TOO_MANY_PEOPLE_TITLE_DESCRIPTOR = msg({@@ -126,6 +127,9 @@ function resolveDmActionErrorContent(code: string | undefined, apiMessage?: stri}export function showDmActionErrorModal(error: unknown): void {+ if (promptForAccountTier(error)) {+ return;+ }const code = failureCode(error);const apiMessage = failureMessage(error);ModalCommands.push(diff --git a/fluxer_app/src/features/app/components/dialogs/components/EmailVerificationAlert.tsx b/fluxer_app/src/features/app/components/dialogs/components/EmailVerificationAlert.tsxindex ca95eea58..0d13c532e 100644--- a/fluxer_app/src/features/app/components/dialogs/components/EmailVerificationAlert.tsx+++ b/fluxer_app/src/features/app/components/dialogs/components/EmailVerificationAlert.tsx@@ -1,13 +1,54 @@// SPDX-License-Identifier: AGPL-3.0-or-laterimport RuntimeConfig from '@app/features/app/state/RuntimeConfig';+import {openClaimAccountModal} from '@app/features/auth/components/modals/ClaimAccountModal';import {useResendVerificationEmail} from '@app/features/auth/hooks/useVerifyEmailAction';import {Button} from '@app/features/ui/button/Button';import {WarningAlert} from '@app/features/ui/warning_alert/WarningAlert';+import type {User} from '@app/features/user/models/User';+import Users from '@app/features/user/state/Users';+import {AccountTiers} from '@fluxer/constants/src/AccountTierConstants';+import type {ValueOf} from '@fluxer/constants/src/ValueOf';import {Trans} from '@lingui/react/macro';import {observer} from 'mobx-react-lite';import type React from 'react';+export const EmailVerificationModes = {+ ENTER_CODE: 'enter_code',+ RESEND: 'resend',+} as const;++type EmailVerificationMode = ValueOf<typeof EmailVerificationModes>;++export function verificationMode(+ user: Pick<User, 'reportsAccountTier' | 'accountTier'> | null | undefined,+): EmailVerificationMode {+ return user?.reportsAccountTier === true && user.accountTier === AccountTiers.UNVERIFIED+ ? EmailVerificationModes.ENTER_CODE+ : EmailVerificationModes.RESEND;+}++export const VerifyEmailButton = observer(({children}: {children: React.ReactNode}) => {+ const {isSending, resend} = useResendVerificationEmail();+ if (!RuntimeConfig.emailsEnabled) return null;+ return (+ <Button+ variant="primary"+ small+ disabled={isSending}+ submitting={isSending}+ onClick={+ verificationMode(Users.currentUser) === EmailVerificationModes.ENTER_CODE+ ? () => openClaimAccountModal()+ : resend+ }+ data-flx="app.email-verification-alert.button.verify-email"+ >+ {children}+ </Button>+ );+});+interface EmailVerificationAlertProps {title?: React.ReactNode;children?: React.ReactNode;@@ -18,6 +59,30 @@ export const EmailVerificationAlert = observer(({title, children}: EmailVerificaif (!RuntimeConfig.emailsEnabled) {return null;}+ if (verificationMode(Users.currentUser) === EmailVerificationModes.ENTER_CODE) {+ return (+ <WarningAlert+ title={title ?? <Trans>Email verification required</Trans>}+ actions={+ <Button+ variant="primary"+ small+ onClick={() => openClaimAccountModal()}+ data-flx="app.email-verification-alert.button.enter-code"+ >+ <Trans>Enter code</Trans>+ </Button>+ }+ data-flx="app.email-verification-alert.code-warning-alert"+ >+ {children ?? (+ <Trans comment="Warning shown when the account email is not confirmed yet. The person confirms it by entering a code sent to their email.">+ Confirm your email with a code to send messages and join communities.+ </Trans>+ )}+ </WarningAlert>+ );+ }return (<WarningAlerttitle={title ?? <Trans>Email verification required</Trans>}diff --git a/fluxer_app/src/features/app/components/dialogs/components/LogoutModal.tsx b/fluxer_app/src/features/app/components/dialogs/components/LogoutModal.tsxindex 546ea4eb2..43b7983cc 100644--- a/fluxer_app/src/features/app/components/dialogs/components/LogoutModal.tsx+++ b/fluxer_app/src/features/app/components/dialogs/components/LogoutModal.tsx@@ -2,6 +2,12 @@import {ConfirmModal} from '@app/features/app/components/dialogs/ConfirmModal';import * as AuthenticationCommands from '@app/features/auth/commands/AuthenticationCommands';+import {openClaimAccountModal} from '@app/features/auth/components/modals/ClaimAccountModal';+import Users from '@app/features/user/state/Users';+import {+ getUnclaimedAccountPresentation,+ UnclaimedAccountSurfaces,+} from '@app/features/user/utils/AccountGatePresentation';import {msg} from '@lingui/core/macro';import {Trans, useLingui} from '@lingui/react/macro';import {observer} from 'mobx-react-lite';@@ -18,8 +24,49 @@ const STAY_SIGNED_IN_DESCRIPTOR = msg({message: 'Stay signed in',comment: 'Short label in the settings dialog logout modal.',});+const SIGN_OUT_ANYWAY_DESCRIPTOR = msg({+ message: 'Sign out anyway',+ comment: 'Button in the sign out dialog for an account that has no way to sign back in.',+});export const LogoutModal = observer(() => {const {i18n} = useLingui();+ const user = Users.currentUser;+ if (user?.isClaimed() === false && user.dateOfBirthRequired) {+ return (+ <ConfirmModal+ title={i18n._(SIGN_OUT_DESCRIPTOR)}+ description={+ <Trans comment="Sign out dialog text for an unclaimed account that has no way to sign back in after signing out.">+ This account is unclaimed, so you can't sign back in to it.+ </Trans>+ }+ primaryText={i18n._(SIGN_OUT_ANYWAY_DESCRIPTOR)}+ primaryVariant="danger"+ secondaryText={i18n._(STAY_SIGNED_IN_DESCRIPTOR)}+ onPrimary={() => AuthenticationCommands.logout()}+ data-flx="app.logout-modal.unclaimed-confirm-modal--date-of-birth"+ />+ );+ }+ if (user?.isClaimed() === false) {+ const presentation = getUnclaimedAccountPresentation(+ i18n,+ UnclaimedAccountSurfaces.SIGN_OUT,+ user.verificationNeed,+ );+ return (+ <ConfirmModal+ title={i18n._(SIGN_OUT_DESCRIPTOR)}+ description={presentation.message}+ primaryText={i18n._(SIGN_OUT_ANYWAY_DESCRIPTOR)}+ primaryVariant="danger"+ secondaryText={presentation.actionLabel}+ onSecondary={() => openClaimAccountModal()}+ onPrimary={() => AuthenticationCommands.logout()}+ data-flx="app.logout-modal.unclaimed-confirm-modal"+ />+ );+ }return (<ConfirmModaltitle={i18n._(SIGN_OUT_DESCRIPTOR)}diff --git a/fluxer_app/src/features/app/components/dialogs/components/UnclaimedAccountAlert.tsx b/fluxer_app/src/features/app/components/dialogs/components/UnclaimedAccountAlert.tsxindex c63e533a1..e610dcb50 100644--- a/fluxer_app/src/features/app/components/dialogs/components/UnclaimedAccountAlert.tsx+++ b/fluxer_app/src/features/app/components/dialogs/components/UnclaimedAccountAlert.tsx@@ -1,40 +1,38 @@// SPDX-License-Identifier: AGPL-3.0-or-later-import RuntimeConfig from '@app/features/app/state/RuntimeConfig';import {openClaimAccountModal} from '@app/features/auth/components/modals/ClaimAccountModal';-import {CLAIM_ACCOUNT_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';import {Button} from '@app/features/ui/button/Button';import {WarningAlert} from '@app/features/ui/warning_alert/WarningAlert';+import Users from '@app/features/user/state/Users';+import {+ getUnclaimedAccountPresentation,+ UnclaimedAccountSurfaces,+} from '@app/features/user/utils/AccountGatePresentation';import {Trans, useLingui} from '@lingui/react/macro';import {observer} from 'mobx-react-lite';export const UnclaimedAccountAlert = observer(() => {const {i18n} = useLingui();+ const presentation = getUnclaimedAccountPresentation(+ i18n,+ UnclaimedAccountSurfaces.ALERT,+ Users.currentUser?.verificationNeed,+ );return (<WarningAlerttitle={<Trans>Unclaimed account</Trans>}actions={<Buttonsmall={true}- onClick={() => openClaimAccountModal({force: true})}+ onClick={() => openClaimAccountModal()}data-flx="app.unclaimed-account-alert.button.open-claim-account-modal">- {i18n._(CLAIM_ACCOUNT_DESCRIPTOR)}+ {presentation.actionLabel}</Button>}data-flx="app.unclaimed-account-alert.warning-alert">- {RuntimeConfig.usesUsernameSignIn ? (- <Trans>- Your account is not yet claimed. Without a username and password, you won't be able to sign in from other- devices and you could lose access to your account. Claim your account now to secure it.- </Trans>- ) : (- <Trans>- Your account is not yet claimed. Without an email and password, you won't be able to sign in from other- devices and you could lose access to your account. Claim your account now to secure it.- </Trans>- )}+ {presentation.message}</WarningAlert>);});diff --git a/fluxer_app/src/features/app/components/layout/app_layout/nagbars/EmailVerificationNagbar.tsx b/fluxer_app/src/features/app/components/layout/app_layout/nagbars/EmailVerificationNagbar.tsxindex 39b658dca..00cbf25ed 100644--- a/fluxer_app/src/features/app/components/layout/app_layout/nagbars/EmailVerificationNagbar.tsx+++ b/fluxer_app/src/features/app/components/layout/app_layout/nagbars/EmailVerificationNagbar.tsx@@ -15,9 +15,9 @@ import {useLingui} from '@lingui/react/macro';import {observer} from 'mobx-react-lite';const EMAIL_VERIFICATION_NAGBAR_MESSAGE_DESCRIPTOR = msg({- message: 'Hey {displayName}, check your inbox for the email we sent to verify your address.',+ message: 'Hey {displayName}, please confirm your email address.',comment:- 'Nagbar warning shown when the current user still needs to verify email. A verification email is sent when the account is created. displayName is the user display name.',+ 'Nagbar warning shown when the current user still needs to confirm their email. A verification email is sent when the account is created, and the button next to this sends another one or opens the code entry dialog. displayName is the user display name.',});const EMAIL_BOUNCED_NAGBAR_MESSAGE_DESCRIPTOR = msg({message: "Hey {displayName}, we can't deliver email to your address. Add a working email to verify your account.",@@ -46,8 +46,8 @@ export const EmailVerificationNagbar = observer(({isMobile}: {isMobile: boolean}return (<NagbarisMobile={isMobile}- backgroundColor={NAGBAR_TONES[NagbarToneKind.ALERT].backgroundColor}- textColor={NAGBAR_TONES[NagbarToneKind.ALERT].textColor}+ backgroundColor={NAGBAR_TONES[NagbarToneKind.NEUTRAL].backgroundColor}+ textColor={NAGBAR_TONES[NagbarToneKind.NEUTRAL].textColor}data-flx="app.app-layout.nagbars.email-verification-nagbar.nagbar"><NagbarContentdiff --git a/fluxer_app/src/features/app/components/layout/app_layout/nagbars/UnclaimedAccountNagbar.tsx b/fluxer_app/src/features/app/components/layout/app_layout/nagbars/UnclaimedAccountNagbar.tsxindex cec5db476..162e39feb 100644--- a/fluxer_app/src/features/app/components/layout/app_layout/nagbars/UnclaimedAccountNagbar.tsx+++ b/fluxer_app/src/features/app/components/layout/app_layout/nagbars/UnclaimedAccountNagbar.tsx@@ -5,45 +5,48 @@ import {NagbarButton} from '@app/features/app/components/layout/NagbarButton';import {NagbarContent} from '@app/features/app/components/layout/NagbarContent';import {NAGBAR_TONES, NagbarToneKind} from '@app/features/app/components/layout/NagbarTones';import {openClaimAccountModal} from '@app/features/auth/components/modals/ClaimAccountModal';-import {CLAIM_ACCOUNT_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';+import NagbarState from '@app/features/ui/state/Nagbar';+import {snoozeUnclaimedNagbar} from '@app/features/ui/state/UnclaimedNagbarSnooze';import Users from '@app/features/user/state/Users';-import * as NicknameUtils from '@app/features/user/utils/NicknameUtils';-import {msg} from '@lingui/core/macro';+import {+ getUnclaimedAccountPresentation,+ UnclaimedAccountSurfaces,+} from '@app/features/user/utils/AccountGatePresentation';import {useLingui} from '@lingui/react/macro';import {observer} from 'mobx-react-lite';-const CLAIM_ACCOUNT_NAGBAR_MESSAGE_DESCRIPTOR = msg({- message: 'Hey {displayName}, claim your account to prevent losing access.',- comment: 'Nagbar warning shown to unclaimed-account users. displayName is the current user display name.',-});export const UnclaimedAccountNagbar = observer(({isMobile}: {isMobile: boolean}) => {const {i18n} = useLingui();- const user = Users.currentUser;- if (!user) {- return null;- }- const handleClaimAccount = () => {- openClaimAccountModal({force: true});+ const presentation = getUnclaimedAccountPresentation(+ i18n,+ UnclaimedAccountSurfaces.NAGBAR,+ Users.currentUser?.verificationNeed,+ );+ const handleDismiss = () => {+ const userId = Users.currentUser?.id;+ if (userId) snoozeUnclaimedNagbar(userId);+ NagbarState.dismissUnclaimedAccountForSession();};return (<NagbarisMobile={isMobile}- backgroundColor={NAGBAR_TONES[NagbarToneKind.ALERT].backgroundColor}- textColor={NAGBAR_TONES[NagbarToneKind.ALERT].textColor}+ backgroundColor={NAGBAR_TONES[NagbarToneKind.NEUTRAL].backgroundColor}+ textColor={NAGBAR_TONES[NagbarToneKind.NEUTRAL].textColor}+ dismissible={true}+ onDismiss={handleDismiss}data-flx="app.app-layout.nagbars.unclaimed-account-nagbar.nagbar"><NagbarContentisMobile={isMobile}- message={i18n._(CLAIM_ACCOUNT_NAGBAR_MESSAGE_DESCRIPTOR, {- displayName: NicknameUtils.getDisplayName(user),- })}+ onDismiss={handleDismiss}+ message={presentation.message}actions={<NagbarButtonisMobile={isMobile}- onClick={handleClaimAccount}+ onClick={() => openClaimAccountModal()}data-flx="app.app-layout.nagbars.unclaimed-account-nagbar.nagbar-button.claim-account">- {i18n._(CLAIM_ACCOUNT_DESCRIPTOR)}+ {presentation.actionLabel}</NagbarButton>}data-flx="app.app-layout.nagbars.unclaimed-account-nagbar.nagbar-content"