cozy-ui-plus 4.0.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 +14 -0
- package/dist/Contacts/AddModal/ContactForm/FieldInput.js +3 -7
- package/dist/Contacts/AddModal/ContactForm/FieldInputArray.js +3 -5
- package/dist/Contacts/AddModal/ContactForm/FieldInputLayout.js +2 -4
- package/dist/Contacts/AddModal/ContactForm/FieldInputWrapper.js +1 -1
- package/dist/Contacts/AddModal/ContactForm/contactToFormValues.js +75 -90
- package/dist/Contacts/AddModal/ContactForm/helpers.js +104 -34
- package/dist/Contacts/AddModal/ContactForm/index.js +7 -2
- package/dist/Contacts/AddModal/ContactForm/locales/index.js +4 -4
- package/dist/src/Contacts/AddModal/ContactForm/FieldInput.d.ts +2 -6
- package/dist/src/Contacts/AddModal/ContactForm/FieldInputArray.d.ts +2 -6
- package/dist/src/Contacts/AddModal/ContactForm/helpers.d.ts +5 -2
- package/package.json +2 -2
- package/src/Contacts/AddModal/ContactForm/FieldInput.jsx +3 -7
- package/src/Contacts/AddModal/ContactForm/FieldInputArray.jsx +7 -4
- package/src/Contacts/AddModal/ContactForm/FieldInputLayout.jsx +3 -3
- package/src/Contacts/AddModal/ContactForm/FieldInputWrapper.jsx +1 -1
- 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 +77 -17
- package/src/Contacts/AddModal/ContactForm/helpers.spec.js +344 -1
- package/src/Contacts/AddModal/ContactForm/index.jsx +24 -10
- package/src/Contacts/AddModal/ContactForm/locales/en.json +1 -1
- package/src/Contacts/AddModal/ContactForm/locales/fr.json +1 -1
- package/src/Contacts/AddModal/ContactForm/locales/ru.json +1 -1
- package/src/Contacts/AddModal/ContactForm/locales/vi.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,20 @@
|
|
|
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
|
+
|
|
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)
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
- **ui-plus:** Add possibility to overrides fields in Contacts AddModal ([7224485](https://github.com/cozy/cozy-libs/commit/72244856a99c879d54b1317e402a095afcb8b3f6))
|
|
17
|
+
- **ui-plus:** Change required logic for Contacts AddModal ([cdd5650](https://github.com/cozy/cozy-libs/commit/cdd565070ddb98a515c63ee9f2026b4e2fa1532d))
|
|
18
|
+
- **ui-plus:** Contacts AddModal form input values are now overridable ([50e7502](https://github.com/cozy/cozy-libs/commit/50e7502e5143e0479941c8aeabe67e90796a735c))
|
|
19
|
+
|
|
6
20
|
# [4.0.0](https://github.com/cozy/cozy-libs/compare/cozy-ui-plus@3.1.2...cozy-ui-plus@4.0.0) (2025-12-04)
|
|
7
21
|
|
|
8
22
|
### Features
|
|
@@ -56,8 +56,7 @@ var FieldInput = function FieldInput(_ref) {
|
|
|
56
56
|
error = _ref.error,
|
|
57
57
|
helperText = _ref.helperText,
|
|
58
58
|
label = _ref.label,
|
|
59
|
-
isInvisible = _ref.isInvisible
|
|
60
|
-
required = _ref.required;
|
|
59
|
+
isInvisible = _ref.isInvisible;
|
|
61
60
|
|
|
62
61
|
var _useState = (0, _react.useState)((0, _uniqueId.default)('field_')),
|
|
63
62
|
_useState2 = (0, _slicedToArray2.default)(_useState, 1),
|
|
@@ -104,7 +103,6 @@ var FieldInput = function FieldInput(_ref) {
|
|
|
104
103
|
'u-dn': isInvisible
|
|
105
104
|
})
|
|
106
105
|
}, /*#__PURE__*/_react.default.createElement(_reactFinalForm.Field, {
|
|
107
|
-
required: required,
|
|
108
106
|
error: error,
|
|
109
107
|
helperText: helperText,
|
|
110
108
|
label: label,
|
|
@@ -153,12 +151,10 @@ FieldInput.propTypes = {
|
|
|
153
151
|
}),
|
|
154
152
|
// Destructuring props
|
|
155
153
|
id: _propTypes.default.string,
|
|
156
|
-
label: _propTypes.default.string
|
|
157
|
-
required: _propTypes.default.bool
|
|
154
|
+
label: _propTypes.default.string
|
|
158
155
|
};
|
|
159
156
|
FieldInput.defaultProps = {
|
|
160
|
-
labelProps: null
|
|
161
|
-
required: false
|
|
157
|
+
labelProps: null
|
|
162
158
|
};
|
|
163
159
|
var _default = FieldInput;
|
|
164
160
|
exports.default = _default;
|
|
@@ -43,15 +43,13 @@ var FieldInputArray = function FieldInputArray(_ref) {
|
|
|
43
43
|
label = _ref$attributes.label,
|
|
44
44
|
restAttributes = (0, _objectWithoutProperties2.default)(_ref$attributes, _excluded),
|
|
45
45
|
contacts = _ref.contacts,
|
|
46
|
-
|
|
47
|
-
valid = _ref$formProps.valid,
|
|
48
|
-
submitFailed = _ref$formProps.submitFailed,
|
|
49
|
-
errors = _ref$formProps.errors;
|
|
46
|
+
formProps = _ref.formProps;
|
|
50
47
|
(0, _twakeI18n.useExtendI18n)(_locales.locales);
|
|
51
48
|
|
|
52
49
|
var _useI18n = (0, _twakeI18n.useI18n)(),
|
|
53
50
|
t = _useI18n.t;
|
|
54
51
|
|
|
52
|
+
var errors = formProps.errors;
|
|
55
53
|
return /*#__PURE__*/_react.default.createElement(_reactFinalFormArrays.FieldArray, {
|
|
56
54
|
name: name
|
|
57
55
|
}, function (_ref2) {
|
|
@@ -62,7 +60,7 @@ var FieldInputArray = function FieldInputArray(_ref) {
|
|
|
62
60
|
var key = ((_fields$value$index = fields.value[index]) === null || _fields$value$index === void 0 ? void 0 : _fields$value$index.fieldId) || nameWithIndex;
|
|
63
61
|
var showRemove = (_fields$value$index2 = fields.value[index]) === null || _fields$value$index2 === void 0 ? void 0 : _fields$value$index2[name];
|
|
64
62
|
var inputName = "".concat(nameWithIndex, ".").concat(name);
|
|
65
|
-
var isError = _helpers.
|
|
63
|
+
var isError = (0, _helpers.makeIsRequiredError)(restAttributes.required, formProps);
|
|
66
64
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
67
65
|
key: key,
|
|
68
66
|
className: (0, _classnames.default)('u-flex u-flex-items-baseline', {
|
|
@@ -46,13 +46,11 @@ var FieldInputLayout = function FieldInputLayout(_ref) {
|
|
|
46
46
|
var _useI18n = (0, _twakeI18n.useI18n)(),
|
|
47
47
|
t = _useI18n.t;
|
|
48
48
|
|
|
49
|
-
var
|
|
50
|
-
submitFailed = formProps.submitFailed,
|
|
51
|
-
errors = formProps.errors;
|
|
49
|
+
var errors = formProps.errors;
|
|
52
50
|
var name = attributes.name,
|
|
53
51
|
label = attributes.label,
|
|
54
52
|
restAttributes = (0, _objectWithoutProperties2.default)(attributes, _excluded2);
|
|
55
|
-
var isError = _helpers.
|
|
53
|
+
var isError = (0, _helpers.makeIsRequiredError)(restAttributes.required, formProps);
|
|
56
54
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
57
55
|
className: (0, _classnames.default)('u-mt-1', {
|
|
58
56
|
'u-flex-items-center': !layout,
|
|
@@ -35,7 +35,7 @@ var FieldInputWrapper = function FieldInputWrapper(_ref) {
|
|
|
35
35
|
fullWidth = _ref.fullWidth,
|
|
36
36
|
props = (0, _objectWithoutProperties2.default)(_ref, _excluded2);
|
|
37
37
|
var Component = component || (restAttributes.customLabelOptions ? _TextFieldCustomLabelSelect.default : restAttributes !== null && restAttributes !== void 0 && restAttributes.select ? _TextFieldSelect.default : _TextField.default);
|
|
38
|
-
return /*#__PURE__*/_react.default.createElement(Component, (0, _extends2.default)({},
|
|
38
|
+
return /*#__PURE__*/_react.default.createElement(Component, (0, _extends2.default)({}, input, restAttributes, props, {
|
|
39
39
|
variant: variant,
|
|
40
40
|
fullWidth: fullWidth,
|
|
41
41
|
minRows: "2"
|
|
@@ -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,16 +5,16 @@ 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.makeInitialCustomValue = exports.makeImppValues = exports.makeFields = exports.makeCustomLabel = exports.hasExtendedAddress = exports.getRelatedContactRelationships = exports.
|
|
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
|
|
|
12
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
-
|
|
14
12
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
15
13
|
|
|
16
14
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
17
15
|
|
|
16
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
17
|
+
|
|
18
18
|
var _get = _interopRequireDefault(require("lodash/get"));
|
|
19
19
|
|
|
20
20
|
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
@@ -35,27 +35,69 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
35
35
|
|
|
36
36
|
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; }
|
|
37
37
|
|
|
38
|
-
var
|
|
38
|
+
var getFirstValueIfArray = function getFirstValueIfArray(values) {
|
|
39
|
+
return Object.keys(values).reduce(function (acc, key) {
|
|
40
|
+
var val = values[key];
|
|
41
|
+
acc[key] = Array.isArray(val) ? val[0] : val;
|
|
42
|
+
return acc;
|
|
43
|
+
}, {});
|
|
44
|
+
};
|
|
39
45
|
/**
|
|
40
|
-
* Returns
|
|
46
|
+
* Returns true if all fields have no values
|
|
41
47
|
* @param {object} values - Fields values
|
|
42
|
-
* @param {
|
|
48
|
+
* @param {import('../types').Field[]} fields - Fields configuration
|
|
49
|
+
* @returns {boolean} True if all fields have no values
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
exports.getFirstValueIfArray = getFirstValueIfArray;
|
|
54
|
+
|
|
55
|
+
var hasNoValues = function hasNoValues(values, fields) {
|
|
56
|
+
var _values = getFirstValueIfArray(values);
|
|
57
|
+
|
|
58
|
+
return fields.every(function (field) {
|
|
59
|
+
return !(0, _get.default)(_values, field.name);
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Returns true if the input is required and the form is invalid
|
|
64
|
+
* @param {boolean} required - Whether the input is required
|
|
65
|
+
* @param {object} formProps - The form props
|
|
66
|
+
* @returns {boolean} True if the input is required and the form is invalid
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
exports.hasNoValues = hasNoValues;
|
|
71
|
+
|
|
72
|
+
var makeIsRequiredError = function makeIsRequiredError(required, formProps) {
|
|
73
|
+
var valid = formProps.valid,
|
|
74
|
+
submitFailed = formProps.submitFailed;
|
|
75
|
+
return required && !valid && submitFailed;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Returns errors for required fields that are empty
|
|
79
|
+
* @param {object} values - Fields values
|
|
80
|
+
* @param {import('../types').Field[]} fields - Fields configuration
|
|
81
|
+
* @param {Function} t - Translation function
|
|
43
82
|
* @returns {object} Errors
|
|
44
83
|
*/
|
|
45
84
|
|
|
46
|
-
exports.fieldsRequired = fieldsRequired;
|
|
47
85
|
|
|
48
|
-
|
|
86
|
+
exports.makeIsRequiredError = makeIsRequiredError;
|
|
87
|
+
|
|
88
|
+
var validateFields = function validateFields(values, fields, t) {
|
|
49
89
|
var errors = {};
|
|
90
|
+
var fieldsRequired = fields.filter(function (field) {
|
|
91
|
+
return field.required;
|
|
92
|
+
});
|
|
50
93
|
|
|
51
|
-
|
|
52
|
-
return !(0, _get.default)(values, field);
|
|
53
|
-
})) {
|
|
54
|
-
fieldsRequired.forEach(function (field) {
|
|
55
|
-
errors[field] = t('Contacts.AddModal.ContactForm.fields.required');
|
|
56
|
-
});
|
|
57
|
-
}
|
|
94
|
+
var _values = getFirstValueIfArray(values);
|
|
58
95
|
|
|
96
|
+
fieldsRequired.forEach(function (field) {
|
|
97
|
+
if (!(0, _get.default)(_values, field.name)) {
|
|
98
|
+
errors[field.name] = field.layout === 'array' ? [(0, _defineProperty2.default)({}, field.name, t('Contacts.AddModal.ContactForm.fields.required'))] : t('Contacts.AddModal.ContactForm.fields.required');
|
|
99
|
+
}
|
|
100
|
+
});
|
|
59
101
|
return errors;
|
|
60
102
|
};
|
|
61
103
|
/**
|
|
@@ -130,10 +172,10 @@ var movePrimaryToHead = moveToHead(function (v) {
|
|
|
130
172
|
});
|
|
131
173
|
exports.movePrimaryToHead = movePrimaryToHead;
|
|
132
174
|
|
|
133
|
-
var createAddress = function createAddress(
|
|
134
|
-
var address =
|
|
135
|
-
oldContact =
|
|
136
|
-
t =
|
|
175
|
+
var createAddress = function createAddress(_ref2) {
|
|
176
|
+
var address = _ref2.address,
|
|
177
|
+
oldContact = _ref2.oldContact,
|
|
178
|
+
t = _ref2.t;
|
|
137
179
|
return address ? address.filter(function (val) {
|
|
138
180
|
return val && val.address;
|
|
139
181
|
}).map(function (addressField, index) {
|
|
@@ -149,9 +191,9 @@ var createAddress = function createAddress(_ref) {
|
|
|
149
191
|
if (addressHasBeenModified) {
|
|
150
192
|
// Use "code" instead "postcode", to be vcard 4.0 rfc 6350 compliant
|
|
151
193
|
// eslint-disable-next-line no-unused-vars
|
|
152
|
-
var
|
|
153
|
-
postcode =
|
|
154
|
-
oldContactAddressCleaned = (0, _objectWithoutProperties2.default)(
|
|
194
|
+
var _ref3 = oldContactAddress || {},
|
|
195
|
+
postcode = _ref3.postcode,
|
|
196
|
+
oldContactAddressCleaned = (0, _objectWithoutProperties2.default)(_ref3, _excluded);
|
|
155
197
|
|
|
156
198
|
return _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, oldContactAddressCleaned), {}, {
|
|
157
199
|
formattedAddress: addressField.address,
|
|
@@ -229,10 +271,10 @@ exports.getRelatedContactRelationships = getRelatedContactRelationships;
|
|
|
229
271
|
var removeRelatedContactRelationships = function removeRelatedContactRelationships(contact) {
|
|
230
272
|
if (!(contact !== null && contact !== void 0 && contact.relationships)) return contact;
|
|
231
273
|
var updatedContact = (0, _merge.default)({}, contact);
|
|
232
|
-
var relationshipsWithoutRelatedContact = Object.entries(updatedContact.relationships).reduce(function (acc,
|
|
233
|
-
var
|
|
234
|
-
relName =
|
|
235
|
-
relValue =
|
|
274
|
+
var relationshipsWithoutRelatedContact = Object.entries(updatedContact.relationships).reduce(function (acc, _ref4) {
|
|
275
|
+
var _ref5 = (0, _slicedToArray2.default)(_ref4, 2),
|
|
276
|
+
relName = _ref5[0],
|
|
277
|
+
relValue = _ref5[1];
|
|
236
278
|
|
|
237
279
|
if ('related' === relName) {
|
|
238
280
|
acc[relName] = relValue;
|
|
@@ -257,10 +299,10 @@ exports.removeRelatedContactRelationships = removeRelatedContactRelationships;
|
|
|
257
299
|
|
|
258
300
|
var removeAsscociatedData = function removeAsscociatedData(contact) {
|
|
259
301
|
if (!contact) return {};
|
|
260
|
-
return Object.entries(contact).reduce(function (cleanedContact,
|
|
261
|
-
var
|
|
262
|
-
key =
|
|
263
|
-
value =
|
|
302
|
+
return Object.entries(contact).reduce(function (cleanedContact, _ref6) {
|
|
303
|
+
var _ref7 = (0, _slicedToArray2.default)(_ref6, 2),
|
|
304
|
+
key = _ref7[0],
|
|
305
|
+
value = _ref7[1];
|
|
264
306
|
|
|
265
307
|
// Add `groups` condition to keep the old implementation functional, see below
|
|
266
308
|
if (!(value instanceof _cozyClient.Association) || key === 'groups') {
|
|
@@ -386,6 +428,19 @@ var makeImppValues = function makeImppValues(oldContact, value) {
|
|
|
386
428
|
}
|
|
387
429
|
}).filter(Boolean)) || [];
|
|
388
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
|
+
};
|
|
389
444
|
/**
|
|
390
445
|
*
|
|
391
446
|
* @param {string} name
|
|
@@ -394,7 +449,7 @@ var makeImppValues = function makeImppValues(oldContact, value) {
|
|
|
394
449
|
*/
|
|
395
450
|
|
|
396
451
|
|
|
397
|
-
exports.
|
|
452
|
+
exports.initializationFieldValues = initializationFieldValues;
|
|
398
453
|
|
|
399
454
|
var makeInitialCustomValue = function makeInitialCustomValue(name, value) {
|
|
400
455
|
// gender input doesn't support custom label
|
|
@@ -456,9 +511,24 @@ var makeFields = function makeFields(customFields, defaultFields) {
|
|
|
456
511
|
}
|
|
457
512
|
|
|
458
513
|
var fields = (0, _toConsumableArray2.default)(defaultFields);
|
|
459
|
-
customFields.
|
|
460
|
-
|
|
461
|
-
|
|
514
|
+
customFields.forEach(function (customField) {
|
|
515
|
+
var defaultField = fields.find(function (field) {
|
|
516
|
+
return field.name === customField.name;
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
var _field = defaultField || customField;
|
|
520
|
+
|
|
521
|
+
if (defaultField) {
|
|
522
|
+
Object.assign(_field, customField);
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
if (_field.position) {
|
|
526
|
+
if (defaultField) {
|
|
527
|
+
var fieldIndex = fields.indexOf(defaultField);
|
|
528
|
+
fields.splice(fieldIndex, 1);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
fields.splice(_field.position, 0, _field);
|
|
462
532
|
}
|
|
463
533
|
});
|
|
464
534
|
return fields;
|
|
@@ -98,15 +98,20 @@ 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
|
|
105
105
|
}),
|
|
106
106
|
validate: function validate(values) {
|
|
107
|
-
return (0, _helpers.validateFields)(values, t);
|
|
107
|
+
return (0, _helpers.validateFields)(values, _fields, t);
|
|
108
108
|
},
|
|
109
109
|
onSubmit: function onSubmit(formValues) {
|
|
110
|
+
// avoid creating an empty contact
|
|
111
|
+
if ((0, _helpers.hasNoValues)(formValues, _fields)) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
110
115
|
return _onSubmit((0, _formValuesToContact.default)({
|
|
111
116
|
formValues: formValues,
|
|
112
117
|
oldContact: contact,
|
|
@@ -32,7 +32,7 @@ var en = {
|
|
|
32
32
|
relationship: "Relationship",
|
|
33
33
|
note: "Notes",
|
|
34
34
|
label: "Label",
|
|
35
|
-
required: "
|
|
35
|
+
required: "All required fields must be filled in"
|
|
36
36
|
},
|
|
37
37
|
label: {
|
|
38
38
|
none: "None",
|
|
@@ -107,7 +107,7 @@ var fr = {
|
|
|
107
107
|
relationship: "Relation",
|
|
108
108
|
note: "Notes",
|
|
109
109
|
label: "Libell\xE9",
|
|
110
|
-
required: "
|
|
110
|
+
required: "Tous les champs requis doivent \xEAtre renseign\xE9s"
|
|
111
111
|
},
|
|
112
112
|
label: {
|
|
113
113
|
none: "Aucun",
|
|
@@ -182,7 +182,7 @@ var ru = {
|
|
|
182
182
|
relationship: "\u041E\u0442\u043D\u043E\u0448\u0435\u043D\u0438\u0435",
|
|
183
183
|
note: "\u0417\u0430\u043C\u0435\u0442\u043A\u0438",
|
|
184
184
|
label: "\u041C\u0435\u0442\u043A\u0430",
|
|
185
|
-
required: "\
|
|
185
|
+
required: "\u0412\u0441\u0435 \u043E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u044B\u0435 \u043F\u043E\u043B\u044F \u0434\u043E\u043B\u0436\u043D\u044B \u0431\u044B\u0442\u044C \u0437\u0430\u043F\u043E\u043B\u043D\u0435\u043D\u044B"
|
|
186
186
|
},
|
|
187
187
|
label: {
|
|
188
188
|
none: "\u041D\u0435\u0442",
|
|
@@ -257,7 +257,7 @@ var vi = {
|
|
|
257
257
|
relationship: "M\u1ED1i quan h\u1EC7",
|
|
258
258
|
note: "Ghi ch\xFA",
|
|
259
259
|
label: "Nh\xE3n",
|
|
260
|
-
required: "
|
|
260
|
+
required: "T\u1EA5t c\u1EA3 c\xE1c tr\u01B0\u1EDDng b\u1EAFt bu\u1ED9c ph\u1EA3i \u0111\u01B0\u1EE3c \u0111i\u1EC1n"
|
|
261
261
|
},
|
|
262
262
|
label: {
|
|
263
263
|
none: "Kh\xF4ng c\xF3",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export default FieldInput;
|
|
2
|
-
declare function FieldInput({ name, labelProps, className, attributes: { subFields, ...restAttributes }, contacts, error, helperText, label, isInvisible
|
|
2
|
+
declare function FieldInput({ name, labelProps, className, attributes: { subFields, ...restAttributes }, contacts, error, helperText, label, isInvisible }: {
|
|
3
3
|
name: any;
|
|
4
4
|
labelProps: any;
|
|
5
5
|
className: any;
|
|
@@ -12,7 +12,6 @@ declare function FieldInput({ name, labelProps, className, attributes: { subFiel
|
|
|
12
12
|
helperText: any;
|
|
13
13
|
label: any;
|
|
14
14
|
isInvisible: any;
|
|
15
|
-
required: any;
|
|
16
15
|
}): JSX.Element;
|
|
17
16
|
declare namespace FieldInput {
|
|
18
17
|
namespace propTypes {
|
|
@@ -26,12 +25,9 @@ declare namespace FieldInput {
|
|
|
26
25
|
}>>;
|
|
27
26
|
export let id: PropTypes.Requireable<string>;
|
|
28
27
|
export let label: PropTypes.Requireable<string>;
|
|
29
|
-
export let required: PropTypes.Requireable<boolean>;
|
|
30
28
|
}
|
|
31
29
|
namespace defaultProps {
|
|
32
|
-
|
|
33
|
-
let required_1: boolean;
|
|
34
|
-
export { required_1 as required };
|
|
30
|
+
let labelProps: any;
|
|
35
31
|
}
|
|
36
32
|
}
|
|
37
33
|
import PropTypes from 'prop-types';
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
export default FieldInputArray;
|
|
2
|
-
declare function FieldInputArray({ attributes: { name, label, ...restAttributes }, contacts, formProps
|
|
2
|
+
declare function FieldInputArray({ attributes: { name, label, ...restAttributes }, contacts, formProps }: {
|
|
3
3
|
attributes: {
|
|
4
4
|
[x: string]: any;
|
|
5
5
|
name: any;
|
|
6
6
|
label: any;
|
|
7
7
|
};
|
|
8
8
|
contacts: any;
|
|
9
|
-
formProps:
|
|
10
|
-
valid: any;
|
|
11
|
-
submitFailed: any;
|
|
12
|
-
errors: any;
|
|
13
|
-
};
|
|
9
|
+
formProps: any;
|
|
14
10
|
}): JSX.Element;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export
|
|
2
|
-
export function
|
|
1
|
+
export function getFirstValueIfArray(values: any): {};
|
|
2
|
+
export function hasNoValues(values: object, fields: import("../types").Field[]): boolean;
|
|
3
|
+
export function makeIsRequiredError(required: boolean, formProps: object): boolean;
|
|
4
|
+
export function validateFields(values: object, fields: import("../types").Field[], t: Function): object;
|
|
3
5
|
export function makeItemLabel(item?: object): string;
|
|
4
6
|
export function makeTypeAndLabel(itemLabel?: string): {
|
|
5
7
|
type?: string;
|
|
@@ -31,5 +33,6 @@ export function makeImppValues(oldContact: import("cozy-client/types/types").IOC
|
|
|
31
33
|
label: string;
|
|
32
34
|
primary?: boolean;
|
|
33
35
|
}[];
|
|
36
|
+
export function initializationFieldValues(fields: any): any;
|
|
34
37
|
export function makeInitialCustomValue(name: string, value: string): string;
|
|
35
38
|
export function makeFields(customFields: (import("../types").Field)[] | undefined, defaultFields: (import("../types").Field)[]): (import("../types").Field)[];
|