From 800d2b1ab29eb344244d3ce325eca31f7c59305a Mon Sep 17 00:00:00 2001 From: Pedro Guerreiro Date: Wed, 22 Nov 2023 23:02:57 +0000 Subject: [PATCH 1/2] fix(expensify card page): not found state showing up and disappearing immediately --- .../settings/Wallet/ExpensifyCardPage.js | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/pages/settings/Wallet/ExpensifyCardPage.js b/src/pages/settings/Wallet/ExpensifyCardPage.js index e92fca171817..beee9d63d984 100644 --- a/src/pages/settings/Wallet/ExpensifyCardPage.js +++ b/src/pages/settings/Wallet/ExpensifyCardPage.js @@ -1,5 +1,5 @@ import PropTypes from 'prop-types'; -import React, {useState} from 'react'; +import React, {useEffect, useMemo, useState} from 'react'; import {ScrollView, View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; @@ -87,7 +87,7 @@ const propTypes = { }; const defaultProps = { - cardList: {}, + cardList: null, draftValues: { addressLine1: '', addressLine2: '', @@ -127,17 +127,21 @@ function ExpensifyCardPage({ const styles = useThemeStyles(); const {isOffline} = useNetwork(); const {translate} = useLocalize(); - const domainCards = CardUtils.getDomainCards(cardList)[domain]; - const virtualCard = _.find(domainCards, (card) => card.isVirtual) || {}; - const physicalCard = _.find(domainCards, (card) => !card.isVirtual) || {}; + const domainCards = useMemo(() => cardList && CardUtils.getDomainCards(cardList)[domain], [cardList, domain]); + const virtualCard = useMemo(() => (domainCards && _.find(domainCards, (card) => card.isVirtual)) || {}, [domainCards]); + const physicalCard = useMemo(() => (domainCards && _.find(domainCards, (card) => !card.isVirtual)) || {}, [domainCards]); const [isLoading, setIsLoading] = useState(false); + const [isNotFound, setIsNotFound] = useState(false); const [details, setDetails] = useState({}); const [cardDetailsError, setCardDetailsError] = useState(''); - if (_.isEmpty(virtualCard) && _.isEmpty(physicalCard)) { - return Navigation.goBack(ROUTES.SETTINGS_WALLET)} />; - } + useEffect(() => { + if (!cardList) { + return; + } + setIsNotFound(_.isEmpty(virtualCard) && _.isEmpty(physicalCard)); + }, [cardList, physicalCard, virtualCard]); const formattedAvailableSpendAmount = CurrencyUtils.convertToDisplayString(physicalCard.availableSpend || virtualCard.availableSpend || 0); @@ -166,6 +170,10 @@ function ExpensifyCardPage({ const hasDetectedIndividualFraud = _.some(domainCards, (card) => card.fraud === CONST.EXPENSIFY_CARD.FRAUD_TYPES.INDIVIDUAL); const cardDetailsErrorObject = cardDetailsError ? {error: cardDetailsError} : {}; + if (isNotFound) { + return Navigation.goBack(ROUTES.SETTINGS_WALLET)} />; + } + return ( Date: Thu, 23 Nov 2023 12:19:13 +0000 Subject: [PATCH 2/2] fix(get physical card): weird back button behaviour --- src/libs/GetPhysicalCardUtils.ts | 2 +- src/libs/Navigation/linkTo.js | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/libs/GetPhysicalCardUtils.ts b/src/libs/GetPhysicalCardUtils.ts index 57a9d773cc9d..80391108e377 100644 --- a/src/libs/GetPhysicalCardUtils.ts +++ b/src/libs/GetPhysicalCardUtils.ts @@ -82,7 +82,7 @@ function setCurrentRoute(currentRoute: string, domain: string, privatePersonalDe } // Redirect the user if he's not allowed to be on the current step - Navigation.navigate(expectedRoute, CONST.NAVIGATION.ACTION_TYPE.REPLACE); + Navigation.goBack(expectedRoute); } /** diff --git a/src/libs/Navigation/linkTo.js b/src/libs/Navigation/linkTo.js index ca87a0d7b79c..db8b0493272c 100644 --- a/src/libs/Navigation/linkTo.js +++ b/src/libs/Navigation/linkTo.js @@ -89,11 +89,6 @@ export default function linkTo(navigation, path, type, isActiveRoute) { if (!isActiveRoute && type === CONST.NAVIGATION.ACTION_TYPE.PUSH) { minimalAction.type = CONST.NAVIGATION.ACTION_TYPE.PUSH; } - // There are situations when the user is trying to access a route which he has no access to - // So we want to redirect him to the right one and replace the one he tried to access - if (type === CONST.NAVIGATION.ACTION_TYPE.REPLACE) { - minimalAction.type = CONST.NAVIGATION.ACTION_TYPE.REPLACE; - } root.dispatch(minimalAction); return; }