ordering-ui-react-native 0.17.38 → 0.17.39-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 (214) hide show
  1. package/package.json +8 -7
  2. package/src/DeliveryApp.tsx +43 -1
  3. package/src/components/BusinessesListing/index.tsx +1 -1
  4. package/src/components/OrderCreating/index.tsx +1 -21
  5. package/src/components/PaymentOptionsWebView/index.tsx +29 -8
  6. package/src/components/StripeMethodForm/index.tsx +135 -102
  7. package/src/components/VerifyPhone/styles.tsx +1 -2
  8. package/src/components/shared/OToast.tsx +4 -4
  9. package/src/types/index.tsx +5 -0
  10. package/src/utils/index.tsx +7 -1
  11. package/themes/business/index.tsx +2 -0
  12. package/themes/business/src/components/AcceptOrRejectOrder/index.tsx +265 -240
  13. package/themes/business/src/components/AcceptOrRejectOrder/styles.tsx +6 -4
  14. package/themes/business/src/components/BusinessController/index.tsx +0 -1
  15. package/themes/business/src/components/Chat/index.tsx +118 -107
  16. package/themes/business/src/components/DriverMap/index.tsx +17 -6
  17. package/themes/business/src/components/GoogleMap/index.tsx +58 -57
  18. package/themes/business/src/components/LoginForm/Otp/index.tsx +120 -0
  19. package/themes/business/src/components/LoginForm/Otp/styles.tsx +7 -0
  20. package/themes/business/src/components/LoginForm/index.tsx +238 -80
  21. package/themes/business/src/components/LoginForm/styles.tsx +10 -0
  22. package/themes/business/src/components/MapView/index.tsx +10 -10
  23. package/themes/business/src/components/NewOrderNotification/index.tsx +43 -50
  24. package/themes/business/src/components/OrderDetails/Delivery.tsx +4 -3
  25. package/themes/business/src/components/OrderDetails/OrderContentComponent.tsx +90 -47
  26. package/themes/business/src/components/OrderDetails/OrderHeaderComponent.tsx +59 -62
  27. package/themes/business/src/components/OrderDetailsLogistic/index.tsx +195 -0
  28. package/themes/business/src/components/OrderDetailsLogistic/styles.tsx +5 -0
  29. package/themes/business/src/components/OrderMessage/index.tsx +18 -17
  30. package/themes/business/src/components/OrderSummary/index.tsx +113 -121
  31. package/themes/business/src/components/OrdersOption/index.tsx +32 -75
  32. package/themes/business/src/components/PreviousOrders/OrderItem.tsx +250 -0
  33. package/themes/business/src/components/PreviousOrders/OrdersGroupedItem.tsx +115 -0
  34. package/themes/business/src/components/PreviousOrders/index.tsx +445 -243
  35. package/themes/business/src/components/PreviousOrders/styles.tsx +31 -3
  36. package/themes/business/src/components/ProductItemAccordion/index.tsx +27 -3
  37. package/themes/business/src/components/ReviewCustomer/index.tsx +41 -24
  38. package/themes/business/src/components/StoresList/index.tsx +2 -2
  39. package/themes/business/src/components/shared/OLink.tsx +33 -13
  40. package/themes/business/src/components/shared/OModal.tsx +16 -9
  41. package/themes/business/src/components/shared/OText.tsx +8 -2
  42. package/themes/business/src/types/index.tsx +32 -2
  43. package/themes/business/src/utils/index.tsx +44 -1
  44. package/themes/doordash/src/components/BusinessesListing/index.tsx +1 -1
  45. package/themes/doordash/src/components/LoginForm/index.tsx +1 -2
  46. package/themes/instacart/src/components/BusinessesListing/index.tsx +1 -1
  47. package/themes/kiosk/src/components/BusinessesListing/index.tsx +2 -1
  48. package/themes/kiosk/src/components/Checkout/index.tsx +6 -0
  49. package/themes/kiosk/src/components/LoginForm/Otp/index.tsx +92 -0
  50. package/themes/kiosk/src/components/LoginForm/Otp/styles.tsx +7 -0
  51. package/themes/kiosk/src/components/LoginForm/index.tsx +473 -151
  52. package/themes/kiosk/src/components/LoginForm/styles.tsx +14 -1
  53. package/themes/kiosk/src/components/NavBar/index.tsx +14 -14
  54. package/themes/kiosk/src/components/OptionCard/index.tsx +1 -1
  55. package/themes/kiosk/src/components/OrderTypeCardSelector/index.tsx +8 -10
  56. package/themes/kiosk/src/components/PhoneInputNumber/index.tsx +3 -2
  57. package/themes/kiosk/src/components/PhoneInputNumber/styles.tsx +1 -3
  58. package/themes/kiosk/src/components/ProductForm/index.tsx +1 -14
  59. package/themes/kiosk/src/components/shared/OButton.tsx +5 -18
  60. package/themes/kiosk/src/components/shared/OModal.tsx +14 -11
  61. package/themes/kiosk/src/layouts/Container.tsx +7 -1
  62. package/themes/kiosk/src/types/index.d.ts +13 -0
  63. package/themes/kiosk/src/utils/index.tsx +15 -0
  64. package/themes/original/index.tsx +6 -0
  65. package/themes/original/src/components/AddressDetails/index.tsx +29 -11
  66. package/themes/original/src/components/AddressForm/index.tsx +79 -44
  67. package/themes/original/src/components/AddressList/index.tsx +26 -21
  68. package/themes/original/src/components/AddressList/styles.tsx +4 -2
  69. package/themes/original/src/components/AnalyticsSegment/index.tsx +193 -10
  70. package/themes/original/src/components/AppleLogin/index.tsx +4 -4
  71. package/themes/original/src/components/BusinessBasicInformation/index.tsx +159 -90
  72. package/themes/original/src/components/BusinessBasicInformation/styles.tsx +9 -7
  73. package/themes/original/src/components/BusinessController/index.tsx +154 -68
  74. package/themes/original/src/components/BusinessController/styles.tsx +22 -9
  75. package/themes/original/src/components/BusinessFeaturedController/index.tsx +21 -54
  76. package/themes/original/src/components/BusinessFeaturedController/styles.tsx +8 -0
  77. package/themes/original/src/components/BusinessInformation/index.tsx +10 -31
  78. package/themes/original/src/components/BusinessItemAccordion/index.tsx +23 -22
  79. package/themes/original/src/components/BusinessListingSearch/index.tsx +351 -326
  80. package/themes/original/src/components/BusinessPreorder/index.tsx +97 -16
  81. package/themes/original/src/components/BusinessProductsList/index.tsx +20 -11
  82. package/themes/original/src/components/BusinessProductsList/styles.tsx +8 -3
  83. package/themes/original/src/components/BusinessProductsListing/UpsellingRedirect.tsx +1 -1
  84. package/themes/original/src/components/BusinessProductsListing/index.tsx +684 -524
  85. package/themes/original/src/components/BusinessProductsListing/styles.tsx +4 -6
  86. package/themes/original/src/components/BusinessReviews/index.tsx +3 -1
  87. package/themes/original/src/components/BusinessesListing/Layout/Appointment/index.tsx +1 -1
  88. package/themes/original/src/components/BusinessesListing/Layout/Original/index.tsx +106 -79
  89. package/themes/original/src/components/BusinessesListing/Layout/Original/styles.tsx +1 -9
  90. package/themes/original/src/components/BusinessesListing/index.tsx +0 -1
  91. package/themes/original/src/components/Cart/index.tsx +102 -69
  92. package/themes/original/src/components/CartContent/index.tsx +115 -19
  93. package/themes/original/src/components/CartContent/styles.tsx +17 -7
  94. package/themes/original/src/components/Checkout/index.tsx +375 -179
  95. package/themes/original/src/components/Checkout/styles.tsx +4 -2
  96. package/themes/original/src/components/CitiesControl/index.tsx +89 -0
  97. package/themes/original/src/components/CitiesControl/styles.tsx +17 -0
  98. package/themes/original/src/components/CouponControl/index.tsx +10 -3
  99. package/themes/original/src/components/DriverTips/index.tsx +52 -34
  100. package/themes/original/src/components/Favorite/index.tsx +7 -4
  101. package/themes/original/src/components/Favorite/styles.tsx +1 -1
  102. package/themes/original/src/components/FavoriteList/index.tsx +51 -80
  103. package/themes/original/src/components/FloatingButton/index.tsx +1 -2
  104. package/themes/original/src/components/FloatingButton/styles.tsx +1 -1
  105. package/themes/original/src/components/GPSButton/index.tsx +6 -4
  106. package/themes/original/src/components/GPSButton/styles.ts +3 -3
  107. package/themes/original/src/components/GiftCard/GiftCardUI/index.tsx +96 -0
  108. package/themes/original/src/components/GiftCard/GiftCardUI/styles.tsx +5 -0
  109. package/themes/original/src/components/GiftCard/PurchaseGiftCard/index.tsx +100 -0
  110. package/themes/original/src/components/GiftCard/PurchaseGiftCard/styles.tsx +8 -0
  111. package/themes/original/src/components/GiftCard/RedeemGiftCard/index.tsx +191 -0
  112. package/themes/original/src/components/GiftCard/RedeemGiftCard/styles.tsx +8 -0
  113. package/themes/original/src/components/GiftCard/SendGiftCard/index.tsx +165 -0
  114. package/themes/original/src/components/GiftCard/SendGiftCard/styles.tsx +9 -0
  115. package/themes/original/src/components/GoogleMap/index.tsx +15 -4
  116. package/themes/original/src/components/Help/index.tsx +8 -8
  117. package/themes/original/src/components/HelpAccountAndPayment/index.tsx +11 -22
  118. package/themes/original/src/components/HelpAccountAndPayment/styles.tsx +6 -0
  119. package/themes/original/src/components/HelpGuide/index.tsx +12 -16
  120. package/themes/original/src/components/HelpGuide/styles.tsx +6 -0
  121. package/themes/original/src/components/HelpOrder/index.tsx +12 -25
  122. package/themes/original/src/components/HelpOrder/styles.tsx +8 -1
  123. package/themes/original/src/components/Home/index.tsx +13 -4
  124. package/themes/original/src/components/LastOrder/index.tsx +1 -34
  125. package/themes/original/src/components/LoginForm/Otp/index.tsx +139 -75
  126. package/themes/original/src/components/LoginForm/Otp/styles.tsx +0 -1
  127. package/themes/original/src/components/LoginForm/index.tsx +71 -28
  128. package/themes/original/src/components/LottieAnimation/index.tsx +103 -0
  129. package/themes/original/src/components/MessageListing/index.tsx +16 -42
  130. package/themes/original/src/components/Messages/index.tsx +32 -10
  131. package/themes/original/src/components/MomentOption/index.tsx +195 -88
  132. package/themes/original/src/components/MultiCart/index.tsx +50 -0
  133. package/themes/original/src/components/MultiCartsPaymethodsAndWallets/index.tsx +219 -117
  134. package/themes/original/src/components/MultiCheckout/index.tsx +308 -88
  135. package/themes/original/src/components/MultiCheckout/styles.tsx +3 -1
  136. package/themes/original/src/components/MultiOrdersDetails/SingleOrderCard.tsx +37 -224
  137. package/themes/original/src/components/MultiOrdersDetails/index.tsx +68 -21
  138. package/themes/original/src/components/MultiOrdersDetails/styles.tsx +1 -1
  139. package/themes/original/src/components/MyOrders/index.tsx +53 -51
  140. package/themes/original/src/components/NavBar/index.tsx +18 -18
  141. package/themes/original/src/components/NotFoundSource/index.tsx +14 -10
  142. package/themes/original/src/components/Notifications/index.tsx +46 -50
  143. package/themes/original/src/components/Notifications/styles.tsx +6 -3
  144. package/themes/original/src/components/OrderDetails/OrderEta.tsx +76 -0
  145. package/themes/original/src/components/OrderDetails/OrderHistory.tsx +15 -3
  146. package/themes/original/src/components/OrderDetails/index.tsx +199 -359
  147. package/themes/original/src/components/OrderDetails/styles.tsx +0 -1
  148. package/themes/original/src/components/OrderItAgain/index.tsx +3 -1
  149. package/themes/original/src/components/OrderProgress/index.tsx +93 -114
  150. package/themes/original/src/components/OrderProgress/styles.tsx +5 -0
  151. package/themes/original/src/components/OrderSummary/index.tsx +87 -59
  152. package/themes/original/src/components/OrderTypeSelector/index.tsx +1 -1
  153. package/themes/original/src/components/OrdersOption/PreviousBusinessOrdered/index.tsx +24 -19
  154. package/themes/original/src/components/OrdersOption/PreviousProductsOrdered/index.tsx +14 -14
  155. package/themes/original/src/components/OrdersOption/index.tsx +70 -65
  156. package/themes/original/src/components/OrdersOption/styles.tsx +1 -1
  157. package/themes/original/src/components/PageBanner/index.tsx +171 -0
  158. package/themes/original/src/components/PageBanner/styles.tsx +11 -0
  159. package/themes/original/src/components/PaymentOptionCard/index.tsx +180 -0
  160. package/themes/original/src/components/PaymentOptionStripe/styles.tsx +1 -1
  161. package/themes/original/src/components/PaymentOptionWallet/index.tsx +56 -56
  162. package/themes/original/src/components/PaymentOptions/index.tsx +64 -7
  163. package/themes/original/src/components/PhoneInputNumber/index.tsx +3 -3
  164. package/themes/original/src/components/PlaceSpot/index.tsx +12 -6
  165. package/themes/original/src/components/ProductForm/index.tsx +223 -232
  166. package/themes/original/src/components/ProductForm/styles.tsx +5 -8
  167. package/themes/original/src/components/ProductItemAccordion/index.tsx +29 -28
  168. package/themes/original/src/components/ProductOptionSubOption/index.tsx +19 -11
  169. package/themes/original/src/components/ProductOptionSubOption/styles.tsx +1 -2
  170. package/themes/original/src/components/ProfessionalFilter/SingleProfessionalCard/index.tsx +108 -0
  171. package/themes/original/src/components/ProfessionalFilter/index.tsx +20 -50
  172. package/themes/original/src/components/ProfessionalProfile/index.tsx +36 -7
  173. package/themes/original/src/components/Promotions/index.tsx +234 -220
  174. package/themes/original/src/components/Promotions/styles.tsx +10 -3
  175. package/themes/original/src/components/ReviewDriver/index.tsx +3 -3
  176. package/themes/original/src/components/ReviewOrder/index.tsx +26 -9
  177. package/themes/original/src/components/ReviewOrder/styles.tsx +7 -0
  178. package/themes/original/src/components/ReviewProducts/index.tsx +23 -11
  179. package/themes/original/src/components/ReviewTrigger/index.tsx +27 -9
  180. package/themes/original/src/components/ReviewTrigger/styles.tsx +8 -1
  181. package/themes/original/src/components/ScheduleAccordion/index.tsx +68 -0
  182. package/themes/original/src/components/ScheduleAccordion/styles.tsx +14 -0
  183. package/themes/original/src/components/ServiceForm/index.tsx +74 -19
  184. package/themes/original/src/components/Sessions/index.tsx +11 -8
  185. package/themes/original/src/components/Sessions/styles.tsx +5 -0
  186. package/themes/original/src/components/SignupForm/index.tsx +42 -19
  187. package/themes/original/src/components/SingleOrderCard/index.tsx +156 -65
  188. package/themes/original/src/components/SingleOrderCard/styles.tsx +11 -9
  189. package/themes/original/src/components/SingleProductCard/index.tsx +100 -56
  190. package/themes/original/src/components/SingleProductCard/styles.tsx +22 -13
  191. package/themes/original/src/components/SingleProductReview/styles.tsx +1 -1
  192. package/themes/original/src/components/StripeCardsList/index.tsx +13 -3
  193. package/themes/original/src/components/StripeElementsForm/index.tsx +28 -15
  194. package/themes/original/src/components/UpsellingProducts/index.tsx +238 -224
  195. package/themes/original/src/components/UpsellingProducts/styles.tsx +12 -1
  196. package/themes/original/src/components/UserDetails/index.tsx +8 -4
  197. package/themes/original/src/components/UserFormDetails/index.tsx +47 -7
  198. package/themes/original/src/components/UserProfile/index.tsx +5 -7
  199. package/themes/original/src/components/UserProfileForm/index.tsx +25 -28
  200. package/themes/original/src/components/UserProfileForm/styles.tsx +7 -0
  201. package/themes/original/src/components/WalletTransactionItem/index.tsx +2 -2
  202. package/themes/original/src/components/WalletTransactions/index.tsx +3 -3
  203. package/themes/original/src/components/Wallets/index.tsx +79 -36
  204. package/themes/original/src/components/Wallets/styles.tsx +5 -4
  205. package/themes/original/src/components/shared/CardAnimation.tsx +47 -0
  206. package/themes/original/src/components/shared/HeaderTitle.tsx +8 -3
  207. package/themes/original/src/components/shared/OBottomPopup.tsx +1 -1
  208. package/themes/original/src/components/shared/OButton.tsx +6 -2
  209. package/themes/original/src/components/shared/OInput.tsx +16 -2
  210. package/themes/original/src/components/shared/OModal.tsx +3 -3
  211. package/themes/original/src/layouts/Container.tsx +13 -9
  212. package/themes/original/src/types/index.tsx +38 -9
  213. package/themes/original/src/utils/index.tsx +364 -58
  214. package/themes/uber-eats/src/components/BusinessesListing/index.tsx +1 -1
