cozy-ui 128.2.0 → 128.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/package.json +6 -2
- package/react/Contacts/AddModal/ContactAddressDialog/helpers.js +22 -0
- package/react/Contacts/AddModal/ContactAddressDialog/helpers.spec.js +64 -0
- package/react/Contacts/AddModal/ContactAddressDialog/index.jsx +84 -0
- package/react/Contacts/AddModal/ContactAddressDialog/locales/en.json +25 -0
- package/react/Contacts/AddModal/ContactAddressDialog/locales/fr.json +25 -0
- package/react/Contacts/AddModal/ContactAddressDialog/locales/index.jsx +7 -0
- package/react/Contacts/AddModal/ContactForm/FieldInput.jsx +117 -0
- package/react/Contacts/AddModal/ContactForm/FieldInputArray.jsx +80 -0
- package/react/Contacts/AddModal/ContactForm/FieldInputLayout.jsx +65 -0
- package/react/Contacts/AddModal/ContactForm/FieldInputWrapper.jsx +41 -0
- package/react/Contacts/AddModal/ContactForm/HasValueCondition.jsx +31 -0
- package/react/Contacts/AddModal/ContactForm/HasValueCondition.spec.jsx +79 -0
- package/react/Contacts/AddModal/ContactForm/RelatedContactList.jsx +37 -0
- package/react/Contacts/AddModal/ContactForm/TextFieldCustomLabelSelect.jsx +78 -0
- package/react/Contacts/AddModal/ContactForm/TextFieldSelect.jsx +39 -0
- package/react/Contacts/AddModal/ContactForm/__snapshots__/HasValueCondition.spec.jsx.snap +33 -0
- package/react/Contacts/AddModal/ContactForm/contactToFormValues.js +99 -0
- package/react/Contacts/AddModal/ContactForm/contactToFormValues.spec.js +128 -0
- package/react/Contacts/AddModal/ContactForm/fieldsConfig.jsx +341 -0
- package/react/Contacts/AddModal/ContactForm/formValuesToContact.js +100 -0
- package/react/Contacts/AddModal/ContactForm/formValuesToContact.spec.js +494 -0
- package/react/Contacts/AddModal/ContactForm/helpers.js +324 -0
- package/react/Contacts/AddModal/ContactForm/helpers.spec.js +152 -0
- package/react/Contacts/AddModal/ContactForm/index.jsx +104 -0
- package/react/Contacts/AddModal/ContactForm/index.spec.jsx +289 -0
- package/react/Contacts/AddModal/ContactForm/locales/en.json +73 -0
- package/react/Contacts/AddModal/ContactForm/locales/fr.json +73 -0
- package/react/Contacts/AddModal/ContactForm/locales/index.jsx +7 -0
- package/react/Contacts/AddModal/ContactForm/styles.styl +2 -0
- package/react/Contacts/AddModal/CustomLabelDialog/index.jsx +108 -0
- package/react/Contacts/AddModal/CustomLabelDialog/locales/en.json +15 -0
- package/react/Contacts/AddModal/CustomLabelDialog/locales/fr.json +15 -0
- package/react/Contacts/AddModal/CustomLabelDialog/locales/index.jsx +7 -0
- package/react/Contacts/AddModal/Readme.md +46 -0
- package/react/Contacts/AddModal/index.jsx +78 -0
- package/react/Contacts/AddModal/locales/en.json +13 -0
- package/react/Contacts/AddModal/locales/fr.json +13 -0
- package/react/Contacts/AddModal/locales/index.jsx +7 -0
- package/react/Contacts/AddModal/mocks.js +249 -0
- package/react/Contacts/AddModal/types.js +57 -0
- package/react/Contacts/Header/Readme.md +0 -2
- package/react/providers/DemoProvider.jsx +3 -2
- package/transpiled/react/Contacts/AddModal/ContactAddressDialog/helpers.d.ts +4 -0
- package/transpiled/react/Contacts/AddModal/ContactAddressDialog/helpers.js +20 -0
- package/transpiled/react/Contacts/AddModal/ContactAddressDialog/helpers.spec.d.ts +1 -0
- package/transpiled/react/Contacts/AddModal/ContactAddressDialog/index.d.ts +39 -0
- package/transpiled/react/Contacts/AddModal/ContactAddressDialog/index.js +87 -0
- package/transpiled/react/Contacts/AddModal/ContactAddressDialog/locales/index.d.ts +6 -0
- package/transpiled/react/Contacts/AddModal/ContactAddressDialog/locales/index.js +54 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInput.d.ts +35 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInput.js +126 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputArray.d.ts +14 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputArray.js +82 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputLayout.d.ts +20 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputLayout.js +70 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputWrapper.d.ts +16 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputWrapper.js +31 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/HasValueCondition.d.ts +18 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/HasValueCondition.js +32 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/HasValueCondition.spec.d.ts +1 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/RelatedContactList.d.ts +15 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/RelatedContactList.js +39 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/TextFieldCustomLabelSelect.d.ts +9 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/TextFieldCustomLabelSelect.js +81 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/TextFieldSelect.d.ts +5 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/TextFieldSelect.js +42 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/contactToFormValues.d.ts +2 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/contactToFormValues.js +88 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/contactToFormValues.spec.d.ts +1 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/fieldsConfig.d.ts +4 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/fieldsConfig.js +278 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/formValuesToContact.d.ts +6 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/formValuesToContact.js +94 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/formValuesToContact.spec.d.ts +1 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/helpers.d.ts +28 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/helpers.js +335 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/helpers.spec.d.ts +1 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/index.d.ts +11 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/index.js +114 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/index.spec.d.ts +1 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/locales/index.d.ts +6 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/locales/index.js +150 -0
- package/transpiled/react/Contacts/AddModal/CustomLabelDialog/index.d.ts +22 -0
- package/transpiled/react/Contacts/AddModal/CustomLabelDialog/index.js +113 -0
- package/transpiled/react/Contacts/AddModal/CustomLabelDialog/locales/index.d.ts +6 -0
- package/transpiled/react/Contacts/AddModal/CustomLabelDialog/locales/index.js +34 -0
- package/transpiled/react/Contacts/AddModal/index.d.ts +7 -0
- package/transpiled/react/Contacts/AddModal/index.js +109 -0
- package/transpiled/react/Contacts/AddModal/locales/index.d.ts +6 -0
- package/transpiled/react/Contacts/AddModal/locales/index.js +30 -0
- package/transpiled/react/Contacts/AddModal/mocks.d.ts +270 -0
- package/transpiled/react/Contacts/AddModal/mocks.js +214 -0
- package/transpiled/react/Contacts/AddModal/types.d.ts +54 -0
- package/transpiled/react/Contacts/AddModal/types.js +49 -0
- package/transpiled/react/providers/DemoProvider.d.ts +2 -1
- package/transpiled/react/providers/DemoProvider.js +7 -3
- package/transpiled/react/stylesheet.css +1 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import React, { useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import ContactForm, { getSubmitContactForm } from './ContactForm'
|
|
4
|
+
import { locales } from './locales'
|
|
5
|
+
import Button from '../../Buttons'
|
|
6
|
+
import { FixedDialog } from '../../CozyDialogs'
|
|
7
|
+
import { useAlert } from '../../providers/Alert'
|
|
8
|
+
import { useI18n, useExtendI18n } from '../../providers/I18n'
|
|
9
|
+
|
|
10
|
+
const AddModal = ({ contacts, contact, onSubmit, onClose }) => {
|
|
11
|
+
useExtendI18n(locales)
|
|
12
|
+
const { t } = useI18n()
|
|
13
|
+
const { showAlert } = useAlert()
|
|
14
|
+
const [isBusy, setIsBusy] = useState(false)
|
|
15
|
+
// Tip to prevent fields from being filled with old information for a short period of time during form submission.
|
|
16
|
+
const [selfContact, setSelfContact] = useState(contact)
|
|
17
|
+
|
|
18
|
+
const handleClick = event => {
|
|
19
|
+
const submitContactForm = getSubmitContactForm()
|
|
20
|
+
submitContactForm(event)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {import('cozy-client/types/types').IOCozyContact} formData - Contact document (except _id, _rev & _type attrs to create a new contact)
|
|
25
|
+
*/
|
|
26
|
+
const handleFormSubmit = async formData => {
|
|
27
|
+
setSelfContact(formData)
|
|
28
|
+
setIsBusy(true)
|
|
29
|
+
try {
|
|
30
|
+
await onSubmit(formData)
|
|
31
|
+
onClose()
|
|
32
|
+
} catch (err) {
|
|
33
|
+
setIsBusy(false)
|
|
34
|
+
console.warn(err) // eslint-disable-line no-console
|
|
35
|
+
showAlert({
|
|
36
|
+
severity: 'error',
|
|
37
|
+
message: t('Contacts.AddModal.error.save')
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<FixedDialog
|
|
44
|
+
open
|
|
45
|
+
onClose={onClose}
|
|
46
|
+
title={
|
|
47
|
+
contact
|
|
48
|
+
? t('Contacts.AddModal.edit-contact')
|
|
49
|
+
: t('Contacts.AddModal.create_contact')
|
|
50
|
+
}
|
|
51
|
+
content={
|
|
52
|
+
<ContactForm
|
|
53
|
+
contacts={contacts}
|
|
54
|
+
contact={selfContact}
|
|
55
|
+
onSubmit={handleFormSubmit}
|
|
56
|
+
/>
|
|
57
|
+
}
|
|
58
|
+
actions={
|
|
59
|
+
<>
|
|
60
|
+
<Button
|
|
61
|
+
variant="secondary"
|
|
62
|
+
label={t('Contacts.AddModal.cancel')}
|
|
63
|
+
onClick={onClose}
|
|
64
|
+
/>
|
|
65
|
+
<Button
|
|
66
|
+
className="u-ml-half"
|
|
67
|
+
type="submit"
|
|
68
|
+
label={t('Contacts.AddModal.save')}
|
|
69
|
+
busy={isBusy}
|
|
70
|
+
onClick={handleClick}
|
|
71
|
+
/>
|
|
72
|
+
</>
|
|
73
|
+
}
|
|
74
|
+
/>
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export default AddModal
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Contacts": {
|
|
3
|
+
"AddModal": {
|
|
4
|
+
"error": {
|
|
5
|
+
"save": "Une erreur est survenue lors de l'enregistrement du contact, veuillez réessayer"
|
|
6
|
+
},
|
|
7
|
+
"edit-contact": "Edit contact",
|
|
8
|
+
"create_contact": "Créer un contact",
|
|
9
|
+
"cancel": "Annuler",
|
|
10
|
+
"save": "Enregistrer"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
export const johnDoeContact = {
|
|
2
|
+
id: '9ecfbf4b-20e7-4bac-87f1-eea53350857d',
|
|
3
|
+
_id: '9ecfbf4b-20e7-4bac-87f1-eea53350857d',
|
|
4
|
+
_type: 'io.cozy.contacts',
|
|
5
|
+
_rev: '1-19c313536e8b27473aa26bf105b03269',
|
|
6
|
+
address: [
|
|
7
|
+
{
|
|
8
|
+
formattedAddress: '94 Hinton Road 05034 Fresno, Singapore',
|
|
9
|
+
type: 'Home',
|
|
10
|
+
primary: true
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
pobox: '2',
|
|
14
|
+
street: '426 Runolfsson Knolls',
|
|
15
|
+
city: 'Port Easter',
|
|
16
|
+
region: undefined,
|
|
17
|
+
country: 'Cocos (Keeling) Islands',
|
|
18
|
+
postcode: '84573',
|
|
19
|
+
type: 'Work'
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
email: [
|
|
23
|
+
{
|
|
24
|
+
address: 'john.doe@posteo.net',
|
|
25
|
+
type: 'personal',
|
|
26
|
+
primary: false
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
address: 'john.doe@cozycloud.cc',
|
|
30
|
+
primary: true
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
birthday: '1999-5-1',
|
|
34
|
+
birthplace: 'somewhere',
|
|
35
|
+
gender: 'male',
|
|
36
|
+
company: 'Cozy cloud',
|
|
37
|
+
jobTitle: 'Dreamer',
|
|
38
|
+
cozy: [
|
|
39
|
+
{
|
|
40
|
+
type: 'MyCozy',
|
|
41
|
+
primary: true,
|
|
42
|
+
url: 'https://johndoe.mycozy.cloud'
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
fullname: 'John Doe',
|
|
46
|
+
name: {
|
|
47
|
+
givenName: 'John',
|
|
48
|
+
familyName: 'Doe',
|
|
49
|
+
additionalName: 'J.'
|
|
50
|
+
},
|
|
51
|
+
metadata: {
|
|
52
|
+
cozy: true,
|
|
53
|
+
version: 1
|
|
54
|
+
},
|
|
55
|
+
note: 'Atque cupiditate saepe omnis quos ut molestiae labore voluptates omnis.',
|
|
56
|
+
phone: [
|
|
57
|
+
{
|
|
58
|
+
number: '+33 (2)0 90 00 54 04',
|
|
59
|
+
primary: true
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
number: '+33 6 77 11 22 33',
|
|
63
|
+
primary: false
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export const johnDoeFormValues = {
|
|
69
|
+
birthday: '1999-5-1',
|
|
70
|
+
birthplace: 'somewhere',
|
|
71
|
+
gender: 'male',
|
|
72
|
+
cozy: 'https://johndoe.mycozy.cloud',
|
|
73
|
+
cozyLabel: '{"type":"MyCozy"}',
|
|
74
|
+
address: [
|
|
75
|
+
{
|
|
76
|
+
fieldId: 'fieldId_1',
|
|
77
|
+
address: '94 Hinton Road 05034 Fresno, Singapore',
|
|
78
|
+
addressLabel: '{"type":"Home"}',
|
|
79
|
+
addressapartment: undefined,
|
|
80
|
+
addressbuilding: undefined,
|
|
81
|
+
addresscity: undefined,
|
|
82
|
+
addresscode: undefined,
|
|
83
|
+
addressregion: undefined,
|
|
84
|
+
addresscountry: undefined,
|
|
85
|
+
addressentrycode: undefined,
|
|
86
|
+
addressfloor: undefined,
|
|
87
|
+
addresslocality: undefined,
|
|
88
|
+
addressnumber: undefined,
|
|
89
|
+
addressstairs: undefined,
|
|
90
|
+
addressstreet: '94 Hinton Road 05034 Fresno, Singapore'
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
fieldId: 'fieldId_2',
|
|
94
|
+
address:
|
|
95
|
+
'426 Runolfsson Knolls 84573 Port Easter Cocos (Keeling) Islands',
|
|
96
|
+
addressLabel: '{"type":"Work"}',
|
|
97
|
+
addressapartment: undefined,
|
|
98
|
+
addressbuilding: undefined,
|
|
99
|
+
addresscity: 'Port Easter',
|
|
100
|
+
addressregion: undefined,
|
|
101
|
+
addresscode: '84573',
|
|
102
|
+
addresscountry: 'Cocos (Keeling) Islands',
|
|
103
|
+
addressentrycode: undefined,
|
|
104
|
+
addressfloor: undefined,
|
|
105
|
+
addresslocality: undefined,
|
|
106
|
+
addressnumber: undefined,
|
|
107
|
+
addressstairs: undefined,
|
|
108
|
+
addressstreet: '426 Runolfsson Knolls'
|
|
109
|
+
}
|
|
110
|
+
],
|
|
111
|
+
email: [
|
|
112
|
+
{
|
|
113
|
+
fieldId: 'fieldId_3',
|
|
114
|
+
email: 'john.doe@cozycloud.cc',
|
|
115
|
+
emailLabel: undefined
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
fieldId: 'fieldId_4',
|
|
119
|
+
email: 'john.doe@posteo.net',
|
|
120
|
+
emailLabel: '{"type":"personal"}'
|
|
121
|
+
}
|
|
122
|
+
],
|
|
123
|
+
phone: [
|
|
124
|
+
{
|
|
125
|
+
fieldId: 'fieldId_5',
|
|
126
|
+
phone: '+33 (2)0 90 00 54 04',
|
|
127
|
+
phoneLabel: undefined
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
fieldId: 'fieldId_6',
|
|
131
|
+
phone: '+33 6 77 11 22 33',
|
|
132
|
+
phoneLabel: undefined
|
|
133
|
+
}
|
|
134
|
+
],
|
|
135
|
+
givenName: 'John',
|
|
136
|
+
additionalName: 'J.',
|
|
137
|
+
familyName: 'Doe',
|
|
138
|
+
company: 'Cozy cloud',
|
|
139
|
+
jobTitle: 'Dreamer',
|
|
140
|
+
note: 'Atque cupiditate saepe omnis quos ut molestiae labore voluptates omnis.',
|
|
141
|
+
relatedContact: [
|
|
142
|
+
{
|
|
143
|
+
relatedContactId: 'relatedContactID',
|
|
144
|
+
relatedContactLabel: '{"type":"related"}'
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export const johnDoeContactWithRelated = {
|
|
150
|
+
id: '9ecfbf4b-20e7-4bac-87f1-eea53350857d',
|
|
151
|
+
_id: '9ecfbf4b-20e7-4bac-87f1-eea53350857d',
|
|
152
|
+
_type: 'io.cozy.contacts',
|
|
153
|
+
_rev: '1-19c313536e8b27473aa26bf105b03269',
|
|
154
|
+
address: [
|
|
155
|
+
{
|
|
156
|
+
formattedAddress: '94 Hinton Road 05034 Fresno, Singapore',
|
|
157
|
+
type: 'Home',
|
|
158
|
+
primary: true
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
pobox: '2',
|
|
162
|
+
street: '426 Runolfsson Knolls',
|
|
163
|
+
city: 'Port Easter',
|
|
164
|
+
region: undefined,
|
|
165
|
+
country: 'Cocos (Keeling) Islands',
|
|
166
|
+
postcode: '84573',
|
|
167
|
+
type: 'Work'
|
|
168
|
+
}
|
|
169
|
+
],
|
|
170
|
+
email: [
|
|
171
|
+
{
|
|
172
|
+
address: 'john.doe@posteo.net',
|
|
173
|
+
type: 'personal',
|
|
174
|
+
primary: false
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
address: 'john.doe@cozycloud.cc',
|
|
178
|
+
primary: true
|
|
179
|
+
}
|
|
180
|
+
],
|
|
181
|
+
birthday: '1999-5-1',
|
|
182
|
+
birthplace: 'somewhere',
|
|
183
|
+
gender: 'male',
|
|
184
|
+
company: 'Cozy cloud',
|
|
185
|
+
jobTitle: 'Dreamer',
|
|
186
|
+
cozy: [
|
|
187
|
+
{
|
|
188
|
+
type: 'MyCozy',
|
|
189
|
+
primary: true,
|
|
190
|
+
url: 'https://johndoe.mycozy.cloud'
|
|
191
|
+
}
|
|
192
|
+
],
|
|
193
|
+
fullname: 'John Doe',
|
|
194
|
+
name: {
|
|
195
|
+
givenName: 'John',
|
|
196
|
+
familyName: 'Doe',
|
|
197
|
+
additionalName: 'J.'
|
|
198
|
+
},
|
|
199
|
+
metadata: {
|
|
200
|
+
cozy: true,
|
|
201
|
+
version: 1
|
|
202
|
+
},
|
|
203
|
+
note: 'Atque cupiditate saepe omnis quos ut molestiae labore voluptates omnis.',
|
|
204
|
+
phone: [
|
|
205
|
+
{
|
|
206
|
+
number: '+33 (2)0 90 00 54 04',
|
|
207
|
+
primary: true
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
number: '+33 6 77 11 22 33',
|
|
211
|
+
primary: false
|
|
212
|
+
}
|
|
213
|
+
],
|
|
214
|
+
|
|
215
|
+
relationships: {
|
|
216
|
+
accounts: { data: [] },
|
|
217
|
+
groups: { data: [] },
|
|
218
|
+
related: {
|
|
219
|
+
data: [
|
|
220
|
+
{
|
|
221
|
+
metadata: { relationTypes: ['spouse'] },
|
|
222
|
+
_id: '5b49553c5916cf7b5b2a5f48600078a8',
|
|
223
|
+
_type: 'io.cozy.contacts'
|
|
224
|
+
}
|
|
225
|
+
]
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
related: {
|
|
229
|
+
target: {
|
|
230
|
+
id: '4e33fd27e1d8e55a34742bac6d16d3bd',
|
|
231
|
+
_id: '4e33fd27e1d8e55a34742bac6d16d3bd',
|
|
232
|
+
_type: 'io.cozy.contacts',
|
|
233
|
+
_rev: '6-57f4ab78b1fb97bb90ea273ec881f196',
|
|
234
|
+
company: '',
|
|
235
|
+
fullname: 'John Doe',
|
|
236
|
+
me: true,
|
|
237
|
+
note: ''
|
|
238
|
+
},
|
|
239
|
+
name: 'related',
|
|
240
|
+
doctype: 'io.cozy.contacts',
|
|
241
|
+
data: [
|
|
242
|
+
{
|
|
243
|
+
displayName: 'Alice Doe',
|
|
244
|
+
_id: '5b49553c5916cf7b5b2a5f48600078a8',
|
|
245
|
+
_type: 'io.cozy.contacts'
|
|
246
|
+
}
|
|
247
|
+
]
|
|
248
|
+
}
|
|
249
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import PropTypes from 'prop-types'
|
|
2
|
+
|
|
3
|
+
import { iconPropType } from '../../Icon'
|
|
4
|
+
|
|
5
|
+
export const labelPropTypes = PropTypes.shape({
|
|
6
|
+
name: PropTypes.string,
|
|
7
|
+
options: PropTypes.arrayOf(
|
|
8
|
+
PropTypes.shape({
|
|
9
|
+
value: PropTypes.string,
|
|
10
|
+
label: PropTypes.string
|
|
11
|
+
})
|
|
12
|
+
),
|
|
13
|
+
customLabelOptions: PropTypes.shape({
|
|
14
|
+
hide: PropTypes.bool,
|
|
15
|
+
defaultType: PropTypes.string,
|
|
16
|
+
defaultLabel: PropTypes.string
|
|
17
|
+
})
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
export const fieldInputAttributesTypes = PropTypes.shape({
|
|
21
|
+
name: PropTypes.string,
|
|
22
|
+
icon: iconPropType,
|
|
23
|
+
type: PropTypes.string,
|
|
24
|
+
label: labelPropTypes,
|
|
25
|
+
isArray: PropTypes.bool,
|
|
26
|
+
subFields: PropTypes.arrayOf(
|
|
27
|
+
PropTypes.shape({
|
|
28
|
+
name: PropTypes.string.isRequired,
|
|
29
|
+
icon: PropTypes.string,
|
|
30
|
+
type: PropTypes.string.isRequired
|
|
31
|
+
})
|
|
32
|
+
),
|
|
33
|
+
labelProps: PropTypes.shape({
|
|
34
|
+
shrink: PropTypes.bool
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
export const FieldInputWrapperPropTypes = {
|
|
39
|
+
// See official documentation for more information: https://final-form.org/docs/react-final-form/types/FieldRenderProps
|
|
40
|
+
input: PropTypes.object,
|
|
41
|
+
//
|
|
42
|
+
attributes: fieldInputAttributesTypes,
|
|
43
|
+
// Destructuring props
|
|
44
|
+
// See official documentation for more information: https://final-form.org/docs/react-final-form/types/FieldRenderProps
|
|
45
|
+
meta: PropTypes.object,
|
|
46
|
+
//
|
|
47
|
+
id: PropTypes.string,
|
|
48
|
+
label: PropTypes.string,
|
|
49
|
+
required: PropTypes.bool,
|
|
50
|
+
variant: PropTypes.string,
|
|
51
|
+
customLabelOptions: PropTypes.shape({
|
|
52
|
+
hide: PropTypes.bool,
|
|
53
|
+
defaultType: PropTypes.string.isRequired,
|
|
54
|
+
defaultLabel: PropTypes.string.isRequired
|
|
55
|
+
}),
|
|
56
|
+
fullWidth: PropTypes.bool
|
|
57
|
+
}
|
|
@@ -22,13 +22,14 @@ const defaultClient = {
|
|
|
22
22
|
})
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
const DemoProvider = ({ client, variant, children }) => {
|
|
25
|
+
const DemoProvider = ({ client, variant, dictRequire, children }) => {
|
|
26
26
|
const lang = localStorage.getItem('lang') || 'en'
|
|
27
|
+
const _dictRequire = dictRequire ? dictRequire : () => ({})
|
|
27
28
|
|
|
28
29
|
return (
|
|
29
30
|
<CozyProvider client={client || defaultClient}>
|
|
30
31
|
<BreakpointsProvider>
|
|
31
|
-
<I18n lang={lang} dictRequire={
|
|
32
|
+
<I18n lang={lang} dictRequire={_dictRequire}>
|
|
32
33
|
<CozyTheme variant={variant}>{children}</CozyTheme>
|
|
33
34
|
</I18n>
|
|
34
35
|
</BreakpointsProvider>
|
|
@@ -0,0 +1,20 @@
|
|
|
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 { cleanFormattedAddress } from 'cozy-client/dist/models/contact';
|
|
8
|
+
/**
|
|
9
|
+
* Make formatted address
|
|
10
|
+
* @param {{ name: string, value: string }[]} subFieldsState - State of address sub fields
|
|
11
|
+
* @returns {string} - Formatted address
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export var makeFormattedAddressWithSubFields = function makeFormattedAddressWithSubFields(subFieldsState, t) {
|
|
15
|
+
var normalizedAddress = subFieldsState.reduce(function (acc, curr) {
|
|
16
|
+
var key = curr.name.split('.').pop().replace(/address/, '');
|
|
17
|
+
return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, key, curr.value || ''));
|
|
18
|
+
}, {});
|
|
19
|
+
return cleanFormattedAddress(t('formatted.address', normalizedAddress));
|
|
20
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export default ContactAddressModal;
|
|
2
|
+
declare function ContactAddressModal({ onClose, name, subFields }: {
|
|
3
|
+
onClose: any;
|
|
4
|
+
name: any;
|
|
5
|
+
subFields: any;
|
|
6
|
+
}): JSX.Element;
|
|
7
|
+
declare namespace ContactAddressModal {
|
|
8
|
+
namespace propTypes {
|
|
9
|
+
const onClose: PropTypes.Validator<(...args: any[]) => any>;
|
|
10
|
+
const name: PropTypes.Validator<string>;
|
|
11
|
+
const subFields: PropTypes.Validator<(PropTypes.InferProps<{
|
|
12
|
+
name: PropTypes.Requireable<string>;
|
|
13
|
+
icon: PropTypes.Requireable<string | object>;
|
|
14
|
+
type: PropTypes.Requireable<string>;
|
|
15
|
+
label: PropTypes.Requireable<PropTypes.InferProps<{
|
|
16
|
+
name: PropTypes.Requireable<string>;
|
|
17
|
+
options: PropTypes.Requireable<(PropTypes.InferProps<{
|
|
18
|
+
value: PropTypes.Requireable<string>;
|
|
19
|
+
label: PropTypes.Requireable<string>;
|
|
20
|
+
}> | null)[]>;
|
|
21
|
+
customLabelOptions: PropTypes.Requireable<PropTypes.InferProps<{
|
|
22
|
+
hide: PropTypes.Requireable<boolean>;
|
|
23
|
+
defaultType: PropTypes.Requireable<string>;
|
|
24
|
+
defaultLabel: PropTypes.Requireable<string>;
|
|
25
|
+
}>>;
|
|
26
|
+
}>>;
|
|
27
|
+
isArray: PropTypes.Requireable<boolean>;
|
|
28
|
+
subFields: PropTypes.Requireable<(PropTypes.InferProps<{
|
|
29
|
+
name: PropTypes.Validator<string>;
|
|
30
|
+
icon: PropTypes.Requireable<string>;
|
|
31
|
+
type: PropTypes.Validator<string>;
|
|
32
|
+
}> | null)[]>;
|
|
33
|
+
labelProps: PropTypes.Requireable<PropTypes.InferProps<{
|
|
34
|
+
shrink: PropTypes.Requireable<boolean>;
|
|
35
|
+
}>>;
|
|
36
|
+
}> | null)[]>;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
import PropTypes from "prop-types";
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Field, useForm } from 'react-final-form';
|
|
4
|
+
import { makeFormattedAddressWithSubFields } from "cozy-ui/transpiled/react/Contacts/AddModal/ContactAddressDialog/helpers";
|
|
5
|
+
import { locales } from "cozy-ui/transpiled/react/Contacts/AddModal/ContactAddressDialog/locales";
|
|
6
|
+
import Button from "cozy-ui/transpiled/react/Buttons";
|
|
7
|
+
import { FixedDialog } from "cozy-ui/transpiled/react/CozyDialogs";
|
|
8
|
+
import { useI18n, useExtendI18n } from "cozy-ui/transpiled/react/providers/I18n";
|
|
9
|
+
import FieldInputWrapper from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/FieldInputWrapper";
|
|
10
|
+
import { fieldInputAttributesTypes } from "cozy-ui/transpiled/react/Contacts/AddModal/types";
|
|
11
|
+
|
|
12
|
+
var ContactAddressModal = function ContactAddressModal(_ref) {
|
|
13
|
+
var onClose = _ref.onClose,
|
|
14
|
+
name = _ref.name,
|
|
15
|
+
subFields = _ref.subFields;
|
|
16
|
+
useExtendI18n(locales);
|
|
17
|
+
|
|
18
|
+
var _useI18n = useI18n(),
|
|
19
|
+
t = _useI18n.t;
|
|
20
|
+
|
|
21
|
+
var _useForm = useForm(),
|
|
22
|
+
getFieldState = _useForm.getFieldState,
|
|
23
|
+
change = _useForm.change;
|
|
24
|
+
|
|
25
|
+
var subFieldsState = subFields.map(function (subField) {
|
|
26
|
+
return getFieldState("".concat(name).concat(subField.name));
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
var onConfirm = function onConfirm() {
|
|
30
|
+
var hasBeenModified = subFieldsState.some(function (state) {
|
|
31
|
+
return !state.pristine;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
if (!hasBeenModified) {
|
|
35
|
+
return onClose();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
var formattedAddress = makeFormattedAddressWithSubFields(subFieldsState, t);
|
|
39
|
+
change(name, formattedAddress);
|
|
40
|
+
onClose();
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
var onCancel = function onCancel() {
|
|
44
|
+
subFieldsState.forEach(function (_ref2) {
|
|
45
|
+
var name = _ref2.name,
|
|
46
|
+
initial = _ref2.initial;
|
|
47
|
+
return change(name, initial);
|
|
48
|
+
});
|
|
49
|
+
onClose();
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
return /*#__PURE__*/React.createElement(FixedDialog, {
|
|
53
|
+
open: true,
|
|
54
|
+
onClose: onClose,
|
|
55
|
+
size: "small",
|
|
56
|
+
title: t('Contacts.AddModal.ContactAddressDialog.fields.address'),
|
|
57
|
+
content: subFields.map(function (subField) {
|
|
58
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
59
|
+
key: subField.name,
|
|
60
|
+
className: "u-mt-1"
|
|
61
|
+
}, /*#__PURE__*/React.createElement(Field, {
|
|
62
|
+
label: t("Contacts.AddModal.ContactAddressDialog.fields.".concat(subField.name)),
|
|
63
|
+
attributes: {
|
|
64
|
+
type: subField.type
|
|
65
|
+
},
|
|
66
|
+
name: "".concat(name).concat(subField.name),
|
|
67
|
+
component: FieldInputWrapper
|
|
68
|
+
}));
|
|
69
|
+
}),
|
|
70
|
+
actions: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, {
|
|
71
|
+
variant: "secondary",
|
|
72
|
+
label: t('Contacts.AddModal.ContactAddressDialog.cancel'),
|
|
73
|
+
onClick: onCancel
|
|
74
|
+
}), /*#__PURE__*/React.createElement(Button, {
|
|
75
|
+
className: "u-ml-half",
|
|
76
|
+
label: t('Contacts.AddModal.ContactAddressDialog.ok'),
|
|
77
|
+
onClick: onConfirm
|
|
78
|
+
}))
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
ContactAddressModal.propTypes = {
|
|
83
|
+
onClose: PropTypes.func.isRequired,
|
|
84
|
+
name: PropTypes.string.isRequired,
|
|
85
|
+
subFields: PropTypes.arrayOf(fieldInputAttributesTypes).isRequired
|
|
86
|
+
};
|
|
87
|
+
export default ContactAddressModal;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
var en = {
|
|
2
|
+
Contacts: {
|
|
3
|
+
AddModal: {
|
|
4
|
+
ContactAddressDialog: {
|
|
5
|
+
fields: {
|
|
6
|
+
address: "Address",
|
|
7
|
+
number: "Lane number",
|
|
8
|
+
street: "Postal address",
|
|
9
|
+
code: "Postal code",
|
|
10
|
+
city: "City",
|
|
11
|
+
country: "Country",
|
|
12
|
+
locality: "Locality",
|
|
13
|
+
building: "Building",
|
|
14
|
+
stairs: "Stairs",
|
|
15
|
+
floor: "Floor",
|
|
16
|
+
apartment: "Apartment",
|
|
17
|
+
region: "Region",
|
|
18
|
+
entrycode: "Entry code"
|
|
19
|
+
},
|
|
20
|
+
cancel: "Cancel",
|
|
21
|
+
ok: "Ok"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var fr = {
|
|
27
|
+
Contacts: {
|
|
28
|
+
AddModal: {
|
|
29
|
+
ContactAddressDialog: {
|
|
30
|
+
fields: {
|
|
31
|
+
address: "Adresse",
|
|
32
|
+
number: "Num\xE9ro de voie",
|
|
33
|
+
street: "Adresse postal",
|
|
34
|
+
code: "Code postal",
|
|
35
|
+
city: "Ville",
|
|
36
|
+
country: "Pays",
|
|
37
|
+
locality: "Lieu-dit",
|
|
38
|
+
building: "B\xE2timent",
|
|
39
|
+
stairs: "Escalier",
|
|
40
|
+
floor: "Etage",
|
|
41
|
+
apartment: "Appartement",
|
|
42
|
+
region: "R\xE9gion",
|
|
43
|
+
entrycode: "Code d'entr\xE9e"
|
|
44
|
+
},
|
|
45
|
+
cancel: "Annuler",
|
|
46
|
+
ok: "Ok"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
export var locales = {
|
|
52
|
+
en: en,
|
|
53
|
+
fr: fr
|
|
54
|
+
};
|