ordering-ui-react-native 0.21.31-test → 0.21.32

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.31-test",
3
+ "version": "0.21.32",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -386,21 +386,30 @@ const ChatUI = (props: MessagesParams) => {
386
386
  style={{ ...styles.firstMessageText, textAlign: 'center' }}
387
387
  >
388
388
  {
389
- message.change?.attribute !== 'driver_id'
390
- ?
391
- `${t('ORDER', 'Order')} ${t(message.change.attribute.toUpperCase(), message.change.attribute.replace('_', ' '))} ${t('CHANGED_FROM', 'Changed from')} ${filterSpecialStatus.includes(message.change.attribute)
392
- ? `${message.change.old === null ? '0' : message.change.old} ${t('TO', 'to')} ${message.change.new} ${t('MINUTES', 'Minutes')}`
393
- : `${message.change?.attribute !== 'logistic_status'
394
- ? message.change.old !== null && t(ORDER_STATUS[parseInt(message.change.old, 10)])
395
- : message.change.old !== null && getLogisticTag(message.change.old)} ${t('TO', 'to')} ${message.change?.attribute !== 'logistic_status'
396
- ? t(ORDER_STATUS[parseInt(message.change.new, 10)])
397
- : getLogisticTag(message.change.new)}`
398
- }`
399
- : message.change.new
389
+ message.change?.attribute === 'driver_group_id'
390
+ ? message.change.old
391
+ ? t('ORDER_ATTRIBUTE_CHANGED_FROM_TO')
392
+ .replace('_attribute_', t(message.change?.attribute.toUpperCase()).toLowerCase())
393
+ .replace('_from_', message.change.old)
394
+ .replace('_to_', message.change.new)
395
+ : t('ORDER_ATTRIBUTE_CHANGED_TO')
396
+ .replace('_attribute_', t(message.change?.attribute.toUpperCase()).toLowerCase())
397
+ .replace('_to_', message.change.new)
398
+ : message.change?.attribute !== 'driver_id'
400
399
  ?
401
- `${message.driver?.name} ${message.driver?.lastname !== null ? message.driver.lastname : ''} ${t('WAS_ASSIGNED_AS_DRIVER', 'Was assigned as driver')} ${message.comment ? message.comment.length : ''}`
402
- :
403
- `${t('DRIVER_UNASSIGNED', 'Driver unassigned')}`
400
+ `${t('ORDER', 'Order')} ${t(message.change.attribute.toUpperCase(), message.change.attribute.replace('_', ' '))} ${t('CHANGED_FROM', 'Changed from')} ${filterSpecialStatus.includes(message.change.attribute)
401
+ ? `${message.change.old === null ? '0' : message.change.old} ${t('TO', 'to')} ${message.change.new} ${t('MINUTES', 'Minutes')}`
402
+ : `${message.change?.attribute !== 'logistic_status'
403
+ ? message.change.old !== null && t(ORDER_STATUS[parseInt(message.change.old, 10)])
404
+ : message.change.old !== null && getLogisticTag(message.change.old)} ${t('TO', 'to')} ${message.change?.attribute !== 'logistic_status'
405
+ ? t(ORDER_STATUS[parseInt(message.change.new, 10)])
406
+ : getLogisticTag(message.change.new)}`
407
+ }`
408
+ : message.change.new
409
+ ?
410
+ `${message.driver?.name} ${message.driver?.lastname !== null ? message.driver.lastname : ''} ${t('WAS_ASSIGNED_AS_DRIVER', 'Was assigned as driver')} ${message.comment ? message.comment.length : ''}`
411
+ :
412
+ `${t('DRIVER_UNASSIGNED', 'Driver unassigned')}`
404
413
  }
405
414
  </OText>
406
415
  <OText size={10} color={'#aaa'} style={{ alignSelf: 'flex-start' }}>
@@ -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(() => {
@@ -106,6 +106,7 @@ const BusinessInformationUI = (props: BusinessInformationParams) => {
106
106
  location={businessLocation.location}
107
107
  markerTitle={businessState?.business?.name}
108
108
  businessZones={businessState?.business?.zones}
109
+ delta={30}
109
110
  />
110
111
  </WrapBusinessMap>
111
112
  )}
@@ -192,6 +192,7 @@ const CheckoutUI = (props: any) => {
192
192
  }, cart?.subtotal)
193
193
 
194
194
  const validateCommentsCartField = validationFields?.fields?.checkout?.comments?.enabled && validationFields?.fields?.checkout?.comments?.required && (cart?.comment === null || cart?.comment?.trim().length === 0)
195
+ const validateZipcodeCard = validationFields?.fields?.card?.zipcode?.enabled && validationFields?.fields?.card?.zipcode?.required && !paymethodSelected?.data?.card?.zipcode
195
196
 
196
197
  const isDisabledButtonPlace = loading || !cart?.valid || (!paymethodSelected && cart?.balance > 0) ||
197
198
  placing || errorCash || subtotalWithTaxes < cart?.minimum ||
@@ -200,7 +201,8 @@ const CheckoutUI = (props: any) => {
200
201
  validationFields?.fields?.checkout?.driver_tip?.enabled &&
201
202
  validationFields?.fields?.checkout?.driver_tip?.required &&
202
203
  (Number(cart?.driver_tip) <= 0)) ||
203
- (validateCommentsCartField)
204
+ (validateCommentsCartField) ||
205
+ (validateZipcodeCard)
204
206
  || (methodsPay.includes(paymethodSelected?.gateway) && (!methodPaySupported.enabled || methodPaySupported.loading))
205
207
 
206
208
  const driverTipsOptions = typeof configs?.driver_tip_options?.value === 'string'
@@ -896,6 +898,15 @@ const CheckoutUI = (props: any) => {
896
898
  {t('WARNING_INVALID_CART_COMMENTS', 'Cart comments is required.')}
897
899
  </OText>
898
900
  )}
