ordering-ui-react-native 0.15.52 → 0.15.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
-
import { View, Pressable, StyleSheet, Linking, Platform } from 'react-native';
|
|
2
|
+
import { View, Pressable, StyleSheet, Linking, Platform, TouchableOpacity } from 'react-native';
|
|
3
3
|
import { useForm, Controller } from 'react-hook-form';
|
|
4
4
|
import Spinner from 'react-native-loading-spinner-overlay';
|
|
5
5
|
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
|
|
6
6
|
import CheckBox from '@react-native-community/checkbox';
|
|
7
7
|
import { PhoneInputNumber } from '../PhoneInputNumber';
|
|
8
8
|
import { FacebookLogin } from '../FacebookLogin';
|
|
9
|
+
import Recaptcha from 'react-native-recaptcha-that-works'
|
|
9
10
|
|
|
10
11
|
import {
|
|
11
12
|
SignupForm as SignUpController,
|
|
@@ -23,6 +24,7 @@ import {
|
|
|
23
24
|
LoginWith as SignupWith,
|
|
24
25
|
OTab,
|
|
25
26
|
OTabs,
|
|
27
|
+
RecaptchaButton
|
|
26
28
|
} from '../LoginForm/styles';
|
|
27
29
|
|
|
28
30
|
import NavBar from '../NavBar';
|
|
@@ -63,7 +65,9 @@ const SignupFormUI = (props: SignupParams) => {
|
|
|
63
65
|
handleSendVerifyCode,
|
|
64
66
|
handleCheckPhoneCode,
|
|
65
67
|
notificationState,
|
|
66
|
-
handleChangePromotions
|
|
68
|
+
handleChangePromotions,
|
|
69
|
+
enableReCaptcha,
|
|
70
|
+
handleReCaptcha
|
|
67
71
|
} = props;
|
|
68
72
|
|
|
69
73
|
const theme = useTheme();
|
|
@@ -117,6 +121,8 @@ const SignupFormUI = (props: SignupParams) => {
|
|
|
117
121
|
cellphone: null,
|
|
118
122
|
},
|
|
119
123
|
});
|
|
124
|
+
const [recaptchaConfig, setRecaptchaConfig] = useState<any>({})
|
|
125
|
+
const [recaptchaVerified, setRecaptchaVerified] = useState(false)
|
|
120
126
|
|
|
121
127
|
const nameRef = useRef<any>(null);
|
|
122
128
|
const lastnameRef = useRef<any>(null);
|
|
@@ -125,6 +131,7 @@ const SignupFormUI = (props: SignupParams) => {
|
|
|
125
131
|
const emailRef = useRef<any>(null);
|
|
126
132
|
const phoneRef = useRef<any>(null);
|
|
127
133
|
const passwordRef = useRef<any>(null);
|
|
134
|
+
const recaptchaRef = useRef<any>({});
|
|
128
135
|
|
|
129
136
|
const showInputPhoneNumber = (validationFields?.fields?.checkout?.cellphone?.enabled ?? false) || configs?.verification_phone_required?.value === '1'
|
|
130
137
|
|
|
@@ -286,6 +293,33 @@ const SignupFormUI = (props: SignupParams) => {
|
|
|
286
293
|
}
|
|
287
294
|
}
|
|
288
295
|
|
|
296
|
+
const handleOpenRecaptcha = () => {
|
|
297
|
+
setRecaptchaVerified(false)
|
|
298
|
+
if (!recaptchaConfig?.siteKey) {
|
|
299
|
+
showToast(ToastType.Error, t('NO_RECAPTCHA_SITE_KEY', 'The config doesn\'t have recaptcha site key'));
|
|
300
|
+
return
|
|
301
|
+
}
|
|
302
|
+
if (!recaptchaConfig?.baseUrl) {
|
|
303
|
+
showToast(ToastType.Error, t('NO_RECAPTCHA_BASE_URL', 'The config doesn\'t have recaptcha base url'));
|
|
304
|
+
return
|
|
305
|
+
}
|
|
306
|
+
recaptchaRef.current.open()
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const onRecaptchaVerify = (token: any) => {
|
|
310
|
+
setRecaptchaVerified(true)
|
|
311
|
+
handleReCaptcha(token)
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
useEffect(() => {
|
|
315
|
+
if (configs && Object.keys(configs).length > 0 && enableReCaptcha) {
|
|
316
|
+
setRecaptchaConfig({
|
|
317
|
+
siteKey: configs?.security_recaptcha_site_key?.value || null,
|
|
318
|
+
baseUrl: configs?.security_recaptcha_base_url?.value || null
|
|
319
|
+
})
|
|
320
|
+
}
|
|
321
|
+
}, [configs, enableReCaptcha])
|
|
322
|
+
|
|
289
323
|
useEffect(() => {
|
|
290
324
|
if (!formState.loading && formState.result?.error) {
|
|
291
325
|
formState.result?.result &&
|
|
@@ -467,6 +501,39 @@ const SignupFormUI = (props: SignupParams) => {
|
|
|
467
501
|
</View>
|
|
468
502
|
)}
|
|
469
503
|
|
|
504
|
+
{enableReCaptcha && (
|
|
505
|
+
<>
|
|
506
|
+
<TouchableOpacity
|
|
507
|
+
onPress={handleOpenRecaptcha}
|
|
508
|
+
style={{ marginHorizontal: 4, marginBottom: 10 }}
|
|
509
|
+
>
|
|
510
|
+
<RecaptchaButton>
|
|
511
|
+
{recaptchaVerified ? (
|
|
512
|
+
<MaterialCommunityIcons
|
|
513
|
+
name="checkbox-marked"
|
|
514
|
+
size={23}
|
|
515
|
+
color={theme.colors.primary}
|
|
516
|
+
/>
|
|
517
|
+
) : (
|
|
518
|
+
<MaterialCommunityIcons
|
|
519
|
+
name="checkbox-blank-outline"
|
|
520
|
+
size={23}
|
|
521
|
+
color={theme.colors.disabled}
|
|
522
|
+
/>
|
|
523
|
+
)}
|
|
524
|
+
<OText size={14} mLeft={8}>{t('VERIFY_ReCAPTCHA', 'Verify reCAPTCHA')}</OText>
|
|
525
|
+
</RecaptchaButton>
|
|
526
|
+
</TouchableOpacity>
|
|
527
|
+
<Recaptcha
|
|
528
|
+
ref={recaptchaRef}
|
|
529
|
+
siteKey={recaptchaConfig?.siteKey}
|
|
530
|
+
baseUrl={recaptchaConfig?.baseUrl}
|
|
531
|
+
onVerify={onRecaptchaVerify}
|
|
532
|
+
onExpire={() => setRecaptchaVerified(false)}
|
|
533
|
+
/>
|
|
534
|
+
</>
|
|
535
|
+
)}
|
|
536
|
+
|
|
470
537
|
<View style={{ flexDirection: 'row', alignItems: 'center', marginBottom: 20 }}>
|
|
471
538
|
<Controller
|
|
472
539
|
control={control}
|
|
@@ -736,6 +803,7 @@ const SignupFormUI = (props: SignupParams) => {
|
|
|
736
803
|
export const SignupForm = (props: any) => {
|
|
737
804
|
const signupProps = {
|
|
738
805
|
...props,
|
|
806
|
+
isRecaptchaEnable: true,
|
|
739
807
|
UIComponent: SignupFormUI,
|
|
740
808
|
};
|
|
741
809
|
return <SignUpController {...signupProps} />;
|