ordering-ui-react-native 0.16.3 → 0.16.4

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.16.3",
3
+ "version": "0.16.4",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -92,6 +92,8 @@ const LoginFormUI = (props: LoginParams) => {
92
92
 
93
93
  const inputRef = useRef<any>({})
94
94
 
95
+ const googleLoginEnabled = configs?.google_login_enabled?.value === '1' || !configs?.google_login_enabled?.enabled
96
+
95
97
  const anySocialButtonActivated = ((configs?.facebook_login?.value === 'true' || configs?.facebook_login?.value === '1') && configs?.facebook_id?.value) ||
96
98
  (configs?.google_login_client_id?.value !== '' && configs?.google_login_client_id?.value !== null) ||
97
99
  (configs?.apple_login_client_id?.value !== '' && configs?.apple_login_client_id?.value !== null)
@@ -381,7 +383,7 @@ const LoginFormUI = (props: LoginParams) => {
381
383
  handleSuccessFacebookLogin={handleSuccessFacebook}
382
384
  />
383
385
  )}
384
- {(configs?.google_login_client_id?.value !== '' && configs?.google_login_client_id?.value !== null) && (
386
+ {(configs?.google_login_client_id?.value !== '' && configs?.google_login_client_id?.value !== null) && googleLoginEnabled && (
385
387
  <GoogleLogin
386
388
  notificationState={notificationState}
387
389
  webClientId={configs?.google_login_client_id?.value}
@@ -115,6 +115,8 @@ const SignupFormUI = (props: SignupParams) => {
115
115
  const phoneRef = useRef<any>(null)
116
116
  const passwordRef = useRef<any>(null)
117
117
 
118
+ const googleLoginEnabled = configs?.google_login_enabled?.value === '1' || !configs?.google_login_enabled?.enabled
119
+
118
120
  const anySocialButtonActivated = ((configs?.facebook_login?.value === 'true' || configs?.facebook_login?.value === '1') && configs?.facebook_id?.value) ||
119
121
  (configs?.google_login_client_id?.value !== '' && configs?.google_login_client_id?.value !== null) ||
120
122
  (configs?.apple_login_client_id?.value !== '' && configs?.apple_login_client_id?.value !== null)
@@ -543,7 +545,7 @@ const SignupFormUI = (props: SignupParams) => {
543
545
  handleSuccessFacebookLogin={handleSuccessFacebook}
544
546
  />
545
547
  )}
546
- {(configs?.google_login_client_id?.value !== '' && configs?.google_login_client_id?.value !== null) && (
548
+ {(configs?.google_login_client_id?.value !== '' && configs?.google_login_client_id?.value !== null) && googleLoginEnabled && (
547
549
  <GoogleLogin
548
550
  notificationState={notificationState}
549
551
  webClientId={configs?.google_login_client_id?.value}
@@ -78,7 +78,7 @@ const OModal = (props: Props): React.ReactElement => {
78
78
  animationType="slide"
79
79
  transparent={isTransparent}
80
80
  visible={open}
81
- onRequestClose={() => { onClose() }}
81
+ onRequestClose={() => { onClose && onClose() }}
82
82
  style={{ height: '100%', flex: 1, position: 'absolute', ...style, zIndex: 9999 }}
83
83
  >
84
84
  {isAvoidKeyBoardView ? (
@@ -165,7 +165,7 @@ const OModal = (props: Props): React.ReactElement => {
165
165
  transparent={isTransparent}
166
166
  visible={open}
167
167
  onRequestClose={() => {
168
- onClose();
168
+ onClose && onClose();
169
169
  }}
170
170
  style={{
171
171
  height: '100%',
@@ -144,7 +144,7 @@ const BusinessPreorderUI = (props: BusinessPreorderParams) => {
144
144
 
145
145
  const validateSelectedDate = (curdate: any, menu: any) => {
146
146
  const day = moment(curdate).format('d')
147
- setIsEnabled(menu?.schedule[day]?.enabled || false)
147
+ setIsEnabled(menu?.schedule?.[day]?.enabled || false)
148
148
  }
149
149
 
150
150
  const getTimes = (curdate: any, menu: any) => {
@@ -57,12 +57,12 @@ const BusinessProductsCategoriesUI = (props: any) => {
57
57
 
58
58
  if (!lazyLoadProductsRecommended) {
59
59
  if (category?.id) {
60
- scrollViewRef.current.scrollTo({
60
+ scrollViewRef?.current?.scrollTo && scrollViewRef.current.scrollTo({
61
61
  y: categoriesLayout[`cat_${category?.id}`]?.y + productListLayout?.y - 70,
62
62
  animated: true
63
63
  })
64
64
  } else {
65
- scrollViewRef.current.scrollTo({
65
+ scrollViewRef?.current?.scrollTo && scrollViewRef.current.scrollTo({
66
66
  y: productListLayout?.y - 70,
67
67
  animated: true
68
68
  })
@@ -106,7 +106,7 @@ const CartUI = (props: any) => {
106
106
  }
107
107
 
108
108
  const getIncludedTaxes = () => {
109
- if (cart?.taxes === null) {
109
+ if (cart?.taxes === null || !cart?.taxes) {
110
110
  return cart.business.tax_type === 1 ? cart?.tax : 0
111
111
  } else {
112
112
  return cart?.taxes.reduce((taxIncluded: number, tax: any) => {
@@ -193,6 +193,7 @@ export const GoogleMap = (props: GoogleMapsParams) => {
193
193
  <React.Fragment key={i}>
194
194
  {
195
195
  <Marker
196
+ zIndex={i}
196
197
  coordinate={location}
197
198
  title={locations[i]?.title}
198
199
  >
@@ -99,6 +99,8 @@ const LoginFormUI = (props: LoginParams) => {
99
99
  const theme = useTheme();
100
100
  const isOtpEmail = loginTab === 'otp' && otpType === 'email'
101
101
  const isOtpCellphone = loginTab === 'otp' && otpType === 'cellphone'
102
+ const googleLoginEnabled = configs?.google_login_enabled?.value === '1' || !configs?.google_login_enabled?.enabled
103
+
102
104
  const loginStyle = StyleSheet.create({
103
105
  btnOutline: {
104
106
  backgroundColor: '#FFF',
@@ -710,7 +712,7 @@ const LoginFormUI = (props: LoginParams) => {
710
712
  handleSuccessFacebookLogin={handleSuccessFacebook}
711
713
  />
712
714
  )}
713
- {(configs?.google_login_client_id?.value !== '' && configs?.google_login_client_id?.value !== null) && (
715
+ {(configs?.google_login_client_id?.value !== '' && configs?.google_login_client_id?.value !== null) && googleLoginEnabled && (
714
716
  <GoogleLogin
715
717
  notificationState={notificationState}
716
718
  webClientId={configs?.google_login_client_id?.value}
@@ -333,7 +333,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
333
333
  };
334
334
 
335
335
  const getIncludedTaxes = () => {
336
- if (order?.taxes?.length === 0) {
336
+ if (order?.taxes?.length === 0 || !order?.taxes) {
337
337
  return order.tax_type === 1 ? order?.summary?.tax ?? 0 : 0
338
338
  } else {
339
339
  return order?.taxes.reduce((taxIncluded: number, tax: any) => {
@@ -364,27 +364,6 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
364
364
  )
365
365
  }
366
366
 
367
- const RenderGoogleMap = () => {
368
- const driverLocationString = typeof order?.driver?.location?.location === 'string' && order?.driver?.location?.location?.split(',').map((l: string) => l.replace(/[^-.0-9]/g, ''))
369
- const parsedLocations = locations.map(location => typeof location?.location === 'string' ? {
370
- ...location,
371
- lat: parseFloat(location?.location?.split(',')[0].replace(/[^-.0-9]/g, '')),
372
- lng: parseFloat(location?.location?.split(',')[1].replace(/[^-.0-9]/g, ''))
373
- } : location)
374
-
375
- return (
376
- <GoogleMap
377
- location={typeof order?.driver?.location?.location === 'string'
378
- ? {
379
- lat: parseFloat(driverLocationString[0]),
380
- lng: parseFloat(driverLocationString[1]),
381
- } : order?.driver?.location
382
- }
383
- locations={parsedLocations}
384
- readOnly
385
- />
386
- )
387
- }
388
367
 
389
368
  useEffect(() => {
390
369
  const _businessId = 'businessId:' + businessData?.id
@@ -436,6 +415,12 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
436
415
  'https://res.cloudinary.com/demo/image/upload/c_thumb,g_face,r_max/d_avatar.png/non_existing_id.png',
437
416
  },
438
417
  ];
418
+ const driverLocationString = typeof order?.driver?.location?.location === 'string' && order?.driver?.location?.location?.split(',').map((l: string) => l.replace(/[^-.0-9]/g, ''))
419
+ const parsedLocations = locations.map(location => typeof location?.location === 'string' ? {
420
+ ...location,
421
+ lat: parseFloat(location?.location?.split(',')[0].replace(/[^-.0-9]/g, '')),
422
+ lng: parseFloat(location?.location?.split(',')[1].replace(/[^-.0-9]/g, ''))
423
+ } : location)
439
424
 
440
425
  useEffect(() => {
441
426
  if (driverLocation) {
@@ -697,7 +682,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
697
682
  </OText>
698
683
  </View>
699
684
  )}
700
- {order?.comment && (
685
+ {!!order?.comment && (
701
686
  <View style={{ marginTop: 15 }}>
702
687
  <OText size={16} style={{ textAlign: 'left' }} color={theme.colors.textNormal}>
703
688
  {t('COMMENT', 'Comment')}
@@ -709,7 +694,16 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
709
694
  <>
710
695
  {order?.driver?.location && mapValidStatuses.includes(parseInt(order?.status)) && (
711
696
  <Map>
712
- <RenderGoogleMap />
697
+ <GoogleMap
698
+ location={typeof order?.driver?.location?.location === 'string'
699
+ ? {
700
+ lat: parseFloat(driverLocationString[0]),
701
+ lng: parseFloat(driverLocationString[1]),
702
+ } : driverLocation ?? order?.driver?.location
703
+ }
704
+ locations={parsedLocations}
705
+ readOnly
706
+ />
713
707
  </Map>
714
708
  )}
715
709
  </>
@@ -71,7 +71,7 @@ const OrderSummaryUI = (props: any) => {
71
71
  }
72
72
 
73
73
  const getIncludedTaxes = () => {
74
- if (cart?.taxes === null) {
74
+ if (cart?.taxes === null || !cart?.taxes) {
75
75
  return cart.business.tax_type === 1 ? cart?.tax : 0
76
76
  } else {
77
77
  return cart?.taxes.reduce((taxIncluded: number, tax: any) => {
@@ -9,7 +9,7 @@ import { PreviousOrders } from '../PreviousOrders'
9
9
 
10
10
  import { OptionTitle, NoOrdersWrapper } from './styles'
11
11
  import { OrdersOptionParams } from '../../types'
12
-
12
+ import { _setStoreData } from '../../providers/StoreUtil';
13
13
  import {
14
14
  Placeholder,
15
15
  PlaceholderLine,
@@ -35,13 +35,15 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
35
35
  setOrdersLength,
36
36
  ordersLength,
37
37
  refreshOrders,
38
- setRefreshOrders
38
+ setRefreshOrders,
39
+ reorderState,
40
+ handleReorder
39
41
  } = props
40
42
 
41
43
  const theme = useTheme();
42
44
 
43
45
  const [, t] = useLanguage()
44
- const [, { reorder }] = useOrder()
46
+ const [{ carts }] = useOrder()
45
47
  const { showToast } = useToast()
46
48
  const { loading, error, orders: values } = orderList
47
49
 
@@ -51,26 +53,6 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
51
53
 
52
54
  const orders = customArray || values || []
53
55
 
54
- const [reorderLoading, setReorderLoading] = useState(false)
55
-
56
-
57
- const handleReorder = async (orderId: number) => {
58
- setReorderLoading(true)
59
- try {
60
- const { error, result } = await reorder(orderId)
61
- if (!error) {
62
- onNavigationRedirect && onNavigationRedirect('CheckoutNavigator', { cartUuid: result.uuid })
63
- setReorderLoading(false)
64
- return
65
- }
66
- setReorderLoading(false)
67
-
68
- } catch (err: any) {
69
- showToast(ToastType.Error, t('ERROR', err.message))
70
- setReorderLoading(false)
71
- }
72
- }
73
-
74
56
  const getOrderStatus = (s: string) => {
75
57
  const status = parseInt(s)
76
58
  const orderStatus = [
@@ -105,6 +87,29 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
105
87
  return objectStatus && objectStatus
106
88
  }
107
89
 
90
+ useEffect(() => {
91
+ const _businessId = 'businessId:' + reorderState?.result?.business_id
92
+ if (reorderState?.error) {
93
+ if (reorderState?.result?.business_id) {
94
+ _setStoreData('adjust-cart-products', JSON.stringify(_businessId))
95
+ navigation.navigate('Business', { store: reorderState?.result?.business?.slug })
96
+ }
97
+ }
98
+ if (!reorderState?.error && reorderState.loading === false && reorderState?.result?.business_id) {
99
+ const cartProducts = carts?.[_businessId]?.products
100
+ const available = cartProducts.every((product: any) => product.valid === true)
101
+ const orderProducts = orders.find((order: any) => order?.id === reorderState?.result?.orderId)?.products
102
+
103
+ if (available && reorderState?.result?.uuid && (cartProducts?.length === orderProducts?.length)) {
104
+ onNavigationRedirect && onNavigationRedirect('CheckoutNavigator', { cartUuid: reorderState?.result.uuid })
105
+ } else {
106
+ _setStoreData('adjust-cart-products', JSON.stringify(_businessId))
107
+ cartProducts?.length !== orderProducts?.length && _setStoreData('already-removed', JSON.stringify('removed'))
108
+ navigation.navigate('Business', { store: reorderState?.result?.business?.slug })
109
+ }
110
+ }
111
+ }, [reorderState])
112
+
108
113
  useFocusEffect(
109
114
  React.useCallback(() => {
110
115
  loadOrders(false, false, false, true)
@@ -213,7 +218,7 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
213
218
  orders={orders.filter((order: any) => orderStatus.includes(order.status))}
214
219
  pagination={pagination}
215
220
  loadMoreOrders={loadMoreOrders}
216
- reorderLoading={reorderLoading}
221
+ reorderLoading={reorderState?.loading}
217
222
  customArray={customArray}
218
223
  getOrderStatus={getOrderStatus}
219
224
  onNavigationRedirect={onNavigationRedirect}
@@ -222,14 +227,14 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
222
227
  <ActiveOrders
223
228
  orders={orders.filter((order: any) => orderStatus.includes(order.status))}
224
229
  pagination={pagination}
225
- reorderLoading={reorderLoading}
230
+ reorderLoading={reorderState?.loading}
226
231
  customArray={customArray}
227
232
  getOrderStatus={getOrderStatus}
228
233
  onNavigationRedirect={onNavigationRedirect}
229
234
  />
230
235
  ) : (
231
236
  <PreviousOrders
232
- reorderLoading={reorderLoading}
237
+ reorderLoading={reorderState?.loading}
233
238
  orders={orders.filter((order: any) => orderStatus.includes(order.status)).sort((a: any, b: any) => a?.id < b?.id)}
234
239
  pagination={pagination}
235
240
  loadMoreOrders={loadMoreOrders}
@@ -100,7 +100,7 @@ export const PreviousOrders = (props: PreviousOrdersParams) => {
100
100
 
101
101
  const handleReorderClick = (id: number) => {
102
102
  setReorderSelected(id);
103
- handleReorder(id);
103
+ handleReorder && handleReorder(id);
104
104
  };
105
105
 
106
106
  return (
@@ -135,6 +135,7 @@ const SignupFormUI = (props: SignupParams) => {
135
135
  const recaptchaRef = useRef<any>({});
136
136
 
137
137
  const showInputPhoneNumber = (validationFields?.fields?.checkout?.cellphone?.enabled ?? false) || configs?.verification_phone_required?.value === '1'
138
+ const googleLoginEnabled = configs?.google_login_enabled?.value === '1' || !configs?.google_login_enabled?.enabled
138
139
 
139
140
  const handleRefs = (ref: any, code: string) => {
140
141
  switch (code) {
@@ -787,7 +788,7 @@ const SignupFormUI = (props: SignupParams) => {
787
788
  handleSuccessFacebookLogin={handleSuccessFacebook}
788
789
  />
789
790
  )}
790
- {(configs?.google_login_client_id?.value !== '' && configs?.google_login_client_id?.value !== null) && (
791
+ {(configs?.google_login_client_id?.value !== '' && configs?.google_login_client_id?.value !== null) && googleLoginEnabled && (
791
792
  <GoogleLogin
792
793
  notificationState={notificationState}
793
794
  webClientId={configs?.google_login_client_id?.value}
@@ -91,7 +91,7 @@ const OModal = (props: Props): React.ReactElement => {
91
91
  animationType="slide"
92
92
  transparent={isTransparent}
93
93
  visible={open}
94
- onRequestClose={() => onClose()}
94
+ onRequestClose={() => onClose && onClose()}
95
95
  style={{ height: '100%', flex: 1, position: 'absolute', ...style, zIndex: 9999 }}
96
96
  >
97
97
  {isAvoidKeyBoardView ? (
@@ -311,6 +311,8 @@ export interface OrdersOptionParams {
311
311
  loadOrders?: any,
312
312
  setOrderList?: any,
313
313
  preOrders?: boolean,
314
+ reorderState?: any,
315
+ handleReorder?: (orderId: number) => {},
314
316
  setOrdersLength?: ({ activeOrdersLength, previousOrdersLength }: { activeOrdersLength: number, previousOrdersLength: number }) => void,
315
317
  ordersLength: { activeOrdersLength: number, previousOrdersLength: number },
316
318
  setSelectedOrderId?: any,
@@ -339,7 +341,7 @@ export interface PreviousOrdersParams {
339
341
  orderID?: number
340
342
  reorderLoading?: boolean,
341
343
  loadMoreOrders?: () => {},
342
- handleReorder: (order: any) => {},
344
+ handleReorder?: (orderId: number) => {},
343
345
  onNavigationRedirect?: (route: string, params?: any) => {}
344
346
  }
345
347
  export interface OrderDetailsParams {