ordering-ui-react-native 0.23.99 → 0.24.1

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.23.99",
3
+ "version": "0.24.1",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -4,10 +4,7 @@ import {
4
4
  View,
5
5
  StyleSheet,
6
6
  Dimensions,
7
- TouchableOpacity,
8
- NativeModules,
9
- PermissionsAndroid,
10
- Platform
7
+ TouchableOpacity
11
8
  } from 'react-native';
12
9
  import { useTheme } from 'styled-components/native'
13
10
  import moment from 'moment'
@@ -20,7 +17,6 @@ import {
20
17
  useEvent,
21
18
  useLanguage,
22
19
  useSession,
23
- useConfig,
24
20
  useToast,
25
21
  ToastType
26
22
  } from 'ordering-components/native'
@@ -36,48 +32,25 @@ const SoundPlayerComponent = (props: any) => {
36
32
  const { evtList, currentEvent, handleCloseEvents } = props
37
33
 
38
34
  const theme = useTheme()
39
- const [count, setCount] = useState(0);
40
- const [isEnabledReadStorage, setIsEnabledReadStorage] = useState(true)
41
- const URL_SOUND = 'https://d33aymufw4jvwf.cloudfront.net/notification.mp3' ?? theme.sounds.notification
35
+ const URL_SOUND = 'https://d33aymufw4jvwf.cloudfront.net/notification.mp3'
42
36
 
43
37
  useEffect(() => {
44
- const id = setInterval(() => setCount(count + 1), 2500)
45
-
46
- const playSound = async () => {
38
+ if (!currentEvent?.orderId) return
39
+ const playSound = () => {
47
40
  try {
48
41
  SoundPlayer.playUrl(URL_SOUND)
49
- await new Promise(resolve => setTimeout(resolve, DELAY_SOUND))
50
- SoundPlayer.stop()
51
- } catch (err: any) {
42
+ } catch (e) {
52
43
  console.log('Sound Error - ', err.message)
53
44
  }
54
45
  }
55
- if (NativeModules?.RNSoundPlayer?.playUrl && typeof URL_SOUND === 'string' && isEnabledReadStorage) {
56
- playSound()
57
- }
58
46
 
59
- return () => {
60
- clearInterval(id);
61
- try {
62
- SoundPlayer.stop()
63
- } catch (err: any) {
64
- console.log('Sound Error - ', err.message)
65
- }
66
- }
67
- }, [count, isEnabledReadStorage])
47
+ const interval = setInterval(() => {
48
+ playSound()
49
+ }, DELAY_SOUND)
68
50
 
69
- useEffect(() => {
70
- const checkSoundMedia = async () => {
71
- if (Platform.OS === 'android') {
72
- const enabled = await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE)
73
- setIsEnabledReadStorage(enabled)
74
- } else {
75
- setIsEnabledReadStorage(true)
76
- }
77
- }
78
- // checkSoundMedia()
51
+ return () => clearInterval(interval)
52
+ }, [currentEvent?.orderId])
79
53
 
80
- }, [])
81
54
  return (
82
55
  <Modal
83
56
  animationType='slide'
@@ -129,7 +102,7 @@ const NewOrderNotificationUI = (props: any) => {
129
102
  const handleEventNotification = async (evtType: number, value: any, orderStatus?: any) => {
130
103
  if (value?.driver) {
131
104
  try {
132
- const location = await getCurrentLocation()
105
+ const location: any = await getCurrentLocation()
133
106
  if (!location?.latitude || !location?.longitude) {
134
107
  showToast(t('ERROR_UPDATING_COORDS', 'Error updating coords'), ToastType.Error)
135
108
  return
@@ -154,18 +127,18 @@ const NewOrderNotificationUI = (props: any) => {
154
127
  const duration = moment.duration(moment().diff(moment.utc(value?.last_driver_assigned_at)))
155
128
  const assignedSecondsDiff = duration.asSeconds()
156
129
  if (assignedSecondsDiff < 5 && !isBusinessApp && !value?.logistic_status) {
157
- setCurrentEvent({ evt: 2, orderId: value?.id ?? value?.order_id })
130
+ setCurrentEvent(() => ({ evt: 2, orderId: value?.id ?? value?.order_id }))
158
131
  }
159
132
  }
160
133
  if ((!orderStatus.includes(value.status) && evtType !== 1 && isBusinessApp && orderStatus?.length > 0) || value?.author_id === user.id) return
161
- setCurrentEvent({
134
+ setCurrentEvent(() => ({
162
135
  evt: evtType,
163
136
  orderId: value?.driver
164
137
  ? value?.order_id ?? value?.id
165
138
  : evtList(currentEvent)[evtType].event === 'messages'
166
139
  ? value?.order?.id
167
140
  : value?.order_id ?? value?.id
168
- })
141
+ }))
169
142
  }
170
143
 
171
144
  useEffect(() => {
@@ -84,6 +84,7 @@ const CartUI = (props: any) => {
84
84
  const driverTipsOptions = typeof configs?.driver_tip_options?.value === 'string'
85
85
  ? JSON.parse(configs?.driver_tip_options?.value) || []
86
86
  : configs?.driver_tip_options?.value || []
87
+ const allowDriverTipPickup = configs?.driver_tip_allowed_at_pickup?.value === '1' && orderState?.options?.type === 2
87
88
 
88
89
  const momentFormatted = !orderState?.option?.moment
89
90
  ? t('RIGHT_NOW', 'Right Now')
@@ -465,7 +466,7 @@ const CartUI = (props: any) => {
465
466
  {!isMultiCheckout &&
466
467
  cart &&
467
468
  cart?.valid &&
468
- orderState?.options?.type === 1 &&
469
+ (orderState?.options?.type === 1 || allowDriverTipPickup) &&
469
470
  cart?.status !== 2 &&
470
471
  validationFields?.fields?.checkout?.driver_tip?.enabled &&
471
472
  driverTipsOptions && driverTipsOptions?.length > 0 &&
@@ -71,6 +71,8 @@ const mapConfigs = {
71
71
  }
72
72
  };
73
73
 
74
+ const driverTipsTypes = [1, 2]
75
+
74
76
  const manageErrorsToShow = (array = []) => {
75
77
  let stringError = ''
76
78
  const list = Array.isArray(array) ? array : Object.values(array)
@@ -184,7 +186,7 @@ const CheckoutUI = (props: any) => {
184
186
  const notFields = ['coupon', 'driver_tip', 'mobile_phone', 'address', 'zipcode', 'address_notes', 'comments']
185
187
 
186
188
  const checkoutFields = useMemo(() => checkoutFieldsState?.fields?.filter((field: any) => field.order_type_id === options?.type), [checkoutFieldsState, options])
187
- const guestCheckoutDriveTip = useMemo(() => checkoutFields?.find((field: any) => field.order_type_id === 1 && field?.validation_field?.code === 'driver_tip'), [JSON.stringify(checkoutFields), options])
189
+ const guestCheckoutDriveTip = useMemo(() => checkoutFields?.find((field: any) => driverTipsTypes.includes(field.order_type_id) && field?.validation_field?.code === 'driver_tip'), [JSON.stringify(checkoutFields), options])
188
190
  const guestCheckoutComment = useMemo(() => checkoutFields?.find((field: any) => field.order_type_id === options?.type && field?.validation_field?.code === 'comments'), [JSON.stringify(checkoutFields), options])
189
191
  const guestCheckoutCoupon = useMemo(() => checkoutFields?.find((field: any) => field.order_type_id === options?.type && field?.validation_field?.code === 'coupon'), [JSON.stringify(checkoutFields), options])
190
192
  const guestCheckoutZipcode = useMemo(() => checkoutFields?.find((field: any) => field.order_type_id === options?.type && field?.validation_field?.code === 'zipcode'), [JSON.stringify(checkoutFields), options])
@@ -213,9 +215,9 @@ const CheckoutUI = (props: any) => {
213
215
  return acc = acc + item?.summary?.tax
214
216
  return acc = acc
215
217
  }, cart?.subtotal)
216
-
218
+ const allowDriverTipPickup = configs?.driver_tip_allowed_at_pickup?.value === '1' && options?.type === 2
217
219
  const validateCommentsCartField = (guestCheckoutComment?.enabled && (user?.guest_id ? guestCheckoutComment?.required_with_guest : guestCheckoutComment?.required)) && (cart?.comment === null || cart?.comment?.trim().length === 0)
218
- const validateDriverTipField = options.type === 1 && (guestCheckoutDriveTip?.enabled && (user?.guest_id ? guestCheckoutDriveTip?.required_with_guest : guestCheckoutDriveTip?.required)) && (Number(cart?.driver_tip) <= 0)
220
+ const validateDriverTipField = (options.type === 1 || allowDriverTipPickup) && (guestCheckoutDriveTip?.enabled && (user?.guest_id ? guestCheckoutDriveTip?.required_with_guest : guestCheckoutDriveTip?.required)) && (Number(cart?.driver_tip) <= 0)
219
221
  const validateCouponField = (guestCheckoutCoupon?.enabled && (user?.guest_id ? guestCheckoutCoupon?.required_with_guest : guestCheckoutCoupon?.required)) && !cart?.offers?.some((offer: any) => offer?.type === 2)
220
222
  const validateZipcodeCard = (guestCheckoutZipcode?.enabled && (user?.guest_id ? guestCheckoutZipcode?.required_with_guest : guestCheckoutZipcode?.required)) && paymethodSelected?.gateway === 'stripe' && paymethodSelected?.data?.card && !paymethodSelected?.data?.card?.zipcode
221
223
 
@@ -236,7 +238,7 @@ const CheckoutUI = (props: any) => {
236
238
  const driverTipsOptions = typeof configs?.driver_tip_options?.value === 'string'
237
239
  ? JSON.parse(configs?.driver_tip_options?.value) || []
238
240
  : configs?.driver_tip_options?.value || []
239
- const driverTipsField = !cartState.loading && cart && cart?.business_id && options.type === 1 && cart?.status !== 2 && (guestCheckoutDriveTip?.enabled) && driverTipsOptions.length > 0
241
+ const driverTipsField = !cartState.loading && cart && cart?.business_id && (options.type === 1 || allowDriverTipPickup) && cart?.status !== 2 && (guestCheckoutDriveTip?.enabled) && driverTipsOptions.length > 0
240
242
 
241
243
  const configTypes = configs?.order_types_allowed?.value.split('|').map((value: any) => Number(value)) || []
242
244
 
@@ -103,6 +103,7 @@ const MultiCheckoutUI = (props: any) => {
103
103
  const configTypes = configs?.order_types_allowed?.value.split('|').map((value: any) => Number(value)) || []
104
104
  const isPreOrder = configs?.preorder_status_enabled?.value === '1'
105
105
  const isMultiDriverTips = configs?.checkout_multi_business_enabled?.value === '1'
106
+ const allowDriverTipPickup = configs?.driver_tip_allowed_at_pickup?.value === '1' && options?.type === 2
106
107
  const isGuestCheckoutEnabled = configs?.guest_checkout_enabled?.value === '1'
107
108
  const walletCarts = (Object.values(carts)?.filter((cart: any) => cart?.products && cart?.products?.length && cart?.status !== 2 && cart?.valid_schedule && cart?.valid_products && cart?.valid_address && cart?.valid_maximum && cart?.valid_minimum && cart?.wallets) || null) || []
108
109
  const isChewLayout = theme?.header?.components?.layout?.type?.toLowerCase() === 'chew'
@@ -494,7 +495,7 @@ const MultiCheckoutUI = (props: any) => {
494
495
  )}
495
496
  {
496
497
  isMultiDriverTips &&
497
- options?.type === 1 &&
498
+ (options?.type === 1 || allowDriverTipPickup) &&
498
499
  validationFields?.fields?.checkout?.driver_tip?.enabled &&
499
500
  openCarts.every((cart: any) => cart.business_id && cart.status !== 2) &&
500
501
  driverTipsOptions && driverTipsOptions?.length > 0 &&