Skip to content
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

fix: show the cards assigned to members #51467

Merged
Changes from all 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
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Card doesn't display on the member detail page, because fundID isn't exist on expensifyCards

Screen.Recording.2024-10-30.at.21.26.42.mov

@koko57 Do you know why we add workspaceAccountID.toString() === card.fundID condition before?

cc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure, I just left this condition as it was

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ECards should have fundID too 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}, [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
Loading