cozy-ui 128.8.0 → 128.10.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 (46) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/assets/icons/ui/matrix.svg +1 -0
  3. package/package.json +1 -1
  4. package/react/Contacts/AddModal/ContactForm/FieldInput.jsx +3 -0
  5. package/react/Contacts/AddModal/ContactForm/FieldInputAccordion.jsx +57 -0
  6. package/react/Contacts/AddModal/ContactForm/FieldInputArray.jsx +1 -1
  7. package/react/Contacts/AddModal/ContactForm/FieldInputLayout.jsx +14 -4
  8. package/react/Contacts/AddModal/ContactForm/contactToFormValues.js +9 -2
  9. package/react/Contacts/AddModal/ContactForm/contactToFormValues.spec.js +5 -0
  10. package/react/Contacts/AddModal/ContactForm/fieldsConfig.jsx +48 -32
  11. package/react/Contacts/AddModal/ContactForm/formValuesToContact.js +3 -0
  12. package/react/Contacts/AddModal/ContactForm/formValuesToContact.spec.js +57 -0
  13. package/react/Contacts/AddModal/ContactForm/helpers.js +41 -0
  14. package/react/Contacts/AddModal/ContactForm/helpers.spec.js +138 -0
  15. package/react/Contacts/AddModal/ContactForm/index.jsx +14 -1
  16. package/react/Contacts/AddModal/ContactForm/index.spec.jsx +12 -0
  17. package/react/Contacts/AddModal/ContactForm/locales/en.json +2 -0
  18. package/react/Contacts/AddModal/ContactForm/locales/fr.json +2 -0
  19. package/react/Contacts/AddModal/Readme.md +1 -1
  20. package/react/Contacts/AddModal/mocks.js +40 -1
  21. package/react/Contacts/AddModal/types.js +1 -1
  22. package/react/Icon/Readme.md +3 -1
  23. package/react/Icons/Matrix.jsx +12 -0
  24. package/transpiled/react/Contacts/AddModal/ContactAddressDialog/index.d.ts +1 -1
  25. package/transpiled/react/Contacts/AddModal/ContactForm/FieldInput.d.ts +3 -1
  26. package/transpiled/react/Contacts/AddModal/ContactForm/FieldInput.js +3 -1
  27. package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputAccordion.d.ts +12 -0
  28. package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputAccordion.js +71 -0
  29. package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputArray.js +1 -1
  30. package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputLayout.d.ts +4 -2
  31. package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputLayout.js +14 -5
  32. package/transpiled/react/Contacts/AddModal/ContactForm/contactToFormValues.js +9 -2
  33. package/transpiled/react/Contacts/AddModal/ContactForm/fieldsConfig.js +41 -28
  34. package/transpiled/react/Contacts/AddModal/ContactForm/formValuesToContact.js +3 -1
  35. package/transpiled/react/Contacts/AddModal/ContactForm/helpers.d.ts +6 -0
  36. package/transpiled/react/Contacts/AddModal/ContactForm/helpers.js +39 -0
  37. package/transpiled/react/Contacts/AddModal/ContactForm/index.js +18 -2
  38. package/transpiled/react/Contacts/AddModal/ContactForm/locales/index.js +4 -0
  39. package/transpiled/react/Contacts/AddModal/mocks.d.ts +19 -0
  40. package/transpiled/react/Contacts/AddModal/mocks.js +32 -0
  41. package/transpiled/react/Contacts/AddModal/types.d.ts +1 -1
  42. package/transpiled/react/Contacts/AddModal/types.js +1 -1
  43. package/transpiled/react/Icon/icons-sprite.d.ts +1 -1
  44. package/transpiled/react/Icon/icons-sprite.js +1 -1
  45. package/transpiled/react/Icons/Matrix.d.ts +2 -0
  46. package/transpiled/react/Icons/Matrix.js +13 -0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
