forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathValidateCodeResendButton.tsx
More file actions
88 lines (75 loc) · 3.3 KB
/
Copy pathValidateCodeResendButton.tsx
File metadata and controls
88 lines (75 loc) · 3.3 KB
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
import PressableWithFeedback from '@components/Pressable/PressableWithFeedback';
import Text from '@components/Text';
import ValidateCodeCountdown from '@components/ValidateCodeCountdown';
import type {ValidateCodeCountdownHandle} from '@components/ValidateCodeCountdown/types';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import React, {useCallback, useImperativeHandle, useRef, useState} from 'react';
import {View} from 'react-native';
type MultifactorAuthenticationValidateCodeResendButtonHandle = {
resetCountdown: () => void;
};
type MultifactorAuthenticationValidateCodeResendButtonProps = {
ref?: React.Ref<MultifactorAuthenticationValidateCodeResendButtonHandle>;
shouldDisableResendCode: boolean;
hasError: boolean;
resendButtonText: TranslationPaths;
onResendValidationCode: () => void;
};
function MultifactorAuthenticationValidateCodeResendButton({
ref,
shouldDisableResendCode,
hasError,
resendButtonText,
onResendValidationCode,
}: MultifactorAuthenticationValidateCodeResendButtonProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {translate} = useLocalize();
const {isOffline} = useNetwork();
const [isCountdownRunning, setIsCountdownRunning] = useState(true);
const countdownRef = useRef<ValidateCodeCountdownHandle>(null);
const handleCountdownFinish = useCallback(() => {
setIsCountdownRunning(false);
}, []);
useImperativeHandle(ref, () => ({
resetCountdown: () => {
countdownRef.current?.resetCountdown();
setIsCountdownRunning(true);
},
}));
return (
<View style={styles.alignItemsStart}>
{isCountdownRunning && !isOffline ? (
<View style={[styles.mt5, styles.flexRow, styles.renderHTML]}>
<ValidateCodeCountdown
ref={countdownRef}
onCountdownFinish={handleCountdownFinish}
/>
</View>
) : (
<PressableWithFeedback
style={styles.mt5}
testID={CONST.MULTIFACTOR_AUTHENTICATION.TEST_ID.VALIDATE_CODE_RESEND_BUTTON}
onPress={onResendValidationCode}
disabled={shouldDisableResendCode}
hoverDimmingValue={1}
pressDimmingValue={0.2}
role={CONST.ROLE.BUTTON}
accessibilityLabel={translate(resendButtonText)}
>
<Text style={[StyleUtils.getDisabledLinkStyles(shouldDisableResendCode)]}>
{hasError ? translate('validateCodeForm.requestNewCodeAfterErrorOccurred') : translate(resendButtonText)}
</Text>
</PressableWithFeedback>
)}
</View>
);
}
MultifactorAuthenticationValidateCodeResendButton.displayName = 'MultifactorAuthenticationValidateCodeResendButton';
export default MultifactorAuthenticationValidateCodeResendButton;
export type {MultifactorAuthenticationValidateCodeResendButtonHandle};