cozy-ui-plus 5.2.0 → 5.2.1
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/CHANGELOG.md +6 -0
- package/dist/Contacts/AddModal/ContactForm/formValuesToContact.js +1 -1
- package/dist/Contacts/AddModal/ContactForm/helpers.js +30 -2
- package/dist/src/Contacts/AddModal/ContactForm/helpers.d.ts +3 -0
- package/package.json +2 -2
- package/src/Contacts/AddModal/ContactForm/formValuesToContact.js +2 -1
- package/src/Contacts/AddModal/ContactForm/helpers.js +23 -0
- package/src/Contacts/AddModal/ContactForm/helpers.spec.js +40 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [5.2.1](https://github.com/cozy/cozy-libs/compare/cozy-ui-plus@5.2.0...cozy-ui-plus@5.2.1) (2026-03-09)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **cozy-ui-plus:** Only country code phone number is now ignored ([d7aedf8](https://github.com/cozy/cozy-libs/commit/d7aedf8a4f0c21e9b433c94fd2f4c93745d2ca22))
|
|
11
|
+
|
|
6
12
|
# [5.2.0](https://github.com/cozy/cozy-libs/compare/cozy-ui-plus@5.1.1...cozy-ui-plus@5.2.0) (2026-03-09)
|
|
7
13
|
|
|
8
14
|
### Bug Fixes
|
|
@@ -76,7 +76,7 @@ var formValuesToContact = function formValuesToContact(_ref) {
|
|
|
76
76
|
t: t
|
|
77
77
|
}),
|
|
78
78
|
phone: phone ? phone.filter(function (val) {
|
|
79
|
-
return val && val.phone;
|
|
79
|
+
return val !== null && val !== void 0 && val.phone ? (0, _helpers.excludedCountryCode)(val) : undefined;
|
|
80
80
|
}).map(function (_ref3, index) {
|
|
81
81
|
var phone = _ref3.phone,
|
|
82
82
|
phoneLabel = _ref3.phoneLabel;
|
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.validateFields = exports.removeRelatedContactRelationships = exports.removeField = exports.removeAsscociatedData = exports.moveToHead = exports.movePrimaryToHead = exports.makeTypeAndLabel = exports.makeRelatedContact = exports.makeItemLabel = exports.makeIsRequiredError = exports.makeInitialCustomValue = exports.makeImppValues = exports.makeFields = exports.makeCustomLabel = exports.initializationFieldValues = exports.hasNoValues = exports.hasExtendedAddress = exports.getRelatedContactRelationships = exports.getFirstValueIfArray = exports.createAddress = exports.addField = void 0;
|
|
8
|
+
exports.validateFields = exports.removeRelatedContactRelationships = exports.removeField = exports.removeAsscociatedData = exports.moveToHead = exports.movePrimaryToHead = exports.makeTypeAndLabel = exports.makeRelatedContact = exports.makeItemLabel = exports.makeIsRequiredError = exports.makeInitialCustomValue = exports.makeImppValues = exports.makeFields = exports.makeCustomLabel = exports.initializationFieldValues = exports.hasNoValues = exports.hasExtendedAddress = exports.getRelatedContactRelationships = exports.getFirstValueIfArray = exports.excludedCountryCode = exports.createAddress = exports.addField = void 0;
|
|
9
9
|
|
|
10
10
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
11
|
|
|
@@ -23,6 +23,8 @@ var _merge = _interopRequireDefault(require("lodash/merge"));
|
|
|
23
23
|
|
|
24
24
|
var _uniqueId = _interopRequireDefault(require("lodash/uniqueId"));
|
|
25
25
|
|
|
26
|
+
var _reactInternationalPhone = require("react-international-phone");
|
|
27
|
+
|
|
26
28
|
var _cozyClient = require("cozy-client");
|
|
27
29
|
|
|
28
30
|
var _contact = require("cozy-client/dist/models/contact");
|
|
@@ -559,5 +561,31 @@ var makeFields = function makeFields(customFields, defaultFields) {
|
|
|
559
561
|
});
|
|
560
562
|
return fields;
|
|
561
563
|
};
|
|
564
|
+
/**
|
|
565
|
+
* Excludes phone numbers that consist only of a country code.
|
|
566
|
+
* If the provided phone value matches only a country code (e.g., "+33"),
|
|
567
|
+
* returns undefined. Otherwise, returns the phone value.
|
|
568
|
+
*
|
|
569
|
+
* @param {Object} val - An object containing the phone number.
|
|
570
|
+
* @param {string} val.phone - The phone number string, possibly starting with "+" and a country code.
|
|
571
|
+
* @returns {string|undefined} The phone number if it is not just a country code, otherwise undefined.
|
|
572
|
+
*/
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
exports.makeFields = makeFields;
|
|
576
|
+
|
|
577
|
+
var excludedCountryCode = function excludedCountryCode(val) {
|
|
578
|
+
var phoneWithoutPrefix = val.phone.split('+')[1];
|
|
579
|
+
|
|
580
|
+
var isOnlyCountryCode = _reactInternationalPhone.defaultCountries.some(function (country) {
|
|
581
|
+
var _parseCountry = (0, _reactInternationalPhone.parseCountry)(country),
|
|
582
|
+
dialCode = _parseCountry.dialCode;
|
|
583
|
+
|
|
584
|
+
return phoneWithoutPrefix === dialCode;
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
if (isOnlyCountryCode) return undefined;
|
|
588
|
+
return val.phone;
|
|
589
|
+
};
|
|
562
590
|
|
|
563
|
-
exports.
|
|
591
|
+
exports.excludedCountryCode = excludedCountryCode;
|
|
@@ -43,3 +43,6 @@ export function makeImppValues(oldContact: import("cozy-client/types/types").IOC
|
|
|
43
43
|
export function initializationFieldValues(fields: any): any;
|
|
44
44
|
export function makeInitialCustomValue(name: string, value: string): string;
|
|
45
45
|
export function makeFields(customFields: (import("../types").Field)[] | undefined, defaultFields: (import("../types").Field)[]): (import("../types").Field)[];
|
|
46
|
+
export function excludedCountryCode(val: {
|
|
47
|
+
phone: string;
|
|
48
|
+
}): string | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-ui-plus",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.1",
|
|
4
4
|
"description": "Cozy-ui-plus is an extension of cozy-ui and provides components based on cozy-client",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -73,5 +73,5 @@
|
|
|
73
73
|
"react-dom": "^16 || ^17 || ^18",
|
|
74
74
|
"twake-i18n": ">=0.3.0"
|
|
75
75
|
},
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "3b9c5cf0b6442700d6a3b9d21010089f3f9f8b32"
|
|
77
77
|
}
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
createAddress,
|
|
7
7
|
getRelatedContactRelationships,
|
|
8
8
|
makeImppValues,
|
|
9
|
+
excludedCountryCode,
|
|
9
10
|
makeTypeAndLabel
|
|
10
11
|
} from './helpers'
|
|
11
12
|
|
|
@@ -76,7 +77,7 @@ const formValuesToContact = ({
|
|
|
76
77
|
address: createAddress({ address, oldContact: oldContactCleaned, t }),
|
|
77
78
|
phone: phone
|
|
78
79
|
? phone
|
|
79
|
-
.filter(val => val
|
|
80
|
+
.filter(val => (val?.phone ? excludedCountryCode(val) : undefined))
|
|
80
81
|
.map(({ phone, phoneLabel }, index) => ({
|
|
81
82
|
number: phone,
|
|
82
83
|
...makeTypeAndLabel(phoneLabel),
|
|
@@ -2,6 +2,7 @@ import get from 'lodash/get'
|
|
|
2
2
|
import isEqual from 'lodash/isEqual'
|
|
3
3
|
import merge from 'lodash/merge'
|
|
4
4
|
import uniqueId from 'lodash/uniqueId'
|
|
5
|
+
import { defaultCountries, parseCountry } from 'react-international-phone'
|
|
5
6
|
|
|
6
7
|
import { Association } from 'cozy-client'
|
|
7
8
|
import { makeDisplayName } from 'cozy-client/dist/models/contact'
|
|
@@ -480,3 +481,25 @@ export const makeFields = (customFields, defaultFields) => {
|
|
|
480
481
|
|
|
481
482
|
return fields
|
|
482
483
|
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Excludes phone numbers that consist only of a country code.
|
|
487
|
+
* If the provided phone value matches only a country code (e.g., "+33"),
|
|
488
|
+
* returns undefined. Otherwise, returns the phone value.
|
|
489
|
+
*
|
|
490
|
+
* @param {Object} val - An object containing the phone number.
|
|
491
|
+
* @param {string} val.phone - The phone number string, possibly starting with "+" and a country code.
|
|
492
|
+
* @returns {string|undefined} The phone number if it is not just a country code, otherwise undefined.
|
|
493
|
+
*/
|
|
494
|
+
export const excludedCountryCode = val => {
|
|
495
|
+
const phoneWithoutPrefix = val.phone.split('+')[1]
|
|
496
|
+
|
|
497
|
+
const isOnlyCountryCode = defaultCountries.some(country => {
|
|
498
|
+
const { dialCode } = parseCountry(country)
|
|
499
|
+
return phoneWithoutPrefix === dialCode
|
|
500
|
+
})
|
|
501
|
+
|
|
502
|
+
if (isOnlyCountryCode) return undefined
|
|
503
|
+
|
|
504
|
+
return val.phone
|
|
505
|
+
}
|
|
@@ -12,10 +12,20 @@ import {
|
|
|
12
12
|
getFirstValueIfArray,
|
|
13
13
|
validateFields
|
|
14
14
|
} from './helpers'
|
|
15
|
+
import { excludedCountryCode } from './helpers'
|
|
15
16
|
import { locales } from './locales'
|
|
16
17
|
|
|
17
18
|
const t = x => get(locales.en, x, x)
|
|
18
19
|
|
|
20
|
+
jest.mock('react-international-phone', () => ({
|
|
21
|
+
...jest.requireActual('react-international-phone'),
|
|
22
|
+
defaultCountries: [
|
|
23
|
+
['France', 'fr', '33'],
|
|
24
|
+
['United States', 'us', '1'],
|
|
25
|
+
['Germany', 'de', '49']
|
|
26
|
+
]
|
|
27
|
+
}))
|
|
28
|
+
|
|
19
29
|
describe('makeCustomLabel', () => {
|
|
20
30
|
it('should return custom type and supported label', () => {
|
|
21
31
|
const resForWork = makeCustomLabel('{"type":"someType","label":"work"}', t)
|
|
@@ -741,3 +751,33 @@ describe('validateFields', () => {
|
|
|
741
751
|
expect(res).toEqual({ mail: 'Some fields are not filled correctly' })
|
|
742
752
|
})
|
|
743
753
|
})
|
|
754
|
+
|
|
755
|
+
describe('excludedCountryCode', () => {
|
|
756
|
+
it('returns undefined for country code only (+33)', () => {
|
|
757
|
+
expect(excludedCountryCode({ phone: '+33' })).toBeUndefined()
|
|
758
|
+
})
|
|
759
|
+
|
|
760
|
+
it('preserves full number for Germany (+4930123456)', () => {
|
|
761
|
+
expect(excludedCountryCode({ phone: '+4930123456' })).toBe('+4930123456')
|
|
762
|
+
})
|
|
763
|
+
|
|
764
|
+
it('returns undefined for country code only (+1)', () => {
|
|
765
|
+
expect(excludedCountryCode({ phone: '+1' })).toBeUndefined()
|
|
766
|
+
})
|
|
767
|
+
|
|
768
|
+
it('preserves full French mobile (+33612345678)', () => {
|
|
769
|
+
expect(excludedCountryCode({ phone: '+33612345678' })).toBe('+33612345678')
|
|
770
|
+
})
|
|
771
|
+
|
|
772
|
+
it('preserves value not matching country code (+490)', () => {
|
|
773
|
+
expect(excludedCountryCode({ phone: '+490' })).toBe('+490')
|
|
774
|
+
})
|
|
775
|
+
|
|
776
|
+
it('preserves numbers with no country code (12345)', () => {
|
|
777
|
+
expect(excludedCountryCode({ phone: '12345' })).toBe('12345')
|
|
778
|
+
})
|
|
779
|
+
|
|
780
|
+
it('returns undefined for country code only (+49)', () => {
|
|
781
|
+
expect(excludedCountryCode({ phone: '+49' })).toBeUndefined()
|
|
782
|
+
})
|
|
783
|
+
})
|