ordering-ui-react-native 0.14.70 → 0.14.71

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.14.70",
3
+ "version": "0.14.71",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -335,7 +335,7 @@ export const ProductOptionsUI = (props: any) => {
335
335
  />
336
336
  ) : (
337
337
  <OButton
338
- onClick={navigation.navigate('AddressList')}
338
+ onClick={() => navigation.navigate('AddressList')}
339
339
  />
340
340
  )
341
341
  )}
@@ -1,4 +1,4 @@
1
- import React, { useState } from 'react';
1
+ import React, { useState, useEffect } from 'react';
2
2
  import { StyleSheet, View, TouchableOpacity } from 'react-native';
3
3
  import { useUtils, useOrder, useLanguage } from 'ordering-components/native';
4
4
  import { useTheme } from 'styled-components/native';
@@ -7,6 +7,12 @@ import { BusinessBasicInformationParams } from '../../types';
7
7
  import { convertHoursToMinutes } from '../../utils';
8
8
  import { BusinessInformation } from '../BusinessInformation';
9
9
  import { BusinessReviews } from '../BusinessReviews';
10
+ import dayjs from 'dayjs';
11
+ import timezone from 'dayjs/plugin/timezone';
12
+ import isBetween from 'dayjs/plugin/isBetween';
13
+
14
+ dayjs.extend(timezone);
15
+ dayjs.extend(isBetween);
10
16
 
11
17
  import {
12
18
  BusinessContainer,
@@ -45,6 +51,31 @@ export const BusinessBasicInformation = (
45
51
  return _types.join(', ');
46
52
  };
47
53
 
54
+
55
+ useEffect(() => {
56
+ if (businessState?.loading) return
57
+ let timeout: any = null
58
+ const currentDate = dayjs().tz(businessState?.business?.timezone)
59
+ let lapse = null
60
+ if (businessState?.business?.today?.enabled) {
61
+ lapse = businessState?.business?.today?.lapses?.find((lapse: any) => {
62
+ const from = currentDate.hour(lapse.open.hour).minute(lapse.open.minute)
63
+ const to = currentDate.hour(lapse.close.hour).minute(lapse.close.minute)
64
+ return currentDate.unix() >= from.unix() && currentDate.unix() <= to.unix()
65
+ })
66
+ }
67
+ if (lapse) {
68
+ const to = currentDate.hour(lapse.close.hour).minute(lapse.close.minute)
69
+ const timeToClose = (to.unix() - currentDate.unix()) * 1000
70
+ timeout = setTimeout(() => {
71
+ navigation.navigate('BusinessPreorder', { business: businessState?.business, handleBusinessClick: () => navigation?.goBack() })
72
+ }, timeToClose)
73
+ }
74
+ return () => {
75
+ timeout && clearTimeout(timeout)
76
+ }
77
+ }, [businessState?.business])
78
+
48
79
  return (
49
80
  <BusinessContainer>
50
81
  <BusinessHeader
@@ -2,12 +2,12 @@ import React, { useState, useEffect } from 'react'
2
2
  import { OrderList, useLanguage, useOrder, ToastType, useToast } from 'ordering-components/native'
3
3
  import { useTheme } from 'styled-components/native';
4
4
  import { useFocusEffect } from '@react-navigation/native'
5
- import { OText } from '../shared'
5
+ import { OText, OButton } from '../shared'
6
6
  import { NotFoundSource } from '../NotFoundSource'
7
7
  import { ActiveOrders } from '../ActiveOrders'
8
8
  import { PreviousOrders } from '../PreviousOrders'
9
9
 
10
- import { OptionTitle } from './styles'
10
+ import { OptionTitle, NoOrdersWrapper } from './styles'
11
11
  import { OrdersOptionParams } from '../../types'
12
12
 
13
13
  import {
@@ -32,6 +32,8 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
32
32
  loadMoreStatus,
33
33
  loadMoreOrders,
34
34
  loadOrders,
35
+ setOrdersLength,
36
+ ordersLength
35
37
  } = props
36
38
 
37
39
  const theme = useTheme();
@@ -112,28 +114,50 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
112
114
  }
113
115
  }, [loadMoreStatus, loading, pagination])
114
116
 