901
+
902
+ {validateZipcodeCard && (
903
+ <OText
904
+ color={theme.colors.error}
905
+ size={12}
906
+ >
907
+ {t('WARNING_CARD_ZIPCODE_REQUIRED', 'Your card selected has not zipcode')}
908
+ </OText>
909
+ )}
899
910
  </ChErrors>
900
911
  </View>
901
912
  )}
@@ -20,7 +20,8 @@ export const GoogleMap = (props: GoogleMapsParams) => {
20
20
  handleToggleMap,
21
21
  locations,
22
22
  isIntGeoCoder,
23
- businessZones
23
+ businessZones,
24
+ delta
24
25
  } = props
25
26
 
26
27
  const [, t] = useLanguage()
@@ -31,8 +32,8 @@ export const GoogleMap = (props: GoogleMapsParams) => {
31
32
  const [region, setRegion] = useState({
32
33
  latitude: location.lat,
33
34
  longitude: location.lng,
34
- latitudeDelta: 0.0010,
35
- longitudeDelta: 0.0010 * ASPECT_RATIO
35
+ latitudeDelta: delta ?? 0.0010,
36
+ longitudeDelta: (delta ?? 0.0010) * ASPECT_RATIO
36
37
  })
37
38
  const [MARKERS, SETMARKERS] = useState(locations)
38
39
  let mapRef = useRef<any>(null)
@@ -265,7 +266,7 @@ export const GoogleMap = (props: GoogleMapsParams) => {
265
266
  )}
266
267
  {(businessZone.type === 5 && businessZone?.data?.distance) && (
267
268
  <Circle
268
- center={{ latitude: businessZone?.data?.center.lat, longitude: businessZone?.data?.center.lng}}
269
+ center={{ latitude: center.lat, longitude: center.lng}}
269
270
  radius={businessZone?.data.distance * units[businessZone?.data?.unit]}
270
271
  fillColor={fillStyles.fillColor}
271
272
  strokeColor={fillStyles.strokeColor}
@@ -152,6 +152,7 @@ const MessagesUI = (props: MessagesParams) => {
152
152
  }
153
153
  const newMessage: any = [];
154
154
  messages.messages.map((message: any) => {
155
+ if (message.change?.attribute === 'driver_group_id') return
155
156
  if (business && message.type !== 0 && (messagesToShow?.messages?.length || message?.can_see?.includes('2'))) {
156
157
  newMessage.push({
157
158
  _id: message?.id,
@@ -40,6 +40,9 @@ export const OSItem = styled.View`
40
40
  justify-content: space-between;
41
41
  align-items: center;
42
42
  padding: 10px 0px;
43
+ ${({ isInvalid } : any) => isInvalid && css`
44
+ opacity: 0.7;
45
+ `}
43
46
  `;
44
47
 
45
48
  export const OSItemContent = styled.TouchableOpacity`
@@ -4,6 +4,7 @@ import {
4
4
  PaymentOptionStripe,
5
5
  useSession,
6
6
  useLanguage,
7
+ useValidationFields
7
8
  } from 'ordering-components/native';
8
9
  import { PlaceholderLine } from 'rn-placeholder';
9
10
  import { useTheme } from 'styled-components/native';
@@ -40,10 +41,13 @@ export const StripeCardsListUI = (props: any) => {
40
41
 
41
42
  const [{ token }] = useSession();
42
43
  const [, t] = useLanguage();
43
-
44
+ const [validationFields] = useValidationFields()
45
+ const validateZipcodeCard =
46
+ validationFields?.fields?.card?.zipcode?.enabled && validationFields?.fields?.card?.zipcode?.required
44
47
  const paymethodsWithoutSaveCards = ['credomatic']
45
48
 
46
49
  const handleCardSelected = (card: any) => {
50
+ if (!card?.zipcode && validateZipcodeCard) return
47
51
  handleCardClick(card);
48
52
  onSelectCard(card);
49
53
  }
@@ -92,7 +96,8 @@ export const StripeCardsListUI = (props: any) => {
92
96
  style={styles.cardsList}
93
97
  >
94
98
  {cardsList.cards.map((card: any) => (
95
- <OSItem key={card.id} isUnique={cardsList.cards.length}>
99
+ <OSItem key={card.id} isUnique={cardsList.cards.length} isInvalid={!card?.zipcode && validateZipcodeCard}>
100
+ {console.log(card?.zipcode && validateZipcodeCard)}
96
101
  <OSItemContent onPress={() => handleCardSelected(card)}>
97
102
  <View style={styles.viewStyle}>
98
103
  {card.id === cardSelected?.id ? (
@@ -117,6 +122,13 @@ export const StripeCardsListUI = (props: any) => {
117
122
  XXXX-XXXX-XXXX-{card.last4}
118
123
  </OText>
119
124
  </View>
125
+ {!card?.zipcode && validateZipcodeCard && (
126
+ <View style={styles.viewStyle}>
127
+ <OText size={10} color={theme?.colors?.danger5}>
128
+ ({t('MISSING_ZIPCODE', 'Missing zipcode')})
129
+ </OText>
130
+ </View>
131
+ )}
120
132
  </OSItemContent>
121
133
  <OSItemActions>
122
134
  <OAlert
@@ -636,6 +636,7 @@ export interface GoogleMapsParams {
636
636
  handleToggleMap?: () => void,
637
637
  isIntGeoCoder: boolean,
638
638
  businessZones?: any
639
+ delta?: number
639
640
  }
640
641
 
641
642
  export interface HelpParams {