@@ -1,17 +1,18 @@
1
1
  import React, { useCallback, useEffect, useRef, useState } from 'react'
2
- import { View, TouchableOpacity, StyleSheet, SafeAreaView, Dimensions, Platform, KeyboardAvoidingViewBase, KeyboardAvoidingView } from 'react-native'
2
+ import { View, TouchableOpacity, StyleSheet, SafeAreaView, Dimensions, Platform, KeyboardAvoidingViewBase, KeyboardAvoidingView, Keyboard, KeyboardEvent, BackHandler } from 'react-native'
3
3
  import { IOScrollView } from 'react-native-intersection-observer'
4
4
  import { useSafeAreaInsets } from 'react-native-safe-area-context'
5
5
  import { useTheme } from 'styled-components/native';
6
6
  import {
7
- BusinessAndProductList,
8
- useLanguage,
9
- useOrder,
10
- useSession,
11
- useUtils,
12
- ToastType,
13
- useToast,
14
- useConfig
7
+ BusinessAndProductList,
8
+ useLanguage,
9
+ useOrder,
10
+ useSession,
11
+ useUtils,
12
+ ToastType,
13
+ useToast,
14
+ useConfig,
15
+ useEvent
15
16
  } from 'ordering-components/native'
16
17
  import { Fade, Placeholder, PlaceholderLine } from 'rn-placeholder';
