ordering-ui-react-native 0.15.82 → 0.15.83
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,16 +1,20 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react';
|
|
1
|
+
import React, { useEffect, useState, useRef } from 'react';
|
|
2
2
|
import { StyleSheet } from 'react-native';
|
|
3
3
|
import { useForm, Controller } from 'react-hook-form';
|
|
4
|
+
import Recaptcha from 'react-native-recaptcha-that-works'
|
|
5
|
+
import { TouchableOpacity } from 'react-native-gesture-handler';
|
|
6
|
+
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
|
|
4
7
|
|
|
5
8
|
import {
|
|
6
9
|
ForgotPasswordForm as ForgotPasswordController,
|
|
7
10
|
useLanguage,
|
|
8
11
|
useToast,
|
|
9
12
|
ToastType,
|
|
13
|
+
useConfig
|
|
10
14
|
} from 'ordering-components/native';
|
|
11
15
|
import { useTheme } from 'styled-components/native';
|
|
12
16
|
import NavBar from '../NavBar';
|
|
13
|
-
import { FormInput, FormSide } from '../LoginForm/styles'
|
|
17
|
+
import { FormInput, FormSide, RecaptchaButton } from '../LoginForm/styles'
|
|
14
18
|
import { Container } from './styles'
|
|
15
19
|
|
|
16
20
|
import { OButton, OInput, OText } from '../shared';
|
|
@@ -20,10 +24,15 @@ const ForgotPasswordUI = (props: any) => {
|
|
|
20
24
|
navigation,
|
|
21
25
|
formState,
|
|
22
26
|
handleButtonForgotPasswordClick,
|
|
27
|
+
handleReCaptcha,
|
|
28
|
+
enableReCaptcha
|
|
23
29
|
} = props;
|
|
24
30
|
const [, t] = useLanguage();
|
|
25
31
|
const [, { showToast }] = useToast();
|
|
32
|
+
const [{ configs }] = useConfig();
|
|
26
33
|
const { control, handleSubmit, errors } = useForm();
|
|
34
|
+
const [recaptchaConfig, setRecaptchaConfig] = useState<any>({})
|
|
35
|
+
const [recaptchaVerified, setRecaptchaVerified] = useState(false)
|
|
27
36
|
|
|
28
37
|
const theme = useTheme();
|
|
29
38
|
|
|
@@ -38,6 +47,7 @@ const ForgotPasswordUI = (props: any) => {
|
|
|
38
47
|
});
|
|
39
48
|
|
|
40
49
|
const [emailSent, setEmailSent] = useState(null);
|
|
50
|
+
const recaptchaRef = useRef<any>({});
|
|
41
51
|
|
|
42
52
|
const onSubmit = (values: any) => {
|
|
43
53
|
setEmailSent(values.email)
|
|
@@ -48,23 +58,52 @@ const ForgotPasswordUI = (props: any) => {
|
|
|
48
58
|
onChange(value.toLowerCase().replace(/[&,()%";:ç?<>{}\\[\]\s]/g, ''))
|
|
49
59
|
}
|
|
50
60
|
|
|
61
|
+
const handleOpenRecaptcha = () => {
|
|
62
|
+
setRecaptchaVerified(false)
|
|
63
|
+
if (!recaptchaConfig?.siteKey) {
|
|
64
|
+
showToast(ToastType.Error, t('NO_RECAPTCHA_SITE_KEY', 'The config doesn\'t have recaptcha site key'));
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
if (!recaptchaConfig?.baseUrl) {
|
|
68
|
+
showToast(ToastType.Error, t('NO_RECAPTCHA_BASE_URL', 'The config doesn\'t have recaptcha base url'));
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
recaptchaRef.current.open()
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const onRecaptchaVerify = (token: any) => {
|
|
75
|
+
setRecaptchaVerified(true)
|
|
76
|
+
handleReCaptcha(token)
|
|
77
|
+
}
|
|
78
|
+
|
|
51
79
|
useEffect(() => {
|
|
52
80
|
if (!formState.loading && emailSent) {
|
|
53
81
|
if (formState.result?.error) {
|
|
54
82
|
setEmailSent(null)
|
|
55
83
|
formState.result?.result && showToast(
|
|
56
84
|
ToastType.Error,
|
|
57
|
-
formState.result?.result
|
|
85
|
+
typeof formState.result?.result === 'string'
|
|
86
|
+
? formState.result?.result
|
|
87
|
+
: formState.result?.result[0]
|
|
58
88
|
)
|
|
59
89
|
return
|
|
60
90
|
}
|
|
61
91
|
showToast(
|
|
62
92
|
ToastType.Success,
|
|
63
|
-
|
|
93
|
+
t('IF_ACCOUNT_EXIST_EMAIL_SEND_PASSWORD', 'If an account exists with this email a password will be sent')
|
|
64
94
|
)
|
|
65
95
|
}
|
|
66
96
|
}, [formState])
|
|
67
97
|
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
if (configs && Object.keys(configs).length > 0 && enableReCaptcha) {
|
|
100
|
+
setRecaptchaConfig({
|
|
101
|
+
siteKey: configs?.security_recaptcha_site_key?.value || null,
|
|
102
|
+
baseUrl: configs?.security_recaptcha_base_url?.value || null
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
}, [configs, enableReCaptcha])
|
|
106
|
+
|
|
68
107
|
return (
|
|
69
108
|
<Container>
|
|
70
109
|
<NavBar
|
|
@@ -126,6 +165,37 @@ const ForgotPasswordUI = (props: any) => {
|
|
|
126
165
|
}}
|
|
127
166
|
defaultValue=""
|
|
128
167
|
/>
|
|
168
|
+
{enableReCaptcha && (
|
|
169
|
+
<>
|
|
170
|
+
<TouchableOpacity
|
|
171
|
+
onPress={handleOpenRecaptcha}
|
|
172
|
+
>
|
|
173
|
+
<RecaptchaButton>
|
|
174
|
+
{recaptchaVerified ? (
|
|
175
|
+
<MaterialCommunityIcons
|
|
176
|
+
name="checkbox-marked"
|
|
177
|
+
size={26}
|
|
178
|
+
color={theme.colors.primary}
|
|
179
|
+
/>
|
|
180
|
+
) : (
|
|
181
|
+
<MaterialCommunityIcons
|
|
182
|
+
name="checkbox-blank-outline"
|
|
183
|
+
size={26}
|
|
184
|
+
color={theme.colors.mediumGray}
|
|
185
|
+
/>
|
|
186
|
+
)}
|
|
187
|
+
<OText size={14} mLeft={8}>{t('VERIFY_ReCAPTCHA', 'Verify reCAPTCHA')}</OText>
|
|
188
|
+
</RecaptchaButton>
|
|
189
|
+
</TouchableOpacity>
|
|
190
|
+
<Recaptcha
|
|
191
|
+
ref={recaptchaRef}
|
|
192
|
+
siteKey={recaptchaConfig?.siteKey}
|
|
193
|
+
baseUrl={recaptchaConfig?.baseUrl}
|
|
194
|
+
onVerify={onRecaptchaVerify}
|
|
195
|
+
onExpire={() => setRecaptchaVerified(false)}
|
|
196
|
+
/>
|
|
197
|
+
</>
|
|
198
|
+
)}
|
|
129
199
|
|
|
130
200
|
<OButton
|
|
131
201
|
text={emailSent && !formState.result?.error ? t('LINK_SEND_FORGOT_PASSWORD', 'Link Sent') : t('FRONT_RECOVER_PASSWORD', 'Recover Password')}
|
|
@@ -146,6 +216,7 @@ const ForgotPasswordUI = (props: any) => {
|
|
|
146
216
|
export const ForgotPasswordForm = (props: any) => {
|
|
147
217
|
const ForgotPasswordProps = {
|
|
148
218
|
...props,
|
|
219
|
+
isRecaptchaEnable: true,
|
|
149
220
|
UIComponent: ForgotPasswordUI
|
|
150
221
|
}
|
|
151
222
|
return <ForgotPasswordController {...ForgotPasswordProps} />
|
|
@@ -363,6 +363,27 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
|
|
|
363
363
|
)
|
|
364
364
|
}
|
|
365
365
|
|
|
366
|
+
const RenderGoogleMap = () => {
|
|
367
|
+
const driverLocationString = typeof order?.driver?.location?.location === 'string' && order?.driver?.location?.location?.split(',').map((l : string) => l.replace(/[^-.0-9]/g, ''))
|
|
368
|
+
const parsedLocations = locations.map(location => typeof location?.location === 'string' ? {
|
|
369
|
+
...location,
|
|
370
|
+
lat: parseFloat(location?.location?.split(',')[0].replace(/[^-.0-9]/g, '')),
|
|
371
|
+
lng: parseFloat(location?.location?.split(',')[1].replace(/[^-.0-9]/g, ''))
|
|
372
|
+
} : location)
|
|
373
|
+
|
|
374
|
+
return (
|
|
375
|
+
<GoogleMap
|
|
376
|
+
location={typeof order?.driver?.location?.location === 'string'
|
|
377
|
+
? {
|
|
378
|
+
lat: parseFloat(driverLocationString[0]),
|
|
379
|
+
lng: parseFloat(driverLocationString[1]),
|
|
380
|
+
} : order?.driver?.location
|
|
381
|
+
}
|
|
382
|
+
locations={parsedLocations}
|
|
383
|
+
readOnly
|
|
384
|
+
/>
|
|
385
|
+
)
|
|
386
|
+
}
|
|
366
387
|
|
|
367
388
|
useEffect(() => {
|
|
368
389
|
if (reorderState?.error) {
|
|
@@ -683,11 +704,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
|
|
|
683
704
|
<>
|
|
684
705
|
{order?.driver?.location && mapValidStatuses.includes(parseInt(order?.status)) && (
|
|
685
706
|
<Map>
|
|
686
|
-
<
|
|
687
|
-
location={order?.driver?.location}
|
|
688
|
-
locations={locations}
|
|
689
|
-
readOnly
|
|
690
|
-
/>
|
|
707
|
+
<RenderGoogleMap />
|
|
691
708
|
</Map>
|
|
692
709
|
)}
|
|
693
710
|
</>
|