-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathCodesPage.js
150 lines (142 loc) · 7.19 KB
/
CodesPage.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
140
141
142
143
144
145
146
147
148
149
150
import React, {useEffect, useState} from 'react';
import {withOnyx} from 'react-native-onyx';
import {ActivityIndicator, View} from 'react-native';
import {ScrollView} from 'react-native-gesture-handler';
import _ from 'underscore';
import PropTypes from 'prop-types';
import HeaderWithBackButton from '../../../../components/HeaderWithBackButton';
import Navigation from '../../../../libs/Navigation/Navigation';
import ScreenWrapper from '../../../../components/ScreenWrapper';
import * as Expensicons from '../../../../components/Icon/Expensicons';
import withLocalize, {withLocalizePropTypes} from '../../../../components/withLocalize';
import compose from '../../../../libs/compose';
import ROUTES from '../../../../ROUTES';
import FullPageOfflineBlockingView from '../../../../components/BlockingViews/FullPageOfflineBlockingView';
import * as Illustrations from '../../../../components/Icon/Illustrations';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../../components/withWindowDimensions';
import styles from '../../../../styles/styles';
import FixedFooter from '../../../../components/FixedFooter';
import Button from '../../../../components/Button';
import PressableWithDelayToggle from '../../../../components/Pressable/PressableWithDelayToggle';
import Text from '../../../../components/Text';
import Section from '../../../../components/Section';
import ONYXKEYS from '../../../../ONYXKEYS';
import Clipboard from '../../../../libs/Clipboard';
import themeColors from '../../../../styles/themes/default';
import localFileDownload from '../../../../libs/localFileDownload';
import * as TwoFactorAuthActions from '../../../../libs/actions/TwoFactorAuthActions';
const propTypes = {
...withLocalizePropTypes,
...windowDimensionsPropTypes,
account: PropTypes.shape({
/** User recovery codes for setting up 2-FA */
recoveryCodes: PropTypes.string,
/** If recovery codes are loading */
isLoading: PropTypes.bool,
}),
};
const defaultProps = {
account: {
recoveryCodes: '',
},
};
function CodesPage(props) {
const [isNextButtonDisabled, setIsNextButtonDisabled] = useState(true);
// Here, this eslint rule will make the unmount effect unreadable, possibly confusing with mount
// eslint-disable-next-line arrow-body-style
useEffect(() => {
return () => {
TwoFactorAuthActions.clearTwoFactorAuthData();
};
}, []);
return (
<ScreenWrapper shouldShowOfflineIndicator={false}>
<HeaderWithBackButton
title={props.translate('twoFactorAuth.headerTitle')}
shouldShowStepCounter
stepCounter={{
step: 1,
text: props.translate('twoFactorAuth.stepCodes'),
}}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_SECURITY)}
/>
<FullPageOfflineBlockingView>
<ScrollView>
<Section
title={props.translate('twoFactorAuth.keepCodesSafe')}
icon={Illustrations.ShieldYellow}
containerStyles={[styles.twoFactorAuthSection]}
iconContainerStyles={[styles.ml6]}
>
<View style={styles.mv3}>
<Text>{props.translate('twoFactorAuth.codesLoseAccess')}</Text>
</View>
<View style={[styles.twoFactorAuthCodesBox(props)]}>
{props.account.isLoading ? (
<View style={styles.twoFactorLoadingContainer}>
<ActivityIndicator color={themeColors.spinner} />
</View>
) : (
<>
<View style={styles.twoFactorAuthCodesContainer}>
{Boolean(props.account.recoveryCodes) &&
_.map(props.account.recoveryCodes.split(', '), (code) => (
<Text
style={styles.twoFactorAuthCode}
key={code}
>
{code}
</Text>
))}
</View>
<View style={[styles.twoFactorAuthCodesButtonsContainer]}>
<PressableWithDelayToggle
text={props.translate('twoFactorAuth.copy')}
textChecked={props.translate('common.copied')}
icon={Expensicons.Copy}
inline={false}
onPress={() => {
Clipboard.setString(props.account.recoveryCodes);
setIsNextButtonDisabled(false);
}}
styles={[styles.button, styles.buttonMedium, styles.twoFactorAuthCodesButton]}
textStyles={[styles.buttonMediumText]}
/>
<PressableWithDelayToggle
text={props.translate('common.download')}
icon={Expensicons.Download}
onPress={() => {
localFileDownload('two-factor-auth-codes', props.account.recoveryCodes);
setIsNextButtonDisabled(false);
}}
inline={false}
styles={[styles.button, styles.buttonMedium, styles.twoFactorAuthCodesButton]}
textStyles={[styles.buttonMediumText]}
/>
</View>
</>
)}
</View>
</Section>
</ScrollView>
<FixedFooter style={[styles.mtAuto, styles.pt2]}>
<Button
success
text={props.translate('common.next')}
onPress={() => Navigation.navigate(ROUTES.SETTINGS_2FA_VERIFY)}
isDisabled={isNextButtonDisabled}
/>
</FixedFooter>
</FullPageOfflineBlockingView>
</ScreenWrapper>
);
}
CodesPage.propTypes = propTypes;
CodesPage.defaultProps = defaultProps;
export default compose(
withLocalize,
withWindowDimensions,
withOnyx({
account: {key: ONYXKEYS.ACCOUNT},
}),
)(CodesPage);