cozy-ui 128.1.0 → 128.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/package.json +5 -1
- package/react/ActionsMenu/Actions/viewInDrive.js +2 -1
- 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/ActionsMenu/Actions/viewInDrive.js +2 -1
- 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,289 @@
|
|
|
1
|
+
import { render, screen, fireEvent, act } from '@testing-library/react'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
import ContactForm, { isSameContactProp } from './index'
|
|
5
|
+
import DemoProvider from '../../../providers/DemoProvider'
|
|
6
|
+
import { johnDoeContact as contact } from '../mocks'
|
|
7
|
+
|
|
8
|
+
const dictRequire = lang => require(`../ContactAddressDialog/locales/${lang}`)
|
|
9
|
+
|
|
10
|
+
const setup = ({ contact }) => {
|
|
11
|
+
return {
|
|
12
|
+
contact,
|
|
13
|
+
onSubmit: () => jest.fn(),
|
|
14
|
+
onCancel: () => jest.fn()
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const labels = [
|
|
19
|
+
'Firstname',
|
|
20
|
+
'Lastname',
|
|
21
|
+
'Phone',
|
|
22
|
+
'Email',
|
|
23
|
+
'Address',
|
|
24
|
+
'Twake URL',
|
|
25
|
+
'Company',
|
|
26
|
+
'Job title',
|
|
27
|
+
'Birthday',
|
|
28
|
+
'Notes'
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
describe('ContactForm', () => {
|
|
32
|
+
it(`should contains ${labels.length} fields and labels`, () => {
|
|
33
|
+
const props = setup({ contact: {} })
|
|
34
|
+
const jsx = (
|
|
35
|
+
<DemoProvider>
|
|
36
|
+
<ContactForm {...props} />
|
|
37
|
+
</DemoProvider>
|
|
38
|
+
)
|
|
39
|
+
render(jsx)
|
|
40
|
+
for (const label of labels) {
|
|
41
|
+
expect(screen.queryByLabelText(label)).not.toBeNull()
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('should fill form with contact data', () => {
|
|
46
|
+
const props = setup({ contact })
|
|
47
|
+
const jsx = (
|
|
48
|
+
<DemoProvider>
|
|
49
|
+
<ContactForm {...props} />
|
|
50
|
+
</DemoProvider>
|
|
51
|
+
)
|
|
52
|
+
render(jsx)
|
|
53
|
+
expect(screen.queryByDisplayValue(contact.name.givenName)).not.toBeNull()
|
|
54
|
+
expect(screen.queryByDisplayValue(contact.name.familyName)).not.toBeNull()
|
|
55
|
+
expect(screen.queryByDisplayValue(contact.phone[0].number)).not.toBeNull()
|
|
56
|
+
expect(screen.queryByDisplayValue(contact.email[0].address)).not.toBeNull()
|
|
57
|
+
expect(
|
|
58
|
+
screen.queryByDisplayValue(contact.address[0].formattedAddress)
|
|
59
|
+
).not.toBeNull()
|
|
60
|
+
expect(screen.queryByDisplayValue(contact.cozy[0].url)).not.toBeNull()
|
|
61
|
+
expect(screen.queryByDisplayValue(contact.company)).not.toBeNull()
|
|
62
|
+
expect(screen.queryByDisplayValue(contact.jobTitle)).not.toBeNull()
|
|
63
|
+
expect(screen.queryByDisplayValue(contact.note)).not.toBeNull()
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('should submit a well formatted contact', () => {
|
|
67
|
+
const expected = {
|
|
68
|
+
address: [
|
|
69
|
+
{
|
|
70
|
+
city: undefined,
|
|
71
|
+
code: undefined,
|
|
72
|
+
country: undefined,
|
|
73
|
+
region: undefined,
|
|
74
|
+
formattedAddress: '18 rue des fleurs, Pecado',
|
|
75
|
+
number: undefined,
|
|
76
|
+
primary: true,
|
|
77
|
+
street: '18 rue des fleurs, Pecado',
|
|
78
|
+
type: undefined
|
|
79
|
+
}
|
|
80
|
+
],
|
|
81
|
+
birthday: '2015-12-31',
|
|
82
|
+
birthplace: 'somewhere',
|
|
83
|
+
gender: 'male',
|
|
84
|
+
company: 'Cozy CLoud',
|
|
85
|
+
cozy: [
|
|
86
|
+
{ label: undefined, primary: true, url: 'https://jcvd.cozy.cloud' }
|
|
87
|
+
],
|
|
88
|
+
displayName: 'Jean-Claude Van Cozy',
|
|
89
|
+
email: [{ address: 'jcvc@cozy.cloud', primary: true, type: undefined }],
|
|
90
|
+
fullname: 'Jean-Claude Van Cozy',
|
|
91
|
+
indexes: {
|
|
92
|
+
byFamilyNameGivenNameEmailCozyUrl:
|
|
93
|
+
'van cozyjean-claudejcvc@cozy.cloudjcvd.cozy.cloud'
|
|
94
|
+
},
|
|
95
|
+
jobTitle: 'Dreamer',
|
|
96
|
+
metadata: { cozy: true, version: 1 },
|
|
97
|
+
name: {
|
|
98
|
+
familyName: 'Van Cozy',
|
|
99
|
+
givenName: 'Jean-Claude',
|
|
100
|
+
additionalName: undefined,
|
|
101
|
+
surname: undefined
|
|
102
|
+
},
|
|
103
|
+
note: 'Whatever.',
|
|
104
|
+
phone: [{ number: '+33678987654', primary: true, type: undefined }],
|
|
105
|
+
relationships: { groups: { data: [] }, related: { data: [] } }
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let received = null
|
|
109
|
+
const onSubmit = contact => {
|
|
110
|
+
received = contact
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
render(
|
|
114
|
+
<DemoProvider dictRequire={dictRequire}>
|
|
115
|
+
<ContactForm onSubmit={onSubmit} onCancel={() => {}} />
|
|
116
|
+
</DemoProvider>
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
const fields = {
|
|
120
|
+
gender: 'male',
|
|
121
|
+
givenName: 'Jean-Claude',
|
|
122
|
+
familyName: 'Van Cozy',
|
|
123
|
+
surname: '',
|
|
124
|
+
additionalName: '',
|
|
125
|
+
'phone[0].phone': '+33678987654',
|
|
126
|
+
'email[0].email': 'jcvc@cozy.cloud',
|
|
127
|
+
cozy: 'https://jcvd.cozy.cloud',
|
|
128
|
+
company: 'Cozy CLoud',
|
|
129
|
+
jobTitle: 'Dreamer',
|
|
130
|
+
birthday: '2015-12-31',
|
|
131
|
+
birthplace: 'somewhere',
|
|
132
|
+
note: 'Whatever.'
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const form = screen.getByRole('form')
|
|
136
|
+
for (const fieldName of Object.keys(fields)) {
|
|
137
|
+
act(() => {
|
|
138
|
+
const field = form.querySelector(`[name='${fieldName}']`)
|
|
139
|
+
expect(field).not.toBeNull()
|
|
140
|
+
fireEvent.change(field, { target: { value: fields[fieldName] } })
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const addressBtn = form.querySelector('[name="address[0].address"]')
|
|
145
|
+
fireEvent.click(addressBtn)
|
|
146
|
+
|
|
147
|
+
const addressStreet = screen
|
|
148
|
+
.getAllByRole('textbox')
|
|
149
|
+
.find(t => t.name == 'address[0].addressstreet')
|
|
150
|
+
|
|
151
|
+
act(() => {
|
|
152
|
+
fireEvent.change(addressStreet, {
|
|
153
|
+
target: { value: '18 rue des fleurs, Pecado' }
|
|
154
|
+
})
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
act(() => {
|
|
158
|
+
fireEvent.click(screen.getByText('Ok'))
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
act(() => {
|
|
162
|
+
fireEvent.submit(screen.getByRole('form'))
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
expect(received).toEqual(expected)
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
it('should change inputs value', () => {
|
|
169
|
+
const testFields = {
|
|
170
|
+
Firstname: 'Jean-Claude',
|
|
171
|
+
Lastname: 'Van Cozy',
|
|
172
|
+
Phone: '+33678987654',
|
|
173
|
+
Email: 'jcvc@cozy.cloud',
|
|
174
|
+
Address: '18 rue des fleurs, Pecado',
|
|
175
|
+
'Twake URL': 'https://jcvd.cozy.cloud',
|
|
176
|
+
Company: 'Cozy CLoud',
|
|
177
|
+
jobTitle: 'Dreamer',
|
|
178
|
+
Birthday: '31/12/2015',
|
|
179
|
+
Notes: 'Whatever.'
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const props = setup({ contact: {} })
|
|
183
|
+
const jsx = (
|
|
184
|
+
<DemoProvider>
|
|
185
|
+
<ContactForm {...props} />
|
|
186
|
+
</DemoProvider>
|
|
187
|
+
)
|
|
188
|
+
render(jsx)
|
|
189
|
+
|
|
190
|
+
for (const label of labels) {
|
|
191
|
+
act(() => {
|
|
192
|
+
fireEvent.change(screen.getByLabelText(label), {
|
|
193
|
+
target: { value: testFields[label] }
|
|
194
|
+
})
|
|
195
|
+
})
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
expect(screen.queryByDisplayValue(testFields['Firstname'])).not.toBeNull()
|
|
199
|
+
expect(screen.queryByDisplayValue(testFields['Notes'])).not.toBeNull()
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
it('should not submit empty fields', () => {
|
|
203
|
+
const onSubmit = jest.fn()
|
|
204
|
+
|
|
205
|
+
render(
|
|
206
|
+
<DemoProvider>
|
|
207
|
+
<ContactForm onSubmit={onSubmit} onCancel={() => {}} />
|
|
208
|
+
</DemoProvider>
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
act(() => {
|
|
212
|
+
fireEvent.submit(screen.getByRole('form'))
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
expect(onSubmit).not.toBeCalled()
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
describe('isSameContactProp', () => {
|
|
219
|
+
it('should return true if contacts have the same "related" relationships', () => {
|
|
220
|
+
const prevProps = {
|
|
221
|
+
contact: {
|
|
222
|
+
relationships: {
|
|
223
|
+
related: {
|
|
224
|
+
data: [{ _id: '1' }, { _id: '2' }]
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const nextProps = {
|
|
230
|
+
contact: {
|
|
231
|
+
relationships: {
|
|
232
|
+
related: {
|
|
233
|
+
data: [{ _id: '2' }, { _id: '1' }]
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
expect(isSameContactProp(prevProps, nextProps)).toBe(true)
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
it('should return false if contacts have different "related" relationships', () => {
|
|
242
|
+
const prevProps = {
|
|
243
|
+
contact: {
|
|
244
|
+
relationships: {
|
|
245
|
+
related: {
|
|
246
|
+
data: [{ _id: '1' }, { _id: '2' }]
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const nextProps = {
|
|
252
|
+
contact: {
|
|
253
|
+
relationships: {
|
|
254
|
+
related: {
|
|
255
|
+
data: [{ _id: '1' }, { _id: '3' }]
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
expect(isSameContactProp(prevProps, nextProps)).toBe(false)
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
it('should return false if one of the contacts has no "related" relationships', () => {
|
|
264
|
+
const prevProps = {
|
|
265
|
+
contact: {
|
|
266
|
+
relationships: {
|
|
267
|
+
related: {
|
|
268
|
+
data: [{ _id: '1' }, { _id: '2' }]
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
const nextProps = {
|
|
274
|
+
contact: {}
|
|
275
|
+
}
|
|
276
|
+
expect(isSameContactProp(prevProps, nextProps)).toBe(false)
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
it('should return false if both contacts have no "related" relationships', () => {
|
|
280
|
+
const prevProps = {
|
|
281
|
+
contact: {}
|
|
282
|
+
}
|
|
283
|
+
const nextProps = {
|
|
284
|
+
contact: {}
|
|
285
|
+
}
|
|
286
|
+
expect(isSameContactProp(prevProps, nextProps)).toBe(false)
|
|
287
|
+
})
|
|
288
|
+
})
|
|
289
|
+
})
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Contacts": {
|
|
3
|
+
"AddModal": {
|
|
4
|
+
"ContactForm": {
|
|
5
|
+
"gender": {
|
|
6
|
+
"man": "Man",
|
|
7
|
+
"woman": "Woman"
|
|
8
|
+
},
|
|
9
|
+
"fields": {
|
|
10
|
+
"gender": "Civility",
|
|
11
|
+
"givenName": "Firstname",
|
|
12
|
+
"additionalName": "2nd firstname",
|
|
13
|
+
"surname": "Name in use",
|
|
14
|
+
"familyName": "Lastname",
|
|
15
|
+
"phone": "Phone",
|
|
16
|
+
"email": "Email",
|
|
17
|
+
"address": "Address",
|
|
18
|
+
"cozy": "Twake URL",
|
|
19
|
+
"company": "Company",
|
|
20
|
+
"jobTitle": "Job title",
|
|
21
|
+
"birthday": "Birthday",
|
|
22
|
+
"birthplace": "Birthplace",
|
|
23
|
+
"relatedContact": "Related contact",
|
|
24
|
+
"relationship": "Relationship",
|
|
25
|
+
"note": "Notes",
|
|
26
|
+
"label": "Label",
|
|
27
|
+
"required": "One of these fields must be filled in"
|
|
28
|
+
},
|
|
29
|
+
"label": {
|
|
30
|
+
"none": "None",
|
|
31
|
+
"home": "Personal",
|
|
32
|
+
"work": "Pro",
|
|
33
|
+
"custom": "Customised",
|
|
34
|
+
"phone": {
|
|
35
|
+
"cell-home": "Cell (personal)",
|
|
36
|
+
"cell-work": "Cell (pro)",
|
|
37
|
+
"voice-home": "Voice (personal)",
|
|
38
|
+
"voice-work": "Voice (pro)",
|
|
39
|
+
"fax-home": "Fax (personal)",
|
|
40
|
+
"fax-work": "Fax (pro)"
|
|
41
|
+
},
|
|
42
|
+
"address": {
|
|
43
|
+
"home": "Home (personal)",
|
|
44
|
+
"work": "Work (pro)"
|
|
45
|
+
},
|
|
46
|
+
"relationship": {
|
|
47
|
+
"parent": "Parent",
|
|
48
|
+
"child": "Child",
|
|
49
|
+
"sibling": "Sibling",
|
|
50
|
+
"spouse": "Spouse",
|
|
51
|
+
"coResident": "Co-resident",
|
|
52
|
+
"friend": "Friend",
|
|
53
|
+
"colleague": "Colleague",
|
|
54
|
+
"coWorker": "Co-worker",
|
|
55
|
+
"acquaintance": "Acquaintance",
|
|
56
|
+
"helper": "Helper",
|
|
57
|
+
"recipient": "Recipient"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"addLabel": {
|
|
61
|
+
"address": "Add an address",
|
|
62
|
+
"email": "Add an email",
|
|
63
|
+
"phone": "Add a phone",
|
|
64
|
+
"relatedContact": "Add a related contact"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"formatted": {
|
|
70
|
+
"date": "yyyy-LL-dd",
|
|
71
|
+
"address": "%{number} %{street}, %{code} %{city}, %{country}"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Contacts": {
|
|
3
|
+
"AddModal": {
|
|
4
|
+
"ContactForm": {
|
|
5
|
+
"gender": {
|
|
6
|
+
"man": "Homme",
|
|
7
|
+
"woman": "Femme"
|
|
8
|
+
},
|
|
9
|
+
"fields": {
|
|
10
|
+
"gender": "Civilité",
|
|
11
|
+
"givenName": "Prénom",
|
|
12
|
+
"additionalName": "2e prénom",
|
|
13
|
+
"surname": "Nom d'usage",
|
|
14
|
+
"familyName": "Nom",
|
|
15
|
+
"phone": "Téléphone",
|
|
16
|
+
"email": "Email",
|
|
17
|
+
"address": "Adresse",
|
|
18
|
+
"cozy": "URL du Twake",
|
|
19
|
+
"company": "Entreprise",
|
|
20
|
+
"jobTitle": "Fonction",
|
|
21
|
+
"birthday": "Anniversaire",
|
|
22
|
+
"birthplace": "Lieu de naissance",
|
|
23
|
+
"relatedContact": "Contact lié",
|
|
24
|
+
"relationship": "Relation",
|
|
25
|
+
"note": "Notes",
|
|
26
|
+
"label": "Libellé",
|
|
27
|
+
"required": "Un de ces champs doit être renseigné"
|
|
28
|
+
},
|
|
29
|
+
"label": {
|
|
30
|
+
"none": "Aucun",
|
|
31
|
+
"home": "Perso",
|
|
32
|
+
"work": "Pro",
|
|
33
|
+
"custom": "Personnalisé",
|
|
34
|
+
"phone": {
|
|
35
|
+
"cell-home": "Mobile (perso)",
|
|
36
|
+
"cell-work": "Mobile (pro)",
|
|
37
|
+
"voice-home": "Fixe (perso)",
|
|
38
|
+
"voice-work": "Fixe (pro)",
|
|
39
|
+
"fax-home": "Fax (perso)",
|
|
40
|
+
"fax-work": "Fax (pro)"
|
|
41
|
+
},
|
|
42
|
+
"address": {
|
|
43
|
+
"home": "Domicile (perso)",
|
|
44
|
+
"work": "Travail (pro)"
|
|
45
|
+
},
|
|
46
|
+
"relationship": {
|
|
47
|
+
"parent": "Parent",
|
|
48
|
+
"child": "Enfant",
|
|
49
|
+
"sibling": "Frère/Soeur",
|
|
50
|
+
"spouse": "Conjoint",
|
|
51
|
+
"coResident": "Colocataire",
|
|
52
|
+
"friend": "Ami",
|
|
53
|
+
"colleague": "Collègue/Collaborateur",
|
|
54
|
+
"coWorker": "Associé/Partenaire",
|
|
55
|
+
"acquaintance": "Connaissance",
|
|
56
|
+
"helper": "Assistant/Aidant",
|
|
57
|
+
"recipient": "Bénéficiaire/Aidé"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"addLabel": {
|
|
61
|
+
"address": "Ajouter une adresse",
|
|
62
|
+
"email": "Ajouter un email",
|
|
63
|
+
"phone": "Ajouter un téléphone",
|
|
64
|
+
"relatedContact": "Ajouter un contact lié"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"formatted": {
|
|
70
|
+
"date": "dd/LL/yyyy",
|
|
71
|
+
"address": "%{number} %{street}, %{code} %{city}, %{country}"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import PropTypes from 'prop-types'
|
|
2
|
+
import React, { useState } from 'react'
|
|
3
|
+
|
|
4
|
+
import { locales } from './locales'
|
|
5
|
+
import Button from '../../../Buttons'
|
|
6
|
+
import { ConfirmDialog } from '../../../CozyDialogs'
|
|
7
|
+
import FormControlLabel from '../../../FormControlLabel'
|
|
8
|
+
import RadioGroup from '../../../RadioGroup'
|
|
9
|
+
import Radio from '../../../Radios'
|
|
10
|
+
import TextField from '../../../TextField'
|
|
11
|
+
import { useBreakpoints } from '../../../providers/Breakpoints'
|
|
12
|
+
import { useI18n, useExtendI18n } from '../../../providers/I18n'
|
|
13
|
+
|
|
14
|
+
const CustomLabelDialog = ({
|
|
15
|
+
customValue,
|
|
16
|
+
setCustomValue,
|
|
17
|
+
customLabelOptions,
|
|
18
|
+
onSubmit,
|
|
19
|
+
onClose
|
|
20
|
+
}) => {
|
|
21
|
+
const customValueObj = JSON.parse(customValue || '{}')
|
|
22
|
+
useExtendI18n(locales)
|
|
23
|
+
const { t } = useI18n()
|
|
24
|
+
const { isMobile } = useBreakpoints()
|
|
25
|
+
const [type, setType] = useState(
|
|
26
|
+
customValueObj.type || customLabelOptions.defaultType
|
|
27
|
+
)
|
|
28
|
+
const [label, setLabel] = useState(
|
|
29
|
+
customValueObj.label || customLabelOptions.defaultLabel
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
const handleSubmit = () => {
|
|
33
|
+
setCustomValue(JSON.stringify({ type, label }))
|
|
34
|
+
onSubmit({ target: { value: JSON.stringify({ type, label }) } })
|
|
35
|
+
onClose()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<ConfirmDialog
|
|
40
|
+
open
|
|
41
|
+
title={t('Contacts.AddModal.CustomLabelDialog.label.custom')}
|
|
42
|
+
content={
|
|
43
|
+
<>
|
|
44
|
+
<TextField
|
|
45
|
+
className="u-mt-half"
|
|
46
|
+
variant="outlined"
|
|
47
|
+
fullWidth
|
|
48
|
+
autoFocus
|
|
49
|
+
value={type}
|
|
50
|
+
onChange={ev => setType(ev.target.value)}
|
|
51
|
+
/>
|
|
52
|
+
{!customLabelOptions.hide && (
|
|
53
|
+
<RadioGroup
|
|
54
|
+
style={{ flexDirection: 'row' }}
|
|
55
|
+
className="u-mt-half u-ml-half"
|
|
56
|
+
aria-label="radio"
|
|
57
|
+
name="label"
|
|
58
|
+
value={label}
|
|
59
|
+
onChange={ev => setLabel(ev.target.value)}
|
|
60
|
+
>
|
|
61
|
+
<FormControlLabel
|
|
62
|
+
value="home"
|
|
63
|
+
label={t('Contacts.AddModal.CustomLabelDialog.label.home')}
|
|
64
|
+
control={<Radio />}
|
|
65
|
+
/>
|
|
66
|
+
<FormControlLabel
|
|
67
|
+
value="work"
|
|
68
|
+
label={t('Contacts.AddModal.CustomLabelDialog.label.work')}
|
|
69
|
+
control={<Radio />}
|
|
70
|
+
/>
|
|
71
|
+
</RadioGroup>
|
|
72
|
+
)}
|
|
73
|
+
</>
|
|
74
|
+
}
|
|
75
|
+
actions={
|
|
76
|
+
<>
|
|
77
|
+
<Button
|
|
78
|
+
variant="secondary"
|
|
79
|
+
fullWidth={isMobile}
|
|
80
|
+
label={t('Contacts.AddModal.CustomLabelDialog.cancel')}
|
|
81
|
+
onClick={onClose}
|
|
82
|
+
/>
|
|
83
|
+
<Button
|
|
84
|
+
label={t('Contacts.AddModal.CustomLabelDialog.ok')}
|
|
85
|
+
fullWidth={isMobile}
|
|
86
|
+
disabled={!type}
|
|
87
|
+
onClick={handleSubmit}
|
|
88
|
+
/>
|
|
89
|
+
</>
|
|
90
|
+
}
|
|
91
|
+
onClose={onClose}
|
|
92
|
+
/>
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
CustomLabelDialog.propTypes = {
|
|
97
|
+
customValue: PropTypes.string,
|
|
98
|
+
setCustomValue: PropTypes.func,
|
|
99
|
+
customLabelOptions: PropTypes.shape({
|
|
100
|
+
hide: PropTypes.bool,
|
|
101
|
+
defaultType: PropTypes.string,
|
|
102
|
+
defaultLabel: PropTypes.string
|
|
103
|
+
}),
|
|
104
|
+
onSubmit: PropTypes.func,
|
|
105
|
+
onClose: PropTypes.func
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export default CustomLabelDialog
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Works with `final-form`, `final-form-arrays`, `react-final-form` and `react-final-form-arrays` packages under the hood.
|
|
2
|
+
|
|
3
|
+
⚠️ Must be used within `AlertProvider`.
|
|
4
|
+
|
|
5
|
+
```jsx
|
|
6
|
+
import { useState } from 'react'
|
|
7
|
+
import ContactsAddModal from 'cozy-ui/transpiled/react/Contacts/AddModal'
|
|
8
|
+
import DemoProvider from 'cozy-ui/docs/components/DemoProvider'
|
|
9
|
+
import AlertProvider from 'cozy-ui/transpiled/react/providers/Alert'
|
|
10
|
+
import Button from 'cozy-ui/transpiled/react/Buttons'
|
|
11
|
+
import { johnDoeContact, johnDoeFormValues } from 'cozy-ui/transpiled/react/Contacts/AddModal/mocks'
|
|
12
|
+
import contacts from 'cozy-ui/transpiled/react/ContactsList/_mockContacts.json'
|
|
13
|
+
import Variants from 'cozy-ui/docs/components/Variants'
|
|
14
|
+
|
|
15
|
+
initialState = { showModal: isTesting() }
|
|
16
|
+
initialVariants = [{ withContact: false }]
|
|
17
|
+
|
|
18
|
+
const open = () => setState({ showModal: true })
|
|
19
|
+
const close = () => setState({ showModal: false })
|
|
20
|
+
|
|
21
|
+
const handleSubmit = async formData => {
|
|
22
|
+
console.info('formData :', formData)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
;
|
|
26
|
+
|
|
27
|
+
<DemoProvider>
|
|
28
|
+
<AlertProvider>
|
|
29
|
+
<Variants initialVariants={initialVariants} screenshotAllVariants>
|
|
30
|
+
{variant => (
|
|
31
|
+
<>
|
|
32
|
+
<Button onClick={open} label="Open Modal" />
|
|
33
|
+
{state.showModal && (
|
|
34
|
+
<ContactsAddModal
|
|
35
|
+
contacts={{ data: contacts }}
|
|
36
|
+
contact={variant.withContact ? johnDoeContact : undefined}
|
|
37
|
+
onSubmit={handleSubmit}
|
|
38
|
+
onClose={close}
|
|
39
|
+
/>
|
|
40
|
+
)}
|
|
41
|
+
</>
|
|
42
|
+
)}
|
|
43
|
+
</Variants>
|
|
44
|
+
</AlertProvider>
|
|
45
|
+
</DemoProvider>
|
|
46
|
+
```
|