ordering-ui-react-native 0.21.80 → 0.21.81-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 (167) 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/PaymentOptionsWebView/index.tsx +1 -0
  5. package/src/components/StripeMethodForm/index.tsx +6 -4
  6. package/src/components/VerifyPhone/styles.tsx +1 -2
  7. package/src/types/index.tsx +3 -1
  8. package/themes/business/index.tsx +4 -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 +3 -1
  14. package/themes/business/src/components/DriverMap/index.tsx +44 -27
  15. package/themes/business/src/components/GoogleMap/index.tsx +15 -8
  16. package/themes/business/src/components/Home/index.tsx +5 -1
  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 +74 -24
  22. package/themes/business/src/components/OrderDetails/Business.tsx +65 -7
  23. package/themes/business/src/components/OrderDetails/Delivery.tsx +35 -20
  24. package/themes/business/src/components/OrderDetails/OrderContentComponent.tsx +110 -40
  25. package/themes/business/src/components/OrderDetails/OrderHeaderComponent.tsx +50 -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/OrderSummary/index.tsx +223 -73
  29. package/themes/business/src/components/OrdersListManager/index.tsx +9 -1
  30. package/themes/business/src/components/OrdersOption/index.tsx +247 -159
  31. package/themes/business/src/components/PhoneInputNumber/index.tsx +8 -5
  32. package/themes/business/src/components/PreviousMessages/index.tsx +20 -3
  33. package/themes/business/src/components/PreviousOrders/OrderItem.tsx +27 -16
  34. package/themes/business/src/components/PreviousOrders/index.tsx +5 -3
  35. package/themes/business/src/components/PrinterEdition/MessageAlert.tsx +33 -0
  36. package/themes/business/src/components/PrinterEdition/index.tsx +431 -0
  37. package/themes/business/src/components/PrinterEdition/printerList.tsx +23 -0
  38. package/themes/business/src/components/PrinterEdition/styles.tsx +61 -0
  39. package/themes/business/src/components/PrinterSettings/index.tsx +267 -0
  40. package/themes/business/src/components/PrinterSettings/styles.tsx +30 -0
  41. package/themes/business/src/components/ReviewCustomer/index.tsx +2 -0
  42. package/themes/business/src/components/Sessions/index.tsx +187 -0
  43. package/themes/business/src/components/Sessions/styles.tsx +20 -0
  44. package/themes/business/src/components/StoresList/index.tsx +2 -2
  45. package/themes/business/src/components/UserFormDetails/index.tsx +111 -107
  46. package/themes/business/src/components/UserProfileForm/index.tsx +84 -47
  47. package/themes/business/src/components/WebsocketStatus/index.tsx +2 -2
  48. package/themes/business/src/components/shared/OInput.tsx +2 -0
  49. package/themes/business/src/components/shared/OTextarea.tsx +8 -9
  50. package/themes/business/src/hooks/useLocation.tsx +5 -4
  51. package/themes/business/src/types/index.tsx +23 -5
  52. package/themes/business/src/utils/index.tsx +19 -1
  53. package/themes/doordash/src/components/BusinessesListing/index.tsx +1 -1
  54. package/themes/doordash/src/components/LoginForm/index.tsx +1 -2
  55. package/themes/instacart/src/components/BusinessesListing/index.tsx +1 -1
  56. package/themes/kiosk/src/components/Checkout/index.tsx +6 -0
  57. package/themes/kiosk/src/components/NavBar/index.tsx +14 -14
  58. package/themes/kiosk/src/components/OptionCard/index.tsx +1 -1
  59. package/themes/kiosk/src/components/OrderTypeCardSelector/index.tsx +8 -10
  60. package/themes/kiosk/src/components/shared/OButton.tsx +5 -18
  61. package/themes/original/index.tsx +13 -1
  62. package/themes/original/src/components/AddressDetails/index.tsx +20 -10
  63. package/themes/original/src/components/AddressForm/index.tsx +32 -17
  64. package/themes/original/src/components/AddressList/index.tsx +8 -7
  65. package/themes/original/src/components/AnalyticsSegment/index.tsx +6 -6
  66. package/themes/original/src/components/AppleLogin/index.tsx +4 -4
  67. package/themes/original/src/components/BusinessBasicInformation/index.tsx +6 -9
  68. package/themes/original/src/components/BusinessController/index.tsx +12 -7
  69. package/themes/original/src/components/BusinessItemAccordion/index.tsx +13 -5
  70. package/themes/original/src/components/BusinessListingSearch/BusinessSearchFooter.tsx +2 -3
  71. package/themes/original/src/components/BusinessListingSearch/BusinessSearchHeader.tsx +1 -3
  72. package/themes/original/src/components/BusinessListingSearch/index.tsx +1 -2
  73. package/themes/original/src/components/BusinessPreorder/index.tsx +20 -15
  74. package/themes/original/src/components/BusinessProductsList/SubcategoriesComponent/index.tsx +5 -5
  75. package/themes/original/src/components/BusinessProductsList/index.tsx +2 -2
  76. package/themes/original/src/components/BusinessProductsList/styles.tsx +0 -3
  77. package/themes/original/src/components/BusinessProductsListing/index.tsx +18 -6
  78. package/themes/original/src/components/BusinessTypeFilter/index.tsx +9 -8
  79. package/themes/original/src/components/BusinessesListing/Layout/Appointment/index.tsx +2 -1
  80. package/themes/original/src/components/BusinessesListing/Layout/Original/index.tsx +1 -1
  81. package/themes/original/src/components/BusinessesListing/Layout/Original/styles.tsx +1 -1
  82. package/themes/original/src/components/BusinessesListing/index.tsx +0 -1
  83. package/themes/original/src/components/Cart/index.tsx +38 -11
  84. package/themes/original/src/components/CartContent/index.tsx +21 -8
  85. package/themes/original/src/components/Checkout/index.tsx +108 -60
  86. package/themes/original/src/components/CitiesControl/index.tsx +0 -3
  87. package/themes/original/src/components/CouponControl/index.tsx +1 -3
  88. package/themes/original/src/components/DriverTips/index.tsx +1 -3
  89. package/themes/original/src/components/Favorite/index.tsx +1 -5
  90. package/themes/original/src/components/FavoriteList/index.tsx +0 -1
  91. package/themes/original/src/components/ForgotPasswordForm/index.tsx +5 -7
  92. package/themes/original/src/components/GiftCard/GiftCardOrdersList/index.tsx +64 -0
  93. package/themes/original/src/components/GiftCard/GiftCardOrdersList/styles.tsx +8 -0
  94. package/themes/original/src/components/GiftCard/GiftCardUI/index.tsx +15 -17
  95. package/themes/original/src/components/GiftCard/PurchaseGiftCard/index.tsx +3 -7
  96. package/themes/original/src/components/GiftCard/RedeemGiftCard/index.tsx +24 -32
  97. package/themes/original/src/components/GiftCard/SendGiftCard/index.tsx +7 -9
  98. package/themes/original/src/components/GiftCard/SingleGiftCard/index.tsx +101 -0
  99. package/themes/original/src/components/GiftCard/SingleGiftCard/styles.tsx +4 -0
  100. package/themes/original/src/components/GiftCard/VerticalGiftCardOrdersLayout/index.tsx +82 -0
  101. package/themes/original/src/components/GiftCard/VerticalGiftCardOrdersLayout/styles.tsx +9 -0
  102. package/themes/original/src/components/GoogleMap/index.tsx +39 -18
  103. package/themes/original/src/components/Help/index.tsx +2 -0
  104. package/themes/original/src/components/HighestRatedBusinesses/index.tsx +1 -1
  105. package/themes/original/src/components/Home/index.tsx +2 -10
  106. package/themes/original/src/components/LoginForm/Otp/index.tsx +0 -3
  107. package/themes/original/src/components/LoginForm/index.tsx +4 -7
  108. package/themes/original/src/components/MessageListing/index.tsx +1 -0
  109. package/themes/original/src/components/Messages/index.tsx +8 -7
  110. package/themes/original/src/components/MomentOption/index.tsx +13 -2
  111. package/themes/original/src/components/MultiCartsPaymethodsAndWallets/index.tsx +7 -3
  112. package/themes/original/src/components/MultiCheckout/index.tsx +139 -87
  113. package/themes/original/src/components/MultiOrdersDetails/index.tsx +2 -1
  114. package/themes/original/src/components/MyOrders/index.tsx +21 -26
  115. package/themes/original/src/components/NavBar/index.tsx +4 -2
  116. package/themes/original/src/components/NetworkError/index.tsx +0 -5
  117. package/themes/original/src/components/NotFoundSource/index.tsx +0 -3
  118. package/themes/original/src/components/OrderDetails/OrderEta.tsx +1 -1
  119. package/themes/original/src/components/OrderDetails/OrderHistory.tsx +5 -7
  120. package/themes/original/src/components/OrderDetails/index.tsx +27 -10
  121. package/themes/original/src/components/OrderDetails/styles.tsx +0 -1
  122. package/themes/original/src/components/OrderProgress/index.tsx +22 -3
  123. package/themes/original/src/components/OrderSummary/index.tsx +28 -9
  124. package/themes/original/src/components/OrderTypeSelector/index.tsx +7 -6
  125. package/themes/original/src/components/OrdersOption/index.tsx +2 -4
  126. package/themes/original/src/components/PaymentOptionStripe/index.tsx +0 -5
  127. package/themes/original/src/components/PaymentOptionWallet/index.tsx +56 -56
  128. package/themes/original/src/components/PaymentOptions/index.tsx +17 -9
  129. package/themes/original/src/components/PlaceSpot/index.tsx +1 -3
  130. package/themes/original/src/components/PreviousOrders/index.tsx +1 -2
  131. package/themes/original/src/components/ProductForm/ActionButton.tsx +17 -20
  132. package/themes/original/src/components/ProductForm/index.tsx +107 -102
  133. package/themes/original/src/components/ProductItemAccordion/index.tsx +55 -49
  134. package/themes/original/src/components/ProductItemAccordion/styles.tsx +3 -4
  135. package/themes/original/src/components/ProductOptionSubOption/index.tsx +8 -1
  136. package/themes/original/src/components/ProfessionalProfile/index.tsx +4 -5
  137. package/themes/original/src/components/Promotions/index.tsx +6 -9
  138. package/themes/original/src/components/ReviewDriver/index.tsx +1 -1
  139. package/themes/original/src/components/ReviewOrder/index.tsx +2 -2
  140. package/themes/original/src/components/ReviewProducts/index.tsx +1 -1
  141. package/themes/original/src/components/ReviewTrigger/index.tsx +2 -2
  142. package/themes/original/src/components/ServiceForm/index.tsx +52 -54
  143. package/themes/original/src/components/Sessions/index.tsx +3 -3
  144. package/themes/original/src/components/SignupForm/index.tsx +86 -78
  145. package/themes/original/src/components/SingleOrderCard/index.tsx +1 -2
  146. package/themes/original/src/components/SingleProductCard/index.tsx +3 -4
  147. package/themes/original/src/components/SingleProductCard/styles.tsx +0 -3
  148. package/themes/original/src/components/StripeCardForm/index.tsx +0 -3
  149. package/themes/original/src/components/StripeCardsList/index.tsx +10 -3
  150. package/themes/original/src/components/StripeElementsForm/index.tsx +77 -60
  151. package/themes/original/src/components/StripeElementsForm/naked.tsx +48 -1
  152. package/themes/original/src/components/StripeRedirectForm/index.tsx +0 -3
  153. package/themes/original/src/components/TaxInformation/index.tsx +3 -2
  154. package/themes/original/src/components/UpsellingProducts/UpsellingContent.tsx +10 -7
  155. package/themes/original/src/components/UpsellingProducts/UpsellingLayout.tsx +8 -3
  156. package/themes/original/src/components/UserDetails/index.tsx +3 -2
  157. package/themes/original/src/components/UserFormDetails/index.tsx +155 -131
  158. package/themes/original/src/components/UserProfile/index.tsx +11 -2
  159. package/themes/original/src/components/Wallets/index.tsx +6 -3
  160. package/themes/original/src/components/WebsocketStatus/index.tsx +169 -0
  161. package/themes/original/src/components/WebsocketStatus/styles.tsx +28 -0
  162. package/themes/original/src/components/shared/OAlert.tsx +2 -1
  163. package/themes/original/src/components/shared/OButton.tsx +5 -4
  164. package/themes/original/src/components/shared/OInput.tsx +4 -8
  165. package/themes/original/src/types/index.tsx +5 -1
  166. package/themes/original/src/utils/index.tsx +12 -1
  167. package/themes/uber-eats/src/components/BusinessesListing/index.tsx +1 -1
