ordering-ui-react-native 0.12.76 → 0.12.80

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 (31) 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/business/src/components/OrderDetails/Delivery.tsx +134 -131
  10. package/themes/business/src/components/OrderDetails/OrderHeaderComponent.tsx +1 -1
  11. package/themes/doordash/src/components/BusinessesListing/index.tsx +33 -1
  12. package/themes/doordash/src/components/BusinessesListing/styles.tsx +11 -1
  13. package/themes/doordash/src/utils/index.tsx +27 -0
  14. package/themes/instacart/src/components/BusinessesListing/index.tsx +35 -3
  15. package/themes/instacart/src/components/BusinessesListing/styles.tsx +11 -1
  16. package/themes/instacart/src/utils/index.tsx +27 -0
  17. package/themes/original/index.tsx +2 -0
  18. package/themes/original/src/components/ActiveOrders/index.tsx +36 -16
  19. package/themes/original/src/components/ActiveOrders/styles.tsx +10 -0
  20. package/themes/original/src/components/MessageListing/index.tsx +298 -0
  21. package/themes/original/src/components/MessageListing/styles.tsx +16 -0
  22. package/themes/original/src/components/Messages/index.tsx +123 -81
  23. package/themes/original/src/components/Messages/styles.tsx +8 -0
  24. package/themes/original/src/components/UserProfile/index.tsx +10 -0
  25. package/themes/original/src/utils/index.tsx +18 -0
  26. package/themes/single-business/src/components/BusinessesListing/index.tsx +33 -0
  27. package/themes/single-business/src/components/BusinessesListing/styles.tsx +9 -0
  28. package/themes/single-business/src/utils/index.tsx +27 -0
  29. package/themes/uber-eats/src/components/BusinessesListing/index.tsx +36 -3
  30. package/themes/uber-eats/src/components/BusinessesListing/styles.tsx +8 -0
  31. package/themes/uber-eats/src/utils/index.tsx +27 -0
@@ -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,
@@ -10,6 +10,7 @@ import {
10
10
  OrderInformation,
11
11
  BusinessInformation,
12
12
  Price,
13
+ UnreadMessageCounter,
13
14
  LoadMore
14
15
  } from './styles';
15
16
  import { View, StyleSheet } from 'react-native';
@@ -26,6 +27,8 @@ export const ActiveOrders = (props: ActiveOrdersParams) => {
26
27
  pagination,
27
28
  loadMoreOrders,
28
29
  getOrderStatus,
30
+ isMessageView,
31
+ handleClickOrder
29
32
  } = props;
30
33
 
31
34
  const theme = useTheme();
@@ -38,6 +41,10 @@ export const ActiveOrders = (props: ActiveOrdersParams) => {
38
41
  };
39
42
 
40
43
  const handleClickCard = (uuid: string) => {
44
+ if (isMessageView ) {
45
+ handleClickOrder(uuid)
46
+ return
47
+ }
41
48
  onNavigationRedirect &&
42
49
  onNavigationRedirect('OrderDetails', { orderId: uuid });
43
50
  };
@@ -49,15 +56,15 @@ export const ActiveOrders = (props: ActiveOrdersParams) => {
49
56
  onPress={() => handleClickCard(order?.uuid)}
50
57
  activeOpacity={0.7}>
51
58
  {/* {!!(configs?.google_maps_api_key?.value) && (
52
- <Map>
53
- <OIcon
54
- url={getGoogleMapImage(order?.business?.location, configs?.google_maps_api_key?.value)}
55
- height={100}
56
- width={320}
57
- style={{resizeMode: 'cover', borderTopRightRadius: 24, borderTopLeftRadius: 24}}
58
- />
59
- </Map>
60
- )} */}
59
+ <Map>
60
+ <OIcon
61
+ url={getGoogleMapImage(order?.business?.location, configs?.google_maps_api_key?.value)}
62
+ height={100}
63
+ width={320}
64
+ style={{resizeMode: 'cover', borderTopRightRadius: 24, borderTopLeftRadius: 24}}
65
+ />
66
+ </Map>
67
+ )} */}
61
68
  <Information>
