-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Changes from 23 commits
5823d37
453e747
8af9818
e3c1050
20d1268
33cc565
597b319
9a04cf0
1040f6b
27e242d
c57bb86
4161195
fc90f3d
b043af1
f0595c0
33325ce
c864fe7
901301a
557bccc
137d1b9
29c6685
48debed
fe87eb4
2f92e75
a22a2d6
a823f1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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({ | ||
/** Currently logged-in user email */ | ||
email: PropTypes.string, | ||
}), | ||
}; | ||
|
||
const defaultProps = { | ||
privatePersonalDetails: { | ||
legalFirstName: '', | ||
legalLastName: '', | ||
}, | ||
session: { | ||
email: '', | ||
}, | ||
}; | ||
|
||
function CardPreview({privatePersonalDetails: {legalFirstName, legalLastName}, session: {email}}) { | ||
usePrivatePersonalDetails(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NAB, but maybe this should be |
||
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); |
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 | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}; |
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); |
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added