117
+ useEffect(() => {
118
+ if (loading) return
119
+
120
+ const updateOrders = orders.filter((order: any) => orderStatus.includes(order.status))
121
+
122
+ if (activeOrders) {
123
+ setOrdersLength && setOrdersLength({ ...ordersLength, activeOrdersLength: updateOrders?.length })
124
+ } else if (!preOrders) {
125
+ setOrdersLength && setOrdersLength({ ...ordersLength, previousOrdersLength: updateOrders?.length })
126
+ }
127
+ }, [orders?.length])
128
+
115
129
  return (
116
130
  <>
117
- {(orders.length > 0) && (
118
- <>
119
- <OptionTitle>
120
- <OText size={16} lineHeight={24} weight={'500'} color={theme.colors.textNormal} mBottom={10} >
121
- {titleContent || (activeOrders
122
- ? t('ACTIVE', 'Active')
123
- : preOrders
124
- ? t('PREORDERS', 'Preorders')
125
- : t('PAST', 'Past'))}
126
- </OText>
127
- </OptionTitle>
128
- </>
129
- )}
130
- {!loading && orders.length === 0 && (
131
+ <OptionTitle>
132
+ <OText size={16} lineHeight={24} weight={'500'} color={theme.colors.textNormal} mBottom={10} >
133
+ {titleContent || (activeOrders
134
+ ? t('ACTIVE', 'Active')
135
+ : preOrders
136
+ ? t('PREORDERS', 'Preorders')
137
+ : t('PAST', 'Past'))}
138
+ </OText>
139
+ </OptionTitle>
140
+ {!(activeOrders && ordersLength.activeOrdersLength === 0 && ordersLength.previousOrdersLength === 0) && !loading && orders.length === 0 && (
131
141
  <NotFoundSource
132
142
  content={t('NO_RESULTS_FOUND', 'Sorry, no results found')}
133
143
  image={imageFails}
134
144
  conditioned
135
145
  />
136
146
  )}
147
+ {!loading && ordersLength.activeOrdersLength === 0 && ordersLength.previousOrdersLength === 0 && activeOrders && (
148
+ <NoOrdersWrapper>
149
+ <OText size={14} numberOfLines={1}>
150
+ {t('YOU_DONT_HAVE_ORDERS', 'You don\'t have any orders')}
151
+ </OText>
152
+ <OButton
153
+ text={t('ORDER_NOW', 'Order now')}
154
+ onClick={() => onNavigationRedirect && onNavigationRedirect('BusinessList')}
155
+ textStyle={{ color: 'white', fontSize: 14 }}
156
+ style={{ borderRadius: 7.6, marginBottom: 10, marginTop: 10, height: 44, paddingLeft: 10, paddingRight: 10 }}
157
+ />
158
+
159
+ </NoOrdersWrapper>
160
+ )}
137
161
  {loading && (
138
162
  <>
139
163
  {!activeOrders ? (
@@ -3,3 +3,8 @@ import styled from 'styled-components/native'
3
3
  export const OptionTitle = styled.View`
4
4
  margin-top: 24px;
5
5
  `
6
+
7
+ export const NoOrdersWrapper = styled.View`
8
+ flex-direction: column;
9
+ align-items: center;
10
+ `
@@ -4,7 +4,9 @@ import {
4
4
  useSession,
5
5
  useLanguage,
6
6
  useOrder,
7
- useUtils
7
+ useUtils,
8
+ ToastType,
9
+ useToast
8
10
  } from 'ordering-components/native';
9
11
  import { useTheme } from 'styled-components/native';
10
12
  import { ProductIngredient } from '../ProductIngredient';
@@ -13,6 +15,7 @@ import Swiper from 'react-native-swiper'
13
15
  import FastImage from 'react-native-fast-image';
14
16
  import IconAntDesign from 'react-native-vector-icons/AntDesign';
15
17
  import YoutubePlayer from "react-native-youtube-iframe"
18
+ import { TextInput } from 'react-native'
16
19
  import {
17
20
  Grayscale
18
21
  } from 'react-native-color-matrix-image-filters'
@@ -54,6 +57,7 @@ export const ProductOptionsUI = (props: any) => {
54
57
  productCart,
55
58
  increment,
56
59
  decrement,
60
+ handleChangeProductCartQuantity,
57
61
  showOption,
58
62
  maxProductQuantity,
59
63
  errors,
@@ -65,6 +69,7 @@ export const ProductOptionsUI = (props: any) => {
65
69
  } = props;
66
70
 
67
71
  const theme = useTheme();
72
+ const [, { showToast }] = useToast()
68
73
 
69
74
  const styles = StyleSheet.create({
70
75
  mainContainer: {
@@ -236,6 +241,14 @@ export const ProductOptionsUI = (props: any) => {
236
241
  setPlaying((prev) => !prev);
237
242
  }, []);
238
243
 
244
+ const onChangeProductCartQuantity = (quantity: number) => {
245
+ if (quantity >= maxProductQuantity) {
246
+ showToast(ToastType.Error, t('MAX_QUANTITY', 'The max quantity is _number_').replace('_number_', maxProductQuantity))
247
+ return
248
+ }
249
+ handleChangeProductCartQuantity(quantity)
250
+ }
251
+
239
252
  useEffect(() => {
240
253
  const imageList: any = []
241
254
  const videoList: any = []
@@ -835,14 +848,32 @@ export const ProductOptionsUI = (props: any) => {
835
848
  }
836
849
  />
837
850
  </TouchableOpacity>
838
- <OText
839
- size={12}
840
- lineHeight={18}
841
- style={{ minWidth: 40, textAlign: 'center' }}
842
- >
843
- {qtyBy?.pieces && productCart.quantity}
844
- {qtyBy?.weight_unit && productCart.quantity * product?.weight}
845
- </OText>
851
+ {qtyBy?.pieces && (
852
+ <TextInput
853
+ keyboardType='numeric'
854
+ value={`${productCart.quantity}` || ''}
855
+ onChangeText={(val: any) => onChangeProductCartQuantity(parseInt(val))}
856
+ editable={!orderState.loading}
857
+ style={{
858
+ borderWidth: 1,
859
+ textAlign: 'center',
860
+ minWidth: 60,
861
+ borderRadius: 8,
862
+ borderColor: theme.colors.inputBorderColor,
863
+ height: 44,
864
+ marginHorizontal: 10
865
+ }}
866
+ />
867
+ )}
868
+ {qtyBy?.weight_unit && (
869
+ <OText
870
+ size={12}
871
+ lineHeight={18}
872
+ style={{ minWidth: 40, textAlign: 'center' }}
873
+ >
874
+ {productCart.quantity * product?.weight}
875
+ </OText>
876
+ )}
846
877
  <TouchableOpacity
847
878
  onPress={increment}
848
879
  disabled={