cozy-ui 128.2.0 → 128.3.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.
Files changed (99) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/package.json +6 -2
  3. package/react/Contacts/AddModal/ContactAddressDialog/helpers.js +22 -0
  4. package/react/Contacts/AddModal/ContactAddressDialog/helpers.spec.js +64 -0
  5. package/react/Contacts/AddModal/ContactAddressDialog/index.jsx +84 -0
  6. package/react/Contacts/AddModal/ContactAddressDialog/locales/en.json +25 -0
  7. package/react/Contacts/AddModal/ContactAddressDialog/locales/fr.json +25 -0
  8. package/react/Contacts/AddModal/ContactAddressDialog/locales/index.jsx +7 -0
  9. package/react/Contacts/AddModal/ContactForm/FieldInput.jsx +117 -0
  10. package/react/Contacts/AddModal/ContactForm/FieldInputArray.jsx +80 -0
  11. package/react/Contacts/AddModal/ContactForm/FieldInputLayout.jsx +65 -0
  12. package/react/Contacts/AddModal/ContactForm/FieldInputWrapper.jsx +41 -0
  13. package/react/Contacts/AddModal/ContactForm/HasValueCondition.jsx +31 -0
  14. package/react/Contacts/AddModal/ContactForm/HasValueCondition.spec.jsx +79 -0
  15. package/react/Contacts/AddModal/ContactForm/RelatedContactList.jsx +37 -0
  16. package/react/Contacts/AddModal/ContactForm/TextFieldCustomLabelSelect.jsx +78 -0
  17. package/react/Contacts/AddModal/ContactForm/TextFieldSelect.jsx +39 -0
  18. package/react/Contacts/AddModal/ContactForm/__snapshots__/HasValueCondition.spec.jsx.snap +33 -0
  19. package/react/Contacts/AddModal/ContactForm/contactToFormValues.js +99 -0
  20. package/react/Contacts/AddModal/ContactForm/contactToFormValues.spec.js +128 -0
  21. package/react/Contacts/AddModal/ContactForm/fieldsConfig.jsx +341 -0
  22. package/react/Contacts/AddModal/ContactForm/formValuesToContact.js +100 -0
  23. package/react/Contacts/AddModal/ContactForm/formValuesToContact.spec.js +494 -0
  24. package/react/Contacts/AddModal/ContactForm/helpers.js +324 -0
  25. package/react/Contacts/AddModal/ContactForm/helpers.spec.js +152 -0
  26. package/react/Contacts/AddModal/ContactForm/index.jsx +104 -0
  27. package/react/Contacts/AddModal/ContactForm/index.spec.jsx +289 -0
  28. package/react/Contacts/AddModal/ContactForm/locales/en.json +73 -0
  29. package/react/Contacts/AddModal/ContactForm/locales/fr.json +73 -0
  30. package/react/Contacts/AddModal/ContactForm/locales/index.jsx +7 -0
  31. package/react/Contacts/AddModal/ContactForm/styles.styl +2 -0
  32. package/react/Contacts/AddModal/CustomLabelDialog/index.jsx +108 -0
  33. package/react/Contacts/AddModal/CustomLabelDialog/locales/en.json +15 -0
  34. package/react/Contacts/AddModal/CustomLabelDialog/locales/fr.json +15 -0
  35. package/react/Contacts/AddModal/CustomLabelDialog/locales/index.jsx +7 -0
  36. package/react/Contacts/AddModal/Readme.md +46 -0
  37. package/react/Contacts/AddModal/index.jsx +78 -0
  38. package/react/Contacts/AddModal/locales/en.json +13 -0
  39. package/react/Contacts/AddModal/locales/fr.json +13 -0
  40. package/react/Contacts/AddModal/locales/index.jsx +7 -0
  41. package/react/Contacts/AddModal/mocks.js +249 -0
  42. package/react/Contacts/AddModal/types.js +57 -0
  43. package/react/Contacts/Header/Readme.md +0 -2
  44. package/react/providers/DemoProvider.jsx +3 -2
  45. package/transpiled/react/Contacts/AddModal/ContactAddressDialog/helpers.d.ts +4 -0
  46. package/transpiled/react/Contacts/AddModal/ContactAddressDialog/helpers.js +20 -0
  47. package/transpiled/react/Contacts/AddModal/ContactAddressDialog/helpers.spec.d.ts +1 -0
  48. package/transpiled/react/Contacts/AddModal/ContactAddressDialog/index.d.ts +39 -0
  49. package/transpiled/react/Contacts/AddModal/ContactAddressDialog/index.js +87 -0
  50. package/transpiled/react/Contacts/AddModal/ContactAddressDialog/locales/index.d.ts +6 -0
  51. package/transpiled/react/Contacts/AddModal/ContactAddressDialog/locales/index.js +54 -0
  52. package/transpiled/react/Contacts/AddModal/ContactForm/FieldInput.d.ts +35 -0
  53. package/transpiled/react/Contacts/AddModal/ContactForm/FieldInput.js +126 -0
  54. package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputArray.d.ts +14 -0
  55. package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputArray.js +82 -0
  56. package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputLayout.d.ts +20 -0
  57. package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputLayout.js +70 -0
  58. package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputWrapper.d.ts +16 -0
  59. package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputWrapper.js +31 -0
  60. package/transpiled/react/Contacts/AddModal/ContactForm/HasValueCondition.d.ts +18 -0
  61. package/transpiled/react/Contacts/AddModal/ContactForm/HasValueCondition.js +32 -0
  62. package/transpiled/react/Contacts/AddModal/ContactForm/HasValueCondition.spec.d.ts +1 -0
  63. package/transpiled/react/Contacts/AddModal/ContactForm/RelatedContactList.d.ts +15 -0
  64. package/transpiled/react/Contacts/AddModal/ContactForm/RelatedContactList.js +39 -0
  65. package/transpiled/react/Contacts/AddModal/ContactForm/TextFieldCustomLabelSelect.d.ts +9 -0
  66. package/transpiled/react/Contacts/AddModal/ContactForm/TextFieldCustomLabelSelect.js +81 -0
  67. package/transpiled/react/Contacts/AddModal/ContactForm/TextFieldSelect.d.ts +5 -0
  68. package/transpiled/react/Contacts/AddModal/ContactForm/TextFieldSelect.js +42 -0
  69. package/transpiled/react/Contacts/AddModal/ContactForm/contactToFormValues.d.ts +2 -0
  70. package/transpiled/react/Contacts/AddModal/ContactForm/contactToFormValues.js +88 -0
  71. package/transpiled/react/Contacts/AddModal/ContactForm/contactToFormValues.spec.d.ts +1 -0
  72. package/transpiled/react/Contacts/AddModal/ContactForm/fieldsConfig.d.ts +4 -0
  73. package/transpiled/react/Contacts/AddModal/ContactForm/fieldsConfig.js +278 -0
  74. package/transpiled/react/Contacts/AddModal/ContactForm/formValuesToContact.d.ts +6 -0
  75. package/transpiled/react/Contacts/AddModal/ContactForm/formValuesToContact.js +94 -0
  76. package/transpiled/react/Contacts/AddModal/ContactForm/formValuesToContact.spec.d.ts +1 -0
  77. package/transpiled/react/Contacts/AddModal/ContactForm/helpers.d.ts +28 -0
  78. package/transpiled/react/Contacts/AddModal/ContactForm/helpers.js +335 -0
  79. package/transpiled/react/Contacts/AddModal/ContactForm/helpers.spec.d.ts +1 -0
  80. package/transpiled/react/Contacts/AddModal/ContactForm/index.d.ts +11 -0
  81. package/transpiled/react/Contacts/AddModal/ContactForm/index.js +114 -0
  82. package/transpiled/react/Contacts/AddModal/ContactForm/index.spec.d.ts +1 -0
  83. package/transpiled/react/Contacts/AddModal/ContactForm/locales/index.d.ts +6 -0
  84. package/transpiled/react/Contacts/AddModal/ContactForm/locales/index.js +150 -0
  85. package/transpiled/react/Contacts/AddModal/CustomLabelDialog/index.d.ts +22 -0
  86. package/transpiled/react/Contacts/AddModal/CustomLabelDialog/index.js +113 -0
  87. package/transpiled/react/Contacts/AddModal/CustomLabelDialog/locales/index.d.ts +6 -0
  88. package/transpiled/react/Contacts/AddModal/CustomLabelDialog/locales/index.js +34 -0
  89. package/transpiled/react/Contacts/AddModal/index.d.ts +7 -0
  90. package/transpiled/react/Contacts/AddModal/index.js +109 -0
  91. package/transpiled/react/Contacts/AddModal/locales/index.d.ts +6 -0
  92. package/transpiled/react/Contacts/AddModal/locales/index.js +30 -0
  93. package/transpiled/react/Contacts/AddModal/mocks.d.ts +270 -0
  94. package/transpiled/react/Contacts/AddModal/mocks.js +214 -0
  95. package/transpiled/react/Contacts/AddModal/types.d.ts +54 -0
  96. package/transpiled/react/Contacts/AddModal/types.js +49 -0
  97. package/transpiled/react/providers/DemoProvider.d.ts +2 -1
  98. package/transpiled/react/providers/DemoProvider.js +7 -3
  99. package/transpiled/react/stylesheet.css +1 -1
