ordering-ui-react-native 0.16.9 → 0.16.10

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.
@@ -0,0 +1,268 @@
1
+ import React, { useEffect } from 'react';
2
+ import { View } from 'react-native';
3
+ import { Fade, Placeholder, PlaceholderLine } from 'rn-placeholder';
4
+ import { FavoriteParams } from '../../types';
5
+ import { SingleOrderCard } from '../SingleOrderCard';
6
+ import {
7
+ FavoriteList as FavoriteListController,
8
+ useOrder,
9
+ useLanguage
10
+ } from 'ordering-components/native';
11
+ import { useTheme } from 'styled-components/native';
12
+ import { _setStoreData } from '../../providers/StoreUtil';
13
+ import { Container, WrappButton } from './styles'
14
+ import { OButton } from '../shared';
15
+ import { BusinessController } from '../BusinessController';
16
+ import { SingleProductCard } from '../SingleProductCard';
17
+
18
+
19
+ const FavoriteListUI = (props: FavoriteParams) => {
20
+ const {
21
+ favoriteList,
22
+ handleUpdateFavoriteList,
23
+ pagination,
24
+ getFavoriteList,
25
+ navigation,
26
+ onNavigationRedirect,
27
+ reorderState,
28
+ handleReorder,
29
+ isBusiness,
30
+ isOrder,
31
+ isProduct
32
+ } = props
33
+
34
+ const theme = useTheme();
35
+ const [, t] = useLanguage()
36
+ const [orderState] = useOrder();
37
+ const [{ carts }] = useOrder()
38
+
39
+ const pastOrders = [1, 2, 5, 6, 10, 11, 12, 15, 16, 17]
40
+
41
+ const getOrderStatus = (s: any) => {
42
+ const status = parseInt(s)
43
+ const orderStatus = [
44
+ { key: 0, value: t('PENDING', theme?.defaultLanguages?.PENDING || 'Pending') },
45
+ { key: 1, value: t('COMPLETED', theme?.defaultLanguages?.COMPLETED || 'Completed') },
46
+ { key: 2, value: t('REJECTED', theme?.defaultLanguages?.REJECTED || 'Rejected') },
47
+ { key: 3, value: t('DRIVER_IN_BUSINESS', theme?.defaultLanguages?.DRIVER_IN_BUSINESS || 'Driver in business') },
48
+ { key: 4, value: t('PREPARATION_COMPLETED', theme?.defaultLanguages?.PREPARATION_COMPLETED || 'Preparation Completed') },
49
+ { key: 5, value: t('REJECTED_BY_BUSINESS', theme?.defaultLanguages?.REJECTED_BY_BUSINESS || 'Rejected by business') },
50
+ { key: 6, value: t('REJECTED_BY_DRIVER', theme?.defaultLanguages?.REJECTED_BY_DRIVER || 'Rejected by Driver') },
51
+ { key: 7, value: t('ACCEPTED_BY_BUSINESS', theme?.defaultLanguages?.ACCEPTED_BY_BUSINESS || 'Accepted by business') },
52
+ { key: 8, value: t('ACCEPTED_BY_DRIVER', theme?.defaultLanguages?.ACCEPTED_BY_DRIVER || 'Accepted by driver') },
53
+ { key: 9, value: t('PICK_UP_COMPLETED_BY_DRIVER', theme?.defaultLanguages?.PICK_UP_COMPLETED_BY_DRIVER || 'Pick up completed by driver') },
54
+ { key: 10, value: t('PICK_UP_FAILED_BY_DRIVER', theme?.defaultLanguages?.PICK_UP_FAILED_BY_DRIVER || 'Pick up Failed by driver') },
55
+ { key: 11, value: t('DELIVERY_COMPLETED_BY_DRIVER', theme?.defaultLanguages?.DELIVERY_COMPLETED_BY_DRIVER || 'Delivery completed by driver') },
56
+ { key: 12, value: t('DELIVERY_FAILED_BY_DRIVER', theme?.defaultLanguages?.DELIVERY_FAILED_BY_DRIVER || 'Delivery Failed by driver') },
57
+ { key: 13, value: t('PREORDER', theme?.defaultLanguages?.PREORDER || 'PreOrder') },
58
+ { key: 14, value: t('ORDER_NOT_READY', theme?.defaultLanguages?.ORDER_NOT_READY || 'Order not ready') },
59
+ { key: 15, value: t('ORDER_PICKEDUP_COMPLETED_BY_CUSTOMER', theme?.defaultLanguages?.ORDER_PICKEDUP_COMPLETED_BY_CUSTOMER || 'Order picked up completed by customer') },
60
+ { key: 16, value: t('ORDER_STATUS_CANCELLED_BY_CUSTOMER', theme?.defaultLanguages?.ORDER_STATUS_CANCELLED_BY_CUSTOMER || 'Order cancelled by customer') },
61
+ { key: 17, value: t('ORDER_NOT_PICKEDUP_BY_CUSTOMER', theme?.defaultLanguages?.ORDER_NOT_PICKEDUP_BY_CUSTOMER || 'Order not picked up by customer') },
62
+ { key: 18, value: t('ORDER_DRIVER_ALMOST_ARRIVED_BUSINESS', theme?.defaultLanguages?.ORDER_DRIVER_ALMOST_ARRIVED_BUSINESS || 'Driver almost arrived to business') },
63
+ { key: 19, value: t('ORDER_DRIVER_ALMOST_ARRIVED_CUSTOMER', theme?.defaultLanguages?.ORDER_DRIVER_ALMOST_ARRIVED_CUSTOMER || 'Driver almost arrived to customer') },
64
+ { key: 20, value: t('ORDER_CUSTOMER_ALMOST_ARRIVED_BUSINESS', theme?.defaultLanguages?.ORDER_CUSTOMER_ALMOST_ARRIVED_BUSINESS || 'Customer almost arrived to business') },
65
+ { key: 21, value: t('ORDER_CUSTOMER_ARRIVED_BUSINESS', theme?.defaultLanguages?.ORDER_CUSTOMER_ARRIVED_BUSINESS || 'Customer arrived to business') },
66
+ { key: 22, value: t('ORDER_LOOKING_FOR_DRIVER', theme?.defaultLanguages?.ORDER_LOOKING_FOR_DRIVER || 'Looking for driver') },
67
+ { key: 23, value: t('ORDER_DRIVER_ON_WAY', theme?.defaultLanguages?.ORDER_DRIVER_ON_WAY || 'Driver on way') }
68
+ ]
69
+
70
+ const objectStatus = orderStatus.find((o) => o.key === status)
71
+
72
+ return objectStatus && objectStatus
73
+ }
74
+
75
+ useEffect(() => {
76
+ const _businessId = 'businessId:' + reorderState?.result?.business_id
77
+ if (reorderState?.error) {
78
+ if (reorderState?.result?.business_id) {
79
+ _setStoreData('adjust-cart-products', JSON.stringify(_businessId))
80
+ onNavigationRedirect && onNavigationRedirect('Business', { store: reorderState?.result?.business?.slug })
81
+ }
82
+ }
83
+ if (!reorderState?.error && reorderState.loading === false && reorderState?.result?.business_id) {
84
+ const cartProducts = carts?.[_businessId]?.products
85
+ const available = cartProducts.every((product: any) => product.valid === true)
86
+ const orderProducts = favoriteList?.favorites.find((order: any) => order?.id === reorderState?.result?.orderId)?.products
87
+
88
+ if (available && reorderState?.result?.uuid && (cartProducts?.length === orderProducts?.length)) {
89
+ onNavigationRedirect && onNavigationRedirect('CheckoutNavigator', { cartUuid: reorderState?.result.uuid })
90
+ } else {
91
+ _setStoreData('adjust-cart-products', JSON.stringify(_businessId))
92
+ cartProducts?.length !== orderProducts?.length && _setStoreData('already-removed', JSON.stringify('removed'))
93
+ onNavigationRedirect && onNavigationRedirect('Business', { store: reorderState?.result?.business?.slug })
94
+ }
95
+ }
96
+ }, [reorderState])
97
+
98
+ const handleBusinessClick = (business: any) => {
99
+ onNavigationRedirect && onNavigationRedirect('Business', {
100
+ store: business.slug,
101
+ header: business.header,
102
+ logo: business.logo,
103
+ });
104
+ }
105
+
106
+ return (
107
+ <Container>
108
+ {isBusiness && (
109
+ <>
110
+ {favoriteList?.loading && (
111
+ [...Array(5).keys()].map(i => (
112
+ <Placeholder
113
+ Animation={Fade}
114
+ key={i}
115
+ style={{ marginBottom: 20 }}>
116
+ <View style={{ width: '100%' }}>
117
+ <PlaceholderLine
118
+ height={200}
119
+ style={{ marginBottom: 20, borderRadius: 25 }}
120
+ />
121
+ <View style={{ paddingHorizontal: 10 }}>
122
+ <View
123
+ style={{
124
+ flexDirection: 'row',
125
+ justifyContent: 'space-between',
126
+ }}>
127
+ <PlaceholderLine
128
+ height={25}
129
+ width={40}
130
+ style={{ marginBottom: 10 }}
131
+ />
132
+ <PlaceholderLine
133
+ height={25}
134
+ width={20}
135
+ style={{ marginBottom: 10 }}
136
+ />
137
+ </View>
138
+ <PlaceholderLine
139
+ height={20}
140
+ width={30}
141
+ style={{ marginBottom: 10 }}
142
+ />
143
+ <PlaceholderLine
144
+ height={20}
145
+ width={80}
146
+ style={{ marginBottom: 10 }}
147
+ />
148
+ </View>
149
+ </View>
150
+ </Placeholder>
151
+ ))
152
+ )}
153
+ {!favoriteList?.loading && favoriteList?.favorites?.length > 0 && (
154
+ favoriteList.favorites.map((business: any, i:number) => (
155
+ <BusinessController
156
+ key={`${business.id}_` + i}
157
+ business={business}
158
+ isBusinessOpen={business.open}
159
+ handleCustomClick={handleBusinessClick}
160
+ orderType={orderState?.options?.type}
161
+ navigation={navigation}
162
+ businessHeader={business?.header}
163
+ businessFeatured={business?.featured}
164
+ businessLogo={business?.logo}
165
+ businessReviews={business?.reviews}
166
+ businessDeliveryPrice={business?.delivery_price}
167
+ businessDeliveryTime={business?.delivery_time}
168
+ businessPickupTime={business?.pickup_time}
169
+ businessDistance={business?.distance}
170
+ handleUpdateBusinessList={handleUpdateFavoriteList}
171
+ />
172
+ ))
173
+ )}
174
+ </>
175
+ )}
176
+
177
+ {isOrder && (
178
+ <>
179
+ {favoriteList?.loading && (
180
+ [...Array(5).keys()].map(i => (
181
+ <Placeholder key={i} style={{ padding: 5 }} Animation={Fade}>
182
+ <View style={{ flexDirection: 'row' }}>
183
+ <PlaceholderLine
184
+ width={24}
185
+ height={70}
186
+ style={{ marginRight: 10, marginBottom: 10 }}
187
+ />
188
+ <Placeholder style={{ paddingVertical: 10 }}>
189
+ <PlaceholderLine width={60} style={{ marginBottom: 25 }} />
190
+ <PlaceholderLine width={20} />
191
+ </Placeholder>
192
+ </View>
193
+ </Placeholder>
194
+ ))
195
+ )}
196
+ {!favoriteList?.loading && favoriteList?.favorites?.length > 0 && (
197
+ favoriteList.favorites.map((order: any) => (
198
+ <SingleOrderCard
199
+ key={order?.id}
200
+ order={order}
201
+ getOrderStatus={getOrderStatus}
202
+ onNavigationRedirect={onNavigationRedirect}
203
+ pastOrders={pastOrders.includes(order?.status)}
204
+ handleUpdateOrderList={handleUpdateFavoriteList}
205
+ handleUpdateFavoriteList={handleUpdateFavoriteList}
206
+ handleReorder={handleReorder}
207
+ reorderLoading={reorderState?.loading}
208
+ />
209
+ ))
210
+ )}
211
+ </>
212
+ )}
213
+
214
+ {isProduct && (
215
+ <>
216
+ {favoriteList?.loading && (
217
+ [...Array(5).keys()].map(i => (
218
+ <Placeholder key={i} style={{ padding: 5 }} Animation={Fade}>
219
+ <View style={{ flexDirection: 'row' }}>
220
+ <PlaceholderLine
221
+ width={24}
222
+ height={70}
223
+ style={{ marginRight: 10, marginBottom: 10 }}
224
+ />
225
+ <Placeholder style={{ paddingVertical: 10 }}>
226
+ <PlaceholderLine width={60} style={{ marginBottom: 25 }} />
227
+ <PlaceholderLine width={20} />
228
+ </Placeholder>
229
+ </View>
230
+ </Placeholder>
231
+ ))
232
+ )}
233
+ {!favoriteList?.loading && favoriteList?.favorites?.length > 0 && (
234
+ favoriteList.favorites.map((product: any) => (
235
+ <SingleProductCard
236
+ key={product?.id}
237
+ isSoldOut={product.inventoried && !product.quantity}
238
+ product={product}
239
+ onProductClick={() => {}}
240
+ handleUpdateProducts={handleUpdateFavoriteList}
241
+ />
242
+ ))
243
+ )}
244
+ </>
245
+ )}
246
+
247
+ {!favoriteList?.loading && pagination.totalPages && pagination.currentPage < pagination.totalPages && (
248
+ <WrappButton>
249
+ <OButton
250
+ onClick={() => getFavoriteList(pagination?.currentPage + 1)}
251
+ text={t('LOAD_MORE_ITEMS', 'Load more items')}
252
+ imgRightSrc={null}
253
+ textStyle={{ color: theme.colors.white }}
254
+ style={{ borderRadius: 7.6, shadowOpacity: 0, marginTop: 20 }}
255
+ />
256
+ </WrappButton>
257
+ )}
258
+ </Container>
259
+ )
260
+ }
261
+
262
+ export const FavoriteList = (props: any) => {
263
+ const favoriteBusinessesProps = {
264
+ ...props,
265
+ UIComponent: FavoriteListUI
266
+ }
267
+ return <FavoriteListController {...favoriteBusinessesProps} />
268
+ }
@@ -0,0 +1,5 @@
1
+ import styled from 'styled-components/native'
2
+
3
+ export const Container = styled.View``
4
+
5
+ export const WrappButton = styled.View``
@@ -20,7 +20,10 @@ const HighestRatedBusinessesUI = (props: HighestRatedBusinessesParams) => {
20
20
  onBusinessClick,
21
21
  navigation,
22
22
  isLoading,
23
- getBusinesses
23
+ getBusinesses,
24
+ favoriteIds,
25
+ setFavoriteIds,
26
+ handleUpdateBusinessList
24
27
  } = props;
