ordering-ui-react-native 0.15.82 → 0.15.85

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,6 +1,6 @@
1
1
  {
2
2
  "name": "ordering-ui-react-native",
3
- "version": "0.15.82",
3
+ "version": "0.15.85",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -1,4 +1,4 @@
1
- import React, { useState } from 'react'
1
+ import React, { useEffect, useState } from 'react'
2
2
  import { LanguageSelector as LanguageSelectorController, useOrder } from 'ordering-components/native'
3
3
  import { useTheme } from 'styled-components/native';
4
4
  import { I18nManager, Platform, StyleSheet, View } from 'react-native'
@@ -87,7 +87,11 @@ const LanguageSelectorUI = (props: LanguageSelectorParams) => {
87
87
  changeDirection(Platform.OS === 'ios' ? language : langCode)
88
88
  handleChangeLanguage(Platform.OS === 'ios' ? language : langCode)
89
89
  }
90
-
90
+
91
+ useEffect(() => {
92
+ changeDirection(currentLanguage)
93
+ }, [])
94
+
91
95
  return (
92
96
  <Container>
93
97
  {languagesState?.languages ? (
@@ -239,7 +239,7 @@ const CheckoutUI = (props: any) => {
239
239
 
240
240
  useEffect(() => {
241
241
  if (cart?.products?.length === 0) {
242
- navigation?.canGoBack() && navigation.goBack();
242
+ onNavigationRedirect('Business', { store: cart?.business?.slug })
243
243
  }
244
244
  }, [cart?.products])
245
245
 
@@ -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[0]
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
- `${t('SUCCESS_SEND_FORGOT_PASSWORD', 'Your link has been sent to the email')}: ${emailSent}`
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
- <GoogleMap
687
- location={order?.driver?.location}
688
- locations={locations}
689
- readOnly
690
- />
707
+ <RenderGoogleMap />
691
708
  </Map>
692
709
  )}
693
710
  </>
@@ -59,7 +59,7 @@ export const PhoneInputNumber = (props: PhoneInputParams) => {
59
59
  }
60
60
 
61
61
  useEffect(() => {
62
- if ((defaultValue && userphoneNumber) || defaultValue === undefined || defaultValue === '') {
62
+ if ((defaultValue && userphoneNumber) || !defaultValue) {
63
63
  if (userphoneNumber) {
64
64
  const checkValid = phoneInput.current?.isValidNumber(userphoneNumber);
65
65
  const callingCode = phoneInput.current?.getCallingCode();
@@ -107,10 +107,6 @@ const UpsellingProductsUI = (props: UpsellingProductsParams) => {
107
107
  }
108
108
  }, [upsellingProducts.loading, upsellingProducts?.products.length])
109
109
 
110
- useEffect(() => {
111
- isCheckout && Object.keys(cart).length === 0 && onNavigationRedirect && onNavigationRedirect('MyOrders')
112
- }, [cart, isCheckout])
113
-
114
110
  const handleFormProduct = (product: any) => {
115
111
  onNavigationRedirect && onNavigationRedirect('ProductDetails', {
116
112
  product: product,