ordering-ui-react-native 0.24.4 → 0.24.6

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.24.4",
3
+ "version": "0.24.6",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -76,6 +76,8 @@ const AddressFormUI = (props: AddressFormParams) => {
76
76
 
77
77
  const [autoCompleteInputFocused, setAutoCompleteInputFocused] = useState(false)
78
78
 
79
+ const isEmptyField = (key: any, str: any) => isRequiredField && isRequiredField(key) && (!str || str.trim().length === 0)
80
+
79
81
  const tagsName = [
80
82
  { icon: theme.images.general.tag_home, value: 'home' },
81
83
  { icon: theme.images.general.tag_building, value: 'office' },
@@ -349,50 +351,50 @@ const AddressFormUI = (props: AddressFormParams) => {
349
351
  };
350
352
 
351
353
  const handleChangeAddress = (data: any, details: any) => {
352
- const addressObj : any = {}
353
- if (details?.address_components) {
354
- details.address_components.map((component: any) => {
355
- const addressType = component.types[0]
356
- if (addressType === 'postal_code') {
357
- addressObj.zipcode = component.short_name
358
- }
359
- if (addressType === 'street_number') {
360
- addressObj.street_number = component.long_name
361
- }
362
- if (addressType === 'neighborhood') {
363
- addressObj.neighborhood = component.long_name
364
- }
365
- if (addressType === 'route') {
366
- addressObj.route = component.short_name
367
- }
368
- if (addressType === 'locality') {
369
- addressObj.locality = component.long_name
370
- }
371
- if (component.types?.includes('sublocality')) {
372
- addressObj.sublocality = component.long_name
373
- }
374
- if (addressType === 'country') {
375
- addressObj.country = component.long_name
376
- addressObj.country_code = component.short_name
377
- }
378
- if (addressType === 'administrative_area_level_1') {
379
- addressObj.state = component.long_name
380
- }
381
- if (addressType === 'administrative_area_level_2') {
382
- addressObj.city = component.long_name
383
- }
384
- })
385
- }
386
- const addressSelected = {
387
- address: data?.description || data?.address,
388
- location: details?.geometry?.location,
389
- utc_offset: details?.utc_offset || null,
390
- map_data: { library: 'google', place_id: data.place_id },
391
- zipcode: data?.zipcode || null,
392
- ...addressObj
393
- };
394
- updateChanges(addressSelected);
395
- };
354
+ const addressObj: any = {}
355
+ if (details?.address_components) {
356
+ details.address_components.map((component: any) => {
357
+ const addressType = component.types[0]
358
+ if (addressType === 'postal_code') {
359
+ addressObj.zipcode = component.short_name
360
+ }
361
+ if (addressType === 'street_number') {
362
+ addressObj.street_number = component.long_name
363
+ }
364
+ if (addressType === 'neighborhood') {
365
+ addressObj.neighborhood = component.long_name
366
+ }
367
+ if (addressType === 'route') {
368
+ addressObj.route = component.short_name
369
+ }
370
+ if (addressType === 'locality') {
371
+ addressObj.locality = component.long_name
372
+ }
373
+ if (component.types?.includes('sublocality')) {
374
+ addressObj.sublocality = component.long_name
375
+ }
376
+ if (addressType === 'country') {
377
+ addressObj.country = component.long_name
378
+ addressObj.country_code = component.short_name
379
+ }
380
+ if (addressType === 'administrative_area_level_1') {
381
+ addressObj.state = component.long_name
382
+ }
383
+ if (addressType === 'administrative_area_level_2') {
384
+ addressObj.city = component.long_name
385
+ }
386
+ })
387
+ }
388
+ const addressSelected = {
389
+ address: data?.description || data?.address,
390
+ location: details?.geometry?.location,
391
+ utc_offset: details?.utc_offset || null,
392
+ map_data: { library: 'google', place_id: data.place_id },
393
+ zipcode: data?.zipcode || null,
394
+ ...addressObj
395
+ };
396
+ updateChanges(addressSelected);
397
+ };
396
398
 
397
399
  const handleAddressTag = (tag: string) => {
398
400
  setAddressTag(tag);
@@ -497,9 +499,9 @@ const AddressFormUI = (props: AddressFormParams) => {
497
499
  }, [formState]);
498
500
 
499
501
  useEffect(() => {
500
- if (formState?.result?.result && !formState?.loading) {
501
- if (formState.result?.error) {
502
- showToast(ToastType.Error, formState.result.result);
502
+ if (formState?.result && !formState?.loading) {
503
+ if (formState?.error) {
504
+ showToast(ToastType.Error, formState.error[0]);
503
505
  } else {
504
506
  showToast(
505
507
  ToastType.Success,
@@ -748,9 +750,9 @@ const AddressFormUI = (props: AddressFormParams) => {
748
750
  <OInput
749
751
  name="internal_number"
750
752
  placeholder={t('INTERNAL_NUMBER', 'Internal number')}
751
- onChange={(text: string) => {
752
- handleChangeInput(text);
753
- setValue('internal_number', text);
753
+ onChange={(data: any) => {
754
+ handleChangeInput(data);
755
+ setValue('internal_number', isEmptyField('internal_number', data?.target?.value) ? null : data);
754
756
  }}
755
757
  value={
756
758
  address?.internal_number ||
@@ -795,9 +797,9 @@ const AddressFormUI = (props: AddressFormParams) => {
795
797
  <OInput
796
798
  name="zipcode"
797
799
  placeholder={t('ZIP_CODE', 'Zip code')}
798
- onChange={(text: string) => {
799
- handleChangeInput(text);
800
- setValue('zipcode', text);
800
+ onChange={(data: any) => {
801
+ handleChangeInput(data);
802
+ setValue('zipcode', isEmptyField('zipcode', data?.target?.value) ? null : data);
801
803
  }}
802
804
  value={
803
805
  address?.zipcode ||