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