1
+ # [128.10.0](https://github.com/cozy/cozy-ui/compare/v128.9.0...v128.10.0) (2025-09-16)
2
+
3
+
4
+ ### Features
5
+
6
+ * **Contacts/AddModal:** Add matrix ID input ([db8f522](https://github.com/cozy/cozy-ui/commit/db8f522))
7
+ * **Icons:** Add matrix ([4838a1f](https://github.com/cozy/cozy-ui/commit/4838a1f))
8
+
9
+ # [128.9.0](https://github.com/cozy/cozy-ui/compare/v128.8.0...v128.9.0) (2025-09-16)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * **ContactForm:** Remove button position wasn't correct on mobile ([d96647f](https://github.com/cozy/cozy-ui/commit/d96647f))
15
+
16
+
17
+ ### Features
18
+
19
+ * **ContactForm/FieldInput:** Add className prop ([38d48f5](https://github.com/cozy/cozy-ui/commit/38d48f5))
20
+ * **ContactForm:** Add `isSecondary` attribute ([ff1bf5f](https://github.com/cozy/cozy-ui/commit/ff1bf5f))
21
+ * **ContactForm:** Add FieldInputAccordion component ([f285990](https://github.com/cozy/cozy-ui/commit/f285990))
22
+
1
23
  # [128.8.0](https://github.com/cozy/cozy-ui/compare/v128.7.0...v128.8.0) (2025-09-09)
2
24
 
3
25
 
@@ -0,0 +1 @@
1
+ <svg width="16" height="10" viewBox="0 0 16 10" xmlns="http://www.w3.org/2000/svg"><path d="M3 1.111H1.333V8.89H3V10H0V0h3v1.111ZM16 10h-3V8.889h1.667V1.11H13V0h3v10ZM9.807 3.667c.587 0 1.043.167 1.368.503.328.332.492.79.492 1.374V9h-1.23V5.72c0-.688-.311-1.032-.931-1.032a.983.983 0 0 0-.531.162.945.945 0 0 0-.36.372V9h-1.23V5.53c0-.258-.08-.462-.241-.612-.161-.153-.387-.23-.68-.23-.153 0-.323.057-.507.171-.18.114-.312.24-.394.377V9h-1.23V3.765h.847l.25.459c.342-.372.784-.557 1.325-.557.699 0 1.226.188 1.58.566.154-.172.369-.309.644-.41.276-.104.552-.156.828-.156Z"/></svg>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "128.8.0",
3
+ "version": "128.10.0",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -16,6 +16,7 @@ import { fieldInputAttributesTypes, labelPropTypes } from '../types'
16
16
  const FieldInput = ({
17
17
  name,
18
18
  labelProps,
19
+ className,
19
20
  attributes: { subFields, ...restAttributes },
20
21
  contacts,
21
22
  error,
@@ -48,6 +49,7 @@ const FieldInput = ({
48
49
  return (
49
50
  <div
50
51
  className={cx(
52
+ className,
51
53
  styles['contact-form-field__wrapper'],
52
54
  'u-flex',
53
55
  'u-flex-column-s'
@@ -98,6 +100,7 @@ const FieldInput = ({
98
100
 
99
101
  FieldInput.propTypes = {
100
102
  name: PropTypes.string.isRequired,
103
+ className: PropTypes.string,
101
104
  labelProps: labelPropTypes,
102
105
  attributes: fieldInputAttributesTypes,
103
106
  contacts: PropTypes.shape({
@@ -0,0 +1,57 @@
1
+ import cx from 'classnames'
2
+ import React, { useState } from 'react'
3
+
4
+ import FieldInput from './FieldInput'
5
+ import { locales } from './locales'
6
+ import Icon from '../../../Icon'
7
+ import IconButton from '../../../IconButton'
8
+ import DropdownIcon from '../../../Icons/Dropdown'
9
+ import DropupIcon from '../../../Icons/Dropup'
10
+ import { useI18n, useExtendI18n } from '../../../providers/I18n'
11
+
12
+ const FieldInputAccordion = ({
13
+ attributes: { name, label, subFields, ...restAttributes },
14
+ contacts,
15
+ error,
16
+ helperText
17
+ }) => {
18
+ useExtendI18n(locales)
19
+ const { t } = useI18n()
20
+ const [showExtended, setShowExtended] = useState(false)
21
+
22
+ return (
23
+ <>
24
+ <div className="u-flex u-flex-items-baseline">
25
+ <FieldInput
26
+ attributes={restAttributes}
27
+ contacts={contacts}
28
+ error={error}
29
+ helperText={helperText}
30
+ name={name}
31
+ label={t(`Contacts.AddModal.ContactForm.fields.${name}`)}
32
+ labelProps={label}
33
+ />
34
+ <IconButton
35
+ className="u-ml-half"
36
+ size="medium"
37
+ onClick={() => setShowExtended(v => !v)}
38
+ >
39
+ <Icon icon={showExtended ? DropupIcon : DropdownIcon} />
40
+ </IconButton>
41
+ </div>
42
+ {subFields.map(({ name, ...attributes }, index) => {
43
+ return (
44
+ <FieldInput
45
+ key={index}
46
+ className={cx('u-mt-1', { 'u-dn': !showExtended })}
47
+ attributes={attributes}
48
+ name={name}
49
+ label={t(`Contacts.AddModal.ContactForm.fields.${name}`)}
50
+ />
51
+ )
52
+ })}
53
+ </>
54
+ )
55
+ }
56
+
57
+ export default FieldInputAccordion
@@ -36,7 +36,7 @@ const FieldInputArray = ({
36
36
  return (
37
37
  <div
38
38
  key={key}
39
- className={cx('u-flex u-flex-items-center', {
39
+ className={cx('u-flex u-flex-items-baseline', {
40
40
  'u-mt-1': index !== 0
41
41
  })}
42
42
  >
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
3
3
  import React from 'react'
4
4
 
5
5
  import FieldInput from './FieldInput'
6
+ import FieldInputAccordion from './FieldInputAccordion'
6
7
  import FieldInputArray from './FieldInputArray'
7
8
  import { fieldsRequired } from './helpers'
8
9
  import { locales } from './locales'
@@ -10,8 +11,9 @@ import Icon from '../../../Icon'
10
11
  import { useI18n, useExtendI18n } from '../../../providers/I18n'
11
12
 
12
13
  const FieldInputLayout = ({
13
- attributes: { isArray, icon, ...attributes }, // ⚠️ isArray and icon here are removed from attributes to avoid DOM propagration
14
+ attributes: { layout, icon, isSecondary, ...attributes }, // ⚠️ `layout` `icon` `isSecondary` here are removed from attributes to avoid DOM propagration
14
15
  contacts,
16
+ showSecondaryFields,
15
17
  formProps
16
18
  }) => {
17
19
  useExtendI18n(locales)
@@ -24,20 +26,28 @@ const FieldInputLayout = ({
24
26
  return (
25
27
  <div
26
28
  className={cx('u-flex u-mt-1', {
27
- 'u-flex-items-center': !isArray,
28
- 'u-flex-items-baseline': isArray
29
+ 'u-flex-items-center': !layout,
30
+ 'u-flex-items-baseline': !!layout,
31
+ 'u-dn': isSecondary && !showSecondaryFields
29
32
  })}
30
33
  >
31
34
  <div className="u-w-2-half">
32
35
  {icon && <Icon icon={icon} color="var(--iconTextColor)" />}
33
36
  </div>
34
37
  <div className="u-w-100">
35
- {isArray ? (
38
+ {layout === 'array' ? (
36
39
  <FieldInputArray
37
40
  attributes={attributes}
38
41
  contacts={contacts}
39
42
  formProps={formProps}
40
43
  />
44
+ ) : layout === 'accordion' ? (
45
+ <FieldInputAccordion
46
+ attributes={attributes}
47
+ contacts={contacts}
48
+ error={isError}
49
+ helperText={isError ? errors[name] : null}
50
+ />
41
51
  ) : (
42
52
  <FieldInput
43
53
  attributes={restAttributes}
@@ -8,8 +8,8 @@ import { makeItemLabel, makeRelatedContact, movePrimaryToHead } from './helpers'
8
8
  const contactToFormValues = (contact, t) => {
9
9
  // initialize the form values, required so that array fields start with at least one editable field
10
10
  const initialFieldValues = fields.reduce(
11
- (initialValues, { name, isArray }) => {
12
- initialValues[name] = isArray ? [undefined] : undefined
11
+ (initialValues, { name, layout }) => {
12
+ initialValues[name] = layout === 'array' ? [undefined] : undefined
13
13
  return initialValues
14
14
  },
15
15
  {}
@@ -25,6 +25,7 @@ const contactToFormValues = (contact, t) => {
25
25
  jobTitle,
26
26
  cozy,
27
27
  email,
28
+ impp,
28
29
  name,
29
30
  note,
30
31
  phone
@@ -62,6 +63,11 @@ const contactToFormValues = (contact, t) => {
62
63
  emailLabel: makeItemLabel(item)
63
64
  }))
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
65
71
  const phoneValue =
66
72
  phone && phone.length > 0
67
73
  ? movePrimaryToHead(phone).map(item => ({
@@ -81,6 +87,7 @@ const contactToFormValues = (contact, t) => {
81
87
  familyName: name?.familyName,
82
88
  phone: phoneValue,
83
89
  email: emailValue,
90
+ matrix: matrixValue,
84
91
  address: addressValue,
85
92
  cozy: cozyValue,
86
93
  cozyLabel: cozyLabel,
@@ -16,6 +16,7 @@ describe('contactToFormValues function', () => {
16
16
  cozy: undefined,
17
17
  cozyLabel: undefined,
18
18
  email: [undefined],
19
+ matrix: undefined,
19
20
  familyName: undefined,
20
21
  givenName: undefined,
21
22
  note: undefined,
@@ -59,6 +60,7 @@ describe('contactToFormValues function', () => {
59
60
  jobTitle: undefined,
60
61
  cozy: undefined,
61
62
  email: undefined,
63
+ impp: undefined,
62
64
  name: {
63
65
  givenName: 'Jane',
64
66
  familyName: 'Doe'
@@ -76,6 +78,7 @@ describe('contactToFormValues function', () => {
76
78
  cozy: undefined,
77
79
  cozyLabel: undefined,
78
80
  email: [undefined],
81
+ matrix: undefined,
79
82
  givenName: 'Jane',
80
83
  familyName: 'Doe',
81
84
  note: undefined,
@@ -101,6 +104,7 @@ describe('contactToFormValues function', () => {
101
104
  jobTitle: undefined,
102
105
  cozy: undefined,
103
106
  email: undefined,
107
+ impp: undefined,
104
108
  name: undefined,
105
109
  note: 'Eligendi velit eos ab libero molestiae consequatur autem sed.',
106
110
  phone: []
@@ -115,6 +119,7 @@ describe('contactToFormValues function', () => {
115
119
  cozy: undefined,
116
120
  cozyLabel: undefined,
117
121
  email: [undefined],
122
+ matrix: undefined,
118
123
  givenName: undefined,
119
124
  familyName: undefined,
120
125
  note: 'Eligendi velit eos ab libero molestiae consequatur autem sed.',
@@ -8,6 +8,7 @@ import CommentIcon from '../../../Icons/Comment'
8
8
  import CompanyIcon from '../../../Icons/Company'
9
9
  import EmailIcon from '../../../Icons/Email'
10
10
  import LocationIcon from '../../../Icons/Location'
11
+ import MatrixIcon from '../../../Icons/Matrix'
11
12
  import PeopleIcon from '../../../Icons/People'
12
13
  import RelationshipIcon from '../../../Icons/Relationship'
13
14
  import TelephoneIcon from '../../../Icons/Telephone'
@@ -35,37 +36,44 @@ export const fields = [
35
36
  {
36
37
  name: 'givenName',
37
38
  icon: null,
38
- type: 'text'
39
- },
40
- {
41
- name: 'additionalName',
42
- icon: null,
43
- type: 'text'
39
+ type: 'text',
40
+ layout: 'accordion',
41
+ subFields: [
42
+ {
43
+ name: 'additionalName',
44
+ icon: null,
45
+ type: 'text'
46
+ },
47
+ {
48
+ name: 'surname',
49
+ icon: null,
50
+ type: 'text'
51
+ }
52
+ ]
44
53
  },
45
54
  {
46
55
  name: 'familyName',
47
56
  icon: null,
48
57
  type: 'text'
49
58
  },
50
- {
51
- name: 'surname',
52
- icon: null,
53
- type: 'text'
54
- },
55
59
  {
56
60
  name: 'company',
57
61
  icon: CompanyIcon,
58
- type: 'text'
59
- },
60
- {
61
- name: 'jobTitle',
62
- icon: null,
63
- type: 'text'
62
+ type: 'text',
63
+ layout: 'accordion',
64
+ subFields: [
65
+ {
66
+ name: 'jobTitle',
67
+ icon: null,
68
+ type: 'text'
69
+ }
70
+ ]
64
71
  },
65
72
  {
66
73
  name: 'phone',
67
74
  icon: TelephoneIcon,
68
75
  type: 'tel',
76
+ layout: 'array',
69
77
  label: {
70
78
  name: 'phoneLabel',
71
79
  select: true,
@@ -103,13 +111,13 @@ export const fields = [
103
111
  label: 'Contacts.AddModal.ContactForm.label.phone.fax-work'
104
112
  }
105
113
  ]
106
- },
107
- isArray: true
114
+ }
108
115
  },
109
116
  {
110
117
  name: 'email',
111
118
  icon: EmailIcon,
112
119
  type: 'email',
120
+ layout: 'array',
113
121
  label: {
114
122
  name: 'emailLabel',
115
123
  select: true,
@@ -131,13 +139,18 @@ export const fields = [
131
139
  label: 'Contacts.AddModal.ContactForm.label.work'
132
140
  }
133
141
  ]
134
- },
135
- isArray: true
142
+ }
143
+ },
144
+ {
145
+ name: 'matrix',
146
+ icon: MatrixIcon,
147
+ type: 'text'
136
148
  },
137
149
  {
138
150
  name: 'address',
139
151
  icon: LocationIcon,
140
152
  type: 'text',
153
+ layout: 'array',
141
154
  InputProps: {
142
155
  readOnly: true
143
156
  },
@@ -224,13 +237,19 @@ export const fields = [
224
237
  label: 'Contacts.AddModal.ContactForm.label.address.work'
225
238
  }
226
239
  ]
227
- },
228
- isArray: true
240
+ }
241
+ },
242
+ {
243
+ name: 'note',
244
+ icon: CommentIcon,
245
+ type: 'text',
246
+ multiline: true
229
247
  },
230
248
  {
231
249
  name: 'cozy',
232
250
  icon: CloudIcon,
233
251
  type: 'url',
252
+ isSecondary: true,
234
253
  label: {
235
254
  name: 'cozyLabel',
236
255
  select: true,
@@ -258,16 +277,20 @@ export const fields = [
258
277
  name: 'birthday',
259
278
  icon: CalendarIcon,
260
279
  type: 'date',
280
+ isSecondary: true,
261
281
  InputLabelProps: { shrink: true }
262
282
  },
263
283
  {
264
284
  name: 'birthplace',
265
285
  icon: null,
266
- type: 'text'
286
+ type: 'text',
287
+ isSecondary: true
267
288
  },
268
289
  {
269
290
  name: 'relatedContact',
270
291
  icon: RelationshipIcon,
292
+ layout: 'array',
293
+ isSecondary: true,
271
294
  InputProps: {
272
295
  readOnly: true,
273
296
  endAdornment: (
@@ -329,13 +352,6 @@ export const fields = [
329
352
  label: 'Contacts.AddModal.ContactForm.label.relationship.recipient'
330
353
  }
331
354
  ]
332
- },
333
- isArray: true
334
- },
335
- {
336
- name: 'note',
337
- icon: CommentIcon,
338
- type: 'text',
339
- multiline: true
355
+ }
340
356
  }
341
357
  ]
@@ -5,6 +5,7 @@ import {
5
5
  removeRelatedContactRelationships,
6
6
  createAddress,
7
7
  getRelatedContactRelationships,
8
+ makeImppValues,
8
9
  makeTypeAndLabel
9
10
  } from './helpers'
10
11
 
@@ -18,6 +19,7 @@ const formValuesToContact = ({ formValues, oldContact, t }) => {
18
19
  phone,
19
20
  email,
20
21
  address,
22
+ matrix,
21
23
  cozy,
22
24
  company,
23
25
  jobTitle,
@@ -62,6 +64,7 @@ const formValuesToContact = ({ formValues, oldContact, t }) => {
62
64
  primary: index === 0
63
65
  }))
64
66
  : [],
67
+ impp: makeImppValues(oldContactCleaned, matrix),
65
68
  address: createAddress({ address, oldContact: oldContactCleaned, t }),
66
69
  phone: phone
67
70
  ? phone
@@ -83,6 +83,14 @@ describe('formValuesToContact', () => {
83
83
  label: undefined
84
84
  }
85
85
  ],
86
+ impp: [
87
+ {
88
+ uri: 'john@doe.matrix.net',
89
+ protocol: 'matrix',
90
+ label: 'work',
91
+ primary: true
92
+ }
93
+ ],
86
94
  fullname: 'John J. Doe',
87
95
  indexes: {
88
96
  byFamilyNameGivenNameEmailCozyUrl:
@@ -160,6 +168,7 @@ describe('formValuesToContact', () => {
160
168
  emailLabel: undefined
161
169
  }
162
170
  ],
171
+ matrix: 'john@doe.matrix.net',
163
172
  familyName: 'Doe',
164
173
  givenName: 'Jane',
165
174
  note: undefined,
@@ -182,6 +191,14 @@ describe('formValuesToContact', () => {
182
191
  cozy: [],
183
192
  displayName: 'Jane Doe',
184
193
  email: [],
194
+ impp: [
195
+ {
196
+ uri: 'john@doe.matrix.net',
197
+ protocol: 'matrix',
198
+ label: 'work',
199
+ primary: true
200
+ }
201
+ ],
185
202
  fullname: 'Jane Doe',
186
203
  indexes: { byFamilyNameGivenNameEmailCozyUrl: 'doejane' },
187
204
  jobTitle: '',
@@ -294,6 +311,7 @@ describe('formValuesToContact', () => {
294
311
  birthplace: undefined,
295
312
  note: undefined,
296
313
  address: [undefined],
314
+ matrix: undefined,
297
315
  email: [undefined],
298
316
  phone: [undefined],
299
317
  cozy: undefined,
@@ -307,6 +325,25 @@ describe('formValuesToContact', () => {
307
325
  jobTitle: '',
308
326
  address: [],
309
327
  email: [],
328
+ impp: [
329
+ {
330
+ uri: 'john.doe@xmpp.net',
331
+ protocol: 'xmpp',
332
+ label: 'home',
333
+ primary: false
334
+ },
335
+ {
336
+ uri: 'john.doe@xmpp.net',
337
+ protocol: 'xmpp',
338
+ label: 'work',
339
+ primary: false
340
+ },
341
+ {
342
+ uri: 'john@doe.matrix.home',
343
+ protocol: 'matrix',
344
+ label: 'home'
345
+ }
346
+ ],
310
347
  cozy: [],
311
348
  phone: [],
312
349
  birthday: '',
@@ -335,6 +372,7 @@ describe('formValuesToContact', () => {
335
372
  birthplace: '',
336
373
  note: '',
337
374
  address: [{}],
375
+ matrix: '',
338
376
  email: [{}],
339
377
  phone: [{}],
340
378
  cozy: '',
@@ -348,6 +386,25 @@ describe('formValuesToContact', () => {
348
386
  jobTitle: '',
349
387
  address: [],
350
388
  email: [],
389
+ impp: [
390
+ {
391
+ uri: 'john.doe@xmpp.net',
392
+ protocol: 'xmpp',
393
+ label: 'home',
394
+ primary: false
395
+ },
396
+ {
397
+ uri: 'john.doe@xmpp.net',
398
+ protocol: 'xmpp',
399
+ label: 'work',
400
+ primary: false
401
+ },
402
+ {
403
+ uri: 'john@doe.matrix.home',
404
+ protocol: 'matrix',
405
+ label: 'home'
406
+ }
407
+ ],
351
408
  cozy: [],
352
409
  phone: [],
353
410
  birthday: '',
@@ -281,6 +281,47 @@ export const makeCustomLabel = (value, t) => {
281
281
  return firstString + secondString || null
282
282
  }
283
283
 
284
+ /**
285
+ *
286
+ * @param {import('cozy-client/types/types').IOCozyContact} oldContact - Contact to be modified
287
+ * @param {string?} value - New URI value to add to the Contact
288
+ * @returns {{ uri: string, protocol: string, label: string, primary?: boolean }[]}
289
+ */
290
+ export const makeImppValues = (oldContact, value) => {
291
+ const _value = value?.trim() || ''
292
+ const oldImppValues = oldContact?.impp
293
+
294
+ if (_value) {
295
+ if (!oldImppValues || oldImppValues.length === 0) {
296
+ return [
297
+ {
298
+ uri: _value,
299
+ protocol: 'matrix',
300
+ label: 'work',
301
+ primary: true
302
+ }
303
+ ]
304
+ }
305
+
306
+ return oldImppValues.map(el => {
307
+ if (el.protocol === 'matrix' && el.label === 'work') {
308
+ return { ...el, uri: _value }
309
+ }
310
+ return el
311
+ })
312
+ }
313
+
314
+ return (
315
+ oldImppValues
316
+ ?.map(el => {
317
+ if (el.protocol !== 'matrix' || el.label !== 'work') {
318
+ return el
319
+ }
320
+ })
321
+ .filter(Boolean) || []
322
+ )
323
+ }
324
+
284
325
  /**
285
326
  *
286
327
  * @param {string} name