ordering-ui-react-native 0.17.75-release → 0.17.76-release
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,82 +1,102 @@
|
|
|
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'
|
|
1
10
|
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'
|
|
6
11
|
import Icon from 'react-native-vector-icons/Feather'
|
|
7
|
-
import
|
|
12
|
+
import SoundPlayer from 'react-native-sound-player'
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
NewOrderNotification as NewOrderNotificationController,
|
|
16
|
+
useApi,
|
|
17
|
+
useEvent,
|
|
18
|
+
useLanguage,
|
|
19
|
+
useSession
|
|
20
|
+
} from 'ordering-components/native'
|
|
8
21
|
|
|
9
|
-
import { useLocation } from '../../hooks/useLocation'
|
|
10
22
|
import { OIcon, OText } from '../shared'
|
|
11
23
|
import { NotificationContainer } from './styles'
|
|
24
|
+
import { useLocation } from '../../hooks/useLocation'
|
|
12
25
|
|
|
13
|
-
|
|
14
|
-
Sound.setMode('Default')
|
|
15
|
-
|
|
26
|
+
const DELAY_SOUND = 2500 // 2 sec
|
|
16
27
|
const windowWidth = Dimensions.get('screen').width
|
|
17
28
|
|
|
18
|
-
const
|
|
29
|
+
const SoundPlayerComponent = (props: any) => {
|
|
30
|
+
const { evtList, currentEvent, handleCloseEvents } = props
|
|
19
31
|
|
|
20
|
-
const NewOrderNotificationUI = (props: any) => {
|
|
21
|
-
const { isBusinessApp } = props
|
|
22
|
-
const [events] = useEvent()
|
|
23
32
|
const theme = useTheme()
|
|
24
|
-
const [,
|
|
25
|
-
const [{ user, token }] = useSession()
|
|
26
|
-
const [ordering] = useApi()
|
|
27
|
-
const { getCurrentLocation } = useLocation();
|
|
28
|
-
const [currentEvent, setCurrentEvent] = useState<any>(null)
|
|
29
|
-
|
|
30
|
-
const evtList: any = {
|
|
31
|
-
1: {
|
|
32
|
-
event: 'messages',
|
|
33
|
-
message: t('NEW_MESSAGES_RECEIVED', 'New messages have been received!'),
|
|
34
|
-
message2: t('ORDER_N_UNREAD_MESSAGES', 'Order #_order_id_ has unread messages.').replace('_order_id_', currentEvent?.orderId),
|
|
35
|
-
},
|
|
36
|
-
2: {
|
|
37
|
-
event: 'order_added',
|
|
38
|
-
message: t('NEW_ORDERS_RECEIVED', 'New orders have been received!'),
|
|
39
|
-
message2: t('ORDER_N_ORDERED', 'Order #_order_id_ has been ordered.').replace('_order_id_', currentEvent?.orderId),
|
|
40
|
-
},
|
|
41
|
-
3: {
|
|
42
|
-
event: 'order_updated',
|
|
43
|
-
message: t('NEW_ORDERS_UPDATED', 'New orders have been updated!'),
|
|
44
|
-
message2: t('ORDER_N_UPDATED', 'Order #_order_id_ has been updated.').replace('_order_id_', currentEvent?.orderId),
|
|
45
|
-
},
|
|
46
|
-
}
|
|
33
|
+
const [count, setCount] = useState(0);
|
|
47
34
|
|
|
48
|
-
const
|
|
35
|
+
const URL_SOUND = 'https://d33aymufw4jvwf.cloudfront.net/notification.mp3' ?? theme.sounds.notification
|
|
49
36
|
|
|
50
|
-
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
const id = setInterval(() => setCount(count + 1), 2500)
|
|
51
39
|
|
|
52
|
-
|
|
53
|
-
|
|
40
|
+
const playSound = async () => {
|
|
41
|
+
SoundPlayer.playUrl(URL_SOUND)
|
|
42
|
+
await new Promise(resolve => setTimeout(resolve, DELAY_SOUND))
|
|
43
|
+
SoundPlayer.stop()
|
|
44
|
+
}
|
|
54
45
|
|
|
55
|
-
|
|
56
|
-
notificationSound.stop()
|
|
57
|
-
setCurrentEvent(null)
|
|
58
|
-
clearInterval(_timeout)
|
|
59
|
-
}
|
|
46
|
+
playSound()
|
|
60
47
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (times === 3) {
|
|
65
|
-
times = 0
|
|
66
|
-
return
|
|
67
|
-
}
|
|
68
|
-
return
|
|
48
|
+
return () => {
|
|
49
|
+
SoundPlayer.stop()
|
|
50
|
+
clearInterval(id);
|
|
69
51
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
52
|
+
}, [count])
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<Modal
|
|
56
|
+
animationType='slide'
|
|
57
|
+
transparent={true}
|
|
58
|
+
visible={!!currentEvent?.orderId}
|
|
59
|
+
>
|
|
60
|
+
<NotificationContainer>
|
|
61
|
+
<View style={styles.modalView}>
|
|
62
|
+
<TouchableOpacity
|
|
63
|
+
style={styles.wrapperIcon}
|
|
64
|
+
onPress={() => handleCloseEvents()}
|
|
65
|
+
>
|
|
66
|
+
<Icon name="x" size={30} />
|
|
67
|
+
</TouchableOpacity>
|
|
68
|
+
<OText
|
|
69
|
+
size={18}
|
|
70
|
+
color={theme.colors.textGray}
|
|
71
|
+
weight={600}
|
|
72
|
+
>
|
|
73
|
+
{evtList(currentEvent)[currentEvent?.evt]?.message}
|
|
74
|
+
</OText>
|
|
75
|
+
<OIcon
|
|
76
|
+
src={theme.images.general.newOrder}
|
|
77
|
+
width={250}
|
|
78
|
+
height={200}
|
|
79
|
+
/>
|
|
80
|
+
<OText
|
|
81
|
+
color={theme.colors.textGray}
|
|
82
|
+
mBottom={15}
|
|
83
|
+
>
|
|
84
|
+
{evtList(currentEvent)[currentEvent?.evt]?.message2}
|
|
85
|
+
</OText>
|
|
86
|
+
</View>
|
|
87
|
+
</NotificationContainer>
|
|
88
|
+
</Modal>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const NewOrderNotificationUI = (props: any) => {
|
|
93
|
+
const { isBusinessApp, evtList } = props
|
|
94
|
+
|
|
95
|
+
const [events] = useEvent()
|
|
96
|
+
const [{ user, token }] = useSession()
|
|
97
|
+
const [ordering] = useApi()
|
|
98
|
+
const { getCurrentLocation } = useLocation()
|
|
99
|
+
const [currentEvent, setCurrentEvent] = useState<any>(null)
|
|
80
100
|
|
|
81
101
|
const handleEventNotification = async (evtType: number, value: any) => {
|
|
82
102
|
if (value?.driver) {
|
|
@@ -93,14 +113,18 @@ const NewOrderNotificationUI = (props: any) => {
|
|
|
93
113
|
const duration = moment.duration(moment().diff(moment.utc(value?.last_driver_assigned_at)))
|
|
94
114
|
const assignedSecondsDiff = duration.asSeconds()
|
|
95
115
|
if (assignedSecondsDiff < 5 && !isBusinessApp && !value?.logistic_status) {
|
|
96
|
-
|
|
116
|
+
setCurrentEvent({ evt: 2, orderId: value?.id })
|
|
97
117
|
}
|
|
98
118
|
}
|
|
99
|
-
if (evtType === 3 || value
|
|
100
|
-
|
|
119
|
+
if (evtType === 3 || value?.author_id === user.id) return
|
|
120
|
+
setCurrentEvent({
|
|
101
121
|
evt: evtType,
|
|
102
|
-
orderId: value?.driver
|
|
103
|
-
|
|
122
|
+
orderId: value?.driver
|
|
123
|
+
? value?.order_id
|
|
124
|
+
: evtList(currentEvent)[evtType].event === 'messages'
|
|
125
|
+
? value?.order?.id
|
|
126
|
+
: value?.order_id ?? value?.id
|
|
127
|
+
})
|
|
104
128
|
}
|
|
105
129
|
|
|
106
130
|
useEffect(() => {
|
|
@@ -120,48 +144,21 @@ const NewOrderNotificationUI = (props: any) => {
|
|
|
120
144
|
}, [])
|
|
121
145
|
|
|
122
146
|
useEffect(() => {
|
|
123
|
-
return () =>
|
|
147
|
+
return () => setCurrentEvent(null)
|
|
124
148
|
}, [])
|
|
125
149
|
|
|
126
150
|
return (
|
|
127
151
|
<>
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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>
|
|
152
|
+
{!!currentEvent ? (
|
|
153
|
+
<SoundPlayerComponent
|
|
154
|
+
evtList={evtList}
|
|
155
|
+
currentEvent={currentEvent}
|
|
156
|
+
handleCloseEvents={() => setCurrentEvent(null)}
|
|
157
|
+
/>
|
|
158
|
+
) : null}
|
|
162
159
|
</>
|
|
163
160
|
)
|
|
164
|
-
}
|
|
161
|
+
};
|
|
165
162
|
|
|
166
163
|
const styles = StyleSheet.create({
|
|
167
164
|
modalView: {
|
|
@@ -181,9 +178,28 @@ const styles = StyleSheet.create({
|
|
|
181
178
|
})
|
|
182
179
|
|
|
183
180
|
export const NewOrderNotification = (props: any) => {
|
|
181
|
+
const [, t] = useLanguage()
|
|
182
|
+
|
|
184
183
|
const newOrderNotificationProps = {
|
|
185
184
|
...props,
|
|
186
|
-
UIComponent: NewOrderNotificationUI
|
|
185
|
+
UIComponent: NewOrderNotificationUI,
|
|
186
|
+
evtList: (currentEvent: any) => ({
|
|
187
|
+
1: {
|
|
188
|
+
event: 'messages',
|
|
189
|
+
message: t('NEW_MESSAGES_RECEIVED', 'New messages have been received!'),
|
|
190
|
+
message2: t('ORDER_N_UNREAD_MESSAGES', 'Order #_order_id_ has unread messages.').replace('_order_id_', currentEvent?.orderId),
|
|
191
|
+
},
|
|
192
|
+
2: {
|
|
193
|
+
event: 'order_added',
|
|
194
|
+
message: t('NEW_ORDERS_RECEIVED', 'New orders have been received!'),
|
|
195
|
+
message2: t('ORDER_N_ORDERED', 'Order #_order_id_ has been ordered.').replace('_order_id_', currentEvent?.orderId),
|
|
196
|
+
},
|
|
197
|
+
3: {
|
|
198
|
+
event: 'order_updated',
|
|
199
|
+
message: t('NEW_ORDERS_UPDATED', 'New orders have been updated!'),
|
|
200
|
+
message2: t('ORDER_N_UPDATED', 'Order #_order_id_ has been updated.').replace('_order_id_', currentEvent?.orderId),
|
|
201
|
+
},
|
|
202
|
+
})
|
|
187
203
|
};
|
|
188
204
|
|
|
189
205
|
return <NewOrderNotificationController {...newOrderNotificationProps} />;
|
|
@@ -6,12 +6,13 @@ import { Placeholder, PlaceholderLine, Fade } from 'rn-placeholder';
|
|
|
6
6
|
import FeatherIcon from 'react-native-vector-icons/Feather';
|
|
7
7
|
import FontistoIcon from 'react-native-vector-icons/Fontisto'
|
|
8
8
|
import AntDesignIcon from 'react-native-vector-icons/AntDesign'
|
|
9
|
+
|
|
9
10
|
import { useTheme } from 'styled-components/native';
|
|
10
11
|
import { DeviceOrientationMethods } from '../../../../../src/hooks/DeviceOrientation'
|
|
11
12
|
import { NotificationSetting } from '../../../../../src/components/NotificationSetting'
|
|
12
13
|
import { NewOrderNotification } from '../NewOrderNotification';
|
|
13
14
|
|
|
14
|
-
import { OText, OButton, OModal,
|
|
15
|
+
import { OText, OButton, OModal, OInput, OIcon } from '../shared';
|
|
15
16
|
import { NotFoundSource } from '../NotFoundSource';
|
|
16
17
|
import {
|
|
17
18
|
FiltersTab,
|
|
@@ -92,17 +93,14 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
|
|
|
92
93
|
const [{ parseDate }] = useUtils()
|
|
93
94
|
const [configState] = useConfig()
|
|
94
95
|
const [orientationState] = useDeviceOrientation();
|
|
95
|
-
const [, { showToast }] = useToast();
|
|
96
96
|
const [openSearchModal, setOpenSearchModal] = useState(false)
|
|
97
97
|
const [openSLASettingModal, setOpenSLASettingModal] = useState(false)
|
|
98
98
|
const [slaSettingTime, setSlaSettingTime] = useState(6000)
|
|
99
99
|
const [currentDeliveryType, setCurrentDeliveryType] = useState('Delivery')
|
|
100
100
|
const [search, setSearch] = useState(defaultSearchList)
|
|
101
101
|
const [selectedTabStatus, setSelectedTabStatus] = useState<any>([])
|
|
102
|
-
const [hour, setHour] = useState(0)
|
|
103
|
-
const [minute, setMinute] = useState(0)
|
|
104
102
|
const [openedSelect, setOpenedSelect] = useState('')
|
|
105
|
-
|
|
103
|
+
|
|
106
104
|
const HEIGHT_SCREEN = orientationState?.dimensions?.height
|
|
107
105
|
const IS_PORTRAIT = orientationState.orientation === PORTRAIT
|
|
108
106
|
|
|
@@ -926,8 +924,6 @@ export const Timer = () => {
|
|
|
926
924
|
|
|
927
925
|
export const OrdersOption = (props: OrdersOptionParams) => {
|
|
928
926
|
const [, t] = useLanguage();
|
|
929
|
-
const [configState] = useConfig()
|
|
930
|
-
const theme = useTheme()
|
|
931
927
|
const [checkNotificationStatus, setCheckNotificationStatus] = useState({ open: false, checked: false })
|
|
932
928
|
const ordersProps = {
|
|
933
929
|
...props,
|