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