ordering-ui-react-native 0.17.55 → 0.17.57

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.17.55",
3
+ "version": "0.17.57",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -75,7 +75,7 @@ const BusinessProductsListingUI = (props: BusinessProductsListingParams) => {
75
75
  const theme = useTheme();
76
76
  const [, t] = useLanguage()
77
77
  const [{ auth }] = useSession()
78
- const [orderState, { clearCart }] = useOrder()
78
+ const [orderState, { addProduct, updateProduct }] = useOrder()
79
79
  const [{ parsePrice }] = useUtils()
80
80
  const [, { showToast }] = useToast()
81
81
  const [{ configs }] = useConfig()
@@ -134,6 +134,7 @@ const BusinessProductsListingUI = (props: BusinessProductsListingParams) => {
134
134
  const [searchBarHeight, setSearchBarHeight] = useState(60)
135
135
 
136
136
  const isCheckoutMultiBusinessEnabled: Boolean = configs?.checkout_multi_business_enabled?.value === '1'
137
+ const isQuickAddProduct = configs?.add_product_with_one_click?.value === '1'
137
138
  const openCarts = (Object.values(orderState?.carts)?.filter((cart: any) => cart?.products && cart?.products?.length && cart?.status !== 2 && cart?.valid_schedule && cart?.valid_products && cart?.valid_address && cart?.valid_maximum && cart?.valid_minimum && !cart?.wallets) || null) || []
138
139
 
139
140
  const currentCart: any = Object.values(orderState.carts).find((cart: any) => cart?.business?.slug === business?.slug) ?? {}
@@ -142,20 +143,39 @@ const BusinessProductsListingUI = (props: BusinessProductsListingParams) => {
142
143
  const onRedirect = (route: string, params?: any) => {
143
144
  navigation.navigate(route, params)
144
145
  }
145
-
146
- const onProductClick = (product: any) => {
147
- const productAddedToCartLength = currentCart?.products?.reduce((productsLength: number, Cproduct: any) => { return productsLength + (Cproduct?.id === product?.id ? Cproduct?.quantity : 0) }, 0) || 0
148
- if (product?.type === 'service' && business?.professionals?.length > 0) {
149
- setCurrentProduct(product)
150
- setOpenService(true)
151
- return
146
+ const onProductClick = async (product: any) => {
147
+ if (product.extras.length === 0 && !product.inventoried && auth && isQuickAddProduct) {
148
+ const isProductAddedToCart = currentCart?.products?.find((Cproduct: any) => Cproduct.id === product.id)
149
+ const productQuantity = isProductAddedToCart?.quantity
150
+ const addCurrentProduct = {
151
+ ...product,
152
+ quantity: 1
153
+ }
154
+ const updateCurrentProduct = {
155
+ id: product.id,
156
+ code: isProductAddedToCart?.code,
157
+ quantity: productQuantity + 1
158
+ }
159
+ const cartData = currentCart?.business_id ? currentCart : { business_id: business.id }
160
+ if (isProductAddedToCart) {
161
+ await updateProduct(updateCurrentProduct, cartData, isQuickAddProduct)
162
+ } else {
163
+ await addProduct(addCurrentProduct, cartData, isQuickAddProduct)
164
+ }
165
+ } else {
166
+ const productAddedToCartLength = currentCart?.products?.reduce((productsLength: number, Cproduct: any) => { return productsLength + (Cproduct?.id === product?.id ? Cproduct?.quantity : 0) }, 0) || 0
167
+ if (product?.type === 'service' && business?.professionals?.length > 0) {
168
+ setCurrentProduct(product)
169
+ setOpenService(true)
170
+ return
171
+ }
172
+ onRedirect('ProductDetails', {
173
+ product: product,
174
+ businessSlug: business.slug,
175
+ businessId: business.id,
176
+ productAddedToCartLength
177
+ })
152
178
  }
153
- onRedirect('ProductDetails', {
154
- product: product,
155
- businessSlug: business.slug,
156
- businessId: business.id,
157
- productAddedToCartLength
158
- })
159
179
  }
160
180
 
161
181
  const handleCancel = () => {
@@ -1,5 +1,5 @@
1
1
  import React, { useEffect, useState, useRef } from 'react';
2
- import { StyleSheet, View, Keyboard } from 'react-native';
2
+ import { StyleSheet, View, Keyboard, Vibration } from 'react-native';
3
3
  import Spinner from 'react-native-loading-spinner-overlay';
4
4
  import { useForm, Controller } from 'react-hook-form';
5
5
  import { PhoneInputNumber } from '../PhoneInputNumber';
@@ -165,6 +165,7 @@ const LoginFormUI = (props: LoginParams) => {
165
165
  if (loginTab === 'otp') {
166
166
  if (phoneInputData.error && (loginTab !== 'otp' || (otpType === 'cellphone' && loginTab === 'otp'))) {
167
167
  showToast(ToastType.Error, t('INVALID_PHONE_NUMBER', 'Invalid phone number'));
168
+ Vibration.vibrate()
168
169
  return
169
170
  }
170
171
  if (loginTab === 'otp') {
@@ -177,6 +178,7 @@ const LoginFormUI = (props: LoginParams) => {
177
178
  } else {
178
179
  if (phoneInputData.error) {
179
180
  showToast(ToastType.Error, phoneInputData.error);
181
+ Vibration.vibrate()
180
182
  return;
181
183
  }
182
184
  handleButtonLoginClick({
@@ -189,6 +191,7 @@ const LoginFormUI = (props: LoginParams) => {
189
191
  const handleVerifyCodeClick = () => {
190
192
  if (phoneInputData.error) {
191
193
  showToast(ToastType.Error, phoneInputData.error);
194
+ Vibration.vibrate()
192
195
  return;
193
196
  }
194
197
  if (
@@ -203,6 +206,7 @@ const LoginFormUI = (props: LoginParams) => {
203
206
  'The field Mobile phone is required.',
204
207
  ),
205
208
  );
209
+ Vibration.vibrate()
206
210
  return;
207
211
  }
208
212
  handleSendVerifyCode && handleSendVerifyCode(phoneInputData.phone);
@@ -224,10 +228,12 @@ const LoginFormUI = (props: LoginParams) => {
224
228
  setRecaptchaVerified(false)
225
229
  if (!recaptchaConfig?.siteKey) {
226
230
  showToast(ToastType.Error, t('NO_RECAPTCHA_SITE_KEY', 'The config doesn\'t have recaptcha site key'));
231
+ Vibration.vibrate()
227
232
  return
228
233
  }
229
234
  if (!recaptchaConfig?.baseUrl) {
230
235
  showToast(ToastType.Error, t('NO_RECAPTCHA_BASE_URL', 'The config doesn\'t have recaptcha base url'));
236
+ Vibration.vibrate()
231
237
  return
232
238
  }
233
239
 
@@ -304,6 +310,7 @@ const LoginFormUI = (props: LoginParams) => {
304
310
  baseUrl: configs?.security_recaptcha_base_url?.value || null
305
311
  })
306
312
  showToast(ToastType.Info, t('TRY_AGAIN', 'Please try again'))
313
+ Vibration.vibrate()
307
314
  return
308
315
  }
309
316
  formState.result?.result &&
@@ -313,6 +320,7 @@ const LoginFormUI = (props: LoginParams) => {
313
320
  ? formState.result?.result
314
321
  : formState.result?.result[0],
315
322
  );
323
+ formState.result?.result && Vibration.vibrate()
316
324
  }
317
325
  }, [formState]);
318
326
 
@@ -324,6 +332,7 @@ const LoginFormUI = (props: LoginParams) => {
324
332
  ? verifyPhoneState?.result?.result
325
333
  : verifyPhoneState?.result?.result[0];
326
334
  verifyPhoneState.result?.result && showToast(ToastType.Error, message);
335
+ verifyPhoneState.result?.result && Vibration.vibrate();
327
336
  setIsLoadingVerifyModal(false);
328
337
  return;
329
338
  }
@@ -363,6 +372,10 @@ const LoginFormUI = (props: LoginParams) => {
363
372
  }
364
373
  }, [checkPhoneCodeState])
365
374
 
375
+ useEffect(() => {
376
+ if (!!Object.values(errors)?.length) Vibration.vibrate()
377
+ }, [errors])
378
+
366
379
  return (
367
380
  <Container>
368
381
  <NavBar
@@ -720,8 +733,8 @@ const LoginFormUI = (props: LoginParams) => {
720
733
 
721
734
  {configs && Object.keys(configs).length > 0 ? (
722
735
  (((configs?.facebook_login?.value === 'true' || configs?.facebook_login?.value === '1') && configs?.facebook_id?.value && facebookLoginEnabled) ||
723
- ((configs?.google_login_client_id?.value !== '' && configs?.google_login_client_id?.value !== null) && googleLoginEnabled) ||
724
- ((configs?.apple_login_client_id?.value !== '' && configs?.apple_login_client_id?.value !== null) && appleLoginEnabled)) &&
736
+ ((configs?.google_login_client_id?.value !== '' && configs?.google_login_client_id?.value !== null) && googleLoginEnabled) ||
737
+ ((configs?.apple_login_client_id?.value !== '' && configs?.apple_login_client_id?.value !== null) && appleLoginEnabled)) &&
725
738
  (
726
739
  <>
727
740
  <View
@@ -749,7 +762,7 @@ const LoginFormUI = (props: LoginParams) => {
749
762
  facebookLoginEnabled && (
750
763
  <FacebookLogin
751
764
  notificationState={notificationState}
752
- handleErrors={(err: any) => showToast(ToastType.Error, err)}
765
+ handleErrors={(err: any) => { showToast(ToastType.Error, err), Vibration.vibrate() }}
753
766
  handleLoading={(val: boolean) => setIsFBLoading(val)}
754
767
  handleSuccessFacebookLogin={handleSuccessFacebook}
755
768
  />
@@ -758,7 +771,7 @@ const LoginFormUI = (props: LoginParams) => {
758
771
  <GoogleLogin
759
772
  notificationState={notificationState}
760
773
  webClientId={configs?.google_login_client_id?.value}
761
- handleErrors={(err: any) => showToast(ToastType.Error, err)}
774
+ handleErrors={(err: any) => { showToast(ToastType.Error, err), Vibration.vibrate() }}
762
775
  handleLoading={(val: boolean) => setIsFBLoading(val)}
763
776
  handleSuccessGoogleLogin={handleSuccessFacebook}
764
777
  />
@@ -766,7 +779,7 @@ const LoginFormUI = (props: LoginParams) => {
766
779
  {(configs?.apple_login_client_id?.value !== '' && configs?.google_login_client_id?.value !== null) && appleLoginEnabled && (
767
780
  <AppleLogin
768
781
  notificationState={notificationState}
769
- handleErrors={(err: any) => showToast(ToastType.Error, err)}
782
+ handleErrors={(err: any) => { showToast(ToastType.Error, err), Vibration.vibrate() }}
770
783
  handleLoading={(val: boolean) => setIsFBLoading(val)}
771
784
  handleSuccessAppleLogin={handleSuccessFacebook}
772
785
  />
@@ -1,5 +1,5 @@
1
1
  import React, { useEffect, useRef, useState } from 'react';
2
- import { View, Pressable, StyleSheet, Linking, Platform, TouchableOpacity } from 'react-native';
2
+ import { View, Pressable, StyleSheet, Linking, Platform, TouchableOpacity, Vibration } 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';
@@ -245,6 +245,7 @@ const SignupFormUI = (props: SignupParams) => {
245
245
  const onSubmit = (values?: any) => {
246
246
  if (phoneInputData.error && signUpTab !== 'otpEmail') {
247
247
  showToast(ToastType.Error, phoneInputData.error);
248
+ Vibration.vibrate()
248
249
  return;
249
250
  }
250
251
  if (
@@ -262,6 +263,7 @@ const SignupFormUI = (props: SignupParams) => {
262
263
  'The field Mobile phone is required.',
263
264
  ),
264
265
  );
266
+ Vibration.vibrate()
265
267
  return;
266
268
  }
267
269
  if (signUpTab === 'otpEmail' || signUpTab === 'otpCellphone') {
@@ -330,6 +332,7 @@ const SignupFormUI = (props: SignupParams) => {
330
332
  await Linking.openURL(url);
331
333
  } else {
332
334
  showToast(ToastType.Error, t('VALIDATION_ERROR_ACTIVE_URL', 'The _attribute_ is not a valid URL.').replace('_attribute_', t('URL', 'URL')))
335
+ Vibration.vibrate()
333
336
  }
334
337
  }
335
338
 
@@ -337,10 +340,12 @@ const SignupFormUI = (props: SignupParams) => {
337
340
  setRecaptchaVerified(false)
338
341
  if (!recaptchaConfig?.siteKey) {
339
342
  showToast(ToastType.Error, t('NO_RECAPTCHA_SITE_KEY', 'The config doesn\'t have recaptcha site key'));
343
+ Vibration.vibrate()
340
344
  return
341
345
  }
342
346
  if (!recaptchaConfig?.baseUrl) {
343
347
  showToast(ToastType.Error, t('NO_RECAPTCHA_BASE_URL', 'The config doesn\'t have recaptcha base url'));
348
+ Vibration.vibrate()
344
349
  return
345
350
  }
346
351
  recaptchaRef.current.open()
@@ -384,10 +389,11 @@ const SignupFormUI = (props: SignupParams) => {
384
389
  baseUrl: configs?.security_recaptcha_base_url?.value || null
385
390
  })
386
391
  showToast(ToastType.Info, t('TRY_AGAIN', 'Please try again'))
392
+ Vibration.vibrate()
387
393
  return
388
394
  }
389
- formState.result?.result &&
390
- showToast(ToastType.Error, formState.result?.result[0]);
395
+ formState.result?.result && showToast(ToastType.Error, formState.result?.result[0]);
396
+ formState.result?.result && Vibration.vibrate()
391
397
  setIsLoadingVerifyModal(false);
392
398
  }
393
399
  }, [formState]);
@@ -395,6 +401,7 @@ const SignupFormUI = (props: SignupParams) => {
395
401
  useEffect(() => {
396
402
  if (Object.keys(errors).length > 0) {
397
403
  setIsLoadingVerifyModal(false);
404
+ Vibration.vibrate()
398
405
  }
399
406
  }, [errors])
400
407
 
@@ -423,6 +430,7 @@ const SignupFormUI = (props: SignupParams) => {
423
430
  ? verifyPhoneState?.result?.result
424
431
  : verifyPhoneState?.result?.result[0];
425
432
  verifyPhoneState.result?.result && showToast(ToastType.Error, message);
433
+ verifyPhoneState.result?.result && Vibration.vibrate()
426
434
  setIsLoadingVerifyModal(false);
427
435
  return;
428
436
  }
@@ -918,7 +926,7 @@ const SignupFormUI = (props: SignupParams) => {
918
926
  (
919
927
  <FacebookLogin
920
928
  notificationState={notificationState}
921
- handleErrors={(err: any) => showToast(ToastType.Error, err)}
929
+ handleErrors={(err: any) => { showToast(ToastType.Error, err), Vibration.vibrate() }}
922
930
  handleLoading={(val: boolean) => setIsFBLoading(val)}
923
931
  handleSuccessFacebookLogin={handleSuccessFacebook}
924
932
  />
@@ -927,7 +935,7 @@ const SignupFormUI = (props: SignupParams) => {
927
935
  <GoogleLogin
928
936
  notificationState={notificationState}
929
937
  webClientId={configs?.google_login_client_id?.value}
930
- handleErrors={(err: any) => showToast(ToastType.Error, err)}
938
+ handleErrors={(err: any) => { showToast(ToastType.Error, err), Vibration.vibrate() }}
931
939
  handleLoading={(val: boolean) => setIsFBLoading(val)}
932
940
  handleSuccessGoogleLogin={handleSuccessFacebook}
933
941
  />
@@ -935,7 +943,7 @@ const SignupFormUI = (props: SignupParams) => {
935
943
  {(configs?.apple_login_client_id?.value !== '' && configs?.apple_login_client_id?.value !== null) && appleLoginEnabled && (
936
944
  <AppleLogin
937
945
  notificationState={notificationState}
938
- handleErrors={(err: any) => showToast(ToastType.Error, err)}
946
+ handleErrors={(err: any) => { showToast(ToastType.Error, err), Vibration.vibrate() }}
939
947
  handleLoading={(val: boolean) => setIsFBLoading(val)}
940
948
  handleSuccessAppleLogin={handleSuccessFacebook}
941
949
  />