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: use pattern B for unassigning cards #52357

Merged
Show file tree
Hide file tree
Changes from 5 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
25 changes: 23 additions & 2 deletions src/libs/actions/CompanyCards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,27 @@ function unassignWorkspaceCompanyCard(workspaceAccountID: number, bankName: stri

const onyxData: OnyxData = {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${bankName}`,
value: {
[cardID]: {
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.CARD_LIST,
value: {
[cardID]: {
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
},
},
},
],

successData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${bankName}`,
Expand All @@ -262,7 +283,7 @@ function unassignWorkspaceCompanyCard(workspaceAccountID: number, bankName: stri
key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${bankName}`,
value: {
[cardID]: {
...card,
pendingAction: null,
errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'),
},
},
Expand All @@ -272,7 +293,7 @@ function unassignWorkspaceCompanyCard(workspaceAccountID: number, bankName: stri
key: ONYXKEYS.CARD_LIST,
value: {
[cardID]: {
...card,
pendingAction: null,
errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function WorkspaceCompanyCardsList({cardsList, policyID}: WorkspaceCompanyCardsL
key={`${item.nameValuePairs?.cardTitle}_${index}`}
errorRowStyles={styles.ph5}
errors={item.errors}
pendingAction={item.pendingAction}
>
<PressableWithFeedback
role={CONST.ROLE.BUTTON}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function WorkspaceCompanyCardsListRow({cardholder, name, cardNumber}: WorkspaceC
<View style={[styles.flexRow, styles.justifyContentBetween, styles.alignItemsCenter, styles.br3, styles.p4]}>
<View style={[styles.flexRow, styles.gap3, styles.alignItemsCenter]}>
<Avatar
source={getDefaultAvatarURL(cardholder?.accountID)}
source={cardholder?.avatar ?? getDefaultAvatarURL(cardholder?.accountID)}
avatarID={cardholder?.accountID}
type={CONST.ICON_TYPE_AVATAR}
size={CONST.AVATAR_SIZE.DEFAULT}
Expand Down
51 changes: 32 additions & 19 deletions src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,25 +315,38 @@ function WorkspaceMemberDetailsPage({personalDetails, policy, route}: WorkspaceM
{translate('walletPage.assignedCards')}
</Text>
</View>
{(memberCards as MemberCard[]).map((memberCard) => (
<MenuItem
key={memberCard.cardID}
title={memberCard.nameValuePairs?.cardTitle ?? memberCard?.cardName}
badgeText={
memberCard.bank === CONST.EXPENSIFY_CARD.BANK
? CurrencyUtils.convertToDisplayString(memberCard.nameValuePairs?.unapprovedExpenseLimit)
: ''
}
icon={CardUtils.getCardFeedIcon(memberCard.bank as CompanyCardFeed)}
displayInDefaultIconColor
iconStyles={styles.cardIcon}
contentFit="contain"
iconWidth={variables.iconSizeExtraLarge}
iconHeight={variables.iconSizeExtraLarge}
onPress={() => navigateToDetails(memberCard)}
shouldShowRightIcon
/>
))}
{(memberCards as MemberCard[]).map((memberCard) => {
const isCardDeleted = memberCard.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const isCardDeleted = memberCard.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;

Copy link
Contributor Author

@koko57 koko57 Nov 12, 2024

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

@mountiny @koko57 It is consistency with the company card page. On the company card page, we still can access to detail card that is pending removed

Screen.Recording.2024-11-12.at.20.45.06.mov

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you should be able to visit that page because the card was already removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mountiny @DylanDylann I've just added the check to disable going to details page after unassigning

return (
<OfflineWithFeedback
key={`${memberCard.nameValuePairs?.cardTitle}_${memberCard.cardID}`}
errorRowStyles={styles.ph5}
errors={memberCard.errors}
pendingAction={memberCard.pendingAction}
>
<MenuItem
key={memberCard.cardID}
title={memberCard.nameValuePairs?.cardTitle ?? memberCard?.cardName}
badgeText={
memberCard.bank === CONST.EXPENSIFY_CARD.BANK
? CurrencyUtils.convertToDisplayString(memberCard.nameValuePairs?.unapprovedExpenseLimit)
: ''
}
icon={CardUtils.getCardFeedIcon(memberCard.bank as CompanyCardFeed)}
displayInDefaultIconColor
iconStyles={styles.cardIcon}
contentFit="contain"
iconWidth={variables.iconSizeExtraLarge}
iconHeight={variables.iconSizeExtraLarge}
onPress={() => navigateToDetails(memberCard)}
shouldRemoveHoverBackground={isCardDeleted}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
shouldRemoveHoverBackground={isCardDeleted}

Copy link
Contributor Author

@koko57 koko57 Nov 12, 2024

Choose a reason for hiding this comment

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

disabled={isCardDeleted}
shouldShowRightIcon={!isCardDeleted}
style={[isCardDeleted ? styles.offlineFeedback.deleted : {}]}
/>
Comment on lines +343 to +346
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
disabled={isCardDeleted}
shouldShowRightIcon={!isCardDeleted}
style={[isCardDeleted ? styles.offlineFeedback.deleted : {}]}
/>
shouldShowRightIcon

I believe that we shouldn't prevent user from going to detail card page

Copy link
Contributor Author

@koko57 koko57 Nov 12, 2024

Choose a reason for hiding this comment

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

</OfflineWithFeedback>
);
})}
<MenuItem
title={translate('workspace.expensifyCard.newCard')}
icon={Expensicons.Plus}
Expand Down
Loading