ordering-ui-react-native 0.21.30 → 0.21.31-testing

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.21.30",
3
+ "version": "0.21.31-testing",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -1,33 +1,22 @@
1
- import React, { useEffect, useState } from 'react';
2
- import {
3
- Modal,
4
- View,
5
- StyleSheet,
6
- Dimensions,
7
- TouchableOpacity
8
- } from 'react-native';
9
- import { useTheme } from 'styled-components/native'
10
1
  import moment from 'moment'
2
+ import { NewOrderNotification as NewOrderNotificationController, useApi, useEvent, useLanguage, useSession } from 'ordering-components/native'
3
+ import React, { useEffect, useState } from 'react'
4
+ import { Dimensions, Modal, StyleSheet, TouchableOpacity, View } from 'react-native'
5
+ import Sound from 'react-native-sound'
11
6
  import Icon from 'react-native-vector-icons/Feather'
7
+ import { useTheme } from 'styled-components/native'
12
8
 
13
- import {
14
- NewOrderNotification as NewOrderNotificationController,
15
- useApi,
16
- useEvent,
17
- useLanguage,
18
- useSession
19
- } from 'ordering-components/native'
20
-
21
- import TrackPlayer from 'react-native-track-player';
22
-
9
+ import { useLocation } from '../../hooks/useLocation'
23
10
  import { OIcon, OText } from '../shared'
24
11
  import { NotificationContainer } from './styles'
25
- import { useLocation } from '../../hooks/useLocation'
26
12
 
27
- const SOUND_LOOP_AMOUNT = 3
28
- const DURATION_BETWEEN_LOOP = 2000 // ms
13
+ Sound.setCategory('Playback', true)
14
+ Sound.setMode('Default')
15
+
29
16
  const windowWidth = Dimensions.get('screen').width
30
17
 