17
18
  import { OButton, OIcon, OModal, OText } from '../shared'
@@ -24,17 +25,18 @@ import { BusinessProductsListingParams } from '../../types'
24
25
  import { _retrieveStoreData, _removeStoreData } from '../../providers/StoreUtil';
25
26
  import IconAntDesign from 'react-native-vector-icons/AntDesign';
26
27
  import { useIsFocused } from '@react-navigation/native';
28
+ import AntDesignIcon from 'react-native-vector-icons/AntDesign'
29
+ import ReactNativeHapticFeedback from "react-native-haptic-feedback";
27
30
 
28
31
  import {
29
- TopHeader,
30
- WrapSearchBar,
31
- WrapContent,
32
- FiltProductsContainer,
33
- ContainerSafeAreaView,
34
- BackgroundGray,
35
- ProfessionalFilterWrapper,
36
- NearBusiness,
37
- TopActions
32
+ TopHeader,
33
+ WrapSearchBar,
34
+ WrapContent,
35
+ FiltProductsContainer,
36
+ BackgroundGray,
37
+ ProfessionalFilterWrapper,
38
+ NearBusiness,
39
+ TopActions
38
40
  } from './styles'
39
41
  import { FloatingButton } from '../FloatingButton'
40
42
  import { UpsellingRedirect } from './UpsellingRedirect'
@@ -42,517 +44,675 @@ import Animated from 'react-native-reanimated'
42
44
  import { ProfessionalFilter } from '../ProfessionalFilter';
43
45
  import { ServiceForm } from '../ServiceForm';
44
46
  import { BusinessesListing } from '../BusinessesListing/Layout/Original'
47
+ import { PageBanner } from '../PageBanner'
45
48
 
46
49
  const PIXELS_TO_SCROLL = 2000
47
50
 
