cozy-ui 130.7.2 → 130.8.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 (32) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/package.json +1 -1
  3. package/react/Avatar/Readme.md +1 -0
  4. package/react/Avatar/index.jsx +9 -1
  5. package/react/Contacts/AddModal/ContactForm/FieldInputWrapper.jsx +9 -7
  6. package/react/Contacts/AddModal/ContactForm/contactToFormValues.js +4 -1
  7. package/react/Contacts/AddModal/ContactForm/contactToFormValues.spec.js +4 -4
  8. package/react/Contacts/AddModal/ContactForm/fieldsConfig.jsx +1 -1
  9. package/react/Contacts/AddModal/ContactForm/formValuesToContact.js +9 -1
  10. package/react/Contacts/AddModal/ContactForm/helpers.js +27 -4
  11. package/react/Contacts/AddModal/ContactForm/helpers.spec.js +66 -0
  12. package/react/Contacts/AddModal/ContactForm/index.jsx +29 -8
  13. package/react/Contacts/AddModal/Readme.md +13 -4
  14. package/react/Contacts/AddModal/index.jsx +8 -1
  15. package/react/Contacts/AddModal/types.js +45 -0
  16. package/transpiled/react/Avatar/index.js +30 -17
  17. package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputWrapper.d.ts +5 -2
  18. package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputWrapper.js +8 -5
  19. package/transpiled/react/Contacts/AddModal/ContactForm/contactToFormValues.d.ts +5 -1
  20. package/transpiled/react/Contacts/AddModal/ContactForm/contactToFormValues.js +16 -6
  21. package/transpiled/react/Contacts/AddModal/ContactForm/fieldsConfig.d.ts +2 -2
  22. package/transpiled/react/Contacts/AddModal/ContactForm/fieldsConfig.js +1 -1
  23. package/transpiled/react/Contacts/AddModal/ContactForm/formValuesToContact.d.ts +2 -1
  24. package/transpiled/react/Contacts/AddModal/ContactForm/formValuesToContact.js +4 -1
  25. package/transpiled/react/Contacts/AddModal/ContactForm/helpers.d.ts +3 -2
  26. package/transpiled/react/Contacts/AddModal/ContactForm/helpers.js +26 -3
  27. package/transpiled/react/Contacts/AddModal/ContactForm/index.d.ts +12 -6
  28. package/transpiled/react/Contacts/AddModal/ContactForm/index.js +30 -10
  29. package/transpiled/react/Contacts/AddModal/index.d.ts +2 -1
  30. package/transpiled/react/Contacts/AddModal/index.js +2 -0
  31. package/transpiled/react/Contacts/AddModal/types.d.ts +134 -0
  32. package/transpiled/react/Contacts/AddModal/types.js +45 -0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ ## [130.8.1](https://github.com/cozy/cozy-ui/compare/v130.8.0...v130.8.1) (2025-10-15)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **Avatar:** Now passing a `number` to `size` prop works correctly ([c8e79f2](https://github.com/cozy/cozy-ui/commit/c8e79f2))
