ordering-ui-react-native 0.12.12 → 0.12.16

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.12.12",
3
+ "version": "0.12.16",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -57,7 +57,7 @@ const AddressListUI = (props: AddressListParams) => {
57
57
 
58
58
  const [orderState] = useOrder()
59
59
  const [, t] = useLanguage()
60
- const [{ auth }] = useSession()
60
+ const [{ auth }, { logout }] = useSession()
61
61
  const [alert, setAlert] = useState<any>({ show: false })
62
62
 
63
63
  const onNavigatorRedirect = () => {
@@ -261,6 +261,8 @@ const AddressListUI = (props: AddressListParams) => {
261
261
  addressList.error[0] ||
262
262
  t('NETWORK_ERROR', 'Network Error, please reload the app')
263
263
  }
264
+ btnTitle={t('LOGIN', 'Login')}
265
+ onClickButton={() => logout()}
264
266
  />
265
267
  )
266
268
  )}
@@ -41,7 +41,7 @@ export const GoogleMap = (props: GoogleMapsParams) => {
41
41
  ERROR_NOT_FOUND_ADDRESS: 'Sorry, we couldn\'t find an address',
42
42
  ERROR_MAX_LIMIT_LOCATION_TO: 'Sorry, You can only set the position to'
43
43
  }