@@ -1,5 +1,6 @@
1
1
  import React, { useState } from 'react';
2
2
  import { StyleSheet, TouchableOpacity, FlatList, RefreshControl } from 'react-native';
3
+ import FastImage from 'react-native-fast-image';
3
4
  import { useTheme } from 'styled-components/native';
4
5
  import { useLanguage, useUtils } from 'ordering-components/native';
5
6
  import { Card, Logo, Information, Header, Badge } from './styles';
@@ -201,6 +202,18 @@ export const PreviousMessages = (props: PreviousMessagesParams) => {
201
202
  value: t('ORDER_DRIVER_ON_WAY', 'Driver on way'),
202
203
  slug: 'ORDER_DRIVER_ON_WAY',
203
204
  percentage: 45
205
+ },
206
+ {
207
+ key: 24,
208
+ value: t('ORDER_DRIVER_WAITING_FOR_ORDER', 'Driver waiting for order'),
209
+ slug: 'ORDER_DRIVER_WAITING_FOR_ORDER',
210
+ percentage: 25
211
+ },
212
+ {
213
+ key: 25,
214
+ value: t('ORDER_ACCEPTED_BY_DRIVER_COMPANY', 'Accepted by driver company'),
215
+ slug: 'ORDER_ACCEPTED_BY_DRIVER_COMPANY',
216
+ percentage: 25
204
217
  }
