ordering-ui-react-native 0.15.75 → 0.15.76-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 (221) hide show
  1. package/package.json +7 -3
  2. package/src/DeliveryApp.tsx +43 -1
  3. package/src/components/ActiveOrders/index.tsx +61 -63
  4. package/src/components/ActiveOrders/styles.tsx +1 -1
  5. package/src/components/AddressForm/index.tsx +18 -2
  6. package/src/components/BusinessBasicInformation/index.tsx +11 -19
  7. package/src/components/BusinessController/index.tsx +16 -8
  8. package/src/components/BusinessInformation/index.tsx +14 -0
  9. package/src/components/BusinessTypeFilter/index.tsx +1 -2
  10. package/src/components/BusinessesListing/index.tsx +1 -1
  11. package/src/components/Checkout/index.tsx +25 -3
  12. package/src/components/DriverTips/index.tsx +11 -6
  13. package/src/components/LanguageSelector/index.tsx +6 -2
  14. package/src/components/LoginForm/index.tsx +120 -30
  15. package/src/components/LoginForm/styles.tsx +6 -0
  16. package/src/components/NotificationSetting/index.tsx +85 -0
  17. package/src/components/OrderDetails/index.tsx +7 -21
  18. package/src/components/PaymentOptions/index.tsx +335 -365
  19. package/src/components/PaymentOptionsWebView/index.tsx +120 -121
  20. package/src/components/ReviewDriver/index.tsx +1 -1
  21. package/src/components/ReviewOrder/index.tsx +2 -1
  22. package/src/components/ReviewProducts/index.tsx +11 -0
  23. package/src/components/SignupForm/index.tsx +145 -61
  24. package/src/components/SingleProductCard/index.tsx +16 -4
  25. package/src/components/SingleProductReview/index.tsx +1 -1
  26. package/src/components/StripeElementsForm/index.tsx +25 -16
  27. package/src/components/StripeMethodForm/index.tsx +22 -24
  28. package/src/components/UpsellingProducts/index.tsx +1 -1
  29. package/src/components/UserProfileForm/index.tsx +63 -6
  30. package/src/components/UserProfileForm/styles.tsx +8 -0
  31. package/src/components/VerifyPhone/styles.tsx +1 -2
  32. package/src/components/shared/OBottomPopup.tsx +6 -2
  33. package/src/components/shared/OModal.tsx +1 -1
  34. package/src/hooks/useCountdownTimer.tsx +26 -0
  35. package/src/index.tsx +2 -0
  36. package/src/navigators/CheckoutNavigator.tsx +6 -0
  37. package/src/navigators/HomeNavigator.tsx +12 -0
  38. package/src/pages/BusinessesListing.tsx +7 -6
  39. package/src/pages/MultiCheckout.tsx +31 -0
  40. package/src/pages/MultiOrdersDetails.tsx +27 -0
  41. package/src/pages/OrderDetails.tsx +1 -1
  42. package/src/pages/ReviewDriver.tsx +2 -2
  43. package/src/pages/ReviewOrder.tsx +2 -2
  44. package/src/pages/Sessions.tsx +22 -0
  45. package/src/theme.json +0 -1
  46. package/src/types/index.tsx +18 -11
  47. package/src/utils/index.tsx +68 -2
  48. package/themes/business/index.tsx +4 -0
  49. package/themes/business/src/components/AcceptOrRejectOrder/index.tsx +103 -15
  50. package/themes/business/src/components/AcceptOrRejectOrder/styles.tsx +6 -0
  51. package/themes/business/src/components/Chat/index.tsx +51 -91
  52. package/themes/business/src/components/DriverMap/index.tsx +6 -5
  53. package/themes/business/src/components/DriverSchedule/index.tsx +71 -0
  54. package/themes/business/src/components/DriverSchedule/styles.tsx +6 -0
  55. package/themes/business/src/components/LoginForm/index.tsx +89 -2
  56. package/themes/business/src/components/LoginForm/styles.tsx +6 -0
  57. package/themes/business/src/components/LogoutButton/index.tsx +1 -1
  58. package/themes/business/src/components/NewOrderNotification/index.tsx +26 -13
  59. package/themes/business/src/components/OrderDetails/Business.tsx +1 -1
  60. package/themes/business/src/components/OrderDetails/Delivery.tsx +28 -11
  61. package/themes/business/src/components/OrderDetails/OrderContentComponent.tsx +9 -2
  62. package/themes/business/src/components/OrderDetails/OrderHeaderComponent.tsx +6 -0
  63. package/themes/business/src/components/OrdersListManager/index.tsx +11 -4
  64. package/themes/business/src/components/OrdersOption/index.tsx +16 -4
  65. package/themes/business/src/components/PreviousOrders/index.tsx +7 -7
  66. package/themes/business/src/components/ProductItemAccordion/index.tsx +2 -2
  67. package/themes/business/src/components/ScheduleBlocked/index.tsx +53 -0
  68. package/themes/business/src/components/UserFormDetails/index.tsx +5 -2
  69. package/themes/business/src/components/UserProfileForm/index.tsx +28 -4
  70. package/themes/business/src/components/shared/OModal.tsx +41 -38
  71. package/themes/business/src/types/index.tsx +14 -7
  72. package/themes/doordash/src/components/BusinessesListing/index.tsx +1 -1
  73. package/themes/doordash/src/components/LoginForm/index.tsx +1 -2
  74. package/themes/instacart/src/components/BusinessesListing/index.tsx +1 -1
  75. package/themes/kiosk/src/components/BusinessMenu/index.tsx +39 -28
  76. package/themes/kiosk/src/components/BusinessesListing/index.tsx +2 -3
  77. package/themes/kiosk/src/components/Cart/index.tsx +11 -12
  78. package/themes/kiosk/src/components/CartBottomSheet/index.tsx +9 -2
  79. package/themes/kiosk/src/components/CartContent/index.tsx +0 -11
  80. package/themes/kiosk/src/components/CartItem/index.tsx +4 -3
  81. package/themes/kiosk/src/components/CategoriesMenu/index.tsx +107 -62
  82. package/themes/kiosk/src/components/Checkout/index.tsx +40 -22
  83. package/themes/kiosk/src/components/CustomerName/index.tsx +0 -6
  84. package/themes/kiosk/src/components/DrawerView/index.tsx +1 -0
  85. package/themes/kiosk/src/components/DrawerView/styles.tsx +2 -2
  86. package/themes/kiosk/src/components/NavBar/index.tsx +29 -20
  87. package/themes/kiosk/src/components/OptionCard/index.tsx +1 -1
  88. package/themes/kiosk/src/components/OrderDetails/index.tsx +32 -27
  89. package/themes/kiosk/src/components/OrderTypeCardSelector/index.tsx +9 -11
  90. package/themes/kiosk/src/components/PaymentOptions/index.tsx +56 -54
  91. package/themes/kiosk/src/components/ProductForm/index.tsx +6 -7
  92. package/themes/kiosk/src/components/ProductItemAccordion/index.tsx +2 -2
  93. package/themes/kiosk/src/components/ProductOption/index.tsx +1 -1
  94. package/themes/kiosk/src/components/ProductOptionSubOption/index.tsx +3 -1
  95. package/themes/kiosk/src/components/UpsellingProducts/index.tsx +16 -5
  96. package/themes/kiosk/src/components/shared/OButton.tsx +5 -18
  97. package/themes/kiosk/src/types/index.d.ts +1 -0
  98. package/themes/original/index.tsx +24 -0
  99. package/themes/original/src/components/ActiveOrders/index.tsx +15 -132
  100. package/themes/original/src/components/ActiveOrders/styles.tsx +0 -54
  101. package/themes/original/src/components/AddressForm/index.tsx +7 -6
  102. package/themes/original/src/components/AddressList/index.tsx +2 -2
  103. package/themes/original/src/components/AppleLogin/index.tsx +6 -8
  104. package/themes/original/src/components/BusinessBasicInformation/index.tsx +287 -150
  105. package/themes/original/src/components/BusinessBasicInformation/styles.tsx +6 -2
  106. package/themes/original/src/components/BusinessController/index.tsx +201 -96
  107. package/themes/original/src/components/BusinessController/styles.tsx +5 -0
  108. package/themes/original/src/components/BusinessItemAccordion/index.tsx +8 -5
  109. package/themes/original/src/components/BusinessItemAccordion/styles.tsx +3 -1
  110. package/themes/original/src/components/BusinessListingSearch/index.tsx +234 -64
  111. package/themes/original/src/components/BusinessListingSearch/styles.tsx +22 -2
  112. package/themes/original/src/components/BusinessPreorder/index.tsx +1 -1
  113. package/themes/original/src/components/BusinessProductsCategories/index.tsx +2 -2
  114. package/themes/original/src/components/BusinessProductsList/CategoryDescription/index.tsx +44 -0
  115. package/themes/original/src/components/BusinessProductsList/SubcategoriesComponent/index.tsx +87 -0
  116. package/themes/original/src/components/BusinessProductsList/SubcategoriesComponent/styles.tsx +12 -0
  117. package/themes/original/src/components/BusinessProductsList/index.tsx +65 -73
  118. package/themes/original/src/components/BusinessProductsList/styles.tsx +0 -3
  119. package/themes/original/src/components/BusinessProductsListing/index.tsx +313 -176
  120. package/themes/original/src/components/BusinessProductsListing/styles.tsx +11 -0
  121. package/themes/original/src/components/BusinessReviews/index.tsx +6 -1
  122. package/themes/original/src/components/BusinessTypeFilter/index.tsx +106 -38
  123. package/themes/original/src/components/BusinessTypeFilter/styles.tsx +2 -0
  124. package/themes/original/src/components/BusinessesListing/Layout/Appointment/index.tsx +560 -0
  125. package/themes/original/src/components/BusinessesListing/{styles.tsx → Layout/Appointment/styles.tsx} +24 -2
  126. package/themes/original/src/components/BusinessesListing/Layout/Original/index.tsx +661 -0
  127. package/themes/original/src/components/BusinessesListing/Layout/Original/styles.tsx +137 -0
  128. package/themes/original/src/components/BusinessesListing/index.tsx +104 -462
  129. package/themes/original/src/components/Cart/index.tsx +83 -39
  130. package/themes/original/src/components/Cart/styles.tsx +4 -0
  131. package/themes/original/src/components/Checkout/index.tsx +90 -40
  132. package/themes/original/src/components/Checkout/styles.tsx +0 -1
  133. package/themes/original/src/components/DriverTips/index.tsx +17 -12
  134. package/themes/original/src/components/Favorite/index.tsx +92 -0
  135. package/themes/original/src/components/Favorite/styles.tsx +22 -0
  136. package/themes/original/src/components/FavoriteList/index.tsx +298 -0
  137. package/themes/original/src/components/FavoriteList/styles.tsx +5 -0
  138. package/themes/original/src/components/ForgotPasswordForm/index.tsx +84 -4
  139. package/themes/original/src/components/GPSButton/index.tsx +15 -8
  140. package/themes/original/src/components/GoogleMap/index.tsx +11 -11
  141. package/themes/original/src/components/Help/index.tsx +21 -4
  142. package/themes/original/src/components/HighestRatedBusinesses/index.tsx +18 -1
  143. package/themes/original/src/components/LastOrders/index.tsx +12 -1
  144. package/themes/original/src/components/LoginForm/Otp/index.tsx +91 -0
  145. package/themes/original/src/components/LoginForm/Otp/styles.tsx +7 -0
  146. package/themes/original/src/components/LoginForm/index.tsx +332 -164
  147. package/themes/original/src/components/LoginForm/styles.tsx +1 -3
  148. package/themes/original/src/components/Messages/index.tsx +1 -1
  149. package/themes/original/src/components/MomentSelector/index.tsx +197 -0
  150. package/themes/original/src/components/MomentSelector/styles.tsx +6 -0
  151. package/themes/original/src/components/MultiCartsPaymethodsAndWallets/index.tsx +243 -0
  152. package/themes/original/src/components/MultiCartsPaymethodsAndWallets/styles.tsx +46 -0
  153. package/themes/original/src/components/MultiCheckout/index.tsx +298 -0
  154. package/themes/original/src/components/MultiCheckout/styles.tsx +59 -0
  155. package/themes/original/src/components/MultiOrdersDetails/SingleOrderCard.tsx +372 -0
  156. package/themes/original/src/components/MultiOrdersDetails/index.tsx +258 -0
  157. package/themes/original/src/components/MultiOrdersDetails/styles.tsx +50 -0
  158. package/themes/original/src/components/MyOrders/index.tsx +132 -27
  159. package/themes/original/src/components/MyOrders/styles.tsx +8 -1
  160. package/themes/original/src/components/NavBar/index.tsx +4 -4
  161. package/themes/original/src/components/OrderDetails/OrderHistory.tsx +167 -0
  162. package/themes/original/src/components/OrderDetails/index.tsx +148 -63
  163. package/themes/original/src/components/OrderDetails/styles.tsx +1 -2
  164. package/themes/original/src/components/OrderItAgain/index.tsx +72 -0
  165. package/themes/original/src/components/OrderItAgain/styles.tsx +10 -0
  166. package/themes/original/src/components/OrderSummary/index.tsx +5 -5
  167. package/themes/original/src/components/OrderTypeSelector/index.tsx +77 -35
  168. package/themes/original/src/components/OrderTypeSelector/styles.tsx +19 -1
  169. package/themes/original/src/components/OrdersOption/PreviousBusinessOrdered/index.tsx +153 -0
  170. package/themes/original/src/components/OrdersOption/PreviousBusinessOrdered/styles.tsx +6 -0
  171. package/themes/original/src/components/OrdersOption/PreviousProductsOrdered/index.tsx +53 -0
  172. package/themes/original/src/components/OrdersOption/PreviousProductsOrdered/styles.tsx +6 -0
  173. package/themes/original/src/components/OrdersOption/index.tsx +139 -46
  174. package/themes/original/src/components/OrdersOption/styles.tsx +4 -1
  175. package/themes/original/src/components/PaymentOptionCash/index.tsx +2 -2
  176. package/themes/original/src/components/PaymentOptionWallet/index.tsx +15 -22
  177. package/themes/original/src/components/PaymentOptions/index.tsx +57 -37
  178. package/themes/original/src/components/PhoneInputNumber/index.tsx +5 -11
  179. package/themes/original/src/components/PreviousOrders/index.tsx +18 -147
  180. package/themes/original/src/components/ProductForm/index.tsx +712 -673
  181. package/themes/original/src/components/ProductForm/styles.tsx +9 -7
  182. package/themes/original/src/components/ProductItemAccordion/index.tsx +2 -2
  183. package/themes/original/src/components/ProductOption/index.tsx +1 -1
  184. package/themes/original/src/components/ProductOptionSubOption/index.tsx +13 -9
  185. package/themes/original/src/components/ProfessionalFilter/index.tsx +128 -0
  186. package/themes/original/src/components/ProfessionalFilter/styles.tsx +0 -0
  187. package/themes/original/src/components/ProfessionalProfile/index.tsx +298 -0
  188. package/themes/original/src/components/ProfessionalProfile/styles.tsx +46 -0
  189. package/themes/original/src/components/Promotions/index.tsx +151 -133
  190. package/themes/original/src/components/Promotions/styles.tsx +2 -1
  191. package/themes/original/src/components/ReviewDriver/index.tsx +6 -6
  192. package/themes/original/src/components/ReviewOrder/index.tsx +1 -1
  193. package/themes/original/src/components/ReviewTrigger/index.tsx +118 -0
  194. package/themes/original/src/components/ReviewTrigger/styles.tsx +34 -0
  195. package/themes/original/src/components/SearchBar/index.tsx +13 -5
  196. package/themes/original/src/components/ServiceForm/index.tsx +579 -0
  197. package/themes/original/src/components/ServiceForm/styles.tsx +50 -0
  198. package/themes/original/src/components/Sessions/index.tsx +160 -0
  199. package/themes/original/src/components/Sessions/styles.tsx +15 -0
  200. package/themes/original/src/components/SignupForm/index.tsx +237 -126
  201. package/themes/original/src/components/SingleOrderCard/index.tsx +316 -0
  202. package/themes/original/src/components/SingleOrderCard/styles.tsx +54 -0
  203. package/themes/original/src/components/SingleProductCard/index.tsx +220 -94
  204. package/themes/original/src/components/SingleProductCard/styles.tsx +2 -2
  205. package/themes/original/src/components/StripeElementsForm/index.tsx +25 -9
  206. package/themes/original/src/components/StripeElementsForm/naked.tsx +2 -2
  207. package/themes/original/src/components/UpsellingProducts/index.tsx +2 -6
  208. package/themes/original/src/components/UserDetails/index.tsx +32 -18
  209. package/themes/original/src/components/UserFormDetails/index.tsx +108 -74
  210. package/themes/original/src/components/UserProfile/index.tsx +10 -1
  211. package/themes/original/src/components/UserProfileForm/index.tsx +14 -9
  212. package/themes/original/src/components/UserVerification/index.tsx +178 -192
  213. package/themes/original/src/components/Wallets/index.tsx +2 -2
  214. package/themes/original/src/components/shared/OBottomPopup.tsx +47 -14
  215. package/themes/original/src/components/shared/OButton.tsx +2 -0
  216. package/themes/original/src/components/shared/OInput.tsx +3 -2
  217. package/themes/original/src/components/shared/OModal.tsx +4 -2
  218. package/themes/original/src/layouts/FloatingBottomContainer.tsx +5 -1
  219. package/themes/original/src/types/index.tsx +199 -36
  220. package/themes/original/src/utils/index.tsx +94 -1
  221. package/themes/uber-eats/src/components/BusinessesListing/index.tsx +1 -1
