@controleonline/ui-customers 1.0.81 → 1.0.82
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/.github/workflows/integration-source-gate.yml +68 -0
- package/.github/workflows/publish-npm.yml +91 -0
- package/AGENTS.md +12 -6
- package/docs/technical/Client-Details-Criar-Usuario.md +113 -0
- package/package.json +5 -4
- package/src/react/components/tabs/AddressesTab.js +240 -335
- package/src/react/components/tabs/DocumentAttachments.js +270 -0
- package/src/react/components/tabs/DocumentsTab.js +355 -463
- package/src/react/components/tabs/DocumentsTab.styles.js +123 -0
- package/src/react/components/tabs/EmployeeCreateFormFields.js +203 -0
- package/src/react/components/tabs/EmployeesTab.js +17 -171
- package/src/react/components/tabs/EmployeesTab.styles.js +220 -172
- package/src/react/components/tabs/GeneralTab.js +84 -46
- package/src/react/components/tabs/GeneralTab.styles.js +81 -77
- package/src/react/components/tabs/MediaTab.js +50 -5
- package/src/react/components/tabs/PeopleCategoriesPanel.js +161 -78
- package/src/react/components/tabs/SalesmanTab.js +1 -1
- package/src/react/components/tabs/UserFormModal.js +26 -2
- package/src/react/components/tabs/UsersTab.js +30 -19
- package/src/react/components/tabs/UsersTab.styles.js +257 -257
- package/src/react/components/tabs/UsersTabApiKeyModal.js +115 -0
- package/src/react/components/tabs/UsersTabUserModal.js +222 -0
- package/src/react/components/tabs/addressesTabHelpers.js +190 -0
- package/src/react/components/tabs/documentsTabHelpers.js +142 -0
- package/src/react/components/tabs/employeeContacts.js +3 -23
- package/src/react/components/tabs/employeeUnlink.js +7 -4
- package/src/react/components/tabs/employeesTabHelpers.js +33 -9
- package/src/react/components/tabs/generalTabHelpers.js +30 -8
- package/src/react/components/tabs/useGeneralTabPeopleLink.js +68 -0
- package/src/react/components/tabs/usersTabHelpers.js +24 -23
- package/src/react/pages/details.page.styles.js +114 -100
- package/src/react/utils/humanCompanyLinkTypes.js +28 -0
- package/src/tests/browser/manager/client-details-add-user-modal.spec.js +281 -0
- package/src/tests/browser/manager/client-details-address-create-coords.spec.js +414 -0
- package/src/tests/browser/manager/client-details-address-edit.spec.js +331 -0
- package/src/tests/browser/manager/client-details-contact-edit.spec.js +198 -0
- package/src/tests/browser/manager/client-details-create-contact.spec.js +306 -0
- package/src/tests/browser/manager/client-details-documents.spec.js +346 -0
- package/src/tests/browser/manager/client-details-identity-case.spec.js +227 -0
- package/src/tests/browser/manager/client-details-people-type.manifest.md +18 -0
- package/src/tests/browser/manager/client-details-people-type.spec.js +345 -0
- package/src/tests/browser/manager/client-details-supplier-product-create.spec.js +334 -0
- package/src/tests/browser/manager/client-details-users-tab-load.spec.js +194 -0
- package/src/tests/browser/manager/employees-salesman-after-sales.spec.js +441 -0
- package/src/tests/react/components/SalesmanTab.company.test.js +40 -0
- package/src/tests/react/components/tabs/UsersTab.styles.test.js +39 -0
- package/src/tests/react/components/tabs/addressesTabHelpers.test.js +78 -0
- package/src/tests/react/components/tabs/documentsTabContract.test.mjs +37 -0
- package/src/tests/react/components/tabs/documentsTabHelpers.test.mjs +93 -0
- package/src/tests/react/components/tabs/employeeContacts.test.js +46 -4
- package/src/tests/react/components/tabs/employeeLinkTypes.contract.test.mjs +52 -0
- package/src/tests/react/components/tabs/employeeUnlink.test.js +11 -11
- package/src/tests/react/components/tabs/employeesTabHelpers.media.test.js +2 -23
- package/src/tests/react/components/tabs/employeesTabHelpers.test.js +59 -0
- package/src/tests/react/components/tabs/generalTabHelpers.test.js +35 -0
- package/src/tests/react/components/tabs/peopleMediaTabs.test.js +217 -217
- package/src/tests/react/components/tabs/peopleType.contract.test.mjs +47 -0
- package/src/tests/react/components/tabs/resolveSeededLinkType.test.mjs +20 -0
- package/src/tests/react/components/tabs/salesmanTabMedia.no-redeclare.test.mjs +33 -0
- package/src/tests/react/components/tabs/usersTabHelpers.test.js +20 -0
- package/src/tests/react/components/tabs/usersTabHelpers.test.mjs +63 -0
- package/src/tests/react/utils/humanCompanyLinkTypes.test.js +50 -0
|
@@ -1,463 +1,355 @@
|
|
|
1
|
-
import { useStores } from '@store';
|
|
2
|
-
import React, { useEffect, useState } from 'react';
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
Modal,
|
|
6
|
-
Text,
|
|
7
|
-
TextInput,
|
|
8
|
-
TouchableOpacity,
|
|
9
|
-
ScrollView,
|
|
10
|
-
View,
|
|
11
|
-
Keyboard,
|
|
12
|
-
} from 'react-native';
|
|
13
|
-
|
|
14
|
-
import AnimatedModal from '@controleonline/ui-common/src/react/components/AnimatedModal';
|
|
15
|
-
import FeatherIcon from 'react-native-vector-icons/Feather';
|
|
16
|
-
import Icon from 'react-native-vector-icons/MaterialIcons';
|
|
17
|
-
import {useMessage} from '@controleonline/ui-common/src/react/components/MessageService';
|
|
18
|
-
|
|
19
|
-
import
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
style={
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
closeModal();
|
|
357
|
-
}}>
|
|
358
|
-
<Text style={inlineStyle_350_20}>Cancelar</Text>
|
|
359
|
-
</TouchableOpacity>
|
|
360
|
-
<TouchableOpacity
|
|
361
|
-
style={customStyles.saveButton}
|
|
362
|
-
onPress={() => {
|
|
363
|
-
Keyboard.dismiss();
|
|
364
|
-
handleSave();
|
|
365
|
-
}}>
|
|
366
|
-
<FeatherIcon
|
|
367
|
-
name="save"
|
|
368
|
-
size={16}
|
|
369
|
-
color={customStyles.iconButtonPrimaryIcon.color}
|
|
370
|
-
/>
|
|
371
|
-
<Text style={customStyles.saveButtonText}>Salvar</Text>
|
|
372
|
-
</TouchableOpacity>
|
|
373
|
-
</View>
|
|
374
|
-
</ScrollView>
|
|
375
|
-
</View>
|
|
376
|
-
</AnimatedModal>
|
|
377
|
-
);
|
|
378
|
-
return (
|
|
379
|
-
<>
|
|
380
|
-
<View style={customStyles.tabContent}>
|
|
381
|
-
<View style={customStyles.section}>
|
|
382
|
-
<View style={customStyles.sectionHeader}>
|
|
383
|
-
<Text style={customStyles.sectionTitle} numberOfLines={1}>
|
|
384
|
-
Documentos
|
|
385
|
-
</Text>
|
|
386
|
-
{isEditing && (
|
|
387
|
-
<TouchableOpacity
|
|
388
|
-
onPress={() => openModal()}
|
|
389
|
-
style={customStyles.iconButtonPrimary}>
|
|
390
|
-
<Icon
|
|
391
|
-
name="add"
|
|
392
|
-
size={20}
|
|
393
|
-
color={customStyles.iconButtonPrimaryIcon.color}
|
|
394
|
-
/>
|
|
395
|
-
</TouchableOpacity>
|
|
396
|
-
)}
|
|
397
|
-
</View>
|
|
398
|
-
{getFilteredDocuments().length === 0 ? (
|
|
399
|
-
<Text style={customStyles.emptyText}>
|
|
400
|
-
Nenhum documento cadastrado
|
|
401
|
-
</Text>
|
|
402
|
-
) : (
|
|
403
|
-
getFilteredDocuments().map(doc => (
|
|
404
|
-
<View
|
|
405
|
-
key={doc.id}
|
|
406
|
-
style={[
|
|
407
|
-
customStyles.listItem,
|
|
408
|
-
customStyles.listItemWithActions,
|
|
409
|
-
]}>
|
|
410
|
-
<View style={customStyles.itemContent}>
|
|
411
|
-
<Icon
|
|
412
|
-
name="description"
|
|
413
|
-
size={20}
|
|
414
|
-
color={customStyles.cardItemIcon.color}
|
|
415
|
-
/>
|
|
416
|
-
<View>
|
|
417
|
-
<Text style={customStyles.itemText}>
|
|
418
|
-
{applyMask(String(doc.value || ''), doc.type)}
|
|
419
|
-
</Text>
|
|
420
|
-
<Text style={customStyles.itemSubtext}>
|
|
421
|
-
{items.find(i => i['@id'] === doc.type)?.documentType ||
|
|
422
|
-
String(doc.type || '')}
|
|
423
|
-
</Text>
|
|
424
|
-
</View>
|
|
425
|
-
</View>
|
|
426
|
-
{isEditing && (
|
|
427
|
-
<View
|
|
428
|
-
style={[
|
|
429
|
-
customStyles.itemActions,
|
|
430
|
-
customStyles.itemActionsPinned,
|
|
431
|
-
]}>
|
|
432
|
-
<TouchableOpacity
|
|
433
|
-
onPress={() => openModal(doc)}
|
|
434
|
-
style={customStyles.iconButtonGhost}>
|
|
435
|
-
<FeatherIcon
|
|
436
|
-
name="edit-2"
|
|
437
|
-
size={16}
|
|
438
|
-
color={customStyles.iconButtonGhostIcon.color}
|
|
439
|
-
/>
|
|
440
|
-
</TouchableOpacity>
|
|
441
|
-
<TouchableOpacity
|
|
442
|
-
onPress={() => handleDelete(doc.id)}
|
|
443
|
-
style={customStyles.iconButtonGhost}>
|
|
444
|
-
<FeatherIcon
|
|
445
|
-
name="trash-2"
|
|
446
|
-
size={16}
|
|
447
|
-
color={customStyles.iconButtonGhostIcon.color}
|
|
448
|
-
/>
|
|
449
|
-
</TouchableOpacity>
|
|
450
|
-
</View>
|
|
451
|
-
)}
|
|
452
|
-
</View>
|
|
453
|
-
))
|
|
454
|
-
)}
|
|
455
|
-
</View>
|
|
456
|
-
</View>
|
|
457
|
-
{renderModal()}
|
|
458
|
-
</>
|
|
459
|
-
);
|
|
460
|
-
};
|
|
461
|
-
|
|
462
|
-
export default DocumentsTab;
|
|
463
|
-
|
|
1
|
+
import { useStores } from '@store';
|
|
2
|
+
import React, { useEffect, useState } from 'react';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
Modal,
|
|
6
|
+
Text,
|
|
7
|
+
TextInput,
|
|
8
|
+
TouchableOpacity,
|
|
9
|
+
ScrollView,
|
|
10
|
+
View,
|
|
11
|
+
Keyboard,
|
|
12
|
+
} from 'react-native';
|
|
13
|
+
|
|
14
|
+
import AnimatedModal from '@controleonline/ui-common/src/react/components/AnimatedModal';
|
|
15
|
+
import FeatherIcon from 'react-native-vector-icons/Feather';
|
|
16
|
+
import Icon from 'react-native-vector-icons/MaterialIcons';
|
|
17
|
+
import { useMessage } from '@controleonline/ui-common/src/react/components/MessageService';
|
|
18
|
+
|
|
19
|
+
import DocumentAttachments from './DocumentAttachments';
|
|
20
|
+
import {
|
|
21
|
+
applyDocumentMask,
|
|
22
|
+
extractId,
|
|
23
|
+
normalizeDocumentFiles,
|
|
24
|
+
removeMask,
|
|
25
|
+
toDocumentItem,
|
|
26
|
+
} from './documentsTabHelpers';
|
|
27
|
+
import { resolveFileDownloadUrl } from '@controleonline/ui-common/src/react/utils/fileUrl';
|
|
28
|
+
|
|
29
|
+
import {
|
|
30
|
+
inlineStyle_265_6,
|
|
31
|
+
inlineStyle_266_12,
|
|
32
|
+
inlineStyle_279_14,
|
|
33
|
+
inlineStyle_288_16,
|
|
34
|
+
inlineStyle_291_49,
|
|
35
|
+
inlineStyle_299_10,
|
|
36
|
+
inlineStyle_302_16,
|
|
37
|
+
inlineStyle_303_18,
|
|
38
|
+
inlineStyle_304_18,
|
|
39
|
+
inlineStyle_308_18,
|
|
40
|
+
inlineStyle_314_24,
|
|
41
|
+
inlineStyle_324_16,
|
|
42
|
+
inlineStyle_325_18,
|
|
43
|
+
inlineStyle_327_14,
|
|
44
|
+
inlineStyle_341_16,
|
|
45
|
+
inlineStyle_343_14,
|
|
46
|
+
inlineStyle_350_20,
|
|
47
|
+
} from './DocumentsTab.styles';
|
|
48
|
+
|
|
49
|
+
const DocumentsTab = ({ client, customStyles, isEditing, onUpdateClient }) => {
|
|
50
|
+
const { showError, showSuccess, showDialog } = useMessage();
|
|
51
|
+
const [documents, setDocuments] = useState([]);
|
|
52
|
+
const [showModal, setShowModal] = useState(false);
|
|
53
|
+
const [editingItem, setEditingItem] = useState(null);
|
|
54
|
+
const [formData, setFormData] = useState({});
|
|
55
|
+
const peopleStore = useStores(state => state.people);
|
|
56
|
+
const peopleGetters = peopleStore.getters;
|
|
57
|
+
const { currentCompany } = peopleGetters;
|
|
58
|
+
|
|
59
|
+
const documentsStore = useStores(state => state.documents) || {};
|
|
60
|
+
const actionsDocuments = documentsStore.actions || {};
|
|
61
|
+
const documentsTypesStore = useStores(state => state.documentsTypes) || {};
|
|
62
|
+
const actionsDocumentsType = documentsTypesStore.actions || {};
|
|
63
|
+
const getters = documentsTypesStore.getters || {};
|
|
64
|
+
const { items = [] } = getters;
|
|
65
|
+
|
|
66
|
+
const resolveTypeLabel = typeIri =>
|
|
67
|
+
items.find(item => item['@id'] === typeIri)?.documentType || String(typeIri || '');
|
|
68
|
+
|
|
69
|
+
const applyMask = (value, type) =>
|
|
70
|
+
applyDocumentMask(value, resolveTypeLabel(type));
|
|
71
|
+
|
|
72
|
+
const syncClientDocuments = nextDocuments => {
|
|
73
|
+
if (typeof onUpdateClient !== 'function') {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const fullDocumentData = nextDocuments.map(documentItem => ({
|
|
77
|
+
'@id': `/documents/${documentItem.id}`,
|
|
78
|
+
id: documentItem.id,
|
|
79
|
+
document: documentItem.value,
|
|
80
|
+
documentType: documentItem.type,
|
|
81
|
+
documentFiles: documentItem.files || [],
|
|
82
|
+
file: documentItem.files?.[0]?.file || null,
|
|
83
|
+
}));
|
|
84
|
+
onUpdateClient({ document: fullDocumentData });
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const updateDocumentFiles = (documentId, nextFiles) => {
|
|
88
|
+
setDocuments(previousDocuments => {
|
|
89
|
+
const nextDocuments = previousDocuments.map(documentItem => {
|
|
90
|
+
if (String(documentItem.id) !== String(documentId)) {
|
|
91
|
+
return documentItem;
|
|
92
|
+
}
|
|
93
|
+
return { ...documentItem, files: nextFiles };
|
|
94
|
+
});
|
|
95
|
+
syncClientDocuments(nextDocuments);
|
|
96
|
+
return nextDocuments;
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
const rawDocuments = Array.isArray(client?.document)
|
|
102
|
+
? client.document
|
|
103
|
+
: Array.isArray(client?.documents)
|
|
104
|
+
? client.documents
|
|
105
|
+
: [];
|
|
106
|
+
setDocuments(
|
|
107
|
+
rawDocuments.map(document => {
|
|
108
|
+
const item = toDocumentItem(document);
|
|
109
|
+
item.files = normalizeDocumentFiles(document, resolveFileDownloadUrl);
|
|
110
|
+
return item;
|
|
111
|
+
}),
|
|
112
|
+
);
|
|
113
|
+
}, [client?.id, client?.document, client?.documents]);
|
|
114
|
+
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
if (actionsDocumentsType?.getItems) {
|
|
117
|
+
actionsDocumentsType.getItems({ itemsPerPage: 100 });
|
|
118
|
+
}
|
|
119
|
+
}, []);
|
|
120
|
+
|
|
121
|
+
const openModal = (item = null) => {
|
|
122
|
+
setEditingItem(item);
|
|
123
|
+
setFormData(
|
|
124
|
+
item
|
|
125
|
+
? { type: item.type, value: applyMask(String(item.value || ''), item.type) }
|
|
126
|
+
: { type: '', value: '' },
|
|
127
|
+
);
|
|
128
|
+
setShowModal(true);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const closeModal = () => {
|
|
132
|
+
setShowModal(false);
|
|
133
|
+
setEditingItem(null);
|
|
134
|
+
setFormData({});
|
|
135
|
+
Keyboard.dismiss();
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const handleSave = async () => {
|
|
139
|
+
if (!formData.type || !formData.value) {
|
|
140
|
+
showError(global.t?.t('customers', 'error', 'Preencha tipo e número do documento.'));
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const cleanValue = removeMask(formData.value);
|
|
144
|
+
if (!cleanValue) {
|
|
145
|
+
showError(global.t?.t('customers', 'error', 'Número do documento inválido.'));
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
try {
|
|
150
|
+
const peopleIri = client?.['@id'] || `/people/${extractId(client?.id)}`;
|
|
151
|
+
let documentId = editingItem?.id;
|
|
152
|
+
const previousFiles = editingItem?.files || [];
|
|
153
|
+
|
|
154
|
+
if (editingItem?.id) {
|
|
155
|
+
await actionsDocuments.save({
|
|
156
|
+
id: editingItem.id,
|
|
157
|
+
document: cleanValue,
|
|
158
|
+
documentType: formData.type,
|
|
159
|
+
people: peopleIri,
|
|
160
|
+
});
|
|
161
|
+
} else {
|
|
162
|
+
const created = await actionsDocuments.save({
|
|
163
|
+
document: cleanValue,
|
|
164
|
+
documentType: formData.type,
|
|
165
|
+
people: peopleIri,
|
|
166
|
+
});
|
|
167
|
+
documentId = extractId(created?.id || created?.['@id'] || created);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const documentItem = {
|
|
171
|
+
id: documentId,
|
|
172
|
+
value: cleanValue,
|
|
173
|
+
type: formData.type,
|
|
174
|
+
files: previousFiles,
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const updatedDocuments = editingItem
|
|
178
|
+
? documents.map(documentValue =>
|
|
179
|
+
String(documentValue.id) === String(editingItem.id) ? documentItem : documentValue,
|
|
180
|
+
)
|
|
181
|
+
: [...documents, documentItem];
|
|
182
|
+
|
|
183
|
+
setDocuments(updatedDocuments);
|
|
184
|
+
syncClientDocuments(updatedDocuments);
|
|
185
|
+
showSuccess(
|
|
186
|
+
global.t?.t(
|
|
187
|
+
'customers',
|
|
188
|
+
'success',
|
|
189
|
+
`Documento ${editingItem ? 'atualizado' : 'adicionado'} com sucesso!`,
|
|
190
|
+
),
|
|
191
|
+
);
|
|
192
|
+
closeModal();
|
|
193
|
+
} catch (error) {
|
|
194
|
+
showError(
|
|
195
|
+
global.t?.t(
|
|
196
|
+
'customers',
|
|
197
|
+
'error',
|
|
198
|
+
`Falha ao ${editingItem ? 'atualizar' : 'adicionar'} documento. Tente novamente.`,
|
|
199
|
+
),
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const handleDelete = id => {
|
|
205
|
+
showDialog({
|
|
206
|
+
title: global.t?.t('customers', 'label', 'Confirmar exclusão'),
|
|
207
|
+
message: global.t?.t('customers', 'label', 'Deseja realmente remover este item?'),
|
|
208
|
+
confirmLabel: global.t?.t('customers', 'label', 'Remover'),
|
|
209
|
+
cancelLabel: global.t?.t('customers', 'label', 'Cancelar'),
|
|
210
|
+
onConfirm: async () => {
|
|
211
|
+
try {
|
|
212
|
+
await actionsDocuments.remove(id);
|
|
213
|
+
const updatedDocuments = documents.filter(
|
|
214
|
+
documentItem => String(documentItem.id) !== String(id),
|
|
215
|
+
);
|
|
216
|
+
setDocuments(updatedDocuments);
|
|
217
|
+
syncClientDocuments(updatedDocuments);
|
|
218
|
+
showSuccess(global.t?.t('customers', 'success', 'Documento removido com sucesso!'));
|
|
219
|
+
} catch {
|
|
220
|
+
showError(global.t?.t('customers', 'error', 'Falha ao remover documento. Tente novamente.'));
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
const getFilteredDocuments = () => documents;
|
|
227
|
+
|
|
228
|
+
const renderModal = () => (
|
|
229
|
+
<Modal visible={showModal} transparent animationType="slide" onRequestClose={closeModal}>
|
|
230
|
+
<AnimatedModal style={inlineStyle_265_6}>
|
|
231
|
+
<View style={inlineStyle_266_12}>
|
|
232
|
+
<View style={inlineStyle_279_14}>
|
|
233
|
+
<Text style={inlineStyle_288_16}>
|
|
234
|
+
{editingItem
|
|
235
|
+
? global.t?.t('customers', 'label', 'Editar documento')
|
|
236
|
+
: global.t?.t('customers', 'label', 'Novo documento')}
|
|
237
|
+
</Text>
|
|
238
|
+
<TouchableOpacity onPress={closeModal} style={inlineStyle_291_49}>
|
|
239
|
+
<Icon name="close" size={18} color="#64748B" />
|
|
240
|
+
</TouchableOpacity>
|
|
241
|
+
</View>
|
|
242
|
+
<ScrollView contentContainerStyle={inlineStyle_299_10}>
|
|
243
|
+
<View style={inlineStyle_302_16}>
|
|
244
|
+
<Text style={inlineStyle_303_18}>{global.t?.t('customers', 'label', 'Tipo')}</Text>
|
|
245
|
+
<View style={inlineStyle_304_18}>
|
|
246
|
+
{items.map(type => (
|
|
247
|
+
<TouchableOpacity
|
|
248
|
+
key={type['@id']}
|
|
249
|
+
style={inlineStyle_308_18({ formData, type })}
|
|
250
|
+
onPress={() =>
|
|
251
|
+
setFormData(previous => ({
|
|
252
|
+
...previous,
|
|
253
|
+
type: type['@id'],
|
|
254
|
+
value: applyMask(removeMask(previous.value), type['@id']),
|
|
255
|
+
}))
|
|
256
|
+
}>
|
|
257
|
+
<Text style={inlineStyle_314_24({ formData, type })}>{type.documentType}</Text>
|
|
258
|
+
</TouchableOpacity>
|
|
259
|
+
))}
|
|
260
|
+
</View>
|
|
261
|
+
</View>
|
|
262
|
+
<View style={inlineStyle_324_16}>
|
|
263
|
+
<Text style={inlineStyle_325_18}>{global.t?.t('customers', 'label', 'Número')}</Text>
|
|
264
|
+
<TextInput
|
|
265
|
+
style={inlineStyle_327_14}
|
|
266
|
+
value={formData.value || ''}
|
|
267
|
+
onChangeText={text =>
|
|
268
|
+
setFormData(previous => ({
|
|
269
|
+
...previous,
|
|
270
|
+
value: applyMask(text, previous.type),
|
|
271
|
+
}))
|
|
272
|
+
}
|
|
273
|
+
keyboardType="numeric"
|
|
274
|
+
placeholder={global.t?.t('customers', 'label', 'Digite o número')}
|
|
275
|
+
/>
|
|
276
|
+
</View>
|
|
277
|
+
<View style={inlineStyle_341_16}>
|
|
278
|
+
<TouchableOpacity style={inlineStyle_343_14} onPress={closeModal}>
|
|
279
|
+
<Text style={inlineStyle_350_20}>{global.t?.t('customers', 'label', 'Cancelar')}</Text>
|
|
280
|
+
</TouchableOpacity>
|
|
281
|
+
<TouchableOpacity
|
|
282
|
+
style={[inlineStyle_343_14, { backgroundColor: '#007bff', borderColor: '#007bff' }]}
|
|
283
|
+
onPress={handleSave}>
|
|
284
|
+
<Text style={[inlineStyle_350_20, { color: '#fff' }]}>
|
|
285
|
+
{global.t?.t('customers', 'label', 'Salvar')}
|
|
286
|
+
</Text>
|
|
287
|
+
</TouchableOpacity>
|
|
288
|
+
</View>
|
|
289
|
+
</ScrollView>
|
|
290
|
+
</View>
|
|
291
|
+
</AnimatedModal>
|
|
292
|
+
</Modal>
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
const companyId = extractId(currentCompany?.id || currentCompany?.['@id']);
|
|
296
|
+
|
|
297
|
+
return (
|
|
298
|
+
<>
|
|
299
|
+
<View style={customStyles.section}>
|
|
300
|
+
<View style={customStyles.card}>
|
|
301
|
+
<View style={customStyles.cardHeader}>
|
|
302
|
+
<Text style={customStyles.cardTitle}>
|
|
303
|
+
{global.t?.t('customers', 'label', 'Documentos')}
|
|
304
|
+
</Text>
|
|
305
|
+
{isEditing && (
|
|
306
|
+
<TouchableOpacity onPress={() => openModal()} style={customStyles.iconButtonPrimary}>
|
|
307
|
+
<Icon name="add" size={20} color={customStyles.iconButtonPrimaryIcon.color} />
|
|
308
|
+
</TouchableOpacity>
|
|
309
|
+
)}
|
|
310
|
+
</View>
|
|
311
|
+
{getFilteredDocuments().length === 0 ? (
|
|
312
|
+
<Text style={customStyles.emptyText}>Nenhum documento cadastrado</Text>
|
|
313
|
+
) : (
|
|
314
|
+
getFilteredDocuments().map(doc => (
|
|
315
|
+
<View
|
|
316
|
+
key={doc.id}
|
|
317
|
+
style={[customStyles.listItem, customStyles.listItemWithActions, { flexDirection: 'column', alignItems: 'stretch' }]}>
|
|
318
|
+
<View style={{ flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' }}>
|
|
319
|
+
<View style={customStyles.itemContent}>
|
|
320
|
+
<Icon name="description" size={20} color={customStyles.cardItemIcon.color} />
|
|
321
|
+
<View>
|
|
322
|
+
<Text style={customStyles.itemText}>
|
|
323
|
+
{applyMask(String(doc.value || ''), doc.type)}
|
|
324
|
+
</Text>
|
|
325
|
+
<Text style={customStyles.itemSubtext}>{resolveTypeLabel(doc.type)}</Text>
|
|
326
|
+
</View>
|
|
327
|
+
</View>
|
|
328
|
+
{isEditing && (
|
|
329
|
+
<View style={[customStyles.itemActions, customStyles.itemActionsPinned]}>
|
|
330
|
+
<TouchableOpacity onPress={() => openModal(doc)} style={customStyles.iconButtonGhost}>
|
|
331
|
+
<FeatherIcon name="edit-2" size={16} color={customStyles.iconButtonGhostIcon.color} />
|
|
332
|
+
</TouchableOpacity>
|
|
333
|
+
<TouchableOpacity onPress={() => handleDelete(doc.id)} style={customStyles.iconButtonGhost}>
|
|
334
|
+
<FeatherIcon name="trash-2" size={16} color={customStyles.iconButtonGhostIcon.color} />
|
|
335
|
+
</TouchableOpacity>
|
|
336
|
+
</View>
|
|
337
|
+
)}
|
|
338
|
+
</View>
|
|
339
|
+
<DocumentAttachments
|
|
340
|
+
documentItem={doc}
|
|
341
|
+
isEditing={isEditing}
|
|
342
|
+
companyId={companyId}
|
|
343
|
+
onFilesChanged={updateDocumentFiles}
|
|
344
|
+
/>
|
|
345
|
+
</View>
|
|
346
|
+
))
|
|
347
|
+
)}
|
|
348
|
+
</View>
|
|
349
|
+
</View>
|
|
350
|
+
{renderModal()}
|
|
351
|
+
</>
|
|
352
|
+
);
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
export default DocumentsTab;
|