cozy-ui 128.2.0 → 128.3.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.
Files changed (99) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/package.json +5 -1
  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,88 @@
1
+ import uniqueId from 'lodash/uniqueId';
2
+ import { getFormattedAddress } from 'cozy-client/dist/models/contact';
3
+ import { fields } from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/fieldsConfig";
4
+ import { makeItemLabel, makeRelatedContact, movePrimaryToHead } from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/helpers";
5
+
6
+ var contactToFormValues = function contactToFormValues(contact, t) {
7
+ // initialize the form values, required so that array fields start with at least one editable field
8
+ var initialFieldValues = fields.reduce(function (initialValues, _ref) {
9
+ var name = _ref.name,
10
+ isArray = _ref.isArray;
11
+ initialValues[name] = isArray ? [undefined] : undefined;
12
+ return initialValues;
13
+ }, {});
14
+
15
+ if (contact) {
16
+ var gender = contact.gender,
17
+ address = contact.address,
18
+ birthday = contact.birthday,
19
+ birthplace = contact.birthplace,
20
+ company = contact.company,
21
+ jobTitle = contact.jobTitle,
22
+ cozy = contact.cozy,
23
+ email = contact.email,
24
+ name = contact.name,
25
+ note = contact.note,
26
+ phone = contact.phone;
27
+ var addressValue = address && address.length > 0 ? movePrimaryToHead(address).map(function (addressInfo) {
28
+ var _addressInfo$extended, _addressInfo$extended2, _addressInfo$extended3, _addressInfo$extended4, _addressInfo$extended5, _addressInfo$extended6;
29
+
30
+ return {
31
+ fieldId: uniqueId('fieldId_'),
32
+ address: getFormattedAddress(addressInfo, t),
33
+ addressnumber: addressInfo.number,
34
+ addressstreet: addressInfo.street || getFormattedAddress(addressInfo, t),
35
+ addresscode: addressInfo.postcode || addressInfo.code,
36
+ addresscity: addressInfo.city,
37
+ addressregion: addressInfo.region,
38
+ addresscountry: addressInfo.country,
39
+ addresslocality: (_addressInfo$extended = addressInfo.extendedAddress) === null || _addressInfo$extended === void 0 ? void 0 : _addressInfo$extended.locality,
40
+ addressbuilding: (_addressInfo$extended2 = addressInfo.extendedAddress) === null || _addressInfo$extended2 === void 0 ? void 0 : _addressInfo$extended2.building,
41
+ addressstairs: (_addressInfo$extended3 = addressInfo.extendedAddress) === null || _addressInfo$extended3 === void 0 ? void 0 : _addressInfo$extended3.stairs,
42
+ addressfloor: (_addressInfo$extended4 = addressInfo.extendedAddress) === null || _addressInfo$extended4 === void 0 ? void 0 : _addressInfo$extended4.floor,
43
+ addressapartment: (_addressInfo$extended5 = addressInfo.extendedAddress) === null || _addressInfo$extended5 === void 0 ? void 0 : _addressInfo$extended5.apartment,
44
+ addressentrycode: (_addressInfo$extended6 = addressInfo.extendedAddress) === null || _addressInfo$extended6 === void 0 ? void 0 : _addressInfo$extended6.entrycode,
45
+ addressLabel: makeItemLabel(addressInfo)
46
+ };
47
+ }) : [undefined];
48
+ var cozyValue = cozy && cozy.length > 0 ? cozy[0].url : undefined;
49
+ var cozyLabel = cozy && cozy.length > 0 ? makeItemLabel(cozy[0]) : undefined;
50
+ var emailValue = email && email.length > 0 ? movePrimaryToHead(email).map(function (item) {
51
+ return {
52
+ fieldId: uniqueId('fieldId_'),
53
+ email: item === null || item === void 0 ? void 0 : item.address,
54
+ emailLabel: makeItemLabel(item)
55
+ };
56
+ }) : [undefined];
57
+ var phoneValue = phone && phone.length > 0 ? movePrimaryToHead(phone).map(function (item) {
58
+ return {
59
+ fieldId: uniqueId('fieldId_'),
60
+ phone: item === null || item === void 0 ? void 0 : item.number,
61
+ phoneLabel: makeItemLabel(item)
62
+ };
63
+ }) : [undefined];
64
+ var relatedContactValue = makeRelatedContact(contact);
65
+ return {
66
+ gender: gender,
67
+ givenName: name === null || name === void 0 ? void 0 : name.givenName,
68
+ additionalName: name === null || name === void 0 ? void 0 : name.additionalName,
69
+ surname: name === null || name === void 0 ? void 0 : name.surname,
70
+ familyName: name === null || name === void 0 ? void 0 : name.familyName,
71
+ phone: phoneValue,
72
+ email: emailValue,
73
+ address: addressValue,
74
+ cozy: cozyValue,
75
+ cozyLabel: cozyLabel,
76
+ company: company,
77
+ jobTitle: jobTitle,
78
+ birthday: birthday,
79
+ birthplace: birthplace,
80
+ note: note,
81
+ relatedContact: relatedContactValue
82
+ };
83
+ }
84
+
85
+ return initialFieldValues;
86
+ };
87
+
88
+ export default contactToFormValues;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @type {import('../../../types').Field[]}
3
+ */
4
+ export const fields: any[];
@@ -0,0 +1,278 @@
1
+ import React from 'react';
2
+ import Icon from "cozy-ui/transpiled/react/Icon";
3
+ import BottomIcon from "cozy-ui/transpiled/react/Icons/Bottom";
4
+ import CalendarIcon from "cozy-ui/transpiled/react/Icons/Calendar";
5
+ import CloudIcon from "cozy-ui/transpiled/react/Icons/Cloud";
6
+ import CommentIcon from "cozy-ui/transpiled/react/Icons/Comment";
7
+ import CompanyIcon from "cozy-ui/transpiled/react/Icons/Company";
8
+ import EmailIcon from "cozy-ui/transpiled/react/Icons/Email";
9
+ import LocationIcon from "cozy-ui/transpiled/react/Icons/Location";
10
+ import PeopleIcon from "cozy-ui/transpiled/react/Icons/People";
11
+ import RelationshipIcon from "cozy-ui/transpiled/react/Icons/Relationship";
12
+ import TelephoneIcon from "cozy-ui/transpiled/react/Icons/Telephone";
13
+ import InputAdornment from "cozy-ui/transpiled/react/InputAdornment";
14
+ /**
15
+ * @type {import('../../../types').Field[]}
16
+ */
17
+
18
+ export var fields = [{
19
+ name: 'gender',
20
+ icon: PeopleIcon,
21
+ select: true,
22
+ options: [{
23
+ value: 'male',
24
+ label: 'Contacts.AddModal.ContactForm.gender.man'
25
+ }, {
26
+ value: 'female',
27
+ label: 'Contacts.AddModal.ContactForm.gender.woman'
28
+ }]
29
+ }, {
30
+ name: 'givenName',
31
+ icon: null,
32
+ type: 'text'
33
+ }, {
34
+ name: 'additionalName',
35
+ icon: null,
36
+ type: 'text'
37
+ }, {
38
+ name: 'familyName',
39
+ icon: null,
40
+ type: 'text'
41
+ }, {
42
+ name: 'surname',
43
+ icon: null,
44
+ type: 'text'
45
+ }, {
46
+ name: 'company',
47
+ icon: CompanyIcon,
48
+ type: 'text'
49
+ }, {
50
+ name: 'jobTitle',
51
+ icon: null,
52
+ type: 'text'
53
+ }, {
54
+ name: 'phone',
55
+ icon: TelephoneIcon,
56
+ type: 'tel',
57
+ label: {
58
+ name: 'phoneLabel',
59
+ select: true,
60
+ customLabelOptions: {
61
+ defaultType: '',
62
+ defaultLabel: 'home'
63
+ },
64
+ options: [{
65
+ value: '',
66
+ label: 'Contacts.AddModal.ContactForm.label.none'
67
+ }, {
68
+ value: '{"type":"cell","label":"home"}',
69
+ label: 'Contacts.AddModal.ContactForm.label.phone.cell-home'
70
+ }, {
71
+ value: '{"type":"cell","label":"work"}',
72
+ label: 'Contacts.AddModal.ContactForm.label.phone.cell-work'
73
+ }, {
74
+ value: '{"type":"voice","label":"home"}',
75
+ label: 'Contacts.AddModal.ContactForm.label.phone.voice-home'
76
+ }, {
77
+ value: '{"type":"voice","label":"work"}',
78
+ label: 'Contacts.AddModal.ContactForm.label.phone.voice-work'
79
+ }, {
80
+ value: '{"type":"fax","label":"home"}',
81
+ label: 'Contacts.AddModal.ContactForm.label.phone.fax-home'
82
+ }, {
83
+ value: '{"type":"fax","label":"work"}',
84
+ label: 'Contacts.AddModal.ContactForm.label.phone.fax-work'
85
+ }]
86
+ },
87
+ isArray: true
88
+ }, {
89
+ name: 'email',
90
+ icon: EmailIcon,
91
+ type: 'email',
92
+ label: {
93
+ name: 'emailLabel',
94
+ select: true,
95
+ customLabelOptions: {
96
+ defaultType: '',
97
+ defaultLabel: 'home'
98
+ },
99
+ options: [{
100
+ value: '',
101
+ label: 'Contacts.AddModal.ContactForm.label.none'
102
+ }, {
103
+ value: '{"label":"home"}',
104
+ label: 'Contacts.AddModal.ContactForm.label.home'
105
+ }, {
106
+ value: '{"label":"work"}',
107
+ label: 'Contacts.AddModal.ContactForm.label.work'
108
+ }]
109
+ },
110
+ isArray: true
111
+ }, {
112
+ name: 'address',
113
+ icon: LocationIcon,
114
+ type: 'text',
115
+ InputProps: {
116
+ readOnly: true
117
+ },
118
+ subFields: [{
119
+ name: 'street',
120
+ icon: null,
121
+ type: 'text'
122
+ }, {
123
+ name: 'number',
124
+ icon: null,
125
+ type: 'text'
126
+ }, {
127
+ name: 'building',
128
+ icon: null,
129
+ type: 'text'
130
+ }, {
131
+ name: 'stairs',
132
+ icon: null,
133
+ type: 'text'
134
+ }, {
135
+ name: 'floor',
136
+ icon: null,
137
+ type: 'text'
138
+ }, {
139
+ name: 'apartment',
140
+ icon: null,
141
+ type: 'text'
142
+ }, {
143
+ name: 'entrycode',
144
+ icon: null,
145
+ type: 'text'
146
+ }, {
147
+ name: 'locality',
148
+ icon: null,
149
+ type: 'text'
150
+ }, {
151
+ name: 'code',
152
+ icon: null,
153
+ type: 'text'
154
+ }, {
155
+ name: 'city',
156
+ icon: null,
157
+ type: 'text'
158
+ }, {
159
+ name: 'region',
160
+ icon: null,
161
+ type: 'text'
162
+ }, {
163
+ name: 'country',
164
+ icon: null,
165
+ type: 'text'
166
+ }],
167
+ label: {
168
+ name: 'addressLabel',
169
+ select: true,
170
+ customLabelOptions: {
171
+ defaultType: '',
172
+ defaultLabel: 'home'
173
+ },
174
+ options: [{
175
+ value: '',
176
+ label: 'Contacts.AddModal.ContactForm.label.none'
177
+ }, {
178
+ value: '{"label":"home"}',
179
+ label: 'Contacts.AddModal.ContactForm.label.address.home'
180
+ }, {
181
+ value: '{"label":"work"}',
182
+ label: 'Contacts.AddModal.ContactForm.label.address.work'
183
+ }]
184
+ },
185
+ isArray: true
186
+ }, {
187
+ name: 'cozy',
188
+ icon: CloudIcon,
189
+ type: 'url',
190
+ label: {
191
+ name: 'cozyLabel',
192
+ select: true,
193
+ customLabelOptions: {
194
+ defaultType: '',
195
+ defaultLabel: 'home'
196
+ },
197
+ options: [{
198
+ value: '',
199
+ label: 'Contacts.AddModal.ContactForm.label.none'
200
+ }, {
201
+ value: '{"label":"home"}',
202
+ label: 'Contacts.AddModal.ContactForm.label.home'
203
+ }, {
204
+ value: '{"label":"work"}',
205
+ label: 'Contacts.AddModal.ContactForm.label.work'
206
+ }]
207
+ }
208
+ }, {
209
+ name: 'birthday',
210
+ icon: CalendarIcon,
211
+ type: 'date',
212
+ InputLabelProps: {
213
+ shrink: true
214
+ }
215
+ }, {
216
+ name: 'birthplace',
217
+ icon: null,
218
+ type: 'text'
219
+ }, {
220
+ name: 'relatedContact',
221
+ icon: RelationshipIcon,
222
+ InputProps: {
223
+ readOnly: true,
224
+ endAdornment: /*#__PURE__*/React.createElement(InputAdornment, {
225
+ position: "end"
226
+ }, /*#__PURE__*/React.createElement(Icon, {
227
+ icon: BottomIcon,
228
+ color: "var(--iconTextColor)"
229
+ }))
230
+ },
231
+ label: {
232
+ name: 'relatedContactLabel',
233
+ select: true,
234
+ options: [{
235
+ value: '',
236
+ label: 'Contacts.AddModal.ContactForm.label.none'
237
+ }, {
238
+ value: '{"type":"parent"}',
239
+ label: 'Contacts.AddModal.ContactForm.label.relationship.parent'
240
+ }, {
241
+ value: '{"type":"child"}',
242
+ label: 'Contacts.AddModal.ContactForm.label.relationship.child'
243
+ }, {
244
+ value: '{"type":"sibling"}',
245
+ label: 'Contacts.AddModal.ContactForm.label.relationship.sibling'
246
+ }, {
247
+ value: '{"type":"spouse"}',
248
+ label: 'Contacts.AddModal.ContactForm.label.relationship.spouse'
249
+ }, {
250
+ value: '{"type":"coResident"}',
251
+ label: 'Contacts.AddModal.ContactForm.label.relationship.coResident'
252
+ }, {
253
+ value: '{"type":"friend"}',
254
+ label: 'Contacts.AddModal.ContactForm.label.relationship.friend'
255
+ }, {
256
+ value: '{"type":"colleague"}',
257
+ label: 'Contacts.AddModal.ContactForm.label.relationship.colleague'
258
+ }, {
259
+ value: '{"type":"coWorker"}',
260
+ label: 'Contacts.AddModal.ContactForm.label.relationship.coWorker'
261
+ }, {
262
+ value: '{"type":"acquaintance"}',
263
+ label: 'Contacts.AddModal.ContactForm.label.relationship.acquaintance'
264
+ }, {
265
+ value: '{"type":"helper"}',
266
+ label: 'Contacts.AddModal.ContactForm.label.relationship.helper'
267
+ }, {
268
+ value: '{"type":"recipient"}',
269
+ label: 'Contacts.AddModal.ContactForm.label.relationship.recipient'
270
+ }]
271
+ },
272
+ isArray: true
273
+ }, {
274
+ name: 'note',
275
+ icon: CommentIcon,
276
+ type: 'text',
277
+ multiline: true
278
+ }];
@@ -0,0 +1,6 @@
1
+ export default formValuesToContact;
2
+ declare function formValuesToContact({ formValues, oldContact, t }: {
3
+ formValues: any;
4
+ oldContact: any;
5
+ t: any;
6
+ }): any;
@@ -0,0 +1,94 @@
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 { updateIndexFullNameAndDisplayName } from 'cozy-client/dist/models/contact';
8
+ import { removeAsscociatedData, removeRelatedContactRelationships, createAddress, getRelatedContactRelationships, makeTypeAndLabel } from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/helpers";
9
+
10
+ var formValuesToContact = function formValuesToContact(_ref) {
11
+ var formValues = _ref.formValues,
12
+ oldContact = _ref.oldContact,
13
+ t = _ref.t;
14
+ var gender = formValues.gender,
15
+ givenName = formValues.givenName,
16
+ additionalName = formValues.additionalName,
17
+ surname = formValues.surname,
18
+ familyName = formValues.familyName,
19
+ phone = formValues.phone,
20
+ email = formValues.email,
21
+ address = formValues.address,
22
+ cozy = formValues.cozy,
23
+ company = formValues.company,
24
+ jobTitle = formValues.jobTitle,
25
+ birthday = formValues.birthday,
26
+ birthplace = formValues.birthplace,
27
+ note = formValues.note,
28
+ relatedContact = formValues.relatedContact;
29
+ var relatedContactRelationships = getRelatedContactRelationships(relatedContact);
30
+ var oldContactCleaned = removeRelatedContactRelationships(removeAsscociatedData(oldContact));
31
+
32
+ var relationshipsFormValues = _objectSpread(_objectSpread(_objectSpread({}, oldContactCleaned === null || oldContactCleaned === void 0 ? void 0 : oldContactCleaned.relationships), relatedContactRelationships), {}, {
33
+ // If we don't create the relationships field manually, cozy-client doesn't create it automatically when needed (eg. b56ea9dd308c31555aa1433514fa3481adb92f31)
34
+ groups: {
35
+ data: []
36
+ }
37
+ });
38
+
39
+ var contactWithFormValues = _objectSpread(_objectSpread({}, oldContactCleaned), {}, {
40
+ gender: gender || '',
41
+ name: _objectSpread(_objectSpread({}, oldContactCleaned === null || oldContactCleaned === void 0 ? void 0 : oldContactCleaned.name), {}, {
42
+ givenName: givenName || '',
43
+ additionalName: additionalName,
44
+ surname: surname,
45
+ familyName: familyName || ''
46
+ }),
47
+ email: email ? email.filter(function (val) {
48
+ return val && val.email;
49
+ }).map(function (_ref2, index) {
50
+ var email = _ref2.email,
51
+ emailLabel = _ref2.emailLabel;
52
+ return _objectSpread(_objectSpread({
53
+ address: email
54
+ }, makeTypeAndLabel(emailLabel)), {}, {
55
+ primary: index === 0
56
+ });
57
+ }) : [],
58
+ address: createAddress({
59
+ address: address,
60
+ oldContact: oldContactCleaned,
61
+ t: t
62
+ }),
63
+ phone: phone ? phone.filter(function (val) {
64
+ return val && val.phone;
65
+ }).map(function (_ref3, index) {
66
+ var phone = _ref3.phone,
67
+ phoneLabel = _ref3.phoneLabel;
68
+ return _objectSpread(_objectSpread({
69
+ number: phone
70
+ }, makeTypeAndLabel(phoneLabel)), {}, {
71
+ primary: index === 0
72
+ });
73
+ }) : [],
74
+ cozy: cozy ? [_objectSpread(_objectSpread({
75
+ url: cozy
76
+ }, makeTypeAndLabel(formValues['cozyLabel'])), {}, {
77
+ primary: true
78
+ })] : [],
79
+ company: company || '',
80
+ jobTitle: jobTitle || '',
81
+ birthday: birthday || '',
82
+ birthplace: birthplace || '',
83
+ note: note || '',
84
+ relationships: relationshipsFormValues,
85
+ metadata: _objectSpread(_objectSpread({}, oldContactCleaned === null || oldContactCleaned === void 0 ? void 0 : oldContactCleaned.metadata), {}, {
86
+ version: 1,
87
+ cozy: true
88
+ })
89
+ });
90
+
91
+ return updateIndexFullNameAndDisplayName(contactWithFormValues);
92
+ };
93
+
94
+ export default formValuesToContact;
@@ -0,0 +1,28 @@
1
+ export const fieldsRequired: string[];
2
+ export function validateFields(values: object, t: func): object;
3
+ export function makeItemLabel(item?: object | undefined): string;
4
+ export function makeTypeAndLabel(itemLabel?: string | undefined): {
5
+ type?: string;
6
+ label?: string;
7
+ };
8
+ export function hasExtendedAddress(addressField: object): boolean;
9
+ export function moveToHead(shouldBeHead: any): (items: any) => any;
10
+ export function movePrimaryToHead(items: any): any;
11
+ export function createAddress({ address, oldContact, t }: {
12
+ address: any;
13
+ oldContact: any;
14
+ t: any;
15
+ }): any;
16
+ export function getRelatedContactRelationships(relatedContact: (any | undefined)[]): Record<string, {
17
+ data: {
18
+ _id: string;
19
+ _type: string;
20
+ }[];
21
+ }>;
22
+ export function removeRelatedContactRelationships(contact: import('cozy-client/types/types').IOCozyContact): import('cozy-client/types/types').IOCozyContact;
23
+ export function removeAsscociatedData(contact: import('cozy-client/types/types').IOCozyContact): import('cozy-client/types/types').IOCozyContact;
24
+ export function makeRelatedContact(contact: import('cozy-client/types/types').IOCozyContact): any[];
25
+ export function addField(fields: any): any;
26
+ export function removeField(fields: any, index: any): void;
27
+ export function makeCustomLabel(value: string, t: func): string;
28
+ export function makeInitialCustomValue(name: string, value: string): string;