7
+
8
+ # [130.8.0](https://github.com/cozy/cozy-ui/compare/v130.7.2...v130.8.0) (2025-10-14)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **AddModal/ContactForm:** Now hide "other fields" button if no secondary field ([bbba734](https://github.com/cozy/cozy-ui/commit/bbba734))
14
+
15
+
16
+ ### Features
17
+
18
+ * **AddModal/ContactForm:** Add `customFieldsProps` prop ([b7d0e60](https://github.com/cozy/cozy-ui/commit/b7d0e60))
19
+ * **AddModal/ContactForm:** Add makeFields func ([f1e453b](https://github.com/cozy/cozy-ui/commit/f1e453b))
20
+ * **AddModal/ContactForm:** Add possiblity to customize fields component ([f600cdd](https://github.com/cozy/cozy-ui/commit/f600cdd))
21
+
1
22
  ## [130.7.2](https://github.com/cozy/cozy-ui/compare/v130.7.1...v130.7.2) (2025-10-10)
2
23
 
3
24
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "130.7.2",
3
+ "version": "130.8.1",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -85,6 +85,7 @@ const initialVariants = [{ disabled: false, border: false, innerBorder: false }]
85
85
  <Avatar disabled={variant.disabled} border={variant.border} innerBorder={variant.innerBorder}>AB</Avatar>
86
86
  <Avatar color="none" disabled={variant.disabled} border={variant.border} innerBorder={variant.innerBorder}>BC</Avatar>
87
87
  <Avatar color="sunrise" disabled={variant.disabled} border={variant.border} innerBorder={variant.innerBorder}>CD</Avatar>
88
+ <Avatar color="sunrise" size={94} disabled={variant.disabled} border={variant.border} innerBorder={variant.innerBorder}>DE</Avatar>
88
89
  </div>
89
90
  </>
90
91
  )}
@@ -8,6 +8,11 @@ import { makeStyles } from '../styles'
8
8
  import { capitalize } from '../utils/index'
9
9
 
10
10
  const useStyles = makeStyles(theme => ({
11
+ root: {
12
+ width: ({ size }) => size,
13
+ height: ({ size }) => size,
14
+ fontSize: ({ size }) => size / 2
15
+ },
11
16
  colorDefault: {
12
17
  color: ({ color }) => (color ? theme.palette.primary.contrastText : ''),
13
18
  background: ({ color }) => colorMapping[color]
@@ -24,9 +29,11 @@ const Avatar = ({
24
29
  display,
25
30
  ...props
26
31
  }) => {
32
+ const isCustomSize = typeof size === 'number'
27
33
  const defaultColor =
28
34
  typeof props.children === 'string' ? nameToColor(props.children) : undefined
29
35
  const classes = useStyles({
36
+ size: isCustomSize ? size : undefined,
30
37
  color:
31
38
  color === 'none'
32
39
  ? undefined
@@ -38,7 +45,8 @@ const Avatar = ({
38
45
  return (
39
46
  <AvatarMui
40
47
  classes={classes}
41
- className={cx(className, `size-${size}`, {
48
+ className={cx(className, {
49
+ [`size-${size}`]: !isCustomSize,
42
50
  disabled: !!disabled,
43
51
  border: !!border,
44
52
  [`display${capitalize(display)}`]: display !== 'initial',
@@ -9,20 +9,22 @@ import { FieldInputWrapperPropTypes } from '../types'
9
9
  // between Field from react-final-form and TextField from Mui
10
10
  const FieldInputWrapper = ({
11
11
  input,
12
- attributes,
12
+ attributes: { component, ...restAttributes },
13
13
  variant,
14
14
  fullWidth,
15
15
  ...props
16
16
  }) => {
17
- const Component = attributes.customLabelOptions
18
- ? TextFieldCustomLabelSelect
19
- : attributes?.select
20
- ? TextFieldSelect
21
- : TextField
17
+ const Component =
18
+ component ||
19
+ (restAttributes.customLabelOptions
20
+ ? TextFieldCustomLabelSelect
21
+ : restAttributes?.select
22
+ ? TextFieldSelect
23
+ : TextField)
22
24
 
23
25
  return (
24
26
  <Component
25
- {...attributes}
27
+ {...restAttributes}
26
28
  {...input}
27
29
  {...props}
28
30
  variant={variant}
@@ -5,7 +5,7 @@ import { getFormattedAddress } from 'cozy-client/dist/models/contact'
5
5
  import { fields } from './fieldsConfig'
6
6
  import { makeItemLabel, makeRelatedContact, movePrimaryToHead } from './helpers'
7
7
 
8
- const contactToFormValues = (contact, t) => {
8
+ const contactToFormValues = ({ contact, makeCustomContactValues, 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
11
  (initialValues, { name, layout }) => {
@@ -79,7 +79,10 @@ const contactToFormValues = (contact, t) => {
79
79
 
80
80
  const relatedContactValue = makeRelatedContact(contact)
81
81
 
82
+ const customValues = makeCustomContactValues?.(contact) || {}
83
+
82
84
  return {
85
+ ...customValues,
83
86
  gender,
84
87
  givenName: name?.givenName,
85
88
  additionalName: name?.additionalName,
@@ -24,7 +24,7 @@ describe('contactToFormValues function', () => {
24
24
  relatedContact: [undefined]
25
25
  }
26
26
 
27
- const result = contactToFormValues(null, tSpy)
27
+ const result = contactToFormValues({ contact: null, t: tSpy })
28
28
  expect(result).toEqual(expected)
29
29
  })
30
30
 
@@ -34,7 +34,7 @@ describe('contactToFormValues function', () => {
34
34
  '426 Runolfsson Knolls 84573 Port Easter Cocos (Keeling) Islands'
35
35
  )
36
36
 
37
- const result = contactToFormValues(johnDoeContact, tSpy)
37
+ const result = contactToFormValues({ contact: johnDoeContact, t: tSpy })
38
38
  expect(result).toEqual(expected)
39
39
  expect(tSpy).toHaveBeenCalledWith('formatted.address', {
40
40
  street: '426 Runolfsson Knolls',
@@ -86,7 +86,7 @@ describe('contactToFormValues function', () => {
86
86
  relatedContact: [undefined]
87
87
  }
88
88
 
89
- const result = contactToFormValues(contact, tSpy)
89
+ const result = contactToFormValues({ contact, t: tSpy })
90
90
  expect(result).toEqual(expected)
91
91
  })
92
92
 
@@ -127,7 +127,7 @@ describe('contactToFormValues function', () => {
127
127
  relatedContact: [undefined]
128
128
  }
129
129
 
130
- const result = contactToFormValues(contact, tSpy)
130
+ const result = contactToFormValues({ contact, t: tSpy })
131
131
  expect(result).toEqual(expected)
132
132
  })
133
133
  })
@@ -15,7 +15,7 @@ import TelephoneIcon from '../../../Icons/Telephone'
15
15
  import InputAdornment from '../../../InputAdornment'
16
16
 
17
17
  /**
18
- * @type {import('../../../types').Field[]}
18
+ * @type {import('../types').Field[]}
19
19
  */
20
20
  export const fields = [
21
21
  {
@@ -9,7 +9,12 @@ import {
9
9
  makeTypeAndLabel
10
10
  } from './helpers'
11
11
 
12
- const formValuesToContact = ({ formValues, oldContact, t }) => {
12
+ const formValuesToContact = ({
13
+ formValues,
14
+ oldContact,
15
+ makeCustomFieldsFormValues,
16
+ t
17
+ }) => {
13
18
  const {
14
19
  gender,
15
20
  givenName,
@@ -45,8 +50,11 @@ const formValuesToContact = ({ formValues, oldContact, t }) => {
45
50
  }
46
51
  }
47
52
 
53
+ const customFieldsFormValues = makeCustomFieldsFormValues?.(formValues) || {}
54
+
48
55
  const contactWithFormValues = {
49
56
  ...oldContactCleaned,
57
+ ...customFieldsFormValues,
50
58
  gender: gender || '',
51
59
  name: {
52
60
  ...oldContactCleaned?.name,
@@ -94,8 +94,10 @@ export const createAddress = ({ address, oldContact, t }) => {
94
94
  .filter(val => val && val.address)
95
95
  .map((addressField, index) => {
96
96
  const oldContactAddress = oldContact?.address?.[index]
97
- const oldContactFormValues = contactToFormValues(oldContact, t)
98
- ?.address?.[index]
97
+ const oldContactFormValues = contactToFormValues({
98
+ contact: oldContact,
99
+ t
100
+ })?.address?.[index]
99
101
 
100
102
  const addressHasBeenModified = !isEqual(
101
103
  addressField,
@@ -138,7 +140,7 @@ export const createAddress = ({ address, oldContact, t }) => {
138
140
  }
139
141
 
140
142
  /**
141
- * @param {(import('../../../types').RelatedContact|undefined)[]} relatedContact - The related contacts array
143
+ * @param {(import('../types').RelatedContact|undefined)[]} relatedContact - The related contacts array
142
144
  * @returns {Record<string, { data: { _id: string, _type: string }[] }>} - The related contacts relationships
143
145
  */
144
146
  export const getRelatedContactRelationships = relatedContact => {
@@ -218,7 +220,7 @@ export const removeAsscociatedData = contact => {
218
220
 
219
221
  /**
220
222
  * @param {import('cozy-client/types/types').IOCozyContact} contact
221
- * @returns {import('../../../types').RelatedContact[]}
223
+ * @returns {import('../types').RelatedContact[]}
222
224
  */
223
225
  export const makeRelatedContact = contact => {
224
226
  if (
@@ -368,3 +370,24 @@ export const makeInitialCustomValue = (name, value) => {
368
370
  return JSON.stringify({ type: valueObj.type, label: valueObj.label })
369
371
  }
370
372
  }
373
+
374
+ /**
375
+ * @param {(import('../types').Field)[]|undefined} customFields
376
+ * @param {(import('../types').Field)[]} defaultFields
377
+ * @returns {(import('../types').Field)[]}
378
+ */
379
+ export const makeFields = (customFields, defaultFields) => {
380
+ if (!customFields) {
381
+ return defaultFields
382
+ }
383
+
384
+ const fields = [...defaultFields]
385
+
386
+ customFields.map(customField => {
387
+ if (customField.position) {
388
+ fields.splice(customField.position, 0, customField)
389
+ }
390
+ })
391
+
392
+ return fields
393
+ }
@@ -6,6 +6,7 @@ import {
6
6
  makeTypeAndLabel,
7
7
  makeImppValues,
8
8
  makeCustomLabel,
9
+ makeFields,
9
10
  makeInitialCustomValue
10
11
  } from './helpers'
11
12
  import { locales } from './locales'
@@ -323,3 +324,68 @@ describe('makeInitialCustomValue', () => {
323
324
  })
324
325
  })
325
326
  })
327
+
328
+ describe('makeFields', () => {
329
+ it('should return custom fields at custom position', () => {
330
+ const customFields = [
331
+ { name: 'middlename', position: 1 },
332
+ { name: 'birthday', position: 3 }
333
+ ]
334
+ const defaultFields = [{ name: 'firstname' }, { name: 'lastname' }]
335
+
336
+ const res = makeFields(customFields, defaultFields)
337
+
338
+ expect(res).toStrictEqual([
339
+ { name: 'firstname' },
340
+ { name: 'middlename', position: 1 },
341
+ { name: 'lastname' },
342
+ { name: 'birthday', position: 3 }
343
+ ])
344
+ })
345
+
346
+ it('should ignore custom fields without position value', () => {
347
+ const customFields = [
348
+ { name: 'middlename', position: 1 },
349
+ { name: 'field-with-no-position' }
350
+ ]
351
+ const defaultFields = [{ name: 'firstname' }, { name: 'lastname' }]
352
+
353
+ const res = makeFields(customFields, defaultFields)
354
+
355
+ expect(res).toStrictEqual([
356
+ { name: 'firstname' },
357
+ { name: 'middlename', position: 1 },
358
+ { name: 'lastname' }
359
+ ])
360
+ })
361
+
362
+ it('should not mutate the original arrays', () => {
363
+ const customFields = [
364
+ { name: 'middlename', position: 1 },
365
+ { name: 'field-with-no-position' },
366
+ { name: 'birthday', position: 3 }
367
+ ]
368
+ const defaultFields = [{ name: 'firstname' }, { name: 'lastname' }]
369
+
370
+ makeFields(customFields, defaultFields)
371
+
372
+ expect(defaultFields).toStrictEqual([
373
+ { name: 'firstname' },
374
+ { name: 'lastname' }
375
+ ])
376
+
377
+ expect(customFields).toStrictEqual([
378
+ { name: 'middlename', position: 1 },
379
+ { name: 'field-with-no-position' },
380
+ { name: 'birthday', position: 3 }
381
+ ])
382
+ })
383
+
384
+ it('should handle undefined custom fields', () => {
385
+ const defaultFields = [{ name: 'firstname' }, { name: 'lastname' }]
386
+
387
+ const res = makeFields(undefined, defaultFields)
388
+
389
+ expect(res).toStrictEqual(defaultFields)
390
+ })
391
+ })
@@ -6,9 +6,9 @@ import { getHasManyItems } from 'cozy-client/dist/associations/HasMany'
6
6
 
7
7
  import FieldInputLayout from './FieldInputLayout'
8
8
  import contactToFormValues from './contactToFormValues'
9
- import { fields } from './fieldsConfig'
9
+ import { fields as defaultFields } from './fieldsConfig'
10
10
  import formValuesToContact from './formValuesToContact'
11
- import { validateFields } from './helpers'
11
+ import { validateFields, makeFields } from './helpers'
12
12
  import { locales } from './locales'
13
13
  import Button from '../../../Buttons'
14
14
  import { useI18n, useExtendI18n } from '../../../providers/I18n'
@@ -31,24 +31,41 @@ export function getSubmitContactForm() {
31
31
  /**
32
32
  *
33
33
  * @param {object} params
34
+ * @param {{ data: Array<object> }} params.contacts
34
35
  * @param {import('cozy-client/types/types').IOCozyContact} params.contact
36
+ * @param {Object} params.customFieldsProps
35
37
  * @param {func} params.onSubmit
36
- * @param {{ data: Array<object> }} params.contacts
37
38
  * @returns
38
39
  */
39
- const ContactForm = ({ contact, onSubmit, contacts }) => {
40
+ const ContactForm = ({ contacts, contact, customFieldsProps, onSubmit }) => {
40
41
  const [showSecondaryFields, setShowSecondaryFields] = useState(false)
41
42
  useExtendI18n(locales)
42
43
  const { t } = useI18n()
44
+ const { fields, makeCustomFieldsFormValues, makeCustomContactValues } =
45
+ customFieldsProps
46
+
47
+ const _fields = makeFields(fields, defaultFields)
48
+ const hasSecondaryFields = _fields.some(el => el.isSecondary)
43
49
 
44
50
  return (
45
51
  <Form
46
52
  mutators={{ ...arrayMutators }}
53
+ initialValues={contactToFormValues({
54
+ contact,
55
+ makeCustomContactValues,
56
+ t
57
+ })}
47
58
  validate={values => validateFields(values, t)}
48
59
  onSubmit={formValues =>
49
- onSubmit(formValuesToContact({ formValues, oldContact: contact, t }))
60
+ onSubmit(
61
+ formValuesToContact({
62
+ formValues,
63
+ oldContact: contact,
64
+ makeCustomFieldsFormValues,
65
+ t
66
+ })
67
+ )
50
68
  }
51
- initialValues={contactToFormValues(contact, t)}
52
69
  render={({ handleSubmit, valid, submitFailed, errors }) => {
53
70
  setSubmitContactForm(handleSubmit)
54
71
  return (
@@ -57,7 +74,7 @@ const ContactForm = ({ contact, onSubmit, contacts }) => {
57
74
  onSubmit={handleSubmit}
58
75
  className="u-flex u-flex-column"
59
76
  >
60
- {fields.map((attributes, index) => (
77
+ {_fields.map((attributes, index) => (
61
78
  <FieldInputLayout
62
79
  key={index}
63
80
  attributes={attributes}
@@ -70,7 +87,7 @@ const ContactForm = ({ contact, onSubmit, contacts }) => {
70
87
  }}
71
88
  />
72
89
  ))}
73
- {!showSecondaryFields && (
90
+ {hasSecondaryFields && !showSecondaryFields && (
74
91
  <div>
75
92
  <Button
76
93
  className="u-db u-ml-2 u-mt-1"
@@ -87,6 +104,10 @@ const ContactForm = ({ contact, onSubmit, contacts }) => {
87
104
  )
88
105
  }
89
106
 
107
+ ContactForm.defaultProps = {
108
+ customFieldsProps: {}
109
+ }
110
+
90
111
  // Used to avoid unnecessary multiple rendering of ContactForm when creating a new contact in another way.
91
112
  // These unnecessary renderings prevented the addition of a newly created linked contact. (Creation of a contact when selecting a linked contact)
92
113
  export const isSameContactProp = (prevProps, nextProps) => {
@@ -4,6 +4,8 @@ Works with `final-form`, `final-form-arrays`, `react-final-form` and `react-fina
4
4
 
5
5
  ```jsx
6
6
  import { useState } from 'react'
7
+ import StarIcon from 'cozy-ui/transpiled/react/Icons/Star'
8
+ import TextField from 'cozy-ui/transpiled/react/TextField'
7
9
  import ContactsAddModal from 'cozy-ui/transpiled/react/Contacts/AddModal'
8
10
  import DemoProvider from 'cozy-ui/docs/components/DemoProvider'
9
11
  import AlertProvider from 'cozy-ui/transpiled/react/providers/Alert'
@@ -13,7 +15,7 @@ import contacts from 'cozy-ui/transpiled/react/ContactsList/_mockContacts.json'
13
15
  import Variants from 'cozy-ui/docs/components/Variants'
14
16
 
15
17
  initialState = { showModal: isTesting() }
16
- initialVariants = [{ withContact: false }]
18
+ initialVariants = [{ withContact: false, withCustomFields: false }]
17
19
 
18
20
  const open = () => setState({ showModal: true })
19
21
  const close = () => setState({ showModal: false })
@@ -22,18 +24,25 @@ const handleSubmit = async formData => {
22
24
  console.info('formData :', formData)
23
25
  }
24
26
 
27
+ const customFields = [{ name: 'customField', icon: StarIcon, type: 'text', position: 5, component: TextField }]
28
+
25
29
  ;
26
30
 
27
- <DemoProvider>
31
+ <DemoProvider dictRequire={() => ({ Contacts: {AddModal: {ContactForm: {fields: {customField: 'Custom field'}}}} })}>
28
32
  <AlertProvider>
29
- <Variants initialVariants={initialVariants} screenshotAllVariants>
33
+ <Variants initialVariants={initialVariants}>
30
34
  {variant => (
31
35
  <>
32
36
  <Button onClick={open} label="Open Modal" />
33
37
  {state.showModal && (
34
38
  <ContactsAddModal
35
39
  contacts={{ data: contacts }}
36
- contact={variant.withContact ? johnDoeContact : undefined}
40
+ contact={variant.withContact ? {...johnDoeContact, customField: "Custom field value"} : undefined}
41
+ customFieldsProps={variant.withCustomFields && {
42
+ fields: customFields,
43
+ makeCustomFieldsFormValues: formValues => ({ customField: formValues.customField }),
44
+ makeCustomContactValues: contact => ({ customField: contact.customField })
45
+ }}
37
46
  onSubmit={handleSubmit}
38
47
  onClose={close}
39
48
  />
@@ -7,7 +7,13 @@ import { FixedDialog } from '../../CozyDialogs'
7
7
  import { useAlert } from '../../providers/Alert'
8
8
  import { useI18n, useExtendI18n } from '../../providers/I18n'
9
9
 
10
- const AddModal = ({ contacts, contact, onSubmit, onClose }) => {
10
+ const AddModal = ({
11
+ contacts,
12
+ contact,
13
+ customFieldsProps,
14
+ onSubmit,
15
+ onClose
16
+ }) => {
11
17
  useExtendI18n(locales)
12
18
  const { t } = useI18n()
13
19
  const { showAlert } = useAlert()
@@ -52,6 +58,7 @@ const AddModal = ({ contacts, contact, onSubmit, onClose }) => {
52
58
  <ContactForm
53
59
  contacts={contacts}
54
60
  contact={selfContact}
61
+ customFieldsProps={customFieldsProps}
55
62
  onSubmit={handleFormSubmit}
56
63
  />
57
64
  }
@@ -2,6 +2,51 @@ import PropTypes from 'prop-types'
2
2
 
3
3
  import { iconPropType } from '../../Icon'
4
4
 
5
+ /**
6
+ * @typedef {'text'|'tel'|'email'|'button'|'url'|'date'} FieldType
7
+ */
8
+
9
+ /**
10
+ * @typedef {Object} CustomLabelOptions
11
+ * @property {string} defaultType - The default type of the option
12
+ * @property {string} defaultLabel - The default label of the option
13
+ * @property {boolean} [hide] - Whether the radio choices is hidden
14
+ */
15
+
16
+ /**
17
+ * @typedef {Object} LabelField
18
+ * @property {string} name - The name of the label field
19
+ * @property {boolean} select - Whether the field is a select
20
+ * @property {CustomLabelOptions} customLabelOptions - The custom label field options
21
+ * @property {Option[]} options - The options of the label field
22
+ */
23
+
24
+ /**
25
+ * @typedef {Object} InputLabelProps
26
+ * @property {boolean} shrink - passed to InputLabelProps props
27
+ */
28
+
29
+ /**
30
+ * @typedef {Object} Field
31
+ * @property {string} name - The name of the field
32
+ * @property {string|null} icon - The icon of the field
33
+ * @property {FieldType} type - The type of the field
34
+ * @property {boolean} [isSecondary] - Whether the field is hidden from the main form
35
+ * @property {LabelField} [label] - Add a "label" field next to the main field
36
+ * @property {'accordion'|'array'} [layout] - Whether the field is an array (To add fields dynamically (e.g. email, address, etc.))
37
+ * @property {Field[]} [subFields] - The subfields of the field
38
+ * @property {InputLabelProps} [InputLabelProps] - The object passed to InputLabelProps props
39
+ * @property {boolean} [multiline] - Whether the field is multiline
40
+ * @property {number} [position] - Position of a field in the form. 1 is first.
41
+ */
42
+
43
+ /**
44
+ * @typedef {Object} RelatedContact
45
+ * @property {string} relatedContactId - The id of the related contact
46
+ * @property {string} relatedContact - The displayName of the related contact
47
+ * @property {string} relatedContactLabel - Object with the type of the related contact stringified (e.g. '{\"type\":\"spouse\"}')
48
+ */
49
+
5
50
  export const labelPropTypes = PropTypes.shape({
6
51
  name: PropTypes.string,
7
52
  options: PropTypes.arrayOf(
@@ -12,41 +12,54 @@ import { makeStyles } from "cozy-ui/transpiled/react/styles";
12
12
  import { capitalize } from "cozy-ui/transpiled/react/utils/index";
13
13
  var useStyles = makeStyles(function (theme) {
14
14
  return {
15
+ root: {
16
+ width: function width(_ref) {
17
+ var size = _ref.size;
18
+ return size;
19
+ },
20
+ height: function height(_ref2) {
21
+ var size = _ref2.size;
22
+ return size;
23
+ },
24
+ fontSize: function fontSize(_ref3) {
25
+ var size = _ref3.size;
26
+ return size / 2;
27
+ }
28
+ },
15
29
  colorDefault: {
16
- color: function color(_ref) {
17
- var _color = _ref.color;
30
+ color: function color(_ref4) {
31
+ var _color = _ref4.color;
18
32
  return _color ? theme.palette.primary.contrastText : '';
19
33
  },
20
- background: function background(_ref2) {
21
- var color = _ref2.color;
34
+ background: function background(_ref5) {
35
+ var color = _ref5.color;
22
36
  return colorMapping[color];
23
37
  }
24
38
  }
25
39
  };
26
40
  });
27
41
 
28
- var Avatar = function Avatar(_ref3) {
42
+ var Avatar = function Avatar(_ref6) {
29
43
  var _cx;
30
44
 
31
- var className = _ref3.className,
32
- color = _ref3.color,
33
- size = _ref3.size,
34
- border = _ref3.border,
35
- innerBorder = _ref3.innerBorder,
36
- disabled = _ref3.disabled,
37
- display = _ref3.display,
38
- props = _objectWithoutProperties(_ref3, _excluded);
45
+ var className = _ref6.className,
46
+ color = _ref6.color,
47
+ size = _ref6.size,
48
+ border = _ref6.border,
49
+ innerBorder = _ref6.innerBorder,
50
+ disabled = _ref6.disabled,
51
+ display = _ref6.display,
52
+ props = _objectWithoutProperties(_ref6, _excluded);
39
53
 
54
+ var isCustomSize = typeof size === 'number';
40
55
  var defaultColor = typeof props.children === 'string' ? nameToColor(props.children) : undefined;
41
56
  var classes = useStyles({
57
+ size: isCustomSize ? size : undefined,
42
58
  color: color === 'none' ? undefined : supportedColors.includes(color) ? color : defaultColor
43
59
  });
44
60
  return /*#__PURE__*/React.createElement(AvatarMui, _extends({
45
61
  classes: classes,
46
- className: cx(className, "size-".concat(size), (_cx = {
47
- disabled: !!disabled,
48
- border: !!border
49
- }, _defineProperty(_cx, "display".concat(capitalize(display)), display !== 'initial'), _defineProperty(_cx, "innerBorder", !!innerBorder), _cx))
62
+ className: cx(className, (_cx = {}, _defineProperty(_cx, "size-".concat(size), !isCustomSize), _defineProperty(_cx, "disabled", !!disabled), _defineProperty(_cx, "border", !!border), _defineProperty(_cx, "display".concat(capitalize(display)), display !== 'initial'), _defineProperty(_cx, "innerBorder", !!innerBorder), _cx))
50
63
  }, props));
51
64
  };
52
65
 
@@ -1,8 +1,11 @@
1
1
  export default FieldInputWrapper;
2
- declare function FieldInputWrapper({ input, attributes, variant, fullWidth, ...props }: {
2
+ declare function FieldInputWrapper({ input, attributes: { component, ...restAttributes }, variant, fullWidth, ...props }: {
3
3
  [x: string]: any;
4
4
  input: any;
5
- attributes: any;
5
+ attributes: {
6
+ [x: string]: any;
7
+ component: any;
8
+ };
6
9
  variant: any;
7
10
  fullWidth: any;
8
11
  }): JSX.Element;
@@ -1,6 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
- var _excluded = ["input", "attributes", "variant", "fullWidth"];
3
+ var _excluded = ["component"],
4
+ _excluded2 = ["input", "attributes", "variant", "fullWidth"];
4
5
  import React from 'react';
5
6
  import TextFieldCustomLabelSelect from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/TextFieldCustomLabelSelect";
6
7
  import TextFieldSelect from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/TextFieldSelect";
@@ -10,13 +11,15 @@ import { FieldInputWrapperPropTypes } from "cozy-ui/transpiled/react/Contacts/Ad
10
11
 
11
12
  var FieldInputWrapper = function FieldInputWrapper(_ref) {
12
13
  var input = _ref.input,
13
- attributes = _ref.attributes,
14
+ _ref$attributes = _ref.attributes,
15
+ component = _ref$attributes.component,
16
+ restAttributes = _objectWithoutProperties(_ref$attributes, _excluded),
14
17
  variant = _ref.variant,
15
18
  fullWidth = _ref.fullWidth,
16
- props = _objectWithoutProperties(_ref, _excluded);
19
+ props = _objectWithoutProperties(_ref, _excluded2);
17
20
 
18
- var Component = attributes.customLabelOptions ? TextFieldCustomLabelSelect : attributes !== null && attributes !== void 0 && attributes.select ? TextFieldSelect : TextField;
19
- return /*#__PURE__*/React.createElement(Component, _extends({}, attributes, input, props, {
21
+ var Component = component || (restAttributes.customLabelOptions ? TextFieldCustomLabelSelect : restAttributes !== null && restAttributes !== void 0 && restAttributes.select ? TextFieldSelect : TextField);
22
+ return /*#__PURE__*/React.createElement(Component, _extends({}, restAttributes, input, props, {
20
23
  variant: variant,
21
24
  fullWidth: fullWidth,
22
25
  minRows: "2"
@@ -1,2 +1,6 @@
1
1
  export default contactToFormValues;
2
- declare function contactToFormValues(contact: any, t: any): any;
2
+ declare function contactToFormValues({ contact, makeCustomContactValues, t }: {
3
+ contact: any;
4
+ makeCustomContactValues: any;
5
+ t: any;
6
+ }): any;
@@ -1,13 +1,22 @@
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
+
1
7
  import uniqueId from 'lodash/uniqueId';
2
8
  import { getFormattedAddress } from 'cozy-client/dist/models/contact';
3
9
  import { fields } from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/fieldsConfig";
4
10
  import { makeItemLabel, makeRelatedContact, movePrimaryToHead } from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/helpers";
5
11
 
6
- var contactToFormValues = function contactToFormValues(contact, t) {
12
+ var contactToFormValues = function contactToFormValues(_ref) {
13
+ var contact = _ref.contact,
14
+ makeCustomContactValues = _ref.makeCustomContactValues,
15
+ t = _ref.t;
7
16
  // 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
- layout = _ref.layout;
17
+ var initialFieldValues = fields.reduce(function (initialValues, _ref2) {
18
+ var name = _ref2.name,
19
+ layout = _ref2.layout;
11
20
  initialValues[name] = layout === 'array' ? [undefined] : undefined;
12
21
  return initialValues;
13
22
  }, {});
@@ -68,7 +77,8 @@ var contactToFormValues = function contactToFormValues(contact, t) {
68
77
  };
69
78
  }) : [undefined];
70
79
  var relatedContactValue = makeRelatedContact(contact);
71
- return {
80
+ var customValues = (makeCustomContactValues === null || makeCustomContactValues === void 0 ? void 0 : makeCustomContactValues(contact)) || {};
81
+ return _objectSpread(_objectSpread({}, customValues), {}, {
72
82
  gender: gender,
73
83
  givenName: name === null || name === void 0 ? void 0 : name.givenName,
74
84
  additionalName: name === null || name === void 0 ? void 0 : name.additionalName,
@@ -86,7 +96,7 @@ var contactToFormValues = function contactToFormValues(contact, t) {
86
96
  birthplace: birthplace,
87
97
  note: note,
88
98
  relatedContact: relatedContactValue
89
- };
99
+ });
90
100
  }
91
101
 
92
102
  return initialFieldValues;
@@ -1,4 +1,4 @@
1
1
  /**
2
- * @type {import('../../../types').Field[]}
2
+ * @type {import('../types').Field[]}
3
3
  */
4
- export const fields: any[];
4
+ export const fields: import('../types').Field[];
@@ -13,7 +13,7 @@ import RelationshipIcon from "cozy-ui/transpiled/react/Icons/Relationship";
13
13
  import TelephoneIcon from "cozy-ui/transpiled/react/Icons/Telephone";
14
14
  import InputAdornment from "cozy-ui/transpiled/react/InputAdornment";
15
15
  /**
16
- * @type {import('../../../types').Field[]}
16
+ * @type {import('../types').Field[]}
17
17
  */
18
18
 
19
19
  export var fields = [{
@@ -1,6 +1,7 @@
1
1
  export default formValuesToContact;
2
- declare function formValuesToContact({ formValues, oldContact, t }: {
2
+ declare function formValuesToContact({ formValues, oldContact, makeCustomFieldsFormValues, t }: {
3
3
  formValues: any;
4
4
  oldContact: any;
5
+ makeCustomFieldsFormValues: any;
5
6
  t: any;
6
7
  }): any;
@@ -10,6 +10,7 @@ import { removeAsscociatedData, removeRelatedContactRelationships, createAddress
10
10
  var formValuesToContact = function formValuesToContact(_ref) {
11
11
  var formValues = _ref.formValues,
12
12
  oldContact = _ref.oldContact,
13
+ makeCustomFieldsFormValues = _ref.makeCustomFieldsFormValues,
13
14
  t = _ref.t;
14
15
  var gender = formValues.gender,
15
16
  givenName = formValues.givenName,
@@ -37,7 +38,9 @@ var formValuesToContact = function formValuesToContact(_ref) {
37
38
  }
38
39
  });
39
40
 
40
- var contactWithFormValues = _objectSpread(_objectSpread({}, oldContactCleaned), {}, {
41
+ var customFieldsFormValues = (makeCustomFieldsFormValues === null || makeCustomFieldsFormValues === void 0 ? void 0 : makeCustomFieldsFormValues(formValues)) || {};
42
+
43
+ var contactWithFormValues = _objectSpread(_objectSpread(_objectSpread({}, oldContactCleaned), customFieldsFormValues), {}, {
41
44
  gender: gender || '',
42
45
  name: _objectSpread(_objectSpread({}, oldContactCleaned === null || oldContactCleaned === void 0 ? void 0 : oldContactCleaned.name), {}, {
43
46
  givenName: givenName || '',
@@ -13,7 +13,7 @@ export function createAddress({ address, oldContact, t }: {
13
13
  oldContact: any;
14
14
  t: any;
15
15
  }): any;
16
- export function getRelatedContactRelationships(relatedContact: (any | undefined)[]): Record<string, {
16
+ export function getRelatedContactRelationships(relatedContact: (import('../types').RelatedContact | undefined)[]): Record<string, {
17
17
  data: {
18
18
  _id: string;
19
19
  _type: string;
@@ -21,7 +21,7 @@ export function getRelatedContactRelationships(relatedContact: (any | undefined)
21
21
  }>;
22
22
  export function removeRelatedContactRelationships(contact: import('cozy-client/types/types').IOCozyContact): import('cozy-client/types/types').IOCozyContact;
23
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[];
24
+ export function makeRelatedContact(contact: import('cozy-client/types/types').IOCozyContact): import('../types').RelatedContact[];
25
25
  export function addField(fields: any): any;
26
26
  export function removeField(fields: any, index: any): void;
27
27
  export function makeCustomLabel(value: string, t: func): string;
@@ -32,3 +32,4 @@ export function makeImppValues(oldContact: import('cozy-client/types/types').IOC
32
32
  primary?: boolean;
33
33
  }[];
34
34
  export function makeInitialCustomValue(name: string, value: string): string;
35
+ export function makeFields(customFields: (import('../types').Field)[] | undefined, defaultFields: (import('../types').Field)[]): (import('../types').Field)[];
@@ -103,7 +103,10 @@ export var createAddress = function createAddress(_ref) {
103
103
  var _oldContact$address, _contactToFormValues, _contactToFormValues$;
104
104
 
105
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];
106
+ var oldContactFormValues = (_contactToFormValues = contactToFormValues({
107
+ contact: oldContact,
108
+ t: t
109
+ })) === null || _contactToFormValues === void 0 ? void 0 : (_contactToFormValues$ = _contactToFormValues.address) === null || _contactToFormValues$ === void 0 ? void 0 : _contactToFormValues$[index];
107
110
  var addressHasBeenModified = !isEqual(addressField, oldContactFormValues);
108
111
 
109
112
  if (addressHasBeenModified) {
@@ -139,7 +142,7 @@ export var createAddress = function createAddress(_ref) {
139
142
  }) : [];
140
143
  };
141
144
  /**
142
- * @param {(import('../../../types').RelatedContact|undefined)[]} relatedContact - The related contacts array
145
+ * @param {(import('../types').RelatedContact|undefined)[]} relatedContact - The related contacts array
143
146
  * @returns {Record<string, { data: { _id: string, _type: string }[] }>} - The related contacts relationships
144
147
  */
145
148
 
@@ -223,7 +226,7 @@ export var removeAsscociatedData = function removeAsscociatedData(contact) {
223
226
  };
224
227
  /**
225
228
  * @param {import('cozy-client/types/types').IOCozyContact} contact
226
- * @returns {import('../../../types').RelatedContact[]}
229
+ * @returns {import('../types').RelatedContact[]}
227
230
  */
228
231
 
229
232
  export var makeRelatedContact = function makeRelatedContact(contact) {
@@ -372,4 +375,24 @@ export var makeInitialCustomValue = function makeInitialCustomValue(name, value)
372
375
  label: valueObj.label
373
376
  });
374
377
  }
378
+ };
379
+ /**
380
+ * @param {(import('../types').Field)[]|undefined} customFields
381
+ * @param {(import('../types').Field)[]} defaultFields
382
+ * @returns {(import('../types').Field)[]}
383
+ */
384
+
385
+ export var makeFields = function makeFields(customFields, defaultFields) {
386
+ if (!customFields) {
387
+ return defaultFields;
388
+ }
389
+
390
+ var fields = _toConsumableArray(defaultFields);
391
+
392
+ customFields.map(function (customField) {
393
+ if (customField.position) {
394
+ fields.splice(customField.position, 0, customField);
395
+ }
396
+ });
397
+ return fields;
375
398
  };
@@ -1,11 +1,17 @@
1
1
  export function getSubmitContactForm(): any;
2
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>;
3
+ declare var _default: React.MemoExoticComponent<{
4
+ ({ contacts, contact, customFieldsProps, onSubmit }: {
5
+ contacts: {
6
+ data: Array<object>;
7
+ };
8
+ contact: import('cozy-client/types/types').IOCozyContact;
9
+ customFieldsProps: Object;
10
+ onSubmit: func;
11
+ }): JSX.Element;
12
+ defaultProps: {
13
+ customFieldsProps: {};
8
14
  };
9
- }) => JSX.Element>;
15
+ }>;
10
16
  export default _default;
11
17
  import React from "react";
@@ -11,9 +11,9 @@ import { Form } from 'react-final-form';
11
11
  import { getHasManyItems } from 'cozy-client/dist/associations/HasMany';
12
12
  import FieldInputLayout from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/FieldInputLayout";
13
13
  import contactToFormValues from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/contactToFormValues";
14
- import { fields } from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/fieldsConfig";
14
+ import { fields as defaultFields } from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/fieldsConfig";
15
15
  import formValuesToContact from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/formValuesToContact";
16
- import { validateFields } from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/helpers";
16
+ import { validateFields, makeFields } from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/helpers";
17
17
  import { locales } from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/locales";
18
18
  import Button from "cozy-ui/transpiled/react/Buttons";
19
19
  import { useI18n, useExtendI18n } from "cozy-ui/transpiled/react/providers/I18n"; // import { fullContactPropTypes } from '../../ContactPropTypes' // !!
@@ -34,16 +34,18 @@ export function getSubmitContactForm() {
34
34
  /**
35
35
  *
36
36
  * @param {object} params
37
+ * @param {{ data: Array<object> }} params.contacts
37
38
  * @param {import('cozy-client/types/types').IOCozyContact} params.contact
39
+ * @param {Object} params.customFieldsProps
38
40
  * @param {func} params.onSubmit
39
- * @param {{ data: Array<object> }} params.contacts
40
41
  * @returns
41
42
  */
42
43
 
43
44
  var ContactForm = function ContactForm(_ref) {
44
- var contact = _ref.contact,
45
- _onSubmit = _ref.onSubmit,
46
- contacts = _ref.contacts;
45
+ var contacts = _ref.contacts,
46
+ contact = _ref.contact,
47
+ customFieldsProps = _ref.customFieldsProps,
48
+ _onSubmit = _ref.onSubmit;
47
49
 
48
50
  var _useState = useState(false),
49
51
  _useState2 = _slicedToArray(_useState, 2),
@@ -55,8 +57,23 @@ var ContactForm = function ContactForm(_ref) {
55
57
  var _useI18n = useI18n(),
56
58
  t = _useI18n.t;
57
59
 
60
+ var fields = customFieldsProps.fields,
61
+ makeCustomFieldsFormValues = customFieldsProps.makeCustomFieldsFormValues,
62
+ makeCustomContactValues = customFieldsProps.makeCustomContactValues;
63
+
64
+ var _fields = makeFields(fields, defaultFields);
65
+
66
+ var hasSecondaryFields = _fields.some(function (el) {
67
+ return el.isSecondary;
68
+ });
69
+
58
70
  return /*#__PURE__*/React.createElement(Form, {
59
71
  mutators: _objectSpread({}, arrayMutators),
72
+ initialValues: contactToFormValues({
73
+ contact: contact,
74
+ makeCustomContactValues: makeCustomContactValues,
75
+ t: t
76
+ }),
60
77
  validate: function validate(values) {
61
78
  return validateFields(values, t);
62
79
  },
@@ -64,10 +81,10 @@ var ContactForm = function ContactForm(_ref) {
64
81
  return _onSubmit(formValuesToContact({
65
82
  formValues: formValues,
66
83
  oldContact: contact,
84
+ makeCustomFieldsFormValues: makeCustomFieldsFormValues,
67
85
  t: t
68
86
  }));
69
87
  },
70
- initialValues: contactToFormValues(contact, t),
71
88
  render: function render(_ref2) {
72
89
  var handleSubmit = _ref2.handleSubmit,
73
90
  valid = _ref2.valid,
@@ -78,7 +95,7 @@ var ContactForm = function ContactForm(_ref) {
78
95
  role: "form",
79
96
  onSubmit: handleSubmit,
80
97
  className: "u-flex u-flex-column"
81
- }, fields.map(function (attributes, index) {
98
+ }, _fields.map(function (attributes, index) {
82
99
  return /*#__PURE__*/React.createElement(FieldInputLayout, {
83
100
  key: index,
84
101
  attributes: attributes,
@@ -90,7 +107,7 @@ var ContactForm = function ContactForm(_ref) {
90
107
  errors: errors
91
108
  }
92
109
  });
93
- }), !showSecondaryFields && /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Button, {
110
+ }), hasSecondaryFields && !showSecondaryFields && /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Button, {
94
111
  className: "u-db u-ml-2 u-mt-1",
95
112
  variant: "text",
96
113
  label: t('Contacts.AddModal.ContactForm.other-fields'),
@@ -100,10 +117,13 @@ var ContactForm = function ContactForm(_ref) {
100
117
  })));
101
118
  }
102
119
  });
120
+ };
121
+
122
+ ContactForm.defaultProps = {
123
+ customFieldsProps: {}
103
124
  }; // Used to avoid unnecessary multiple rendering of ContactForm when creating a new contact in another way.
104
125
  // These unnecessary renderings prevented the addition of a newly created linked contact. (Creation of a contact when selecting a linked contact)
105
126
 
106
-
107
127
  export var isSameContactProp = function isSameContactProp(prevProps, nextProps) {
108
128
  var _prevProps$contact, _nextProps$contact;
109
129
 
@@ -1,7 +1,8 @@
1
1
  export default AddModal;
2
- declare function AddModal({ contacts, contact, onSubmit, onClose }: {
2
+ declare function AddModal({ contacts, contact, customFieldsProps, onSubmit, onClose }: {
3
3
  contacts: any;
4
4
  contact: any;
5
+ customFieldsProps: any;
5
6
  onSubmit: any;
6
7
  onClose: any;
7
8
  }): JSX.Element;
@@ -12,6 +12,7 @@ import { useI18n, useExtendI18n } from "cozy-ui/transpiled/react/providers/I18n"
12
12
  var AddModal = function AddModal(_ref) {
13
13
  var contacts = _ref.contacts,
14
14
  contact = _ref.contact,
15
+ customFieldsProps = _ref.customFieldsProps,
15
16
  onSubmit = _ref.onSubmit,
16
17
  onClose = _ref.onClose;
17
18
  useExtendI18n(locales);
@@ -90,6 +91,7 @@ var AddModal = function AddModal(_ref) {
90
91
  content: /*#__PURE__*/React.createElement(ContactForm, {
91
92
  contacts: contacts,
92
93
  contact: selfContact,
94
+ customFieldsProps: customFieldsProps,
93
95
  onSubmit: handleFormSubmit
94
96
  }),
95
97
  actions: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, {
@@ -1,3 +1,42 @@
1
+ /**
2
+ * @typedef {'text'|'tel'|'email'|'button'|'url'|'date'} FieldType
3
+ */
4
+ /**
5
+ * @typedef {Object} CustomLabelOptions
6
+ * @property {string} defaultType - The default type of the option
7
+ * @property {string} defaultLabel - The default label of the option
8
+ * @property {boolean} [hide] - Whether the radio choices is hidden
9
+ */
10
+ /**
11
+ * @typedef {Object} LabelField
12
+ * @property {string} name - The name of the label field
13
+ * @property {boolean} select - Whether the field is a select
14
+ * @property {CustomLabelOptions} customLabelOptions - The custom label field options
15
+ * @property {Option[]} options - The options of the label field
16
+ */
17
+ /**
18
+ * @typedef {Object} InputLabelProps
19
+ * @property {boolean} shrink - passed to InputLabelProps props
20
+ */
21
+ /**
22
+ * @typedef {Object} Field
23
+ * @property {string} name - The name of the field
24
+ * @property {string|null} icon - The icon of the field
25
+ * @property {FieldType} type - The type of the field
26
+ * @property {boolean} [isSecondary] - Whether the field is hidden from the main form
27
+ * @property {LabelField} [label] - Add a "label" field next to the main field
28
+ * @property {'accordion'|'array'} [layout] - Whether the field is an array (To add fields dynamically (e.g. email, address, etc.))
29
+ * @property {Field[]} [subFields] - The subfields of the field
30
+ * @property {InputLabelProps} [InputLabelProps] - The object passed to InputLabelProps props
31
+ * @property {boolean} [multiline] - Whether the field is multiline
32
+ * @property {number} [position] - Position of a field in the form. 1 is first.
33
+ */
34
+ /**
35
+ * @typedef {Object} RelatedContact
36
+ * @property {string} relatedContactId - The id of the related contact
37
+ * @property {string} relatedContact - The displayName of the related contact
38
+ * @property {string} relatedContactLabel - Object with the type of the related contact stringified (e.g. '{\"type\":\"spouse\"}')
39
+ */
1
40
  export const labelPropTypes: PropTypes.Requireable<PropTypes.InferProps<{
2
41
  name: PropTypes.Requireable<string>;
3
42
  options: PropTypes.Requireable<(PropTypes.InferProps<{
@@ -51,4 +90,99 @@ export namespace FieldInputWrapperPropTypes {
51
90
  }>>;
52
91
  export const fullWidth: PropTypes.Requireable<boolean>;
53
92
  }
93
+ export type FieldType = 'text' | 'tel' | 'email' | 'button' | 'url' | 'date';
94
+ export type CustomLabelOptions = {
95
+ /**
96
+ * - The default type of the option
97
+ */
98
+ defaultType: string;
99
+ /**
100
+ * - The default label of the option
101
+ */
102
+ defaultLabel: string;
103
+ /**
104
+ * - Whether the radio choices is hidden
105
+ */
106
+ hide?: boolean | undefined;
107
+ };
108
+ export type LabelField = {
109
+ /**
110
+ * - The name of the label field
111
+ */
112
+ name: string;
113
+ /**
114
+ * - Whether the field is a select
115
+ */
116
+ select: boolean;
117
+ /**
118
+ * - The custom label field options
119
+ */
120
+ customLabelOptions: CustomLabelOptions;
121
+ /**
122
+ * - The options of the label field
123
+ */
124
+ options: (new (text?: string | undefined, value?: string | undefined, defaultSelected?: boolean | undefined, selected?: boolean | undefined) => HTMLOptionElement)[];
125
+ };
126
+ export type InputLabelProps = {
127
+ /**
128
+ * - passed to InputLabelProps props
129
+ */
130
+ shrink: boolean;
131
+ };
132
+ export type Field = {
133
+ /**
134
+ * - The name of the field
135
+ */
136
+ name: string;
137
+ /**
138
+ * - The icon of the field
139
+ */
140
+ icon: string | null;
141
+ /**
142
+ * - The type of the field
143
+ */
144
+ type: FieldType;
145
+ /**
146
+ * - Whether the field is hidden from the main form
147
+ */
148
+ isSecondary?: boolean | undefined;
149
+ /**
150
+ * - Add a "label" field next to the main field
151
+ */
152
+ label?: LabelField | undefined;
153
+ /**
154
+ * - Whether the field is an array (To add fields dynamically (e.g. email, address, etc.))
155
+ */
156
+ layout?: "array" | "accordion" | undefined;
157
+ /**
158
+ * - The subfields of the field
159
+ */
160
+ subFields?: Field[] | undefined;
161
+ /**
162
+ * - The object passed to InputLabelProps props
163
+ */
164
+ InputLabelProps?: InputLabelProps | undefined;
165
+ /**
166
+ * - Whether the field is multiline
167
+ */
168
+ multiline?: boolean | undefined;
169
+ /**
170
+ * - Position of a field in the form. 1 is first.
171
+ */
172
+ position?: number | undefined;
173
+ };
174
+ export type RelatedContact = {
175
+ /**
176
+ * - The id of the related contact
177
+ */
178
+ relatedContactId: string;
179
+ /**
180
+ * - The displayName of the related contact
181
+ */
182
+ relatedContact: string;
183
+ /**
184
+ * - Object with the type of the related contact stringified (e.g. '{\"type\":\"spouse\"}')
185
+ */
186
+ relatedContactLabel: string;
187
+ };
54
188
  import PropTypes from "prop-types";
@@ -1,5 +1,50 @@
1
1
  import PropTypes from 'prop-types';
2
2
  import { iconPropType } from "cozy-ui/transpiled/react/Icon";
3
+ /**
4
+ * @typedef {'text'|'tel'|'email'|'button'|'url'|'date'} FieldType
5
+ */
6
+
7
+ /**
8
+ * @typedef {Object} CustomLabelOptions
9
+ * @property {string} defaultType - The default type of the option
10
+ * @property {string} defaultLabel - The default label of the option
11
+ * @property {boolean} [hide] - Whether the radio choices is hidden
12
+ */
13
+
14
+ /**
15
+ * @typedef {Object} LabelField
16
+ * @property {string} name - The name of the label field
17
+ * @property {boolean} select - Whether the field is a select
18
+ * @property {CustomLabelOptions} customLabelOptions - The custom label field options
19
+ * @property {Option[]} options - The options of the label field
20
+ */
21
+
22
+ /**
23
+ * @typedef {Object} InputLabelProps
24
+ * @property {boolean} shrink - passed to InputLabelProps props
25
+ */
26
+
27
+ /**
28
+ * @typedef {Object} Field
29
+ * @property {string} name - The name of the field
30
+ * @property {string|null} icon - The icon of the field
31
+ * @property {FieldType} type - The type of the field
32
+ * @property {boolean} [isSecondary] - Whether the field is hidden from the main form
33
+ * @property {LabelField} [label] - Add a "label" field next to the main field
34
+ * @property {'accordion'|'array'} [layout] - Whether the field is an array (To add fields dynamically (e.g. email, address, etc.))
35
+ * @property {Field[]} [subFields] - The subfields of the field
36
+ * @property {InputLabelProps} [InputLabelProps] - The object passed to InputLabelProps props
37
+ * @property {boolean} [multiline] - Whether the field is multiline
38
+ * @property {number} [position] - Position of a field in the form. 1 is first.
39
+ */
40
+
41
+ /**
42
+ * @typedef {Object} RelatedContact
43
+ * @property {string} relatedContactId - The id of the related contact
44
+ * @property {string} relatedContact - The displayName of the related contact
45
+ * @property {string} relatedContactLabel - Object with the type of the related contact stringified (e.g. '{\"type\":\"spouse\"}')
46
+ */
47
+
3
48
  export var labelPropTypes = PropTypes.shape({
4
49
  name: PropTypes.string,
5
50
  options: PropTypes.arrayOf(PropTypes.shape({