Skip to content

Commit

Permalink
Merge pull request #31782 from pac-guerreiro/feature/add-get-physical…
Browse files Browse the repository at this point in the history
…-card-button-and-necessary-routes

Request Physical Card Follow Up
  • Loading branch information
grgia authored Dec 19, 2023
2 parents 2641a24 + ca1b223 commit c0313c2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
3 changes: 1 addition & 2 deletions src/libs/GetPhysicalCardUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import {Login} from '@src/types/onyx';
import Navigation from './Navigation/Navigation';
Expand Down Expand Up @@ -82,7 +81,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);
}

/**
Expand Down
5 changes: 0 additions & 5 deletions src/libs/Navigation/linkTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@ export default function linkTo(navigation: NavigationContainerRef<RootStackParam
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;
}
Expand Down
24 changes: 16 additions & 8 deletions src/pages/settings/Wallet/ExpensifyCardPage.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -86,7 +86,7 @@ const propTypes = {
};

const defaultProps = {
cardList: {},
cardList: null,
draftValues: {
addressLine1: '',
addressLine2: '',
Expand Down Expand Up @@ -125,17 +125,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 <NotFoundPage onBackButtonPress={() => 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);

Expand Down Expand Up @@ -164,6 +168,10 @@ function ExpensifyCardPage({
const hasDetectedIndividualFraud = _.some(domainCards, (card) => card.fraud === CONST.EXPENSIFY_CARD.FRAUD_TYPES.INDIVIDUAL);
const cardDetailsErrorObject = cardDetailsError ? {error: cardDetailsError} : {};

if (isNotFound) {
return <NotFoundPage onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WALLET)} />;
}

return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
Expand Down

0 comments on commit c0313c2

Please sign in to comment.