Skip to content

Commit

Permalink
Merge pull request #51467 from callstack-internal/fix/50441-cards-not…
Browse files Browse the repository at this point in the history
…-shown-for-member

fix: show the cards assigned to members
  • Loading branch information
mountiny authored Oct 31, 2024
2 parents e7532e9 + 02da13c commit 9400244
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ function WorkspaceMemberDetailsPage({personalDetails, policy, route}: WorkspaceM
const {translate} = useLocalize();
const StyleUtils = useStyleUtils();
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const [allCardsList] = useOnyx(`${ONYXKEYS.CARD_LIST}`);
const [cards] = useOnyx(`${ONYXKEYS.CARD_LIST}`);
const [expensifyCards] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${CONST.EXPENSIFY_CARD.BANK}`);
const [cardFeeds] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`);
const [cardSettings] = useOnyx(`${ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`);

Expand Down Expand Up @@ -89,11 +90,22 @@ function WorkspaceMemberDetailsPage({personalDetails, policy, route}: WorkspaceM
}, [policyID, workspaceAccountID]);

const memberCards = useMemo(() => {
if (!allCardsList) {
if (!cards && !expensifyCards) {
return [];
}
return Object.values(allCardsList ?? {}).filter((card) => card.accountID === accountID && workspaceAccountID.toString() === card.fundID);
}, [allCardsList, accountID, workspaceAccountID]);
// For admin Expensify Cards can also appear in the cards list, so we need to remove duplicates
const allCards = [...Object.values(cards ?? {}), ...Object.values(expensifyCards ?? {})];
const cardIDs = new Set();
const uniqueObjects = allCards.filter((obj) => {
if (cardIDs.has(obj.cardID)) {
return false;
}
cardIDs.add(obj.cardID);
return true;
});

return Object.values(uniqueObjects ?? {}).filter((card) => card.accountID === accountID && workspaceAccountID.toString() === card.fundID);
}, [accountID, workspaceAccountID, cards, expensifyCards]);

const confirmModalPrompt = useMemo(() => {
const isApprover = Member.isApprover(policy, accountID);
Expand Down Expand Up @@ -303,7 +315,7 @@ function WorkspaceMemberDetailsPage({personalDetails, policy, route}: WorkspaceM
{translate('walletPage.assignedCards')}
</Text>
</View>
{memberCards.map((memberCard) => (
{(memberCards as MemberCard[]).map((memberCard) => (
<MenuItem
key={memberCard.cardID}
title={memberCard.nameValuePairs?.cardTitle ?? memberCard?.cardName}
Expand Down

0 comments on commit 9400244

Please sign in to comment.