ordering-ui-react-native 0.15.4 → 0.15.7

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.15.4",
3
+ "version": "0.15.7",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -48,6 +48,8 @@
48
48
  "@react-navigation/material-bottom-tabs": "^5.3.14",
49
49
  "@react-navigation/native": "^5.7.6",
50
50
  "@react-navigation/stack": "^5.9.3",
51
+ "@segment/analytics-react-native": "^2.1.11",
52
+ "@segment/sovran-react-native": "^0.2.6",
51
53
  "@sentry/react-native": "^2.6.0",
52
54
  "@stripe/stripe-react-native": "^0.2.0",
53
55
  "@types/react-native-loading-spinner-overlay": "^0.5.2",
@@ -1,5 +1,6 @@
1
1
  import { AddressForm } from './src/components/AddressForm';
2
2
  import { AddressDetails } from './src/components/AddressDetails';
3
+ import { AnalyticsSegment } from './src/components/AnalyticsSegment';
3
4
  import { Home } from './src/components/Home';
4
5
  import { LoginForm } from './src/components/LoginForm';
5
6
  import { SignupForm } from './src/components/SignupForm';
@@ -67,6 +68,7 @@ import {
67
68
  export {
68
69
  AddressForm,
69
70
  AddressDetails,
71
+ AnalyticsSegment,
70
72
  Home as HomeView,
71
73
  SignupForm,
72
74
  LoginForm,
@@ -0,0 +1,127 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { createClient, AnalyticsProvider } from '@segment/analytics-react-native';
3
+ import { useEvent, useConfig } from 'ordering-components/native';
4
+
5
+ export const AnalyticsSegment = (props: any) => {
6
+ const { children } = props
7
+
8
+ const [events] = useEvent()
9
+ const [configState] = useConfig()
10
+ const [segmentClient, setSegmentClient] = useState<any>({})
11
+
12
+ const handleClickProduct = (product: any) => {
13
+ segmentClient.track('Product Clicked', {
14
+ id: product.id,
15
+ name: product.name,
16
+ category: product.category_id,
17
+ price: product.price
18
+ })
19
+ }
20
+
21
+ const handleProductAdded = (product: any) => {
22
+ segmentClient.track('Product Added', {
23
+ id: product.id,
24
+ name: product.name,
25
+ category: product.category_id,
26
+ price: product.price,
27
+ quantity: product.quantity
28
+ })
29
+ }
30
+
31
+ const handleProductRemoved = (product: any) => {
32
+ segmentClient.track('Product Removed', {
33
+ id: product.id,
34
+ name: product.name,
35
+ category: product.category_id,
36
+ price: product.price,
37
+ quantity: product.quantity
38
+ })
39
+ }
40
+
41
+ const handleOrderPlaced = (order: any) => {
42
+ segmentClient.track('Order Placed', {
43
+ id: order.id,
44
+ affiliation: order.business?.name,
45
+ revenue: order.total,
46
+ tax: order.tax_total,
47
+ shipping: order.delivery_zone_price
48
+ })
49
+ segmentClient.track('Payment Info Entered', {
50
+ order: order.id,
51
+ business: order.business?.name,
52
+ business_id: order.business_id,
53
+ total: order.total,
54
+ tax: order.tax_total,
55
+ delivery: order.delivery_zone_price,
56
+ paymethod: order.paymethod
57
+ })
58
+ }
59
+
60
+ const handleUpdateOrder = (order: any) => {
61
+ segmentClient.track('Order Updated', {
62
+ id: order.id,
63
+ affiliation: order.business?.name,
64
+ revenue: order.total,
65
+ tax: order.tax_total,
66
+ shipping: order.delivery_zone_price
67
+ })
68
+ }
69
+
70
+ const handleAddOrder = (order: any) => {
71
+ segmentClient.track('Order Added', {
72
+ id: order.id,
73
+ affiliation: order.business?.name,
74
+ revenue: order.total,
75
+ tax: order.tax_total,
76
+ shipping: order.delivery_zone_price
77
+ })
78
+ }
79
+
80
+ const handleLogin = (data: any) => {
81
+ segmentClient.identify(data.id, {
82
+ email: data.email,
83
+ name: data.name
84
+ })
85
+ }
86
+
87
+ useEffect(() => {
88
+ if (segmentClient?.config?.writeKey) {
89
+ events.on('product_clicked', handleClickProduct)
90
+ events.on('userLogin', handleLogin)
91
+ events.on('product_added', handleProductAdded)
92
+ events.on('order_placed', handleOrderPlaced)
93
+ events.on('order_updated', handleUpdateOrder)
94
+ events.on('order_added', handleAddOrder)
95
+ events.on('cart_product_removed', handleProductRemoved)
96
+ }
97
+ return () => {
98
+ if (segmentClient?.config?.writeKey) {
99
+ events.off('product_clicked', handleClickProduct)
100
+ events.off('userLogin', handleLogin)
101
+ events.off('product_added', handleProductAdded)
102
+ events.off('order_placed', handleOrderPlaced)
103
+ events.off('order_updated', handleUpdateOrder)
104
+ events.off('order_added', handleAddOrder)
105
+ events.off('cart_product_removed', handleProductRemoved)
106
+ }
107
+ }
108
+ }, [segmentClient])
109
+
110
+ useEffect(() => {
111
+ if (configState?.configs?.segment_track_id?.value) {
112
+ const _segmentClient: any = createClient({
113
+ writeKey: configState?.configs?.segment_track_id?.value
114
+ });
115
+ setSegmentClient(_segmentClient)
116
+ }
117
+ }, [configState])
118
+
119
+ return (
120
+ <>
121
+ <AnalyticsProvider client={segmentClient}>
122
+ {children}
123
+ </AnalyticsProvider>
124
+ </>
125
+
126
+ )
127
+ }
@@ -29,7 +29,7 @@ const types = ['food', 'laundry', 'alcohol', 'groceries'];
29
29
  export const BusinessBasicInformation = (
30
30
  props: BusinessBasicInformationParams,
31
31
  ) => {
32
- const { navigation, businessState, isBusinessInfoShow, logo, header } = props;
32
+ const { navigation, businessState, isBusinessInfoShow, logo, header, isPreOrder } = props;
33
33
  const { business, loading } = businessState;
34
34
 
35
35
  const theme = useTheme();
@@ -181,12 +181,16 @@ export const BusinessBasicInformation = (
181
181
  <WrapReviews>
182
182
  {!isBusinessInfoShow && (
183
183
  <>
184
- <TouchableOpacity onPress={() => navigation.navigate('BusinessPreorder', { business: businessState?.business, handleBusinessClick: () => navigation?.goBack() })}>
185
- <OText color={theme.colors.textSecondary} style={{ textDecorationLine: 'underline' }}>
186
- {t('PRE_ORDER', 'Preorder')}
187
- </OText>
188
- </TouchableOpacity>
189
- <OText size={12} color={theme.colors.textSecondary}>{' \u2022 '}</OText>
184
+ { isPreOrder && (
185
+ <>
186
+ <TouchableOpacity onPress={() => navigation.navigate('BusinessPreorder', { business: businessState?.business, handleBusinessClick: () => navigation?.goBack() })}>
187
+ <OText color={theme.colors.textSecondary} style={{ textDecorationLine: 'underline' }}>
188
+ {t('PRE_ORDER', 'Preorder')}
189
+ </OText>
190
+ </TouchableOpacity>
191
+ <OText size={12} color={theme.colors.textSecondary}>{' \u2022 '}</OText>
192
+ </>
193
+ )}
190
194
  <TouchableOpacity onPress={() => setOpenBusinessReviews(true)}>
191
195
  <OText color={theme.colors.textSecondary} style={{ textDecorationLine: 'underline' }}>
192
196
  {t('REVIEWS', 'Reviews')}
@@ -262,4 +266,4 @@ const styles = StyleSheet.create({
262
266
  zIndex: 100,
263
267
  left: 40
264
268
  },
265
- });
269
+ });
@@ -8,7 +8,8 @@ import {
8
8
  useSession,
9
9
  useUtils,
10
10
  ToastType,
11
- useToast
11
+ useToast,
12
+ useConfig
12
13
  } from 'ordering-components/native'
13
14
  import { OButton, OIcon, OModal, OText } from '../shared'
14
15
  import { BusinessBasicInformation } from '../BusinessBasicInformation'
@@ -52,7 +53,8 @@ const BusinessProductsListingUI = (props: BusinessProductsListingParams) => {
52
53
  const [orderState] = useOrder()
53
54
  const [{ parsePrice }] = useUtils()
54
55
  const [, { showToast }] = useToast()
55
-
56
+ const [{ configs }] = useConfig()
57
+ const isPreOrder = configs?.preorder_status_enabled?.value === '1'
56
58
  const styles = StyleSheet.create({
57
59
  mainContainer: {
58
60
  flex: 1,
@@ -231,6 +233,7 @@ const BusinessProductsListingUI = (props: BusinessProductsListingParams) => {
231
233
  openBusinessInformation={openBusinessInformation}
232
234
  header={header}
233
235
  logo={logo}
236
+ isPreOrder={isPreOrder}
234
237
  />
235
238
  <View style={{ height: 8, backgroundColor: theme.colors.backgroundGray100 }} />
236
239
  {!loading && business?.id && (
@@ -134,6 +134,7 @@ const CheckoutUI = (props: any) => {
134
134
 
135
135
 
136
136
  const isWalletEnabled = configs?.wallet_enabled?.value === '1' && (configs?.wallet_cash_enabled?.value === '1' || configs?.wallet_credit_point_enabled?.value === '1')
137
+ const isPreOrder = configs?.preorder_status_enabled?.value === '1'
137
138
 
138
139
  const driverTipsOptions = typeof configs?.driver_tip_options?.value === 'string'
139
140
  ? JSON.parse(configs?.driver_tip_options?.value) || []
@@ -149,6 +150,12 @@ const CheckoutUI = (props: any) => {
149
150
  }
150
151
  })
151
152
 
153
+ const handleMomentClick = () => {
154
+ if (isPreOrder) {
155
+ navigation.navigate('MomentOption')
156
+ }
157
+ }
158
+
152
159
  const handlePlaceOrder = () => {
153
160
  if (!userErrors.length) {
154
161
  handlerClickPlaceOrder && handlerClickPlaceOrder()
@@ -260,19 +267,21 @@ const CheckoutUI = (props: any) => {
260
267
  />
261
268
  </CHMomentWrapper>
262
269
  <CHMomentWrapper
263
- onPress={() => navigation.navigate('MomentOption')}
264
- disabled={loading}
270
+ onPress={() => handleMomentClick()}
271
+ disabled={loading}
265
272
  >
266
273
  <OText size={12} numberOfLines={1} ellipsizeMode='tail' color={theme.colors.textSecondary}>
267
274
  {options?.moment
268
275
  ? parseDate(options?.moment, { outputFormat: configs?.dates_moment_format?.value })
269
276
  : t('ASAP_ABBREVIATION', 'ASAP')}
270
277
  </OText>
271
- <OIcon
272
- src={theme.images.general.arrow_down}
273
- width={10}
274
- style={{ marginStart: 8 }}
275
- />
278
+ { isPreOrder && (
279
+ <OIcon
280
+ src={theme.images.general.arrow_down}
281
+ width={10}
282
+ style={{ marginStart: 8 }}
283
+ />
284
+ )}
276
285
  </CHMomentWrapper>
277
286
  </ChHeader>
278
287
  <View style={{ height: 8, backgroundColor: theme.colors.backgroundGray100, marginTop: 18, marginHorizontal: -40 }} />
@@ -290,7 +290,15 @@ export const ProductOptionsUI = (props: any) => {
290
290
  }
291
291
  if (img?.video) {
292
292
  const keys = img?.video.split('/')
293
- const _videoId = keys[keys.length - 1]
293
+ let _videoId = keys[keys.length - 1]
294
+ if (_videoId.includes('watch')) {
295
+ const __url = _videoId.split('=')[1]
296
+ _videoId = __url
297
+ }
298
+ if (_videoId.includes('?')) {
299
+ const __url = _videoId.split('?')[0]
300
+ _videoId = __url
301
+ }
294
302
  videoList.push(_videoId)
295
303
  }
296
304
  }
@@ -193,6 +193,7 @@ export interface BusinessBasicInformationParams {
193
193
  isBusinessInfoShow?: boolean;
194
194
  header?: any;
195
195
  logo?: any;
196
+ isPreOrder?: boolean;
196
197
  }
197
198
  export interface BusinessProductsCategoriesParams {
198
199
  categories: Array<any>;