62
69
  {!!order.business?.logo && (
63
70
  <Logo>
@@ -96,15 +103,28 @@ export const ActiveOrders = (props: ActiveOrdersParams) => {
96
103
  </OText>
97
104
  {/* )} */}
98
105
  </BusinessInformation>
99
- <Price>
100
- <OText size={12} lineHeight={18}>
101
- {parsePrice(order?.summary?.total || order?.total)}
102
- </OText>
103
- </Price>
106
+ {isMessageView ? (
107
+ <>
108
+ {order?.unread_count > 0 && (
109
+ <UnreadMessageCounter>
110
+ <OText size={12} color={theme.colors.primary} lineHeight={18} >
111
+ {order?.unread_count}
112
+ </OText>
113
+ </UnreadMessageCounter>
114
+ )}
115
+ </>
116
+ ) : (
117
+ <Price>
118
+ <OText size={12} lineHeight={18}>
119
+ {parsePrice(order?.summary?.total || order?.total)}
120
+ </OText>
121
+ </Price>
122
+ )}
123
+
104
124
  </OrderInformation>
105
125
  </Information>
106
- </Card>
107
- </React.Fragment>
126
+ </Card >
127
+ </React.Fragment >
108
128
  );
109
129
 
110
130
  return (
@@ -42,6 +42,16 @@ export const Price = styled.View`
42
42
  margin-left: 10px;
43
43
  width: 30%;
44
44
  `
45
+
46
+ export const UnreadMessageCounter = styled.View`
47
+ justify-content: center;
48
+ align-items: center;
49
+ margin-left: 10px;
50
+ width: 24px;
51
+ height: 24px;
52
+ border-radius: 7.6px;
53
+ background-color: ${(props: any) => props.theme.colors.primaryContrast};
54
+ `
45
55
  export const LoadMore = styled.View`
46
56
  flex-direction: row;
47
57
  justify-content: center;
@@ -0,0 +1,298 @@
1
+ import React, { useState, useEffect } from 'react'
2
+ import { OrderList, useLanguage, useOrder, ToastType, useToast } from 'ordering-components/native'
3
+ import { OrderDetails as OrderDetailsConTableoller } from './naked'
4
+ import { useTheme } from 'styled-components/native';
5
+ import { useFocusEffect } from '@react-navigation/native'
6
+ import { OText, OModal } from '../shared'
7
+ import { NotFoundSource } from '../NotFoundSource'
8
+ import { ActiveOrders } from '../ActiveOrders'
9
+ import { Messages } from '../Messages';
10
+ import NavBar from '../NavBar'
11
+ import {
12
+ MessageListingParams,
13
+ OrdersOptionParams
14
+ } from '../../types'
15
+ import {
16
+ Placeholder,
17
+ PlaceholderLine,
18
+ Fade
19
+ } from "rn-placeholder";
20
+ import { View, BackHandler } from 'react-native'
21
+ import {
22
+ MessageListingWrapper,
23
+ MessageContainer
24
+ } from './styles';
25
+
26
+ const OrdersOptionUI = (props: OrdersOptionParams) => {
27
+ const {
28
+ navigation,
29
+ activeOrders,
30
+ orderList,
31
+ pagination,
32
+ titleContent,
33
+ customArray,
34
+ onNavigationRedirect,
35
+ orderStatus,
36
+ loadMoreOrders,
37
+ loadOrders,
38
+ setSelectedOrderId,
39
+ setOrderList,
40
+ setOpenMessges
41
+ } = props
42
+
43
+ const theme = useTheme();
44
+ const [, t] = useLanguage()
45
+ const [, { reorder }] = useOrder()
46
+ const { showToast } = useToast()
47
+ const { loading, error, orders: values } = orderList
48
+ const imageFails = activeOrders
49
+ ? theme.images.general.emptyActiveOrders
50
+ : theme.images.general.emptyPastOrders
51
+ const orders = customArray || values || []
52
+
53
+ const getOrderStatus = (s: string) => {
54
+ const status = parseInt(s)
55
+ const orderStatus = [
56
+ { key: 0, value: t('PENDING', 'Pending') },
57
+ { key: 1, value: t('COMPLETED', 'Completed') },
58
+ { key: 2, value: t('REJECTED', 'Rejected') },
59
+ { key: 3, value: t('DRIVER_IN_BUSINESS', 'Driver in business') },
60
+ { key: 4, value: t('PREPARATION_COMPLETED', 'Preparation Completed') },
61
+ { key: 5, value: t('REJECTED_BY_BUSINESS', 'Rejected by business') },
62
+ { key: 6, value: t('REJECTED_BY_DRIVER', 'Rejected by Driver') },
63
+ { key: 7, value: t('ACCEPTED_BY_BUSINESS', 'Accepted by business') },
64
+ { key: 8, value: t('ACCEPTED_BY_DRIVER', 'Accepted by driver') },
65
+ { key: 9, value: t('PICK_UP_COMPLETED_BY_DRIVER', 'Pick up completed by driver') },
66
+ { key: 10, value: t('PICK_UP_FAILED_BY_DRIVER', 'Pick up Failed by driver') },
67
+ { key: 11, value: t('DELIVERY_COMPLETED_BY_DRIVER', 'Delivery completed by driver') },
68
+ { key: 12, value: t('DELIVERY_FAILED_BY_DRIVER', 'Delivery Failed by driver') },
69
+ { key: 13, value: t('PREORDER', 'PreOrder') },
70
+ { key: 14, value: t('ORDER_NOT_READY', 'Order not ready') },
71
+ { key: 15, value: t('ORDER_PICKEDUP_COMPLETED_BY_CUSTOMER', 'Order picked up completed by customer') },
72
+ { key: 16, value: t('CANCELLED_BY_CUSTOMER', 'Cancelled by customer') },
73
+ { key: 17, value: t('ORDER_NOT_PICKEDUP_BY_CUSTOMER', 'Order not picked up by customer') },
74
+ { key: 18, value: t('DRIVER_ALMOST_ARRIVED_TO_BUSINESS', 'Driver almost arrived to business') },
75
+ { key: 19, value: t('DRIVER_ALMOST_ARRIVED_TO_CUSTOMER', 'Driver almost arrived to customer') },
76
+ { key: 20, value: t('ORDER_CUSTOMER_ALMOST_ARRIVED_BUSINESS', 'Customer almost arrived to business') },
77
+ { key: 21, value: t('ORDER_CUSTOMER_ARRIVED_BUSINESS', 'Customer arrived to business') }
78
+ ]
79
+
80
+ const objectStatus = orderStatus.find((o) => o.key === status)
81
+
82
+ return objectStatus && objectStatus
83
+ }
84
+
85
+ const handleClickOrder = (uuid: string) => {
86
+ setSelectedOrderId(uuid)
87
+ setOpenMessges(true)
88
+ }
89
+
90
+ useFocusEffect(
91
+ React.useCallback(() => {
92
+ loadOrders()
93
+ }, [navigation])
94
+ )
95
+
96
+ useEffect(() => {
97
+ if (loading) return
98
+ setOrderList(orderList)
99
+ }, [orderList, loading])
100
+
101
+ return (
102
+ <>
103
+ {!loading && orders.length === 0 && (
104
+ <NotFoundSource
105
+ content={t('NO_RESULTS_FOUND', 'Sorry, no results found')}
106
+ image={imageFails}
107
+ conditioned
108
+ />
109
+ )}
110
+ {loading && (
111
+ <View style={{ marginTop: 30 }}>
112
+ {[...Array(6)].map((item, i) => (
113
+ <Placeholder key={i} Animation={Fade}>
114
+ <View style={{ width: '100%', flexDirection: 'row' }}>
115
+ <PlaceholderLine width={20} height={70} style={{ marginRight: 20, marginBottom: 20 }} />
116
+ <Placeholder>
117
+ <PlaceholderLine width={30} style={{ marginTop: 5 }} />
118
+ <PlaceholderLine width={50} />
119
+ <PlaceholderLine width={20} />
120
+ </Placeholder>
121
+ </View>
122
+ </Placeholder>
123
+ ))}
124
+ </View>
125
+ )}
126
+ {!loading && !error && orders.length > 0 && (
127
+ <ActiveOrders
128
+ orders={orders.filter((order: any) => orderStatus.includes(order.status))}
129
+ pagination={pagination}
130
+ loadMoreOrders={loadMoreOrders}
131
+ customArray={customArray}
132
+ getOrderStatus={getOrderStatus}
133
+ onNavigationRedirect={onNavigationRedirect}
134
+ isMessageView
135
+ handleClickOrder={handleClickOrder}
136
+ />
137
+ )}
138
+ </>
139
+ )
140
+ }
141
+
142
+ const OrderMessageUI = (props: any) => {
143
+ const {
144
+ navigation,
145
+ messages,
146
+ setMessages,
147
+ readMessages,
148
+ messagesReadList,
149
+ setOpenMessges
150
+ } = props;
151
+ const [openModalForBusiness, setOpenModalForBusiness] = useState(false);
152
+ const [openModalForDriver, setOpenModalForDriver] = useState(false);
153
+ const [unreadAlert, setUnreadAlert] = useState({
154
+ business: false,
155
+ driver: false,
156
+ });
157
+ const [, t] = useLanguage()
158
+ const { order } = props.order;
159
+ const handleArrowBack: any = () => {
160
+ navigation.navigate('BottomTab');
161
+ };
162
+
163
+ const handleClose = () => {
164
+ setOpenMessges(false)
165
+ }
166
+
167
+ useEffect(() => {
168
+ if (messagesReadList?.length) {
169
+ openModalForBusiness
170
+ ? setUnreadAlert({ ...unreadAlert, business: false })
171
+ : setUnreadAlert({ ...unreadAlert, driver: false });
172
+ }
173
+ }, [messagesReadList]);
174
+
175
+ useEffect(() => {
176
+ setOpenModalForBusiness(true);
177
+ setOpenModalForDriver(true);
178
+ readMessages && readMessages();
179
+ }, [order])
180
+
181
+ useEffect(() => {
182
+ BackHandler.addEventListener('hardwareBackPress', handleArrowBack);
183
+ return () => {
184
+ BackHandler.removeEventListener('hardwareBackPress', handleArrowBack);
185
+ };
186
+ }, []);
187
+
188
+ return (
189
+ <>
190
+ {(order?.business && !order?.driver) && (
191
+ <Messages
192
+ orderId={order?.id}
193
+ messages={messages}
194
+ order={order}
195
+ setMessages={setMessages}
196
+ readMessages={readMessages}
197
+ isMeesageListing
198
+ onClose={() => handleClose()}
199
+ />
200
+ )}
201
+ </>
202
+
203
+ )
204
+ }
205
+
206
+ export const OrderListing = (props: OrdersOptionParams) => {
207
+ const OrderListingProps = {
208
+ ...props,
209
+ UIComponent: OrdersOptionUI,
210
+ orderStatus: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21],
211
+ useDefualtSessionManager: true,
212
+ paginationSettings: {
213
+ initialPage: 1,
214
+ pageSize: 10,
215
+ controlType: 'infinity'
216
+ }
217
+ }
218
+ return <OrderList {...OrderListingProps} />
219
+ }
220
+
221
+ export const MessagesView = (props: any) => {
222
+ const orderDetailsProps = {
223
+ ...props,
224
+ UIComponent: OrderMessageUI,
225
+ };
226
+ return <OrderDetailsConTableoller {...orderDetailsProps} />;
227
+ };
228
+
229
+
230
+ export const MessageListing = (props: MessageListingParams) => {
231
+ const {
232
+ navigation
233
+ } = props
234
+ const [orderListStatus, setOrderListStatus] = useState({
235
+ error: null,
236
+ loading: false,
237
+ orders: []
238
+ })
239
+ const [selectedOrderId, setSelectedOrderId] = useState(null)
240
+ const [seletedOrder, setSeletedOrder] = useState<any>()
241
+ const [openMessages, setOpenMessges] = useState(false)
242
+ const [, t] = useLanguage()
243
+
244
+ const goToBack = () => {
245
+ navigation?.canGoBack() && navigation.goBack()
246
+ setSelectedOrderId(null)
247
+ setSeletedOrder([])
248
+ }
249
+
250
+ const handleCloseModal = () => {
251
+ setOpenMessges(false)
252
+ }
253
+
254
+ useEffect(() => {
255
+ if (!orderListStatus?.loading && selectedOrderId) {
256
+ const _orders = orderListStatus?.orders
257
+ const _seletedOrder = _orders.find((order: any) => order?.uuid === selectedOrderId)
258
+ setSeletedOrder(_seletedOrder)
259
+ }
260
+ }, [orderListStatus, selectedOrderId])
261
+
262
+ useEffect(() => {
263
+
264
+ }, [orderListStatus])
265
+
266
+ return (
267
+ <MessageListingWrapper>
268
+ <NavBar
269
+ title={t('MESSAGES', 'Messages')}
270
+ titleAlign={'center'}
271
+ onActionLeft={goToBack}
272
+ showCall={false}
273
+ paddingTop={10}
274
+ btnStyle={{ paddingLeft: 0 }}
275
+ />
276
+ <OrderListing
277
+ ordersLength={{ activeOrdersLength: 0, previousOrdersLength: 0 }}
278
+ setSelectedOrderId={setSelectedOrderId}
279
+ setOrderList={setOrderListStatus}
280
+ setOpenMessges={setOpenMessges}
281
+ />
282
+ {openMessages && seletedOrder && (
283
+ <OModal
284
+ open={openMessages}
285
+ entireModal
286
+ customClose
287
+ onClose={() => handleCloseModal()}
288
+ >
289
+ <MessagesView
290
+ order={seletedOrder}
291
+ setOpenMessges={setOpenMessges}
292
+ />
293
+ </OModal>
294
+ )}
295
+ </MessageListingWrapper>
296
+ )
297
+ }
298
+