Skip to content

Commit

Permalink
Merge pull request #52741 from bernhardoj/fix/52339-no-rhp-close-anim…
Browse files Browse the repository at this point in the history
…ation

Fix no close animation of 2fa validate screen
  • Loading branch information
mountiny authored Nov 25, 2024
2 parents 38568ed + 7150429 commit d7ee957
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/hooks/useBeforeRemove.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {useNavigation} from '@react-navigation/native';
import {useEffect} from 'react';

const useBeforeRemove = (onBeforeRemove: () => void) => {
const navigation = useNavigation();

useEffect(() => {
const unsubscribe = navigation.addListener('beforeRemove', onBeforeRemove);
return unsubscribe;
}, [navigation, onBeforeRemove]);
};

export default useBeforeRemove;
3 changes: 3 additions & 0 deletions src/pages/ReimbursementAccount/ReimbursementAccountPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {useSession} from '@components/OnyxProvider';
import ReimbursementAccountLoadingIndicator from '@components/ReimbursementAccountLoadingIndicator';
import ScreenWrapper from '@components/ScreenWrapper';
import Text from '@components/Text';
import useBeforeRemove from '@hooks/useBeforeRemove';
import useEnvironment from '@hooks/useEnvironment';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
Expand Down Expand Up @@ -267,6 +268,8 @@ function ReimbursementAccountPage({route, policy}: ReimbursementAccountPageProps
BankAccounts.openReimbursementAccountPage(stepToOpen, subStep, localCurrentStep, policyIDParam);
}

useBeforeRemove(() => setIsValidateCodeActionModalVisible(false));

