ordering-ui-react-native 0.18.40-test → 0.18.41

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.18.40-test",
3
+ "version": "0.18.41",
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, { useContext, useState } from 'react';
1
+ import React, { useState } from 'react';
2
2
  import { OText, OIconButton } from '../shared';
3
3
  import { StyleSheet, View, Platform, Alert } from 'react-native';
4
4
  import {
@@ -23,11 +23,7 @@ import { useTheme } from 'styled-components/native';
23
23
 
24
24
  import { ProductItemAccordion } from '../ProductItemAccordion';
25
25
 
26
- export const OrderSummary = ({ order, navigation, orderStatus, permissions,
27
- askBluetoothPermission,
28
- getPermissions,
29
- isGrantedPermissions,
30
- checkBluetoothPermission }: any) => {
26
+ export const OrderSummary = ({ order, navigation, orderStatus, askBluetoothPermission, getPermissions, isGrantedPermissions, checkBluetoothPermission }: any) => {
31
27
  const handleArrowBack: any = () => {
32
28
  navigation?.canGoBack() && navigation.goBack();
33
29
  };
@@ -377,8 +373,8 @@ export const OrderSummary = ({ order, navigation, orderStatus, permissions,
377
373
 
378
374
  <OText style={{ marginBottom: 5 }}>
379
375
  {`${t('DELIVERY_DATE', 'Delivery Date')}: ${order?.delivery_datetime_utc
380
- ? parseDate(order?.delivery_datetime_utc)
381
- : parseDate(order?.delivery_datetime, { utc: false })
376
+ ? parseDate(order?.delivery_datetime_utc)
377
+ : parseDate(order?.delivery_datetime, { utc: false })
382
378
  }`}
383
379
  </OText>
384
380
 
@@ -187,7 +187,7 @@ export const AnalyticsSegment = (props: any) => {
187
187
  segmentClient.track('Coupon Denied', {
188
188
  business_id: coupon.business_id,
189
189
  coupon: coupon.coupon,
190
- user_id: coupon.user.id,
190
+ user_id: coupon?.user_id,
191
191
  reason: typeof coupon.reason === 'string' ? t(coupon.reason) : t(coupon.reason[0])
192
192
  })
193
193
  }
@@ -1,5 +1,5 @@
1
1
  import React, { useEffect, useState } from 'react'
2
- import { useLanguage, BusinessSearchList, useOrder, useUtils, showToast, ToastType } from 'ordering-components/native'
2
+ import { useLanguage, BusinessSearchList, useOrder, useUtils, useEvent, showToast, ToastType } from 'ordering-components/native'
3
3
  import { ScrollView, StyleSheet, TouchableOpacity, View, Dimensions } from 'react-native'
4
4
  import { useSafeAreaInsets } from 'react-native-safe-area-context'
5
5
  import { useTheme } from 'styled-components/native'
@@ -54,6 +54,7 @@ export const BusinessListingSearchUI = (props: BusinessSearchParams) => {
54
54
  const screenWidth = Dimensions.get('window').width;
55
55
  const theme = useTheme()
56
56
  const [orderState] = useOrder()
57
+ const [events] = useEvent()
57
58
  const { top } = useSafeAreaInsets();
58
59
  const [, t] = useLanguage()
59
60
  const [{ parsePrice, parseDistance, optimizeImage }] = useUtils();
@@ -225,6 +226,13 @@ export const BusinessListingSearchUI = (props: BusinessSearchParams) => {
225
226
  }
226
227
  };
227
228
 
229
+ const onChangeTermValue = (query: any) => {
230
+ handleChangeTermValue(query)
231
+ if (query) {
232
+ events.emit('products_searched', query)
233
+ }
234
+ }
235
+
228
236
  useEffect(() => {
229
237
  if (filters.business_types?.length === 0 && filters.orderBy === 'default' && Object.keys(filters)?.length === 2 && !openFilters) {
230
238
  handleSearchbusinessAndProducts(true)
@@ -287,7 +295,7 @@ export const BusinessListingSearchUI = (props: BusinessSearchParams) => {
287
295
  {...(isChewLayout && { height: 55 })}
288
296
  inputStyle={{ ...styles.searchInput }}
289
297
  placeholder={t('SEARCH_BUSINESSES', 'Search Businesses')}
290
- onSearch={(val: string) => handleChangeTermValue(val)}
298
+ onSearch={(val: string) => onChangeTermValue(val)}
291
299
  value={termValue}
292
300
  />
293
301
  </SearchWrapper>
@@ -261,7 +261,7 @@ const CheckoutUI = (props: any) => {
261
261
  const checkValidationFields = () => {
262
262
  setUserErrors([])
263
263
  const errors = []
264
- const notFields = ['coupon', 'driver_tip', 'mobile_phone', 'address', 'zipcode', 'address_notes']
264
+ const notFields = ['coupon', 'driver_tip', 'mobile_phone', 'address', 'zipcode', 'address_notes', 'comments']
265
265
  const _requiredFields: any = []
266
266
 
267
267
  Object.values(validationFields?.fields?.checkout).map((field: any) => {
@@ -454,7 +454,7 @@ export const MultiCheckout = (props: any) => {
454
454
  handleOnRedirectCheckout: (cartUuid: string) => {
455
455
  props.navigation.navigate('CheckoutNavigator', {
456
456
  screen: 'CheckoutPage',
457
- cartUuid: cartUuid
457
+ cartUuid
458
458
  })
459
459
  }
460
460
  }
@@ -18,7 +18,7 @@ import {
18
18
  } from "rn-placeholder";
19
19
 
20
20
  import { View, ScrollView } from 'react-native'
21
- import { getOrderStatus } from '../../utils'
21
+ import { getOrderStatus, flatArray } from '../../utils'
22
22
 
23
23
  const OrdersOptionUI = (props: OrdersOptionParams) => {
24
24
  const {
@@ -121,6 +121,7 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
121
121
  }
122
122
 
123
123
  useEffect(() => {
124
+ if (reorderState?.loading) return
124
125
  const _businessId = 'businessId:' + reorderState?.result?.business_id
125
126
  if (reorderState?.error) {
126
127
  if (reorderState?.result?.business_id) {
@@ -128,21 +129,39 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
128
129
  navigation.navigate('Business', { store: reorderState?.result?.business?.slug })
129
130
  }
130
131
  }
131
- if (!reorderState?.error && reorderState.loading === false && reorderState?.result?.business_id) {
132
+ if (!reorderState?.error && !reorderState.loading && reorderState?.result?.business_id) {
132
133
  const cartProducts = carts?.[_businessId]?.products
133
- const available = cartProducts.every((product: any) => product.valid === true)
134
- const orderProducts = orders.find((order: any) => order?.id === reorderState?.result?.orderId)?.products
135
134
 
136
- if (available && reorderState?.result?.uuid && (cartProducts?.length === orderProducts?.length)) {
137
- onNavigationRedirect && onNavigationRedirect('CheckoutNavigator', { cartUuid: reorderState?.result.uuid })
135
+ const available = cartProducts.every((product: any) => product.valid)
136
+ const orderProducts = orders.find(
137
+ (order: any) => Array.isArray(order?.id)
138
+ ? order?.id?.includes(reorderState?.result?.orderId)
139
+ : order?.id === reorderState?.result?.orderId
140
+ )?.products
141
+
142
+ const productsFlatten = orderProducts?.length && flatArray(orderProducts)?.filter(product => product?.order_id === reorderState?.result?.orderId)
143
+
144
+ if (available && reorderState?.result?.uuid && (cartProducts?.length === productsFlatten?.length)) {
145
+ const multiOrders = flatArray(orderProducts)?.map(product => product.order_id)
146
+ const params = multiOrders?.length > 1
147
+ ? { screen: 'MultiCheckout', checkCarts: true }
148
+ : { cartUuid: reorderState?.result.uuid }
149
+
150
+ onNavigationRedirect && onNavigationRedirect('CheckoutNavigator', params)
138
151
  } else {
139
152
  _setStoreData('adjust-cart-products', JSON.stringify(_businessId))
140
- cartProducts?.length !== orderProducts?.length && _setStoreData('already-removed', JSON.stringify('removed'))
153
+ cartProducts?.length !== productsFlatten?.length && _setStoreData('already-removed', JSON.stringify('removed'))
141
154
  navigation.navigate('Business', { store: reorderState?.result?.business?.slug })
142
155
  }
143
156
  }
144
157
  }, [reorderState])
145
158
 
159
+ useEffect(() => {
160
+ if (reorderState?.error) {
161
+ showToast(ToastType.Error, reorderState?.result)
162
+ }
163
+ }, [reorderState])
164
+
146
165
  useFocusEffect(
147
166
  React.useCallback(() => {
148
167
  if (!businessesSearchList) {
@@ -47,7 +47,7 @@ const SingleOrderCardUI = (props: SingleOrderCardParams) => {
47
47
  const theme = useTheme();
48
48
  const isFocused = useIsFocused();
49
49
 
50
- const [reorderSelected, setReorderSelected] = useState<number | null>(null);
50
+ let [reorderSelected, setReorderSelected] = useState<number | null>(null);
51
51
  const [confirm, setConfirm] = useState<any>({ open: false, content: null, handleOnAccept: null, id: null, title: null })
52
52
  const [isPressed, setIsPressed] = useState(false)
53
53
 
@@ -130,19 +130,29 @@ const SingleOrderCardUI = (props: SingleOrderCardParams) => {
130
130
  });
131
131
 
132
132
  const handleReorderClick = (order: any) => {
133
- if (carts[`businessId:${order?.business_id}`] && carts[`businessId:${order?.business_id}`]?.products?.length > 0) {
133
+ setReorderSelected(null)
134
+ reorderSelected = null
135
+ const isMultiOrders = Array.isArray(order?.id)
136
+
137
+ const isRemoveCart = isMultiOrders
138
+ ? order?.business_id?.some((businessId: any) => !!carts[`businessId:${businessId}`]?.uuid)
139
+ : carts[`businessId:${order?.business_id}`] && !!carts[`businessId:${order?.business_id}`]?.uuid
140
+
141
+ if (isRemoveCart) {
134
142
  setConfirm({
135
143
  open: true,
136
144
  content: [t('QUESTION_DELETE_PRODUCTS_FROM_CART', 'Are you sure that you want to delete all products from cart?')],
137
145
  title: t('ORDER', 'Order'),
138
146
  handleOnAccept: async () => {
139
- handleRemoveCart()
147
+ handleRemoveCart(order)
140
148
  setConfirm({ ...confirm, open: false })
141
149
  }
142
150
  })
143
151
  } else {
144
- setReorderSelected(order?.id);
145
- handleReorder && handleReorder(order?.id);
152
+ const orderId = Array.isArray(order?.id) ? order?.id[0] : order?.id
153
+ setReorderSelected(orderId)
154
+ reorderSelected = orderId
155
+ handleReorder && handleReorder(order?.id)
146
156
  }
147
157
  };
148
158
 
@@ -286,7 +296,7 @@ const SingleOrderCardUI = (props: SingleOrderCardParams) => {
286
296
  </OText>
287
297
  </TouchableOpacity>
288
298
  )}
289
- {order.cart && !hideReorderButton && (
299
+ {!hideReorderButton && order?.id === 'number' && (
290
300
  <OButton
291
301
  text={t('REORDER', 'Reorder')}
292
302
  imgRightSrc={''}
@@ -751,7 +751,7 @@ export interface SingleOrderCardParams {
751
751
  pastOrders: any,
752
752
  isMessageView?: any,
753
753
  handleClickOrder: (value: any) => {},
754
- handleRemoveCart: () => {},
754
+ handleRemoveCart: (value: any) => {},
755
755
  cartState: any
756
756
  }
757
757