ordering-ui-react-native 0.12.77 → 0.12.81

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 (30) hide show
  1. package/package.json +1 -1
  2. package/src/components/BusinessesListing/index.tsx +35 -3
  3. package/src/components/BusinessesListing/styles.tsx +10 -0
  4. package/src/components/Checkout/index.tsx +77 -8
  5. package/src/components/Messages/index.tsx +3 -3
  6. package/src/components/PaymentOptions/index.tsx +2 -2
  7. package/src/theme.json +3 -1
  8. package/src/utils/index.tsx +27 -0
  9. package/themes/doordash/src/components/BusinessesListing/index.tsx +33 -1
  10. package/themes/doordash/src/components/BusinessesListing/styles.tsx +11 -1
  11. package/themes/doordash/src/utils/index.tsx +27 -0
  12. package/themes/instacart/src/components/BusinessesListing/index.tsx +35 -3
  13. package/themes/instacart/src/components/BusinessesListing/styles.tsx +11 -1
  14. package/themes/instacart/src/utils/index.tsx +27 -0
  15. package/themes/original/index.tsx +2 -0
  16. package/themes/original/src/components/ActiveOrders/index.tsx +36 -16
  17. package/themes/original/src/components/ActiveOrders/styles.tsx +10 -0
  18. package/themes/original/src/components/MessageListing/index.tsx +298 -0
  19. package/themes/original/src/components/MessageListing/styles.tsx +16 -0
  20. package/themes/original/src/components/Messages/index.tsx +123 -81
  21. package/themes/original/src/components/Messages/styles.tsx +8 -0
  22. package/themes/original/src/components/UserProfile/index.tsx +10 -0
  23. package/themes/original/src/types/index.tsx +11 -3
  24. package/themes/original/src/utils/index.tsx +18 -0
  25. package/themes/single-business/src/components/BusinessesListing/index.tsx +33 -0
  26. package/themes/single-business/src/components/BusinessesListing/styles.tsx +9 -0
  27. package/themes/single-business/src/utils/index.tsx +27 -0
  28. package/themes/uber-eats/src/components/BusinessesListing/index.tsx +36 -3
  29. package/themes/uber-eats/src/components/BusinessesListing/styles.tsx +8 -0
  30. package/themes/uber-eats/src/utils/index.tsx +27 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ordering-ui-react-native",
3
- "version": "0.12.77",
3
+ "version": "0.12.81",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -1,6 +1,7 @@
1
- import React, {useEffect} from 'react'
1
+ import React, { useEffect, useState} from 'react'
2
2
  import { Fade, Placeholder, PlaceholderLine } from 'rn-placeholder'
3
3
  import { View, StyleSheet, ScrollView, Platform, PanResponder, I18nManager } from 'react-native'
4
+ import Geolocation from '@react-native-community/geolocation'
4
5
  import MaterialComIcon from 'react-native-vector-icons/MaterialCommunityIcons'
5
6
  import {
6
7
  BusinessList as BusinessesListingController,
@@ -13,7 +14,7 @@ import {
13
14
  useToast
14
15
  } from 'ordering-components/native'
15
16
 
16
- import { WelcomeTitle, Search, OrderControlContainer, AddressInput, WrapMomentOption } from './styles'
17
+ import { WelcomeTitle, Search, OrderControlContainer, AddressInput, WrapMomentOption, FarAwayMessage } from './styles'
17
18
 
18
19
  import NavBar from '../NavBar'
19
20
  import { SearchBar } from '../SearchBar'
@@ -24,6 +25,8 @@ import { BusinessTypeFilter } from '../BusinessTypeFilter'
24
25
  import { BusinessController } from '../BusinessController'
25
26
  import { OrderTypeSelector } from '../OrderTypeSelector'
26
27
  import { useTheme } from 'styled-components/native'
28
+ import { getDistance } from '../../utils'
29
+ import Ionicons from 'react-native-vector-icons/Ionicons'
27
30
 
28
31
  const PIXELS_TO_SCROLL = 1200
29
32
 
@@ -68,7 +71,16 @@ const BusinessesListingUI = (props: BusinessesListingParams) => {
68
71
  borderColor: theme.colors.backgroundGray,
69
72
  borderWidth: 1,
70
73
  borderRadius: 10,
71
- }
74
+ },
75
+ iconStyle: {
76
+ fontSize: 18,
77
+ color: theme.colors.warning5,
78
+ marginRight: 8
79
+ },
80
+ farAwayMsg: {
81
+ paddingVertical: 6,
82
+ paddingHorizontal: 20
83
+ }
72
84
  })
