Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/Button/validateSubmitShortcut/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type ValidateSubmitShortcut from './types';

const IGNORED_NODE_NAMES = ['TEXTAREA', 'INPUT'];

/**
* Validate if the submit shortcut should be triggered depending on the button state
*
Expand All @@ -11,7 +13,9 @@ import type ValidateSubmitShortcut from './types';

const validateSubmitShortcut: ValidateSubmitShortcut = (isDisabled, isLoading, event) => {
const eventTarget = event?.target as HTMLElement;
if (isDisabled || isLoading || eventTarget.nodeName === 'TEXTAREA' || (eventTarget?.contentEditable === 'true' && eventTarget.ariaMultiLine)) {

// If the event target node is for an input, such as when there's a stray "Enter" event from an autocomplete input, then ignore it because it's not meant for this button
if (isDisabled || isLoading || IGNORED_NODE_NAMES.includes(eventTarget.nodeName) || (eventTarget?.contentEditable === 'true' && eventTarget.ariaMultiLine)) {
return false;
}

Expand Down
5 changes: 5 additions & 0 deletions src/libs/actions/Session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,10 @@ function toggleTwoFactorAuth(enable: boolean, twoFactorAuthCode = '') {
API.write(WRITE_COMMANDS.DISABLE_TWO_FACTOR_AUTH, params, {optimisticData, successData, failureData});
}

function clearDisableTwoFactorAuthErrors() {
Onyx.merge(ONYXKEYS.ACCOUNT, {errorFields: {requiresTwoFactorAuth: null}});
}

function updateAuthTokenAndOpenApp(authToken?: string, encryptedAuthToken?: string) {
// Update authToken in Onyx and in our local variables so that API requests will use the new authToken
updateSessionAuthTokens(authToken, encryptedAuthToken);
Expand Down Expand Up @@ -1341,4 +1345,5 @@ export {
validateUserAndGetAccessiblePolicies,
isUserOnPrivateDomain,
resetSMSDeliveryFailureStatus,
clearDisableTwoFactorAuthErrors,
};
22 changes: 21 additions & 1 deletion src/pages/settings/Security/TwoFactorAuth/DisablePage.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import React, {useEffect, useRef} from 'react';
import isEmpty from 'lodash/isEmpty';
import React, {useCallback, useEffect, useRef} from 'react';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import Button from '@components/Button';
import ConfirmModal from '@components/ConfirmModal';
import FixedFooter from '@components/FixedFooter';
import ScrollView from '@components/ScrollView';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import {clearDisableTwoFactorAuthErrors} from '@libs/actions/Session';
import Navigation from '@libs/Navigation/Navigation';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand All @@ -30,6 +33,13 @@ function DisablePage() {
Navigation.navigate(ROUTES.SETTINGS_2FA_DISABLED, {forceReplace: true});
}, [account?.requiresTwoFactorAuth]);

const closeModal = useCallback(() => {
clearDisableTwoFactorAuthErrors();

// Go back to the previous page because the user can't disable 2FA and this page is no longer relevant
Navigation.goBack();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Navigation.goBack();
Navigation.dismissModal();

Makes more sense ?

Copy link
Contributor Author

@neil-marcellini neil-marcellini Mar 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I specifically want to go back to the previous page. Is that the right way to do it? What would you advise and why?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me test both approaches and get back

}, []);

return (
<TwoFactorAuthWrapper
stepName={CONST.TWO_FACTOR_AUTH_STEPS.DISABLE}
Expand Down Expand Up @@ -60,6 +70,16 @@ function DisablePage() {
}}
/>
</FixedFooter>
<ConfirmModal
title={translate('twoFactorAuth.twoFactorAuthCannotDisable')}
prompt={translate('twoFactorAuth.twoFactorAuthRequired')}
confirmText={translate('common.buttonConfirm')}
onConfirm={closeModal}
shouldShowCancelButton={false}
onBackdropPress={closeModal}
onCancel={closeModal}
isVisible={!isEmpty(account?.errorFields?.requiresTwoFactorAuth ?? {})}
/>
</TwoFactorAuthWrapper>
);
}
Expand Down
3 changes: 3 additions & 0 deletions src/types/onyx/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ type Account = {
/** Authentication failure errors */
errors?: OnyxCommon.Errors | null;

/** Errors related to specific account fields */
errorFields?: OnyxCommon.ErrorFields;

/** Authentication success message */
success?: string;

Expand Down
Loading