From f4482dd29225d0e82c09b189ab1603e54e6fab39 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Fri, 25 Apr 2025 15:57:54 -0500 Subject: [PATCH] Handle instructions and integrate into 2FA setting --- .../EmailDialog/components/TokenField.tsx | 4 +- .../dialogs/EmailDialog/screens/Verify.tsx | 74 +++++++++++++++---- src/components/dialogs/EmailDialog/types.ts | 7 +- .../Settings/components/Email2FAToggle.tsx | 38 +++++----- 4 files changed, 82 insertions(+), 41 deletions(-) diff --git a/src/components/dialogs/EmailDialog/components/TokenField.tsx b/src/components/dialogs/EmailDialog/components/TokenField.tsx index 54d4f43599..e434dae634 100644 --- a/src/components/dialogs/EmailDialog/components/TokenField.tsx +++ b/src/components/dialogs/EmailDialog/components/TokenField.tsx @@ -1,4 +1,4 @@ -import {View, TextInputProps} from 'react-native' +import {type TextInputProps,View} from 'react-native' import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' @@ -14,6 +14,7 @@ export function normalizeCode(value: string) { export function TokenField({ value, onChangeText, + onSubmitEditing, }: Pick) { const {_} = useLingui() @@ -30,6 +31,7 @@ export function TokenField({ placeholder="XXXXX-XXXXX" value={value} onChangeText={handleOnChangeText} + onSubmitEditing={onSubmitEditing} /> diff --git a/src/components/dialogs/EmailDialog/screens/Verify.tsx b/src/components/dialogs/EmailDialog/screens/Verify.tsx index e09ffeddea..2902861d96 100644 --- a/src/components/dialogs/EmailDialog/screens/Verify.tsx +++ b/src/components/dialogs/EmailDialog/screens/Verify.tsx @@ -21,7 +21,7 @@ import {createStaticClick, InlineLinkText} from '#/components/Link' import {Loader} from '#/components/Loader' import {Span, Text} from '#/components/Typography' -export function Verify(_props: {config: Exclude}) { +export function Verify({config}: {config: Exclude}) { const t = useTheme() const {_} = useLingui() const {currentAccount} = useSession() @@ -96,6 +96,22 @@ export function Verify(_props: {config: Exclude}) { )} + {step === 'default' && ( + <> + {config.instructions?.map((int, i) => ( + + {int} + + ))} + + )} + {step === 'sent' ? ( @@ -136,6 +152,26 @@ export function Verify(_props: {config: Exclude}) { )} + {step === 'sent' && ( + <> + + + + + Have a code?{' '} + { + setStep('token') + })}> + Click here. + + + + + )} + {step === 'default' ? ( <> {error && {error} } @@ -155,21 +191,29 @@ export function Verify(_props: {config: Exclude}) { /> - + {!config.hideInitialCodeButton && ( + <> + - - - Have a code?{' '} - { - setStep('token') - })}> - Click here. - - - + + + Have a code?{' '} + { + setStep('token') + })}> + Click here. + + + + + )} ) : step === 'token' ? ( <> diff --git a/src/components/dialogs/EmailDialog/types.ts b/src/components/dialogs/EmailDialog/types.ts index 9a8cc422b9..65124d9c32 100644 --- a/src/components/dialogs/EmailDialog/types.ts +++ b/src/components/dialogs/EmailDialog/types.ts @@ -14,13 +14,8 @@ export type Screen = } | { id: ScreenID.Verify - /** - * - default flow - * - new user blockers (x5) - */ instructions?: ReactNode[] - // onCloseWithoutVerifying, - // onCloseAfterVerifying, + hideInitialCodeButton?: boolean } export enum ScreenID { diff --git a/src/screens/Settings/components/Email2FAToggle.tsx b/src/screens/Settings/components/Email2FAToggle.tsx index 3e341cd738..d29d1960a9 100644 --- a/src/screens/Settings/components/Email2FAToggle.tsx +++ b/src/screens/Settings/components/Email2FAToggle.tsx @@ -1,11 +1,14 @@ import React from 'react' -import {msg} from '@lingui/macro' +import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {useAgent, useSession} from '#/state/session' import {useDialogControl} from '#/components/Dialog' -import {ChangeEmailDialog} from '#/components/dialogs/ChangeEmailDialog' -import {VerifyEmailDialog} from '#/components/dialogs/VerifyEmailDialog' +import { + EmailDialog, + EmailDialogScreenID, + useEmailDialogControl, +} from '#/components/dialogs/EmailDialog' import * as Prompt from '#/components/Prompt' import {DisableEmail2FADialog} from './DisableEmail2FADialog' import * as SettingsList from './SettingsList' @@ -15,9 +18,8 @@ export function Email2FAToggle() { const {currentAccount} = useSession() const disableDialogControl = useDialogControl() const enableDialogControl = useDialogControl() - const verifyEmailDialogControl = useDialogControl() - const changeEmailDialogControl = useDialogControl() const agent = useAgent() + const emailDialogControl = useEmailDialogControl() const enableEmailAuthFactor = React.useCallback(async () => { if (currentAccount?.email) { @@ -37,7 +39,16 @@ export function Email2FAToggle() { disableDialogControl.open() } else { if (!currentAccount.emailConfirmed) { - verifyEmailDialogControl.open() + emailDialogControl.open({ + id: EmailDialogScreenID.Verify, + hideInitialCodeButton: true, + instructions: [ + + You need to verify your email address before you can enable email + 2FA. + , + ], + }) return } enableDialogControl.open() @@ -45,8 +56,8 @@ export function Email2FAToggle() { }, [ currentAccount, enableDialogControl, - verifyEmailDialogControl, disableDialogControl, + emailDialogControl, ]) return ( @@ -59,18 +70,7 @@ export function Email2FAToggle() { onConfirm={enableEmailAuthFactor} confirmButtonCta={_(msg`Enable`)} /> - - +