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