25
28
 
26
29
  const [, t] = useLanguage()
@@ -33,6 +36,17 @@ const HighestRatedBusinessesUI = (props: HighestRatedBusinessesParams) => {
33
36
  getBusinesses(true)
34
37
  }, [isLoading])
35
38
 
39
+ useEffect(() => {
40
+ if (!businessesList?.businesses?.length) return
41
+ const ids = [...favoriteIds]
42
+ businessesList.businesses.forEach(business => {
43
+ if (business?.favorite) {
44
+ ids.push(business.id)
45
+ }
46
+ })
47
+ setFavoriteIds([...new Set(ids)])
48
+ }, [businessesList?.businesses?.length])
49
+
36
50
  return (
37
51
  <>
38
52
 
@@ -123,6 +137,9 @@ const HighestRatedBusinessesUI = (props: HighestRatedBusinessesParams) => {
123
137
  handleCustomClick={onBusinessClick}
124
138
  orderType={orderState?.options?.type}
125
139
  navigation={navigation}
140
+ favoriteIds={favoriteIds}
141
+ setFavoriteIds={setFavoriteIds}
142
+ handleUpdateBusinessList={handleUpdateBusinessList}
126
143
  />
127
144
  </View>
128
145
  )
@@ -37,7 +37,8 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
37
37
  refreshOrders,
38
38
  setRefreshOrders,
39
39
  reorderState,
40
- handleReorder
40
+ handleReorder,
41
+ handleUpdateOrderList
41
42
  } = props
