Skip to content

Commit

Permalink
Merge pull request #57202 from Expensify/neil-xero-2fa-disable
Browse files Browse the repository at this point in the history
Display Xero disable 2FA error from backend
  • Loading branch information
MarioExpensify authored Mar 10, 2025
2 parents ccc4d65 + 60d4e6d commit d9bc5a6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
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 @@ -1090,6 +1090,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 @@ -1349,4 +1353,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();
}, []);

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

0 comments on commit d9bc5a6

Please sign in to comment.