44
- const MARKERS = locations && locations.map((location: { lat: number, lng: number }) => {
44
+ let MARKERS = locations && locations.map((location: { lat: number, lng: number }) => {
45
45
  return {
46
46
  latitude: location.lat,
47
47
  longitude: location.lng
@@ -176,6 +176,17 @@ export const GoogleMap = (props: GoogleMapsParams) => {
176
176
  return () => clearInterval(interval)
177
177
  }, [locations])
178
178
 
179
+ useEffect(() => {
180
+ if(!locations) return
181
+ locations[0] = {...locations[0], lat: location.lat, lng: location.lng}
182
+ MARKERS = locations && locations.map((location: { lat: number, lng: number }) => {
183
+ return {
184
+ latitude: location.lat,
185
+ longitude: location.lng
186
+ }
187
+ })
188
+ }, [location])
189
+
179
190
  return (
180
191
  <>
181
192
  <MapView
@@ -208,7 +208,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
208
208
  }
209
209
  }, [messagesReadList])
210
210
 
211
- const locations = [
211
+ let locations = [
212
212
  { ...order?.driver?.location, title: t('DRIVER', 'Driver'), icon: order?.driver?.photo || 'https://res.cloudinary.com/demo/image/fetch/c_thumb,g_face,r_max/https://www.freeiconspng.com/thumbs/driver-icon/driver-icon-14.png' },
213
213
  { ...order?.business?.location, title: order?.business?.name, icon: order?.business?.logo || theme.images.dummies.businessLogo },
214
214
  { ...order?.customer?.location, title: t('YOUR_LOCATION', 'Your Location'), icon: order?.customer?.photo || 'https://res.cloudinary.com/demo/image/upload/c_thumb,g_face,r_max/d_avatar.png/non_existing_id.png' }
@@ -216,7 +216,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
216
216
 
217
217
  useEffect(() => {
218
218
  if (driverLocation) {
219
- locations[0] = driverLocation
219
+ locations[0] = {...locations[0], lat: driverLocation.lat, lng: driverLocation.lng}
220
220
  }
221
221
  }, [driverLocation])
222
222
 
@@ -361,9 +361,8 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
361
361
  {order?.driver?.location && parseInt(order?.status) === 9 && (
362
362
  <Map>
363
363
  <GoogleMap
364
- location={order?.driver?.location}
364
+ location={driverLocation ?? order?.driver?.location}
365
365
  locations={locations}
366
- readOnly
367
366
  />
368
367
  </Map>
369
368
  )}
@@ -111,7 +111,7 @@ export const AcceptOrRejectOrder = (props: AcceptOrRejectOrderParams) => {
111
111
  openTimerIOnput();
112
112
  }
113
113
 
114
- if (actions && action === 'reject') {
114
+ if (actions && (action === 'reject' || action === 'failed')) {
115
115
  openTextTareaOInput();
116
116
  }
117
117
  }, []);
@@ -178,6 +178,10 @@ export const AcceptOrRejectOrder = (props: AcceptOrRejectOrderParams) => {
178
178
  comment: comments,
179
179
  status: 6,
180
180
  },
181
+ failedByDriver: {
182
+ comment: comments,
183
+ status: 12
184
+ }
181
185
  };
182
186
 
183
187
  if (actions && action === 'accept') {
@@ -186,6 +190,9 @@ export const AcceptOrRejectOrder = (props: AcceptOrRejectOrderParams) => {
186
190
  if (actions && action === 'reject') {
187
191
  bodyToSend = orderStatus[actions.reject];
188
192
  }
193
+ if(actions && action === 'failed'){
194
+ bodyToSend = orderStatus[actions.failed]
195
+ }
189
196
 
190
197
  bodyToSend.id = orderId;
191
198
 
@@ -330,7 +337,6 @@ export const AcceptOrRejectOrder = (props: AcceptOrRejectOrderParams) => {
330
337
  </Timer>
331
338
  </View>
332
339
  )}
333
-
334
340
  <TimeField
335
341
  ref={timerRef}
336
342
  keyboardType="numeric"
@@ -346,11 +352,11 @@ export const AcceptOrRejectOrder = (props: AcceptOrRejectOrderParams) => {
346
352
  onEndEditing={handleFixTime}
347
353
  />
348
354
 
349
- {action === 'reject' && (
355
+ {(action === 'reject' || action === 'failed') && (
350
356
  <Comments ref={viewRef}>
351
357
  <OTextarea
352
358
  textTareaRef={textTareaRef}
353
- autoFocus={actions && action === 'reject'}
359
+ autoFocus={actions && (action === 'reject' || action === 'failed')}
354
360
  onFocus={handleFocus}
355
361
  placeholder={t(
356
362
  'PLEASE_TYPE_YOUR_COMMENTS_IN_HERE',
@@ -42,7 +42,7 @@ const MapViewComponent = (props: MapViewParams) => {
42
42
  } = useLocation();
43
43
 
44
44
  const location = { lat: userLocation.latitude, lng: userLocation.longitude }
45
-
45
+ const haveOrders = Object.values(markerGroups)?.length > 0 && Object.values(customerMarkerGroups)?.length > 0
46
46
  const closeAlert = () => {
47
47
  setAlertState({
48
48
  open: false,
@@ -222,8 +222,8 @@ const MapViewComponent = (props: MapViewParams) => {
222
222
  initialRegion={{
223
223
  latitude: initialPosition.latitude,
224
224
  longitude: initialPosition.longitude,
225
- latitudeDelta: 0.001,
226
- longitudeDelta: 0.001 * ASPECT_RATIO,
225
+ latitudeDelta: haveOrders ? 0.01 : 0.1,
226
+ longitudeDelta: haveOrders ? 0.01 * ASPECT_RATIO : 0.1 * ASPECT_RATIO,
227
227
  }}
228
228
  style={{ flex: 1 }}
229
229
  zoomTapEnabled
@@ -241,7 +241,7 @@ const MapViewComponent = (props: MapViewParams) => {
241
241
  orderIds={marker.map((order: any) => order.id).join(', ')}
242
242
  />
243
243
  ))}
244
- {Object.values(customerMarkerGroups).map((marker: any) => (
244
+ {Object.values(customerMarkerGroups).map((marker: any) => (
245
245
  <RenderMarker
246
246
  key={marker[0]?.customer_id}
247
247
  marker={marker[0]}
@@ -1,5 +1,5 @@
1
1
  import React, { useState, useEffect, useCallback } from 'react'
2
- import { useEvent, useLanguage, useUtils, useSession } from 'ordering-components/native'
2
+ import { useEvent, useLanguage, useUtils, useSession, useApi } from 'ordering-components/native'
3
3
  import { View, Modal, StyleSheet, TouchableOpacity, Dimensions } from 'react-native'
4
4
  import { OText, OIcon } from '../shared'
5
5
  import { useTheme } from 'styled-components/native'
@@ -7,7 +7,7 @@ import Icon from 'react-native-vector-icons/Feather'
7
7
  import { NotificationContainer } from './styles'
8
8
  import Sound from 'react-native-sound'
9
9
  import moment from 'moment'
10
-
10
+ import { useLocation } from '../../hooks/useLocation'
11
11
  Sound.setCategory('Playback')
12
12
 
13
13
  const windowWidth = Dimensions.get('screen').width
@@ -16,9 +16,10 @@ export const NewOrderNotification = (props: any) => {
16
16
  const [events] = useEvent()
17
17
  const theme = useTheme()
18
18
  const [, t] = useLanguage()
19
- const [{ user }] = useSession()
19
+ const [{ user, token }] = useSession()
20
+ const [ordering] = useApi()
20
21
  const [{ getTimeAgo }] = useUtils()
21
-
22
+ const { getCurrentLocation } = useLocation();
22
23
  const [modalOpen, setModalOpen] = useState(false)
23
24
  const [newOrderId, setNewOrderId] = useState(null)
24
25
  const [soundTimeout, setSoundTimeout] = useState<any>(null)
@@ -33,15 +34,21 @@ export const NewOrderNotification = (props: any) => {
33
34
 
34
35
 
35
36
  const handlePlayNotificationSound = () => {
37
+ let times = 0
36
38
  const _timeout = setInterval(function () {
37
39
  notificationSound.play(success => {
38
40
  if (success) {
39
41
  console.log('successfully finished playing');
42
+ times = times + 1
40
43
  } else {
41
44
  console.log('playback failed due to audio decoding errors');
42
45
  }
43
46
  })
44
47
  setSoundTimeout(_timeout)
48
+ if (times === 3) {
49
+ clearInterval(_timeout)
50
+ clearInterval(soundTimeout)
51
+ }
45
52
  }, 2500)
46
53
  }
47
54
 
@@ -64,9 +71,16 @@ export const NewOrderNotification = (props: any) => {
64
71
  }
65
72
  }, [handleNotification])
66
73
 
67
-
68
- const handleUpdateOrder = useCallback((order: any) => {
74
+ const handleUpdateOrder = useCallback(async (order: any) => {
69
75
  if (order?.driver) {
76
+ const location = await getCurrentLocation()
77
+ await fetch(`${ordering.root}/users/${user.id}/locations`, {
78
+ method: 'POST',
79
+ body: JSON.stringify({
80
+ location: JSON.stringify({location: `{lat: ${location.latitude}, lng: ${location.longitude}}`})
81
+ }),
82
+ headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` }
83
+ })
70
84
  const assignedTimeDiff = moment.utc(order?.driver?.last_order_assigned_at).local().fromNow()
71
85
  if (assignedTimeDiff === 'a few seconds ago') {
72
86
  clearInterval(soundTimeout)
@@ -75,13 +75,14 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
75
75
  const showFloatButtonsPickUp: any = {
76
76
  8: true,
77
77
  3: true,
78
- 18: true
78
+ 18: true,
79
79
  };
80
80
 
81
81
  const showFloatButtonsAcceptOrReject: any = {
82
82
  0: true,
83
83
  4: true,
84
84
  7: true,
85
+ 14: true
85
86
  };
86
87
 
87
88
  const marginContainer: any = {
@@ -295,7 +296,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
295
296
  </Pickup>
296
297
  )}
297
298
  {(order?.status === 3) && order?.delivery_type === 1 && (
298
- <View style={{paddingVertical: 20, marginBottom: 20}}>
299
+ <View style={{ paddingVertical: 20, marginBottom: 20 }}>
299
300
  <OButton
300
301
  style={styles.btnPickUp}
301
302
  textStyle={{ color: theme.colors.white }}
@@ -388,7 +389,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
388
389
  handleChangeOrderStatus && handleChangeOrderStatus(9)
389
390
  }
390
391
  firstButtonClick={() =>
391
- handleChangeOrderStatus && handleChangeOrderStatus(12)
392
+ handleViewActionOrder && handleViewActionOrder('failed')
392
393
  }
393
394
  secondBtnText={t('PICKUP_COMPLETE', 'Pickup complete')}
394
395
  secondButton={true}
@@ -407,7 +408,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
407
408
  handleChangeOrderStatus && handleChangeOrderStatus(11)
408
409
  }
409
410
  firstButtonClick={() =>
410
- handleChangeOrderStatus && handleChangeOrderStatus(12)
411
+ handleViewActionOrder && handleViewActionOrder('failed')
411
412
  }
412
413
  secondBtnText={t('DELIVERY_COMPLETE', 'Delivery complete')}
413
414
  secondButton={true}
@@ -49,6 +49,9 @@ export const OrderContentComponent = (props: OrderContent) => {
49
49
  textBold: {
50
50
  fontWeight: '600',
51
51
  },
52
+ textLink: {
53
+ color: '#365CC7'
54
+ }
52
55
  })
53
56
  return (
54
57
  <OrderContent>
@@ -67,6 +70,7 @@ export const OrderContentComponent = (props: OrderContent) => {
67
70
  PressStyle={styles.linkWithIcons}
68
71
  url={`mailto:${order?.business?.email}`}
69
72
  shorcut={order?.business?.email}
73
+ TextStyle={styles.textLink}
70
74
  />
71
75
  </View>
72
76
  )}
@@ -77,6 +81,7 @@ export const OrderContentComponent = (props: OrderContent) => {
77
81
  PressStyle={styles.linkWithIcons}
78
82
  url={`tel:${order?.business?.cellphone}`}
79
83
  shorcut={`${order?.business?.cellphone}`}
84
+ TextStyle={styles.textLink}
80
85
  />
81
86
  </View>
82
87
  )}
@@ -87,6 +92,7 @@ export const OrderContentComponent = (props: OrderContent) => {
87
92
  PressStyle={styles.linkWithIcons}
88
93
  url={`tel:${order?.business?.phone}`}
89
94
  shorcut={order?.business?.phone}
95
+ TextStyle={styles.textLink}
90
96
  />
91
97
  </View>
92
98
  )}
@@ -100,6 +106,7 @@ export const OrderContentComponent = (props: OrderContent) => {
100
106
  android: `geo:0,0?q=${order?.business?.address}`,
101
107
  })}
102
108
  shorcut={order?.business?.address}
109
+ TextStyle={styles.textLink}
103
110
  />
104
111
  </View>
105
112
  )}
@@ -113,6 +120,7 @@ export const OrderContentComponent = (props: OrderContent) => {
113
120
  android: `geo:0,0?q=${order?.business?.address_notes}`,
114
121
  })}
115
122
  shorcut={order?.business?.address_notes}
123
+ TextStyle={styles.textLink}
116
124
  />
117
125
  </View>
118
126
  )}
@@ -165,6 +173,8 @@ export const OrderContentComponent = (props: OrderContent) => {
165
173
  PressStyle={styles.linkWithIcons}
166
174
  url={`mailto:${order?.customer?.email}`}
167
175
  shorcut={order?.customer?.email}
176
+ TextStyle={styles.textLink}
177
+
168
178
  />
169
179
  </View>
170
180
  )}
@@ -175,6 +185,7 @@ export const OrderContentComponent = (props: OrderContent) => {
175
185
  PressStyle={styles.linkWithIcons}
176
186
  url={`tel:${order?.customer?.cellphone}`}
177
187
  shorcut={order?.customer?.cellphone}
188
+ TextStyle={styles.textLink}
178
189
  />
179
190
  </View>
180
191
  )}
@@ -185,6 +196,7 @@ export const OrderContentComponent = (props: OrderContent) => {
185
196
  PressStyle={styles.linkWithIcons}
186
197
  url={`tel:${order?.customer?.phone}`}
187
198
  shorcut={order?.customer?.phone}
199
+ TextStyle={styles.textLink}
188
200
  />
189
201
  </View>
190
202
  )}
@@ -198,6 +210,7 @@ export const OrderContentComponent = (props: OrderContent) => {
198
210
  android: `geo:0,0?q=${order?.customer?.address}`,
199
211
  })}
200
212
  shorcut={order?.customer?.address}
213
+ TextStyle={styles.textLink}
201
214
  />
202
215
  </View>
203
216
  )}
@@ -226,7 +239,7 @@ export const OrderContentComponent = (props: OrderContent) => {
226
239
  {t('ORDER_DETAILS', 'Order Details')}
227
240
  </OText>
228
241
 
229
- {order?.products?.length &&
242
+ {order?.products?.length > 0 &&
230
243
  order?.products.map((product: any, i: number) => (
231
244
  <ProductItemAccordion
232
245
  key={product?.id || i}