cozy-ui-plus 4.1.0 → 4.2.0
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/contactToFormValues.js +75 -90
- package/dist/Contacts/AddModal/ContactForm/helpers.js +15 -2
- package/dist/Contacts/AddModal/ContactForm/index.js +1 -1
- package/dist/src/Contacts/AddModal/ContactForm/helpers.d.ts +1 -0
- package/package.json +2 -2
- package/src/Contacts/AddModal/ContactForm/contactToFormValues.js +79 -94
- package/src/Contacts/AddModal/ContactForm/contactToFormValues.spec.js +0 -23
- package/src/Contacts/AddModal/ContactForm/helpers.js +12 -0
- package/src/Contacts/AddModal/ContactForm/index.jsx +15 -6
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
|
+
# [4.2.0](https://github.com/cozy/cozy-libs/compare/cozy-ui-plus@4.1.0...cozy-ui-plus@4.2.0) (2026-01-14)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **AddModal:** Add possibility to set field default value ([db6e8f7](https://github.com/cozy/cozy-libs/commit/db6e8f723cf3c155765458c8e022005006403351))
|
|
11
|
+
|
|
6
12
|
# [4.1.0](https://github.com/cozy/cozy-libs/compare/cozy-ui-plus@4.0.0...cozy-ui-plus@4.1.0) (2025-12-10)
|
|
7
13
|
|
|
8
14
|
### Features
|
|
@@ -13,8 +13,6 @@ var _uniqueId = _interopRequireDefault(require("lodash/uniqueId"));
|
|
|
13
13
|
|
|
14
14
|
var _contact = require("cozy-client/dist/models/contact");
|
|
15
15
|
|
|
16
|
-
var _fieldsConfig = require("./fieldsConfig");
|
|
17
|
-
|
|
18
16
|
var _helpers = require("./helpers");
|
|
19
17
|
|
|
20
18
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
@@ -22,97 +20,84 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
22
20
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
23
21
|
|
|
24
22
|
var contactToFormValues = function contactToFormValues(_ref) {
|
|
23
|
+
var _impp$find;
|
|
24
|
+
|
|
25
25
|
var contact = _ref.contact,
|
|
26
26
|
makeCustomContactValues = _ref.makeCustomContactValues,
|
|
27
27
|
t = _ref.t;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
email: emailValue,
|
|
102
|
-
matrix: matrixValue,
|
|
103
|
-
address: addressValue,
|
|
104
|
-
cozy: cozyValue,
|
|
105
|
-
cozyLabel: cozyLabel,
|
|
106
|
-
company: company,
|
|
107
|
-
jobTitle: jobTitle,
|
|
108
|
-
birthday: birthday,
|
|
109
|
-
birthplace: birthplace,
|
|
110
|
-
note: note,
|
|
111
|
-
relatedContact: relatedContactValue
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return initialFieldValues;
|
|
28
|
+
var gender = contact.gender,
|
|
29
|
+
address = contact.address,
|
|
30
|
+
birthday = contact.birthday,
|
|
31
|
+
birthplace = contact.birthplace,
|
|
32
|
+
company = contact.company,
|
|
33
|
+
jobTitle = contact.jobTitle,
|
|
34
|
+
cozy = contact.cozy,
|
|
35
|
+
email = contact.email,
|
|
36
|
+
impp = contact.impp,
|
|
37
|
+
name = contact.name,
|
|
38
|
+
note = contact.note,
|
|
39
|
+
phone = contact.phone;
|
|
40
|
+
var addressValue = address && address.length > 0 ? (0, _helpers.movePrimaryToHead)(address).map(function (addressInfo) {
|
|
41
|
+
var _addressInfo$extended, _addressInfo$extended2, _addressInfo$extended3, _addressInfo$extended4, _addressInfo$extended5, _addressInfo$extended6;
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
fieldId: (0, _uniqueId.default)('fieldId_'),
|
|
45
|
+
address: (0, _contact.getFormattedAddress)(addressInfo, t),
|
|
46
|
+
addressnumber: addressInfo.number,
|
|
47
|
+
addressstreet: addressInfo.street || (0, _contact.getFormattedAddress)(addressInfo, t),
|
|
48
|
+
addresscode: addressInfo.postcode || addressInfo.code,
|
|
49
|
+
addresscity: addressInfo.city,
|
|
50
|
+
addressregion: addressInfo.region,
|
|
51
|
+
addresscountry: addressInfo.country,
|
|
52
|
+
addresslocality: (_addressInfo$extended = addressInfo.extendedAddress) === null || _addressInfo$extended === void 0 ? void 0 : _addressInfo$extended.locality,
|
|
53
|
+
addressbuilding: (_addressInfo$extended2 = addressInfo.extendedAddress) === null || _addressInfo$extended2 === void 0 ? void 0 : _addressInfo$extended2.building,
|
|
54
|
+
addressstairs: (_addressInfo$extended3 = addressInfo.extendedAddress) === null || _addressInfo$extended3 === void 0 ? void 0 : _addressInfo$extended3.stairs,
|
|
55
|
+
addressfloor: (_addressInfo$extended4 = addressInfo.extendedAddress) === null || _addressInfo$extended4 === void 0 ? void 0 : _addressInfo$extended4.floor,
|
|
56
|
+
addressapartment: (_addressInfo$extended5 = addressInfo.extendedAddress) === null || _addressInfo$extended5 === void 0 ? void 0 : _addressInfo$extended5.apartment,
|
|
57
|
+
addressentrycode: (_addressInfo$extended6 = addressInfo.extendedAddress) === null || _addressInfo$extended6 === void 0 ? void 0 : _addressInfo$extended6.entrycode,
|
|
58
|
+
addressLabel: (0, _helpers.makeItemLabel)(addressInfo)
|
|
59
|
+
};
|
|
60
|
+
}) : [undefined];
|
|
61
|
+
var cozyValue = cozy && cozy.length > 0 ? cozy[0].url : undefined;
|
|
62
|
+
var cozyLabel = cozy && cozy.length > 0 ? (0, _helpers.makeItemLabel)(cozy[0]) : undefined;
|
|
63
|
+
var emailValue = email && email.length > 0 ? (0, _helpers.movePrimaryToHead)(email).map(function (item) {
|
|
64
|
+
return {
|
|
65
|
+
fieldId: (0, _uniqueId.default)('fieldId_'),
|
|
66
|
+
email: item === null || item === void 0 ? void 0 : item.address,
|
|
67
|
+
emailLabel: (0, _helpers.makeItemLabel)(item)
|
|
68
|
+
};
|
|
69
|
+
}) : [undefined];
|
|
70
|
+
var matrixValue = impp && impp.length > 0 ? ((_impp$find = impp.find(function (item) {
|
|
71
|
+
return item.label === 'work' && item.protocol === 'matrix';
|
|
72
|
+
})) === null || _impp$find === void 0 ? void 0 : _impp$find.uri) || undefined : undefined;
|
|
73
|
+
var phoneValue = phone && phone.length > 0 ? (0, _helpers.movePrimaryToHead)(phone).map(function (item) {
|
|
74
|
+
return {
|
|
75
|
+
fieldId: (0, _uniqueId.default)('fieldId_'),
|
|
76
|
+
phone: item === null || item === void 0 ? void 0 : item.number,
|
|
77
|
+
phoneLabel: (0, _helpers.makeItemLabel)(item)
|
|
78
|
+
};
|
|
79
|
+
}) : [undefined];
|
|
80
|
+
var relatedContactValue = (0, _helpers.makeRelatedContact)(contact);
|
|
81
|
+
var customValues = (makeCustomContactValues === null || makeCustomContactValues === void 0 ? void 0 : makeCustomContactValues(contact)) || {};
|
|
82
|
+
return _objectSpread(_objectSpread({}, customValues), {}, {
|
|
83
|
+
gender: gender,
|
|
84
|
+
givenName: name === null || name === void 0 ? void 0 : name.givenName,
|
|
85
|
+
additionalName: name === null || name === void 0 ? void 0 : name.additionalName,
|
|
86
|
+
surname: name === null || name === void 0 ? void 0 : name.surname,
|
|
87
|
+
familyName: name === null || name === void 0 ? void 0 : name.familyName,
|
|
88
|
+
phone: phoneValue,
|
|
89
|
+
email: emailValue,
|
|
90
|
+
matrix: matrixValue,
|
|
91
|
+
address: addressValue,
|
|
92
|
+
cozy: cozyValue,
|
|
93
|
+
cozyLabel: cozyLabel,
|
|
94
|
+
company: company,
|
|
95
|
+
jobTitle: jobTitle,
|
|
96
|
+
birthday: birthday,
|
|
97
|
+
birthplace: birthplace,
|
|
98
|
+
note: note,
|
|
99
|
+
relatedContact: relatedContactValue
|
|
100
|
+
});
|
|
116
101
|
};
|
|
117
102
|
|
|
118
103
|
var _default = contactToFormValues;
|
|
@@ -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.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.createAddress = exports.addField = void 0;
|
|
9
9
|
|
|
10
10
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
11
|
|
|
@@ -428,6 +428,19 @@ var makeImppValues = function makeImppValues(oldContact, value) {
|
|
|
428
428
|
}
|
|
429
429
|
}).filter(Boolean)) || [];
|
|
430
430
|
};
|
|
431
|
+
|
|
432
|
+
exports.makeImppValues = makeImppValues;
|
|
433
|
+
|
|
434
|
+
var initializationFieldValues = function initializationFieldValues(fields) {
|
|
435
|
+
var initialFieldValues = fields.reduce(function (initialValues, _ref8) {
|
|
436
|
+
var name = _ref8.name,
|
|
437
|
+
layout = _ref8.layout,
|
|
438
|
+
defaultValue = _ref8.defaultValue;
|
|
439
|
+
initialValues[name] = layout === 'array' ? [undefined] : defaultValue;
|
|
440
|
+
return initialValues;
|
|
441
|
+
}, {});
|
|
442
|
+
return initialFieldValues;
|
|
443
|
+
};
|
|
431
444
|
/**
|
|
432
445
|
*
|
|
433
446
|
* @param {string} name
|
|
@@ -436,7 +449,7 @@ var makeImppValues = function makeImppValues(oldContact, value) {
|
|
|
436
449
|
*/
|
|
437
450
|
|
|
438
451
|
|
|
439
|
-
exports.
|
|
452
|
+
exports.initializationFieldValues = initializationFieldValues;
|
|
440
453
|
|
|
441
454
|
var makeInitialCustomValue = function makeInitialCustomValue(name, value) {
|
|
442
455
|
// gender input doesn't support custom label
|
|
@@ -98,7 +98,7 @@ var ContactForm = function ContactForm(_ref) {
|
|
|
98
98
|
|
|
99
99
|
return /*#__PURE__*/_react.default.createElement(_reactFinalForm.Form, {
|
|
100
100
|
mutators: _objectSpread({}, _finalFormArrays.default),
|
|
101
|
-
initialValues: (0, _contactToFormValues.default)({
|
|
101
|
+
initialValues: !contact ? (0, _helpers.initializationFieldValues)(_fields) : (0, _contactToFormValues.default)({
|
|
102
102
|
contact: contact,
|
|
103
103
|
makeCustomContactValues: makeCustomContactValues,
|
|
104
104
|
t: t
|
|
@@ -33,5 +33,6 @@ export function makeImppValues(oldContact: import("cozy-client/types/types").IOC
|
|
|
33
33
|
label: string;
|
|
34
34
|
primary?: boolean;
|
|
35
35
|
}[];
|
|
36
|
+
export function initializationFieldValues(fields: any): any;
|
|
36
37
|
export function makeInitialCustomValue(name: string, value: string): string;
|
|
37
38
|
export function makeFields(customFields: (import("../types").Field)[] | undefined, defaultFields: (import("../types").Field)[]): (import("../types").Field)[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-ui-plus",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
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",
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"react-dom": "^16 || ^17 || ^18",
|
|
75
75
|
"twake-i18n": ">=0.3.0"
|
|
76
76
|
},
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "1fe28398fc8315ebb5eba401731f8e318c00f05a"
|
|
78
78
|
}
|
|
@@ -2,108 +2,93 @@ import uniqueId from 'lodash/uniqueId'
|
|
|
2
2
|
|
|
3
3
|
import { getFormattedAddress } from 'cozy-client/dist/models/contact'
|
|
4
4
|
|
|
5
|
-
import { fields } from './fieldsConfig'
|
|
6
5
|
import { makeItemLabel, makeRelatedContact, movePrimaryToHead } from './helpers'
|
|
7
6
|
|
|
8
7
|
const contactToFormValues = ({ contact, makeCustomContactValues, t }) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
const {
|
|
9
|
+
gender,
|
|
10
|
+
address,
|
|
11
|
+
birthday,
|
|
12
|
+
birthplace,
|
|
13
|
+
company,
|
|
14
|
+
jobTitle,
|
|
15
|
+
cozy,
|
|
16
|
+
email,
|
|
17
|
+
impp,
|
|
18
|
+
name,
|
|
19
|
+
note,
|
|
20
|
+
phone
|
|
21
|
+
} = contact
|
|
17
22
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
const addressValue =
|
|
24
|
+
address && address.length > 0
|
|
25
|
+
? movePrimaryToHead(address).map(addressInfo => ({
|
|
26
|
+
fieldId: uniqueId('fieldId_'),
|
|
27
|
+
address: getFormattedAddress(addressInfo, t),
|
|
28
|
+
addressnumber: addressInfo.number,
|
|
29
|
+
addressstreet:
|
|
30
|
+
addressInfo.street || getFormattedAddress(addressInfo, t),
|
|
31
|
+
addresscode: addressInfo.postcode || addressInfo.code,
|
|
32
|
+
addresscity: addressInfo.city,
|
|
33
|
+
addressregion: addressInfo.region,
|
|
34
|
+
addresscountry: addressInfo.country,
|
|
35
|
+
addresslocality: addressInfo.extendedAddress?.locality,
|
|
36
|
+
addressbuilding: addressInfo.extendedAddress?.building,
|
|
37
|
+
addressstairs: addressInfo.extendedAddress?.stairs,
|
|
38
|
+
addressfloor: addressInfo.extendedAddress?.floor,
|
|
39
|
+
addressapartment: addressInfo.extendedAddress?.apartment,
|
|
40
|
+
addressentrycode: addressInfo.extendedAddress?.entrycode,
|
|
41
|
+
addressLabel: makeItemLabel(addressInfo)
|
|
42
|
+
}))
|
|
43
|
+
: [undefined]
|
|
44
|
+
const cozyValue = cozy && cozy.length > 0 ? cozy[0].url : undefined
|
|
45
|
+
const cozyLabel = cozy && cozy.length > 0 ? makeItemLabel(cozy[0]) : undefined
|
|
46
|
+
const emailValue =
|
|
47
|
+
email && email.length > 0
|
|
48
|
+
? movePrimaryToHead(email).map(item => ({
|
|
49
|
+
fieldId: uniqueId('fieldId_'),
|
|
50
|
+
email: item?.address,
|
|
51
|
+
emailLabel: makeItemLabel(item)
|
|
52
|
+
}))
|
|
53
|
+
: [undefined]
|
|
54
|
+
const matrixValue =
|
|
55
|
+
impp && impp.length > 0
|
|
56
|
+
? impp.find(item => item.label === 'work' && item.protocol === 'matrix')
|
|
57
|
+
?.uri || undefined
|
|
58
|
+
: undefined
|
|
59
|
+
const phoneValue =
|
|
60
|
+
phone && phone.length > 0
|
|
61
|
+
? movePrimaryToHead(phone).map(item => ({
|
|
62
|
+
fieldId: uniqueId('fieldId_'),
|
|
63
|
+
phone: item?.number,
|
|
64
|
+
phoneLabel: makeItemLabel(item)
|
|
65
|
+
}))
|
|
66
|
+
: [undefined]
|
|
33
67
|
|
|
34
|
-
|
|
35
|
-
address && address.length > 0
|
|
36
|
-
? movePrimaryToHead(address).map(addressInfo => ({
|
|
37
|
-
fieldId: uniqueId('fieldId_'),
|
|
38
|
-
address: getFormattedAddress(addressInfo, t),
|
|
39
|
-
addressnumber: addressInfo.number,
|
|
40
|
-
addressstreet:
|
|
41
|
-
addressInfo.street || getFormattedAddress(addressInfo, t),
|
|
42
|
-
addresscode: addressInfo.postcode || addressInfo.code,
|
|
43
|
-
addresscity: addressInfo.city,
|
|
44
|
-
addressregion: addressInfo.region,
|
|
45
|
-
addresscountry: addressInfo.country,
|
|
46
|
-
addresslocality: addressInfo.extendedAddress?.locality,
|
|
47
|
-
addressbuilding: addressInfo.extendedAddress?.building,
|
|
48
|
-
addressstairs: addressInfo.extendedAddress?.stairs,
|
|
49
|
-
addressfloor: addressInfo.extendedAddress?.floor,
|
|
50
|
-
addressapartment: addressInfo.extendedAddress?.apartment,
|
|
51
|
-
addressentrycode: addressInfo.extendedAddress?.entrycode,
|
|
52
|
-
addressLabel: makeItemLabel(addressInfo)
|
|
53
|
-
}))
|
|
54
|
-
: [undefined]
|
|
55
|
-
const cozyValue = cozy && cozy.length > 0 ? cozy[0].url : undefined
|
|
56
|
-
const cozyLabel =
|
|
57
|
-
cozy && cozy.length > 0 ? makeItemLabel(cozy[0]) : undefined
|
|
58
|
-
const emailValue =
|
|
59
|
-
email && email.length > 0
|
|
60
|
-
? movePrimaryToHead(email).map(item => ({
|
|
61
|
-
fieldId: uniqueId('fieldId_'),
|
|
62
|
-
email: item?.address,
|
|
63
|
-
emailLabel: makeItemLabel(item)
|
|
64
|
-
}))
|
|
65
|
-
: [undefined]
|
|
66
|
-
const matrixValue =
|
|
67
|
-
impp && impp.length > 0
|
|
68
|
-
? impp.find(item => item.label === 'work' && item.protocol === 'matrix')
|
|
69
|
-
?.uri || undefined
|
|
70
|
-
: undefined
|
|
71
|
-
const phoneValue =
|
|
72
|
-
phone && phone.length > 0
|
|
73
|
-
? movePrimaryToHead(phone).map(item => ({
|
|
74
|
-
fieldId: uniqueId('fieldId_'),
|
|
75
|
-
phone: item?.number,
|
|
76
|
-
phoneLabel: makeItemLabel(item)
|
|
77
|
-
}))
|
|
78
|
-
: [undefined]
|
|
68
|
+
const relatedContactValue = makeRelatedContact(contact)
|
|
79
69
|
|
|
80
|
-
|
|
70
|
+
const customValues = makeCustomContactValues?.(contact) || {}
|
|
81
71
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
note,
|
|
102
|
-
relatedContact: relatedContactValue
|
|
103
|
-
}
|
|
72
|
+
return {
|
|
73
|
+
...customValues,
|
|
74
|
+
gender,
|
|
75
|
+
givenName: name?.givenName,
|
|
76
|
+
additionalName: name?.additionalName,
|
|
77
|
+
surname: name?.surname,
|
|
78
|
+
familyName: name?.familyName,
|
|
79
|
+
phone: phoneValue,
|
|
80
|
+
email: emailValue,
|
|
81
|
+
matrix: matrixValue,
|
|
82
|
+
address: addressValue,
|
|
83
|
+
cozy: cozyValue,
|
|
84
|
+
cozyLabel: cozyLabel,
|
|
85
|
+
company,
|
|
86
|
+
jobTitle,
|
|
87
|
+
birthday,
|
|
88
|
+
birthplace,
|
|
89
|
+
note,
|
|
90
|
+
relatedContact: relatedContactValue
|
|
104
91
|
}
|
|
105
|
-
|
|
106
|
-
return initialFieldValues
|
|
107
92
|
}
|
|
108
93
|
|
|
109
94
|
export default contactToFormValues
|
|
@@ -5,29 +5,6 @@ import { johnDoeContact, johnDoeFormValues } from '../mocks'
|
|
|
5
5
|
describe('contactToFormValues function', () => {
|
|
6
6
|
const tSpy = jest.fn()
|
|
7
7
|
|
|
8
|
-
it('should return default initial values', () => {
|
|
9
|
-
const expected = {
|
|
10
|
-
address: [undefined],
|
|
11
|
-
birthday: undefined,
|
|
12
|
-
birthplace: undefined,
|
|
13
|
-
gender: undefined,
|
|
14
|
-
company: undefined,
|
|
15
|
-
jobTitle: undefined,
|
|
16
|
-
cozy: undefined,
|
|
17
|
-
cozyLabel: undefined,
|
|
18
|
-
email: [undefined],
|
|
19
|
-
matrix: undefined,
|
|
20
|
-
familyName: undefined,
|
|
21
|
-
givenName: undefined,
|
|
22
|
-
note: undefined,
|
|
23
|
-
phone: [undefined],
|
|
24
|
-
relatedContact: [undefined]
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const result = contactToFormValues({ contact: null, t: tSpy })
|
|
28
|
-
expect(result).toEqual(expected)
|
|
29
|
-
})
|
|
30
|
-
|
|
31
8
|
it('should return initial values when a contact is given (edit)', () => {
|
|
32
9
|
const expected = { ...johnDoeFormValues, relatedContact: [undefined] }
|
|
33
10
|
tSpy.mockReturnValue(
|
|
@@ -366,6 +366,18 @@ export const makeImppValues = (oldContact, value) => {
|
|
|
366
366
|
)
|
|
367
367
|
}
|
|
368
368
|
|
|
369
|
+
export const initializationFieldValues = fields => {
|
|
370
|
+
const initialFieldValues = fields.reduce(
|
|
371
|
+
(initialValues, { name, layout, defaultValue }) => {
|
|
372
|
+
initialValues[name] = layout === 'array' ? [undefined] : defaultValue
|
|
373
|
+
return initialValues
|
|
374
|
+
},
|
|
375
|
+
{}
|
|
376
|
+
)
|
|
377
|
+
|
|
378
|
+
return initialFieldValues
|
|
379
|
+
}
|
|
380
|
+
|
|
369
381
|
/**
|
|
370
382
|
*
|
|
371
383
|
* @param {string} name
|
|
@@ -10,7 +10,12 @@ import FieldInputLayout from './FieldInputLayout'
|
|
|
10
10
|
import contactToFormValues from './contactToFormValues'
|
|
11
11
|
import { fields as defaultFields } from './fieldsConfig'
|
|
12
12
|
import formValuesToContact from './formValuesToContact'
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
validateFields,
|
|
15
|
+
makeFields,
|
|
16
|
+
hasNoValues,
|
|
17
|
+
initializationFieldValues
|
|
18
|
+
} from './helpers'
|
|
14
19
|
import { locales } from './locales'
|
|
15
20
|
// import { fullContactPropTypes } from '../../ContactPropTypes' // !!
|
|
16
21
|
|
|
@@ -50,11 +55,15 @@ const ContactForm = ({ contacts, contact, customFieldsProps, onSubmit }) => {
|
|
|
50
55
|
return (
|
|
51
56
|
<Form
|
|
52
57
|
mutators={{ ...arrayMutators }}
|
|
53
|
-
initialValues={
|
|
54
|
-
contact
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
initialValues={
|
|
59
|
+
!contact
|
|
60
|
+
? initializationFieldValues(_fields)
|
|
61
|
+
: contactToFormValues({
|
|
62
|
+
contact,
|
|
63
|
+
makeCustomContactValues,
|
|
64
|
+
t
|
|
65
|
+
})
|
|
66
|
+
}
|
|
58
67
|
validate={values => validateFields(values, _fields, t)}
|
|
59
68
|
onSubmit={formValues => {
|
|
60
69
|
// avoid creating an empty contact
|