diff --git a/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx b/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx index 8f5c9b2994cd..6d865df7280b 100644 --- a/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx +++ b/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx @@ -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}`); @@ -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); @@ -303,7 +315,7 @@ function WorkspaceMemberDetailsPage({personalDetails, policy, route}: WorkspaceM {translate('walletPage.assignedCards')} - {memberCards.map((memberCard) => ( + {(memberCards as MemberCard[]).map((memberCard) => (