ordering-ui-react-native 0.18.10 → 0.18.11

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ordering-ui-react-native",
3
- "version": "0.18.10",
3
+ "version": "0.18.11",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -54,12 +54,12 @@ export const OrderDetailsLogisticUI = (props: OrderDetailsLogisticParams) => {
54
54
  };
55
55
 
56
56
  const handleRejectLogisticOrder = (order: any) => {
57
- handleClickLogisticOrder?.(2, orderAssingId || order?.logistic_order_id)
57
+ handleClickLogisticOrder?.(2, orderAssingId || order?.logistic_order_id, order)
58
58
  handleArrowBack()
59
59
  }
60
60
 
61
61
  const handleAcceptLogisticOrder = (order: any) => {
62
- handleClickLogisticOrder?.(1, orderAssingId || order?.logistic_order_id)
62
+ handleClickLogisticOrder?.(1, orderAssingId || order?.logistic_order_id, order)
63
63
  handleArrowBack()
64
64
  }
65
65
 
@@ -346,7 +346,7 @@ export const getOrderStatus = (s: string, t: any) => {
346
346
  return objectStatus && objectStatus;
347
347
  };
348
348
 
349
- export const transformDistance = (value : number, distanceUnit?: string) => {
349
+ export const transformDistance = (value: number, distanceUnit?: string) => {
350
350
  return distanceUnit === 'mi'
351
351
  ? (value / 1.609).toFixed(2)
352
352
  : distanceUnit === 'ft'
@@ -354,7 +354,7 @@ export const transformDistance = (value : number, distanceUnit?: string) => {
354
354
  : (value).toFixed(2)
355
355
  }
356
356
 
357
- export const formatSeconds = (seconds : number) => {
357
+ export const formatSeconds = (seconds: number) => {
358
358
  // Hours, minutes and seconds
359
359
  const hrs = Math.floor(seconds / 3600)
360
360
  const mins = Math.floor((seconds % 3600) / 60)
@@ -377,8 +377,8 @@ export const calculateDistance = (
377
377
  const lat1 = pointA.lat;
378
378
  const lon1 = pointA.lng;
379
379
 
380
- const lat2 = pointB.latitude;
381
- const lon2 = pointB.longitude;
380
+ const lat2 = pointB?.latitude;
381
+ const lon2 = pointB?.longitude;
382
382
 
383
383
  const R = 6371e3;
384
384
  const φ1 = lat1 * (Math.PI / 180);
@@ -29,6 +29,12 @@ const BusinessInformationUI = (props: BusinessInformationParams) => {
29
29
  const [, t] = useLanguage();
30
30
  const [{ optimizeImage }] = useUtils();
31
31
 
32
+ const hideLocation = theme?.business_view?.components?.information?.components?.location?.hidden
33
+ const hideSchedule = theme?.business_view?.components?.information?.components?.schedule?.hidden
34
+ const hideVideos = theme?.business_view?.components?.information?.components?.videos?.hidden
35
+ const hideImages = theme?.business_view?.components?.information?.components?.images?.hidden
36
+ const hideAddress = theme?.business_view?.components?.information?.components?.address?.hidden
37
+
32
38
  const scheduleFormatted = ({
33
39
  hour,
34
40
  minute,
@@ -78,87 +84,108 @@ const BusinessInformationUI = (props: BusinessInformationParams) => {
78
84
  <OText size={24} weight={'600'}>
79
85
  {businessState?.business?.name}
80
86
  </OText>
81
- <GrayBackground>
82
- <OText size={16} weight="500">
83
- {t('BUSINESS_LOCATION', 'Business Location')}
87
+ {!hideLocation && (
88
+ <>
89
+ <GrayBackground>
90
+ <OText size={16} weight="500">
91
+ {t('BUSINESS_LOCATION', 'Business Location')}
92
+ </OText>
93
+ </GrayBackground>
94
+ {businessLocation.location && (
95
+ <WrapBusinessMap style={styles.wrapMapStyle}>
96
+ <GoogleMap
97
+ readOnly
98
+ location={businessLocation.location}
99
+ markerTitle={businessState?.business?.name}
100
+ />
101
+ </WrapBusinessMap>
102
+ )}
103
+ </>
104
+ )}
105
+ {!hideAddress && (
106
+ <OText size={12} mBottom={20}>
107
+ {businessState?.business?.address}
84
108
  </OText>
85
- </GrayBackground>
86
- {businessLocation.location && (
87
- <WrapBusinessMap style={styles.wrapMapStyle}>
88
- <GoogleMap
89
- readOnly
90
- location={businessLocation.location}
91
- markerTitle={businessState?.business?.name}
92
- />
93
- </WrapBusinessMap>
94
109
  )}
95
- <OText size={12} mBottom={20}>
96
- {businessState?.business?.address}
97
- </OText>
98
110
  <DivideView />
99
- <GrayBackground>
100
- <OText size={16} weight="500">
101
- {t('OPENING_TIME', 'Opening Time')}
102
- </OText>
103
- </GrayBackground>
104
- {businessSchedule && businessSchedule?.length > 0 && (
105
- <WrapScheduleBlock>
106
- {businessSchedule.map((schedule: any, i: number) => (
107
- <ScheduleBlock key={i}>
108
- <ScheduleAccordion
109
- weekIndex={i}
110
- scheduleFormatted={scheduleFormatted}
111
- schedule={schedule}
112
- />
113
- </ScheduleBlock>
114
- ))}
115
- </WrapScheduleBlock>
111
+ {!hideSchedule && (
112
+ <>
113
+ <GrayBackground>
114
+ <OText size={16} weight="500">
115
+ {t('OPENING_TIME', 'Opening Time')}
116
+ </OText>
117
+ </GrayBackground>
118
+ {businessSchedule && businessSchedule?.length > 0 && (
119
+ <WrapScheduleBlock>
120
+ {businessSchedule.map((schedule: any, i: number) => (
121
+ <ScheduleBlock key={i}>
122
+ <ScheduleAccordion
123
+ weekIndex={i}
124
+ scheduleFormatted={scheduleFormatted}
125
+ schedule={schedule}
126
+ />
127
+ </ScheduleBlock>
128
+ ))}
129
+ </WrapScheduleBlock>
130
+ )}
131
+ </>
116
132
  )}
133
+
117
134
  {/* {businessState?.business?.gallery?.length > 0 && ( */}
135
+
118
136
  <>
119
- {bVideos().length > 0 && (
137
+ {!hideVideos && (
120
138
  <>
121
- <DivideView />
122
- <GrayBackground>
123
- <OText size={16} weight="500">
124
- {t('VIDEOS', 'Videos')}
125
- </OText>
126
- </GrayBackground>
127
- <MediaWrapper horizontal>
128
- {bVideos().map((v: any) => (
129
- <WebView
130
- key={`vid_id_${v.id}`}
131
- style={{ width: 210, height: 127, borderRadius: 7.6 }}
132
- javaScriptEnabled={true}
133
- domStorageEnabled={true}
134
- source={{
135
- html: `
136
- <iframe width='80%' height='80%' src="${formatUrlVideo(v.video)}" frameBorder='0' allow='autoplay; encrypted-media' allowFullScreen />
139
+ {bVideos().length > 0 && (
140
+ <>
141
+ <DivideView />
142
+ <GrayBackground>
143
+ <OText size={16} weight="500">
144
+ {t('VIDEOS', 'Videos')}
145
+ </OText>
146
+ </GrayBackground>
147
+ <MediaWrapper horizontal>
148
+ {bVideos().map((v: any) => (
149
+ <WebView
150
+ key={`vid_id_${v.id}`}
151
+ style={{ width: 210, height: 127, borderRadius: 7.6 }}
152
+ javaScriptEnabled={true}
153
+ domStorageEnabled={true}
154
+ source={{
155
+ html: `
156
+ <iframe width='80%' height='80%' src="${formatUrlVideo(v.video)}" frameBorder='0' allow='autoplay; encrypted-media' allowFullScreen />
137
157
  `,
138
- }}
139
- mediaPlaybackRequiresUserAction={true}
140
- />
141
- ))}
142
- </MediaWrapper>
158
+ }}
159
+ mediaPlaybackRequiresUserAction={true}
160
+ />
161
+ ))}
162
+ </MediaWrapper>
163
+ </>
164
+ )}
143
165
  </>
144
166
  )}
145
- {bImages().length > 0 && (
167
+
168
+ {!hideImages && (
146
169
  <>
147
- <DivideView />
148
- <GrayBackground>
149
- <OText size={16} weight="500">
150
- {t('IMAGES', 'Images')}
151
- </OText>
152
- </GrayBackground>
153
- <MediaWrapper horizontal>
154
- {bImages().map((i: any) => (
155
- i.file != null &&
156
- <View key={i.id} style={{ width: 210, height: 127, borderRadius: 7.6, marginEnd: 20, overflow: 'hidden' }}>
157
- <OIcon cover url={optimizeImage(i?.file, 'h_150,c_limit')} width={210} height={127} />
158
- {/* <OText size={12} color={colors.red} style={{position: 'absolute'}}>{i.file}</OText> */}
159
- </View>
160
- ))}
161
- </MediaWrapper>
170
+ {bImages().length > 0 && (
171
+ <>
172
+ <DivideView />
173
+ <GrayBackground>
174
+ <OText size={16} weight="500">
175
+ {t('IMAGES', 'Images')}
176
+ </OText>
177
+ </GrayBackground>
178
+ <MediaWrapper horizontal>
179
+ {bImages().map((i: any) => (
180
+ i.file != null &&
181
+ <View key={i.id} style={{ width: 210, height: 127, borderRadius: 7.6, marginEnd: 20, overflow: 'hidden' }}>
182
+ <OIcon cover url={optimizeImage(i?.file, 'h_150,c_limit')} width={210} height={127} />
183
+ {/* <OText size={12} color={colors.red} style={{position: 'absolute'}}>{i.file}</OText> */}
184
+ </View>
185
+ ))}
186
+ </MediaWrapper>
187
+ </>
188
+ )}
162
189
  </>
163
190
  )}
164
191
  </>
@@ -0,0 +1,59 @@
1
+ import React, { useEffect, useState } from 'react'
2
+ import { useUtils } from 'ordering-components/native'
3
+ import moment from 'moment'
4
+
5
+ export const OrderEta = (props: any) => {
6
+ const {
7
+ order,
8
+ outputFormat
9
+ } = props
10
+
11
+ const [{ parseDate }] = useUtils()
12
+ const [estimatedDeliveryTime, setEstimatedDeliveryTime] = useState(null)
13
+
14
+ const getEstimatedDeliveryTime = () => {
15
+ let _estimatedTime
16
+ let totalEta = 0
17
+ const _delivery = order?.delivery_datetime_utc
18
+ ? order?.delivery_datetime_utc
19
+ : order?.delivery_datetime
20
+ if (order?.eta_current_status_time) {
21
+ const currentStatueEta = order?.eta_current_status_time
22
+ totalEta += currentStatueEta
23
+ let nextStatusTimes = 0
24
+ if (order?.eta_next_status_times) {
25
+ Object.keys(order.eta_next_status_times).map(key => {
26
+ if (!key.includes('status_penalty')) {
27
+ nextStatusTimes += order.eta_next_status_times[key]
28
+ }
29
+ })
30
+ }
31
+
32
+ totalEta += nextStatusTimes
33
+
34
+ const diffTimeAsSeconds = moment.utc(order?.reporting_data?.at[`status:${order.status}`]).add(order?.eta_current_status_time, 'minutes').diff(moment().utc(), 'seconds')
35
+ const diffTimeAsMinutes = Math.ceil(diffTimeAsSeconds / 60)
36
+ if (diffTimeAsMinutes <= 0) {
37
+ totalEta += (Math.floor(Math.abs(diffTimeAsMinutes / order?.eta_current_status_time) + 1) * order?.eta_current_status_penalty_time)
38
+ }
39
+ _estimatedTime = parseDate(moment(_delivery).add(totalEta, 'minutes'))
40
+ } else {
41
+ _estimatedTime = parseDate(moment(_delivery).add(order?.eta_time, 'minutes'))
42
+ }
43
+ setEstimatedDeliveryTime(_estimatedTime)
44
+ }
45
+
46
+ useEffect(() => {
47
+ getEstimatedDeliveryTime()
48
+ const interval = setInterval(() => {
49
+ getEstimatedDeliveryTime()
50
+ }, 1000)
51
+ return () => clearInterval(interval)
52
+ }, [order])
53
+
54
+ return (
55
+ <>
56
+ {!outputFormat ? estimatedDeliveryTime : moment(estimatedDeliveryTime).format(outputFormat)}
57
+ </>
58
+ )
59
+ }
@@ -49,6 +49,7 @@ import NavBar from '../NavBar'
49
49
  import { OrderHistory } from './OrderHistory';
50
50
  import { PlaceSpot } from '../PlaceSpot'
51
51
  import { SendGiftCard } from '../GiftCard/SendGiftCard'
52
+ import { OrderEta } from './OrderEta'
52
53
  export const OrderDetailsUI = (props: OrderDetailsParams) => {
53
54
  const {
54
55
  navigation,
@@ -410,13 +411,11 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
410
411
  titleWrapStyle={{ paddingHorizontal: 0 }}
411
412
  titleStyle={{ marginRight: 0, marginLeft: 0 }}
412
413
  subTitle={!hideDeliveryDate && <OText size={12} lineHeight={18} color={theme.colors.textNormal}>
413
- {
414
- activeStatus.includes(order?.status)
415
- ? order?.eta_time + 'min'
416
- : order?.delivery_datetime_utc
417
- ? parseDate(order?.delivery_datetime_utc)
418
- : parseDate(order?.delivery_datetime, { utc: false })
419
- }
414
+ {activeStatus.includes(order?.status) ? (
415
+ <OrderEta order={order} />
416
+ ) : (
417
+ parseDate(order?.reporting_data?.at[`status:${order.status}`])
418
+ )}
420
419
  </OText>}
421
420
  />
422
421
  {enabledPoweredByOrdering && (
@@ -12,6 +12,7 @@ import { NotFoundSource } from '../NotFoundSource'
12
12
  import { View, StyleSheet, TouchableOpacity, Platform } from 'react-native'
13
13
  import { Placeholder, Fade, PlaceholderLine } from "rn-placeholder";
14
14
  import FastImage from 'react-native-fast-image'
15
+ import { OrderEta } from '../OrderDetails/OrderEta'
15
16
  import {
16
17
  ProgressContentWrapper,
17
18
  ProgressBar,
@@ -33,7 +34,7 @@ const OrderProgressUI = (props: any) => {
33
34
  const theme = useTheme();
34
35
 
35
36
  const [, t] = useLanguage()
36
- const [{ optimizeImage, parseDate, parseTime }] = useUtils()
37
+ const [{ optimizeImage, parseTime }] = useUtils()
37
38
  const [lastOrder, setLastOrder] = useState<any>(null)
38
39
  const imageFails = theme.images.general.emptyActiveOrders
39
40
  const [initialLoaded, setInitialLoaded] = useState(false)
@@ -76,15 +77,6 @@ const OrderProgressUI = (props: any) => {
76
77
  }
77
78
  });
78
79
 
79
- const convertDiffToHours = (order: any) => {
80
- const minute = order?.eta_time
81
- const deliveryTime = order?.delivery_datetime_utc
82
- ? parseDate(order?.delivery_datetime_utc, { outputFormat: 'YYYY-MM-DD HH:mm' })
83
- : parseDate(order?.delivery_datetime, { utc: false, outputFormat: 'YYYY-MM-DD HH:mm' })
84
- const returnedDate = moment(deliveryTime).add(minute, 'minutes').format('hh:mm A')
85
- return returnedDate
86
- }
87
-
88
80
  const handleGoToOrder = (index: string) => {
89
81
  navigation && navigation.navigate(index)
90
82
  }
@@ -171,7 +163,7 @@ const OrderProgressUI = (props: any) => {
171
163
  ? parseTime(lastOrder?.delivery_datetime_utc, { outputFormat: 'hh:mm A' })
172
164
  : parseTime(lastOrder?.delivery_datetime, { utc: false })}
173
165
  &nbsp;-&nbsp;
174
- {convertDiffToHours(lastOrder)}
166
+ <OrderEta order={lastOrder} outputFormat='hh:mm A' />
175
167
  </OText>
176
168
  </TimeWrapper>
177
169
  </ProgressTextWrapper>
@@ -10,7 +10,7 @@ import { useTheme } from 'styled-components/native';
10
10
  import { OIcon, OText, OButton } from '../shared';
11
11
  import { SingleOrderCardParams } from '../../types';
12
12
  import { OAlert } from '../../../../../src/components/shared'
13
-
13
+ import { OrderEta } from '../OrderDetails/OrderEta'
14
14
  import {
15
15
  InnerContainer,
16
16
  Logo,
@@ -333,7 +333,7 @@ const SingleOrderCardUI = (props: SingleOrderCardParams) => {
333
333
  {
334
334
  pastOrders
335
335
  ? order?.delivery_datetime_utc ? parseDate(order?.delivery_datetime_utc) : parseDate(order?.delivery_datetime, { utc: false })
336
- : order?.eta_time + 'min'
336
+ : <OrderEta order={order} />
337
337
  }
338
338
  </OText>
339
339
  )}
@@ -28,7 +28,7 @@ const StyledButton = styled.View<Props>`
28
28
  padding-right: 20px;
29
29
  position: relative;
30
30
  ${(props : any) => props?.theme?.general?.components?.buttons?.borderRadius && css`
31
- border-radius: ${props?.theme?.general?.components?.buttons?.borderRadius};
31
+ border-radius: ${props?.theme?.general?.components?.buttons?.borderRadius}px;
32
32
  `}
33
33
  `
34
34
  const StyledButtonDisabled = styled(StyledButton)`
@@ -119,7 +119,7 @@ const OButton = (props: Props): React.ReactElement => {
119
119
  style={{ width: props.isCircle ? 52 : props.style?.width, ...props.parentStyle }}
120
120
  disabled={props.isDisabledWithSameStyles}
121
121
  >
122
- <StyledButton style={props.bgColor ? { ...props.style, backgroundColor: props.bgColor, borderColor: props.borderColor } : props.style}>
122
+ <StyledButton style={props.bgColor ? { ...props.style, backgroundColor: props.bgColor, borderColor: props.borderColor, borderRadius: theme?.general?.components?.buttons?.borderRadius || props.style?.borderRadius} : {...props.style, borderRadius: theme?.general?.components?.buttons?.borderRadius || props.style?.borderRadius}}>
123
123
  {props.icon ? (
124
124
  <props.icon {...props.iconProps} />
125
125
  ) : null}