-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathExpiredValidateCodeModal.js
134 lines (123 loc) · 5.23 KB
/
ExpiredValidateCodeModal.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
import React, {PureComponent} from 'react';
import {withOnyx} from 'react-native-onyx';
import PropTypes from 'prop-types';
import _, {compose} from 'underscore';
import lodashGet from 'lodash/get';
import {View} from 'react-native';
import colors from '../../styles/colors';
import styles from '../../styles/styles';
import Icon from '../Icon';
import withLocalize, {withLocalizePropTypes} from '../withLocalize';
import Text from '../Text';
import * as Expensicons from '../Icon/Expensicons';
import * as Illustrations from '../Icon/Illustrations';
import variables from '../../styles/variables';
import TextLink from '../TextLink';
import ONYXKEYS from '../../ONYXKEYS';
import * as ErrorUtils from '../../libs/ErrorUtils';
import * as Session from '../../libs/actions/Session';
const propTypes = {
/** The details about the account that the user is signing in with */
account: PropTypes.shape({
/** An error message to display to the user */
errors: PropTypes.objectOf(PropTypes.string),
/** The message to be displayed when code requested */
message: PropTypes.string,
}),
/** The credentials of the logged in person */
credentials: PropTypes.shape({
/** The email the user logged in with */
login: PropTypes.string,
}),
...withLocalizePropTypes,
};
const defaultProps = {
account: {},
credentials: {},
};
class ExpiredValidateCodeModal extends PureComponent {
constructor(props) {
super(props);
this.requestNewCode = this.requestNewCode.bind(this);
}
shouldShowRequestCodeLink() {
return Boolean(lodashGet(this.props, 'credentials.login', null));
}
requestNewCode() {
Session.resendValidateCode();
}
render() {
const codeRequestedMessage = lodashGet(this.props, 'account.message', null);
const accountErrors = lodashGet(this.props, 'account.errors', {});
let codeRequestedErrors;
if (_.keys(accountErrors).length > 1) {
codeRequestedErrors = ErrorUtils.getLatestErrorMessage(this.props.account);
}
return (
<View style={styles.deeplinkWrapperContainer}>
<View style={styles.deeplinkWrapperMessage}>
<View style={styles.mb2}>
<Icon
width={variables.modalTopIconWidth}
height={variables.modalTopIconHeight}
src={Illustrations.ToddBehindCloud}
/>
</View>
<Text style={[styles.textHeadline, styles.textXXLarge, styles.textAlignCenter]}>
{this.props.translate('validateCodeModal.expiredCodeTitle')}
</Text>
<View style={[styles.mt2, styles.mb2]}>
<Text style={[styles.fontSizeNormal, styles.textAlignCenter]}>
{this.props.translate('validateCodeModal.expiredCodeDescription')}
{this.shouldShowRequestCodeLink() && !codeRequestedMessage
&& (
<>
<br />
{this.props.translate('validateCodeModal.requestNewCode')}
{' '}
<TextLink onPress={this.requestNewCode}>
{this.props.translate('validateCodeModal.requestNewCodeLink')}
</TextLink>
!
</>
)}
</Text>
{this.shouldShowRequestCodeLink() && Boolean(codeRequestedErrors)
&& (
<Text style={[styles.textDanger, styles.validateCodeMessage]}>
<br />
<br />
{codeRequestedErrors}
</Text>
)}
{this.shouldShowRequestCodeLink() && Boolean(codeRequestedMessage)
&& (
<Text style={styles.validateCodeMessage}>
<br />
<br />
{codeRequestedMessage}
</Text>
)}
</View>
</View>
<View style={styles.deeplinkWrapperFooter}>
<Icon
width={variables.modalWordmarkWidth}
height={variables.modalWordmarkHeight}
fill={colors.green}
src={Expensicons.ExpensifyWordmark}
/>
</View>
</View>
);
}
}
ExpiredValidateCodeModal.propTypes = propTypes;
ExpiredValidateCodeModal.defaultProps = defaultProps;
export default compose(
withLocalize,
withOnyx({
account: {key: ONYXKEYS.ACCOUNT},
credentials: {key: ONYXKEYS.CREDENTIALS},
}),
)(ExpiredValidateCodeModal);