18
+ const SOUND_LOOP = 3
19
+
31
20
  const NewOrderNotificationUI = (props: any) => {
32
21
  const { isBusinessApp } = props
33
22
  const [events] = useEvent()
@@ -35,7 +24,7 @@ const NewOrderNotificationUI = (props: any) => {
35
24
  const [, t] = useLanguage()
36
25
  const [{ user, token }] = useSession()
37
26
  const [ordering] = useApi()
38
- const { getCurrentLocation } = useLocation()
27
+ const { getCurrentLocation } = useLocation();
39
28
  const [currentEvent, setCurrentEvent] = useState<any>(null)
40
29
 
41
30
  const evtList: any = {
@@ -56,28 +45,37 @@ const NewOrderNotificationUI = (props: any) => {
56
45
  },
57
46
  }
58
47
 
48
+ const soundSrc = 'https://d33aymufw4jvwf.cloudfront.net/notification.mp3' ?? theme.sounds.notification
49
+
50
+ const notificationSound = new Sound(soundSrc, '', () => { });
51
+
52
+ let _timeout: any = null
53
+ let times = 0
54
+
59
55
  const handleCloseEvents = () => {
56
+ notificationSound.stop()
60
57
  setCurrentEvent(null)
61
- }
62
-
63
- const playSoundNotification = () => {
64
- let count = 0;
65
- const intervalId = setInterval(() => {
66
- TrackPlayer.seekTo(0)
67
- TrackPlayer.play()
68
- setTimeout(() => {
69
- TrackPlayer.pause()
70
- count++
71
- if (count === SOUND_LOOP_AMOUNT) {
72
- clearInterval(intervalId);
73
- }
74
- }, 500) // sound duration divide by 2
75
- }, DURATION_BETWEEN_LOOP) // notification duration
58
+ clearInterval(_timeout)
76
59
  }
77
60
 
78
61
  const handlePlayNotificationSound = (eventObj: any = null) => {
79
62
  setCurrentEvent(eventObj)
80
- playSoundNotification()
63
+ if (times > 0) {
64
+ if (times === 3) {
65
+ times = 0
66
+ return
67
+ }
68
+ return
69
+ }
70
+ _timeout = setInterval(() => {
71
+ if (times < SOUND_LOOP) {
72
+ notificationSound.play()
73
+ times++
74
+ } else {
75
+ clearInterval(_timeout)
76
+ return
77
+ }
78
+ }, 2500)
81
79
  }
82
80
 
83
81
  const handleEventNotification = async (evtType: number, value: any) => {
@@ -98,15 +96,11 @@ const NewOrderNotificationUI = (props: any) => {
98
96
  handlePlayNotificationSound({ evt: 2, orderId: value?.id })
99
97
  }
100
98
  }
101
- if (evtType === 3 || value?.author_id === user.id) return
102
- handlePlayNotificationSound({
99
+ if (evtType === 3 || value.author_id === user.id) return
100
+ setTimeout(() => handlePlayNotificationSound({
103
101
  evt: evtType,
104
- orderId: value?.driver
105
- ? value?.order_id
106
- : evtList[evtType].event === 'messages'
107
- ? value?.order?.id
108
- : value?.order_id ?? value?.id
109
- })
102
+ orderId: value?.driver ? value?.order_id : evtList[evtType].event === 'messages' ? value?.order?.id : value?.order_id
103
+ }), 1000)
110
104
  }
111
105
 
112
106
  useEffect(() => {
@@ -126,46 +120,46 @@ const NewOrderNotificationUI = (props: any) => {
126
120
  }, [])
127
121
 
128
122
  useEffect(() => {
129
- return () => {
130
- handleCloseEvents()
131
- }
123
+ return () => handleCloseEvents()
132
124
  }, [])
133
125
 
134
126
  return (
135
- <Modal
136
- animationType='slide'
137
- transparent={true}
138
- visible={!!currentEvent?.orderId}
139
- >
140
- <NotificationContainer>
141
- <View style={styles.modalView}>
142
- <TouchableOpacity
143
- style={styles.wrapperIcon}
144
- onPress={() => handleCloseEvents()}
145
- >
146
- <Icon name="x" size={30} />
147
- </TouchableOpacity>
148
- <OText
149
- size={18}
150
- color={theme.colors.textGray}
151
- weight={600}
152
- >
153
- {evtList[currentEvent?.evt]?.message}
154
- </OText>
155
- <OIcon
156
- src={theme.images.general.newOrder}
157
- width={250}
158
- height={200}
159
- />
160
- <OText
161
- color={theme.colors.textGray}
162
- mBottom={15}
163
- >
164
- {evtList[currentEvent?.evt]?.message2}
165
- </OText>
166
- </View>
167
- </NotificationContainer>
168
- </Modal>
127
+ <>
128
+ <Modal
129
+ animationType='slide'
130
+ transparent={true}
131
+ visible={!!currentEvent?.orderId}
132
+ >
133
+ <NotificationContainer>
134
+ <View style={styles.modalView}>
135
+ <TouchableOpacity
136
+ style={styles.wrapperIcon}
137
+ onPress={() => handleCloseEvents()}
138
+ >
139
+ <Icon name="x" size={30} />
140
+ </TouchableOpacity>
141
+ <OText
142
+ size={18}
143
+ color={theme.colors.textGray}
144
+ weight={600}
145
+ >
146
+ {evtList[currentEvent?.evt]?.message}
147
+ </OText>
148
+ <OIcon
149
+ src={theme.images.general.newOrder}
150
+ width={250}
151
+ height={200}
152
+ />
153
+ <OText
154
+ color={theme.colors.textGray}
155
+ mBottom={15}
156
+ >
157
+ {evtList[currentEvent?.evt]?.message2}
158
+ </OText>
159
+ </View>
160
+ </NotificationContainer>
161
+ </Modal>
162
+ </>
169
163
  )
170
164
  }
171
165
 
@@ -117,9 +117,11 @@ const PaymentOptionsUI = (props: any) => {
117
117
  // { name: t('SELECT_A_PAYMENT_METHOD', 'Select a payment method'), value: '-1' },
118
118
  // ]
119
119
 
120
+ const paymethodsFieldRequired = ['paypal', 'apple_pay', 'global_apple_pay', 'google_pay', 'global_google_pay']
121
+
120
122
  const handlePaymentMethodClick = (paymethod: any) => {
121
123
  if (cart?.balance > 0) {
122
- if (paymethod?.gateway === 'paypal' && requiredFields.length > 0) {
124
+ if (paymethodsFieldRequired.includes(paymethod?.gateway) && requiredFields.length > 0) {
123
125
  openUserModal && openUserModal(true)
124
126
  setPaymethodClicked({
125
127
  confirmed: false,