ordering-ui-react-native 0.9.2 → 0.9.6

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.
Files changed (37) hide show
  1. package/package.json +1 -1
  2. package/src/DeliveryApp.tsx +2 -1
  3. package/src/components/OrdersOption/test.tsx +410 -0
  4. package/src/components/PreviousOrders/index.tsx +14 -1
  5. package/src/components/ReviewDriver/index.tsx +313 -0
  6. package/src/components/ReviewDriver/styles.tsx +38 -0
  7. package/src/components/ReviewOrder/index.tsx +231 -103
  8. package/src/components/ReviewOrder/styles.tsx +24 -11
  9. package/src/components/ReviewProducts/index.tsx +113 -0
  10. package/src/components/ReviewProducts/styles.tsx +16 -0
  11. package/src/components/SingleProductReview/index.tsx +166 -0
  12. package/src/components/SingleProductReview/styles.tsx +26 -0
  13. package/src/components/shared/OButton.tsx +0 -1
  14. package/src/index.tsx +9 -0
  15. package/src/layouts/FloatingBottomContainer.tsx +26 -0
  16. package/src/navigators/HomeNavigator.tsx +12 -0
  17. package/src/pages/ReviewDriver.tsx +30 -0
  18. package/src/pages/ReviewOrder.tsx +5 -4
  19. package/src/pages/ReviewProducts.tsx +30 -0
  20. package/src/theme.json +2 -1
  21. package/src/types/index.tsx +27 -2
  22. package/themes/business/src/components/Chat/index.tsx +1 -0
  23. package/themes/business/src/components/DriverMap/index.tsx +31 -6
  24. package/themes/business/src/components/OrderDetails/index.tsx +39 -13
  25. package/themes/business/src/components/OrderDetailsDelivery/index.tsx +17 -4
  26. package/themes/business/src/components/OrdersOption/index.tsx +24 -12
  27. package/themes/business/src/components/PreviousOrders/index.tsx +54 -53
  28. package/themes/business/src/components/StoresList/index.tsx +3 -6
  29. package/themes/business/src/components/UserFormDetails/index.tsx +5 -4
  30. package/themes/business/src/components/UserProfileForm/index.tsx +9 -8
  31. package/themes/business/src/hooks/useLocation.tsx +1 -1
  32. package/themes/business/src/types/index.tsx +6 -0
  33. package/themes/doordash/src/components/PreviousOrders/index.tsx +14 -1
  34. package/themes/instacart/src/components/PreviousOrders/index.tsx +14 -1
  35. package/themes/original/src/components/PreviousOrders/index.tsx +4 -0
  36. package/themes/uber-eats/src/components/AddressForm/index.tsx +2 -0
  37. package/themes/uber-eats/src/components/PreviousOrders/index.tsx +14 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ordering-ui-react-native",
3
- "version": "0.9.2",
3
+ "version": "0.9.6",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -96,7 +96,8 @@ theme.images = {
96
96
  stripes: require('./assets/icons/stripe-s.png'),
97
97
  stripesb: require('./assets/icons/stripe-sb.png'),
98
98
  creditCard: require('./assets/icons/credit-card.png'),
99
- help: require('./assets/images/help.png')
99
+ help: require('./assets/images/help.png'),
100
+ close: require('./assets/icons/close.png')
100
101
  },
