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

create the Expensify card page #26915

Merged
merged 26 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5823d37
create the Expensify card page
pasyukevich Sep 6, 2023
453e747
feat(expensify card): add screen routing
pac-guerreiro Sep 8, 2023
8af9818
fix(expensify card): card holder label style
pac-guerreiro Sep 8, 2023
e3c1050
refactor(expensify card): apply code guidelines
pac-guerreiro Sep 8, 2023
20d1268
feat(expensify card): add virtual and physical card number rows
pac-guerreiro Sep 14, 2023
33cc565
fix type for route
pasyukevich Sep 14, 2023
597b319
update styles for card
pasyukevich Sep 14, 2023
9a04cf0
fix upper cased domain
pasyukevich Sep 14, 2023
1040f6b
adjust displayed card data
pasyukevich Sep 14, 2023
27e242d
fix styles file after rebase
pasyukevich Sep 14, 2023
c57bb86
fix conditional rendering to a boolean
pasyukevich Sep 15, 2023
4161195
fix translation for card page
pasyukevich Sep 15, 2023
fc90f3d
fix crash with empty card list state
pasyukevich Sep 15, 2023
b043af1
add showing not found page in case of empty cards
pasyukevich Sep 18, 2023
f0595c0
Merge branch 'main' into feature/expensify-card
pasyukevich Sep 19, 2023
33325ce
update card holder name width
pasyukevich Sep 20, 2023
c864fe7
update prop types for card page
pasyukevich Sep 20, 2023
901301a
fix empty card handling
pasyukevich Sep 21, 2023
557bccc
move style constants to variables
pasyukevich Sep 21, 2023
137d1b9
Merge branch 'main' into feature/expensify-card
pasyukevich Sep 21, 2023
29c6685
update card types with new PAN
pasyukevich Sep 21, 2023
48debed
add maskCard helper to create mask card with PAN
pasyukevich Sep 21, 2023
fe87eb4
Merge branch 'main' into feature/expensify-card
JKobrynski Sep 22, 2023
2f92e75
Merge branch 'main' into feature/expensify-card
pasyukevich Sep 25, 2023
a22a2d6
add testID for expensify card page
pasyukevich Sep 25, 2023
a823f1a
add doc for session
pasyukevich Sep 25, 2023
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
69 changes: 69 additions & 0 deletions assets/images/expensify-card.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export default {
SETTINGS_ABOUT: 'settings/about',
SETTINGS_APP_DOWNLOAD_LINKS: 'settings/about/app-download-links',
SETTINGS_WALLET: 'settings/wallet',
SETTINGS_WALLET_DOMAINCARDS: '/settings/wallet/card/:domain',
getWalletCardRoute: (domain: string) => `/settings/wallet/card/${domain}`,
SETTINGS_ADD_DEBIT_CARD: 'settings/wallet/add-debit-card',
SETTINGS_ADD_BANK_ACCOUNT: 'settings/wallet/add-bank-account',
SETTINGS_ENABLE_PAYMENTS: 'settings/wallet/enable-payments',
Expand Down
67 changes: 67 additions & 0 deletions src/components/CardPreview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import PropTypes from 'prop-types';
import styles from '../styles/styles';
import Text from './Text';
import usePrivatePersonalDetails from '../hooks/usePrivatePersonalDetails';
import ONYXKEYS from '../ONYXKEYS';
import ExpensifyCardImage from '../../assets/images/expensify-card.svg';
import variables from '../styles/variables';

const propTypes = {
/** User's private personal details */
privatePersonalDetails: PropTypes.shape({
legalFirstName: PropTypes.string,
legalLastName: PropTypes.string,
}),
session: PropTypes.shape({
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a doc above this for completeness?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

/** Currently logged-in user email */
email: PropTypes.string,
}),
};

const defaultProps = {
privatePersonalDetails: {
legalFirstName: '',
legalLastName: '',
},
session: {
email: '',
},
};

function CardPreview({privatePersonalDetails: {legalFirstName, legalLastName}, session: {email}}) {
usePrivatePersonalDetails();
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB, but maybe this should be useFetchPrivatePersonalDetails() or something that maybe better explains what this does. Started some conversation here but not a blocker for this PR.

const cardHolder = legalFirstName && legalLastName ? `${legalFirstName} ${legalLastName}` : email;

return (
<View style={styles.walletCard}>
<ExpensifyCardImage
pointerEvents="none"
height={variables.cardPreviewHeight}
width={variables.cardPreviewWidth}
/>
<Text
style={styles.walletCardHolder}
numberOfLines={1}
ellipsizeMode="tail"
>
{cardHolder}
</Text>
</View>
);
}

CardPreview.propTypes = propTypes;
CardPreview.defaultProps = defaultProps;
CardPreview.displayName = 'CardPreview';

export default withOnyx({
privatePersonalDetails: {
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
},
session: {
key: ONYXKEYS.SESSION,
},
})(CardPreview);
6 changes: 6 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,12 @@ export default {
},
addBankAccountFailure: 'An unexpected error occurred while trying to add your bank account. Please try again.',
},
cardPage: {
expensifyCard: 'Expensify Card',
availableSpend: 'Remaining spending power',
virtualCardNumber: 'Virtual card number',
physicalCardNumber: 'Physical card number',
},
transferAmountPage: {
transfer: ({amount}: TransferParams) => `Transfer${amount ? ` ${amount}` : ''}`,
instant: 'Instant (Debit card)',
Expand Down
6 changes: 6 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,12 @@ export default {
},
addBankAccountFailure: 'Ocurrió un error inesperado al intentar añadir la cuenta bancaria. Inténtalo de nuevo.',
},
cardPage: {
expensifyCard: 'Tarjeta Expensify',
availableSpend: 'Capacidad de gasto restante',
virtualCardNumber: 'Número de la tarjeta virtual',
physicalCardNumber: 'Número de la tarjeta física',
},
transferAmountPage: {
transfer: ({amount}: TransferParams) => `Transferir${amount ? ` ${amount}` : ''}`,
instant: 'Instante',
Expand Down
33 changes: 32 additions & 1 deletion src/libs/CardUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import lodash from 'lodash';
import {Card} from '../types/onyx';
import CONST from '../CONST';
import * as OnyxTypes from '../types/onyx';

/**
* @returns string with a month in MM format
Expand All @@ -25,4 +27,33 @@ function getCompanyCards(cardList: {string: Card}) {
return Object.values(cardList).filter((card) => card.bank !== CONST.EXPENSIFY_CARD.BANK);
}

export {getMonthFromExpirationDateString, getYearFromExpirationDateString, getCompanyCards};
/**
* @param cardList - collection of assigned cards
* @returns collection of assigned cards grouped by domain
*/
function getDomainCards(cardList: Record<string, OnyxTypes.Card>) {
// eslint-disable-next-line you-dont-need-lodash-underscore/filter
Copy link
Contributor

Choose a reason for hiding this comment

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

Underscore/Lodash should no longer be used in Typescript files @pasyukevich

const activeCards = lodash.filter(cardList, (card) => [2, 3, 4, 7].includes(card.state));
return lodash.groupBy(activeCards, (card) => card.domainName.toLowerCase());
}

/**
* Returns a masked credit card string with spaces for every four symbols.
* If the last four digits are provided, all preceding digits will be masked.
* If not, the entire card string will be masked.
*
* @param [lastFour=""] - The last four digits of the card (optional).
* @returns - The masked card string.
*/
function maskCard(lastFour = ''): string {
const totalDigits = 16;
const maskedLength = totalDigits - lastFour.length;

// Create a string with '•' repeated for the masked portion
const maskedString = '•'.repeat(maskedLength) + lastFour;

// Insert space for every four symbols
return maskedString.replace(/(.{4})/g, '$1 ').trim();
}

export {getDomainCards, getCompanyCards, getMonthFromExpirationDateString, getYearFromExpirationDateString, maskCard};
7 changes: 7 additions & 0 deletions src/libs/Navigation/AppNavigator/ModalStackNavigators.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,13 @@ const SettingsModalStackNavigator = createModalStackNavigator([
},
name: 'Settings_Wallet',
},
{
getComponent: () => {
const SettingsWalletExpensifyCardPage = require('../../../pages/settings/Wallet/ExpensifyCardPage').default;
return SettingsWalletExpensifyCardPage;
},
name: 'Settings_Wallet_DomainCards',
},
{
getComponent: () => {
const TransferBalancePage = require('../../../pages/settings/Wallet/TransferBalancePage').default;
Expand Down
4 changes: 4 additions & 0 deletions src/libs/Navigation/linkingConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export default {
path: ROUTES.SETTINGS_WALLET,
exact: true,
},
Settings_Wallet_DomainCards: {
path: ROUTES.SETTINGS_WALLET_DOMAINCARDS,
exact: true,
},
Settings_Wallet_EnablePayments: {
path: ROUTES.SETTINGS_ENABLE_PAYMENTS,
exact: true,
Expand Down
104 changes: 104 additions & 0 deletions src/pages/settings/Wallet/ExpensifyCardPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import PropTypes from 'prop-types';
import React from 'react';
import {ScrollView, View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import ONYXKEYS from '../../../ONYXKEYS';
import ROUTES from '../../../ROUTES';
import NotFoundPage from '../../ErrorPage/NotFoundPage';
import CardPreview from '../../../components/CardPreview';
import HeaderWithBackButton from '../../../components/HeaderWithBackButton';
import MenuItemWithTopDescription from '../../../components/MenuItemWithTopDescription';
import ScreenWrapper from '../../../components/ScreenWrapper';
import assignedCardPropTypes from './assignedCardPropTypes';
import useLocalize from '../../../hooks/useLocalize';
import * as CurrencyUtils from '../../../libs/CurrencyUtils';
import Navigation from '../../../libs/Navigation/Navigation';
import styles from '../../../styles/styles';
import * as CardUtils from '../../../libs/CardUtils';

const propTypes = {
/* Onyx Props */
cardList: PropTypes.objectOf(assignedCardPropTypes),

pasyukevich marked this conversation as resolved.
Show resolved Hide resolved
/** Navigation route context info provided by react navigation */
route: PropTypes.shape({
params: PropTypes.shape({
/** domain passed via route /settings/wallet/card/:domain */
domain: PropTypes.string,
}),
}).isRequired,
};

const defaultProps = {
cardList: {},
};

function ExpensifyCardPage({
cardList,
route: {
params: {domain},
},
}) {
const {translate} = useLocalize();
const domainCards = CardUtils.getDomainCards(cardList)[domain];
const virtualCard = _.find(domainCards, (card) => card.isVirtual) || {};
const physicalCard = _.find(domainCards, (card) => !card.isVirtual) || {};

if (_.isEmpty(virtualCard) && _.isEmpty(physicalCard)) {
return <NotFoundPage />;
}

const formattedAvailableSpendAmount = CurrencyUtils.convertToDisplayString(physicalCard.availableSpend || virtualCard.availableSpend || 0);

return (
<ScreenWrapper includeSafeAreaPaddingBottom={false}>
{({safeAreaPaddingBottomStyle}) => (
<>
<HeaderWithBackButton
title={translate('cardPage.expensifyCard')}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WALLET)}
/>
<ScrollView contentContainerStyle={safeAreaPaddingBottomStyle}>
<View style={[styles.flex1, styles.mb4, styles.mt4]}>
<CardPreview />
</View>

<MenuItemWithTopDescription
description={translate('cardPage.availableSpend')}
title={formattedAvailableSpendAmount}
interactive={false}
titleStyle={styles.newKansasLarge}
/>
{!_.isEmpty(physicalCard) && (
<MenuItemWithTopDescription
description={translate('cardPage.virtualCardNumber')}
title={CardUtils.maskCard(virtualCard.lastFourPAN)}
interactive={false}
titleStyle={styles.walletCardNumber}
/>
)}
{!_.isEmpty(physicalCard) && (
<MenuItemWithTopDescription
description={translate('cardPage.physicalCardNumber')}
title={CardUtils.maskCard(physicalCard.lastFourPAN)}
interactive={false}
titleStyle={styles.walletCardNumber}
/>
)}
</ScrollView>
</>
)}
</ScreenWrapper>
);
}

ExpensifyCardPage.propTypes = propTypes;
ExpensifyCardPage.defaultProps = defaultProps;
ExpensifyCardPage.displayName = 'ExpensifyCardPage';

export default withOnyx({
cardList: {
key: ONYXKEYS.CARD_LIST,
},
})(ExpensifyCardPage);
20 changes: 20 additions & 0 deletions src/pages/settings/Wallet/assignedCardPropTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import PropTypes from 'prop-types';
import CONST from '../../../CONST';

/** Assigned Card props */
const assignedCardPropTypes = PropTypes.shape({
cardID: PropTypes.number,
state: PropTypes.number,
bank: PropTypes.string,
availableSpend: PropTypes.number,
domainName: PropTypes.string,
lastFourPAN: PropTypes.string,
cardName: PropTypes.string,
isVirtual: PropTypes.bool,
fraud: PropTypes.oneOf([CONST.EXPENSIFY_CARD.FRAUD_TYPES.DOMAIN, CONST.EXPENSIFY_CARD.FRAUD_TYPES.USER, CONST.EXPENSIFY_CARD.FRAUD_TYPES.NONE]),
cardholderFirstName: PropTypes.string,
cardholderLastName: PropTypes.string,
errors: PropTypes.objectOf(PropTypes.string),
});
grgia marked this conversation as resolved.
Show resolved Hide resolved

export default assignedCardPropTypes;
22 changes: 22 additions & 0 deletions src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -3672,6 +3672,28 @@ const styles = (theme) => ({
height: 30,
width: '100%',
},

walletCard: {
borderRadius: variables.componentBorderRadiusLarge,
position: 'relative',
alignSelf: 'center',
overflow: 'hidden',
},

walletCardNumber: {
color: theme.text,
fontSize: variables.fontSizeNormal,
},

walletCardHolder: {
position: 'absolute',
left: 16,
bottom: 16,
width: variables.cardNameWidth,
color: theme.text,
fontSize: variables.fontSizeSmall,
lineHeight: variables.lineHeightLarge,
},
});

// For now we need to export the styles function that takes the theme as an argument
Expand Down
Loading
Loading