205
218
  ];
206
219
 
@@ -284,10 +297,14 @@ export const PreviousMessages = (props: PreviousMessagesParams) => {
284
297
  activeOpacity={1}>
285
298
  <Card key={order?.id}>
286
299
  <Logo style={styles.logo}>
287
- <OIcon
288
- url={optimizeImage(order?.business?.logo, 'h_300,c_limit')}
289
- src={!order?.business?.logo && theme?.images?.dummies?.businessLogo}
300
+ <FastImage
290
301
  style={styles.icon}
302
+ source={order.business?.logo?.includes('https') ? {
303
+ uri: order.business?.logo,
304
+ priority: FastImage.priority.high,
305
+ cache: FastImage.cacheControl.immutable
306
+ } : order.business?.logo ?? theme?.images?.dummies?.businessLogo}
307
+ resizeMode={FastImage.resizeMode.cover}
291
308
  />
292
309
  </Logo>
293
310
  <Information>
@@ -1,5 +1,5 @@
1
1
  import React, { useEffect, useState } from 'react';
2
- import { Platform, PlatformIOSStatic, StyleSheet, TouchableOpacity, View } from 'react-native';
2
+ import { Platform, PlatformIOSStatic, Pressable, StyleSheet, View } from 'react-native';
3
3
  import DeviceInfo from 'react-native-device-info';
4
4
  import { useTheme } from 'styled-components/native';
5
5
  import { useLanguage, useUtils, useConfig } from 'ordering-components/native';
@@ -47,6 +47,7 @@ export const OrderItem = React.memo((props: any) => {
47
47
  timer: configState?.configs?.order_deadlines_enabled?.value === '1',
48
48
  slaBar: configState?.configs?.order_deadlines_enabled?.value === '1',
49
49
  })
50
+ const showExternalId = configState?.configs?.change_order_id?.value === '1'
50
51
 
51
52
  const IS_PORTRAIT = orientationState.orientation === PORTRAIT
52
53
  const platformIOS = Platform as PlatformIOSStatic
@@ -76,7 +77,6 @@ export const OrderItem = React.memo((props: any) => {
76
77
  marginLeft: 3,
77
78
  },
78
79
  title: {
79
- marginBottom: 6,
80
80
  fontFamily: 'Poppins',
81
81
  fontStyle: 'normal',
82
82
  fontWeight: '600',
@@ -84,7 +84,6 @@ export const OrderItem = React.memo((props: any) => {
84
84
  color: theme.colors.textGray,
85
85
  },
86
86
  date: {
87
- marginBottom: 6,
88
87
  fontFamily: 'Poppins',
89
88
  fontStyle: 'normal',
90
89
  fontWeight: 'normal',
@@ -120,7 +119,7 @@ export const OrderItem = React.memo((props: any) => {
120
119
  let restHours: string | number = Math.floor(restMinOfTargetedMin / 60)
121
120
  let restMins: string | number = restMinOfTargetedMin - 60 * restHours
122
121
  // make standard time format
123
- day = day === 0 ? '' : day + 'day '
122
+ day = day === 0 ? '' : `${day + ' ' + t('DAY', 'day') + ' '}`
124
123
  restHours = restHours < 10 ? '0' + restHours : restHours
125
124
  restMins = restMins < 10 ? '0' + restMins : restMins
126
125
 
@@ -138,8 +137,7 @@ export const OrderItem = React.memo((props: any) => {
138
137
  }, [configState.loading])
139
138
 
140
139
  return (
141
- <TouchableOpacity
142
- activeOpacity={1}
140
+ <Pressable
143
141
  disabled={order?.locked && isLogisticOrder}
144
142
  style={styles.cardButton}
145
143
  onPress={() => handlePressOrder({ ...order, logistic_order_id: _order?.id })}
@@ -155,7 +153,8 @@ export const OrderItem = React.memo((props: any) => {
155
153
  style={styles.icon}
156
154
  source={order.business?.logo?.includes('https') ? {
157
155
  uri: order.business?.logo,
158
- priority: FastImage.priority.normal,
156
+ priority: FastImage.priority.high,
157
+ cache: FastImage.cacheControl.immutable
159
158
  } : order.business?.logo ?? theme?.images?.dummies?.businessLogo}
160
159
  resizeMode={FastImage.resizeMode.cover}
161
160
  />
@@ -180,24 +179,36 @@ export const OrderItem = React.memo((props: any) => {
180
179
  />
181
180
  </NotificationIcon>
182
181
  )}
183
- <View style={{ flexDirection: 'row', flexWrap: 'wrap' }}>
184
- <OText
182
+ <View>
183
+ {!order?.order_group_id && showExternalId && !order?.order_group && (
184
+ <OText
185
+ style={styles.date}
186
+ color={theme.colors.unselectText}
187
+ numberOfLines={1}
188
+ adjustsFontSizeToFit
189
+ >
190
+ {`${order?.external_id ?? t('NO_EXTERNAL_ID', 'No external Id ') + t('NO', 'Order No.') + order?.id}` + ' · ' + `${order?.delivery_datetime_utc
191
+ ? parseDate(order?.delivery_datetime_utc)
192
+ : parseDate(order?.delivery_datetime, { utc: false })
193
+ }`}
194
+ </OText>
195
+ )}
196
+ {!showExternalId && (<OText
185
197
  style={styles.date}
186
198
  color={theme.colors.unselectText}
187
199
  numberOfLines={1}
188
200
  adjustsFontSizeToFit
189
201
  >
190
- {(!!order?.order_group_id && order?.order_group && isLogisticOrder
202
+ {((!!order?.order_group_id && order?.order_group && isLogisticOrder
191
203
  ? `${order?.order_group?.orders?.length} ${t('ORDERS', 'Orders')}`
192
- : (t('NO', 'Order No.') + order.id)
193
- ) + ' · '}
194
- {order?.delivery_datetime_utc
204
+ : (t('NO', 'Order No.') + order?.id)
205
+ ) + ' · ' + `${order?.delivery_datetime_utc
195
206
  ? parseDate(order?.delivery_datetime_utc)
196
- : parseDate(order?.delivery_datetime, { utc: false })}
207
+ : parseDate(order?.delivery_datetime, { utc: false })}`)}
197
208
  </OText>
209
+ )}
198
210
  {((currentTabSelected === 'pending' || currentTabSelected === 'inProgress') && allowColumns?.timer) && (
199
211
  <>
200
- <OText> · </OText>
201
212
  <OText
202
213
  style={styles.date}
203
214
  color={
@@ -237,6 +248,6 @@ export const OrderItem = React.memo((props: any) => {
237
248
  )}
238
249
  </Information>
239
250
  </Card>
240
- </TouchableOpacity>
251
+ </Pressable>
241
252
  )
242
253
  }, OrderItemPropsAreEqual)
@@ -45,6 +45,8 @@ export const PreviousOrders = (props: any) => {
45
45
  const deliveryPickupBtn = props.appTitle?.text?.includes('Delivery') && [3, 8, 18]
46
46
  const deliveryStatusCompleteBtn = props.appTitle?.text?.includes('Delivery') && [9, 19, 23]
47
47
  const isHideRejectButtons = configs?.reject_orders_enabled && configs?.reject_orders_enabled?.value !== '1' && !isBusinessApp
48
+ const isEnabledOrderNotReady = configs?.order_not_ready_enabled?.value === '1'
49
+ const isEnabledFailedPickupDriver = configs?.failed_pickup_by_driver_enabled?.value === '1'
48
50
 
49
51
  const handlePressOrder = (order: any) => {
50
52
  if (order?.locked && isLogisticOrder) return
@@ -242,7 +244,7 @@ export const PreviousOrders = (props: any) => {
242
244
  />
243
245
  </AcceptOrRejectOrderStyle>
244
246
  )}
245
- {_ordersGrouped[k][0]?.status === 3 && _ordersGrouped[k][0]?.delivery_type === 1 && !isHideRejectButtons &&
247
+ {_ordersGrouped[k][0]?.status === 3 && _ordersGrouped[k][0]?.delivery_type === 1 && !isHideRejectButtons && isEnabledOrderNotReady &&
246
248
  (
247
249
  <AcceptOrRejectOrderStyle>
248
250
  <OButton
@@ -330,9 +332,9 @@ export const PreviousOrders = (props: any) => {
330
332
  })}
331
333
  />
332
334
  )}
333
- {!!deliveryPickupBtn && deliveryPickupBtn?.includes(_ordersGrouped[k][0]?.status) && (
335
+ {!!deliveryPickupBtn && deliveryPickupBtn?.includes(_ordersGrouped[k][0]?.status) && isEnabledFailedPickupDriver && (
334
336
  <AcceptOrRejectOrderStyle>
335
- {!isHideRejectButtons && (
337
+ {!isHideRejectButtons && isEnabledOrderNotReady && (
336
338
  <OButton
337
339
  text={t('PICKUP_FAILED', 'Pickup failed')}
338
340
  bgColor={theme.colors.danger100}
@@ -0,0 +1,33 @@
1
+ import React, { useEffect, useState } from 'react'
2
+ import { useTheme } from 'styled-components/native'
3
+ import { OText } from '../shared'
4
+
5
+ export const MessageAlert = ({ message, resetMsg }: any) => {
6
+ const theme = useTheme()
7
+
8
+ const [text, setText] = useState(message)
9
+
10
+ useEffect(() => {
11
+ setText(message)
12
+ }, [message])
13
+
14
+ useEffect(() => {
15
+ if (text) {
16
+ setTimeout(() => {
17
+ setText(null)
18
+ resetMsg()
19
+ }, 2000);
20
+ }
21
+ }, [text])
22
+
23
+ return (
24
+ text ? (
25
+ <OText
26
+ size={14}
27
+ color={theme.colors.danger500}
28
+ >
29
+ {text}
30
+ </OText>
31
+ ) : null
32
+ )
33
+ }
@@ -0,0 +1,431 @@
1
+ import React, { useEffect, useState } from 'react'
2
+ import { StarPRNT } from 'react-native-star-prnt';
3
+ import { ActivityIndicator, Dimensions, SafeAreaView, StyleSheet, View } from 'react-native';
4
+ import SelectDropdown from 'react-native-select-dropdown'
5
+ import { useLanguage } from 'ordering-components/native'
6
+ import { useTheme } from 'styled-components/native'
7
+ import { useForm, Controller } from 'react-hook-form';
8
+ import FAIcons from 'react-native-vector-icons/FontAwesome'
9
+ import MCIcons from 'react-native-vector-icons/MaterialCommunityIcons'
10
+ import SimpleLineIcons from 'react-native-vector-icons/SimpleLineIcons'
11
+ import FeatherIcon from 'react-native-vector-icons/Feather'
12
+ import {
13
+ ContainerEdition,
14
+ BackArrowWrapper,
15
+ BackArrow,
16
+ WrapperIcons,
17
+ WrapperHeader,
18
+ WrapperIcon
19
+ } from './styles'
20
+
21
+ import { Container } from '../../layouts/Container'
22
+ import { OText, OInput, OIcon, OButton } from '../shared'
23
+
24
+ import { PRINTERS } from './printerList'
25
+ import { MessageAlert } from './MessageAlert'
26
+
27
+ const printerList = PRINTERS.map(printer => ({
28
+ ...printer,
29
+ ip: '',
30
+ type: 1,
31
+ nickname: printer.model,
32
+ portName1: `BT:${printer.model.split(' ')[0]}`,
33
+ bt: `BT:${printer.model.split(' ')[0]}`
34
+ }))
35
+
36
+ export const PrinterEdition = (props: any) => {
37
+ const { printer, onClose } = props
38
+
39
+ const HEIGHT_SCREEN = Dimensions.get('window').height
40
+ const [, t] = useLanguage()
41
+ const theme = useTheme()
42
+ const { control, setValue, watch } = useForm()
43
+
44
+ const [currentPrinter, setCurrentPrinter] = useState(printer)
45
+ const [discoverPort, setDiscoverPort] = useState({ loading: false, msg: null })
46
+
47
+ const watchIp = watch('ip')
48
+ const watchBt = watch('bt')
49
+ const watchNickname = watch('nickname')
50
+ const errorIP = !/^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/i.test(watchIp)
51
+ const errorBT = !/^[^\n]*$/i.test(watchBt) || !watchBt
52
+ const isErrorInput = currentPrinter?.type === 2 ? errorIP : errorBT
53
+ const isErrorNickname = watchNickname && !/^[^\n]*$/i.test(watchNickname)
54
+
55
+ const styles = StyleSheet.create({
56
+ icons: {
57
+ maxWidth: 40,
58
+ height: 40,
59
+ padding: 10,
60
+ alignItems: 'flex-end'
61
+ },
62
+ optionIcons: {
63
+ paddingRight: 10
64
+ },
65
+ inputStyle: {
66
+ borderWidth: 1,
67
+ borderRadius: 8,
68
+ color: theme.colors.arrowColor,
69
+ borderColor: theme.colors.inputSignup,
70
+ backgroundColor: theme.colors.transparent,
71
+ minHeight: 50,
72
+ maxHeight: 50
73
+ },
74
+ savePrinterBtnText: {
75
+ color: theme.colors.white,
76
+ fontSize: 18,
77
+ },
78
+ savePrinterBtn: {
79
+ height: 44,
80
+ borderRadius: 8,
81
+ marginHorizontal: 20
82
+ }
83
+ })
84
+
85
+ const handleChangePrinter = (values: any) => {
86
+ props.handleChangePrinter({
87
+ ...values,
88
+ index: currentPrinter?.index ?? null,
89
+ type: currentPrinter?.type,
90
+ ip: currentPrinter?.ip,
91
+ item: currentPrinter
92
+ })
93
+ }
94
+
95
+ const portDiscovery = async () => {
96
+ try {
97
+ setDiscoverPort({ ...discoverPort, loading: true })
98
+ let printers = await StarPRNT.portDiscovery('Bluetooth');
99
+
100
+ if (printers?.length) {
101
+ setValue('bt', printers[0]?.portName)
102
+ setCurrentPrinter({
103
+ ...currentPrinter,
104
+ ['bt']: printers[0]?.portName
105
+ })
106
+ }
107
+ setTimeout(() => {
108
+ setDiscoverPort({
109
+ ...discoverPort,
110
+ loading: false,
111
+ msg: !printers?.length
112
+ ? t('NO_PRINTERS_FOUND', 'No printers found')
113
+ : null
114
+ })
115
+ }, 1000);
116
+ } catch (e) {
117
+ setValue('bt', currentPrinter?.portName)
118
+ setCurrentPrinter({
119
+ ...currentPrinter,
120
+ ['bt']: currentPrinter?.portName
121
+ })
122
+ }
123
+ }
124
+
125
+ const onSubmit = () => {
126
+ handleChangePrinter({ edit: !!printer, isAdd: !printer })
127
+ onClose && onClose()
128
+ }
129
+
130
+ useEffect(() => {
131
+ currentPrinter?.ip && setValue('ip', currentPrinter?.ip)
132
+ currentPrinter?.bt && setValue('bt', currentPrinter?.bt)
133
+ currentPrinter?.nickname && setValue('nickname', currentPrinter?.nickname)
134
+ }, [currentPrinter?.type])
135
+
136
+ useEffect(() => {
137
+ setCurrentPrinter(printer)
138
+ }, [printer])
139
+
140
+ return (
141
+ <SafeAreaView style={{ flex: 1, marginBottom: 20 }}>
142
+ <Container>
143
+ <ContainerEdition>
144
+ <BackArrowWrapper>
145
+ <BackArrow activeOpacity={1} onPress={() => onClose()}>
146
+ <OIcon
147
+ src={theme.images.general.arrow_left}
148
+ color={theme.colors.textGray}
149
+ />
150
+ </BackArrow>
151
+ </BackArrowWrapper>
152
+ <WrapperHeader>
153
+ <SimpleLineIcons
154
+ name='printer'
155
+ color={theme.colors.textGray}
156
+ size={20}
157
+ style={{
158
+ ...styles.icons,
159
+ paddingLeft: 0,
160
+ color: theme.colors.primary
161
+ }}
162
+ />
163
+ <OText
164
+ size={22}
165
+ style={{ paddingTop: 0 }}
166
+ >
167
+ {t('PRINTER_CONFIGURE', 'Printer Configure')}
168
+ </OText>
169
+ </WrapperHeader>
170
+
171
+ <SelectDropdown
172
+ data={printerList}
173
+ defaultValueByIndex={printerList.findIndex(p => p.model === currentPrinter?.model)}
174
+ dropdownOverlayColor='transparent'
175
+ defaultButtonText={t('SELECT_PRINTER', 'Select printer')}
176
+ buttonTextAfterSelection={item => item.model}
177
+ rowTextForSelection={item => item.model}
178
+ renderDropdownIcon={() => dropDownIcon()}
179
+ buttonStyle={{
180
+ width: '100%',
181
+ backgroundColor: theme.colors.primary,
182
+ borderRadius: 8,
183
+ flexDirection: 'row-reverse',
184
+ justifyContent: 'space-between',
185
+ alignItems: 'center',
186
+ height: 44,
187
+ marginTop: 20,
188
+ }}
189
+ buttonTextStyle={{
190
+ color: theme.colors.white,
191
+ fontSize: 18,
192
+ textAlign: 'left',
193
+ marginHorizontal: 0
194
+ }}
195
+ dropdownStyle={{
196
+ borderRadius: 8,
197
+ borderColor: theme.colors.primary,
198
+ maxHeight: HEIGHT_SCREEN * 0.3
199
+ }}
200
+ rowStyle={{
201
+ borderBottomColor: theme.colors.disabled,
202
+ backgroundColor: theme.colors.gray100,
203
+ height: 40,
204
+ flexDirection: 'column',
205
+ alignItems: 'flex-start',
206
+ paddingTop: 8,
207
+ paddingHorizontal: 14,
208
+ width: '100%'
209
+ }}
210
+ rowTextStyle={{
211
+ marginHorizontal: 0,
212
+ fontSize: 14,
213
+ }}
214
+ onSelect={item => setCurrentPrinter(item)}
215
+ />
216
+ {!!currentPrinter && (
217
+ <WrapperIcons>
218
+ <OText
219
+ size={20}
220
+ style={{ paddingTop: 0, marginBottom: 10 }}
221
+ >
222
+ {`${t('PRINTER_NICKNAME', 'Nickname')}:`}
223
+ </OText>
224
+ <Controller
225
+ control={control}
226
+ name={'nickname'}
227
+ rules={{
228
+ pattern: {
229
+ value: /^[a-zA-Z0-9\s]+$/i,
230
+ message: t('INVALID_ERROR_PRINTER_NICKNAME', 'Invalid Nickname')
231
+ }
232
+ }}
233
+ defaultValue={currentPrinter?.ip ?? ''}
234
+ render={() => (
235
+ <OInput
236
+ placeholder={`${t('EXAMPLE_SHORT', 'Ex:')} ${t('NICKNAME_EXAMPLE_TEXT', 'Kitchen printer')}`}
237
+ placeholderTextColor={theme.colors.arrowColor}
238
+ style={{
239
+ ...styles.inputStyle,
240
+ borderColor: isErrorNickname ? theme.colors.danger500 : theme.colors.tabBar,
241
+ marginBottom: 10
242
+ }}
243
+ value={currentPrinter?.nickname ?? ''}
244
+ selectionColor={theme.colors.primary}
245
+ color={theme.colors.textGray}
246
+ onChange={(value: any) => {
247
+ setValue('nickname', value)
248
+ setCurrentPrinter({
249
+ ...currentPrinter,
250
+ nickname: value
251
+ })
252
+ }}
253
+ />
254
+ )}
255
+ />
256
+ <OText
257
+ size={20}
258
+ style={{ paddingTop: 0, marginBottom: 10 }}
259
+ >
260
+ {`${t('CONNECTION_TYPE', 'Connection type')}:`}
261
+ </OText>
262
+ <WrapperIcon
263
+ activeOpacity={1}
264
+ style={{
265
+ borderColor: currentPrinter?.type === 1 ? theme.colors.primary : theme.colors.textGray
266
+ }}
267
+ onPress={() => {
268
+ setCurrentPrinter({
269
+ ...currentPrinter,
270
+ type: 1,
271
+ ip: '',
272
+ portName: currentPrinter?.portName1
273
+ })
274
+ }}
275
+ >
276
+ <FAIcons
277
+ name='bluetooth'
278
+ size={22}
279
+ {...(currentPrinter?.type === 1 ? { color: theme.colors.primary } : {})}
280
+ style={styles.optionIcons}
281
+ />
282
+ <OText
283
+ size={18}
284
+ style={{ paddingTop: 0 }}
285
+ >
286
+ {t('CONNECTION_VIA_BLUETOOTH', 'Via Bluetooth')}
287
+ </OText>
288
+ </WrapperIcon>
289
+ <WrapperIcon
290
+ activeOpacity={1}
291
+ style={{
292
+ borderColor: currentPrinter?.type === 2 ? theme.colors.primary : theme.colors.textGray
293
+ }}
294
+ onPress={() => setCurrentPrinter({ ...currentPrinter, type: 2 })}
295
+ >
296
+ <MCIcons
297
+ name='access-point-network'
298
+ size={22}
299
+ {...(currentPrinter?.type === 2 ? { color: theme.colors.primary } : {})}
300
+ style={styles.optionIcons}
301
+ />
302
+ <OText
303
+ size={18}
304
+ style={{ paddingTop: 0 }}
305
+ >
306
+ {t('CONNECTION_VIA_LAN', 'Via LAN')}
307
+ </OText>
308
+ </WrapperIcon>
309
+ <View style={{ flexDirection: 'column', marginTop: 30 }}>
310
+ {currentPrinter?.type === 1 && (
311
+ <OText
312
+ size={14}
313
+ color={theme.colors.toastInfo}
314
+ style={{ marginBottom: 10 }}
315
+ >
316
+ {t('SEARCH_AVAILABLE_PRINTER_MESSAGE', 'Use the search icon to find an available printer')}
317
+ </OText>
318
+ )}
319
+ <View style={{ flexDirection: 'row', alignItems: 'center' }}>
320
+ <Controller
321
+ control={control}
322
+ name={currentPrinter?.type === 2 ? 'ip' : 'bt'}
323
+ rules={{
324
+ required: currentPrinter?.type === 2
325
+ ? t('VALIDATION_ERROR_IP_ADDRESS_REQUIRED', 'Ip address is required')
326
+ : t('VALIDATION_ERROR_BLUETOOTH_PORN_REQUIRED', 'Bluetooth port name is required'),
327
+ pattern: {
328
+ value: currentPrinter?.type === 2
329
+ ? /^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/i
330
+ : /^[a-zA-Z0-9]+$/i,
331
+ message: currentPrinter?.type === 2
332
+ ? t('INVALID_ERROR_IP_ADDRESS', 'Invalid ip address')
333
+ : t('INVALID_ERROR_BLUETOOTH_PORT_NAME', 'Invalid bluetooth port name')
334
+ }
335
+ }}
336
+ defaultValue={currentPrinter?.type === 2 ? currentPrinter?.ip ?? '' : currentPrinter?.bt ?? ''}
337
+ render={() => (
338
+ <OInput
339
+ placeholder={currentPrinter?.type === 2
340
+ ? t('IP_ADDRESS', 'Ip address')
341
+ : t('BLUETOOTH_PORT', 'Bluetooth port')
342
+ }
343
+ placeholderTextColor={theme.colors.arrowColor}
344
+ style={{
345
+ ...styles.inputStyle,
346
+ borderColor: isErrorInput ? theme.colors.danger500 : theme.colors.tabBar
347
+ }}
348
+ value={currentPrinter?.type === 2 ? currentPrinter?.ip ?? '' : currentPrinter?.bt ?? ''}
349
+ selectionColor={theme.colors.primary}
350
+ color={theme.colors.textGray}
351
+ onChange={(value: any) => {
352
+ setValue(currentPrinter?.type === 2 ? 'ip' : 'bt', value)
353
+ setCurrentPrinter({
354
+ ...currentPrinter,
355
+ [currentPrinter?.type === 2 ? 'ip' : 'bt']: value
356
+ })
357
+ }}
358
+ />
359
+ )}
360
+ />
361
+ {currentPrinter?.type === 1 && (
362
+ <>
363
+ {!discoverPort.loading ? (
364
+ <FAIcons
365
+ name='search'
366
+ size={22}
367
+ color={theme.colors.primary}
368
+ style={{ marginLeft: 10 }}
369
+ onPress={() => portDiscovery()}
370
+ />
371
+ ) : (
372
+ <ActivityIndicator
373
+ size="small"
374
+ style={{ marginLeft: 10 }}
375
+ color={theme.colors.primary}
376
+ />
377
+ )}
378
+ </>
379
+ )}
380
+ </View>
381
+ </View>
382
+ <OText
383
+ size={14}
384
+ color={theme.colors.tabBar}
385
+ style={{ paddingTop: 5, paddingLeft: 10 }}
386
+ >
387
+ {discoverPort.msg ? (
388
+ <MessageAlert
389
+ message={discoverPort.msg}
390
+ resetMsg={() => setDiscoverPort({ ...discoverPort, msg: null })}
391
+ />
392
+ ) : (
393
+ `${t('EXAMPLE_SHORT', 'Ex:')} ${currentPrinter?.type === 2 ? '8.8.8.8' : currentPrinter?.portName1}`
394
+ )}
395
+ </OText>
396
+ </WrapperIcons>
397
+ )}
398
+ </ContainerEdition>
399
+ </Container>
400
+ <View>
401
+ <OButton
402
+ text={t('SAVE_PRINTER', 'Save Printer')}
403
+ imgRightSrc={null}
404
+ textStyle={styles.savePrinterBtnText}
405
+ style={styles.savePrinterBtn}
406
+ bgColor={theme.colors.primary}
407
+ borderColor={theme.colors.primary}
408
+ isDisabled={
409
+ isErrorNickname ||
410
+ !currentPrinter?.model ||
411
+ currentPrinter?.type === 1 && !currentPrinter?.bt ||
412
+ currentPrinter?.type === 2 && !currentPrinter?.ip
413
+ }
414
+ onClick={() => onSubmit()}
415
+ />
416
+ </View>
417
+ </SafeAreaView>
418
+ )
419
+ }
420
+
421
+ const dropDownIcon = () => {
422
+ const theme = useTheme()
423
+
424
+ return (
425
+ <FeatherIcon
426
+ name='chevron-down'
427
+ size={20}
428
+ color={theme.colors.white}
429
+ />
430
+ )
431
+ }
@@ -0,0 +1,23 @@
1
+ export const PRINTERS = [
2
+ { model: 'mPOP', emulation: 'StarPRNT', printMode: 'append' },
3
+ { model: 'FVP10', emulation: 'StarLine', printMode: 'append' },
4
+ { model: 'TSP100', emulation: 'StarGraphic', printMode: 'appendBitmapText' },
5
+ { model: 'TSP100IV', emulation: 'StarLine', printMode: 'append' },
6
+ { model: 'TSP65011', emulation: 'StarLine', printMode: 'append' },
7
+ { model: 'TSP7001', emulation: 'StarLine', printMode: 'append' },
8
+ { model: 'TSP80011', emulation: 'StarLine', printMode: 'append' },
9
+ { model: 'SP700', emulation: 'StarDotImpact', printMode: 'append' },
10
+ { model: 'SM-S210i', emulation: 'EscPosMobile', printMode: 'append' },
11
+ { model: 'SM-S220i', emulation: 'EscPosMobile', printMode: 'append' },
12
+ { model: 'SM-S230i', emulation: 'EscosMobile', printMode: 'append' },
13
+ { model: 'SM-T300i/T300', emulation: 'EscPosMobile', printMode: 'append' },
14
+ { model: 'SM-T400i', emulation: 'EscosMobile', printMode: 'append' },
15
+ { model: 'SM-L200', emulation: 'StarPRNT', printMode: 'append' },
16
+ { model: 'SM-L300', emulation: 'StarPRNT', printMode: 'append' },
17
+ { model: 'BSC10', emulation: 'EscPos', bt: 'BT:BSC10', printMode: 'append' },
18
+ { model: 'SM-S210i StarPRNT', emulation: 'StarPRNT', printMode: 'append' },
19
+ { model: 'SM-S220i StarPRNT', emulation: 'StarPRNT', printMode: 'append' },
20
+ { model: 'SM-S230i StarPRNT', emulation: 'StarPRNT', printMode: 'append' },
21
+ { model: 'SM-T300i/T300 StarPRNT', emulation: 'StarPRNT', printMode: 'append' },
22
+ { model: 'SM-T400i StarPRNT', emulation: 'StarPRNT', printMode: 'append' },
23
+ ]