ordering-ui-react-native 0.17.71 → 0.17.72-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 (201) 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 -24
  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 +35 -21
  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 +103 -39
  29. package/themes/business/src/components/OrderDetails/OrderHeaderComponent.tsx +61 -60
  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 +17 -15
  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 +186 -114
  41. package/themes/business/src/components/PreviousOrders/styles.tsx +1 -1
  42. package/themes/business/src/components/ProductItemAccordion/index.tsx +27 -3
  43. package/themes/business/src/components/ReviewCustomer/index.tsx +18 -13
  44. package/themes/business/src/components/StoresList/index.tsx +3 -4
  45. package/themes/business/src/components/UserProfileForm/index.tsx +14 -15
  46. package/themes/business/src/components/shared/OLink.tsx +11 -3
  47. package/themes/business/src/components/shared/OModal.tsx +16 -9
  48. package/themes/business/src/components/shared/OText.tsx +6 -1
  49. package/themes/business/src/types/index.tsx +25 -10
  50. package/themes/business/src/utils/index.tsx +29 -2
  51. package/themes/doordash/src/components/BusinessesListing/index.tsx +1 -1
  52. package/themes/doordash/src/components/LoginForm/index.tsx +1 -2
  53. package/themes/instacart/src/components/BusinessesListing/index.tsx +1 -1
  54. package/themes/kiosk/src/components/Checkout/index.tsx +6 -0
  55. package/themes/kiosk/src/components/Intro/index.tsx +16 -1
  56. package/themes/kiosk/src/components/LoginForm/index.tsx +7 -9
  57. package/themes/kiosk/src/components/NavBar/index.tsx +14 -14
  58. package/themes/kiosk/src/components/OptionCard/index.tsx +1 -1
  59. package/themes/kiosk/src/components/OrderTypeCardSelector/index.tsx +8 -10
  60. package/themes/kiosk/src/components/PhoneInputNumber/index.tsx +2 -2
  61. package/themes/kiosk/src/components/shared/OButton.tsx +5 -18
  62. package/themes/original/index.tsx +1 -1
  63. package/themes/original/src/components/AddressDetails/index.tsx +19 -3
  64. package/themes/original/src/components/AddressForm/index.tsx +61 -39
  65. package/themes/original/src/components/AddressList/index.tsx +25 -24
  66. package/themes/original/src/components/AddressList/styles.tsx +4 -2
  67. package/themes/original/src/components/AnalyticsSegment/index.tsx +193 -10
  68. package/themes/original/src/components/AppleLogin/index.tsx +4 -4
  69. package/themes/original/src/components/AppleLogin/styles.tsx +3 -1
  70. package/themes/original/src/components/BusinessBasicInformation/index.tsx +153 -96
  71. package/themes/original/src/components/BusinessBasicInformation/styles.tsx +10 -12
  72. package/themes/original/src/components/BusinessController/index.tsx +80 -66
  73. package/themes/original/src/components/BusinessController/styles.tsx +12 -5
  74. package/themes/original/src/components/BusinessFeaturedController/index.tsx +21 -54
  75. package/themes/original/src/components/BusinessFeaturedController/styles.tsx +8 -0
  76. package/themes/original/src/components/BusinessInformation/index.tsx +139 -85
  77. package/themes/original/src/components/BusinessItemAccordion/index.tsx +15 -20
  78. package/themes/original/src/components/BusinessListingSearch/index.tsx +349 -339
  79. package/themes/original/src/components/BusinessListingSearch/styles.tsx +0 -18
  80. package/themes/original/src/components/BusinessPreorder/index.tsx +103 -19
  81. package/themes/original/src/components/BusinessProductsCategories/index.tsx +1 -2
  82. package/themes/original/src/components/BusinessProductsList/index.tsx +15 -7
  83. package/themes/original/src/components/BusinessProductsList/styles.tsx +8 -3
  84. package/themes/original/src/components/BusinessProductsListing/UpsellingRedirect.tsx +1 -1
  85. package/themes/original/src/components/BusinessProductsListing/index.tsx +684 -555
  86. package/themes/original/src/components/BusinessProductsListing/styles.tsx +2 -2
  87. package/themes/original/src/components/BusinessReviews/index.tsx +3 -1
  88. package/themes/original/src/components/BusinessesListing/Layout/Original/index.tsx +69 -38
  89. package/themes/original/src/components/BusinessesListing/Layout/Original/styles.tsx +0 -1
  90. package/themes/original/src/components/BusinessesListing/index.tsx +0 -1
  91. package/themes/original/src/components/Cart/index.tsx +77 -79
  92. package/themes/original/src/components/CartContent/index.tsx +117 -20
  93. package/themes/original/src/components/CartContent/styles.tsx +17 -7
  94. package/themes/original/src/components/Checkout/index.tsx +356 -124
  95. package/themes/original/src/components/CitiesControl/index.tsx +1 -1
  96. package/themes/original/src/components/CouponControl/index.tsx +10 -3
  97. package/themes/original/src/components/DriverTips/index.tsx +52 -34
  98. package/themes/original/src/components/FacebookLogin/styles.tsx +3 -1
  99. package/themes/original/src/components/Favorite/index.tsx +2 -6
  100. package/themes/original/src/components/FavoriteList/index.tsx +1 -35
  101. package/themes/original/src/components/FloatingButton/index.tsx +10 -13
  102. package/themes/original/src/components/GPSButton/index.tsx +6 -4
  103. package/themes/original/src/components/GiftCard/GiftCardUI/index.tsx +96 -0
  104. package/themes/original/src/components/GiftCard/GiftCardUI/styles.tsx +5 -0
  105. package/themes/original/src/components/GiftCard/PurchaseGiftCard/index.tsx +100 -0
  106. package/themes/original/src/components/GiftCard/PurchaseGiftCard/styles.tsx +8 -0
  107. package/themes/original/src/components/GiftCard/RedeemGiftCard/index.tsx +191 -0
  108. package/themes/original/src/components/GiftCard/RedeemGiftCard/styles.tsx +8 -0
  109. package/themes/original/src/components/GiftCard/SendGiftCard/index.tsx +165 -0
  110. package/themes/original/src/components/GiftCard/SendGiftCard/styles.tsx +9 -0
  111. package/themes/original/src/components/GoogleLogin/styles.tsx +1 -1
  112. package/themes/original/src/components/GoogleMap/index.tsx +60 -5
  113. package/themes/original/src/components/Help/index.tsx +2 -2
  114. package/themes/original/src/components/HelpAccountAndPayment/index.tsx +10 -31
  115. package/themes/original/src/components/HelpAccountAndPayment/styles.tsx +5 -3
  116. package/themes/original/src/components/HelpGuide/index.tsx +6 -6
  117. package/themes/original/src/components/HelpGuide/styles.tsx +6 -0
  118. package/themes/original/src/components/HelpOrder/index.tsx +6 -15
  119. package/themes/original/src/components/HelpOrder/styles.tsx +8 -1
  120. package/themes/original/src/components/Home/index.tsx +13 -4
  121. package/themes/original/src/components/LastOrder/index.tsx +1 -34
  122. package/themes/original/src/components/LoginForm/Otp/index.tsx +91 -25
  123. package/themes/original/src/components/LoginForm/index.tsx +64 -34
  124. package/themes/original/src/components/LottieAnimation/index.tsx +88 -63
  125. package/themes/original/src/components/MessageListing/index.tsx +16 -42
  126. package/themes/original/src/components/Messages/index.tsx +14 -7
  127. package/themes/original/src/components/MomentOption/index.tsx +193 -90
  128. package/themes/original/src/components/MomentSelector/index.tsx +1 -1
  129. package/themes/original/src/components/MultiCart/index.tsx +41 -54
  130. package/themes/original/src/components/MultiCartsPaymethodsAndWallets/index.tsx +162 -50
  131. package/themes/original/src/components/MultiCheckout/index.tsx +329 -100
  132. package/themes/original/src/components/MultiCheckout/styles.tsx +3 -1
  133. package/themes/original/src/components/MultiOrdersDetails/SingleOrderCard.tsx +37 -224
  134. package/themes/original/src/components/MultiOrdersDetails/index.tsx +54 -21
  135. package/themes/original/src/components/MultiOrdersDetails/styles.tsx +1 -1
  136. package/themes/original/src/components/MyOrders/index.tsx +40 -29
  137. package/themes/original/src/components/NavBar/index.tsx +20 -17
  138. package/themes/original/src/components/NotFoundSource/index.tsx +14 -10
  139. package/themes/original/src/components/Notifications/index.tsx +42 -52
  140. package/themes/original/src/components/Notifications/styles.tsx +6 -3
  141. package/themes/original/src/components/OrderDetails/OrderEta.tsx +76 -0
  142. package/themes/original/src/components/OrderDetails/OrderHistory.tsx +21 -5
  143. package/themes/original/src/components/OrderDetails/index.tsx +191 -363
  144. package/themes/original/src/components/OrderDetails/styles.tsx +0 -1
  145. package/themes/original/src/components/OrderItAgain/index.tsx +3 -1
  146. package/themes/original/src/components/OrderProgress/index.tsx +30 -56
  147. package/themes/original/src/components/OrderSummary/index.tsx +88 -59
  148. package/themes/original/src/components/OrderTypeSelector/index.tsx +2 -1
  149. package/themes/original/src/components/OrdersOption/PreviousProductsOrdered/index.tsx +14 -14
  150. package/themes/original/src/components/OrdersOption/index.tsx +68 -87
  151. package/themes/original/src/components/OrdersOption/styles.tsx +1 -1
  152. package/themes/original/src/components/PageBanner/index.tsx +98 -38
  153. package/themes/original/src/components/PageBanner/styles.tsx +0 -10
  154. package/themes/original/src/components/PaymentOptionCard/index.tsx +180 -0
  155. package/themes/original/src/components/PaymentOptionStripe/styles.tsx +1 -1
  156. package/themes/original/src/components/PaymentOptionWallet/index.tsx +56 -56
  157. package/themes/original/src/components/PaymentOptions/index.tsx +78 -35
  158. package/themes/original/src/components/PhoneInputNumber/index.tsx +18 -4
  159. package/themes/original/src/components/ProductForm/index.tsx +104 -29
  160. package/themes/original/src/components/ProductForm/styles.tsx +5 -5
  161. package/themes/original/src/components/ProductItemAccordion/index.tsx +12 -9
  162. package/themes/original/src/components/ProductOptionSubOption/index.tsx +20 -18
  163. package/themes/original/src/components/ProductOptionSubOption/styles.tsx +5 -9
  164. package/themes/original/src/components/ProfessionalFilter/SingleProfessionalCard/index.tsx +108 -0
  165. package/themes/original/src/components/ProfessionalFilter/index.tsx +20 -50
  166. package/themes/original/src/components/ProfessionalProfile/index.tsx +36 -7
  167. package/themes/original/src/components/Promotions/index.tsx +2 -2
  168. package/themes/original/src/components/Promotions/styles.tsx +3 -1
  169. package/themes/original/src/components/ReviewProducts/index.tsx +16 -7
  170. package/themes/original/src/components/ScheduleAccordion/index.tsx +3 -3
  171. package/themes/original/src/components/ServiceForm/index.tsx +66 -17
  172. package/themes/original/src/components/Sessions/index.tsx +11 -8
  173. package/themes/original/src/components/Sessions/styles.tsx +5 -0
  174. package/themes/original/src/components/SignupForm/index.tsx +43 -27
  175. package/themes/original/src/components/SingleOrderCard/index.tsx +102 -63
  176. package/themes/original/src/components/SingleOrderCard/styles.tsx +1 -1
  177. package/themes/original/src/components/SingleProductCard/index.tsx +72 -31
  178. package/themes/original/src/components/SingleProductCard/styles.tsx +20 -4
  179. package/themes/original/src/components/SingleProductReview/styles.tsx +1 -1
  180. package/themes/original/src/components/StripeCardsList/index.tsx +49 -5
  181. package/themes/original/src/components/StripeElementsForm/index.tsx +48 -34
  182. package/themes/original/src/components/StripeElementsForm/naked.tsx +12 -1
  183. package/themes/original/src/components/UpsellingProducts/index.tsx +238 -224
  184. package/themes/original/src/components/UpsellingProducts/styles.tsx +12 -1
  185. package/themes/original/src/components/UserDetails/index.tsx +3 -1
  186. package/themes/original/src/components/UserFormDetails/index.tsx +76 -7
  187. package/themes/original/src/components/UserFormDetails/styles.tsx +1 -1
  188. package/themes/original/src/components/UserProfile/index.tsx +88 -79
  189. package/themes/original/src/components/UserProfileForm/index.tsx +17 -21
  190. package/themes/original/src/components/UserProfileForm/styles.tsx +7 -0
  191. package/themes/original/src/components/UserVerification/index.tsx +55 -50
  192. package/themes/original/src/components/WalletTransactionItem/index.tsx +2 -2
  193. package/themes/original/src/components/WalletTransactions/index.tsx +3 -3
  194. package/themes/original/src/components/Wallets/index.tsx +66 -30
  195. package/themes/original/src/components/Wallets/styles.tsx +3 -4
  196. package/themes/original/src/components/shared/OButton.tsx +6 -2
  197. package/themes/original/src/components/shared/OInput.tsx +6 -1
  198. package/themes/original/src/components/shared/OModal.tsx +3 -3
  199. package/themes/original/src/types/index.tsx +41 -11
  200. package/themes/original/src/utils/index.tsx +273 -1
  201. 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,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,545 +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
