-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathindex.tsx
91 lines (82 loc) · 3.04 KB
/
index.tsx
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
import React, {useCallback, useEffect, useRef} from 'react';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import Modal from '@components/Modal';
import ScreenWrapper from '@components/ScreenWrapper';
import Text from '@components/Text';
import useThemeStyles from '@hooks/useThemeStyles';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {ValidateCodeActionModalProps} from './type';
import ValidateCodeForm from './ValidateCodeForm';
import type {ValidateCodeFormHandle} from './ValidateCodeForm/BaseValidateCodeForm';
function ValidateCodeActionModal({
isVisible,
title,
description,
onClose,
onModalHide,
validatePendingAction,
validateError,
handleSubmitForm,
clearError,
footer,
sendValidateCode,
hasMagicCodeBeenSent,
}: ValidateCodeActionModalProps) {
const themeStyles = useThemeStyles();
const firstRenderRef = useRef(true);
const validateCodeFormRef = useRef<ValidateCodeFormHandle>(null);
const [validateCodeAction] = useOnyx(ONYXKEYS.VALIDATE_ACTION_CODE);
const hide = useCallback(() => {
clearError();
onClose();
}, [onClose, clearError]);
useEffect(() => {
if (!firstRenderRef.current || !isVisible) {
return;
}
firstRenderRef.current = false;
sendValidateCode();
}, [isVisible, sendValidateCode]);
return (
<Modal
type={CONST.MODAL.MODAL_TYPE.RIGHT_DOCKED}
isVisible={isVisible}
onClose={hide}
onModalHide={onModalHide ?? hide}
hideModalContentWhileAnimating
useNativeDriver
shouldUseModalPaddingStyle={false}
>
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
shouldEnableMaxHeight
testID={ValidateCodeActionModal.displayName}
offlineIndicatorStyle={themeStyles.mtAuto}
>
<HeaderWithBackButton
title={title}
onBackButtonPress={hide}
/>
<View style={[themeStyles.ph5, themeStyles.mt3, themeStyles.mb7]}>
<Text style={[themeStyles.mb3]}>{description}</Text>
<ValidateCodeForm
validateCodeAction={validateCodeAction}
validatePendingAction={validatePendingAction}
validateError={validateError}
handleSubmitForm={handleSubmitForm}
sendValidateCode={sendValidateCode}
clearError={clearError}
ref={validateCodeFormRef}
hasMagicCodeBeenSent={hasMagicCodeBeenSent}
/>
</View>
{footer?.()}
</ScreenWrapper>
</Modal>
);
}
ValidateCodeActionModal.displayName = 'ValidateCodeActionModal';
export default ValidateCodeActionModal;