73
85
 
74
86
  const [, t] = useLanguage()
@@ -79,6 +91,7 @@ const BusinessesListingUI = (props: BusinessesListingParams) => {
79
91
  const [, {showToast}] = useToast()
80
92
  const configTypes = configs?.order_types_allowed?.value.split('|').map((value: any) => Number(value)) || []
81
93
  const isPreOrderSetting = configs?.preorder_status_enabled?.value === '1'
94
+ const [isFarAway, setIsFarAway] = useState(false)
82
95
 
83
96
  const handleScroll = ({ nativeEvent }: any) => {
84
97
  const y = nativeEvent.contentOffset.y
@@ -91,6 +104,19 @@ const BusinessesListingUI = (props: BusinessesListingParams) => {
91
104
  }
92
105
  }
93
106
 
107
+ useEffect(() => {
108
+ Geolocation.getCurrentPosition((pos) => {
109
+ const crd = pos.coords
110
+ const distance = getDistance(crd.latitude, crd.longitude, orderState?.options?.address?.location?.lat, orderState?.options?.address?.location?.lng)
111
+ if (distance > 20) setIsFarAway(true)
112
+ else setIsFarAway(false)
113
+ }, (err) => {
114
+ console.log(`ERROR(${err.code}): ${err.message}`)
115
+ }, {
116
+ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000
117
+ })
118
+ }, [orderState?.options?.address?.location])
119
+
94
120
  return (
95
121
  <ScrollView style={styles.container} onScroll={(e: any) => handleScroll(e)}>
96
122
  {!auth && (
@@ -162,6 +188,12 @@ const BusinessesListingUI = (props: BusinessesListingParams) => {
162
188
  {orderState?.options?.address?.address}
163
189
  </OText>
164
190
  </AddressInput>
191
+ {isFarAway && (
192
+ <FarAwayMessage style={styles.farAwayMsg}>
193
+ <Ionicons name='md-warning-outline' style={styles.iconStyle} />
194
+ <OText size={12} numberOfLines={1} ellipsizeMode={'tail'} color={theme.colors.textNormal}>{t('YOU_ARE_FAR_FROM_ADDRESS', 'Your are far from this address')}</OText>
195
+ </FarAwayMessage>
196
+ )}
165
197
  </OrderControlContainer>
166
198
  <BusinessTypeFilter
167
199
  images={props.images}
@@ -48,3 +48,13 @@ export const WrapMomentOption = styled.TouchableOpacity`
48
48
  padding: 15px 20px;
49
49
  max-width: 240px;
50
50
  `
51
+
52
+ export const FarAwayMessage = styled.View`
53
+ flex-direction: row;
54
+ align-items: center;
55
+ background-color: ${(props: any) => props.theme.colors.warning1};
56
+ margin-top: 15px;
57
+ border-radius: 7.6px;
58
+ border: 1px solid ${(props: any) => props.theme.colors.warning5};
59
+ width: 100%;
60
+ `
@@ -116,13 +116,13 @@ const CheckoutUI = (props: any) => {
116
116
  const [validationFields] = useValidationFields();
117
117
  const [ordering] = useApi()
118
118
  const webviewRef = useRef<any>(null)
119
-
119
+ const webviewRefSquare = useRef<any>(null)
120
120
  const [errorCash, setErrorCash] = useState(false);
121
121
  const [userErrors, setUserErrors] = useState<any>([]);
122
122
  const [isUserDetailsEdit, setIsUserDetailsEdit] = useState(false);
123
123
  const [phoneUpdate, setPhoneUpdate] = useState(false);
124
124
  const [showGateway, setShowGateway] = useState<any>({ closedByUsed: false, open: false });
125
- const [paypalMethod, setPaypalMethod] = useState<any>(null)
125
+ const [webviewPaymethod, setWebviewPaymethod] = useState<any>(null)
126
126
  const [progClr, setProgClr] = useState('#424242');
127
127
  const [prog, setProg] = useState(true);
128
128
  const [openOrderCreating, setOpenOrderCreating] = useState(false)
@@ -183,7 +183,7 @@ const CheckoutUI = (props: any) => {
183
183
  }
184
184
 
185
185
  const onMessage = (e: any) => {
186
- if (e?.nativeEvent?.data) {
186
+ if (e?.nativeEvent?.data && e?.nativeEvent?.data !== 'undefined') {
187
187
  let payment = JSON.parse(e.nativeEvent.data);
188
188
 
189
189
  if (payment === 'api error') {
@@ -213,7 +213,7 @@ const CheckoutUI = (props: any) => {
213
213
 
214
214
  const handlePaymentMethodClick = (paymethod: any) => {
215
215
  setShowGateway({ closedByUser: false, open: true })
216
- setPaypalMethod(paymethod)
216
+ setWebviewPaymethod(paymethod)
217
217
  }
218
218
 
219
219
  const handleCloseWebview = () => {
@@ -570,7 +570,7 @@ const CheckoutUI = (props: any) => {
570
570
  </>
571
571
  </>
572
572
  )}
573
- {paypalMethod && showGateway.open && (
573
+ {webviewPaymethod?.gateway === 'paypal' && showGateway.open && (
574
574
  <View style={{ zIndex: 9999, height: '100%', width: '100%', position: 'absolute', backgroundColor: 'white' }}>
575
575
  <Icon
576
576
  name="x"
@@ -620,22 +620,91 @@ const CheckoutUI = (props: any) => {
620
620
  urlPlace: `${ordering.root}/carts/${cart?.uuid}/place`,
621
621
  urlConfirm: `${ordering.root}/carts/${cart?.uuid}/confirm`,
622
622
  payData: {
623
- paymethod_id: paypalMethod?.id,
623
+ paymethod_id: webviewPaymethod?.id,
624
624
  amount: cart?.total,
625
625
  delivery_zone_id: cart?.delivery_zone_id,
626
626
  user_id: user?.id
627
627
  },
628
628
  currency: configs?.stripe_currency?.value || currency,
629
629
  userToken: token,
630
- clientId: paypalMethod?.credentials?.client_id
630
+ clientId: webviewPaymethod?.credentials?.client_id
631
631
  }
632
632
  }
633
633
  setProg(false);
634
- webviewRef.current.postMessage(JSON.stringify(message))
634
+ webviewRef?.current?.postMessage?.(JSON.stringify(message))
635
635
  }}
636
636
  />
637
637
  </View>
638
638
  )}
639
+ {webviewPaymethod?.gateway === 'square' && showGateway.open && (
640
+ <View style={{ zIndex: 9999, height: '100%', width: '100%', position: 'absolute', backgroundColor: 'white' }}>
641
+ <Icon
642
+ name="x"
643
+ size={35}
644
+ style={{ backgroundColor: 'white', paddingTop: 30, paddingLeft: 10 }}
645
+ onPress={handleCloseWebview}
646
+ />
647
+ <OText
648
+ style={{
649
+ textAlign: 'center',
650
+ fontSize: 16,
651
+ fontWeight: 'bold',
652
+ color: '#00457C',
653
+ marginBottom: 5,
654
+ marginTop: 10
655
+ }}>
656
+ {t('SQUARE_PAYMENT', 'Square payment')}
657
+ </OText>
658
+ <View style={{ padding: 20, opacity: prog ? 1 : 0, backgroundColor: 'white' }}>
659
+ <ActivityIndicator size={24} color={progClr} />
660
+ </View>
661
+ <WebView
662
+ source={{ uri: `https://test-square-f50f7.web.app` }}
663
+ onMessage={onMessage}
664
+ ref={webviewRefSquare}
665
+ javaScriptEnabled={true}
666
+ javaScriptEnabledAndroid={true}
667
+ cacheEnabled={false}
668
+ cacheMode='LOAD_NO_CACHE'
669
+ style={{ flex: 1 }}
670
+ onShouldStartLoadWithRequest={() => true}
671
+ onLoadStart={() => {
672
+ setProg(true);
673
+ setProgClr('#424242');
674
+ }}
675
+ onLoadProgress={() => {
676
+ setProg(true);
677
+ setProgClr('#00457C');
678
+ }}
679
+ onLoad={() => {
680
+ setProg(true);
681
+ setProgClr('#00457C');
682
+ }}
683
+ onLoadEnd={(e) => {
684
+ const message = {
685
+ action: 'init',
686
+ data: {
687
+ urlPlace: `${ordering.root}/carts/${cart?.uuid}/place`,
688
+ urlConfirm: `${ordering.root}/carts/${cart?.uuid}/confirm`,
689
+ payData: {
690
+ paymethod_id: webviewPaymethod?.id,
691
+ amount: cart?.total,
692
+ delivery_zone_id: cart?.delivery_zone_id,
693
+ user_id: user?.id,
694
+ },
695
+ currency: configs?.stripe_currency?.value || currency,
696
+ userToken: token,
697
+ clientId: 'sandbox-sq0idb-rMLAce87hOfpGvokZCygEw',
698
+ locationId: 'L1NGAY5M6KJRX'
699
+ }
700
+ }
701
+ setProg(false);
702
+ webviewRefSquare?.current?.postMessage?.(JSON.stringify(message))
703
+ }}
704
+ />
705
+ </View>
706
+ )
707
+ }
639
708
  {openOrderCreating && (
640
709
  <View style={{ zIndex: 9999, height: '100%', width: '100%', position: 'absolute', backgroundColor: 'white' }}>
641
710
  <OrderCreating
@@ -209,11 +209,11 @@ const MessagesUI = (props: MessagesParams) => {
209
209
  <InputToolbar
210
210
  {...props}
211
211
  containerStyle={{
212
- padding: Platform.OS === 'ios' && isKeyboardShow ? 0 : 10,
213
- flexDirection: 'column-reverse'
212
+ marginBottom: Platform.OS === 'ios' && isKeyboardShow ? 0 : 10,
213
+ flexDirection: Platform.OS === 'ios' && isKeyboardShow ? 'column' : 'column-reverse'
214
214
  }}
215
215
  primaryStyle={{ alignItems: 'center', justifyContent: 'flex-start' }}
216
- renderAccessory={() => renderAccessory()}
216
+ renderAccessory={() => !isKeyboardShow && renderAccessory()}
217
217
  />
218
218
  )
219
219
 
@@ -90,9 +90,9 @@ const PaymentOptionsUI = (props: any) => {
90
90
  }
91
91
 
92
92
  const handlePaymentMethodClick = (paymethod: any) => {
93
- const isPopupMethod = ['stripe', 'stripe_direct', 'stripe_connect', 'stripe_redirect', 'paypal'].includes(paymethod?.gateway)
93
+ const isPopupMethod = ['stripe', 'stripe_direct', 'stripe_connect', 'stripe_redirect', 'paypal', 'square'].includes(paymethod?.gateway)
94
94
  handlePaymethodClick(paymethod, isPopupMethod)
95
- if(paymethod?.gateway === 'paypal') {
95
+ if(paymethod?.gateway === 'paypal' || paymethod?.gateway === 'square') {
96
96
  handlePaymentMethodClickCustom(paymethod)
97
97
  }
98
98
  setCardData(paymethodData)
package/src/theme.json CHANGED
@@ -42,7 +42,9 @@
42
42
  "colorTextTutorial": "#000000",
43
43
  "toastSuccess":"#90C68E",
44
44
  "toastError":"#D83520",
45
- "toastInfo":"#6BA4FF"
45
+ "toastInfo":"#6BA4FF",
46
+ "warning5": "#FFC700",
47
+ "warning1": "#FFF4CC"
46
48
  },
47
49
  "images": {
48
50
  "logos": {
@@ -164,3 +164,30 @@ export const transformCountryCode = (countryCode : number) => {
164
164
  return parser(value)
165
165
  }
166
166
  }
167
+
168
+ /**
169
+ * Function to transform degree to radian
170
+ * @param {number} value for transform
171
+ *
172
+ */
173
+ export const convertToRadian = (value: number) => {
174
+ return value * Math.PI / 180
175
+ }
176
+
177
+ /**
178
+ * Function to distance between two locations
179
+ * @param lat1 Lat for first location
180
+ * @param lon1 Lon for first location
181
+ * @param lat2 Lat for second location
182
+ * @param lon2 Lon for second location
183
+ */
184
+ export const getDistance = (lat1: any, lon1: any, lat2: any, lon2: any) => {
185
+ const R = 6371 // km
186
+ const dLat = convertToRadian(lat2 - lat1)
187
+ const dLon = convertToRadian(lon2 - lon1)
188
+ const curLat1 = convertToRadian(lat1)
189
+ const curLat2 = convertToRadian(lat2)
190
+ const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(curLat1) * Math.cos(curLat2)
191
+ const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
192
+ return R * c
193
+ }
@@ -1,5 +1,6 @@
1
1
  import React, { useEffect, useState } from 'react'
2
2
  import { Fade, Placeholder, PlaceholderLine } from 'rn-placeholder'
3
+ import Geolocation from '@react-native-community/geolocation'
3
4
  import { View, StyleSheet, ScrollView, Platform, PanResponder, I18nManager, TouchableOpacity } from 'react-native'
4
5
  import {
5
6
  BusinessList as BusinessesListingController,
@@ -11,7 +12,7 @@ import {
11
12
  ToastType, useToast
12
13
  } from 'ordering-components/native'
13
14
 
14
- import { Search, AddressInput, HeaderCont, FeaturedBussiCont } from './styles'
15
+ import { Search, AddressInput, HeaderCont, FeaturedBussiCont, FarAwayMessage } from './styles'
15
16
 
16
17
  import { useTheme } from 'styled-components/native'
17
18
  import { SearchBar } from '../SearchBar'
@@ -21,6 +22,8 @@ import { NotFoundSource } from '../NotFoundSource'
21
22
  import { BusinessTypeFilter } from '../BusinessTypeFilter'
22
23
  import { BusinessController } from '../BusinessController'
23
24
  import BusinessesSortBy from '../BusinessesSortBy'
25
+ import { getDistance } from '../../utils'
26
+ import Ionicons from 'react-native-vector-icons/Ionicons'
24
27
 
25
28
  const PIXELS_TO_SCROLL = 1200
26
29
 
@@ -44,6 +47,7 @@ const BusinessesListingUI = (props: BusinessesListingParams) => {
44
47
 
45
48
  const [businesses, setBusinesses] = useState(businessesList?.businesses || []);
46
49
  const [hasFeatured, setHasFeatured] = useState(false);
50
+ const [isFarAway, setIsFarAway] = useState(false);
47
51
 
48
52
  const theme = useTheme();
49
53
 
@@ -75,6 +79,15 @@ const BusinessesListingUI = (props: BusinessesListingParams) => {
75
79
  borderColor: theme.colors.backgroundGray,
76
80
  borderWidth: 1,
77
81
  borderRadius: 40,
82
+ },
83
+ iconStyle: {
84
+ fontSize: 18,
85
+ color: theme.colors.warning5,
86
+ marginRight: 8
87
+ },
88
+ farAwayMsg: {
89
+ paddingVertical: 6,
90
+ paddingHorizontal: 20
78
91
  }
79
92
  })
80
93
 
@@ -145,6 +158,19 @@ const BusinessesListingUI = (props: BusinessesListingParams) => {
145
158
  }
146
159
  }, [businesses])
147
160
 
161
+ useEffect(() => {
162
+ Geolocation.getCurrentPosition((pos) => {
163
+ const crd = pos.coords
164
+ const distance = getDistance(crd.latitude, crd.longitude, orderState?.options?.address?.location?.lat, orderState?.options?.address?.location?.lng)
165
+ if (distance > 20) setIsFarAway(true)
166
+ else setIsFarAway(false)
167
+ }, (err) => {
168
+ console.log(`ERROR(${err.code}): ${err.message}`)
169
+ }, {
170
+ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000
171
+ })
172
+ }, [orderState?.options?.address?.location])
173
+
148
174
  return (
149
175
  <ScrollView style={styles.container} onScroll={(e) => handleScroll(e)} scrollEventThrottle={50}>
150
176
  <HeaderCont>
@@ -168,6 +194,12 @@ const BusinessesListingUI = (props: BusinessesListingParams) => {
168
194
  </AddressInput>
169
195
  </HeaderCont>
170
196
  <View style={{ height: 1, backgroundColor: theme.colors.border, marginHorizontal: -40 }} />
197
+ {isFarAway && (
198
+ <FarAwayMessage style={styles.farAwayMsg}>
199
+ <Ionicons name='md-warning-outline' style={styles.iconStyle} />
200
+ <OText size={12} numberOfLines={1} ellipsizeMode={'tail'} color={theme.colors.textNormal}>{t('YOU_ARE_FAR_FROM_ADDRESS', 'Your are far from this address')}</OText>
201
+ </FarAwayMessage>
202
+ )}
171
203
  {!auth && (
172
204
  <Search>
173
205
  <SearchBar
@@ -55,4 +55,14 @@ export const HeaderCont = styled.View`
55
55
  export const FeaturedBussiCont = styled.ScrollView`
56
56
  min-height: 190px;
57
57
  margin-horizontal: -40px;
58
- `;
58
+ `;
59
+
60
+ export const FarAwayMessage = styled.View`
61
+ flex-direction: row;
62
+ align-items: center;
63
+ background-color: ${(props: any) => props.theme.colors.warning1};
64
+ margin-top: -5px;
65
+ border-radius: 7.6px;
66
+ border: 1px solid ${(props: any) => props.theme.colors.warning5};
67
+ width: 100%;
68
+ `
@@ -163,3 +163,30 @@ export const transformCountryCode = (countryCode : number) => {
163
163
  return parser(value)
164
164
  }
165
165
  }
166
+
167
+ /**
168
+ * Function to transform degree to radian
169
+ * @param {number} value for transform
170
+ *
171
+ */
172
+ export const convertToRadian = (value: number) => {
173
+ return value * Math.PI / 180
174
+ }
175
+
176
+ /**
177
+ * Function to distance between two locations
178
+ * @param lat1 Lat for first location
179
+ * @param lon1 Lon for first location
180
+ * @param lat2 Lat for second location
181
+ * @param lon2 Lon for second location
182
+ */
183
+ export const getDistance = (lat1: any, lon1: any, lat2: any, lon2: any) => {
184
+ const R = 6371 // km
185
+ const dLat = convertToRadian(lat2 - lat1)
186
+ const dLon = convertToRadian(lon2 - lon1)
187
+ const curLat1 = convertToRadian(lat1)
188
+ const curLat2 = convertToRadian(lat2)
189
+ const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(curLat1) * Math.cos(curLat2)
190
+ const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
191
+ return R * c
192
+ }
@@ -1,5 +1,6 @@
1
- import React from 'react'
1
+ import React, { useState, useEffect } from 'react'
2
2
  import { Fade, Placeholder, PlaceholderLine } from 'rn-placeholder'
3
+ import Geolocation from '@react-native-community/geolocation'
3
4
  import { View, StyleSheet, ScrollView, Platform, PanResponder, I18nManager } from 'react-native'
4
5
  import MaterialComIcon from 'react-native-vector-icons/MaterialCommunityIcons'
5
6
  import {
@@ -13,7 +14,7 @@ import {
13
14
  useToast
14
15
  } from 'ordering-components/native'
15
16
 
16
- import { WelcomeTitle, Search, OrderControlContainer, AddressInput, WrapMomentOption } from './styles'
17
+ import { WelcomeTitle, Search, OrderControlContainer, AddressInput, WrapMomentOption, FarAwayMessage } from './styles'
17
18
 
18
19
  import NavBar from '../NavBar'
19
20
  import { SearchBar } from '../SearchBar'
@@ -24,6 +25,8 @@ import { BusinessTypeFilter } from '../BusinessTypeFilter'
24
25
  import { BusinessController } from '../BusinessController'
25
26
  import { OrderTypeSelector } from '../OrderTypeSelector'
26
27
  import { useTheme } from 'styled-components/native'
28
+ import { getDistance } from '../../utils'
29
+ import Ionicons from 'react-native-vector-icons/Ionicons'
27
30
 
28
31
  const PIXELS_TO_SCROLL = 1200
29
32
 
@@ -60,12 +63,22 @@ const BusinessesListingUI = (props: BusinessesListingParams) => {
60
63
  flexDirection: 'row',
61
64
  alignItems: 'center',
62
65
  marginBottom: 10,
66
+ marginTop: 10,
63
67
  zIndex: 100
64
68
  },
65
69
  borderStyle: {
66
70
  borderColor: theme.colors.backgroundGray,
67
71
  borderWidth: 1,
68
72
  borderRadius: 10,
73
+ },
74
+ iconStyle: {
75
+ fontSize: 18,
76
+ color: theme.colors.warning5,
77
+ marginRight: 8
78
+ },
79
+ farAwayMsg: {
80
+ paddingVertical: 6,
81
+ paddingHorizontal: 20
69
82
  }
70
83
  })
71
84
 
@@ -75,6 +88,7 @@ const BusinessesListingUI = (props: BusinessesListingParams) => {
75
88
  const [{ configs }] = useConfig()
76
89
  const [{ parseDate }] = useUtils()
77
90
  const [, { showToast }] = useToast()
91
+ const [isFarAway, setIsFarAway] = useState(false)
78
92
 
79
93
  const configTypes = configs?.order_types_allowed?.value.split('|').map((value: any) => Number(value)) || []
80
94
 
@@ -95,6 +109,19 @@ const BusinessesListingUI = (props: BusinessesListingParams) => {
95
109
  return fBusiness !== undefined && fBusiness !== null;
96
110
  }
97
111
 
112
+ useEffect(() => {
113
+ Geolocation.getCurrentPosition((pos) => {
114
+ const crd = pos.coords
115
+ const distance = getDistance(crd.latitude, crd.longitude, orderState?.options?.address?.location?.lat, orderState?.options?.address?.location?.lng)
116
+ if (distance > 20) setIsFarAway(true)
117
+ else setIsFarAway(false)
118
+ }, (err) => {
119
+ console.log(`ERROR(${err.code}): ${err.message}`)
120
+ }, {
121
+ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000
122
+ })
123
+ }, [orderState?.options?.address?.location])
124
+
98
125
  return (
99
126
  <ScrollView style={styles.container} contentContainerStyle={{ paddingHorizontal: 40 }} onScroll={(e: any) => handleScroll(e)}>
100
127
  {!auth && (
@@ -125,7 +152,12 @@ const BusinessesListingUI = (props: BusinessesListingParams) => {
125
152
  {orderState?.options?.address?.address}
126
153
  </OText>
127
154
  </AddressInput>
128
-
155
+ {isFarAway && (
156
+ <FarAwayMessage style={styles.farAwayMsg}>
157
+ <Ionicons name='md-warning-outline' style={styles.iconStyle} />
158
+ <OText size={12} numberOfLines={1} ellipsizeMode={'tail'} color={theme.colors.textNormal}>{t('YOU_ARE_FAR_FROM_ADDRESS', 'Your are far from this address')}</OText>
159
+ </FarAwayMessage>
160
+ )}
129
161
  <View style={styles.wrapperOrderOptions}>
130
162
  <OrderTypeSelector configTypes={configTypes} />
131
163
  <WrapMomentOption
@@ -25,7 +25,6 @@ export const AddressInput = styled.TouchableOpacity`
25
25
  border-radius: 3px;
26
26
  align-items: center;
27
27
  padding-vertical: 4px;
28
- margin-bottom: 10px;
29
28
  flex: 1;
30
29
  width: 100%;
31
30
  z-index: -10;
@@ -50,3 +49,14 @@ export const WrapMomentOption = styled.TouchableOpacity`
50
49
  margin-start: 15px;
51
50
  min-height: 28px;
52
51
  `
52
+
53
+ export const FarAwayMessage = styled.View`
54
+ flex-direction: row;
55
+ align-items: center;
56
+ background-color: ${(props: any) => props.theme.colors.warning1};
57
+ margin-top: 0px;
58
+ margin-left: 0px;
59
+ border-radius: 7.6px;
60
+ border: 1px solid ${(props: any) => props.theme.colors.warning5};
61
+ width: 100%;
62
+ `
@@ -163,3 +163,30 @@ export const transformCountryCode = (countryCode : number) => {
163
163
  return parser(value)
164
164
  }
165
165
  }
166
+
167
+ /**
168
+ * Function to transform degree to radian
169
+ * @param {number} value for transform
170
+ *
171
+ */
172
+ export const convertToRadian = (value: number) => {
173
+ return value * Math.PI / 180
174
+ }
175
+
176
+ /**
177
+ * Function to distance between two locations
178
+ * @param lat1 Lat for first location
179
+ * @param lon1 Lon for first location
180
+ * @param lat2 Lat for second location
181
+ * @param lon2 Lon for second location
182
+ */
183
+ export const getDistance = (lat1: any, lon1: any, lat2: any, lon2: any) => {
184
+ const R = 6371 // km
185
+ const dLat = convertToRadian(lat2 - lat1)
186
+ const dLon = convertToRadian(lon2 - lon1)
187
+ const curLat1 = convertToRadian(lat1)
188
+ const curLat2 = convertToRadian(lat2)
189
+ const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(curLat1) * Math.cos(curLat2)
190
+ const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
191
+ return R * c
192
+ }
@@ -20,6 +20,7 @@ import { BusinessMenuList } from './src/components/BusinessMenuList';
20
20
  import { UserProfileForm } from './src/components/UserProfileForm';
21
21
  import { ReviewOrder } from './src/components/ReviewOrder';
22
22
  import { UserProfile } from './src/components/UserProfile';
23
+ import { MessageListing } from './src/components/MessageListing';
23
24
  import { Help } from './src/components/Help';
24
25
  import { HelpAccountAndPayment } from './src/components/HelpAccountAndPayment';
25
26
  import { HelpGuide } from './src/components/HelpGuide';
@@ -76,6 +77,7 @@ export {
76
77
  ReviewOrder,
77
78
  BusinessMenuList,
78
79
  UserProfile,
80
+ MessageListing,
79
81
  Help,
80
82
  HelpAccountAndPayment,
81
83
  HelpGuide,