Skip to content

Fix/57403 do not show feeds in pending state #57679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/libs/CardUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,15 @@ function isCustomFeed(feed: CompanyCardFeedWithNumber): boolean {
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));
}

function getCompanyFeeds(cardFeeds: OnyxEntry<CardFeeds>, shouldFilterOutRemovedFeeds = false): CompanyFeeds {
function getCompanyFeeds(cardFeeds: OnyxEntry<CardFeeds>, shouldFilterOutRemovedFeeds = false, shouldFilterOutPendingFeeds = false): CompanyFeeds {
return Object.fromEntries(
Object.entries(cardFeeds?.settings?.companyCards ?? {}).filter(([key, value]) => {
if (shouldFilterOutRemovedFeeds && value.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {
return false;
}
if (shouldFilterOutPendingFeeds && value.pending) {
return false;
}
return key !== CONST.EXPENSIFY_CARD.BANK;
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function WorkspaceMemberDetailsPage({personalDetails, policy, route}: WorkspaceM
const isCurrentUserOwner = policy?.owner === currentUserPersonalDetails?.login;
const ownerDetails = useMemo(() => personalDetails?.[policy?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID] ?? ({} as PersonalDetails), [personalDetails, policy?.ownerAccountID]);
const policyOwnerDisplayName = formatPhoneNumber(getDisplayNameOrDefault(ownerDetails)) ?? policy?.owner ?? '';
const hasMultipleFeeds = Object.values(getCompanyFeeds(cardFeeds)).filter((feed) => !feed.pending).length > 0;
const hasMultipleFeeds = Object.keys(getCompanyFeeds(cardFeeds, false, true)).length > 0;
const workspaceCards = getAllCardsForWorkspace(workspaceAccountID, cardList);

const policyApproverEmail = policy?.approver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function WorkspaceMemberNewCardPage({route, personalDetails}: WorkspaceMemberNew
const accountID = Number(route.params.accountID);
const memberLogin = personalDetails?.[accountID]?.login ?? '';
const memberName = personalDetails?.[accountID]?.firstName ? personalDetails?.[accountID]?.firstName : personalDetails?.[accountID]?.login;
const companyFeeds = getCompanyFeeds(cardFeeds);
const companyFeeds = getCompanyFeeds(cardFeeds, false, true);
const isFeedExpired = isSelectedFeedExpired((selectedFeed as CompanyCardFeed) ? cardFeeds?.settings?.oAuthAccountDetails?.[selectedFeed as CompanyCardFeed] : undefined);

const [list] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${selectedFeed}`);
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/CardUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ const companyCardsSettingsWithoutExpensifyBank = {
...companyCardsDirectFeedSettings,
};

const companyCardsSettingsWithOnePendingFeed = {
[CONST.COMPANY_CARD.FEED_BANK_NAME.MASTER_CARD]: {
pending: true,
},
[CONST.COMPANY_CARD.FEED_BANK_NAME.VISA]: {
pending: false,
},
};

const oAuthAccountDetails = {
[CONST.COMPANY_CARD.FEED_BANK_NAME.CHASE]: {
accountList: ['CREDIT CARD...6607', 'CREDIT CARD...5501'],
Expand Down Expand Up @@ -237,6 +246,13 @@ const cardFeedsCollection: OnyxCollection<CardFeeds> = {
companyCards: companyCardsCustomVisaFeedSettingsWithNumbers,
},
},

// Policy with one pending feed
FAKE_ID_6: {
settings: {
companyCards: companyCardsSettingsWithOnePendingFeed,
},
},
};

/* eslint-disable @typescript-eslint/naming-convention */
Expand Down Expand Up @@ -379,6 +395,11 @@ describe('CardUtils', () => {
const companyFeeds = getCompanyFeeds(undefined);
expect(companyFeeds).toStrictEqual({});
});

it('Should return only feeds that are not pending', () => {
const companyFeeds = getCompanyFeeds(cardFeedsCollection.FAKE_ID_4, false, true);
expect(Object.keys(companyFeeds).length).toStrictEqual(1);
});
});

describe('getSelectedFeed', () => {
Expand Down