Skip to content

Commit

Permalink
Merge pull request Expensify#53835 from thelullabyy/fix/53560-empty-c…
Browse files Browse the repository at this point in the history
…ard-page-can-be-opened-after-deactivating-card

Fix display not here page if card is deactivated
  • Loading branch information
mountiny authored Dec 11, 2024
2 parents 0cd91a6 + 0ff876d commit fb35d5c
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useCallback, useEffect, useState} from 'react';
import {View} from 'react-native';
import {InteractionManager, View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import ExpensifyCardImage from '@assets/images/expensify-card.svg';
import Badge from '@components/Badge';
Expand All @@ -25,13 +25,15 @@ import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
import * as PolicyUtils from '@libs/PolicyUtils';
import Navigation from '@navigation/Navigation';
import NotFoundPage from '@pages/ErrorPage/NotFoundPage';
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
import variables from '@styles/variables';
import * as Card from '@userActions/Card';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';

type WorkspaceExpensifyCardDetailsPageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.EXPENSIFY_CARD_DETAILS>;

Expand All @@ -48,7 +50,7 @@ function WorkspaceExpensifyCardDetailsPage({route}: WorkspaceExpensifyCardDetail
const styles = useThemeStyles();

const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
const [cardsList] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${CONST.EXPENSIFY_CARD.BANK}`);
const [cardsList, cardsListResult] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${CONST.EXPENSIFY_CARD.BANK}`);

const card = cardsList?.[cardID];
const cardholder = personalDetails?.[card?.accountID ?? -1];
Expand All @@ -68,10 +70,16 @@ function WorkspaceExpensifyCardDetailsPage({route}: WorkspaceExpensifyCardDetail

const deactivateCard = () => {
setIsDeactivateModalVisible(false);
Card.deactivateCard(workspaceAccountID, card);
Navigation.goBack();
InteractionManager.runAfterInteractions(() => {
Card.deactivateCard(workspaceAccountID, card);
});
};

if (!card && !isLoadingOnyxValue(cardsListResult)) {
return <NotFoundPage />;
}

return (
<AccessOrNotFoundWrapper
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.PAID]}
Expand Down

0 comments on commit fb35d5c

Please sign in to comment.