48
51
  const BusinessProductsListingUI = (props: BusinessProductsListingParams) => {
49
- const {
50
- navigation,
51
- errors,
52
- businessState,
53
- categoryState,
54
- handleChangeSearch,
55
- categorySelected,
56
- searchValue,
57
- handleChangeCategory,
58
- handleSearchRedirect,
59
- featuredProducts,
60
- errorQuantityProducts,
61
- header,
62
- logo,
63
- alertState,
64
- setAlertState,
65
- multiRemoveProducts,
66
- getNextProducts,
67
- handleUpdateProducts,
68
- professionalSelected,
69
- handleChangeProfessionalSelected,
70
- onBusinessClick
71
- } = props
72
-
73
- const insets = useSafeAreaInsets()
74
- const theme = useTheme();
75
- const [, t] = useLanguage()
76
- const [{ auth }] = useSession()
77
- const [orderState, { clearCart }] = useOrder()
78
- const [{ parsePrice }] = useUtils()
79
- const [, { showToast }] = useToast()
80
- const [{ configs }] = useConfig()
81
- const isFocused = useIsFocused();
82
- const isPreOrder = configs?.preorder_status_enabled?.value === '1'
83
-
84
- const isChewLayout = theme?.business_view?.components?.header?.components?.layout?.type === 'chew'
85
- const showLogo = !theme?.business_view?.components?.header?.components?.business?.components?.logo?.hidden
86
- const hideBusinessNearCity = theme?.business_view?.components?.near_business?.hidden ?? true
87
-
88
- const styles = StyleSheet.create({
89
- mainContainer: {
90
- flex: 1
91
- },
92
- BackIcon: {
93
- paddingRight: 20,
94
- },
95
- headerItem: {
96
- flexDirection: 'row',
97
- alignItems: 'center',
98
- marginVertical: 2,
99
- marginHorizontal: 20,
100
- },
101
- btnBackArrow: {
102
- borderWidth: 0,
103
- backgroundColor: theme.colors.clear,
104
- shadowColor: theme.colors.clear,
105
- padding: 40,
106
- },
107
- searchIcon: {
108
- borderWidth: 0,
109
- padding: 15,
110
- justifyContent: 'center',
111
- shadowColor: theme.colors.clear,
112
- },
113
- businessSkeleton: {
114
- borderRadius: 8,
115
- marginRight: 20,
116
- width: 56,
117
- height: 56
118
- },
119
- })
120
-
121
- const { business, loading, error } = businessState
122
- const [openBusinessInformation, setOpenBusinessInformation] = useState(false)
123
- const [isOpenSearchBar, setIsOpenSearchBar] = useState(false)
124
- const [openUpselling, setOpenUpselling] = useState(false)
125
- const [canOpenUpselling, setCanOpenUpselling] = useState(false)
126
- const scrollViewRef = useRef<any>(null)
127
- const [categoriesLayout, setCategoriesLayout] = useState<any>({})
128
- const [productListLayout, setProductListLayout] = useState<any>(null)
129
- const [isCategoryClicked, setCategoryClicked] = useState(false)
130
- const [subcategoriesSelected, setSubcategoriesSelected] = useState([])
131
- const [openService, setOpenService] = useState(false)
132
- const [currentProduct, setCurrentProduct] = useState(null)
133
-
134
- const isCheckoutMultiBusinessEnabled: Boolean = configs?.checkout_multi_business_enabled?.value === '1'
135
- const openCarts = (Object.values(orderState?.carts)?.filter((cart: any) => cart?.products && cart?.products?.length && cart?.status !== 2 && cart?.valid_schedule && cart?.valid_products && cart?.valid_address && cart?.valid_maximum && cart?.valid_minimum && !cart?.wallets) || null) || []
136
-
137
- const currentCart: any = Object.values(orderState.carts).find((cart: any) => cart?.business?.slug === business?.slug) ?? {}
138
- const isOpenFiltProducts = isOpenSearchBar && !!searchValue
139
- const filtProductsHeight = Platform.OS === 'ios' ? 0 : 100
140
- const onRedirect = (route: string, params?: any) => {
141
- navigation.navigate(route, params)
142
- }
143
-
144
- const onProductClick = (product: any) => {
145
- const productAddedToCartLength = currentCart?.products?.reduce((productsLength: number, Cproduct: any) => { return productsLength + (Cproduct?.id === product?.id ? Cproduct?.quantity : 0) }, 0) || 0
146
- if (product?.type === 'service' && business?.professionals?.length > 0) {
147
- setCurrentProduct(product)
148
- setOpenService(true)
149
- return
150
- }
151
- onRedirect('ProductDetails', {
152
- product: product,
153
- businessSlug: business.slug,
154
- businessId: business.id,
155
- productAddedToCartLength
156
- })
157
- }
158
-
159
- const handleCancel = () => {
160
- setIsOpenSearchBar(false)
161
- handleChangeSearch('')
162
- }
163
-
164
- const handleUpsellingPage = () => {
165
- if (isCheckoutMultiBusinessEnabled && openCarts.length > 1) {
166
- onRedirect('CheckoutNavigator', {
167
- screen: 'MultiCheckout'
168
- })
169
- } else {
170
- onRedirect('CheckoutNavigator', {
171
- screen: 'CheckoutPage',
172
- cartUuid: currentCart?.uuid,
173
- businessLogo: logo,
174
- businessName: business?.name,
175
- cartTotal: currentCart?.total
176
- })
177
- }
178
- setOpenUpselling(false)
179
- }
180
-
181
- const handleCloseUpsellingPage = () => {
182
- setOpenUpselling(false)
183
- }
184
-
185
- const [selectedCategoryId, setSelectedCategoryId] = useState<any>(null)
186
-
187
- const handlePageScroll = useCallback(({ nativeEvent }: any) => {
188
- const scrollOffset = nativeEvent.contentOffset.y
189
- if (businessState?.business?.lazy_load_products_recommended) {
190
- const height = nativeEvent.contentSize.height
191
- const hasMore = !(categoryState.pagination.totalPages === categoryState.pagination.currentPage)
192
- if (scrollOffset + PIXELS_TO_SCROLL > height && !loading && hasMore && getNextProducts) {
193
- getNextProducts()
194
- showToast(ToastType.Info, t('LOADING_MORE_PRODUCTS', 'Loading more products'))
195
- }
196
- } else {
197
- if (!scrollOffset || !categoriesLayout || !productListLayout || isCategoryClicked) return
198
-
199
- for (const key in categoriesLayout) {
200
- const categoryOffset = categoriesLayout[key].y + productListLayout?.y - 70
201
- if (scrollOffset < 10) {
202
- setSelectedCategoryId('cat_all');
203
- return;
204
- }
205
- if (categoryOffset - 50 <= scrollOffset && scrollOffset <= categoryOffset + 50) {
206
- if (selectedCategoryId !== key) {
207
- setSelectedCategoryId(key)
208
- }
209
- }
210
- }
211
- }
212
- }, [isCategoryClicked, selectedCategoryId, productListLayout])
213
-
214
- const handleTouchDrag = useCallback(() => {
215
- setCategoryClicked(false);
216
- }, []);
217
-
218
- const handleBackNavigation = () => {
219
- navigation?.canGoBack() ? navigation.goBack() : navigation.navigate('BottomTab')
220
- }
221
-
222
- const adjustBusiness = async (adjustBusinessId: number) => {
223
- const _carts = orderState?.carts?.[adjustBusinessId]
224
- const products = _carts?.products
225
- const unavailableProducts = products.filter((product: any) => product.valid !== true)
226
- const alreadyRemoved = await _retrieveStoreData('already-removed')
227
- _removeStoreData('already-removed')
228
- if (unavailableProducts.length > 0) {
229
- multiRemoveProducts && await multiRemoveProducts(unavailableProducts, _carts)
230
- return
231
- }
232
-
233
- if (alreadyRemoved === 'removed') {
234
- setAlertState({ open: true, content: [t('NOT_AVAILABLE_PRODUCT', 'This product is not available.')] })
235
- }
236
- }
237
-
238
- const removeCartByReOrder = async () => {
239
- const adjustBusinessId = await _retrieveStoreData('adjust-cart-products')
240
- if (currentCart && adjustBusinessId) {
241
- _removeStoreData('adjust-cart-products')
242
- adjustBusiness(adjustBusinessId)
243
- }
244
- }
245
-
246
- useEffect(() => {
247
- removeCartByReOrder()
248
- }, [currentCart])
249
-
250
- useEffect(() => {
251
- if (!isFocused) {
252
- handleChangeSearch('')
253
- setIsOpenSearchBar(false)
254
- }
255
- }, [isFocused])
256
-
257
- return (
258
- <>
259
- <View style={{ flex: 1 }}>
260
- <Animated.View style={{ position: 'relative' }}>
261
- <TopHeader
262
- style={{
263
- marginTop: Platform.OS === 'ios' ? insets.top : 0
264
- }}
265
- >
266
- {!isOpenSearchBar && (
267
- <>
268
- <TopActions onPress={() => handleBackNavigation()}>
269
- <IconAntDesign name='arrowleft' size={26} />
270
- </TopActions>
271
- {!errorQuantityProducts && (
272
- <View style={{ ...styles.headerItem }}>
273
- <TouchableOpacity
274
- onPress={() => setIsOpenSearchBar(true)}
275
- style={styles.searchIcon}
276
- >
277
- <OIcon src={theme.images.general.search} color={theme.colors.textNormal} width={16} />
278
- </TouchableOpacity>
279
- </View>
280
- )}
281
- </>
282
- )}
283
- {isOpenSearchBar && (
284
- <WrapSearchBar>
285
- <SearchBar
286
- autoFocus
287
- onSearch={handleChangeSearch}
288
- onCancel={() => handleCancel()}
289
- isCancelXButtonShow
290
- noBorderShow
291
- placeholder={t('SEARCH_PRODUCTS', 'Search Products')}
292
- lazyLoad={businessState?.business?.lazy_load_products_recommended}
293
- />
294
- </WrapSearchBar>
295
- )}
296
- </TopHeader>
297
- {!hideBusinessNearCity && loading && (
298
- <NearBusiness style={{ paddingBottom: 10 }}>
299
- <Placeholder Animation={Fade}>
300
- <View style={{ flexDirection: 'row' }}>
301
- {[...Array(10).keys()].map(i => (
302
- <View style={styles.businessSkeleton} key={i}>
303
- <PlaceholderLine style={{ width: '100%', height: '100%' }} />
304
- </View>
305
- ))}
306
- </View>
307
- </Placeholder>
308
- </NearBusiness>
309
- )}
310
- {!loading && !hideBusinessNearCity && businessState?.business?.city_id && (
311
- <NearBusiness>
312
- <BusinessesListing
313
- logosLayout
314
- propsToFetch={['id', 'logo', 'location', 'timezone', 'schedule', 'open', 'slug']}
315
- cityId={businessState?.business?.city_id}
316
- onBusinessClick={onBusinessClick}
317
- actualSlug={businessState?.business?.slug}
318
- />
319
- </NearBusiness>
320
- )}
321
- </Animated.View>
322
-
323
- {business?.categories?.length > 0 && isOpenFiltProducts && (
324
- <FiltProductsContainer
325
- isIos={Platform.OS === 'ios'}
326
- style={{
327
- height: Dimensions.get('window').height - filtProductsHeight
328
- }}
329
- contentContainerStyle={{ flexGrow: 1 }}
330
- >
331
- <View style={{ padding: 20, backgroundColor: theme.colors.white }}>
332
- <BusinessProductsList
333
- categories={[
334
- { id: null, name: t('ALL', 'All') },
335
- { id: 'featured', name: t('FEATURED', 'Featured') },
336
- ...business?.categories.sort((a: any, b: any) => a.rank - b.rank)
337
- ]}
338
- category={categorySelected}
339
- categoryState={categoryState}
340
- businessId={business.id}
341
- errors={errors}
342
- onProductClick={onProductClick}
343
- handleSearchRedirect={handleSearchRedirect}
344
- featured={featuredProducts}
345
- searchValue={searchValue}
346
- handleClearSearch={handleChangeSearch}
347
- errorQuantityProducts={errorQuantityProducts}
348
- handleCancelSearch={handleCancel}
349
- categoriesLayout={categoriesLayout}
350
- subcategoriesSelected={subcategoriesSelected}
351
- lazyLoadProductsRecommended={business?.lazy_load_products_recommended}
352
- setCategoriesLayout={setCategoriesLayout}
353
- currentCart={currentCart}
354
- setSubcategoriesSelected={setSubcategoriesSelected}
355
- onClickCategory={handleChangeCategory}
356
- handleUpdateProducts={handleUpdateProducts}
357
- previouslyProducts={business?.previously_products}
358
- navigation={navigation}
359
- isFiltMode
360
- />
361
- </View>
362
- </FiltProductsContainer>
363
- )}
364
- {isOpenFiltProducts && (
365
- <BackgroundGray isIos={Platform.OS === 'ios'} />
366
- )}
367
- <IOScrollView
368
- stickyHeaderIndices={[business?.professionals?.length > 0 ? 3 : 2]}
369
- style={{
370
- ...styles.mainContainer,
371
- marginBottom: currentCart?.products?.length > 0 && categoryState.products.length !== 0 ?
372
- 50 : 0
373
- }}
374
- ref={scrollViewRef}
375
- onScroll={handlePageScroll}
376
- onScrollBeginDrag={handleTouchDrag}
377
- scrollEventThrottle={16}
378
- bounces={false}
379
- >
380
- <BusinessBasicInformation
381
- navigation={navigation}
382
- businessState={businessState}
383
- openBusinessInformation={openBusinessInformation}
384
- header={header}
385
- logo={logo}
386
- isPreOrder={isPreOrder}
387
- />
388
- {business?.professionals?.length > 0 && (
389
- <ProfessionalFilterWrapper>
390
- <OText
391
- size={16}
392
- style={{ marginBottom: 16 }}
393
- weight={Platform.OS === 'ios' ? '600' : 'bold'}
394
- >
395
- {t('PROFESSIONALS', 'Professionals')}
396
- </OText>
397
- <ProfessionalFilter
398
- professionals={business?.professionals}
399
- professionalSelected={professionalSelected}
400
- handleChangeProfessionalSelected={handleChangeProfessionalSelected}
401
- />
402
- </ProfessionalFilterWrapper>
403
- )}
404
- <View
405
- style={{
406
- height: 8,
407
- backgroundColor: theme.colors.backgroundGray100,
408
- marginTop: isChewLayout && showLogo ? 10 : 0
409
- }}
410
- />
411
- {!loading && business?.id && !(business?.categories?.length === 0) && (
412
- <BusinessProductsCategories
413
- categories={[{ id: null, name: t('ALL', 'All') }, { id: 'featured', name: t('FEATURED', 'Featured') }, ...business?.categories.sort((a: any, b: any) => a.rank - b.rank)]}
414
- categorySelected={categorySelected}
415
- onClickCategory={handleChangeCategory}
416
- featured={featuredProducts}
417
- openBusinessInformation={openBusinessInformation}
418
- scrollViewRef={scrollViewRef}
419
- productListLayout={productListLayout}
420
- categoriesLayout={categoriesLayout}
421
- selectedCategoryId={selectedCategoryId}
422
- lazyLoadProductsRecommended={business?.lazy_load_products_recommended}
423
- setSelectedCategoryId={setSelectedCategoryId}
424
- setCategoryClicked={setCategoryClicked}
425
- />
426
- )}
427
- {!loading && business?.id && (
428
- <>
429
- <WrapContent
430
- onLayout={(event: any) => setProductListLayout(event.nativeEvent.layout)}
431
- >
432
- <BusinessProductsList
433
- categories={[
434
- { id: null, name: t('ALL', 'All') },
435
- { id: 'featured', name: t('FEATURED', 'Featured') },
436
- ...business?.categories.sort((a: any, b: any) => a.rank - b.rank)
437
- ]}
438
- category={categorySelected}
439
- categoryState={categoryState}
440
- businessId={business.id}
441
- errors={errors}
442
- onProductClick={onProductClick}
443
- handleSearchRedirect={handleSearchRedirect}
444
- featured={featuredProducts}
445
- searchValue={searchValue}
446
- handleClearSearch={handleChangeSearch}
447
- errorQuantityProducts={errorQuantityProducts}
448
- handleCancelSearch={handleCancel}
449
- categoriesLayout={categoriesLayout}
450
- subcategoriesSelected={subcategoriesSelected}
451
- lazyLoadProductsRecommended={business?.lazy_load_products_recommended}
452
- setCategoriesLayout={setCategoriesLayout}
453
- currentCart={currentCart}
454
- setSubcategoriesSelected={setSubcategoriesSelected}
455
- onClickCategory={handleChangeCategory}
456
- handleUpdateProducts={handleUpdateProducts}
457
- navigation={navigation}
458
- previouslyProducts={business?.previously_products}
459
- />
460
- </WrapContent>
461
- </>
462
- )}
463
- {loading && !error && (
464
- <>
465
- <BusinessProductsCategories
466
- categories={[]}
467
- categorySelected={categorySelected}
468
- onClickCategory={handleChangeCategory}
469
- featured={featuredProducts}
470
- openBusinessInformation={openBusinessInformation}
471
- loading={loading}
472
- />
473
- <WrapContent>
474
- <BusinessProductsList
475
- categories={[]}
476
- category={categorySelected}
477
- categoryState={categoryState}
478
- isBusinessLoading={loading}
479
- errorQuantityProducts={errorQuantityProducts}
480
- handleUpdateProducts={handleUpdateProducts}
481
- navigation={navigation}
482
- />
483
- </WrapContent>
484
- </>
485
- )}
486
- </IOScrollView>
487
- {!loading && auth && currentCart?.products?.length > 0 && categoryState.products.length !== 0 && (
488
- <FloatingButton
489
- btnText={
490
- openUpselling
491
- ? t('LOADING', 'Loading')
492
- : currentCart?.subtotal >= currentCart?.minimum
493
- ? t('VIEW_ORDER', 'View Order')
494
- : `${t('MINIMUN_SUBTOTAL_ORDER', 'Minimum subtotal order:')} ${parsePrice(currentCart?.minimum)}`
495
- }
496
- isSecondaryBtn={currentCart?.subtotal < currentCart?.minimum || openUpselling}
497
- btnLeftValueShow={currentCart?.subtotal >= currentCart?.minimum && currentCart?.products?.length > 0}
498
- btnRightValueShow={currentCart?.subtotal >= currentCart?.minimum && currentCart?.products?.length > 0}
499
- btnLeftValue={currentCart?.products.reduce((prev: number, product: any) => prev + product.quantity, 0)}
500
- btnRightValue={parsePrice(currentCart?.total)}
501
- disabled={currentCart?.subtotal < currentCart?.minimum || openUpselling}
502
- handleClick={() => setOpenUpselling(true)}
503
- />
504
- )}
505
- {openUpselling && (
506
- <UpsellingRedirect
507
- businessId={currentCart?.business_id}
508
- business={currentCart?.business}
509
- cartProducts={currentCart?.products}
510
- cart={currentCart}
511
- setOpenUpselling={setOpenUpselling}
512
- handleUpsellingPage={handleUpsellingPage}
513
- handleCloseUpsellingPage={handleCloseUpsellingPage}
514
- openUpselling={openUpselling}
515
- canOpenUpselling={canOpenUpselling}
516
- setCanOpenUpselling={setCanOpenUpselling}
517
- onRedirect={onRedirect}
518
- />
519
- )}
520
- <Alert
521
- open={alertState?.open || false}
522
- title=''
523
- content={[t('NOT_AVAILABLE_PRODUCTS', 'These products are not available.')]}
524
- onAccept={() => setAlertState({ open: false, content: [] })}
525
- onClose={() => setAlertState({ open: false, content: [] })}
526
- />
527
- </View>
528
- <OModal
529
- open={openService}
530
- onClose={() => setOpenService(false)}
531
- entireModal
532
- >
533
- <ServiceForm
534
- navigation={navigation}
535
- product={currentProduct}
536
- businessSlug={business.slug}
537
- businessId={business.id}
538
- professionalList={business?.professionals}
539
- professionalSelected={professionalSelected}
540
- handleChangeProfessional={handleChangeProfessionalSelected}
541
- onSave={() => setOpenService(false)}
542
- onClose={() => setOpenService(false)}
543
- />
544
- </OModal>
545
- </>
546
- )
52
+ const {
53
+ navigation,
54
+ errors,
55
+ businessState,
56
+ categoryState,
57
+ handleChangeSearch,
58
+ categorySelected,
59
+ searchValue,
60
+ handleChangeCategory,
61
+ handleSearchRedirect,
62
+ featuredProducts,
63
+ errorQuantityProducts,
64
+ header,
65
+ logo,
66
+ alertState,
67
+ setAlertState,
68
+ multiRemoveProducts,
69
+ getNextProducts,
70
+ handleUpdateProducts,
71
+ professionalSelected,
72
+ handleUpdateProfessionals,
73
+ handleChangeProfessionalSelected,
74
+ onBusinessClick,
75
+ businessSingleId
76
+ } = props
77
+
78
+ const insets = useSafeAreaInsets()
79
+ const theme = useTheme();
80
+ const [, t] = useLanguage()
81
+ const [{ auth }] = useSession()
82
+ const [orderState, { addProduct, updateProduct }] = useOrder()
83
+ const [{ parsePrice }] = useUtils()
84
+ const [, { showToast }] = useToast()
85
+ const [{ configs }] = useConfig()
86
+ const [events] = useEvent()
87
+ const isFocused = useIsFocused();
88
+ const isPreOrder = configs?.preorder_status_enabled?.value === '1'
89
+
90
+ const isChewLayout = theme?.header?.components?.layout?.type === 'chew'
91
+ const showLogo = !theme?.business_view?.components?.header?.components?.business?.components?.logo?.hidden
92
+ const hideBusinessNearCity = theme?.business_view?.components?.near_business?.hidden ?? true
93
+ const backgroundColor = theme?.business_view?.components?.style?.backgroundColor
94
+ const styles = StyleSheet.create({
95
+ mainContainer: {
96
+ flex: 1
97
+ },
98
+ BackIcon: {
99
+ paddingRight: 20,
100
+ },
101
+ headerItem: {
102
+ flexDirection: 'row',
103
+ alignItems: 'center',
104
+ marginVertical: 2,
105
+ marginHorizontal: 20,
106
+ },
107
+ btnBackArrow: {
108
+ borderWidth: 0,
109
+ backgroundColor: theme.colors.clear,
110
+ shadowColor: theme.colors.clear,
111
+ padding: 40,
112
+ },
113
+ searchIcon: {
114
+ borderWidth: 0,
115
+ padding: 15,
116
+ justifyContent: 'center',
117
+ shadowColor: theme.colors.clear,
118
+ },
119
+ businessSkeleton: {
120
+ borderRadius: 8,
121
+ marginRight: 20,
122
+ width: 56,
123
+ height: 56
124
+ },
125
+ })
126
+
127
+ const { business, loading, error } = businessState
128
+ const [openBusinessInformation, setOpenBusinessInformation] = useState(false)
129
+ const [isOpenSearchBar, setIsOpenSearchBar] = useState(false)
130
+ const [openUpselling, setOpenUpselling] = useState(false)
131
+ const [canOpenUpselling, setCanOpenUpselling] = useState(false)
132
+ const scrollViewRef = useRef<any>(null)
133
+ const [categoriesLayout, setCategoriesLayout] = useState<any>({})
134
+ const [productListLayout, setProductListLayout] = useState<any>(null)
135
+ const [isCategoryClicked, setCategoryClicked] = useState(false)
136
+ const [subcategoriesSelected, setSubcategoriesSelected] = useState([])
137
+ const [openService, setOpenService] = useState(false)
138
+ const [currentProduct, setCurrentProduct] = useState(null)
139
+ const [searchBarHeight, setSearchBarHeight] = useState(60)
140
+ const [keyboardHeight, setKeyboardHeight] = useState(0);
141
+ const [viewedCategory, setViewedCategory] = useState<any>(null)
142
+ const [showTitle, setShowTitle] = useState(false)
143
+
144
+ const isCheckoutMultiBusinessEnabled: Boolean = configs?.checkout_multi_business_enabled?.value === '1'
145
+ const isQuickAddProduct = configs?.add_product_with_one_click?.value === '1'
146
+ const openCarts = (Object.values(orderState?.carts)?.filter((cart: any) => cart?.products && cart?.products?.length && cart?.status !== 2 && cart?.valid_schedule && cart?.valid_products && cart?.valid_address && cart?.valid_maximum && cart?.valid_minimum && !cart?.wallets) || null) || []
147
+ const currentCart: any = Object.values(orderState.carts).find((cart: any) => cart?.business?.slug === business?.slug) ?? {}
148
+ const isOpenFiltProducts = isOpenSearchBar && !!searchValue
149
+ const filtProductsHeight = Platform.OS === 'ios' ? 165 : 100
150
+ const viewOrderButtonVisible = !loading && auth && currentCart?.products?.length > 0 && categoryState.products.length !== 0
151
+
152
+ const onRedirect = (route: string, params?: any) => {
153
+ navigation.navigate(route, params)
154
+ }
155
+ const vibrateApp = (impact?: string) => {
156
+ const options = {
157
+ enableVibrateFallback: true,
158
+ ignoreAndroidSystemSettings: false
159
+ };
160
+ ReactNativeHapticFeedback.trigger(impact || "impactLight", options);
161
+ }
162
+ const onProductClick = async (product: any) => {
163
+ if (product.ingredients?.length === 0 && product.extras.length === 0 && !product.inventoried && auth && isQuickAddProduct) {
164
+ const isProductAddedToCart = currentCart?.products?.find((Cproduct: any) => Cproduct.id === product.id)
165
+ const productQuantity = isProductAddedToCart?.quantity
166
+ const addCurrentProduct = {
167
+ ...product,
168
+ quantity: 1
169
+ }
170
+ const updateCurrentProduct = {
171
+ name: product?.name,
172
+ id: product.id,
173
+ code: isProductAddedToCart?.code,
174
+ quantity: productQuantity + 1
175
+ }
176
+ vibrateApp()
177
+ const cartData = currentCart?.business_id ? currentCart : { business_id: business.id }
178
+ if (isProductAddedToCart) {
179
+ await updateProduct(updateCurrentProduct, cartData, isQuickAddProduct)
180
+ } else {
181
+ await addProduct(addCurrentProduct, cartData, isQuickAddProduct)
182
+ }
183
+ } else {
184
+ const productAddedToCartLength = currentCart?.products?.reduce((productsLength: number, Cproduct: any) => { return productsLength + (Cproduct?.id === product?.id ? Cproduct?.quantity : 0) }, 0) || 0
185
+ if (product?.type === 'service' && business?.professionals?.length > 0) {
186
+ setCurrentProduct(product)
187
+ setOpenService(true)
188
+ return
189
+ }
190
+ onRedirect('ProductDetails', {
191
+ product: product,
192
+ businessSlug: business.slug,
193
+ businessId: business.id,
194
+ productAddedToCartLength
195
+ })
196
+ }
197
+ events.emit('product_clicked', product)
198
+ }
199
+
200
+ const handleCancel = () => {
201
+ setIsOpenSearchBar(false)
202
+ handleChangeSearch('')
203
+ }
204
+
205
+ const handleUpsellingPage = (cart: any) => {
206
+ const isProductCartParam = !!cart?.products?.length
207
+ setOpenUpselling(false)
208
+ setCanOpenUpselling(false)
209
+ const cartsAvailable: any = Object.values(orderState?.carts)
210
+ ?.filter((_cart: any) => _cart?.valid && _cart?.status !== 2 && _cart?.products?.length)
211
+ ?.filter((_c: any) => !isProductCartParam ? _c.uuid !== cart?.uuid : _c)
212
+ if (cartsAvailable.length === 1 || !isCheckoutMultiBusinessEnabled) {
213
+ const cart = isCheckoutMultiBusinessEnabled ? cartsAvailable[0] : currentCart
214
+
215
+ props.onNavigationRedirect('CheckoutNavigator', {
216
+ screen: 'CheckoutPage',
217
+ cartUuid: cart?.uuid,
218
+ businessLogo: cart?.business?.logo,
219
+ businessName: cart?.business?.name,
220
+ cartTotal: cart?.total
221
+ }, true)
222
+ } else {
223
+ const groupKeys: any = {}
224
+ cartsAvailable.forEach((_cart: any) => {
225
+ groupKeys[_cart?.group?.uuid]
226
+ ? groupKeys[_cart?.group?.uuid] += 1
227
+ : groupKeys[_cart?.group?.uuid ?? 'null'] = 1
228
+ })
229
+
230
+ if (
231
+ (Object.keys(groupKeys).length === 1 && Object.keys(groupKeys)[0] === 'null') ||
232
+ Object.keys(groupKeys).length > 1
233
+ ) {
234
+ props.onNavigationRedirect('CheckoutNavigator', {
235
+ screen: 'MultiCheckout',
236
+ checkCarts: true
237
+ }, true)
238
+ } else {
239
+ props.onNavigationRedirect('CheckoutNavigator', {
240
+ screen: 'MultiCheckout',
241
+ cartUuid: cartsAvailable[0]?.group?.uuid
242
+ }, true)
243
+ }
244
+ }
245
+ }
246
+
247
+ const handleCloseUpsellingPage = () => {
248
+ setOpenUpselling(false)
249
+ }
250
+
251
+ const [selectedCategoryId, setSelectedCategoryId] = useState<any>(null)
252
+
253
+ const handlePageScroll = useCallback(({ nativeEvent }: any) => {
254
+ const scrollOffset = nativeEvent.contentOffset.y
255
+ setShowTitle(scrollOffset > 30)
256
+
257
+ if (businessState?.business?.lazy_load_products_recommended) {
258
+ const height = nativeEvent.contentSize.height
259
+ const hasMore = !(categoryState.pagination.totalPages === categoryState.pagination.currentPage)
260
+ if (scrollOffset + PIXELS_TO_SCROLL > height && !loading && hasMore && getNextProducts) {
261
+ getNextProducts()
262
+ showToast(ToastType.Info, t('LOADING_MORE_PRODUCTS', 'Loading more products'))
263
+ }
264
+ } else {
265
+ if (!scrollOffset || !categoriesLayout || !productListLayout || isCategoryClicked) return
266
+
267
+ for (const key in categoriesLayout) {
268
+ const categoryOffset = categoriesLayout[key].y + productListLayout?.y - 70
269
+ if (scrollOffset < 10) {
270
+ setSelectedCategoryId('cat_all');
271
+ return;
272
+ }
273
+ if (categoryOffset - 50 <= scrollOffset && scrollOffset <= categoryOffset + 50) {
274
+ if (selectedCategoryId !== key) {
275
+ setSelectedCategoryId(key)
276
+ }
277
+ }
278
+ }
279
+ }
280
+ }, [isCategoryClicked, selectedCategoryId, productListLayout])
281
+
282
+ const handleTouchDrag = useCallback(() => {
283
+ setCategoryClicked(false);
284
+ }, []);
285
+
286
+ const handleBackNavigation = () => {
287
+ navigation?.canGoBack() ? navigation.goBack() : navigation.navigate('BottomTab')
288
+ }
289
+
290
+ const adjustBusiness = async (adjustBusinessId: number) => {
291
+ const _carts = orderState?.carts?.[adjustBusinessId]
292
+ const products = _carts?.products
293
+ const unavailableProducts = products.filter((product: any) => product.valid !== true)
294
+ const alreadyRemoved = await _retrieveStoreData('already-removed')
295
+ _removeStoreData('already-removed')
296
+ if (unavailableProducts.length > 0) {
297
+ multiRemoveProducts && await multiRemoveProducts(unavailableProducts, _carts)
298
+ return
299
+ }
300
+
301
+ if (alreadyRemoved === 'removed') {
302
+ setAlertState({ open: true, content: [t('NOT_AVAILABLE_PRODUCT', 'This product is not available.')] })
303
+ }
304
+ }
305
+
306
+ const removeCartByReOrder = async () => {
307
+ const adjustBusinessId = await _retrieveStoreData('adjust-cart-products')
308
+ if (currentCart && adjustBusinessId) {
309
+ _removeStoreData('adjust-cart-products')
310
+ adjustBusiness(adjustBusinessId)
311
+ }
312
+ }
313
+
314
+ useEffect(() => {
315
+ removeCartByReOrder()
316
+ }, [currentCart])
317
+
318
+ useEffect(() => {
319
+ if (!isFocused) {
320
+ handleChangeSearch('')
321
+ setIsOpenSearchBar(false)
322
+ }
323
+ }, [isFocused])
324
+
325
+
326
+ useEffect(() => {
327
+ function onKeyboardDidShow(e: KeyboardEvent) {
328
+ setKeyboardHeight(e?.endCoordinates?.height);
329
+ }
330
+
331
+ function onKeyboardDidHide() {
332
+ setKeyboardHeight(0);
333
+ }
334
+
335
+ const showSubscription = Keyboard.addListener('keyboardDidShow', onKeyboardDidShow);
336
+ const hideSubscription = Keyboard.addListener('keyboardDidHide', onKeyboardDidHide);
337
+ return () => {
338
+ showSubscription.remove();
339
+ hideSubscription.remove();
340
+ };
341
+ }, []);
342
+
343
+ const subtotalWithTaxes = currentCart?.taxes?.reduce((acc: any, item: any) => {
344
+ if (item?.type === 1)
345
+ return acc = acc + item?.summary?.tax
346
+ return acc = acc
347
+ }, currentCart?.subtotal)
348
+
349
+ const onChangeSearch = (query: any) => {
350
+ handleChangeSearch(query)
351
+ if (query) {
352
+ events.emit('products_searched', query)
353
+ }
354
+ }
355
+
356
+ useEffect(() => {
357
+ let categoryId: any = null
358
+ if (business?.lazy_load_products_recommended) {
359
+ if (categorySelected?.id) {
360
+ categoryId = categorySelected.id
361
+ }
362
+ } else {
363
+ if (selectedCategoryId) {
364
+ const originCategoryId = selectedCategoryId.replace('cat_', '')
365
+ if (!isNaN(originCategoryId)) {
366
+ categoryId = Number(originCategoryId)
367
+ }
368
+ }
369
+ }
370
+ if (categoryId) {
371
+ const _viewedCategory = business.categories.find(category => category.id === categoryId)
372
+ if (_viewedCategory?.id !== viewedCategory?.id) {
373
+ setViewedCategory(_viewedCategory)
374
+ events.emit('product_list_viewed', _viewedCategory)
375
+ }
376
+ }
377
+ }, [business?.lazy_load_products_recommended, selectedCategoryId, categorySelected?.id, viewedCategory])
378
+
379
+ useEffect(() => {
380
+ const handleArrowBack: any = () => {
381
+ navigation.goBack()
382
+ return true
383
+ }
384
+ BackHandler.addEventListener('hardwareBackPress', handleArrowBack);
385
+ return () => {
386
+ BackHandler.removeEventListener('hardwareBackPress', handleArrowBack);
387
+ }
388
+ }, [])
389
+
390
+ return (
391
+ <>
392
+ <View style={{ flex: 1, backgroundColor: backgroundColor }}>
393
+ <Animated.View style={{ position: 'relative' }}>
394
+ <TopHeader
395
+ style={{
396
+ marginTop: Platform.OS === 'ios' ? insets.top : 0
397
+ }}
398
+ onLayout={(event: any) => setSearchBarHeight(event.nativeEvent.layout.height)}
399
+ hideArrow={(businessSingleId && auth)}
400
+ >
401
+ {!isOpenSearchBar && (
402
+ <>
403
+ {!(businessSingleId && auth) && (
404
+ <TopActions onPress={() => handleBackNavigation()}>
405
+ <AntDesignIcon
406
+ name='arrowleft'
407
+ size={26}
408
+ />
409
+ </TopActions>
410
+ )}
411
+ {showTitle && (
412
+ <OText
413
+ size={16}
414
+ style={{ flex: 1, textAlign: 'center' }}
415
+ weight={Platform.OS === 'ios' ? '600' : 'bold'}
416
+ numberOfLines={2}
417
+ ellipsizeMode='tail'
418
+ >
419
+ {business?.name}
420
+ </OText>
421
+ )}
422
+ {!errorQuantityProducts && (
423
+ <View style={{ ...styles.headerItem }}>
424
+ <TouchableOpacity
425
+ onPress={() => setIsOpenSearchBar(true)}
426
+ style={styles.searchIcon}
427
+ >
428
+ <OIcon src={theme.images.general.search} color={theme.colors.textNormal} width={20} />
429
+ </TouchableOpacity>
430
+ </View>
431
+ )}
432
+ </>
433
+ )}
434
+ {isOpenSearchBar && (
435
+ <WrapSearchBar>
436
+ <SearchBar
437
+ autoFocus
438
+ onSearch={onChangeSearch}
439
+ onCancel={() => handleCancel()}
440
+ isCancelXButtonShow
441
+ noBorderShow
442
+ placeholder={t('SEARCH_PRODUCTS', 'Search Products')}
443
+ lazyLoad
444
+ />
445
+ </WrapSearchBar>
446
+ )}
447
+ </TopHeader>
448
+ {!hideBusinessNearCity && loading && (
449
+ <NearBusiness style={{ paddingBottom: 10 }}>
450
+ <Placeholder Animation={Fade}>
451
+ <View style={{ flexDirection: 'row' }}>
452
+ {[...Array(10).keys()].map(i => (
453
+ <View style={styles.businessSkeleton} key={i}>
454
+ <PlaceholderLine style={{ width: '100%', height: '100%' }} />
455
+ </View>
456
+ ))}
457
+ </View>
458
+ </Placeholder>
459
+ </NearBusiness>
460
+ )}
461
+ {!loading && !hideBusinessNearCity && businessState?.business?.city_id && (
462
+ <NearBusiness>
463
+ <BusinessesListing
464
+ logosLayout
465
+ propsToFetch={['id', 'logo', 'location', 'timezone', 'schedule', 'open', 'slug']}
466
+ cityId={businessState?.business?.city_id}
467
+ onBusinessClick={onBusinessClick}
468
+ actualSlug={businessState?.business?.slug}
469
+ />
470
+ </NearBusiness>
471
+ )}
472
+ </Animated.View>
473
+
474
+ {business?.categories?.length > 0 && isOpenFiltProducts && (
475
+ <FiltProductsContainer
476
+ style={{
477
+ height: Dimensions.get('window').height - filtProductsHeight - keyboardHeight - (keyboardHeight > 0 && viewOrderButtonVisible ? 55 : 0),
478
+ top: Platform.OS === 'ios' ? (searchBarHeight - 10) + insets.top : searchBarHeight,
479
+ }}
480
+ contentContainerStyle={{ flexGrow: 1 }}
481
+ >
482
+ <View style={{ padding: 20, backgroundColor: theme.colors.white }}>
483
+ <BusinessProductsList
484
+ categories={[
485
+ { id: null, name: t('ALL', 'All') },
486
+ { id: 'featured', name: t('FEATURED', 'Featured') },
487
+ ...business?.categories.sort((a: any, b: any) => a.rank - b.rank)
488
+ ]}
489
+ category={categorySelected}
490
+ categoryState={categoryState}
491
+ businessId={business.id}
492
+ errors={errors}
493
+ onProductClick={onProductClick}
494
+ handleSearchRedirect={handleSearchRedirect}
495
+ featured={featuredProducts}
496
+ searchValue={searchValue}
497
+ handleClearSearch={handleChangeSearch}
498
+ errorQuantityProducts={errorQuantityProducts}
499
+ handleCancelSearch={handleCancel}
500
+ categoriesLayout={categoriesLayout}
501
+ subcategoriesSelected={subcategoriesSelected}
502
+ lazyLoadProductsRecommended={business?.lazy_load_products_recommended}
503
+ setCategoriesLayout={setCategoriesLayout}
504
+ currentCart={currentCart}
505
+ setSubcategoriesSelected={setSubcategoriesSelected}
506
+ onClickCategory={handleChangeCategory}
507
+ handleUpdateProducts={handleUpdateProducts}
508
+ previouslyProducts={business?.previously_products}
509
+ navigation={navigation}
510
+ isFiltMode
511
+ businessSingleId={businessSingleId}
512
+ />
513
+ </View>
514
+ </FiltProductsContainer>
515
+ )}
516
+ {isOpenFiltProducts && (
517
+ <BackgroundGray isIos={Platform.OS === 'ios'} />
518
+ )}
519
+ <IOScrollView
520
+ stickyHeaderIndices={[business?.professionals?.length > 0 ? 4 : 3]}
521
+ style={{
522
+ ...styles.mainContainer,
523
+ marginBottom: currentCart?.products?.length > 0 && categoryState.products.length !== 0 ?
524
+ 50 : 0
525
+ }}
526
+ ref={scrollViewRef}
527
+ onScroll={handlePageScroll}
528
+ onScrollBeginDrag={handleTouchDrag}
529
+ scrollEventThrottle={16}
530
+ bounces={false}
531
+ >
532
+ <BusinessBasicInformation
533
+ navigation={navigation}
534
+ businessState={businessState}
535
+ openBusinessInformation={openBusinessInformation}
536
+ header={header}
537
+ logo={logo}
538
+ isPreOrder={isPreOrder}
539
+ />
540
+ {business?.professionals?.length > 0 && (
541
+ <ProfessionalFilterWrapper>
542
+ <OText
543
+ size={16}
544
+ style={{ marginBottom: 16 }}
545
+ weight={Platform.OS === 'ios' ? '600' : 'bold'}
546
+ >
547
+ {t('PROFESSIONALS', 'Professionals')}
548
+ </OText>
549
+ <ProfessionalFilter
550
+ professionals={business?.professionals}
551
+ professionalSelected={professionalSelected}
552
+ handleChangeProfessionalSelected={handleChangeProfessionalSelected}
553
+ handleUpdateProfessionals={handleUpdateProfessionals}
554
+ />
555
+ </ProfessionalFilterWrapper>
556
+ )}
557
+ <PageBanner position='app_business_page' navigation={navigation} />
558
+ <View
559
+ style={{
560
+ height: 8,
561
+ backgroundColor: theme.colors.backgroundGray100,
562
+ marginTop: isChewLayout && showLogo ? 10 : 0
563
+ }}
564
+ />
565
+ {!loading && business?.id && !(business?.categories?.length === 0) && (
566
+ <BusinessProductsCategories
567
+ categories={[{ id: null, name: t('ALL', 'All') }, { id: 'featured', name: t('FEATURED', 'Featured') }, ...business?.categories.sort((a: any, b: any) => a.rank - b.rank)]}
568
+ categorySelected={categorySelected}
569
+ onClickCategory={handleChangeCategory}
570
+ featured={featuredProducts}
571
+ openBusinessInformation={openBusinessInformation}
572
+ scrollViewRef={scrollViewRef}
573
+ productListLayout={productListLayout}
574
+ categoriesLayout={categoriesLayout}
575
+ selectedCategoryId={selectedCategoryId}
576
+ lazyLoadProductsRecommended={business?.lazy_load_products_recommended}
577
+ setSelectedCategoryId={setSelectedCategoryId}
578
+ setCategoryClicked={setCategoryClicked}
579
+ />
580
+ )}
581
+ {!loading && business?.id && (
582
+ <>
583
+ <WrapContent
584
+ onLayout={(event: any) => setProductListLayout(event.nativeEvent.layout)}
585
+ style={{ paddingHorizontal: isChewLayout ? 20 : 40 }}
586
+ >
587
+ <BusinessProductsList
588
+ categories={[
589
+ { id: null, name: t('ALL', 'All') },
590
+ { id: 'featured', name: t('FEATURED', 'Featured') },
591
+ ...business?.categories.sort((a: any, b: any) => a.rank - b.rank)
592
+ ]}
593
+ category={categorySelected}
594
+ categoryState={categoryState}
595
+ businessId={business.id}
596
+ errors={errors}
597
+ onProductClick={onProductClick}
598
+ handleSearchRedirect={handleSearchRedirect}
599
+ featured={featuredProducts}
600
+ searchValue={searchValue}
601
+ handleClearSearch={handleChangeSearch}
602
+ errorQuantityProducts={errorQuantityProducts}
603
+ handleCancelSearch={handleCancel}
604
+ categoriesLayout={categoriesLayout}
605
+ subcategoriesSelected={subcategoriesSelected}
606
+ lazyLoadProductsRecommended={business?.lazy_load_products_recommended}
607
+ setCategoriesLayout={setCategoriesLayout}
608
+ currentCart={currentCart}
609
+ setSubcategoriesSelected={setSubcategoriesSelected}
610
+ onClickCategory={handleChangeCategory}
611
+ handleUpdateProducts={handleUpdateProducts}
612
+ navigation={navigation}
613
+ previouslyProducts={business?.previously_products}
614
+ businessSingleId={businessSingleId}
615
+ />
616
+ </WrapContent>
617
+ </>
618
+ )}
619
+ {loading && !error && (
620
+ <>
621
+ <BusinessProductsCategories
622
+ categories={[]}
623
+ categorySelected={categorySelected}
624
+ onClickCategory={handleChangeCategory}
625
+ featured={featuredProducts}
626
+ openBusinessInformation={openBusinessInformation}
627
+ loading={loading}
628
+ />
629
+ <WrapContent>
630
+ <BusinessProductsList
631
+ categories={[]}
632
+ category={categorySelected}
633
+ categoryState={categoryState}
634
+ isBusinessLoading={loading}
635
+ errorQuantityProducts={errorQuantityProducts}
636
+ handleUpdateProducts={handleUpdateProducts}
637
+ navigation={navigation}
638
+ />
639
+ </WrapContent>
640
+ </>
641
+ )}
642
+ </IOScrollView>
643
+ {viewOrderButtonVisible && (
644
+ <View style={{ marginBottom: 0 }}>
645
+ <FloatingButton
646
+ btnText={
647
+ openUpselling
648
+ ? t('LOADING', 'Loading')
649
+ : subtotalWithTaxes >= currentCart?.minimum
650
+ ? t('VIEW_ORDER', 'View Order')
651
+ : `${t('MINIMUN_SUBTOTAL_ORDER', 'Minimum subtotal order:')} ${parsePrice(currentCart?.minimum)}`
652
+ }
653
+ isSecondaryBtn={subtotalWithTaxes < currentCart?.minimum || openUpselling}
654
+ btnLeftValueShow={subtotalWithTaxes >= currentCart?.minimum && currentCart?.products?.length > 0}
655
+ btnRightValueShow={subtotalWithTaxes >= currentCart?.minimum && currentCart?.products?.length > 0}
656
+ btnLeftValue={currentCart?.products.reduce((prev: number, product: any) => prev + product.quantity, 0)}
657
+ btnRightValue={parsePrice(currentCart?.total)}
658
+ disabled={subtotalWithTaxes < currentCart?.minimum || openUpselling}
659
+ handleClick={() => setOpenUpselling(true)}
660
+ />
661
+ </View>
662
+ )}
663
+ {openUpselling && (
664
+ <UpsellingRedirect
665
+ businessId={currentCart?.business_id}
666
+ business={currentCart?.business}
667
+ cartProducts={currentCart?.products}
668
+ cart={currentCart}
669
+ setOpenUpselling={setOpenUpselling}
670
+ handleUpsellingPage={handleUpsellingPage}
671
+ handleCloseUpsellingPage={handleCloseUpsellingPage}
672
+ openUpselling={openUpselling}
673
+ canOpenUpselling={canOpenUpselling}
674
+ setCanOpenUpselling={setCanOpenUpselling}
675
+ onRedirect={onRedirect}
676
+ />
677
+ )}
678
+ <Alert
679
+ open={alertState?.open || false}
680
+ title=''
681
+ content={[t('NOT_AVAILABLE_PRODUCTS', 'These products are not available.')]}
682
+ onAccept={() => setAlertState({ open: false, content: [] })}
683
+ onClose={() => setAlertState({ open: false, content: [] })}
684
+ />
685
+ </View>
686
+ <OModal
687
+ open={openService}
688
+ onClose={() => setOpenService(false)}
689
+ entireModal
690
+ >
691
+ <ServiceForm
692
+ navigation={navigation}
693
+ product={currentProduct}
694
+ businessSlug={business.slug}
695
+ businessId={business.id}
696
+ professionalList={business?.professionals}
697
+ professionalSelected={professionalSelected}
698
+ handleChangeProfessional={handleChangeProfessionalSelected}
699
+ handleChangeProfessional={handleChangeProfessionalSelected}
700
+ handleUpdateProfessionals={handleUpdateProfessionals}
701
+ onSave={() => setOpenService(false)}
702
+ onClose={() => setOpenService(false)}
703
+ />
704
+ </OModal>
705
+ </>
706
+ )
547
707
  }
548
708
 
549
709
  export const BusinessProductsListing = (props: BusinessProductsListingParams) => {
550
- const businessProductslistingProps = {
551
- ...props,
552
- isForceSearch: Platform.OS === 'ios',
553
- UIComponent: BusinessProductsListingUI
554
- }
555
- return (
556
- <BusinessAndProductList {...businessProductslistingProps} />
557
- )
710
+ const businessProductslistingProps = {
711
+ ...props,
712
+ isForceSearch: Platform.OS === 'ios',
713
+ UIComponent: BusinessProductsListingUI
714
+ }
715
+ return (
716
+ <BusinessAndProductList {...businessProductslistingProps} />
717
+ )
558
718
  }