42
43
 
43
44
  const theme = useTheme();
@@ -222,6 +223,7 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
222
223
  customArray={customArray}
223
224
  getOrderStatus={getOrderStatus}
224
225
  onNavigationRedirect={onNavigationRedirect}
226
+ handleUpdateOrderList={handleUpdateOrderList}
225
227
  />
226
228
  ) : activeOrders ? (
227
229
  <ActiveOrders
@@ -231,6 +233,7 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
231
233
  customArray={customArray}
232
234
  getOrderStatus={getOrderStatus}
233
235
  onNavigationRedirect={onNavigationRedirect}
236
+ handleUpdateOrderList={handleUpdateOrderList}
234
237
  />
235
238
  ) : (
236
239
  <PreviousOrders
@@ -241,6 +244,7 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
241
244
  getOrderStatus={getOrderStatus}
242
245
  onNavigationRedirect={onNavigationRedirect}
243
246
  handleReorder={handleReorder}
247
+ handleUpdateOrderList={handleUpdateOrderList}
244
248
  />
245
249
  )
246
250
  )}
@@ -1,18 +1,13 @@
1
- import React, { useState } from 'react';
2
- import { useLanguage, useUtils } from 'ordering-components/native';
1
+ import React from 'react';
2
+ import { useLanguage } from 'ordering-components/native';
3
3
  import { useTheme } from 'styled-components/native';