useEffect(() => {
if (isPreviousPolicy) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import ScreenWrapper from '@components/ScreenWrapper';
import ScrollView from '@components/ScrollView';
import Text from '@components/Text';
import ValidateCodeActionModal from '@components/ValidateCodeActionModal';
import useBeforeRemove from '@hooks/useBeforeRemove';
import useLocalize from '@hooks/useLocalize';
import usePrevious from '@hooks/usePrevious';
import useTheme from '@hooks/useTheme';
Expand Down Expand Up @@ -147,6 +148,8 @@ function ContactMethodDetailsPage({route}: ContactMethodDetailsPageProps) {
Navigation.goBack(ROUTES.SETTINGS_CONTACT_METHODS.getRoute(backTo));
}, [prevValidatedDate, loginData?.validatedDate, isDefaultContactMethod, backTo, loginData]);

useBeforeRemove(() => setIsValidateCodeActionModalVisible(false));

useEffect(() => {
setIsValidateCodeActionModalVisible(!loginData?.validatedDate);
}, [loginData?.validatedDate, loginData?.errorFields?.addedLogin]);
Expand Down
3 changes: 3 additions & 0 deletions src/pages/settings/Profile/Contacts/NewContactMethodPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ScreenWrapper from '@components/ScreenWrapper';
import Text from '@components/Text';
import TextInput from '@components/TextInput';
import ValidateCodeActionModal from '@components/ValidateCodeActionModal';
import useBeforeRemove from '@hooks/useBeforeRemove';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ErrorUtils from '@libs/ErrorUtils';
Expand Down Expand Up @@ -64,6 +65,8 @@ function NewContactMethodPage({route}: NewContactMethodPageProps) {
[pendingContactAction?.contactMethod],
);

useBeforeRemove(() => setIsValidateCodeActionModalVisible(false));

useEffect(() => {
if (!pendingContactAction?.actionVerified) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {FallbackAvatar} from '@components/Icon/Expensicons';
import MenuItem from '@components/MenuItem';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import Text from '@components/Text';
import useBeforeRemove from '@hooks/useBeforeRemove';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -37,6 +38,8 @@ function ConfirmDelegatePage({route}: ConfirmDelegatePageProps) {
const formattedLogin = formatPhoneNumber(login ?? '');
const displayName = personalDetails?.displayName ?? formattedLogin;

useBeforeRemove(() => setIsValidateCodeActionModalVisible(false));

const submitButton = (
<Button
success
Expand Down
13 changes: 11 additions & 2 deletions src/pages/settings/Security/TwoFactorAuth/Steps/CodesStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ScrollView from '@components/ScrollView';
import Section from '@components/Section';
import Text from '@components/Text';
import ValidateCodeActionModal from '@components/ValidateCodeActionModal';
import useBeforeRemove from '@hooks/useBeforeRemove';
import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTheme from '@hooks/useTheme';
Expand Down Expand Up @@ -56,9 +57,12 @@ function CodesStep({backTo}: CodesStepProps) {
const validateLoginError = ErrorUtils.getEarliestErrorField(loginData, 'validateLogin');
const hasMagicCodeBeenSent = !!validateCodeAction?.validateCodeSent;

const [isValidateModalVisible, setIsValidateModalVisible] = useState(!isUserValidated);

const {setStep} = useTwoFactorAuthContext();

useEffect(() => {
setIsValidateModalVisible(!isUserValidated);
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
if (account?.requiresTwoFactorAuth || account?.recoveryCodes || !isUserValidated) {
return;
Expand All @@ -67,6 +71,8 @@ function CodesStep({backTo}: CodesStepProps) {
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps -- We want to run this when component mounts
}, [isUserValidated]);

useBeforeRemove(() => setIsValidateModalVisible(false));

return (
<StepWrapper
title={translate('twoFactorAuth.headerTitle')}
Expand Down Expand Up @@ -173,15 +179,18 @@ function CodesStep({backTo}: CodesStepProps) {
title={translate('contacts.validateAccount')}
descriptionPrimary={translate('contacts.featureRequiresValidate')}
descriptionSecondary={translate('contacts.enterMagicCode', {contactMethod})}
isVisible={!isUserValidated}
isVisible={isValidateModalVisible}
hasMagicCodeBeenSent={hasMagicCodeBeenSent}
validatePendingAction={loginData?.pendingFields?.validateCodeSent}
sendValidateCode={() => User.requestValidateCodeAction()}
handleSubmitForm={(validateCode) => User.validateSecondaryLogin(loginList, contactMethod, validateCode, true)}
validateError={!isEmptyObject(validateLoginError) ? validateLoginError : ErrorUtils.getLatestErrorField(loginData, 'validateCodeSent')}
clearError={() => User.clearContactMethodErrors(contactMethod, !isEmptyObject(validateLoginError) ? 'validateLogin' : 'validateCodeSent')}
onModalHide={() => {}}
onClose={() => TwoFactorAuthActions.quitAndNavigateBack(backTo)}
onClose={() => {
setIsValidateModalVisible(false);
TwoFactorAuthActions.quitAndNavigateBack(backTo);
}}
/>
</ScrollView>
</StepWrapper>
Expand Down
3 changes: 3 additions & 0 deletions src/pages/settings/Wallet/Card/BaseGetPhysicalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import Text from '@components/Text';
import ValidateCodeActionModal from '@components/ValidateCodeActionModal';
import useBeforeRemove from '@hooks/useBeforeRemove';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as FormActions from '@libs/actions/FormActions';
Expand Down Expand Up @@ -105,6 +106,8 @@ function BaseGetPhysicalCard({
const [currentCardID, setCurrentCardID] = useState<string | undefined>(cardToBeIssued?.cardID.toString());
const errorMessage = ErrorUtils.getLatestErrorMessageField(cardToBeIssued);

useBeforeRemove(() => setActionCodeModalVisible(false));

useEffect(() => {
if (isRouteSet.current || !privatePersonalDetails || !cardList) {
return;
Expand Down
4 changes: 4 additions & 0 deletions src/pages/settings/Wallet/ExpensifyCardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import ScreenWrapper from '@components/ScreenWrapper';
import ScrollView from '@components/ScrollView';
import ValidateCodeActionModal from '@components/ValidateCodeActionModal';
import useBeforeRemove from '@hooks/useBeforeRemove';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -84,6 +85,9 @@ function ExpensifyCardPage({
}
return [cardList?.[cardID]];
}, [shouldDisplayCardDomain, cardList, cardID, domain]);

useBeforeRemove(() => setIsValidateCodeActionModalVisible(false));

useEffect(() => {
setIsNotFound(!cardsToShow);
}, [cardList, cardsToShow]);
Expand Down
3 changes: 3 additions & 0 deletions src/pages/settings/Wallet/ReportCardLostPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ScreenWrapper from '@components/ScreenWrapper';
import SingleOptionSelector from '@components/SingleOptionSelector';
import Text from '@components/Text';
import ValidateCodeActionModal from '@components/ValidateCodeActionModal';
import useBeforeRemove from '@hooks/useBeforeRemove';
import useLocalize from '@hooks/useLocalize';
import usePrevious from '@hooks/usePrevious';
import useStyledSafeAreaInsets from '@hooks/useStyledSafeAreaInsets';
Expand Down Expand Up @@ -83,6 +84,8 @@ function ReportCardLostPage({
const formattedAddress = PersonalDetailsUtils.getFormattedAddress(privatePersonalDetails ?? {});
const primaryLogin = account?.primaryLogin ?? '';

useBeforeRemove(() => setIsValidateCodeActionModalVisible(false));

useEffect(() => {
if (!isEmptyObject(physicalCard?.errors) || !(prevIsLoading && !formData?.isLoading)) {
return;
Expand Down
3 changes: 3 additions & 0 deletions src/pages/settings/Wallet/ReportVirtualCardFraudPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import Text from '@components/Text';
import ValidateCodeActionModal from '@components/ValidateCodeActionModal';
import useBeforeRemove from '@hooks/useBeforeRemove';
import useLocalize from '@hooks/useLocalize';
import usePrevious from '@hooks/usePrevious';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -45,6 +46,8 @@ function ReportVirtualCardFraudPage({

const prevIsLoading = usePrevious(formData?.isLoading);

useBeforeRemove(() => setIsValidateCodeActionModalVisible(false));

useEffect(() => {
if (!prevIsLoading || formData?.isLoading) {
return;
Expand Down
3 changes: 3 additions & 0 deletions src/pages/settings/Wallet/VerifyAccountPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import ValidateCodeActionModal from '@components/ValidateCodeActionModal';
import useBeforeRemove from '@hooks/useBeforeRemove';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ErrorUtils from '@libs/ErrorUtils';
Expand All @@ -31,6 +32,8 @@ function VerifyAccountPage({route}: VerifyAccountPageProps) {

const navigateBackTo = route?.params?.backTo;

useBeforeRemove(() => setIsValidateCodeActionModalVisible(false));

useEffect(() => () => User.clearUnvalidatedNewContactMethodAction(), []);

const handleSubmitForm = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import ScrollView from '@components/ScrollView';
import Text from '@components/Text';
import ValidateCodeActionModal from '@components/ValidateCodeActionModal';
import useBeforeRemove from '@hooks/useBeforeRemove';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -46,6 +47,8 @@ function ConfirmationStep({policyID, backTo}: ConfirmationStepProps) {

const submitButton = useRef<View>(null);

useBeforeRemove(() => setIsValidateCodeActionModalVisible(false));

useEffect(() => {
submitButton.current?.focus();
}, []);
Expand Down

0 comments on commit d7ee957

Please sign in to comment.