Skip to content

Commit 5e18eed

Browse files
authored
Merge pull request #57679 from callstack-internal/fix/57403-do-not-show-feeds-in-pending-state
Fix/57403 do not show feeds in pending state
2 parents 7009fe8 + ef31d09 commit 5e18eed

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

src/libs/CardUtils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,15 @@ function isCustomFeed(feed: CompanyCardFeedWithNumber): boolean {
308308
return [CONST.COMPANY_CARD.FEED_BANK_NAME.MASTER_CARD, CONST.COMPANY_CARD.FEED_BANK_NAME.VISA, CONST.COMPANY_CARD.FEED_BANK_NAME.AMEX].some((value) => feed.startsWith(value));
309309
}
310310

311-
function getCompanyFeeds(cardFeeds: OnyxEntry<CardFeeds>, shouldFilterOutRemovedFeeds = false): CompanyFeeds {
311+
function getCompanyFeeds(cardFeeds: OnyxEntry<CardFeeds>, shouldFilterOutRemovedFeeds = false, shouldFilterOutPendingFeeds = false): CompanyFeeds {
312312
return Object.fromEntries(
313313
Object.entries(cardFeeds?.settings?.companyCards ?? {}).filter(([key, value]) => {
314314
if (shouldFilterOutRemovedFeeds && value.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {
315315
return false;
316316
}
317+
if (shouldFilterOutPendingFeeds && value.pending) {
318+
return false;
319+
}
317320
return key !== CONST.EXPENSIFY_CARD.BANK;
318321
}),
319322
);

src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function WorkspaceMemberDetailsPage({personalDetails, policy, route}: WorkspaceM
8686
const isCurrentUserOwner = policy?.owner === currentUserPersonalDetails?.login;
8787
const ownerDetails = useMemo(() => personalDetails?.[policy?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID] ?? ({} as PersonalDetails), [personalDetails, policy?.ownerAccountID]);
8888
const policyOwnerDisplayName = formatPhoneNumber(getDisplayNameOrDefault(ownerDetails)) ?? policy?.owner ?? '';
89-
const hasMultipleFeeds = Object.values(getCompanyFeeds(cardFeeds)).filter((feed) => !feed.pending).length > 0;
89+
const hasMultipleFeeds = Object.keys(getCompanyFeeds(cardFeeds, false, true)).length > 0;
9090
const workspaceCards = getAllCardsForWorkspace(workspaceAccountID, cardList);
9191

9292
const policyApproverEmail = policy?.approver;

src/pages/workspace/members/WorkspaceMemberNewCardPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function WorkspaceMemberNewCardPage({route, personalDetails}: WorkspaceMemberNew
6262
const accountID = Number(route.params.accountID);
6363
const memberLogin = personalDetails?.[accountID]?.login ?? '';
6464
const memberName = personalDetails?.[accountID]?.firstName ? personalDetails?.[accountID]?.firstName : personalDetails?.[accountID]?.login;
65-
const companyFeeds = getCompanyFeeds(cardFeeds);
65+
const companyFeeds = getCompanyFeeds(cardFeeds, false, true);
6666
const isFeedExpired = isSelectedFeedExpired((selectedFeed as CompanyCardFeed) ? cardFeeds?.settings?.oAuthAccountDetails?.[selectedFeed as CompanyCardFeed] : undefined);
6767

6868
const [list] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${selectedFeed}`);

tests/unit/CardUtilsTest.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ const companyCardsSettingsWithoutExpensifyBank = {
9797
...companyCardsDirectFeedSettings,
9898
};
9999

100+
const companyCardsSettingsWithOnePendingFeed = {
101+
[CONST.COMPANY_CARD.FEED_BANK_NAME.MASTER_CARD]: {
102+
pending: true,
103+
},
104+
[CONST.COMPANY_CARD.FEED_BANK_NAME.VISA]: {
105+
pending: false,
106+
},
107+
};
108+
100109
const oAuthAccountDetails = {
101110
[CONST.COMPANY_CARD.FEED_BANK_NAME.CHASE]: {
102111
accountList: ['CREDIT CARD...6607', 'CREDIT CARD...5501'],
@@ -237,6 +246,13 @@ const cardFeedsCollection: OnyxCollection<CardFeeds> = {
237246
companyCards: companyCardsCustomVisaFeedSettingsWithNumbers,
238247
},
239248
},
249+
250+
// Policy with one pending feed
251+
FAKE_ID_6: {
252+
settings: {
253+
companyCards: companyCardsSettingsWithOnePendingFeed,
254+
},
255+
},
240256
};
241257

242258
/* eslint-disable @typescript-eslint/naming-convention */
@@ -379,6 +395,11 @@ describe('CardUtils', () => {
379395
const companyFeeds = getCompanyFeeds(undefined);
380396
expect(companyFeeds).toStrictEqual({});
381397
});
398+
399+
it('Should return only feeds that are not pending', () => {
400+
const companyFeeds = getCompanyFeeds(cardFeedsCollection.FAKE_ID_6, false, true);
401+
expect(Object.keys(companyFeeds).length).toStrictEqual(1);
402+
});
382403
});
383404

384405
describe('getSelectedFeed', () => {

0 commit comments

Comments
 (0)