4
- import { StyleSheet, TouchableOpacity, ScrollView, View } from 'react-native';
5
- import { OButton, OIcon, OText } from '../shared';
4
+ import { View } from 'react-native';
5
+ import { OButton } from '../shared';
6
6
  import {
7
- Card,
8
- Logo,
9
- Information,
10
- MyOrderOptions,
11
- Status,
12
7
  WrappButton,
13
8
  } from './styles';
14
9
  import { PreviousOrdersParams } from '../../types';
15
- import moment from 'moment';
10
+ import { SingleOrderCard } from '../SingleOrderCard';
16
11
 
17
12
  export const PreviousOrders = (props: PreviousOrdersParams) => {
18
13
  const {
@@ -24,152 +19,28 @@ export const PreviousOrders = (props: PreviousOrdersParams) => {
24
19
  handleReorder,
25
20
  reorderLoading,
26
21
  orderID,
22
+ handleUpdateOrderList
27
23
  } = props;
28
24
 
29
25
  const theme = useTheme();
30
26
 
31
-
32
- const styles = StyleSheet.create({
33
- logo: {
34
- borderRadius: 10,
35
- width: 64,
36
- height: 64,
37
- },
38
- reorderbutton: {
39
- height: 23,
40
- paddingLeft: 10,
41
- paddingRight: 10,
42
- borderRadius: 23,
43
- shadowOpacity: 0,
44
- backgroundColor: theme.colors.primaryContrast,
45
- borderWidth: 0,
46
- },
47
- reorderLoading: {
48
- width: 80,
49
- height: 40,
50
- borderRadius: 10,
51
- },
52
- reviewButton: {
53
- height: 23,
54
- maxHeight: 23,
55
- backgroundColor: theme.colors.white,
56
- alignItems: 'center',
57
- justifyContent: 'center',
58
- paddingHorizontal: 10,
59
- borderRadius: 23,
60
- borderWidth: 1,
61
- borderColor: theme.colors.primaryContrast,
62
- },
63
- buttonText: {
64
- color: theme.colors.primary,
65
- fontSize: 10,
66
- marginLeft: 2,
67
- marginRight: 2,
68
- },
69
- });
70
-
71
-
72
27
  const [, t] = useLanguage();
73
- const [reorderSelected, setReorderSelected] = useState<number | null>(null);
74
- const [{ parseDate, optimizeImage }] = useUtils();
75
- const allowedOrderStatus = [1, 2, 5, 6, 10, 11, 12];
76
-
77
- const handleClickViewOrder = (uuid: string) => {
78
- onNavigationRedirect &&
79
- onNavigationRedirect('OrderDetails', { orderId: uuid });
80
- };
81
-
82
- const handleClickOrderReview = (order: any) => {
83
- onNavigationRedirect &&
84
- onNavigationRedirect('ReviewOrder', {
85
- order: {
86
- id: order?.id,
87
- business_id: order?.business_id,
88
- logo: order?.business?.logo,
89
- driver: order?.driver,
90
- products: order?.products,
91
- review: order?.review,
92
- user_review: order?.user_review
93
- },
94
- });
95
- };
96
-
97
- const formatDate = (date: string, option?: any) => {
98
- return option?.utc ? moment.utc(date).format('DD/MM/YY \u2022 h:m a') : moment(date).format('DD/MM/YY \u2022 h:m a');
99
- };
100
28
 
101
- const handleReorderClick = (id: number) => {
102
- setReorderSelected(id);
103
- handleReorder && handleReorder(id);
104
- };
29
+ const pastOrders = [1, 2, 5, 6, 10, 11, 12, 15, 16, 17]
105
30
 
106
31
  return (
107
32
  <View style={{ marginBottom: 30 }}>
108
- {orders.map((order: any) => (
109
- <TouchableOpacity
110
- onPress={() => handleClickViewOrder(order?.uuid)}
111
- activeOpacity={0.7}
112
- style={{ flexDirection: 'row' }}
113
- key={order.id}>
114
- <Card>
115
- {!!order.business?.logo && (
116
- <Logo>
117
- <OIcon
118
- url={optimizeImage(order.business?.logo, 'h_300,c_limit')}
119
- style={styles.logo}
120
- />
121
- </Logo>
122
- )}
123
- <Information>
124
- <OText size={12} lineHeight={18} weight={'600'} numberOfLines={1} ellipsizeMode={'tail'}>
125
- {order.business?.name}
126
- </OText>
127
- <OText
128
- size={10}
129
- lineHeight={15}
130
- color={theme.colors.textSecondary}
131
- style={{ marginVertical: 3 }}
132
- numberOfLines={1}>
133
- {order?.delivery_datetime_utc
134
- ? formatDate(order?.delivery_datetime_utc)
135
- : formatDate(order?.delivery_datetime, { utc: false })}
136
- </OText>
137
- <OText
138
- color={theme.colors.primary}
139
- size={10}
140
- lineHeight={15}
141
- numberOfLines={1}>
142
- {getOrderStatus(order.status)?.value}
143
- </OText>
144
- </Information>
145
- <Status>
146
- {order.cart && (
147
- <OButton
148
- text={t('REORDER', 'Reorder')}
149
- imgRightSrc={''}
150
- textStyle={styles.buttonText}
151
- style={
152
- reorderLoading && order.id === reorderSelected
153
- ? styles.reorderLoading
154
- : styles.reorderbutton
155
- }
156
- onClick={() => handleReorderClick(order.id)}
157
- isLoading={reorderLoading && order.id === reorderSelected}
158
- />
159
- )}
160
- {allowedOrderStatus.includes(parseInt(order?.status)) &&
161
- !order.review && (
162
- <TouchableOpacity
163
- onPress={() => handleClickOrderReview(order)}
164
- style={styles.reviewButton}>
165
- <OText size={10} color={theme.colors.primary} numberOfLines={1}>
166
- {t('REVIEW', 'Review')}
167
- </OText>
168
- </TouchableOpacity>
169
- )}
170
- </Status>
171
- </Card>
172
- </TouchableOpacity>
33
+ {orders.map((order: any, i: number) => (
34
+ <SingleOrderCard
35
+ key={i}
36
+ order={order}
37
+ reorderLoading={reorderLoading}
38
+ handleReorder={handleReorder}
39
+ onNavigationRedirect={onNavigationRedirect}
40
+ getOrderStatus={getOrderStatus}
41
+ pastOrders={pastOrders.includes(order?.status)}
42
+ handleUpdateOrderList={handleUpdateOrderList}
43
+ />
173
44
  ))}
174
45
  {pagination.totalPages && pagination.currentPage < pagination.totalPages && (
175
46
  <WrappButton>