101
102
  order: {
102
103
  status0: require('./assets/images/status-0.png'),
@@ -0,0 +1,410 @@
1
+ import React, { useEffect, useState } from 'react'
2
+ import PropTypes, { object, number } from 'prop-types'
3
+
4
+ import { useSession, useApi, useWebsocket, ToastType, useToast, useLanguage } from 'ordering-components/native'
5
+
6
+ export const OrderList = (props) => {
7
+ const {
8
+ UIComponent,
9
+ orders,
10
+ orderIds,
11
+ orderStatus,
12
+ orderBy,
13
+ orderDirection,
14
+ useDefualtSessionManager,
15
+ paginationSettings,
16
+ asDashboard,
17
+ customArray,
18
+ userCustomerId,
19
+ activeOrders,
20
+ isDynamicSort
21
+ } = props
22
+
23
+ const [ordering] = useApi()
24
+ const [session] = useSession()
25
+ const [, { showToast }] = useToast()
26
+ const socket = useWebsocket()
27
+ const [, t] = useLanguage()
28
+ const [orderList, setOrderList] = useState({ loading: !orders, error: null, orders: [] })
29
+ const [pagination, setPagination] = useState({
30
+ currentPage: (paginationSettings.controlType === 'pages' && paginationSettings.initialPage && paginationSettings.initialPage >= 1) ? paginationSettings.initialPage - 1 : 0,
31
+ pageSize: paginationSettings.pageSize ?? 10
32
+ })
33
+ const [messages, setMessages] = useState({ loading: false, error: null, messages: [] })
34
+ const [updateOtherStatus, setUpdateOtherStatus] = useState([])
35
+ const [sortBy, setSortBy] = useState({ param: orderBy, direction: orderDirection })
36
+
37
+ const accessToken = useDefualtSessionManager ? session.token : props.accessToken
38
+ const requestsState = {}
39
+
40
+ const getOrders = async (page, otherStatus = [], pageSize = paginationSettings.pageSize) => {
41
+ const options = {
42
+ query: {
43
+ orderBy: `${(sortBy.direction === 'desc' ? '-' : '')}${sortBy.param}`,
44
+ page: page,
45
+ page_size: pageSize
46
+ }
47
+ }
48
+ if (orderIds || orderStatus) {
49
+ options.query.where = []
50
+ if (orderIds) {
51
+ options.query.where.push({ attribute: 'id', value: orderIds })
52
+ }
53
+ if (orderStatus) {
54
+ const searchByStatus = otherStatus?.length > 0 ? otherStatus : orderStatus
55
+ options.query.where.push({ attribute: 'status', value: searchByStatus })
56
+ }
57
+ }
58
+ if (userCustomerId) {
59
+ options.query.where.push({ attribute: 'customer_id', value: parseInt(userCustomerId, 10) })
60
+ }
61
+ const source = {}
62
+ requestsState.orders = source
63
+ options.cancelToken = source
64
+ const functionFetch = asDashboard
65
+ ? ordering.setAccessToken(accessToken).orders().asDashboard()
66
+ : ordering.setAccessToken(accessToken).orders()
67
+ return await functionFetch.get(options)
68
+ }
69
+
70
+ const loadOrders = async (isNextPage, searchByOtherStatus, keepOrders = false) => {
71
+ const pageSize = keepOrders ? paginationSettings.pageSize * pagination.currentPage : paginationSettings.pageSize
72
+ if (!session.token) {
73
+ setOrderList({
74
+ ...orderList,
75
+ loading: false
76
+ })
77
+ return
78
+ }
79
+ try {
80
+ setOrderList({
81
+ ...orderList,
82
+ loading: true
83
+ })
84
+ const nextPage = !isNextPage ? pagination.currentPage + 1 : 1
85
+ const response = await getOrders(nextPage, searchByOtherStatus, pageSize)
86
+ setOrderList({
87
+ loading: false,
88
+ orders: response.content.error ? [] : response.content.result,
89
+ error: response.content.error ? response.content.result : null
90
+ })
91
+ if (!response.content.error) {
92
+ setPagination({
93
+ currentPage: keepOrders ? pagination.currentPage : response.content.pagination.current_page,
94
+ pageSize: response.content.pagination.page_size,
95
+ totalPages: keepOrders ? pagination.totalPages : response.content.pagination.total_pages,
96
+ total: keepOrders ? pagination.total : response.content.pagination.total,
97
+ from: keepOrders ? 1 : response.content.pagination.from,
98
+ to: keepOrders ? pagination.to : response.content.pagination.to
99
+ })
100
+ }
101
+ } catch (err) {
102
+ if (err.constructor.name !== 'Cancel') {
103
+ setOrderList({ ...orderList, loading: false, error: [err.message] })
104
+ }
105
+ }
106
+ }
107
+
108
+ const loadMessages = async (orderId) => {
109
+ try {
110
+ setMessages({ ...messages, loading: true })
111
+ const url = `${ordering.root}/orders/${orderId}/messages?mode=dashboard`
112
+
113
+ const response = await fetch(url, { method: 'GET', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}` } })
114
+ const { error, result } = await response.json()
115
+ if (!error) {
116
+ setMessages({
117
+ messages: result,
118
+ loading: false,
119
+ error: null
120
+ })
121
+ } else {
122
+ setMessages({
123
+ ...messages,
124
+ loading: false,
125
+ error: result
126
+ })
127
+ }
128
+ } catch (error) {
129
+ setMessages({ ...messages, loading: false, error: [error.Messages] })
130
+ }
131
+ }
132
+
133
+ useEffect(() => {
134
+ if (orders || customArray) {
135
+ setOrderList({
136
+ ...orderList,
137
+ orders: orders?.lenght > 0 ? orders : customArray || [],
138
+ loading: false
139
+ })
140
+ } else {
141
+ loadOrders()
142
+ }
143
+
144
+ return () => {
145
+ if (requestsState.orders) {
146
+ requestsState.orders.cancel()
147
+ }
148
+ }
149
+ }, [session])
150
+
151
+ useEffect(() => {
152
+ if (orderList.loading) return
153
+ const handleUpdateOrder = (order) => {
154
+ setOrderList({ ...orderList, loading: true })
155
+ const found = orderList.orders.find(_order => _order.id === order.id)
156
+ let orders = []
157
+ showToast(ToastType.Info, t('SPECIFIC_ORDER_UPDATED', 'Your order number _NUMBER_ has updated').replace('_NUMBER_', order.id))
158
+ if (found) {
159
+ orders = orderList.orders.filter(_order => {
160
+ if (_order.id === order.id) {
161
+ delete order.total
162
+ delete order.subtotal
163
+ Object.assign(_order, order)
164
+ }
165
+ const valid = orderStatus.length === 0 || orderStatus.includes(parseInt(_order.status)) || updateOtherStatus.length === 0 || updateOtherStatus.includes(parseInt(_order.status))
166
+ if (!valid) {
167
+ pagination.total--
168
+ setPagination({
169
+ ...pagination
170
+ })
171
+ }
172
+ return valid
173
+ })
174
+ } else {
175
+ orders = [order, ...orderList.orders]
176
+ pagination.total++
177
+ setPagination({
178
+ ...pagination
179
+ })
180
+ }
181
+ setOrderList({
182
+ ...orderList,
183
+ orders,
184
+ loading: false
185
+ })
186
+ console.log('update')
187
+ }
188
+
189
+ const handleAddNewOrder = (order) => {
190
+ setOrderList({
191
+ ...orderList,
192
+ loading: true
193
+ })
194
+ showToast(ToastType.Info, t('SPECIFIC_ORDER_ORDERED', 'Order _NUMBER_ has been ordered').replace('_NUMBER_', order.id))
195
+ const newOrder = [order, ...orderList.orders]
196
+ setOrderList({
197
+ ...orderList,
198
+ orders: newOrder,
199
+ loading: false
200
+ })
201
+ }
202
+
203
+ socket.on('orders_register', handleAddNewOrder)
204
+ socket.on('update_order', handleUpdateOrder)
205
+ return () => {
206
+ socket.off('update_order', handleUpdateOrder)
207
+ socket.off('orders_register', handleAddNewOrder)
208
+ }
209
+ }, [orderList.orders, pagination, socket])
210
+
211
+ useEffect(() => {
212
+ if (!session.user) return
213
+ const ordersRoom = session?.user?.level === 0 ? 'orders' : `orders_${userCustomerId || session?.user?.id}`
214
+ socket.join(ordersRoom)
215
+ return () => {
216
+ socket.leave(ordersRoom)
217
+ }
218
+ }, [socket, session, userCustomerId])
219
+
220
+ const loadMoreOrders = async (searchByOtherStatus) => {
221
+ setOrderList({ ...orderList, loading: true })
222
+ try {
223
+ const response = await getOrders(pagination.currentPage + 1, searchByOtherStatus)
224
+ setOrderList({
225
+ loading: false,
226
+ orders: response.content.error ? orderList.orders : orderList.orders.concat(response.content.result),
227
+ error: response.content.error ? response.content.result : null
228
+ })
229
+ if (!response.content.error) {
230
+ setPagination({
231
+ currentPage: response.content.pagination.current_page,
232
+ pageSize: response.content.pagination.page_size,
233
+ totalPages: response.content.pagination.total_pages,
234
+ total: response.content.pagination.total,
235
+ from: response.content.pagination.from,
236
+ to: response.content.pagination.to
237
+ })
238
+ }
239
+ } catch (err) {
240
+ if (err.constructor.name !== 'Cancel') {
241
+ setOrderList({ ...orderList, loading: false, error: [err.message] })
242
+ }
243
+ }
244
+ }
245
+
246
+ const goToPage = async (page) => {
247
+ setOrderList({ ...orderList, loading: true })
248
+ try {
249
+ const response = await getOrders(page)
250
+ setOrderList({
251
+ loading: false,
252
+ orders: response.content.error ? [] : response.content.result,
253
+ error: response.content.error ? response.content.result : null
254
+ })
255
+ if (!response.content.error) {
256
+ setPagination({
257
+ currentPage: response.content.pagination.current_page,
258
+ pageSize: response.content.pagination.page_size,
259
+ totalPages: response.content.pagination.total_pages,
260
+ total: response.content.pagination.total,
261
+ from: response.content.pagination.from,
262
+ to: response.content.pagination.to
263
+ })
264
+ }
265
+ } catch (err) {
266
+ if (err.constructor.name !== 'Cancel') {
267
+ setOrderList({ ...orderList, loading: false, error: [err.message] })
268
+ }
269
+ }
270
+ }
271
+
272
+ useEffect(() => {
273
+ if (!orderList.loading) {
274
+ const ordersSorted = orderList.orders.sort((a, b) => {
275
+ if (activeOrders) {
276
+ return new Date(b.created_at) - new Date(a.created_at)
277
+ }
278
+ return new Date(a.created_at) - new Date(b.created_at)
279
+ })
280
+ setOrderList({
281
+ ...orderList,
282
+ orders: ordersSorted
283
+ })
284
+ }
285
+ }, [orderList.loading])
286
+
287
+ /**
288
+ * This effect is used to reload orders with dynamic params, using `isDynamicSort` as validation
289
+ */
290
+ useEffect(() => {
291
+ if (isDynamicSort) {
292
+ loadOrders(true, [])
293
+ }
294
+ }, [sortBy])
295
+
296
+ return (
297
+ <>
298
+ {UIComponent && (
299
+ <UIComponent
300
+ {...props}
301
+ setSortBy={setSortBy}
302
+ orderList={orderList}
303
+ pagination={pagination}
304
+ loadMoreOrders={loadMoreOrders}
305
+ goToPage={goToPage}
306
+ loadOrders={loadOrders}
307
+ loadMessages={loadMessages}
308
+ messages={messages}
309
+ setMessages={setMessages}
310
+ setUpdateOtherStatus={setUpdateOtherStatus}
311
+ />
312
+ )}
313
+ </>
314
+ )
315
+ }
316
+
317
+ OrderList.propTypes = {
318
+ /**
319
+ * UI Component, this must be containt all graphic elements and use parent props
320
+ */
321
+ UIComponent: PropTypes.elementType,
322
+ /**
323
+ * Function to get order that was clicked
324
+ * @param {Object} order Order that was clicked
325
+ */
326
+ onOrderClick: PropTypes.func,
327
+ /**
328
+ * Enable/Disable default session manager
329
+ * Save user and token with default session manager
330
+ */
331
+ useDefualtSessionManager: PropTypes.bool,
332
+ /**
333
+ * Access token to update user
334
+ * Is required when `useDefualtSessionManager` is false
335
+ */
336
+ accessToken: (props, propName) => {
337
+ if (props[propName] !== undefined && typeof props[propName] !== 'string') {
338
+ return new Error(`Invalid prop \`${propName}\` of type \`${typeof props[propName]}\` supplied to \`UserProfile\`, expected \`object\`.`)
339
+ }
340
+ if (props[propName] === undefined && !props.useDefualtSessionManager) {
341
+ return new Error(`Invalid prop \`${propName}\` is required when \`useDefualtSessionManager\` is false.`)
342
+ }
343
+ },
344
+ /**
345
+ * Array of orders
346
+ * This is used of first option to show list
347
+ */
348
+ orders: PropTypes.arrayOf(object),
349
+ /**
350
+ * Array of id of orders
351
+ * Get a list of orders by ids form Ordering API
352
+ */
353
+ orderIds: PropTypes.arrayOf(number),
354
+ /**
355
+ * Array of id of orders
356
+ * Get a list of orders by status form Ordering API
357
+ * This can be use together `orderIds` option but not has effect with `orders` option
358
+ */
359
+ orderStatus: PropTypes.arrayOf(number),
360
+ /**
361
+ * Order orders by some attribute. Default by `id`.
362
+ */
363
+ orderBy: PropTypes.string,
364
+ /**
365
+ * Order direction ascendent (asc) or descendent (desc). Default is `desc`.
366
+ */
367
+ orderDirection: PropTypes.oneOf(['asc', 'desc']),
368
+ /**
369
+ * Pagination settings
370
+ * You can set the pageSize, initialPage and controlType can be by pages or infinity
371
+ */
372
+ paginationSettings: PropTypes.exact({
373
+ /**
374
+ * initialPage only work with control type `pages`
375
+ */
376
+ initialPage: PropTypes.number,
377
+ pageSize: PropTypes.number,
378
+ controlType: PropTypes.oneOf(['infinity', 'pages'])
379
+ }),
380
+ /**
381
+ * Components types before Facebook login button
382
+ * Array of type components, the parent props will pass to these components
383
+ */
384
+ beforeComponents: PropTypes.arrayOf(PropTypes.elementType),
385
+ /**
386
+ * Components types after Facebook login button
387
+ * Array of type components, the parent props will pass to these components
388
+ */
389
+ afterComponents: PropTypes.arrayOf(PropTypes.elementType),
390
+ /**
391
+ * Elements before Facebook login button
392
+ * Array of HTML/Components elements, these components will not get the parent props
393
+ */
394
+ beforeElements: PropTypes.arrayOf(PropTypes.element),
395
+ /**
396
+ * Elements after Facebook login button
397
+ * Array of HTML/Components elements, these components will not get the parent props
398
+ */
399
+ afterElements: PropTypes.arrayOf(PropTypes.element)
400
+ }
401
+
402
+ OrderList.defaultProps = {
403
+ orderBy: 'id',
404
+ orderDirection: 'desc',
405
+ paginationSettings: { initialPage: 1, pageSize: 10, controlType: 'infinity' },
406
+ beforeComponents: [],
407
+ afterComponents: [],
408
+ beforeElements: [],
409
+ afterElements: []
410
+ }
@@ -56,7 +56,20 @@ export const PreviousOrders = (props: PreviousOrdersParams) => {
56
56
  }
57
57
 
58
58
  const handleClickOrderReview = (order: any) => {
59
- onNavigationRedirect && onNavigationRedirect('ReviewOrder', { order: { id: order?.id, business_id: order?.business_id, logo: order.business?.logo } })
59
+ onNavigationRedirect && onNavigationRedirect(
60
+ 'ReviewOrder',
61
+ {
62
+ order: {
63
+ id: order?.id,
64
+ business_id: order?.business_id,
65
+ logo: order.business?.logo,
66
+ driver: order?.driver,
67
+ products: order?.products,
68
+ review: order?.review,
69
+ user_review: order?.user_review
70
+ }
71
+ }
72
+ )
60
73
  }
61
74
 
62
75
  const handleReorderClick = (id : number) => {