@@ -0,0 +1,661 @@
1
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
2
+ import { Fade, Placeholder, PlaceholderLine } from 'rn-placeholder';
3
+ import Geolocation from '@react-native-community/geolocation'
4
+ import { IOScrollView } from 'react-native-intersection-observer'
5
+ import { getTrackingStatus, requestTrackingPermission } from 'react-native-tracking-transparency'
6
+ import {
7
+ View,
8
+ StyleSheet,
9
+ ScrollView,
10
+ Platform,
11
+ TouchableOpacity,
12
+ RefreshControl,
13
+ AppState
14
+ } from 'react-native';
15
+ import {
16
+ BusinessList as BusinessesListingController,
17
+ useLanguage,
18
+ useSession,
19
+ useOrder,
20
+ useConfig,
21
+ useUtils
22
+ } from 'ordering-components/native';
23
+ import { useTheme } from 'styled-components/native';
24
+ import Ionicons from 'react-native-vector-icons/Ionicons'
25
+
26
+ import {
27
+ Search,
28
+ OrderControlContainer,
29
+ AddressInput,
30
+ WrapMomentOption,
31
+ HeaderWrapper,
32
+ ListWrapper,
33
+ FeaturedWrapper,
34
+ OrderProgressWrapper,
35
+ FarAwayMessage,
36
+ AddressInputContainer,
37
+ PreorderInput,
38
+ OrderTypesContainer,
39
+ BusinessLogosContainer
40
+ } from './styles';
41
+
42
+ import { SearchBar } from '../../../SearchBar';
43
+ import { OButton, OIcon, OText, OBottomPopup, OModal } from '../../../shared';
44
+ import { BusinessesListingParams } from '../../../../types';
45
+ import { NotFoundSource } from '../../../NotFoundSource';
46
+ import { BusinessTypeFilter } from '../../../BusinessTypeFilter';
47
+ import { BusinessController } from '../../../BusinessController';
48
+ import { OrderTypeSelector } from '../../../OrderTypeSelector';
49
+ import { useSafeAreaInsets } from 'react-native-safe-area-context';
50
+ import { BusinessFeaturedController } from '../../../BusinessFeaturedController';
51
+ import { HighestRatedBusinesses } from '../../../HighestRatedBusinesses';
52
+ import { getTypesText, convertToRadian } from '../../../../utils';
53
+ import { OrderProgress } from '../../../OrderProgress';
54
+ import { useFocusEffect, useIsFocused } from '@react-navigation/native';
55
+ import FastImage from 'react-native-fast-image';
56
+
57
+ const PIXELS_TO_SCROLL = 2000;
58
+
59
+ const BusinessesListingUI = (props: BusinessesListingParams) => {
60
+ const {
61
+ navigation,
62
+ businessesList,
63
+ searchValue,
64
+ getBusinesses,
65
+ handleChangeBusinessType,
66
+ handleBusinessClick,
67
+ paginationProps,
68
+ handleChangeSearch,
69
+ businessId,
70
+ isGuestUser,
71
+ handleUpdateBusinessList,
72
+ citiesState,
73
+ actualSlug,
74
+ logosLayout
75
+ } = props;
76
+ const theme = useTheme();
77
+ const isFocused = useIsFocused();
78
+ const appState = useRef(AppState.currentState)
79
+ const searchBarRef = useRef<any>()
80
+ const [appStateVisible, setAppStateVisible] = useState(appState.current);
81
+ const isChewLayout = theme?.header?.components?.layout?.type === 'original'
82
+ const hideCities = theme?.business_listing_view?.components?.cities?.hidden ?? true
83
+ const [refreshing] = useState(false);
84
+ const styles = StyleSheet.create({
85
+ container: {
86
+ marginBottom: 0,
87
+ },
88
+ welcome: {
89
+ flex: 1,
90
+ flexDirection: 'row',
91
+ },
92
+ inputStyle: {
93
+ backgroundColor: theme.colors.inputDisabled,
94
+ flex: 1,
95
+ },
96
+ wrapperOrderOptions: {
97
+ width: '100%',
98
+ flexDirection: 'row',
99
+ justifyContent: 'center',
100
+ marginBottom: 10,
101
+ zIndex: 100,
102
+ },
103
+ borderStyle: {
104
+ borderColor: theme.colors.backgroundGray,
105
+ borderWidth: 1,
106
+ borderRadius: 10,
107
+ },
108
+ searchInput: {
109
+ fontSize: 16,
110
+ backgroundColor: theme.colors.white,
111
+ paddingLeft: 10,
112
+ paddingTop: 7
113
+ },
114
+ iconStyle: {
115
+ fontSize: 18,
116
+ color: theme.colors.warning5,
117
+ marginRight: 8
118
+ },
119
+ farAwayMsg: {
120
+ paddingVertical: 6,
121
+ paddingHorizontal: 20
122
+ },
123
+ inputContainerStyles: {
124
+ backgroundColor: theme.colors.white,
125
+ borderColor: theme.colors.backgroundGray,
126
+ borderWidth: 1,
127
+ },
128
+ buttonCityStyle: {
129
+ backgroundColor: theme.colors.white,
130
+ borderColor: theme.colors.backgroundGray,
131
+ borderRadius: 8,
132
+ marginHorizontal: 40,
133
+ minHeight: 45,
134
+ paddingVertical: 5,
135
+ paddingHorizontal: 20,
136
+ borderWidth: 1
137
+ },
138
+ businessSkeleton: {
139
+ borderRadius: 8,
140
+ marginRight: 20,
141
+ width: 56,
142
+ height: 56
143
+ },
144
+ });
145
+
146
+
147
+ const [, t] = useLanguage();
148
+ const [{ user, auth }] = useSession();
149
+ const [orderState, { changeCityFilter }] = useOrder();
150
+ const [{ configs }] = useConfig();
151
+ const [{ parseDate }] = useUtils();
152
+
153
+ const { top } = useSafeAreaInsets();
154
+
155
+ const [featuredBusiness, setFeaturedBusinesses] = useState(Array);
156
+ const [isFarAway, setIsFarAway] = useState(false)
157
+ const [businessTypes, setBusinessTypes] = useState(null)
158
+ const [orderTypeValue, setOrderTypeValue] = useState(orderState?.options.value)
159
+ const [isOpenCities, setIsOpenCities] = useState(false)
160
+ const isPreorderEnabled = (configs?.preorder_status_enabled?.value === '1' || configs?.preorder_status_enabled?.value === 'true') &&
161
+ Number(configs?.max_days_preorder?.value) > 0
162
+ const isPreOrderSetting = configs?.preorder_status_enabled?.value === '1'
163
+ const timerId = useRef<any>(false)
164
+ const [favoriteIds, setFavoriteIds] = useState<any>([])
165
+ const chewOrderTypes = [{ name: t('DELIVERY', 'Delivery').toUpperCase(), value: 1 }, { name: t('PICKUP', 'Pickup').toUpperCase(), value: 2 }]
166
+
167
+ // const panResponder = useRef(
168
+ // PanResponder.create({
169
+ // onMoveShouldSetPanResponder: (e, gestureState) => {
170
+ // const { dx, dy } = gestureState;
171
+ // resetInactivityTimeout()
172
+ // return (Math.abs(dx) > 20) || (Math.abs(dy) > 20);
173
+ // },
174
+ // })
175
+ // ).current
176
+
177
+ const handleMomentClick = () => {
178
+ if (isPreorderEnabled) {
179
+ navigation.navigate('MomentOption')
180
+ }
181
+ }
182
+
183
+ const configTypes =
184
+ configs?.order_types_allowed?.value
185
+ .split('|')
186
+ .map((value: any) => Number(value)) || [];
187
+
188
+ const handleScroll = ({ nativeEvent }: any) => {
189
+ const y = nativeEvent.contentOffset.y;
190
+ const height = nativeEvent.contentSize.height;
191
+ const hasMore = !(
192
+ paginationProps.totalPages === paginationProps.currentPage
193
+ );
194
+
195
+ if (y + PIXELS_TO_SCROLL > height && !businessesList.loading && hasMore) {
196
+ getBusinesses();
197
+ }
198
+ };
199
+
200
+ const getDistance = (lat1: any, lon1: any, lat2: any, lon2: any) => {
201
+ const R = 6371 // km
202
+ const dLat = convertToRadian(lat2 - lat1)
203
+ const dLon = convertToRadian(lon2 - lon1)
204
+ const curLat1 = convertToRadian(lat1)
205
+ const curLat2 = convertToRadian(lat2)
206
+ const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(curLat1) * Math.cos(curLat2)
207
+ const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
208
+ return R * c
209
+ }
210
+
211
+ const resetInactivityTimeout = () => {
212
+ if (!logosLayout) {
213
+ clearTimeout(timerId.current)
214
+ timerId.current = setInterval(() => {
215
+ getBusinesses(true)
216
+ }, 120000)
217
+ }
218
+ }
219
+
220
+ const handleChangeCity = (cityId: number | null) => {
221
+ changeCityFilter(orderState?.options?.city_id === cityId ? null : cityId)
222
+ setIsOpenCities(false)
223
+ }
224
+
225
+ useEffect(() => {
226
+ if (!businessesList?.loading) {
227
+ const fb = businessesList.businesses.filter((b) => b.featured === true && b?.open);
228
+ const ary = [];
229
+ while (fb.length > 0) {
230
+ ary.push(fb.splice(0, 2));
231
+ }
232
+ setFeaturedBusinesses(ary);
233
+ }
234
+ resetInactivityTimeout()
235
+ }, [businessesList.loading])
236
+
237
+ const handleOnRefresh = () => {
238
+ if (!businessesList.loading) {
239
+ getBusinesses(true);
240
+ }
241
+ }
242
+
243
+ const checkUserLocation = async () => {
244
+ let trackingStatus = await getTrackingStatus()
245
+ if (trackingStatus === 'not-determined') {
246
+ trackingStatus = await requestTrackingPermission()
247
+ }
248
+ if (trackingStatus === 'authorized' || trackingStatus === 'unavailable') {
249
+ Geolocation.getCurrentPosition((pos) => {
250
+ const crd = pos.coords
251
+ const distance = getDistance(crd.latitude, crd.longitude, orderState?.options?.address?.location?.lat, orderState?.options?.address?.location?.lng)
252
+ if (distance > 20) setIsFarAway(true)
253
+ else setIsFarAway(false)
254
+ }, (err) => {
255
+ console.log(`ERROR(${err.code}): ${err.message}`)
256
+ }, {
257
+ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000
258
+ })
259
+ }
260
+ }
261
+
262
+ useEffect(() => {
263
+ if (!logosLayout) {
264
+ checkUserLocation()
265
+ }
266
+ }, [orderState?.options?.address?.location])
267
+
268
+ useEffect(() => {
269
+ if (!orderState?.loading) {
270
+ setOrderTypeValue(orderState?.options?.type)
271
+ }
272
+ }, [orderState?.options?.type])
273
+
274
+ useFocusEffect(
275
+ useCallback(() => {
276
+ resetInactivityTimeout()
277
+ return () => clearTimeout(timerId.current)
278
+ }, [navigation])
279
+ )
280
+
281
+ useEffect(() => {
282
+ if (!businessesList?.businesses?.length) return
283
+ const ids = [...favoriteIds]
284
+ businessesList.businesses.forEach((business: any) => {
285
+ if (business?.favorite) {
286
+ ids.push(business?.id)
287
+ }
288
+ })
289
+ setFavoriteIds([...new Set(ids)])
290
+ }, [businessesList?.businesses?.length])
291
+
292
+ useEffect(() => {
293
+ setIsOpenCities(false)
294
+ }, [orderState?.options?.city_id])
295
+
296
+ if (logosLayout) {
297
+ return (
298
+ <BusinessLogosContainer horizontal>
299
+ {businessesList?.loading ? (
300
+ <Placeholder Animation={Fade}>
301
+ <View style={{ flexDirection: 'row' }}>
302
+ {[...Array(10).keys()].map(i => (
303
+ <View style={styles.businessSkeleton} key={i}>
304
+ <PlaceholderLine style={{ width: '100%', height: '100%' }} />
305
+ </View>
306
+ ))}
307
+ </View>
308
+ </Placeholder>
309
+ ) : (
310
+ <>
311
+ {businessesList.businesses
312
+ ?.filter(business => business?.slug !== actualSlug && business?.open)
313
+ ?.map(business => (
314
+ <TouchableOpacity
315
+ key={business?.id}
316
+ onPress={() => handleBusinessClick && handleBusinessClick(business)}
317
+ >
318
+ <FastImage
319
+ style={{ width: 56, height: 56, marginRight: 20, borderRadius: 7.6 }}
320
+ source={{
321
+ uri: business?.logo,
322
+ priority: FastImage.priority.normal,
323
+ }}
324
+ resizeMode={FastImage.resizeMode.cover}
325
+ />
326
+ </TouchableOpacity>
327
+ ))}
328
+ </>
329
+ )}
330
+ </BusinessLogosContainer>
331
+ )
332
+ }
333
+
334
+ return (
335
+ <IOScrollView style={styles.container} onScroll={(e) => handleScroll(e)} showsVerticalScrollIndicator={false}
336
+ refreshControl={
337
+ <RefreshControl
338
+ refreshing={refreshing}
339
+ onRefresh={() => handleOnRefresh()}
340
+ />
341
+ }
342
+ >
343
+ <View style={{
344
+ height: !isPreOrderSetting && isChewLayout ? 150 : isChewLayout ? 200 : isFarAway ? 150 : 100,
345
+ marginTop: Platform.OS == 'ios' ? 0 : 50,
346
+ backgroundColor: isChewLayout ? theme?.colors?.chew : theme.colors?.white
347
+ }}
348
+ >
349
+ {isChewLayout && (
350
+ <View style={{ marginTop: 30, paddingHorizontal: 30, flexDirection: 'row', justifyContent: 'space-between' }}>
351
+ <OText size={18} weight={700} color={theme.colors?.white}>
352
+ {t('WELCOME', 'Welcome')} {user?.name}!
353
+ </OText>
354
+ </View>
355
+ )}
356
+ <Search isChewLayout={isChewLayout}>
357
+ <AddressInput
358
+ isChewLayout={isChewLayout}
359
+ onPress={() =>
360
+ auth
361
+ ? navigation.navigate('AddressList', { isFromBusinesses: true })
362
+ : navigation.navigate('AddressForm', {
363
+ address: orderState.options?.address,
364
+ isFromBusinesses: true,
365
+ isGuestUser: isGuestUser
366
+ })
367
+ }>
368
+ <AddressInputContainer isChewLayout={isChewLayout}>
369
+ <OIcon
370
+ src={theme.images.general.pin}
371
+ color={theme.colors.disabled}
372
+ width={16}
373
+ style={{ marginRight: isChewLayout ? 0 : 10 }}
374
+ />
375
+ <OText size={12} numberOfLines={1} style={{ flex: 1 }}>
376
+ {orderState?.options?.address?.address}
377
+ </OText>
378
+ {!isChewLayout && (
379
+ <OIcon
380
+ src={theme.images.general.arrow_down}
381
+ width={10}
382
+ style={{ marginStart: 8 }}
383
+ />
384
+ )}
385
+ </AddressInputContainer>
386
+ </AddressInput>
387
+ </Search>
388
+ {isFarAway && !isChewLayout && (
389
+ <FarAwayMessage style={styles.farAwayMsg}>
390
+ <Ionicons name='md-warning-outline' style={styles.iconStyle} />
391
+ <OText size={12} numberOfLines={1} ellipsizeMode={'tail'} color={theme.colors.textNormal}>{t('YOU_ARE_FAR_FROM_ADDRESS', 'You are far from this address')}</OText>
392
+ </FarAwayMessage>
393
+ )}
394
+ {!isChewLayout ? (
395
+ <OrderControlContainer>
396
+ <View style={styles.wrapperOrderOptions}>
397
+ {isPreOrderSetting && (
398
+ <WrapMomentOption
399
+ onPress={() => handleMomentClick()}>
400
+ <OText
401
+ size={12}
402
+ numberOfLines={1}
403
+ ellipsizeMode="tail"
404
+ color={theme.colors.textSecondary}>
405
+ {orderState.options?.moment
406
+ ? parseDate(orderState.options?.moment, { outputFormat: configs?.dates_moment_format?.value })
407
+ : t('ASAP_ABBREVIATION', 'ASAP')}
408
+ </OText>
409
+ {isPreorderEnabled && (
410
+ <OIcon
411
+ src={theme.images.general.arrow_down}
412
+ width={10}
413
+ style={{ marginStart: 8 }}
414
+ />
415
+ )}
416
+ </WrapMomentOption>
417
+ )}
418
+ <WrapMomentOption onPress={() => navigation.navigate('OrderTypes', { configTypes: configTypes, setOrderTypeValue })}>
419
+ <OText size={12} numberOfLines={1} ellipsizeMode={'tail'} color={theme.colors.textSecondary}>{t(getTypesText(orderTypeValue || orderState?.options?.type || 1), 'Delivery')}</OText>
420
+ <OIcon
421
+ src={theme.images.general.arrow_down}
422
+ width={10}
423
+ style={{ marginStart: 8 }}
424
+ />
425
+ </WrapMomentOption>
426
+ </View>
427
+ </OrderControlContainer>
428
+ ) : (
429
+ <>
430
+ {isPreOrderSetting && (
431
+ <View style={{ paddingHorizontal: 30 }}>
432
+ <PreorderInput
433
+ isChewLayout={isChewLayout}
434
+ onPress={() => handleMomentClick()}
435
+ >
436
+ <OText color={theme.colors.textSecondary}>
437
+ {orderState.options?.moment
438
+ ? parseDate(orderState.options?.moment, { outputFormat: configs?.dates_moment_format?.value })
439
+ : t('ASAP_ABBREVIATION', 'ASAP')}</OText>
440
+ </PreorderInput>
441
+ </View>
442
+ )}
443
+ </>
444
+ )}
445
+ </View>
446
+ {!isChewLayout ? (
447
+ <HeaderWrapper
448
+ source={theme.images.backgrounds.business_list_header}
449
+ style={{ paddingTop: top + 20 }}
450
+ resizeMode='cover'
451
+ >
452
+ {!auth && (
453
+ <TouchableOpacity onPress={() => navigation?.canGoBack() && navigation.goBack()} style={{ position: 'absolute', marginStart: 40, paddingVertical: 20 }}>
454
+ <OIcon src={theme.images.general.arrow_left} width={20} style={{ tintColor: theme.colors.white }} />
455
+ </TouchableOpacity>
456
+ )}
457
+ </HeaderWrapper>
458
+ ) : (
459
+ <OrderTypesContainer>
460
+ <OrderTypeSelector
461
+ handleChangeBusinessType={handleChangeBusinessType}
462
+ isChewLayout
463
+ chewOrderTypes={chewOrderTypes}
464
+ />
465
+ </OrderTypesContainer>
466
+ )}
467
+
468
+ {!hideCities && (
469
+ <View style={{ marginTop: 20 }}>
470
+ <TouchableOpacity
471
+ style={styles.buttonCityStyle}
472
+ onPress={() => setIsOpenCities(true)}
473
+ >
474
+ <OText size={18} color={theme.colors.backgroundGray} weight='bold' style={{ textAlign: 'center' }}>
475
+ {citiesState?.cities?.find((city: any) => city?.id === orderState?.options?.city_id)?.name || t('FILTER_BY_CITY', 'Filter by city')}
476
+ </OText>
477
+ </TouchableOpacity>
478
+ </View>
479
+ )}
480
+ <OrderProgressWrapper>
481
+ <OrderProgress
482
+ {...props}
483
+ isFocused={isFocused}
484
+ />
485
+ </OrderProgressWrapper>
486
+ {
487
+ !businessId && !props.franchiseId && featuredBusiness && featuredBusiness.length > 0 && (
488
+ <FeaturedWrapper>
489
+ <OText size={16} style={{ marginLeft: 40 }} weight={Platform.OS === 'ios' ? '600' : 'bold'}>{t('BUSINESS_FEATURE', 'Featured business')}</OText>
490
+ <ScrollView
491
+ showsHorizontalScrollIndicator={false}
492
+ nestedScrollEnabled
493
+ horizontal
494
+ contentContainerStyle={{ paddingHorizontal: 40 }}
495
+ >
496
+ {featuredBusiness.map((bAry: any, idx) => (
497
+ <View key={'f-listing_' + idx}>
498
+ <BusinessFeaturedController
499
+ business={bAry[0]}
500
+ isBusinessOpen={bAry[0]?.open}
501
+ handleCustomClick={handleBusinessClick}
502
+ orderType={orderState?.options?.type}
503
+ />
504
+ {bAry.length > 1 && (
505
+ <BusinessFeaturedController
506
+ business={bAry[1]}
507
+ isBusinessOpen={bAry[1]?.open}
508
+ handleCustomClick={handleBusinessClick}
509
+ orderType={orderState?.options?.type}
510
+ />
511
+ )}
512
+ </View>
513
+ ))}
514
+ </ScrollView>
515
+ </FeaturedWrapper>
516
+ )
517
+ }
518
+ <View style={{ height: 8, backgroundColor: theme.colors.backgroundGray100 }} />
519
+ {
520
+ !businessId && !props.franchiseId && (
521
+ <HighestRatedBusinesses
522
+ onBusinessClick={handleBusinessClick}
523
+ navigation={navigation}
524
+ favoriteIds={favoriteIds}
525
+ setFavoriteIds={setFavoriteIds}
526
+ />
527
+ )
528
+ }
529
+ <View style={{ height: 8, backgroundColor: theme.colors.backgroundGray100 }} />
530
+ <ListWrapper>
531
+ {!businessId && (
532
+ <BusinessTypeFilter
533
+ images={props.images}
534
+ businessTypes={props.businessTypes}
535
+ defaultBusinessType={props.defaultBusinessType}
536
+ handleChangeBusinessType={handleChangeBusinessType}
537
+ setBusinessTypes={setBusinessTypes}
538
+ />
539
+ )}
540
+ {!businessesList.loading && businessesList.businesses.length === 0 && (
541
+ <NotFoundSource
542
+ content={t(
543
+ 'NOT_FOUND_BUSINESSES',
544
+ 'No businesses to delivery / pick up at this address, please change filters or change address.',
545
+ )}
546
+ />
547
+ )}
548
+ {businessesList.businesses?.map(
549
+ (business: any, i: number) => (
550
+ <BusinessController
551
+ key={`${business.id}_` + i}
552
+ enableIntersection
553
+ business={business}
554
+ isBusinessOpen={business.open}
555
+ handleCustomClick={handleBusinessClick}
556
+ orderType={orderState?.options?.type}
557
+ navigation={navigation}
558
+ businessHeader={business?.header}
559
+ businessFeatured={business?.featured}
560
+ businessLogo={business?.logo}
561
+ businessReviews={business?.reviews}
562
+ businessDeliveryPrice={business?.delivery_price}
563
+ businessDeliveryTime={business?.delivery_time}
564
+ businessPickupTime={business?.pickup_time}
565
+ businessDistance={business?.distance}
566
+ handleUpdateBusinessList={handleUpdateBusinessList}
567
+ favoriteIds={favoriteIds}
568
+ setFavoriteIds={setFavoriteIds}
569
+ />
570
+ )
571
+ )}
572
+ {businessesList.loading && (
573
+ <>
574
+ {[
575
+ ...Array(
576
+ paginationProps.nextPageItems
577
+ ? paginationProps.nextPageItems
578
+ : 8,
579
+ ).keys(),
580
+ ].map((item, i) => (
581
+ <Placeholder
582
+ Animation={Fade}
583
+ key={i}
584
+ style={{ marginBottom: 20 }}>
585
+ <View style={{ width: '100%' }}>
586
+ <PlaceholderLine
587
+ height={200}
588
+ style={{ marginBottom: 20, borderRadius: 25 }}
589
+ />
590
+ <View style={{ paddingHorizontal: 10 }}>
591
+ <View
592
+ style={{
593
+ flexDirection: 'row',
594
+ justifyContent: 'space-between',
595
+ }}>
596
+ <PlaceholderLine
597
+ height={25}
598
+ width={40}
599
+ style={{ marginBottom: 10 }}
600
+ />
601
+ <PlaceholderLine
602
+ height={25}
603
+ width={20}
604
+ style={{ marginBottom: 10 }}
605
+ />
606
+ </View>
607
+ <PlaceholderLine
608
+ height={20}
609
+ width={30}
610
+ style={{ marginBottom: 10 }}
611
+ />
612
+ <PlaceholderLine
613
+ height={20}
614
+ width={80}
615
+ style={{ marginBottom: 10 }}
616
+ />
617
+ </View>
618
+ </View>
619
+ </Placeholder>
620
+ ))}
621
+ </>
622
+ )}
623
+ </ListWrapper>
624
+ <OModal
625
+ open={isOpenCities}
626
+ onClose={() => setIsOpenCities(false)}
627
+ title={t('SELECT_A_CITY', 'Select a city')}
628
+ >
629
+ <View style={{ padding: 40, width: '100%' }}>
630
+ {citiesState?.cities?.map((city: any) => (
631
+ <TouchableOpacity
632
+ key={city?.id}
633
+ style={{
634
+ padding: 10,
635
+ borderBottomWidth: 1,
636
+ borderBottomColor: orderState?.options?.city_id === city?.id ? theme.colors.primary : theme.colors.backgroundGray,
637
+ marginBottom: 10,
638
+ }}
639
+ onPress={() => handleChangeCity(city?.id)}
640
+ disabled={orderState?.loading}
641
+ >
642
+ <OText color={orderState?.options?.city_id === city?.id ? theme.colors.primary : theme.colors.black}>
643
+ {city?.name}
644
+ </OText>
645
+ </TouchableOpacity>
646
+ ))}
647
+ </View>
648
+ </OModal>
649
+ </IOScrollView>
650
+ );
651
+ };
652
+
653
+ export const BusinessesListing = (props: BusinessesListingParams) => {
654
+ const BusinessesListingProps = {
655
+ ...props,
656
+ isForceSearch: Platform.OS === 'ios',
657
+ UIComponent: BusinessesListingUI,
658
+ };
659
+
660
+ return <BusinessesListingController {...BusinessesListingProps} />;
661
+ };