- 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, { addProduct, updateProduct }] = 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
- const [searchBarHeight, setSearchBarHeight] = useState(60)
134
-
135
- const isCheckoutMultiBusinessEnabled: Boolean = configs?.checkout_multi_business_enabled?.value === '1'
136
- const isQuickAddProduct = configs?.add_product_with_one_click?.value === '1'
137
- 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) || []
138
-
139
- const currentCart: any = Object.values(orderState.carts).find((cart: any) => cart?.business?.slug === business?.slug) ?? {}
140
- const isOpenFiltProducts = isOpenSearchBar && !!searchValue
141
- const filtProductsHeight = Platform.OS === 'ios' ? 0 : 100
142
- const onRedirect = (route: string, params?: any) => {
143
- navigation.navigate(route, params)
144
- }
145
- const onProductClick = async (product: any) => {
146
- if (product.extras.length === 0 && !product.inventoried && auth && isQuickAddProduct) {
147
- const isProductAddedToCart = currentCart?.products?.find((Cproduct: any) => Cproduct.id === product.id)
148
- const productQuantity = isProductAddedToCart?.quantity
149
- const addCurrentProduct = {
150
- ...product,
151
- quantity: 1
152
- }
153
- const updateCurrentProduct = {
154
- id: product.id,
155
- code: isProductAddedToCart?.code,
156
- quantity: productQuantity + 1
157
- }
158
- const cartData = currentCart?.business_id ? currentCart : { business_id: business.id }
159
- if (isProductAddedToCart) {
160
- await updateProduct(updateCurrentProduct, cartData, isQuickAddProduct)
161
- } else {
162
- await addProduct(addCurrentProduct, cartData, isQuickAddProduct)
163
- }
164
- } else {
165
- const productAddedToCartLength = currentCart?.products?.reduce((productsLength: number, Cproduct: any) => { return productsLength + (Cproduct?.id === product?.id ? Cproduct?.quantity : 0) }, 0) || 0
166
- if (product?.type === 'service' && business?.professionals?.length > 0) {
167
- setCurrentProduct(product)
168
- setOpenService(true)
169
- return
170
- }
171
- onRedirect('ProductDetails', {
172
- product: product,
173
- businessSlug: business.slug,
174
- businessId: business.id,
175
- productAddedToCartLength
176
- })
177
- }
178
- }
179
-
180
- const handleCancel = () => {
181
- setIsOpenSearchBar(false)
182
- handleChangeSearch('')
183
- }
184
-
185
- const handleUpsellingPage = () => {
186
- if (isCheckoutMultiBusinessEnabled && openCarts.length > 1) {
187
- onRedirect('CheckoutNavigator', {
188
- screen: 'MultiCheckout'
189
- })
190
- } else {
191
- onRedirect('CheckoutNavigator', {
192
- screen: 'CheckoutPage',
193
- cartUuid: currentCart?.uuid,
194
- businessLogo: logo,
195
- businessName: business?.name,
196
- cartTotal: currentCart?.total
197
- })
198
- }
199
- setOpenUpselling(false)
200
- }
201
-
202
- const handleCloseUpsellingPage = () => {
203
- setOpenUpselling(false)
204
- }
205
-
206
- const [selectedCategoryId, setSelectedCategoryId] = useState<any>(null)
207
-
208
- const handlePageScroll = useCallback(({ nativeEvent }: any) => {
209
- const scrollOffset = nativeEvent.contentOffset.y
210
- if (businessState?.business?.lazy_load_products_recommended) {
211
- const height = nativeEvent.contentSize.height
212
- const hasMore = !(categoryState.pagination.totalPages === categoryState.pagination.currentPage)
213
- if (scrollOffset + PIXELS_TO_SCROLL > height && !loading && hasMore && getNextProducts) {
214
- getNextProducts()
215
- showToast(ToastType.Info, t('LOADING_MORE_PRODUCTS', 'Loading more products'))
216
- }
217
- } else {
218
- if (!scrollOffset || !categoriesLayout || !productListLayout || isCategoryClicked) return
219
-
220
- for (const key in categoriesLayout) {
221
- const categoryOffset = categoriesLayout[key].y + productListLayout?.y - 70
222
- if (scrollOffset < 10) {
223
- setSelectedCategoryId('cat_all');
224
- return;
225
- }
226
- if (categoryOffset - 50 <= scrollOffset && scrollOffset <= categoryOffset + 50) {
227
- if (selectedCategoryId !== key) {
228
- setSelectedCategoryId(key)
229
- }
230
- }
231
- }
232
- }
233
- }, [isCategoryClicked, selectedCategoryId, productListLayout])
234
-
235
- const handleTouchDrag = useCallback(() => {
236
- setCategoryClicked(false);
237
- }, []);
238
-
239
- const handleBackNavigation = () => {
240
- navigation?.canGoBack() ? navigation.goBack() : navigation.navigate('BottomTab')
241
- }
242
-
243
- const adjustBusiness = async (adjustBusinessId: number) => {
244
- const _carts = orderState?.carts?.[adjustBusinessId]
245
- const products = _carts?.products
246
- const unavailableProducts = products.filter((product: any) => product.valid !== true)
247
- const alreadyRemoved = await _retrieveStoreData('already-removed')
248
- _removeStoreData('already-removed')
249
- if (unavailableProducts.length > 0) {
250
- multiRemoveProducts && await multiRemoveProducts(unavailableProducts, _carts)
251
- return
252
- }
253
-
254
- if (alreadyRemoved === 'removed') {
255
- setAlertState({ open: true, content: [t('NOT_AVAILABLE_PRODUCT', 'This product is not available.')] })
256
- }
257
- }
258
-
259
- const removeCartByReOrder = async () => {
260
- const adjustBusinessId = await _retrieveStoreData('adjust-cart-products')
261
- if (currentCart && adjustBusinessId) {
262
- _removeStoreData('adjust-cart-products')
263
- adjustBusiness(adjustBusinessId)
264
- }
265
- }
266
-
267
- useEffect(() => {
268
- removeCartByReOrder()
269
- }, [currentCart])
270
-
271
- useEffect(() => {
272
- if (!isFocused) {
273
- handleChangeSearch('')
274
- setIsOpenSearchBar(false)
275
- }
276
- }, [isFocused])
277
-
278
- const subtotalWithTaxes = currentCart?.taxes?.reduce((acc: any, item: any) => {
279
- if (item?.type === 1)
280
- return acc = acc + item?.summary?.tax
281
- return acc = acc
282
- }, currentCart?.subtotal)
283
-
284
- return (
285
- <>
286
- <View style={{ flex: 1 }}>
287
- <Animated.View style={{ position: 'relative' }}>
288
- <TopHeader
289
- style={{
290
- marginTop: Platform.OS === 'ios' ? insets.top : 0
291
- }}
292
- onLayout={(event: any) => setSearchBarHeight(event.nativeEvent.layout.height)}
293
- >
294
- {!isOpenSearchBar && (
295
- <>
296
- <TopActions onPress={() => handleBackNavigation()}>
297
- <OIcon src={theme.images.general.arrow_left} color={theme.colors.textNormal} />
298
- </TopActions>
299
- {!errorQuantityProducts && (
300
- <View style={{ ...styles.headerItem }}>
301
- <TouchableOpacity
302
- onPress={() => setIsOpenSearchBar(true)}
303
- style={styles.searchIcon}
304
- >
305
- <OIcon src={theme.images.general.search} color={theme.colors.textNormal} width={20} />
306
- </TouchableOpacity>
307
- </View>
308
- )}
309
- </>
310
- )}
311
- {isOpenSearchBar && (
312
- <WrapSearchBar>
313
- <SearchBar
314
- autoFocus
315
- onSearch={handleChangeSearch}
316
- onCancel={() => handleCancel()}
317
- isCancelXButtonShow
318
- noBorderShow
319
- placeholder={t('SEARCH_PRODUCTS', 'Search Products')}
320
- lazyLoad={businessState?.business?.lazy_load_products_recommended}
321
- />
322
- </WrapSearchBar>
323
- )}
324
- </TopHeader>
325
- {!hideBusinessNearCity && loading && (
326
- <NearBusiness style={{ paddingBottom: 10 }}>
327
- <Placeholder Animation={Fade}>
328
- <View style={{ flexDirection: 'row' }}>
329
- {[...Array(10).keys()].map(i => (
330
- <View style={styles.businessSkeleton} key={i}>
331
- <PlaceholderLine style={{ width: '100%', height: '100%' }} />
332
- </View>
333
- ))}
334
- </View>
335
- </Placeholder>
336
- </NearBusiness>
337
- )}
338
- {!loading && !hideBusinessNearCity && businessState?.business?.city_id && (
339
- <NearBusiness>
340
- <BusinessesListing
341
- logosLayout
342
- propsToFetch={['id', 'logo', 'location', 'timezone', 'schedule', 'open', 'slug']}
343
- cityId={businessState?.business?.city_id}
344
- onBusinessClick={onBusinessClick}
345
- actualSlug={businessState?.business?.slug}
346
- />
347
- </NearBusiness>
348
- )}
349
- </Animated.View>
350
-
351
- {business?.categories?.length > 0 && isOpenFiltProducts && (
352
- <FiltProductsContainer
353
- style={{
354
- height: Dimensions.get('window').height - filtProductsHeight,
355
- top: Platform.OS === 'ios' ? (searchBarHeight - 10) + insets.top : searchBarHeight
356
- }}
357
- contentContainerStyle={{ flexGrow: 1 }}
358
- >
359
- <View style={{ padding: 20, backgroundColor: theme.colors.white }}>
360
- <BusinessProductsList
361
- categories={[
362
- { id: null, name: t('ALL', 'All') },
363
- { id: 'featured', name: t('FEATURED', 'Featured') },
364
- ...business?.categories.sort((a: any, b: any) => a.rank - b.rank)
365
- ]}
366
- category={categorySelected}
367
- categoryState={categoryState}
368
- businessId={business.id}
369
- errors={errors}
370
- onProductClick={onProductClick}
371
- handleSearchRedirect={handleSearchRedirect}
372
- featured={featuredProducts}
373
- searchValue={searchValue}
374
- handleClearSearch={handleChangeSearch}
375
- errorQuantityProducts={errorQuantityProducts}
376
- handleCancelSearch={handleCancel}
377
- categoriesLayout={categoriesLayout}
378
- subcategoriesSelected={subcategoriesSelected}
379
- lazyLoadProductsRecommended={business?.lazy_load_products_recommended}
380
- setCategoriesLayout={setCategoriesLayout}
381
- currentCart={currentCart}
382
- setSubcategoriesSelected={setSubcategoriesSelected}
383
- onClickCategory={handleChangeCategory}
384
- handleUpdateProducts={handleUpdateProducts}
385
- previouslyProducts={business?.previously_products}
386
- navigation={navigation}
387
- isFiltMode
388
- />
389
- </View>
390
- </FiltProductsContainer>
391
- )}
392
- {isOpenFiltProducts && (
393
- <BackgroundGray isIos={Platform.OS === 'ios'} />
394
- )}
395
- <IOScrollView
396
- stickyHeaderIndices={[business?.professionals?.length > 0 ? 4 : 3]}
397
- style={{
398
- ...styles.mainContainer,
399
- marginBottom: currentCart?.products?.length > 0 && categoryState.products.length !== 0 ?
400
- 50 : 0
401
- }}
402
- ref={scrollViewRef}
403
- onScroll={handlePageScroll}
404
- onScrollBeginDrag={handleTouchDrag}
405
- scrollEventThrottle={16}
406
- bounces={false}
407
- >
408
- <BusinessBasicInformation
409
- navigation={navigation}
410
- businessState={businessState}
411
- openBusinessInformation={openBusinessInformation}
412
- header={header}
413
- logo={logo}
414
- isPreOrder={isPreOrder}
415
- />
416
- {business?.professionals?.length > 0 && (
417
- <ProfessionalFilterWrapper>
418
- <OText
419
- size={16}
420
- style={{ marginBottom: 16 }}
421
- weight={Platform.OS === 'ios' ? '600' : 'bold'}
422
- >
423
- {t('PROFESSIONALS', 'Professionals')}
424
- </OText>
425
- <ProfessionalFilter
426
- professionals={business?.professionals}
427
- professionalSelected={professionalSelected}
428
- handleChangeProfessionalSelected={handleChangeProfessionalSelected}
429
- />
430
- </ProfessionalFilterWrapper>
431
- )}
432
- <PageBanner position='app_business_page' />
433
- <View
434
- style={{
435
- height: 8,
436
- backgroundColor: theme.colors.backgroundGray100,
437
- marginTop: isChewLayout && showLogo ? 10 : 0
438
- }}
439
- />
440
- {!loading && business?.id && !(business?.categories?.length === 0) && (
441
- <BusinessProductsCategories
442
- categories={[{ id: null, name: t('ALL', 'All') }, { id: 'featured', name: t('FEATURED', 'Featured') }, ...business?.categories.sort((a: any, b: any) => a.rank - b.rank)]}
443
- categorySelected={categorySelected}
444
- onClickCategory={handleChangeCategory}
445
- featured={featuredProducts}
446
- openBusinessInformation={openBusinessInformation}
447
- scrollViewRef={scrollViewRef}
448
- productListLayout={productListLayout}
449
- categoriesLayout={categoriesLayout}
450
- selectedCategoryId={selectedCategoryId}
451
- lazyLoadProductsRecommended={business?.lazy_load_products_recommended}
452
- setSelectedCategoryId={setSelectedCategoryId}
453
- setCategoryClicked={setCategoryClicked}
454
- />
455
- )}
456
- {!loading && business?.id && (
457
- <>
458
- <WrapContent
459
- onLayout={(event: any) => setProductListLayout(event.nativeEvent.layout)}
460
- >
461
- <BusinessProductsList
462
- categories={[
463
- { id: null, name: t('ALL', 'All') },
464
- { id: 'featured', name: t('FEATURED', 'Featured') },
465
- ...business?.categories.sort((a: any, b: any) => a.rank - b.rank)
466
- ]}
467
- category={categorySelected}
468
- categoryState={categoryState}
469
- businessId={business.id}
470
- errors={errors}
471
- onProductClick={onProductClick}
472
- handleSearchRedirect={handleSearchRedirect}
473
- featured={featuredProducts}
474
- searchValue={searchValue}
475
- handleClearSearch={handleChangeSearch}
476
- errorQuantityProducts={errorQuantityProducts}
477
- handleCancelSearch={handleCancel}
478
- categoriesLayout={categoriesLayout}
479
- subcategoriesSelected={subcategoriesSelected}
480
- lazyLoadProductsRecommended={business?.lazy_load_products_recommended}
481
- setCategoriesLayout={setCategoriesLayout}
482
- currentCart={currentCart}
483
- setSubcategoriesSelected={setSubcategoriesSelected}
484
- onClickCategory={handleChangeCategory}
485
- handleUpdateProducts={handleUpdateProducts}
486
- navigation={navigation}
487
- previouslyProducts={business?.previously_products}
488
- />
489
- </WrapContent>
490
- </>
491
- )}
492
- {loading && !error && (
493
- <>
494
- <BusinessProductsCategories
495
- categories={[]}
496
- categorySelected={categorySelected}
497
- onClickCategory={handleChangeCategory}
498
- featured={featuredProducts}
499
- openBusinessInformation={openBusinessInformation}
500
- loading={loading}
501
- />
502
- <WrapContent>
503
- <BusinessProductsList
504
- categories={[]}
505
- category={categorySelected}
506
- categoryState={categoryState}
507
- isBusinessLoading={loading}
508
- errorQuantityProducts={errorQuantityProducts}
509
- handleUpdateProducts={handleUpdateProducts}
510
- navigation={navigation}
511
- />
512
- </WrapContent>
513
- </>
514
- )}
515
- </IOScrollView>
516
- {!loading && auth && currentCart?.products?.length > 0 && categoryState.products.length !== 0 && (
517
- <View style={{ marginBottom: 0, zIndex: 20000 }}>
518
- <FloatingButton
519
- btnText={
520
- openUpselling
521
- ? t('LOADING', 'Loading')
522
- : subtotalWithTaxes >= currentCart?.minimum
523
- ? t('VIEW_ORDER', 'View Order')
524
- : `${t('MINIMUN_SUBTOTAL_ORDER', 'Minimum subtotal order:')} ${parsePrice(currentCart?.minimum)}`
525
- }
526
- isSecondaryBtn={subtotalWithTaxes < currentCart?.minimum || openUpselling}
527
- btnLeftValueShow={subtotalWithTaxes >= currentCart?.minimum && currentCart?.products?.length > 0}
528
- btnRightValueShow={subtotalWithTaxes >= currentCart?.minimum && currentCart?.products?.length > 0}
529
- btnLeftValue={currentCart?.products.reduce((prev: number, product: any) => prev + product.quantity, 0)}
530
- btnRightValue={parsePrice(currentCart?.total)}
531
- disabled={subtotalWithTaxes < currentCart?.minimum || openUpselling}
532
- hideButton={isCheckoutMultiBusinessEnabled}
533
- handleClick={() => setOpenUpselling(true)}
534
- />
535
- </View>
536
- )}
537
- {openUpselling && (
538
- <UpsellingRedirect
539
- businessId={currentCart?.business_id}
540
- business={currentCart?.business}
541
- cartProducts={currentCart?.products}
542
- cart={currentCart}
543
- setOpenUpselling={setOpenUpselling}
544
- handleUpsellingPage={handleUpsellingPage}
545
- handleCloseUpsellingPage={handleCloseUpsellingPage}
546
- openUpselling={openUpselling}
547
- canOpenUpselling={canOpenUpselling}
548
- setCanOpenUpselling={setCanOpenUpselling}
549
- onRedirect={onRedirect}
550
- />
551
- )}
552
- <Alert
553
- open={alertState?.open || false}
554
- title=''
555
- content={[t('NOT_AVAILABLE_PRODUCTS', 'These products are not available.')]}
556
- onAccept={() => setAlertState({ open: false, content: [] })}
557
- onClose={() => setAlertState({ open: false, content: [] })}
558
- />
559
- </View>
560
- <OModal
561
- open={openService}
562
- onClose={() => setOpenService(false)}
563
- entireModal
564
- >
565
- <ServiceForm
566
- navigation={navigation}
567
- product={currentProduct}
568
- businessSlug={business.slug}
569
- businessId={business.id}
570
- professionalList={business?.professionals}
571
- professionalSelected={professionalSelected}
572
- handleChangeProfessional={handleChangeProfessionalSelected}
573
- onSave={() => setOpenService(false)}
574
- onClose={() => setOpenService(false)}
575
- />
576
- </OModal>
577
- </>
578
- )
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
+ )
579
708
  }
580
709
 
581
710
  export const BusinessProductsListing = (props: BusinessProductsListingParams) => {
582
- const businessProductslistingProps = {
583
- ...props,
584
- isForceSearch: Platform.OS === 'ios',
585
- UIComponent: BusinessProductsListingUI
586
- }
587
- return (
588
- <BusinessAndProductList {...businessProductslistingProps} />
589
- )
711
+ const businessProductslistingProps = {
712
+ ...props,
713
+ isForceSearch: Platform.OS === 'ios',
714
+ UIComponent: BusinessProductsListingUI
715
+ }
716
+ return (
717
+ <BusinessAndProductList {...businessProductslistingProps} />
718
+ )
590
719
  }