-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cfad43f
commit 8adb129
Showing
6 changed files
with
187 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import * as Expensicons from '../../../../components/Icon/Expensicons'; | ||
import MenuItemWithTopDescription from '../../../../components/MenuItemWithTopDescription'; | ||
import Clipboard from '../../../../libs/Clipboard'; | ||
import useLocalize from '../../../../hooks/useLocalize'; | ||
import usePrivatePersonalDetails from '../../../../hooks/usePrivatePersonalDetails'; | ||
import ONYXKEYS from '../../../../ONYXKEYS'; | ||
|
||
const propTypes = { | ||
/** Card number */ | ||
pan: PropTypes.string, | ||
|
||
/** Card expiration date */ | ||
expiration: PropTypes.string, | ||
|
||
/** 3 digit code */ | ||
cvv: PropTypes.string, | ||
|
||
/** User's private personal details */ | ||
privatePersonalDetails: PropTypes.shape({ | ||
/** User's home address */ | ||
address: PropTypes.shape({ | ||
street: PropTypes.string, | ||
city: PropTypes.string, | ||
state: PropTypes.string, | ||
zip: PropTypes.string, | ||
country: PropTypes.string, | ||
}), | ||
}), | ||
}; | ||
|
||
const defaultProps = { | ||
pan: '', | ||
expiration: '', | ||
cvv: '', | ||
privatePersonalDetails: { | ||
address: { | ||
street: '', | ||
street2: '', | ||
city: '', | ||
state: '', | ||
zip: '', | ||
country: '', | ||
}, | ||
}, | ||
}; | ||
|
||
function CardDetails({pan, expiration, cvv, privatePersonalDetails}) { | ||
usePrivatePersonalDetails(); | ||
const {translate} = useLocalize(); | ||
|
||
/** | ||
* Formats an address object into an easily readable string | ||
* | ||
* @returns {String} | ||
*/ | ||
const getFormattedAddress = () => { | ||
const address = privatePersonalDetails.address || {}; | ||
const [street1, street2] = (address.street || '').split('\n'); | ||
const formatted = [street1, street2, address.city, address.state, address.zip, address.country].join(', '); | ||
|
||
// Remove the last comma of the address | ||
return formatted.trim().replace(/,$/, ''); | ||
}; | ||
|
||
const handleCopyToClipboard = () => { | ||
Clipboard.setString(pan); | ||
}; | ||
|
||
return ( | ||
<> | ||
<MenuItemWithTopDescription | ||
description={translate('walletPage.cardDetails.cardNumber')} | ||
title={pan} | ||
iconRight={Expensicons.Copy} | ||
shouldShowRightIcon | ||
interactive={false} | ||
onIconRightPress={handleCopyToClipboard} | ||
iconRightAccessibilityLabel={translate('walletPage.cardDetails.copyCardNumber')} | ||
/> | ||
<MenuItemWithTopDescription | ||
description={translate('walletPage.cardDetails.expiration')} | ||
title={expiration} | ||
interactive={false} | ||
/> | ||
<MenuItemWithTopDescription | ||
description={translate('walletPage.cardDetails.cvv')} | ||
title={cvv} | ||
interactive={false} | ||
/> | ||
<MenuItemWithTopDescription | ||
description={translate('walletPage.cardDetails.address')} | ||
title={getFormattedAddress()} | ||
interactive={false} | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
CardDetails.displayName = 'CardDetails'; | ||
CardDetails.propTypes = propTypes; | ||
CardDetails.defaultProps = defaultProps; | ||
|
||
export default withOnyx({ | ||
privatePersonalDetails: { | ||
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS, | ||
}, | ||
})(CardDetails); |