ordering-ui-react-native 0.22.55 → 0.22.56-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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ordering-ui-react-native",
3
- "version": "0.22.55",
3
+ "version": "0.22.56-test",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -133,6 +133,7 @@ const AddressFormUI = (props: AddressFormParams) => {
133
133
  const [configState] = useConfig();
134
134
  const [orderState] = useOrder();
135
135
  const { handleSubmit, errors, control, setValue } = useForm();
136
+ const [autoCompleteAddress, setAutoCompleteAddress] = useState(false)
136
137
 
137
138
  const [toggleMap, setToggleMap] = useState(false);
138
139
  const [alertState, setAlertState] = useState<{
@@ -572,6 +573,7 @@ const AddressFormUI = (props: AddressFormParams) => {
572
573
  placeholder={t('ADD_ADDRESS', 'Add a address')}
573
574
  onPress={(data, details: any) => {
574
575
  handleChangeAddress(data, details);
576
+ setAutoCompleteAddress(true);
575
577
  }}
576
578
  query={{
577
579
  key: googleMapsApiKey,
@@ -586,6 +588,7 @@ const AddressFormUI = (props: AddressFormParams) => {
586
588
  target: { name: 'address', value: text },
587
589
  });
588
590
  setValue('address', text);
591
+ setAutoCompleteAddress(true)
589
592
  }
590
593
  setIsFirstTime(false);
591
594
  setAddressEditing(text.length == 0);
@@ -673,6 +676,8 @@ const AddressFormUI = (props: AddressFormParams) => {
673
676
  setSaveLocation={setSaveMapLocation}
674
677
  handleToggleMap={handleToggleMap}
675
678
  isIntGeoCoder
679
+ setAutoCompleteAddress={setAutoCompleteAddress}
680
+ autoCompleteAddress={autoCompleteAddress}
676
681
  />
677
682
  </GoogleMapContainer>
678
683
  </View>
@@ -21,7 +21,9 @@ export const GoogleMap = (props: GoogleMapsParams) => {
21
21
  locations,
22
22
  isIntGeoCoder,
23
23
  businessZones,
24
- delta
24
+ delta,
25
+ autoCompleteAddress,
26
+ setAutoCompleteAddress
25
27
  } = props
26
28
 
27
29
  const [, t] = useLanguage()
@@ -59,7 +61,7 @@ export const GoogleMap = (props: GoogleMapsParams) => {
59
61
  strokeWidth: 2
60
62
  }
61
63
 
62
- const geocodePosition = (pos: { latitude: number, longitude: number }, isMovingRegion ?: boolean) => {
64
+ const geocodePosition = (pos: { latitude: number, longitude: number }, isMovingRegion?: boolean) => {
63
65
  Geocoder.from({
64
66
  latitude: pos.latitude,
65
67
  longitude: pos.longitude
@@ -84,7 +86,7 @@ export const GoogleMap = (props: GoogleMapsParams) => {
84
86
  }
85
87
  handleChangeAddressMap && handleChangeAddressMap(address, details)
86
88
  setSaveLocation && setSaveLocation(false)
87
- if(!isMovingRegion){
89
+ if (!isMovingRegion) {
88
90
  handleToggleMap && handleToggleMap()
89
91
  }
90
92
  } else {
@@ -95,7 +97,7 @@ export const GoogleMap = (props: GoogleMapsParams) => {
95
97
  })
96
98
  }
97
99
 
98
- const validateResult = (curPos: { latitude: number, longitude: number }) => {
100
+ const validateResult = (curPos: any) => {
99
101
  const loc1 = center
100
102
  const loc2 = curPos
101
103
  const distance = calculateDistance(loc1, loc2)
@@ -103,25 +105,33 @@ export const GoogleMap = (props: GoogleMapsParams) => {
103
105
  if (!maxLimitLocation) {
104
106
  geocodePosition(curPos)
105
107
  setMarkerPosition(curPos)
106
- setRegion({ ...region, longitude: curPos.longitude, latitude: curPos.latitude })
108
+ if (!autoCompleteAddress) {
109
+ setRegion({ longitude: curPos?.longitude || 0, latitude: curPos?.latitude || 0, latitudeDelta: curPos?.latitudeDelta || 0.0010, longitudeDelta: curPos?.longitudeDelta || (delta ?? 0.0010) * ASPECT_RATIO })
110
+ } else {
111
+ setRegion({ longitude: curPos?.longitude, latitude: curPos?.latitude, latitudeDelta: delta ?? 0.0010, longitudeDelta: (delta ?? 0.0010) * ASPECT_RATIO })
112
+ }
107
113
  return
108
114
  }
109
115
 
110
116
  const _maxLimitLocation = typeof maxLimitLocation === 'string' ? parseInt(maxLimitLocation, 10) : maxLimitLocation
111
117
 
112
118
  if (distance <= _maxLimitLocation) {
113
- if (!aproxEqual(curPos.latitude, center.lat) || !aproxEqual(curPos.longitude, center.lng)){
119
+ if (!aproxEqual(curPos?.latitude, center.lat) || !aproxEqual(curPos?.longitude, center.lng)) {
114
120
  geocodePosition(curPos, true)
115
121
  }
116
122
  setMarkerPosition(curPos)
117
- setRegion({ ...region, longitude: curPos.longitude, latitude: curPos.latitude })
123
+ if (!autoCompleteAddress) {
124
+ setRegion({ longitude: curPos?.longitude || 0, latitude: curPos?.latitude || 0, latitudeDelta: curPos?.latitudeDelta || 0.0010, longitudeDelta: curPos?.longitudeDelta || (delta ?? 0.0010) * ASPECT_RATIO })
125
+ } else {
126
+ setRegion({ longitude: curPos?.longitude, latitude: curPos?.latitude, latitudeDelta: delta ?? 0.0010, longitudeDelta: (delta ?? 0.0010) * ASPECT_RATIO })
127
+ }
118
128
  } else {
119
129
  setMapErrors && setMapErrors('ERROR_MAX_LIMIT_LOCATION')
120
130
  setMarkerPosition({ latitude: center.lat, longitude: center.lng })
121
131
  }
122
132
  }
123
133
 
124
- const aproxEqual = (n1 : number, n2 : number, epsilon = 0.000001) => {
134
+ const aproxEqual = (n1: number, n2: number, epsilon = 0.000001) => {
125
135
  return Math.abs(n1 - n2) < epsilon
126
136
  }
127
137
 
@@ -182,11 +192,21 @@ export const GoogleMap = (props: GoogleMapsParams) => {
182
192
  }, [isIntGeoCoder])
183
193
 
184
194
  useEffect(() => {
185
- mapRef.current.animateToRegion({
186
- ...region,
195
+ const regionConfig = {
187
196
  latitude: location?.lat,
188
197
  longitude: location?.lng,
189
- })
198
+ latitudeDelta: delta ?? 0.0010,
199
+ longitudeDelta: (delta ?? 0.0010) * ASPECT_RATIO
200
+ }
201
+
202
+ mapRef.current.animateToRegion(autoCompleteAddress
203
+ ? regionConfig
204
+ : { ...region, ...regionConfig }
205
+ )
206
+
207
+ if (autoCompleteAddress) {
208
+ setAutoCompleteAddress && setAutoCompleteAddress(false)
209
+ }
190
210
  }, [location])
191
211
 
192
212
  useEffect(() => {
@@ -213,7 +233,7 @@ export const GoogleMap = (props: GoogleMapsParams) => {
213
233
  provider={PROVIDER_GOOGLE}
214
234
  initialRegion={region}
215
235
  style={styles.map}
216
- onRegionChangeComplete={!readOnly ? (coordinates) => handleChangeRegion(coordinates) : () => { }}
236
+ onRegionChangeComplete={!readOnly ? (coordinates) => { handleChangeRegion(coordinates) } : () => { }}
217
237
  zoomTapEnabled
218
238
  zoomEnabled
219
239
  zoomControlEnabled
@@ -249,7 +269,7 @@ export const GoogleMap = (props: GoogleMapsParams) => {
249
269
  <React.Fragment key={i}>
250
270
  {businessZone?.type === 2 && Array.isArray(businessZone?.data) && (
251
271
  <Polygon
252
- coordinates={businessZone?.data.map((item: any) => ({ latitude: item.lat, longitude: item.lng}))}
272
+ coordinates={businessZone?.data.map((item: any) => ({ latitude: item.lat, longitude: item.lng }))}
253
273
  fillColor={fillStyles.fillColor}
254
274
  strokeColor={fillStyles.strokeColor}
255
275
  strokeWidth={fillStyles.strokeWidth}
@@ -257,7 +277,7 @@ export const GoogleMap = (props: GoogleMapsParams) => {
257
277
  )}
258
278
  {(businessZone.type === 1 && businessZone?.data?.center && businessZone?.data?.radio) && (
259
279
  <Circle
260
- center={{ latitude: businessZone?.data?.center.lat, longitude: businessZone?.data?.center.lng}}
280
+ center={{ latitude: businessZone?.data?.center.lat, longitude: businessZone?.data?.center.lng }}
261
281
  radius={businessZone?.data.radio * 1000}
262
282
  fillColor={fillStyles.fillColor}
263
283
  strokeColor={fillStyles.strokeColor}
@@ -266,7 +286,7 @@ export const GoogleMap = (props: GoogleMapsParams) => {
266
286
  )}
267
287
  {(businessZone.type === 5 && businessZone?.data?.distance) && (
268
288
  <Circle
269
- center={{ latitude: center.lat, longitude: center.lng}}
289
+ center={{ latitude: center.lat, longitude: center.lng }}
270
290
  radius={businessZone?.data.distance * units[businessZone?.data?.unit]}
271
291
  fillColor={fillStyles.fillColor}
272
292
  strokeColor={fillStyles.strokeColor}
@@ -275,7 +295,7 @@ export const GoogleMap = (props: GoogleMapsParams) => {
275
295
  )}
276
296
  </React.Fragment>
277
297
  ))}
278
- </MapView>
298
+ </MapView >
279
299
  <Alert
280
300
  open={alertState.open}
281
301
  onAccept={closeAlert}
@@ -29,7 +29,7 @@ import {
29
29
  TimeItem
30
30
  } from './styles';
31
31
  import { useSafeAreaInsets } from 'react-native-safe-area-context';
32
- import { locale, monthsEnum } from '../../utils';
32
+ import { locale, monthsEnum, setLocalMoment } from '../../utils';
33
33
 
34
34
  const MomentOptionUI = (props: MomentOptionParams) => {
35
35
  const {
@@ -323,6 +323,10 @@ const MomentOptionUI = (props: MomentOptionParams) => {
323
323
  }
324
324
  }, [dateSelected, JSON.stringify(hoursList), JSON.stringify(datesWhitelist), cateringPreorder, JSON.stringify(business)])
325
325
 
326
+ useEffect(() => {
327
+ setLocalMoment(moment, t)
328
+ }, [])
329
+
326
330
  return (
327
331
  <>
328
332
  <Container
@@ -394,7 +398,6 @@ const MomentOptionUI = (props: MomentOptionParams) => {
394
398
  <View style={{ flex: 1 }}>
395
399
  {selectDate && datesWhitelist[0]?.start !== null && (
396
400
  <CalendarStrip
397
- locale={locale}
398
401
  scrollable
399
402
  style={styles.calendar}
400
403
  calendarHeaderContainerStyle={styles.calendarHeaderContainer}
@@ -35,7 +35,8 @@ export const ProductOptionSubOptionUI = (props: any) => {
35
35
  disabled,
36
36
  setIsScrollAvailable,
37
37
  image,
38
- enableIntersection
38
+ enableIntersection,
39
+ onChange
39
40
  } = props
40
41
 
41
42
  const disableIncrement = option?.limit_suboptions_by_max ? balance === option?.max || state.quantity === suboption?.max : state.quantity === suboption?.max || (!state.selected && balance === option?.max)
@@ -88,6 +89,12 @@ export const ProductOptionSubOptionUI = (props: any) => {
88
89
  }
89
90
  }, [balance])
90
91
 
92
+ useEffect(() => {
93
+ if (!suboption?.preselected || !option?.respect_to) return
94
+ const newState = { ...state, selected: suboption?.preselected, quantity: state.selected ? 0 : 1 }
95
+ onChange(newState, suboption, option)
96
+ }, [suboption, option])
97
+
91
98
  return (
92
99
  <InView onChange={(inView: boolean) => handleChangeInterSection(inView)} triggerOnce={true}>
93
100
  {isIntersectionObserver ? (
@@ -607,7 +607,7 @@ export interface UpsellingProductsParams {
607
607
  business?: any;
608
608
  businessId?: number;
609
609
  cartProducts?: Array<any>;
610
- handleUpsellingPage: (cart ?: any) => void;
610
+ handleUpsellingPage: (cart?: any) => void;
611
611
  openUpselling: boolean;
612
612
  canOpenUpselling?: boolean;
613
613
  setCanOpenUpselling?: (value: any) => void;
@@ -637,6 +637,8 @@ export interface GoogleMapsParams {
637
637
  isIntGeoCoder: boolean,
638
638
  businessZones?: any
639
639
  delta?: number
640
+ setAutoCompleteAddress?: (val: boolean) => void,
641
+ autoCompleteAddress?: boolean,
640
642
  }
641
643
 
642
644
  export interface HelpParams {