ordering-ui-react-native 0.21.32-test → 0.21.33-test
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
|
@@ -23,57 +23,80 @@ import { OIcon, OText } from '../shared'
|
|
|
23
23
|
import { NotificationContainer } from './styles'
|
|
24
24
|
import { useLocation } from '../../hooks/useLocation'
|
|
25
25
|
|
|
26
|
-
const
|
|
27
|
-
const DELAY_SOUND = 2000 // 2 sec
|
|
26
|
+
const DELAY_SOUND = 2500 // 2 sec
|
|
28
27
|
const windowWidth = Dimensions.get('screen').width
|
|
29
28
|
|
|
30
|
-
const
|
|
31
|
-
const {
|
|
32
|
-
|
|
29
|
+
const SoundPlayerComponent = (props: any) => {
|
|
30
|
+
const { evtList, currentEvent, handleCloseEvents } = props
|
|
31
|
+
|
|
33
32
|
const theme = useTheme()
|
|
34
|
-
const [,
|
|
35
|
-
const [{ user, token }] = useSession()
|
|
36
|
-
const [ordering] = useApi()
|
|
37
|
-
const { getCurrentLocation } = useLocation()
|
|
38
|
-
const [currentEvent, setCurrentEvent] = useState<any>(null)
|
|
33
|
+
const [count, setCount] = useState(0);
|
|
39
34
|
|
|
40
35
|
const URL_SOUND = 'https://d33aymufw4jvwf.cloudfront.net/notification.mp3' ?? theme.sounds.notification
|
|
41
36
|
|
|
42
|
-
|
|
43
|
-
1
|
|
44
|
-
event: 'messages',
|
|
45
|
-
message: t('NEW_MESSAGES_RECEIVED', 'New messages have been received!'),
|
|
46
|
-
message2: t('ORDER_N_UNREAD_MESSAGES', 'Order #_order_id_ has unread messages.').replace('_order_id_', currentEvent?.orderId),
|
|
47
|
-
},
|
|
48
|
-
2: {
|
|
49
|
-
event: 'order_added',
|
|
50
|
-
message: t('NEW_ORDERS_RECEIVED', 'New orders have been received!'),
|
|
51
|
-
message2: t('ORDER_N_ORDERED', 'Order #_order_id_ has been ordered.').replace('_order_id_', currentEvent?.orderId),
|
|
52
|
-
},
|
|
53
|
-
3: {
|
|
54
|
-
event: 'order_updated',
|
|
55
|
-
message: t('NEW_ORDERS_UPDATED', 'New orders have been updated!'),
|
|
56
|
-
message2: t('ORDER_N_UPDATED', 'Order #_order_id_ has been updated.').replace('_order_id_', currentEvent?.orderId),
|
|
57
|
-
},
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const handleCloseEvents = () => {
|
|
61
|
-
setCurrentEvent(null)
|
|
62
|
-
SoundPlayer.stop();
|
|
63
|
-
}
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
const id = setInterval(() => setCount(count + 1), 2500)
|
|
64
39
|
|
|
65
|
-
|
|
66
|
-
for (let i = 0; i < SOUND_REPETITIONS; i++) {
|
|
40
|
+
const playSound = async () => {
|
|
67
41
|
SoundPlayer.playUrl(URL_SOUND)
|
|
68
|
-
await new Promise(resolve => setTimeout(resolve, DELAY_SOUND))
|
|
69
|
-
SoundPlayer.stop()
|
|
42
|
+
await new Promise(resolve => setTimeout(resolve, DELAY_SOUND))
|
|
43
|
+
SoundPlayer.stop()
|
|
70
44
|
}
|
|
71
|
-
}
|
|
72
45
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
46
|
+
playSound()
|
|
47
|
+
|
|
48
|
+
return () => {
|
|
49
|
+
SoundPlayer.stop()
|
|
50
|
+
clearInterval(id);
|
|
51
|
+
}
|
|
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)
|
|
77
100
|
|
|
78
101
|
const handleEventNotification = async (evtType: number, value: any) => {
|
|
79
102
|
if (value?.driver) {
|
|
@@ -90,15 +113,15 @@ const NewOrderNotificationUI = (props: any) => {
|
|
|
90
113
|
const duration = moment.duration(moment().diff(moment.utc(value?.last_driver_assigned_at)))
|
|
91
114
|
const assignedSecondsDiff = duration.asSeconds()
|
|
92
115
|
if (assignedSecondsDiff < 5 && !isBusinessApp && !value?.logistic_status) {
|
|
93
|
-
|
|
116
|
+
setCurrentEvent({ evt: 2, orderId: value?.id })
|
|
94
117
|
}
|
|
95
118
|
}
|
|
96
119
|
if (evtType === 3 || value?.author_id === user.id) return
|
|
97
|
-
|
|
120
|
+
setCurrentEvent({
|
|
98
121
|
evt: evtType,
|
|
99
122
|
orderId: value?.driver
|
|
100
123
|
? value?.order_id
|
|
101
|
-
: evtList[evtType].event === 'messages'
|
|
124
|
+
: evtList(currentEvent)[evtType].event === 'messages'
|
|
102
125
|
? value?.order?.id
|
|
103
126
|
: value?.order_id ?? value?.id
|
|
104
127
|
})
|
|
@@ -121,48 +144,21 @@ const NewOrderNotificationUI = (props: any) => {
|
|
|
121
144
|
}, [])
|
|
122
145
|
|
|
123
146
|
useEffect(() => {
|
|
124
|
-
return () =>
|
|
147
|
+
return () => setCurrentEvent(null)
|
|
125
148
|
}, [])
|
|
126
149
|
|
|
127
150
|
return (
|
|
128
151
|
<>
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
<TouchableOpacity
|
|
137
|
-
style={styles.wrapperIcon}
|
|
138
|
-
onPress={() => handleCloseEvents()}
|
|
139
|
-
>
|
|
140
|
-
<Icon name="x" size={30} />
|
|
141
|
-
</TouchableOpacity>
|
|
142
|
-
<OText
|
|
143
|
-
size={18}
|
|
144
|
-
color={theme.colors.textGray}
|
|
145
|
-
weight={600}
|
|
146
|
-
>
|
|
147
|
-
{evtList[currentEvent?.evt]?.message}
|
|
148
|
-
</OText>
|
|
149
|
-
<OIcon
|
|
150
|
-
src={theme.images.general.newOrder}
|
|
151
|
-
width={250}
|
|
152
|
-
height={200}
|
|
153
|
-
/>
|
|
154
|
-
<OText
|
|
155
|
-
color={theme.colors.textGray}
|
|
156
|
-
mBottom={15}
|
|
157
|
-
>
|
|
158
|
-
{evtList[currentEvent?.evt]?.message2}
|
|
159
|
-
</OText>
|
|
160
|
-
</View>
|
|
161
|
-
</NotificationContainer>
|
|
162
|
-
</Modal>
|
|
152
|
+
{!!currentEvent ? (
|
|
153
|
+
<SoundPlayerComponent
|
|
154
|
+
evtList={evtList}
|
|
155
|
+
currentEvent={currentEvent}
|
|
156
|
+
handleCloseEvents={() => setCurrentEvent(null)}
|
|
157
|
+
/>
|
|
158
|
+
) : null}
|
|
163
159
|
</>
|
|
164
160
|
)
|
|
165
|
-
}
|
|
161
|
+
};
|
|
166
162
|
|
|
167
163
|
const styles = StyleSheet.create({
|
|
168
164
|
modalView: {
|
|
@@ -182,9 +178,28 @@ const styles = StyleSheet.create({
|
|
|
182
178
|
})
|
|
183
179
|
|
|
184
180
|
export const NewOrderNotification = (props: any) => {
|
|
181
|
+
const [, t] = useLanguage()
|
|
182
|
+
|
|
185
183
|
const newOrderNotificationProps = {
|
|
186
184
|
...props,
|
|
187
|
-
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
|
+
})
|
|
188
203
|
};
|
|
189
204
|
|
|
190
205
|
return <NewOrderNotificationController {...newOrderNotificationProps} />;
|