@@ -0,0 +1,335 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
5
+ var _excluded = ["postcode"];
6
+
7
+ 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; }
8
+
9
+ 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) { _defineProperty(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; }
10
+
11
+ import get from 'lodash/get';
12
+ import isEqual from 'lodash/isEqual';
13
+ import merge from 'lodash/merge';
14
+ import uniqueId from 'lodash/uniqueId';
15
+ import { Association } from 'cozy-client';
16
+ import { makeDisplayName } from 'cozy-client/dist/models/contact';
17
+ import { CONTACTS_DOCTYPE } from 'cozy-client/dist/models/contact';
18
+ import contactToFormValues from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/contactToFormValues";
19
+ export var fieldsRequired = ['givenName', 'familyName', 'email[0].email', 'cozy'];
20
+ /**
21
+ * Returns errors if all required fields are empty
22
+ * @param {object} values - Fields values
23
+ * @param {func} t - Translation function
24
+ * @returns {object} Errors
25
+ */
26
+
27
+ export var validateFields = function validateFields(values, t) {
28
+ var errors = {};
29
+
30
+ if (fieldsRequired.every(function (field) {
31
+ return !get(values, field);
32
+ })) {
33
+ fieldsRequired.forEach(function (field) {
34
+ errors[field] = t('Contacts.AddModal.ContactForm.fields.required');
35
+ });
36
+ }
37
+
38
+ return errors;
39
+ };
40
+ /**
41
+ * @param {object} [item] - Contact attribute
42
+ * @returns {string} Stringified object
43
+ */
44
+
45
+ export var makeItemLabel = function makeItemLabel(item) {
46
+ if (!item) return undefined;
47
+ var res = item.label || item.type ? JSON.stringify({
48
+ type: item.type,
49
+ label: item.label
50
+ }) : undefined;
51
+ return res;
52
+ };
53
+ /**
54
+ *
55
+ * @param {string} [itemLabel] - Value of the label for a contact attribute
56
+ * @returns {{ type?: string, label?: string }}
57
+ */
58
+
59
+ export var makeTypeAndLabel = function makeTypeAndLabel(itemLabel) {
60
+ if (!itemLabel) {
61
+ return {
62
+ type: undefined,
63
+ label: undefined
64
+ };
65
+ }
66
+
67
+ var itemLabelObj = JSON.parse(itemLabel);
68
+ var res = {
69
+ type: itemLabelObj.type,
70
+ label: itemLabelObj.label
71
+ };
72
+ return res;
73
+ };
74
+ /**
75
+ * @param {object} addressField
76
+ * @returns {boolean} True if addressField has extended address
77
+ */
78
+
79
+ export var hasExtendedAddress = function hasExtendedAddress(addressField) {
80
+ if (!addressField) return false;
81
+ var extendedAddressKeys = ['addresslocality', 'addressbuilding', 'addressstairs', 'addressfloor', 'addressapartment', 'addressentrycode'];
82
+ return Object.keys(addressField).some(function (ext) {
83
+ return extendedAddressKeys.includes(ext);
84
+ });
85
+ };
86
+ export var moveToHead = function moveToHead(shouldBeHead) {
87
+ return function (items) {
88
+ return items.reduce(function (arr, v) {
89
+ return shouldBeHead(v) ? [v].concat(_toConsumableArray(arr)) : [].concat(_toConsumableArray(arr), [v]);
90
+ }, []);
91
+ };
92
+ };
93
+ export var movePrimaryToHead = moveToHead(function (v) {
94
+ return v === null || v === void 0 ? void 0 : v.primary;
95
+ });
96
+ export var createAddress = function createAddress(_ref) {
97
+ var address = _ref.address,
98
+ oldContact = _ref.oldContact,
99
+ t = _ref.t;
100
+ return address ? address.filter(function (val) {
101
+ return val && val.address;
102
+ }).map(function (addressField, index) {
103
+ var _oldContact$address, _contactToFormValues, _contactToFormValues$;
104
+
105
+ var oldContactAddress = oldContact === null || oldContact === void 0 ? void 0 : (_oldContact$address = oldContact.address) === null || _oldContact$address === void 0 ? void 0 : _oldContact$address[index];
106
+ var oldContactFormValues = (_contactToFormValues = contactToFormValues(oldContact, t)) === null || _contactToFormValues === void 0 ? void 0 : (_contactToFormValues$ = _contactToFormValues.address) === null || _contactToFormValues$ === void 0 ? void 0 : _contactToFormValues$[index];
107
+ var addressHasBeenModified = !isEqual(addressField, oldContactFormValues);
108
+
109
+ if (addressHasBeenModified) {
110
+ // Use "code" instead "postcode", to be vcard 4.0 rfc 6350 compliant
111
+ // eslint-disable-next-line no-unused-vars
112
+ var _ref2 = oldContactAddress || {},
113
+ postcode = _ref2.postcode,
114
+ oldContactAddressCleaned = _objectWithoutProperties(_ref2, _excluded);
115
+
116
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, oldContactAddressCleaned), {}, {
117
+ formattedAddress: addressField.address,
118
+ number: addressField.addressnumber,
119
+ street: addressField.addressstreet,
120
+ code: addressField.addresscode,
121
+ city: addressField.addresscity,
122
+ region: addressField.addressregion,
123
+ country: addressField.addresscountry
124
+ }, hasExtendedAddress(addressField) && {
125
+ extendedAddress: _objectSpread(_objectSpread({}, oldContactAddressCleaned.extendedAddress), {}, {
126
+ locality: addressField.addresslocality,
127
+ building: addressField.addressbuilding,
128
+ stairs: addressField.addressstairs,
129
+ floor: addressField.addressfloor,
130
+ apartment: addressField.addressapartment,
131
+ entrycode: addressField.addressentrycode
132
+ })
133
+ }), makeTypeAndLabel(addressField.addressLabel)), {}, {
134
+ primary: index === 0
135
+ });
136
+ }
137
+
138
+ return oldContactAddress;
139
+ }) : [];
140
+ };
141
+ /**
142
+ * @param {(import('../../../types').RelatedContact|undefined)[]} relatedContact - The related contacts array
143
+ * @returns {Record<string, { data: { _id: string, _type: string }[] }>} - The related contacts relationships
144
+ */
145
+
146
+ export var getRelatedContactRelationships = function getRelatedContactRelationships(relatedContact) {
147
+ // Tips filter Boolean to remove undefined value from array when relatedContact is empty (see contactToFormValues)
148
+ var data = relatedContact.filter(Boolean).reduce(function (acc, curr) {
149
+ var relationType = curr.relatedContactLabel ? JSON.parse(curr.relatedContactLabel).type : 'related';
150
+ var existingIndex = acc.findIndex(function (item) {
151
+ return item._id === curr.relatedContactId;
152
+ });
153
+
154
+ if (existingIndex !== -1) {
155
+ acc[existingIndex].metadata.relationTypes = Array.from(new Set([].concat(_toConsumableArray(acc[existingIndex].metadata.relationTypes), [relationType])));
156
+ } else {
157
+ acc.push({
158
+ _id: curr.relatedContactId,
159
+ _type: CONTACTS_DOCTYPE,
160
+ metadata: {
161
+ relationTypes: [relationType]
162
+ }
163
+ });
164
+ }
165
+
166
+ return acc;
167
+ }, []); // `data` can be empty, you still have to return an object to override the behavior of the cozy-client store, otherwise it will keep the old value, and without refreshing the page, the data will not be up to date in the store and therefore on the interface
168
+
169
+ return {
170
+ related: {
171
+ data: data
172
+ }
173
+ };
174
+ };
175
+ /**
176
+ * When changing the type of relationship, it must be ensured that no empty relationship remains.
177
+ * The old and new ones are merged into `formValuesToContact`.
178
+ *
179
+ * @param {import('cozy-client/types/types').IOCozyContact} contact - The contact object with all relationships
180
+ * @returns {import('cozy-client/types/types').IOCozyContact} - The contact object without the related contacts relationships
181
+ */
182
+
183
+ export var removeRelatedContactRelationships = function removeRelatedContactRelationships(contact) {
184
+ if (!(contact !== null && contact !== void 0 && contact.relationships)) return contact;
185
+ var updatedContact = merge({}, contact);
186
+ var relationshipsWithoutRelatedContact = Object.entries(updatedContact.relationships).reduce(function (acc, _ref3) {
187
+ var _ref4 = _slicedToArray(_ref3, 2),
188
+ relName = _ref4[0],
189
+ relValue = _ref4[1];
190
+
191
+ if ('related' === relName) {
192
+ acc[relName] = relValue;
193
+ }
194
+
195
+ return acc;
196
+ }, {});
197
+ updatedContact.relationships = relationshipsWithoutRelatedContact;
198
+ return updatedContact;
199
+ }; // TODO : Update dehydrate function to HasMany class in cozy-client
200
+
201
+ /**
202
+ * This function is used to clean the contact object from the associated data
203
+ * cozy-client dehydrates the document before saving it (via the `HasMany` method), but by doing it manually, we ensure that all hydrated relationships in the document (and without data of course) are not saved in the `relationships` of the document, which adds unnecessary data.
204
+ *
205
+ * @param {import('cozy-client/types/types').IOCozyContact} contact - The contact object with associated data
206
+ * @returns {import('cozy-client/types/types').IOCozyContact} - The contact object without associated data
207
+ */
208
+
209
+ export var removeAsscociatedData = function removeAsscociatedData(contact) {
210
+ if (!contact) return {};
211
+ return Object.entries(contact).reduce(function (cleanedContact, _ref5) {
212
+ var _ref6 = _slicedToArray(_ref5, 2),
213
+ key = _ref6[0],
214
+ value = _ref6[1];
215
+
216
+ // Add `groups` condition to keep the old implementation functional, see below
217
+ if (!(value instanceof Association) || key === 'groups') {
218
+ cleanedContact[key] = value;
219
+ }
220
+
221
+ return cleanedContact;
222
+ }, {});
223
+ };
224
+ /**
225
+ * @param {import('cozy-client/types/types').IOCozyContact} contact
226
+ * @returns {import('../../../types').RelatedContact[]}
227
+ */
228
+
229
+ export var makeRelatedContact = function makeRelatedContact(contact) {
230
+ var _contact$relationship;
231
+
232
+ if (!(contact.related instanceof Association) || !((_contact$relationship = contact.relationships) !== null && _contact$relationship !== void 0 && _contact$relationship.related)) {
233
+ return [undefined];
234
+ }
235
+
236
+ var relatedData = contact.related.data.reduce(function (acc, curr) {
237
+ // Use `makeDisplayName` because if the contact is newly created, it has no `displayName` attribute. (Creation of a contact when selecting a linked contact)
238
+ acc[curr._id] = curr.displayName || makeDisplayName(curr);
239
+ return acc;
240
+ }, {});
241
+ var res = contact.relationships.related.data.flatMap(function (item) {
242
+ return item.metadata.relationTypes.map(function (type) {
243
+ return {
244
+ relatedContactId: item._id,
245
+ relatedContact: relatedData[item._id],
246
+ relatedContactLabel: makeItemLabel({
247
+ type: type === 'related' ? '' : type
248
+ })
249
+ };
250
+ });
251
+ }); // Useful because a contact always has at least the `related` relationships (see `getRelatedContactRelationships`)
252
+
253
+ return res.length > 0 ? res : [undefined];
254
+ };
255
+ export var addField = function addField(fields) {
256
+ return fields.push({
257
+ fieldId: uniqueId('fieldId_')
258
+ });
259
+ };
260
+ export var removeField = function removeField(fields, index) {
261
+ var isLastRemainingField = fields.length === 1;
262
+
263
+ if (isLastRemainingField) {
264
+ fields.update(index, undefined);
265
+ } else {
266
+ fields.remove(index);
267
+ }
268
+ };
269
+ /**
270
+ *
271
+ * @param {string} value
272
+ * @param {func} t
273
+ * @returns {string}
274
+ */
275
+
276
+ export var makeCustomLabel = function makeCustomLabel(value, t) {
277
+ var _JSON$parse = JSON.parse(value),
278
+ type = _JSON$parse.type,
279
+ label = _JSON$parse.label;
280
+
281
+ var firstString = type || '';
282
+ var secondString = label ? type ? " (".concat(t("Contacts.AddModal.ContactForm.label.".concat(label)), ")").toLowerCase() : "label.".concat(label) : '';
283
+ return firstString + secondString || null;
284
+ };
285
+ /**
286
+ *
287
+ * @param {string} name
288
+ * @param {string} value
289
+ * @returns {string}
290
+ */
291
+
292
+ export var makeInitialCustomValue = function makeInitialCustomValue(name, value) {
293
+ // gender input doesn't support custom label
294
+ if (!name || !value || name === 'gender') return undefined;
295
+ var valueObj = JSON.parse(value); // Voluntarily before the "backwards compatibility" condition
296
+
297
+ if (name.includes('relatedContactLabel')) {
298
+ if (!'related' === valueObj.type) {
299
+ return JSON.stringify({
300
+ type: valueObj.type
301
+ });
302
+ }
303
+
304
+ return undefined;
305
+ } // for backwards compatiblity - historically there is only type and no label
306
+
307
+
308
+ if (valueObj.type && !valueObj.label) {
309
+ return JSON.stringify({
310
+ type: valueObj.type
311
+ });
312
+ } // for phone label
313
+
314
+
315
+ if (name.includes('phoneLabel')) {
316
+ // but unsupported one
317
+ if (!['cell', 'voice', 'fax'].includes(valueObj.type)) {
318
+ return JSON.stringify({
319
+ type: valueObj.type,
320
+ label: valueObj.label
321
+ });
322
+ } // we don't want to create a custom label if supported
323
+
324
+
325
+ return undefined;
326
+ } // at this point if label and type are both present, it's a custom label
327
+
328
+
329
+ if (valueObj.type && valueObj.label) {
330
+ return JSON.stringify({
331
+ type: valueObj.type,
332
+ label: valueObj.label
333
+ });
334
+ }
335
+ };
@@ -0,0 +1,11 @@
1
+ export function getSubmitContactForm(): any;
2
+ export function isSameContactProp(prevProps: any, nextProps: any): boolean;
3
+ declare var _default: React.MemoExoticComponent<({ contact, onSubmit, contacts }: {
4
+ contact: import('cozy-client/types/types').IOCozyContact;
5
+ onSubmit: func;
6
+ contacts: {
7
+ data: Array<object>;
8
+ };
9
+ }) => JSX.Element>;
10
+ export default _default;
11
+ import React from "react";
@@ -0,0 +1,114 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+
3
+ 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; }
4
+
5
+ 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) { _defineProperty(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; }
6
+
7
+ import arrayMutators from 'final-form-arrays';
8
+ import React from 'react';
9
+ import { Form } from 'react-final-form';
10
+ import { getHasManyItems } from 'cozy-client/dist/associations/HasMany';
11
+ import FieldInputLayout from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/FieldInputLayout";
12
+ import contactToFormValues from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/contactToFormValues";
13
+ import { fields } from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/fieldsConfig";
14
+ import formValuesToContact from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/formValuesToContact";
15
+ import { validateFields } from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/helpers";
16
+ import { locales } from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/locales";
17
+ import { useI18n, useExtendI18n } from "cozy-ui/transpiled/react/providers/I18n"; // import { fullContactPropTypes } from '../../ContactPropTypes' // !!
18
+ // this variable will be set in the form's render prop
19
+ // and used by the submit button in ContactFormModal
20
+ // to be able to trigger the submit from outside the form
21
+ // See react-final-form examples here: https://www.npmjs.com/package/react-final-form#external-submit
22
+
23
+ var _submitContactForm;
24
+
25
+ function setSubmitContactForm(handleSubmit) {
26
+ _submitContactForm = handleSubmit;
27
+ }
28
+
29
+ export function getSubmitContactForm() {
30
+ return _submitContactForm;
31
+ }
32
+ /**
33
+ *
34
+ * @param {object} params
35
+ * @param {import('cozy-client/types/types').IOCozyContact} params.contact
36
+ * @param {func} params.onSubmit
37
+ * @param {{ data: Array<object> }} params.contacts
38
+ * @returns
39
+ */
40
+
41
+ var ContactForm = function ContactForm(_ref) {
42
+ var contact = _ref.contact,
43
+ _onSubmit = _ref.onSubmit,
44
+ contacts = _ref.contacts;
45
+ useExtendI18n(locales);
46
+
47
+ var _useI18n = useI18n(),
48
+ t = _useI18n.t;
49
+
50
+ return /*#__PURE__*/React.createElement(Form, {
51
+ mutators: _objectSpread({}, arrayMutators),
52
+ validate: function validate(values) {
53
+ return validateFields(values, t);
54
+ },
55
+ onSubmit: function onSubmit(formValues) {
56
+ return _onSubmit(formValuesToContact({
57
+ formValues: formValues,
58
+ oldContact: contact,
59
+ t: t
60
+ }));
61
+ },
62
+ initialValues: contactToFormValues(contact, t),
63
+ render: function render(_ref2) {
64
+ var handleSubmit = _ref2.handleSubmit,
65
+ valid = _ref2.valid,
66
+ submitFailed = _ref2.submitFailed,
67
+ errors = _ref2.errors;
68
+ setSubmitContactForm(handleSubmit);
69
+ return /*#__PURE__*/React.createElement("form", {
70
+ role: "form",
71
+ onSubmit: handleSubmit,
72
+ className: "u-flex u-flex-column"
73
+ }, fields.map(function (attributes, index) {
74
+ return /*#__PURE__*/React.createElement(FieldInputLayout, {
75
+ key: index,
76
+ attributes: attributes,
77
+ contacts: contacts,
78
+ formProps: {
79
+ valid: valid,
80
+ submitFailed: submitFailed,
81
+ errors: errors
82
+ }
83
+ });
84
+ }));
85
+ }
86
+ });
87
+ }; // Used to avoid unnecessary multiple rendering of ContactForm when creating a new contact in another way.
88
+ // These unnecessary renderings prevented the addition of a newly created linked contact. (Creation of a contact when selecting a linked contact)
89
+
90
+
91
+ export var isSameContactProp = function isSameContactProp(prevProps, nextProps) {
92
+ var _prevProps$contact, _nextProps$contact;
93
+
94
+ if (!((_prevProps$contact = prevProps.contact) !== null && _prevProps$contact !== void 0 && _prevProps$contact.relationships) || !((_nextProps$contact = nextProps.contact) !== null && _nextProps$contact !== void 0 && _nextProps$contact.relationships)) {
95
+ return false;
96
+ }
97
+
98
+ var prevContactIdsRelated = getHasManyItems(prevProps.contact, 'related').map(function (r) {
99
+ return r._id;
100
+ });
101
+ var nextContactIdsRelated = getHasManyItems(nextProps.contact, 'related').map(function (r) {
102
+ return r._id;
103
+ });
104
+
105
+ if (prevContactIdsRelated.length !== nextContactIdsRelated.length || !prevContactIdsRelated.every(function (id) {
106
+ return nextContactIdsRelated.includes(id);
107
+ })) {
108
+ return false;
109
+ }
110
+
111
+ return true;
112
+ }; // export default ContactForm
113
+
114
+ export default /*#__PURE__*/React.memo(ContactForm, isSameContactProp);
@@ -0,0 +1,6 @@
1
+ export namespace locales {
2
+ export { en };
3
+ export { fr };
4
+ }
5
+ import en from "./en.json";
6
+ import fr from "./fr.json";
@@ -0,0 +1,150 @@
1
+ var en = {
2
+ Contacts: {
3
+ AddModal: {
4
+ ContactForm: {
5
+ gender: {
6
+ man: "Man",
7
+ woman: "Woman"
8
+ },
9
+ fields: {
10
+ gender: "Civility",
11
+ givenName: "Firstname",
12
+ additionalName: "2nd firstname",
13
+ surname: "Name in use",
14
+ familyName: "Lastname",
15
+ phone: "Phone",
16
+ email: "Email",
17
+ address: "Address",
18
+ cozy: "Twake URL",
19
+ company: "Company",
20
+ jobTitle: "Job title",
21
+ birthday: "Birthday",
22
+ birthplace: "Birthplace",
23
+ relatedContact: "Related contact",
24
+ relationship: "Relationship",
25
+ note: "Notes",
26
+ label: "Label",
27
+ required: "One of these fields must be filled in"
28
+ },
29
+ label: {
30
+ none: "None",
31
+ home: "Personal",
32
+ work: "Pro",
33
+ custom: "Customised",
34
+ phone: {
35
+ "cell-home": "Cell (personal)",
36
+ "cell-work": "Cell (pro)",
37
+ "voice-home": "Voice (personal)",
38
+ "voice-work": "Voice (pro)",
39
+ "fax-home": "Fax (personal)",
40
+ "fax-work": "Fax (pro)"
41
+ },
42
+ address: {
43
+ home: "Home (personal)",
44
+ work: "Work (pro)"
45
+ },
46
+ relationship: {
47
+ parent: "Parent",
48
+ child: "Child",
49
+ sibling: "Sibling",
50
+ spouse: "Spouse",
51
+ coResident: "Co-resident",
52
+ friend: "Friend",
53
+ colleague: "Colleague",
54
+ coWorker: "Co-worker",
55
+ acquaintance: "Acquaintance",
56
+ helper: "Helper",
57
+ recipient: "Recipient"
58
+ }
59
+ },
60
+ addLabel: {
61
+ address: "Add an address",
62
+ email: "Add an email",
63
+ phone: "Add a phone",
64
+ relatedContact: "Add a related contact"
65
+ }
66
+ }
67
+ }
68
+ },
69
+ formatted: {
70
+ date: "yyyy-LL-dd",
71
+ address: "%{number} %{street}, %{code} %{city}, %{country}"
72
+ }
73
+ };
74
+ var fr = {
75
+ Contacts: {
76
+ AddModal: {
77
+ ContactForm: {
78
+ gender: {
79
+ man: "Homme",
80
+ woman: "Femme"
81
+ },
82
+ fields: {
83
+ gender: "Civilit\xE9",
84
+ givenName: "Pr\xE9nom",
85
+ additionalName: "2e pr\xE9nom",
86
+ surname: "Nom d'usage",
87
+ familyName: "Nom",
88
+ phone: "T\xE9l\xE9phone",
89
+ email: "Email",
90
+ address: "Adresse",
91
+ cozy: "URL du Twake",
92
+ company: "Entreprise",
93
+ jobTitle: "Fonction",
94
+ birthday: "Anniversaire",
95
+ birthplace: "Lieu de naissance",
96
+ relatedContact: "Contact li\xE9",
97
+ relationship: "Relation",
98
+ note: "Notes",
99
+ label: "Libell\xE9",
100
+ required: "Un de ces champs doit \xEAtre renseign\xE9"
101
+ },
102
+ label: {
103
+ none: "Aucun",
104
+ home: "Perso",
105
+ work: "Pro",
106
+ custom: "Personnalis\xE9",
107
+ phone: {
108
+ "cell-home": "Mobile (perso)",
109
+ "cell-work": "Mobile (pro)",
110
+ "voice-home": "Fixe (perso)",
111
+ "voice-work": "Fixe (pro)",
112
+ "fax-home": "Fax (perso)",
113
+ "fax-work": "Fax (pro)"
114
+ },
115
+ address: {
116
+ home: "Domicile (perso)",
117
+ work: "Travail (pro)"
118
+ },
119
+ relationship: {
120
+ parent: "Parent",
121
+ child: "Enfant",
122
+ sibling: "Fr\xE8re/Soeur",
123
+ spouse: "Conjoint",
124
+ coResident: "Colocataire",
125
+ friend: "Ami",
126
+ colleague: "Coll\xE8gue/Collaborateur",
127
+ coWorker: "Associ\xE9/Partenaire",
128
+ acquaintance: "Connaissance",
129
+ helper: "Assistant/Aidant",
130
+ recipient: "B\xE9n\xE9ficiaire/Aid\xE9"
131
+ }
132
+ },
133
+ addLabel: {
134
+ address: "Ajouter une adresse",
135
+ email: "Ajouter un email",
136
+ phone: "Ajouter un t\xE9l\xE9phone",
137
+ relatedContact: "Ajouter un contact li\xE9"
138
+ }
139
+ }
140
+ }
141
+ },
142
+ formatted: {
143
+ date: "dd/LL/yyyy",
144
+ address: "%{number} %{street}, %{code} %{city}, %{country}"
145
+ }
146
+ };
147
+ export var locales = {
148
+ en: en,
149
+ fr: fr
150
+ };
@@ -0,0 +1,22 @@
1
+ export default CustomLabelDialog;
2
+ declare function CustomLabelDialog({ customValue, setCustomValue, customLabelOptions, onSubmit, onClose }: {
3
+ customValue: any;
4
+ setCustomValue: any;
5
+ customLabelOptions: any;
6
+ onSubmit: any;
7
+ onClose: any;
8
+ }): JSX.Element;
9
+ declare namespace CustomLabelDialog {
10
+ namespace propTypes {
11
+ const customValue: PropTypes.Requireable<string>;
12
+ const setCustomValue: PropTypes.Requireable<(...args: any[]) => any>;
13
+ const customLabelOptions: PropTypes.Requireable<PropTypes.InferProps<{
14
+ hide: PropTypes.Requireable<boolean>;
15
+ defaultType: PropTypes.Requireable<string>;
16
+ defaultLabel: PropTypes.Requireable<string>;
17
+ }>>;
18
+ const onSubmit: PropTypes.Requireable<(...args: any[]) => any>;
19
+ const onClose: PropTypes.Requireable<(...args: any[]) => any>;
20
+ }
21
+ }
22
+ import PropTypes from "prop-types";