ordering-ui-react-native 0.21.32 → 0.21.33

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.32",
3
+ "version": "0.21.33",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -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 { useTheme } from 'styled-components/native'
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
- Sound.setCategory('Playback', true)
14
- Sound.setMode('Default')
15
-
26
+ const DELAY_SOUND = 2500 // 2 sec
16
27
  const windowWidth = Dimensions.get('screen').width
17
28
 
18
- const SOUND_LOOP = 3
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 [, t] = useLanguage()
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 soundSrc = 'https://d33aymufw4jvwf.cloudfront.net/notification.mp3' ?? theme.sounds.notification
35
+ const URL_SOUND = 'https://d33aymufw4jvwf.cloudfront.net/notification.mp3' ?? theme.sounds.notification
49
36
 
50
- const notificationSound = new Sound(soundSrc, '', () => { });
37
+ useEffect(() => {
38
+ const id = setInterval(() => setCount(count + 1), 2500)
51
39
 
52
- let _timeout: any = null
53
- let times = 0
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
- const handleCloseEvents = () => {
56
- notificationSound.stop()
57
- setCurrentEvent(null)
58
- clearInterval(_timeout)
59
- }
46
+ playSound()
60
47
 
61
- const handlePlayNotificationSound = (eventObj: any = null) => {
62
- setCurrentEvent(eventObj)
63
- if (times > 0) {
64
- if (times === 3) {
65
- times = 0
66
- return
67
- }
68
- return
48
+ return () => {
49
+ SoundPlayer.stop()
50
+ clearInterval(id);
69
51
  }
70
- _timeout = setInterval(() => {
71
- if (times < SOUND_LOOP) {
72
- notificationSound.play()
73
- times++
74
- } else {
75
- clearInterval(_timeout)
76
- return
77
- }
78
- }, 2500)
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
- handlePlayNotificationSound({ evt: 2, orderId: value?.id })
116
+ setCurrentEvent({ evt: 2, orderId: value?.id })
97
117
  }
98
118
  }
99
- if (evtType === 3 || value.author_id === user.id) return
100
- setTimeout(() => handlePlayNotificationSound({
119
+ if (evtType === 3 || value?.author_id === user.id) return
120
+ setCurrentEvent({
101
121
  evt: evtType,
102
- orderId: value?.driver ? value?.order_id : evtList[evtType].event === 'messages' ? value?.order?.id : value?.order_id
103
- }), 1000)
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 () => handleCloseEvents()
147
+ return () => setCurrentEvent(null)
124
148
  }, [])
125
149
 
126
150
  return (
127
151
  <>
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>
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,18 +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
- import TrackPlayer, {
10
- RepeatMode,
11
- Capability,
12
- AppKilledPlaybackBehavior
13
- } from 'react-native-track-player';
14
9
 
15
10
  import { useTheme } from 'styled-components/native';
16
11
  import { DeviceOrientationMethods } from '../../../../../src/hooks/DeviceOrientation'
17
12
  import { NotificationSetting } from '../../../../../src/components/NotificationSetting'
18
13
  import { NewOrderNotification } from '../NewOrderNotification';
19
14
 
20
- import { OText, OButton, OModal, OIconButton, OInput, OIcon } from '../shared';
15
+ import { OText, OButton, OModal, OInput, OIcon } from '../shared';
21
16
  import { NotFoundSource } from '../NotFoundSource';
22
17
  import {
23
18
  FiltersTab,
@@ -98,93 +93,17 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
98
93
  const [{ parseDate }] = useUtils()
99
94
  const [configState] = useConfig()
100
95
  const [orientationState] = useDeviceOrientation();
101
- const [, { showToast }] = useToast();
102
96
  const [openSearchModal, setOpenSearchModal] = useState(false)
103
97
  const [openSLASettingModal, setOpenSLASettingModal] = useState(false)
104
98
  const [slaSettingTime, setSlaSettingTime] = useState(6000)
105
99
  const [currentDeliveryType, setCurrentDeliveryType] = useState('Delivery')
106
100
  const [search, setSearch] = useState(defaultSearchList)
107
101
  const [selectedTabStatus, setSelectedTabStatus] = useState<any>([])
108
- const [hour, setHour] = useState(0)
109
- const [minute, setMinute] = useState(0)
110
102
  const [openedSelect, setOpenedSelect] = useState('')
111
- const WIDTH_SCREEN = orientationState?.dimensions?.width
103
+
112
104
  const HEIGHT_SCREEN = orientationState?.dimensions?.height
113
105
  const IS_PORTRAIT = orientationState.orientation === PORTRAIT
114
106
 
115
- const URL_SOUND = 'https://d33aymufw4jvwf.cloudfront.net/notification.mp3' ?? theme.sounds.notification
116
-
117
- const setupPlayer = async (options: any) => {
118
- const setup = async () => {
119
- try {
120
- await TrackPlayer.setupPlayer(options);
121
- } catch (error) {
122
- return (error as Error & { code?: string }).code;
123
- }
124
- }
125
- while ((await setup()) === 'android_cannot_setup_player_in_background') {
126
- await new Promise<void>((resolve) => setTimeout(resolve, 1));
127
- }
128
- };
129
-
130
- const SetupService = async () => {
131
- await setupPlayer({ autoHandleInterruptions: true });
132
- await TrackPlayer.updateOptions({
133
- android: {
134
- appKilledPlaybackBehavior:
135
- AppKilledPlaybackBehavior.StopPlaybackAndRemoveNotification,
136
- },
137
- capabilities: [
138
- Capability.Play,
139
- Capability.Pause,
140
- Capability.SkipToNext,
141
- Capability.SkipToPrevious,
142
- Capability.SeekTo,
143
- ],
144
- compactCapabilities: [
145
- Capability.Play,
146
- Capability.Pause,
147
- Capability.SkipToNext,
148
- ],
149
- progressUpdateEventInterval: 2,
150
- });
151
- await TrackPlayer.setRepeatMode(RepeatMode.Track);
152
- };
153
-
154
- const QueueInitialTracksService = async () => {
155
- await TrackPlayer.add([
156
- {
157
- id: 'notification',
158
- url: URL_SOUND,
159
- title: 'notification'
160
- },
161
- ]);
162
- }
163
-
164
- function useSetupPlayer() {
165
- const [playerReady, setPlayerReady] = useState<boolean>(false)
166
-
167
- useEffect(() => {
168
- let unmounted = false;
169
- (async () => {
170
- await SetupService()
171
- if (unmounted) return
172
- setPlayerReady(true)
173
- const queue = await TrackPlayer.getQueue()
174
- if (unmounted) return
175
- if (queue.length <= 0) {
176
- await QueueInitialTracksService()
177
- }
178
- })();
179
- return () => {
180
- unmounted = true;
181
- };
182
- }, []);
183
- return playerReady;
184
- }
185
-
186
- const isPlayerReady = useSetupPlayer()
187
-
188
107
  const preorderTypeList = [
189
108
  { key: null, name: t('SLA', 'SLA\'s') },
190
109
  { key: 'in_time', name: t('OK', 'Ok') },
@@ -780,10 +699,7 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
780
699
  </View>
781
700
 
782
701
  {isBusinessApp && (
783
- <NewOrderNotification
784
- isBusinessApp={isBusinessApp}
785
- isPlayerReady={isPlayerReady}
786
- />
702
+ <NewOrderNotification isBusinessApp={isBusinessApp} />
787
703
  )}
788
704
 
789
705
  {(openSearchModal || openSLASettingModal) && (
@@ -1008,8 +924,6 @@ export const Timer = () => {
1008
924
 
1009
925
  export const OrdersOption = (props: OrdersOptionParams) => {
1010
926
  const [, t] = useLanguage();
1011
- const [configState] = useConfig()
1012
- const theme = useTheme()
1013
927
  const [checkNotificationStatus, setCheckNotificationStatus] = useState({ open: false, checked: false })
1014
928
  const ordersProps = {
1015
929
  ...props,
@@ -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']
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,