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

Display company cards #29718

Merged
merged 8 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
26 changes: 16 additions & 10 deletions src/components/OfflineWithFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ const propTypes = {

/** Whether to apply needsOffscreenAlphaCompositing prop to the children */
needsOffscreenAlphaCompositing: PropTypes.bool,

/** Whether we can dismiss the error message */
canDismissError: PropTypes.bool,
};

const defaultProps = {
Expand All @@ -72,6 +75,7 @@ const defaultProps = {
errorRowStyles: [],
shouldDisableStrikeThrough: false,
needsOffscreenAlphaCompositing: false,
canDismissError: true,
};

/**
Expand Down Expand Up @@ -130,16 +134,18 @@ function OfflineWithFeedback(props) {
messages={errorMessages}
type="error"
/>
<Tooltip text={translate('common.close')}>
<PressableWithoutFeedback
onPress={props.onClose}
style={[styles.touchableButtonImage]}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON}
accessibilityLabel={translate('common.close')}
>
<Icon src={Expensicons.Close} />
</PressableWithoutFeedback>
</Tooltip>
{props.canDismissError && (
<Tooltip text={translate('common.close')}>
<PressableWithoutFeedback
onPress={props.onClose}
style={[styles.touchableButtonImage]}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON}
accessibilityLabel={translate('common.close')}
>
<Icon src={Expensicons.Close} />
</PressableWithoutFeedback>
</Tooltip>
)}
</View>
)}
</View>
Expand Down
10 changes: 1 addition & 9 deletions src/libs/CardUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import lodash from 'lodash';
import Onyx from 'react-native-onyx';
import {Card} from '../types/onyx';
import CONST from '../CONST';
import * as Localize from './Localize';
import * as OnyxTypes from '../types/onyx';
Expand Down Expand Up @@ -60,13 +59,6 @@ function getYearFromExpirationDateString(expirationDateString: string) {
return cardYear.length === 2 ? `20${cardYear}` : cardYear;
}

function getCompanyCards(cardList: {string: Card}) {
if (!cardList) {
return [];
}
return Object.values(cardList).filter((card) => card.bank !== CONST.EXPENSIFY_CARD.BANK);
}

/**
* @param cardList - collection of assigned cards
* @returns collection of assigned cards grouped by domain
Expand Down Expand Up @@ -96,4 +88,4 @@ function maskCard(lastFour = ''): string {
return maskedString.replace(/(.{4})/g, '$1 ').trim();
}

export {isExpensifyCard, getDomainCards, getCompanyCards, getMonthFromExpirationDateString, getYearFromExpirationDateString, maskCard, getCardDescription};
export {isExpensifyCard, getDomainCards, getMonthFromExpirationDateString, getYearFromExpirationDateString, maskCard, getCardDescription};
29 changes: 23 additions & 6 deletions src/pages/settings/Wallet/PaymentMethodList.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import Navigation from '../../../libs/Navigation/Navigation';
import ROUTES from '../../../ROUTES';
import getBankIcon from '../../../components/Icon/BankIcons';
import assignedCardPropTypes from './assignedCardPropTypes';
import * as CardUtils from '../../../libs/CardUtils';

const propTypes = {
/** What to do when a menu item is pressed */
Expand Down Expand Up @@ -124,6 +125,11 @@ const defaultProps = {
* @param {Object} item
*/
function dismissError(item) {
// Users can't dismiss company card errors because there's nothing they can do about it besides contacting their admin
if (item.canDismissError === false) {
return;
}
luacmartins marked this conversation as resolved.
Show resolved Hide resolved

const isBankAccount = item.accountType === CONST.PAYMENT_METHODS.BANK_ACCOUNT;
const paymentList = isBankAccount ? ONYXKEYS.BANK_ACCOUNT_LIST : ONYXKEYS.FUND_LIST;
const paymentID = isBankAccount ? lodashGet(item, ['accountData', 'bankAccountID'], '') : lodashGet(item, ['accountData', 'fundID'], '');
Expand Down Expand Up @@ -199,14 +205,23 @@ function PaymentMethodList({
const paymentCardList = fundList || {};

if (shouldShowAssignedCards) {
const assignedCards = _.filter(cardList, (card) => CONST.EXPENSIFY_CARD.ACTIVE_STATES.includes(card.state));
const assignedCards = _.chain(cardList)
.filter((card) => CONST.EXPENSIFY_CARD.ACTIVE_STATES.includes(card.state))
.sortBy((card) => (CardUtils.isExpensifyCard(card.cardID) ? 0 : 1))
.value();

return _.map(assignedCards, (card) => {
const icon = getBankIcon(card.bank);
const isExpensifyCard = CardUtils.isExpensifyCard(card.cardID);
return {
key: card.key,
title: translate('walletPage.expensifyCard'),
key: card.cardID,
title: isExpensifyCard ? translate('walletPage.expensifyCard') : card.cardName,
description: card.domainName,
onPress: () => Navigation.navigate(ROUTES.SETTINGS_WALLET_DOMAINCARDS.getRoute(card.domainName)),
onPress: isExpensifyCard ? () => Navigation.navigate(ROUTES.SETTINGS_WALLET_DOMAINCARDS.getRoute(card.domainName)) : () => {},
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can keep the onPress as is because interactive being false should prevent the onPress from being triggered, no?

shouldShowRightIcon: isExpensifyCard,
interactive: isExpensifyCard,
canDismissError: isExpensifyCard,
errors: card.errors,
...icon,
};
});
Expand Down Expand Up @@ -274,6 +289,7 @@ function PaymentMethodList({
pendingAction={item.pendingAction}
errors={item.errors}
errorRowStyles={styles.ph6}
canDismissError={item.canDismissError}
>
<MenuItem
onPress={item.onPress}
Expand All @@ -286,13 +302,14 @@ function PaymentMethodList({
iconWidth={item.iconSize}
badgeText={shouldShowDefaultBadge(filteredPaymentMethods, item.isDefault) ? translate('paymentMethodList.defaultPaymentMethod') : null}
wrapperStyle={styles.paymentMethod}
shouldShowRightIcon={shouldShowAssignedCards}
shouldShowRightIcon={item.shouldShowRightIcon}
shouldShowSelectedState={shouldShowSelectedState}
isSelected={selectedMethodID === item.methodID}
interactive={item.interactive}
/>
</OfflineWithFeedback>
),
[filteredPaymentMethods, translate, shouldShowAssignedCards, shouldShowSelectedState, selectedMethodID],
[filteredPaymentMethods, translate, shouldShowSelectedState, selectedMethodID],
);

return (
Expand Down
Loading