1
- import React , { useCallback } from 'react' ;
1
+ import React , { useCallback , useMemo } from 'react' ;
2
2
import { useOnyx } from 'react-native-onyx' ;
3
3
import CheckboxWithLabel from '@components/CheckboxWithLabel' ;
4
4
import FormProvider from '@components/Form/FormProvider' ;
@@ -10,11 +10,12 @@ import useLocalize from '@hooks/useLocalize';
10
10
import type { SubStepProps } from '@hooks/useSubStep/types' ;
11
11
import useThemeStyles from '@hooks/useThemeStyles' ;
12
12
import { getFieldRequiredErrors , isRequiredFulfilled } from '@libs/ValidationUtils' ;
13
+ import getSubStepValues from '@pages/ReimbursementAccount/utils/getSubStepValues' ;
13
14
import ONYXKEYS from '@src/ONYXKEYS' ;
14
15
import INPUT_IDS from '@src/types/form/ReimbursementAccountForm' ;
15
16
16
- const { AUTHORIZED_TO_BIND_CLIENT_TO_AGREEMENT , PROVIDE_TRUTHFUL_INFORMATION , AGREE_TO_TERMS_AND_CONDITIONS } = INPUT_IDS . ADDITIONAL_DATA . CORPAY ;
17
- const STEP_FIELDS = [ AUTHORIZED_TO_BIND_CLIENT_TO_AGREEMENT , PROVIDE_TRUTHFUL_INFORMATION , AGREE_TO_TERMS_AND_CONDITIONS ] ;
17
+ const { AUTHORIZED_TO_BIND_CLIENT_TO_AGREEMENT , PROVIDE_TRUTHFUL_INFORMATION , AGREE_TO_TERMS_AND_CONDITIONS , CONSENT_TO_PRIVACY_NOTICE } = INPUT_IDS . ADDITIONAL_DATA . CORPAY ;
18
+ const STEP_FIELDS = [ AUTHORIZED_TO_BIND_CLIENT_TO_AGREEMENT , PROVIDE_TRUTHFUL_INFORMATION , AGREE_TO_TERMS_AND_CONDITIONS , CONSENT_TO_PRIVACY_NOTICE ] ;
18
19
19
20
function IsAuthorizedToUseBankAccountLabel ( ) {
20
21
const { translate} = useLocalize ( ) ;
@@ -31,24 +32,34 @@ function TermsAndConditionsLabel() {
31
32
return (
32
33
< Text >
33
34
{ translate ( 'common.iAcceptThe' ) }
34
- < TextLink href = "https://cross-border.corpay.com/tc/" > { `${ translate ( 'agreementsStep.termsAndConditions' ) } ` } </ TextLink >
35
+ < TextLink href = "https://cross-border.corpay.com/tc/" > { `${ translate ( 'agreementsStep.termsAndConditions' ) } ` } </ TextLink > .
35
36
</ Text >
36
37
) ;
37
38
}
38
39
40
+ function ConsentToPrivacyNoticeLabel ( ) {
41
+ const { translate} = useLocalize ( ) ;
42
+ return (
43
+ < Text >
44
+ { translate ( 'agreementsStep.iConsentToThe' ) } < TextLink href = "https://payments.corpay.com/compliance" > { `${ translate ( 'agreementsStep.privacyNotice' ) } ` } </ TextLink > .
45
+ </ Text >
46
+ ) ;
47
+ }
48
+
49
+ const INPUT_KEYS = {
50
+ PROVIDE_TRUTHFUL_INFORMATION : INPUT_IDS . ADDITIONAL_DATA . CORPAY . PROVIDE_TRUTHFUL_INFORMATION ,
51
+ AGREE_TO_TERMS_AND_CONDITIONS : INPUT_IDS . ADDITIONAL_DATA . CORPAY . AGREE_TO_TERMS_AND_CONDITIONS ,
52
+ CONSENT_TO_PRIVACY_NOTICE : INPUT_IDS . ADDITIONAL_DATA . CORPAY . CONSENT_TO_PRIVACY_NOTICE ,
53
+ AUTHORIZED_TO_BIND_CLIENT_TO_AGREEMENT : INPUT_IDS . ADDITIONAL_DATA . CORPAY . AUTHORIZED_TO_BIND_CLIENT_TO_AGREEMENT ,
54
+ } ;
55
+
39
56
function Confirmation ( { onNext} : SubStepProps ) {
40
57
const { translate} = useLocalize ( ) ;
41
58
const styles = useThemeStyles ( ) ;
42
59
43
- const [ reimbursementAccount ] = useOnyx ( ONYXKEYS . REIMBURSEMENT_ACCOUNT ) ;
44
- const [ reimbursementAccountDraft ] = useOnyx ( ONYXKEYS . FORMS . REIMBURSEMENT_ACCOUNT_FORM_DRAFT ) ;
45
-
46
- const defaultValues = {
47
- [ AUTHORIZED_TO_BIND_CLIENT_TO_AGREEMENT ] :
48
- ! ! reimbursementAccount ?. achData ?. corpay ?. [ AUTHORIZED_TO_BIND_CLIENT_TO_AGREEMENT ] ?? reimbursementAccountDraft ?. [ AUTHORIZED_TO_BIND_CLIENT_TO_AGREEMENT ] ?? '' ,
49
- [ PROVIDE_TRUTHFUL_INFORMATION ] : ! ! reimbursementAccount ?. achData ?. corpay ?. [ PROVIDE_TRUTHFUL_INFORMATION ] ?? reimbursementAccountDraft ?. [ PROVIDE_TRUTHFUL_INFORMATION ] ?? '' ,
50
- [ AGREE_TO_TERMS_AND_CONDITIONS ] : ! ! reimbursementAccount ?. achData ?. corpay ?. [ AGREE_TO_TERMS_AND_CONDITIONS ] ?? reimbursementAccountDraft ?. [ AGREE_TO_TERMS_AND_CONDITIONS ] ?? '' ,
51
- } ;
60
+ const [ reimbursementAccount ] = useOnyx ( ONYXKEYS . REIMBURSEMENT_ACCOUNT , { canBeMissing : false } ) ;
61
+ const [ reimbursementAccountDraft ] = useOnyx ( ONYXKEYS . FORMS . REIMBURSEMENT_ACCOUNT_FORM_DRAFT , { canBeMissing : false } ) ;
62
+ const agreementsStepValues = useMemo ( ( ) => getSubStepValues ( INPUT_KEYS , reimbursementAccountDraft , reimbursementAccount ) , [ reimbursementAccount , reimbursementAccountDraft ] ) ;
52
63
53
64
const validate = useCallback (
54
65
( values : FormOnyxValues < typeof ONYXKEYS . FORMS . REIMBURSEMENT_ACCOUNT_FORM > ) : FormInputErrors < typeof ONYXKEYS . FORMS . REIMBURSEMENT_ACCOUNT_FORM > => {
@@ -66,6 +77,10 @@ function Confirmation({onNext}: SubStepProps) {
66
77
errors [ AGREE_TO_TERMS_AND_CONDITIONS ] = translate ( 'common.error.acceptTerms' ) ;
67
78
}
68
79
80
+ if ( ! isRequiredFulfilled ( values [ CONSENT_TO_PRIVACY_NOTICE ] ) ) {
81
+ errors [ CONSENT_TO_PRIVACY_NOTICE ] = translate ( 'agreementsStep.error.consent' ) ;
82
+ }
83
+
69
84
return errors ;
70
85
} ,
71
86
[ translate ] ,
@@ -79,6 +94,7 @@ function Confirmation({onNext}: SubStepProps) {
79
94
submitButtonText = { translate ( 'agreementsStep.accept' ) }
80
95
style = { [ styles . mh5 , styles . flexGrow1 ] }
81
96
enabledWhenOffline = { false }
97
+ isLoading = { reimbursementAccount ?. isFinishingCorpayBankAccountOnboarding }
82
98
>
83
99
< Text style = { [ styles . textHeadlineLineHeightXXL ] } > { translate ( 'agreementsStep.pleaseConfirm' ) } </ Text >
84
100
< Text style = { [ styles . pv3 , styles . textSupporting ] } > { translate ( 'agreementsStep.regulationRequiresUs' ) } </ Text >
@@ -88,7 +104,7 @@ function Confirmation({onNext}: SubStepProps) {
88
104
inputID = { AUTHORIZED_TO_BIND_CLIENT_TO_AGREEMENT }
89
105
style = { styles . mt6 }
90
106
LabelComponent = { IsAuthorizedToUseBankAccountLabel }
91
- defaultValue = { defaultValues [ AUTHORIZED_TO_BIND_CLIENT_TO_AGREEMENT ] }
107
+ defaultValue = { agreementsStepValues [ AUTHORIZED_TO_BIND_CLIENT_TO_AGREEMENT ] }
92
108
shouldSaveDraft
93
109
/>
94
110
< InputWrapper
@@ -97,16 +113,25 @@ function Confirmation({onNext}: SubStepProps) {
97
113
inputID = { PROVIDE_TRUTHFUL_INFORMATION }
98
114
style = { styles . mt6 }
99
115
LabelComponent = { CertifyTrueAndAccurateLabel }
100
- defaultValue = { defaultValues [ PROVIDE_TRUTHFUL_INFORMATION ] }
116
+ defaultValue = { agreementsStepValues [ PROVIDE_TRUTHFUL_INFORMATION ] }
101
117
shouldSaveDraft
102
118
/>
103
119
< InputWrapper
104
120
InputComponent = { CheckboxWithLabel }
105
- accessibilityLabel = { `${ translate ( 'common.iAcceptThe' ) } ${ translate ( 'agreementsStep.termsAndConditions' ) } ` }
121
+ accessibilityLabel = { `${ translate ( 'common.iAcceptThe' ) } ${ translate ( 'agreementsStep.termsAndConditions' ) } . ` }
106
122
inputID = { AGREE_TO_TERMS_AND_CONDITIONS }
107
123
style = { styles . mt6 }
108
124
LabelComponent = { TermsAndConditionsLabel }
109
- defaultValue = { defaultValues [ AGREE_TO_TERMS_AND_CONDITIONS ] }
125
+ defaultValue = { agreementsStepValues [ AGREE_TO_TERMS_AND_CONDITIONS ] }
126
+ shouldSaveDraft
127
+ />
128
+ < InputWrapper
129
+ InputComponent = { CheckboxWithLabel }
130
+ accessibilityLabel = { `${ translate ( 'agreementsStep.iConsentToThe' ) } ${ translate ( 'agreementsStep.privacyNotice' ) } .` }
131
+ inputID = { CONSENT_TO_PRIVACY_NOTICE }
132
+ style = { styles . mt6 }
133
+ LabelComponent = { ConsentToPrivacyNoticeLabel }
134
+ defaultValue = { agreementsStepValues [ CONSENT_TO_PRIVACY_NOTICE ] }
110
135
shouldSaveDraft
111
136
/>
112
137
</ FormProvider >
0 commit comments