ordering-ui-react-native 0.21.94 → 0.21.95-release

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 (160) hide show
  1. package/package.json +6 -7
  2. package/src/DeliveryApp.tsx +43 -1
  3. package/src/components/BusinessesListing/index.tsx +1 -1
  4. package/src/components/StripeMethodForm/index.tsx +6 -4
  5. package/src/components/VerifyPhone/styles.tsx +1 -2
  6. package/src/context/OfflineActions/index.tsx +236 -0
  7. package/src/types/index.tsx +3 -1
  8. package/themes/business/index.tsx +2 -0
  9. package/themes/business/src/components/AcceptOrRejectOrder/index.tsx +9 -6
  10. package/themes/business/src/components/AcceptOrRejectOrder/styles.tsx +1 -0
  11. package/themes/business/src/components/BusinessController/index.tsx +8 -3
  12. package/themes/business/src/components/BusinessProductList/index.tsx +2 -1
  13. package/themes/business/src/components/Chat/index.tsx +15 -3
  14. package/themes/business/src/components/DriverMap/index.tsx +49 -27
  15. package/themes/business/src/components/FloatingButton/index.tsx +3 -2
  16. package/themes/business/src/components/GoogleMap/index.tsx +15 -8
  17. package/themes/business/src/components/LanguageSelector/index.tsx +2 -3
  18. package/themes/business/src/components/LanguageSelector/lang_country.json +515 -70
  19. package/themes/business/src/components/LogoutButton/index.tsx +1 -1
  20. package/themes/business/src/components/MapView/index.tsx +36 -17
  21. package/themes/business/src/components/NewOrderNotification/index.tsx +49 -29
  22. package/themes/business/src/components/OrderDetails/Business.tsx +74 -9
  23. package/themes/business/src/components/OrderDetails/Delivery.tsx +138 -55
  24. package/themes/business/src/components/OrderDetails/OrderContentComponent.tsx +125 -43
  25. package/themes/business/src/components/OrderDetails/OrderHeaderComponent.tsx +62 -24
  26. package/themes/business/src/components/OrderDetails/styles.tsx +39 -3
  27. package/themes/business/src/components/OrderDetails/usePrinterCommands.tsx +221 -0
  28. package/themes/business/src/components/OrderDetailsLogistic/index.tsx +3 -2
  29. package/themes/business/src/components/OrderSummary/index.tsx +210 -65
  30. package/themes/business/src/components/OrdersListManager/index.tsx +13 -1
  31. package/themes/business/src/components/OrdersOption/index.tsx +219 -150
  32. package/themes/business/src/components/PhoneInputNumber/index.tsx +8 -5
  33. package/themes/business/src/components/PreviousMessages/index.tsx +26 -3
  34. package/themes/business/src/components/PreviousOrders/OrderItem.tsx +42 -20
  35. package/themes/business/src/components/PreviousOrders/index.tsx +76 -66
  36. package/themes/business/src/components/PrinterEdition/MessageAlert.tsx +33 -0
  37. package/themes/business/src/components/PrinterEdition/index.tsx +431 -0
  38. package/themes/business/src/components/PrinterEdition/printerList.tsx +23 -0
  39. package/themes/business/src/components/PrinterEdition/styles.tsx +61 -0
  40. package/themes/business/src/components/PrinterSettings/index.tsx +267 -0
  41. package/themes/business/src/components/PrinterSettings/styles.tsx +30 -0
  42. package/themes/business/src/components/ReviewCustomer/index.tsx +2 -0
  43. package/themes/business/src/components/StoresList/index.tsx +2 -2
  44. package/themes/business/src/components/UserFormDetails/index.tsx +111 -107
  45. package/themes/business/src/components/UserProfileForm/index.tsx +43 -25
  46. package/themes/business/src/components/WebsocketStatus/index.tsx +2 -2
  47. package/themes/business/src/components/shared/OTextarea.tsx +8 -9
  48. package/themes/business/src/hooks/useLocation.tsx +5 -4
  49. package/themes/business/src/layouts/SafeAreaContainer.tsx +35 -19
  50. package/themes/business/src/types/index.tsx +15 -5
  51. package/themes/business/src/utils/index.tsx +25 -1
  52. package/themes/doordash/src/components/BusinessesListing/index.tsx +1 -1
  53. package/themes/doordash/src/components/LoginForm/index.tsx +1 -2
  54. package/themes/instacart/src/components/BusinessesListing/index.tsx +1 -1
  55. package/themes/kiosk/src/components/Checkout/index.tsx +6 -0
  56. package/themes/kiosk/src/components/NavBar/index.tsx +14 -14
  57. package/themes/kiosk/src/components/OptionCard/index.tsx +1 -1
  58. package/themes/kiosk/src/components/OrderTypeCardSelector/index.tsx +8 -10
  59. package/themes/kiosk/src/components/shared/OButton.tsx +5 -18
  60. package/themes/original/index.tsx +11 -0
  61. package/themes/original/src/components/AddressForm/index.tsx +32 -17
  62. package/themes/original/src/components/AddressList/index.tsx +8 -7
  63. package/themes/original/src/components/AnalyticsSegment/index.tsx +6 -6
  64. package/themes/original/src/components/AppleLogin/index.tsx +4 -4
  65. package/themes/original/src/components/BusinessBasicInformation/index.tsx +5 -8
  66. package/themes/original/src/components/BusinessController/index.tsx +12 -7
  67. package/themes/original/src/components/BusinessItemAccordion/index.tsx +13 -5
  68. package/themes/original/src/components/BusinessListingSearch/BusinessSearchFooter.tsx +2 -3
  69. package/themes/original/src/components/BusinessListingSearch/BusinessSearchHeader.tsx +1 -3
  70. package/themes/original/src/components/BusinessListingSearch/index.tsx +1 -2
  71. package/themes/original/src/components/BusinessPreorder/index.tsx +20 -15
  72. package/themes/original/src/components/BusinessProductsList/SubcategoriesComponent/index.tsx +73 -70
  73. package/themes/original/src/components/BusinessProductsList/index.tsx +6 -7
  74. package/themes/original/src/components/BusinessProductsList/styles.tsx +0 -3
  75. package/themes/original/src/components/BusinessProductsListing/index.tsx +18 -6
  76. package/themes/original/src/components/BusinessTypeFilter/index.tsx +9 -8
  77. package/themes/original/src/components/BusinessesListing/Layout/Appointment/index.tsx +2 -1
  78. package/themes/original/src/components/BusinessesListing/Layout/Original/index.tsx +1 -1
  79. package/themes/original/src/components/BusinessesListing/Layout/Original/styles.tsx +1 -1
  80. package/themes/original/src/components/BusinessesListing/index.tsx +0 -1
  81. package/themes/original/src/components/Cart/index.tsx +43 -15
  82. package/themes/original/src/components/CartContent/index.tsx +2 -4
  83. package/themes/original/src/components/Checkout/index.tsx +104 -58
  84. package/themes/original/src/components/CitiesControl/index.tsx +0 -3
  85. package/themes/original/src/components/CouponControl/index.tsx +1 -3
  86. package/themes/original/src/components/DriverTips/index.tsx +1 -3
  87. package/themes/original/src/components/Favorite/index.tsx +1 -5
  88. package/themes/original/src/components/FavoriteList/index.tsx +0 -1
  89. package/themes/original/src/components/ForgotPasswordForm/index.tsx +5 -7
  90. package/themes/original/src/components/GiftCard/GiftCardUI/index.tsx +15 -17
  91. package/themes/original/src/components/GiftCard/PurchaseGiftCard/index.tsx +3 -7
  92. package/themes/original/src/components/GiftCard/RedeemGiftCard/index.tsx +24 -32
  93. package/themes/original/src/components/GiftCard/SendGiftCard/index.tsx +7 -9
  94. package/themes/original/src/components/GiftCard/VerticalGiftCardOrdersLayout/index.tsx +11 -12
  95. package/themes/original/src/components/GoogleMap/index.tsx +39 -18
  96. package/themes/original/src/components/Help/index.tsx +2 -0
  97. package/themes/original/src/components/HighestRatedBusinesses/index.tsx +1 -1
  98. package/themes/original/src/components/Home/index.tsx +2 -10
  99. package/themes/original/src/components/LoginForm/Otp/index.tsx +0 -3
  100. package/themes/original/src/components/LoginForm/index.tsx +4 -7
  101. package/themes/original/src/components/MessageListing/index.tsx +2 -1
  102. package/themes/original/src/components/Messages/index.tsx +29 -17
  103. package/themes/original/src/components/MomentOption/index.tsx +13 -2
  104. package/themes/original/src/components/MultiCartsPaymethodsAndWallets/index.tsx +7 -3
  105. package/themes/original/src/components/MultiCheckout/index.tsx +129 -85
  106. package/themes/original/src/components/MultiOrdersDetails/index.tsx +1 -0
  107. package/themes/original/src/components/MyOrders/index.tsx +10 -23
  108. package/themes/original/src/components/NavBar/index.tsx +7 -4
  109. package/themes/original/src/components/NetworkError/index.tsx +0 -5
  110. package/themes/original/src/components/NotFoundSource/index.tsx +0 -3
  111. package/themes/original/src/components/OrderDetails/OrderEta.tsx +4 -3
  112. package/themes/original/src/components/OrderDetails/OrderHistory.tsx +13 -10
  113. package/themes/original/src/components/OrderDetails/index.tsx +42 -19
  114. package/themes/original/src/components/OrderDetails/styles.tsx +0 -1
  115. package/themes/original/src/components/OrderProgress/index.tsx +16 -6
  116. package/themes/original/src/components/OrderSummary/index.tsx +29 -10
  117. package/themes/original/src/components/OrderTypeSelector/index.tsx +7 -6
  118. package/themes/original/src/components/OrdersOption/index.tsx +3 -6
  119. package/themes/original/src/components/PaymentOptionStripe/index.tsx +0 -5
  120. package/themes/original/src/components/PaymentOptionWallet/index.tsx +56 -56
  121. package/themes/original/src/components/PaymentOptions/index.tsx +17 -9
  122. package/themes/original/src/components/PlaceSpot/index.tsx +1 -3
  123. package/themes/original/src/components/PreviousOrders/index.tsx +1 -2
  124. package/themes/original/src/components/ProductForm/ActionButton.tsx +17 -20
  125. package/themes/original/src/components/ProductForm/index.tsx +107 -102
  126. package/themes/original/src/components/ProductItemAccordion/index.tsx +55 -49
  127. package/themes/original/src/components/ProductItemAccordion/styles.tsx +3 -4
  128. package/themes/original/src/components/ProductOptionSubOption/index.tsx +16 -8
  129. package/themes/original/src/components/ProfessionalProfile/index.tsx +4 -5
  130. package/themes/original/src/components/Promotions/index.tsx +6 -9
  131. package/themes/original/src/components/ReviewDriver/index.tsx +1 -1
  132. package/themes/original/src/components/ReviewOrder/index.tsx +2 -2
  133. package/themes/original/src/components/ReviewProducts/index.tsx +1 -1
  134. package/themes/original/src/components/ReviewTrigger/index.tsx +2 -2
  135. package/themes/original/src/components/ServiceForm/index.tsx +52 -54
  136. package/themes/original/src/components/Sessions/index.tsx +3 -3
  137. package/themes/original/src/components/SignupForm/index.tsx +86 -78
  138. package/themes/original/src/components/SingleOrderCard/index.tsx +6 -4
  139. package/themes/original/src/components/SingleProductCard/index.tsx +3 -4
  140. package/themes/original/src/components/SingleProductCard/styles.tsx +0 -3
  141. package/themes/original/src/components/StripeCardForm/index.tsx +0 -3
  142. package/themes/original/src/components/StripeCardsList/index.tsx +10 -3
  143. package/themes/original/src/components/StripeElementsForm/index.tsx +77 -60
  144. package/themes/original/src/components/StripeElementsForm/naked.tsx +48 -1
  145. package/themes/original/src/components/StripeRedirectForm/index.tsx +0 -3
  146. package/themes/original/src/components/TaxInformation/index.tsx +3 -2
  147. package/themes/original/src/components/UpsellingProducts/UpsellingContent.tsx +10 -7
  148. package/themes/original/src/components/UpsellingProducts/UpsellingLayout.tsx +8 -3
  149. package/themes/original/src/components/UserDetails/index.tsx +3 -2
  150. package/themes/original/src/components/UserFormDetails/index.tsx +154 -130
  151. package/themes/original/src/components/UserProfile/index.tsx +9 -1
  152. package/themes/original/src/components/Wallets/index.tsx +6 -3
  153. package/themes/original/src/components/WebsocketStatus/index.tsx +1 -4
  154. package/themes/original/src/components/shared/OAlert.tsx +2 -1
  155. package/themes/original/src/components/shared/OButton.tsx +5 -4
  156. package/themes/original/src/components/shared/OInput.tsx +4 -8
  157. package/themes/original/src/components/shared/OModal.tsx +7 -2
  158. package/themes/original/src/types/index.tsx +5 -1
  159. package/themes/original/src/utils/index.tsx +30 -1
  160. package/themes/uber-eats/src/components/BusinessesListing/index.tsx +1 -1
