-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
PersonalDetailsInitialPage.js
139 lines (127 loc) · 5.3 KB
/
PersonalDetailsInitialPage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import React from 'react';
import PropTypes from 'prop-types';
import {ScrollView, View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import lodashGet from 'lodash/get';
import ScreenWrapper from '../../../../components/ScreenWrapper';
import HeaderWithBackButton from '../../../../components/HeaderWithBackButton';
import withLocalize, {withLocalizePropTypes} from '../../../../components/withLocalize';
import ROUTES from '../../../../ROUTES';
import Text from '../../../../components/Text';
import styles from '../../../../styles/styles';
import Navigation from '../../../../libs/Navigation/Navigation';
import compose from '../../../../libs/compose';
import MenuItemWithTopDescription from '../../../../components/MenuItemWithTopDescription';
import ONYXKEYS from '../../../../ONYXKEYS';
import {withNetwork} from '../../../../components/OnyxProvider';
import usePrivatePersonalDetails from '../../../../hooks/usePrivatePersonalDetails';
import FullscreenLoadingIndicator from '../../../../components/FullscreenLoadingIndicator';
const propTypes = {
/* Onyx Props */
/** User's private personal details */
privatePersonalDetails: PropTypes.shape({
legalFirstName: PropTypes.string,
legalLastName: PropTypes.string,
dob: PropTypes.string,
/** User's home address */
address: PropTypes.shape({
street: PropTypes.string,
city: PropTypes.string,
state: PropTypes.string,
zip: PropTypes.string,
country: PropTypes.string,
}),
}),
...withLocalizePropTypes,
};
const defaultProps = {
privatePersonalDetails: {
legalFirstName: '',
legalLastName: '',
dob: '',
address: {
street: '',
street2: '',
city: '',
state: '',
zip: '',
country: '',
},
},
};
function PersonalDetailsInitialPage(props) {
usePrivatePersonalDetails();
const privateDetails = props.privatePersonalDetails || {};
const address = privateDetails.address || {};
const legalName = `${privateDetails.legalFirstName || ''} ${privateDetails.legalLastName || ''}`.trim();
const isLoadingPersonalDetails = lodashGet(props.privatePersonalDetails, 'isLoading', true);
/**
* Applies common formatting to each piece of an address
*
* @param {String} piece
* @returns {String}
*/
const formatPiece = (piece) => (piece ? `${piece}, ` : '');
/**
* Formats an address object into an easily readable string
*
* @returns {String}
*/
const getFormattedAddress = () => {
const [street1, street2] = (address.street || '').split('\n');
const formattedAddress =
formatPiece(street1) + formatPiece(street2) + formatPiece(address.city) + formatPiece(address.state) + formatPiece(address.zip) + formatPiece(address.country);
// Remove the last comma of the address
return formattedAddress.trim().replace(/,$/, '');
};
return (
<ScreenWrapper>
<HeaderWithBackButton
title={props.translate('privatePersonalDetails.personalDetails')}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_PROFILE)}
/>
{isLoadingPersonalDetails ? (
<FullscreenLoadingIndicator style={[styles.flex1, styles.pRelative]} />
) : (
<ScrollView>
<View style={styles.flex1}>
<View style={[styles.ph5, styles.mb5]}>
<Text>{props.translate('privatePersonalDetails.privateDataMessage')}</Text>
</View>
<MenuItemWithTopDescription
title={legalName}
description={props.translate('privatePersonalDetails.legalName')}
shouldShowRightIcon
onPress={() => Navigation.navigate(ROUTES.SETTINGS_PERSONAL_DETAILS_LEGAL_NAME)}
/>
<MenuItemWithTopDescription
title={privateDetails.dob || ''}
description={props.translate('common.dob')}
shouldShowRightIcon
onPress={() => Navigation.navigate(ROUTES.SETTINGS_PERSONAL_DETAILS_DATE_OF_BIRTH)}
titleStyle={[styles.flex1]}
/>
<MenuItemWithTopDescription
title={getFormattedAddress()}
description={props.translate('privatePersonalDetails.homeAddress')}
shouldShowRightIcon
onPress={() => Navigation.navigate(ROUTES.SETTINGS_PERSONAL_DETAILS_ADDRESS)}
/>
</View>
</ScrollView>
)}
</ScreenWrapper>
);
}
PersonalDetailsInitialPage.propTypes = propTypes;
PersonalDetailsInitialPage.defaultProps = defaultProps;
PersonalDetailsInitialPage.displayName = 'PersonalDetailsInitialPage';
export default compose(
withLocalize,
withOnyx({
privatePersonalDetails: {
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
},
}),
withNetwork(),
)(PersonalDetailsInitialPage);