@@ -53,16 +53,23 @@ const MapViewComponent = (props: MapViewParams) => {
53
53
 
54
54
  const fitCoordinates = (location?: any) => {
55
55
  if (mapRef.current) {
56
- mapRef.current.fitToCoordinates(
57
- [
58
- { latitude: location.latitude ?? 0, longitude: location.longitude ?? 0},
59
- {
60
- latitude: userLocation?.latitude,
61
- longitude: userLocation?.longitude,
62
- },
63
- ],
56
+ const isSendCoordinates =
57
+ location &&
58
+ userLocation &&
59
+ location.latitude !== userLocation.latitude &&
60
+ location.longitude !== userLocation.longitude &&
61
+ location.latitude !== 0 &&
62
+ location.longitude !== 0 &&
63
+ userLocation.latitude !== 0 &&
64
+ userLocation.longitude !== 0
65
+
66
+ isSendCoordinates && mapRef.current.fitToCoordinates(
67
+ [location, userLocation].map(_location => ({
68
+ latitude: _location.latitude,
69
+ longitude: _location.longitude
70
+ })),
64
71
  {
65
- edgePadding: { top: 120, right: 120, bottom: 120, left: 120 },
72
+ edgePadding: { top: 120, right: 120, bottom: 120, left: 120 }
66
73
  },
67
74
  );
68
75
  }
@@ -133,8 +140,20 @@ const MapViewComponent = (props: MapViewParams) => {
133
140
  const RenderMarker = ({ marker, customer, orderIds }: { marker: any, customer?: boolean, orderIds?: Array<number> }) => {
134
141
  const markerRef = useRef<any>()
135
142
 
136
- let coordinateLat = (customer ? marker?.customer?.location?.lat : marker?.business?.location?.lat) ?? initialPosition?.latitude
137
- let coordinateLng = (customer ? marker?.customer?.location?.lng : marker?.business?.location?.lng) ?? initialPosition?.longitude
143
+ let coordinateLat = (customer
144
+ ? typeof marker?.customer?.location?.lat === 'number' && !Number.isNaN(marker?.customer?.location?.lat)
145
+ ? marker?.customer?.location?.lat
146
+ : 0
147
+ : typeof marker?.business?.location?.lat === 'number' && !Number.isNaN(marker?.business?.location?.lat)
148
+ ? marker?.business?.location?.lat
149
+ : 0) ?? (initialPosition?.latitude || 0)
150
+ let coordinateLng = (customer
151
+ ? typeof marker?.customer?.location?.lng === 'number' && !Number.isNaN(marker?.customer?.location?.lng)
152
+ ? marker?.customer?.location?.lng
153
+ : 0
154
+ : typeof marker?.business?.location?.lng === 'number' && !Number.isNaN(marker?.business?.location?.lng)
155
+ ? marker?.business?.location?.lng
156
+ : 0) ?? (initialPosition?.longitude || 0)
138
157
 
139
158
  useEffect(() => {
140
159
  if (
@@ -154,8 +173,8 @@ const MapViewComponent = (props: MapViewParams) => {
154
173
  }}
155
174
  onPress={() =>
156
175
  setLocationSelected({
157
- latitude: customer ? marker?.customer?.location?.lat : marker?.business?.location?.lat,
158
- longitude: customer ? marker?.customer?.location?.lng : marker?.business?.location?.lng
176
+ latitude: coordinateLat,
177
+ longitude: coordinateLng
159
178
  })
160
179
  }
161
180
  ref={(ref) => markerRef.current = ref}
@@ -235,8 +254,8 @@ const MapViewComponent = (props: MapViewParams) => {
235
254
  ref={mapRef}
236
255
  provider={PROVIDER_GOOGLE}
237
256
  initialRegion={{
238
- latitude: initialPosition?.latitude,
239
- longitude: initialPosition?.longitude,
257
+ latitude: initialPosition?.latitude || 0,
258
+ longitude: initialPosition?.longitude || 0,
240
259
  latitudeDelta: haveOrders ? 0.01 : 0.1,
241
260
  longitudeDelta: haveOrders ? 0.01 * ASPECT_RATIO : 0.1 * ASPECT_RATIO,
242
261
  }}
@@ -266,8 +285,8 @@ const MapViewComponent = (props: MapViewParams) => {
266
285
  ))}
267
286
  <Marker
268
287
  coordinate={{
269
- latitude: location.lat,
270
- longitude: location.lng,
288
+ latitude: typeof location.lat === 'number' && !Number.isNaN(location.lat) ? location.lat : 0,
289
+ longitude: typeof location.lng === 'number' && !Number.isNaN(location.lng) ? location.lng : 0,
271
290
  }}
272
291
  title={t('YOUR_LOCATION', 'Your Location')}
273
292
  >
@@ -20,7 +20,9 @@ import {
20
20
  useEvent,
21
21
  useLanguage,
22
22
  useSession,
23
- useConfig
23
+ useConfig,
24
+ useToast,
25
+ ToastType
24
26
  } from 'ordering-components/native'
25
27
 
26
28
  import { OIcon, OText } from '../shared'
@@ -42,17 +44,25 @@ const SoundPlayerComponent = (props: any) => {
42
44
  const id = setInterval(() => setCount(count + 1), 2500)
43
45
 
44
46
  const playSound = async () => {
45
- SoundPlayer.playUrl(URL_SOUND)
46
- await new Promise(resolve => setTimeout(resolve, DELAY_SOUND))
47
- SoundPlayer.stop()
47
+ try {
48
+ SoundPlayer.playUrl(URL_SOUND)
49
+ await new Promise(resolve => setTimeout(resolve, DELAY_SOUND))
50
+ SoundPlayer.stop()
51
+ } catch (err: any) {
52
+ console.log('Sound Error - ', err.message)
53
+ }
48
54
  }
49
55
  if (NativeModules?.RNSoundPlayer?.playUrl && typeof URL_SOUND === 'string' && isEnabledReadStorage) {
50
56
  playSound()
51
57
  }
52
58
 
53
59
  return () => {
54
- SoundPlayer.stop()
55
60
  clearInterval(id);
61
+ try {
62
+ SoundPlayer.stop()
63
+ } catch (err: any) {
64
+ console.log('Sound Error - ', err.message)
65
+ }
56
66
  }
57
67
  }, [count, isEnabledReadStorage])
58
68
 
@@ -65,7 +75,7 @@ const SoundPlayerComponent = (props: any) => {
65
75
  setIsEnabledReadStorage(true)
66
76
  }
67
77
  }
68
- checkSoundMedia()
78
+ // checkSoundMedia()
69
79
 
70
80
  }, [])
71
81
  return (
@@ -107,23 +117,23 @@ const SoundPlayerComponent = (props: any) => {
107
117
  }
108
118
 
109
119
  const NewOrderNotificationUI = (props: any) => {
110
- const { isBusinessApp, evtList } = props
111
-
120
+ const { isBusinessApp, evtList, orderStatus } = props
121
+ const [, t] = useLanguage()
112
122
  const [events] = useEvent()
113
123
  const [{ user, token }] = useSession()
114
124
  const [ordering] = useApi()
115
- const [{ configs }] = useConfig()
125
+ const [, { showToast }] = useToast()
116
126
  const { getCurrentLocation } = useLocation()
117
127
  const [currentEvent, setCurrentEvent] = useState<any>(null)
118
128
 
119
- const orderStatus = !!isBusinessApp
120
- ? configs?.notification_business_states?.value.split('|').map((value: any) => Number(value)) || []
121
- : configs?.notification_driver_states?.value.split('|').map((value: any) => Number(value)) || []
122
-
123
- const handleEventNotification = async (evtType: number, value: any) => {
129
+ const handleEventNotification = async (evtType: number, value: any, orderStatus?: any) => {
124
130
  if (value?.driver) {
125
131
  try {
126
132
  const location = await getCurrentLocation()
133
+ if (!location?.latitude || !location?.longitude) {
134
+ showToast(t('ERROR_UPDATING_COORDS', 'Error updating coords'), ToastType.Error)
135
+ return
136
+ }
127
137
  await fetch(`${ordering.root}/users/${user.id}/locations`, {
128
138
  method: 'POST',
129
139
  body: JSON.stringify({
@@ -142,11 +152,11 @@ const NewOrderNotificationUI = (props: any) => {
142
152
  } catch { }
143
153
  const duration = moment.duration(moment().diff(moment.utc(value?.last_driver_assigned_at)))
144
154
  const assignedSecondsDiff = duration.asSeconds()
145
- if (assignedSecondsDiff < 5 && !isBusinessApp && !value?.logistic_status && orderStatus.includes(value.status)) {
155
+ if (assignedSecondsDiff < 5 && !isBusinessApp && !value?.logistic_status) {
146
156
  setCurrentEvent({ evt: 2, orderId: value?.id ?? value?.order_id })
147
157
  }
148
158
  }
149
- if (!orderStatus.includes(value.status) || value?.author_id === user.id) return
159
+ if ((!orderStatus.includes(value.status) && evtType !== 1 && isBusinessApp && orderStatus?.length > 0) || value?.author_id === user.id) return
150
160
  setCurrentEvent({
151
161
  evt: evtType,
152
162
  orderId: value?.driver
@@ -158,20 +168,30 @@ const NewOrderNotificationUI = (props: any) => {
158
168
  }
159
169
 
160
170
  useEffect(() => {
161
- events.on('message_added_notification', (o: any) => handleEventNotification(1, o))
162
- events.on('order_added_notification', (o: any) => handleEventNotification(2, o))
163
- events.on('order_updated_notification', (o: any) => handleEventNotification(3, o))
164
- events.on('request_register_notification', (o: any) => handleEventNotification(2, o))
165
- events.on('request_update_notification', (o: any) => handleEventNotification(3, o))
171
+ const handleEventTypeOne = (o: any) => {
172
+ handleEventNotification(1, o, orderStatus)
173
+ }
174
+ const handleEventTypeTwo = (o: any) => {
175
+ handleEventNotification(2, o, orderStatus)
176
+ }
177
+ const handleEventTypeThree = (o: any) => {
178
+ handleEventNotification(3, o, orderStatus)
179
+ }
180
+
181
+ events.on('message_added_notification', handleEventTypeOne)
182
+ events.on('order_added_notification', handleEventTypeTwo)
183
+ events.on('order_updated_notification', handleEventTypeThree)
184
+ events.on('request_register_notification', handleEventTypeTwo)
185
+ events.on('request_update_notification', handleEventTypeThree)
166
186
 
167
187
  return () => {
168
- events.off('message_added_notification', (o: any) => handleEventNotification(1, o))
169
- events.off('order_added_notification', (o: any) => handleEventNotification(2, o))
170
- events.off('order_updated_notification', (o: any) => handleEventNotification(3, o))
171
- events.off('request_register_notification', (o: any) => handleEventNotification(2, o))
172
- events.off('request_update_notification', (o: any) => handleEventNotification(3, o))
188
+ events.off('message_added_notification', handleEventTypeOne)
189
+ events.off('order_added_notification', handleEventTypeTwo)
190
+ events.off('order_updated_notification', handleEventTypeThree)
191
+ events.off('request_register_notification', handleEventTypeTwo)
192
+ events.off('request_update_notification', handleEventTypeThree)
173
193
  }
174
- }, [])
194
+ }, [orderStatus, events])
175
195
 
176
196
  useEffect(() => {
177
197
  return () => setCurrentEvent(null)
@@ -179,13 +199,13 @@ const NewOrderNotificationUI = (props: any) => {
179
199
 
180
200
  return (
181
201
  <>
182
- {!!currentEvent ? (
202
+ {!!currentEvent && (
183
203
  <SoundPlayerComponent
184
204
  evtList={evtList}
185
205
  currentEvent={currentEvent}
186
206
  handleCloseEvents={() => setCurrentEvent(null)}
187
207
  />
188
- ) : null}
208
+ )}
189
209
  </>
190
210
  )
191
211
  };
@@ -4,8 +4,10 @@ import {
4
4
  View,
5
5
  TouchableOpacity,
6
6
  ActivityIndicator,
7
+ Alert,
7
8
  } from 'react-native';
8
9
  import Clipboard from '@react-native-clipboard/clipboard';
10
+ import { StarPRNT } from 'react-native-star-prnt';
9
11
  import { Placeholder, PlaceholderLine, Fade } from 'rn-placeholder';
10
12
  import { useTheme } from 'styled-components/native';
11
13
  import {
@@ -35,6 +37,8 @@ import CountryPicker from 'react-native-country-picker-modal';
35
37
  import { NotFoundSource } from '../NotFoundSource';
36
38
  import { OrderHeaderComponent } from './OrderHeaderComponent';
37
39
  import { OrderContentComponent } from './OrderContentComponent';
40
+ import { _retrieveStoreData } from '../../providers/StoreUtil'
41
+ import { usePrinterCommands } from './usePrinterCommands'
38
42
 
39
43
  export const OrderDetailsUI = (props: OrderDetailsParams) => {
40
44
  const {
@@ -44,12 +48,13 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
44
48
  readMessages,
45
49
  messagesReadList,
46
50
  handleAssignDriver,
47
- handleChangeOrderStatus,
48
51
  isFromCheckout,
49
52
  driverLocation,
50
53
  actions,
51
54
  orderTitle,
52
55
  appTitle,
56
+ loadMessages,
57
+ notificationApp
53
58
  } = props;
54
59
 
55
60
  const theme = useTheme();
@@ -57,6 +62,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
57
62
  const [{ parsePrice, parseNumber, parseDate }] = useUtils();
58
63
  const [{ user, token }] = useSession();
59
64
  const [{ configs }] = useConfig();
65
+ const { generateCommands } = usePrinterCommands()
60
66
  const [, { showToast }] = useToast();
61
67
  const [unreadAlert, setUnreadAlert] = useState({
62
68
  business: false,
@@ -70,6 +76,12 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
70
76
  const [openModalForAccept, setOpenModalForAccept] = useState(false);
71
77
  const [openModalForMapView, setOpenModalForMapView] = useState(false);
72
78
  const [isDriverModalVisible, setIsDriverModalVisible] = useState(false);
79
+ const [printerSettings, setPrinterSettings] = useState<any>('')
80
+ const [autoPrintEnabled, setAutoPrintEnabled] = useState<boolean>(false)
81
+
82
+ const orderToComplete = [4, 20, 21]
83
+ const orderToReady = [7, 14]
84
+ const deliveryTypes = [1, 7]
73
85
 
74
86
  if (order?.status === 7 || order?.status === 4) {
75
87
  if (drivers?.length > 0 && drivers) {
@@ -120,6 +132,16 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
120
132
  }
121
133
  }
122
134
 
135
+ const handleChangeOrderStatus = async (status: any, isAcceptOrReject: any = {}) => {
136
+ if (props.handleChangeOrderStatus) {
137
+ const order: any = await props.handleChangeOrderStatus(status, isAcceptOrReject)
138
+
139
+ if (order?.status === 7 && autoPrintEnabled && printerSettings) {
140
+ handleViewSummaryOrder()
141
+ }
142
+ }
143
+ }
144
+
123
145
  const getFormattedSubOptionName = ({ quantity, name, position, price }: any) => {
124
146
  if (name !== 'No') {
125
147
  const pos = position && position !== 'whole' ? `(${t(position.toUpperCase(), position)})` : '';
@@ -190,7 +212,13 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
190
212
  ? t('EAT_IN', 'Eat in')
191
213
  : order.delivery_type === 4
192
214
  ? t('CURBSIDE', 'Curbside')
193
- : t('DRIVER_THRU', 'Driver thru')
215
+ : order.delivery_type === 5
216
+ ? t('DRIVER_THRU', 'Driver thru')
217
+ : order.delivery_type === 7
218
+ ? t('CATERING_DELIVERY', 'Catering delivery')
219
+ : order.delivery_type === 8
220
+ ? t('CATERING_PICKUP', 'Catering pickup')
221
+ : t('DELIVERY', 'Delivery')
194
222
  }\n`
195
223
  : '';
196
224
 
@@ -279,7 +307,8 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
279
307
 
280
308
  const handleOpenMessagesForBusiness = () => {
281
309
  setOpenModalForBusiness(true);
282
- readMessages && readMessages();
310
+ readMessages && readMessages()
311
+ loadMessages && loadMessages()
283
312
  setUnreadAlert({ ...unreadAlert, business: false });
284
313
  };
285
314
 
@@ -291,7 +320,28 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
291
320
  setOpenModalForAccept(true);
292
321
  };
293
322
 
323
+ const printAction = async (printerSettings: any, commands: any, showAlert: boolean = true) => {
324
+ try {
325
+ var printResult = await StarPRNT.print(printerSettings?.emulation, commands, printerSettings?.portName);
326
+ showAlert && showToast(ToastType.Info, t('ORDER_PRINTED_SUCCESS', 'Order printed'), 1000)
327
+ } catch (e) {
328
+ showAlert && showToast(ToastType.Error, t('ORDER_PRINTED_FAILED', 'Order not printed, connection failed'), 1000)
329
+ }
330
+ }
331
+
294
332
  const handleViewSummaryOrder = () => {
333
+ if (printerSettings) {
334
+ printerSettings.map((printer: any, idx: number) => {
335
+ const commands: any = generateCommands({
336
+ ...order,
337
+ orderStatus: getOrderStatus(order?.status, t)?.value
338
+ }, printer?.printMode)
339
+ commands.push({ appendCutPaper: StarPRNT.CutPaperAction.PartialCutWithFeed })
340
+
341
+ printAction(printer, commands, idx === printerSettings.length - 1)
342
+ })
343
+ return
344
+ }
295
345
  navigation?.navigate &&
296
346
  navigation.navigate('OrderSummary', {
297
347
  order,
@@ -300,6 +350,8 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
300
350
  };
301
351
 
302
352
  const handleCloseModal = () => {
353
+ readMessages && readMessages()
354
+ loadMessages && loadMessages()
303
355
  setOpenModalForBusiness(false);
304
356
  };
305
357
 
@@ -340,7 +392,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
340
392
  },
341
393
  {
342
394
  ...order?.customer?.location,
343
- title: order?.customer?.name ?? t('CUSTOMER', 'Customer'),
395
+ title: order?.customer?.name ?? t('CUSTOMER', 'Customer'),
344
396
  address: {
345
397
  addressName: order?.customer?.address,
346
398
  zipcode: order?.customer?.zipcode
@@ -372,6 +424,17 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
372
424
  }
373
425
  }, [driverLocation]);
374
426
 
427
+ useEffect(() => {
428
+ const getStorageData = async () => {
429
+ const printers = await _retrieveStoreData('printers')
430
+ const autoPrint = await _retrieveStoreData('auto_print_after_accept_order')
431
+ setPrinterSettings(printers?.length && printers)
432
+ setAutoPrintEnabled(!!autoPrint)
433
+ }
434
+
435
+ getStorageData()
436
+ }, [])
437
+
375
438
  const styles = StyleSheet.create({
376
439
  driverOff: {
377
440
  backgroundColor: theme.colors.notAvailable,
@@ -432,6 +495,8 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
432
495
  handleCopyClipboard={handleCopyClipboard}
433
496
  handleArrowBack={handleArrowBack}
434
497
  isCustomView={props.isCustomView}
498
+ messages={messages}
499
+ messagesReadList={messagesReadList}
435
500
  />
436
501
  <OrderDetailsContainer
437
502
  keyboardShouldPersistTaps="handled"
@@ -439,7 +504,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
439
504
  <>
440
505
  <OrderContentComponent order={order} />
441
506
  {(order?.status === 7 || order?.status === 4) &&
442
- order?.delivery_type === 1 && configs?.assign_driver_enabled?.value === '1' && (
507
+ deliveryTypes.includes(order?.delivery_type) && configs?.assign_driver_enabled?.value === '1' && (
443
508
  <AssignDriver>
444
509
  <OText style={{ marginBottom: 5 }} size={16} weight="600">
445
510
  {t('ASSIGN_DRIVER', 'Assign driver')}
@@ -537,6 +602,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
537
602
  messages={messages}
538
603
  order={order}
539
604
  setMessages={setMessages}
605
+ notificationApp={notificationApp}
540
606
  />
541
607
  </OModal>
542
608
 
@@ -580,7 +646,6 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
580
646
  </>
581
647
  <View style={{ height: 30 }} />
582
648
  </OrderDetailsContainer>
583
-
584
649
  {order &&
585
650
  Object.keys(order).length > 0 &&
586
651
  getOrderStatus(order?.status, t)?.value ===
@@ -597,7 +662,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
597
662
  widthButton={'45%'}
598
663
  />
599
664
  )}
600
- {order?.status === 7 && (
665
+ {orderToReady.includes(order?.status) && (
601
666
  <FloatingButton
602
667
  btnText={t('READY_FOR_PICKUP', 'Ready for pickup')}
603
668
  colorTxt1={theme.colors.primary}
@@ -607,7 +672,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
607
672
  disabled={loading}
608
673
  />
609
674
  )}
610
- {order?.status === 4 && ![1].includes(order?.delivery_type) && (
675
+ {orderToComplete.includes(order?.status) && !deliveryTypes.includes(order?.delivery_type) && (
611
676
  <FloatingButton
612
677
  btnText={t(
613
678
  'ORDER_NOT_PICKEDUP_BY_CUSTOMER',
@@ -618,7 +683,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
618
683
  secondButtonClick={() => handleChangeOrderStatus?.(15)}
619
684
  firstButtonClick={() => handleChangeOrderStatus?.(17)}
620
685
  secondBtnText={t(
621
- 'PICKUP_COMPLETED_BY_CUSTOMER',
686
+ 'ORDER_PICKUP_COMPLETED_BY_CUSTOMER',
622
687
  'Pickup completed by customer',
623
688
  )}
624
689
  secondButton={true}