@hed-hog/catalog 0.0.279 → 0.0.286
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/README.md +3 -1
- package/dist/catalog-resource.config.d.ts +1 -0
- package/dist/catalog-resource.config.d.ts.map +1 -1
- package/dist/catalog-resource.config.js +12 -0
- package/dist/catalog-resource.config.js.map +1 -1
- package/dist/catalog.service.js +2 -2
- package/dist/catalog.service.js.map +1 -1
- package/hedhog/frontend/app/[resource]/page.tsx.ejs +648 -636
- package/hedhog/frontend/app/_components/catalog-resource-form-sheet.tsx.ejs +973 -964
- package/hedhog/frontend/app/_lib/catalog-resources.tsx.ejs +1161 -1154
- package/hedhog/frontend/app/dashboard/page.tsx.ejs +546 -562
- package/hedhog/frontend/app/page.tsx.ejs +5 -5
- package/hedhog/frontend/messages/en.json +299 -293
- package/hedhog/frontend/messages/pt.json +299 -293
- package/package.json +5 -5
- package/src/catalog-resource.config.ts +231 -218
- package/src/catalog.service.ts +167 -167
|
@@ -1,964 +1,973 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
} from '@/components/ui/
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
import {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
import {
|
|
52
|
-
import {
|
|
53
|
-
import {
|
|
54
|
-
import {
|
|
55
|
-
import {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
type CatalogRecord = Record<string, unknown>;
|
|
64
|
-
type CatalogFormValues = Record<string, unknown>;
|
|
65
|
-
type RelationOption = { id: number; label: string };
|
|
66
|
-
type FormSheetProps = {
|
|
67
|
-
open: boolean;
|
|
68
|
-
onOpenChange: (open: boolean) => void;
|
|
69
|
-
resource: string;
|
|
70
|
-
resourceConfig: CatalogResourceDefinition;
|
|
71
|
-
resourceTitle: string;
|
|
72
|
-
resourceDescription: string;
|
|
73
|
-
recordId: number | null;
|
|
74
|
-
onSuccess: (record: CatalogRecord) => Promise<void> | void;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
function toDateInputValue(value: unknown) {
|
|
78
|
-
if (!value) return '';
|
|
79
|
-
const date = new Date(String(value));
|
|
80
|
-
if (Number.isNaN(date.getTime())) return '';
|
|
81
|
-
return date.toISOString().slice(0, 10);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function toDateTimeInputValue(value: unknown) {
|
|
85
|
-
if (!value) return '';
|
|
86
|
-
const date = new Date(String(value));
|
|
87
|
-
if (Number.isNaN(date.getTime())) return '';
|
|
88
|
-
const offset = date.getTimezoneOffset();
|
|
89
|
-
const local = new Date(date.getTime() - offset * 60 * 1000);
|
|
90
|
-
return local.toISOString().slice(0, 16);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function buildFieldSchema(field: CatalogFormFieldDefinition) {
|
|
94
|
-
switch (field.type) {
|
|
95
|
-
case 'switch':
|
|
96
|
-
return z.boolean().default(false);
|
|
97
|
-
case 'number':
|
|
98
|
-
case 'currency':
|
|
99
|
-
case 'relation':
|
|
100
|
-
case 'upload':
|
|
101
|
-
return z.number().nullable().optional();
|
|
102
|
-
case 'json':
|
|
103
|
-
return z.string().superRefine((value, ctx) => {
|
|
104
|
-
if (!value.trim()) return;
|
|
105
|
-
try {
|
|
106
|
-
JSON.parse(value);
|
|
107
|
-
} catch {
|
|
108
|
-
ctx.addIssue({
|
|
109
|
-
code: z.ZodIssueCode.custom,
|
|
110
|
-
message: 'JSON inválido',
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
case 'url':
|
|
115
|
-
return z.string().superRefine((value, ctx) => {
|
|
116
|
-
const normalized = value.trim();
|
|
117
|
-
if (!normalized) return;
|
|
118
|
-
|
|
119
|
-
try {
|
|
120
|
-
new URL(normalized);
|
|
121
|
-
} catch {
|
|
122
|
-
ctx.addIssue({
|
|
123
|
-
code: z.ZodIssueCode.custom,
|
|
124
|
-
message: 'URL inválida',
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
default:
|
|
129
|
-
return z.string();
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function buildFormSchema(resourceConfig: CatalogResourceDefinition) {
|
|
134
|
-
const shape: Record<string, z.ZodTypeAny> = {};
|
|
135
|
-
|
|
136
|
-
for (const section of resourceConfig.formSections) {
|
|
137
|
-
for (const field of section.fields) {
|
|
138
|
-
let schema = buildFieldSchema(field);
|
|
139
|
-
|
|
140
|
-
if (field.required) {
|
|
141
|
-
if (
|
|
142
|
-
field.type === 'text' ||
|
|
143
|
-
field.type === 'url' ||
|
|
144
|
-
field.type === 'textarea' ||
|
|
145
|
-
field.type === 'richtext' ||
|
|
146
|
-
field.type === 'select' ||
|
|
147
|
-
field.type === 'date' ||
|
|
148
|
-
field.type === 'datetime' ||
|
|
149
|
-
field.type === 'json'
|
|
150
|
-
) {
|
|
151
|
-
schema = z.string().min(1, 'Campo obrigatório');
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (
|
|
155
|
-
field.type === 'number' ||
|
|
156
|
-
field.type === 'currency' ||
|
|
157
|
-
field.type === 'relation' ||
|
|
158
|
-
field.type === 'upload'
|
|
159
|
-
) {
|
|
160
|
-
schema = z.number({
|
|
161
|
-
required_error: 'Campo obrigatório',
|
|
162
|
-
invalid_type_error: 'Campo obrigatório',
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
shape[field.key] = schema;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return z.object(shape);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function serializeInitialValue(
|
|
175
|
-
field: CatalogFormFieldDefinition,
|
|
176
|
-
rawValue: unknown
|
|
177
|
-
): unknown {
|
|
178
|
-
if (field.type === 'json') {
|
|
179
|
-
if (rawValue === null || rawValue === undefined || rawValue === '') {
|
|
180
|
-
return '{}';
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return JSON.stringify(rawValue, null, 2);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (field.type === 'switch') {
|
|
187
|
-
return Boolean(rawValue);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if (field.type === 'currency' || field.type === 'number') {
|
|
191
|
-
return rawValue === null || rawValue === undefined || rawValue === ''
|
|
192
|
-
? null
|
|
193
|
-
: Number(rawValue);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (field.type === 'relation' || field.type === 'upload') {
|
|
197
|
-
return rawValue === null || rawValue === undefined || rawValue === ''
|
|
198
|
-
? null
|
|
199
|
-
: Number(rawValue);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (field.type === 'date') {
|
|
203
|
-
return toDateInputValue(rawValue);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if (field.type === 'datetime') {
|
|
207
|
-
return toDateTimeInputValue(rawValue);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
return rawValue === null || rawValue === undefined ? '' : String(rawValue);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
function buildDefaultValues(
|
|
214
|
-
resourceConfig: CatalogResourceDefinition,
|
|
215
|
-
payload: CatalogRecord
|
|
216
|
-
) {
|
|
217
|
-
const defaults: CatalogFormValues = {};
|
|
218
|
-
|
|
219
|
-
for (const section of resourceConfig.formSections) {
|
|
220
|
-
for (const field of section.fields) {
|
|
221
|
-
defaults[field.key] = serializeInitialValue(field, payload[field.key]);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
return defaults;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
function normalizeSubmitValue(
|
|
229
|
-
field: CatalogFormFieldDefinition,
|
|
230
|
-
rawValue: unknown
|
|
231
|
-
) {
|
|
232
|
-
if (field.type === 'json') {
|
|
233
|
-
return String(rawValue || '').trim() ? JSON.parse(String(rawValue)) : {};
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if (field.type === 'switch') {
|
|
237
|
-
return Boolean(rawValue);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (
|
|
241
|
-
field.type === 'number' ||
|
|
242
|
-
field.type === 'currency' ||
|
|
243
|
-
field.type === 'relation' ||
|
|
244
|
-
field.type === 'upload'
|
|
245
|
-
) {
|
|
246
|
-
if (rawValue === null || rawValue === undefined || rawValue === '') {
|
|
247
|
-
return null;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const parsed = Number(rawValue);
|
|
251
|
-
return Number.isNaN(parsed) ? null : parsed;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
if (
|
|
255
|
-
field.type === 'text' ||
|
|
256
|
-
field.type === 'url' ||
|
|
257
|
-
field.type === 'textarea' ||
|
|
258
|
-
field.type === 'richtext'
|
|
259
|
-
) {
|
|
260
|
-
return String(rawValue || '').trim() || null;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
if (
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
return
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
function
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
field
|
|
309
|
-
value
|
|
310
|
-
onChange
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
const
|
|
317
|
-
const
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
debounceRef.current
|
|
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
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
}}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
);
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
<
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
);
|
|
676
|
-
|
|
677
|
-
const
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
const
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
const
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
const
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
</
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
{section.
|
|
778
|
-
<
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
}
|
|
783
|
-
>
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
placeholder={getLocalizedPlaceholder(
|
|
822
|
-
field,
|
|
823
|
-
currentLocaleCode
|
|
824
|
-
)}
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
{
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { RichTextEditor } from '@/components/rich-text-editor';
|
|
4
|
+
import { Button } from '@/components/ui/button';
|
|
5
|
+
import {
|
|
6
|
+
Command,
|
|
7
|
+
CommandEmpty,
|
|
8
|
+
CommandGroup,
|
|
9
|
+
CommandInput,
|
|
10
|
+
CommandItem,
|
|
11
|
+
CommandList,
|
|
12
|
+
} from '@/components/ui/command';
|
|
13
|
+
import {
|
|
14
|
+
Form,
|
|
15
|
+
FormControl,
|
|
16
|
+
FormField,
|
|
17
|
+
FormItem,
|
|
18
|
+
FormLabel,
|
|
19
|
+
FormMessage,
|
|
20
|
+
} from '@/components/ui/form';
|
|
21
|
+
import { Input } from '@/components/ui/input';
|
|
22
|
+
import { InputMoney } from '@/components/ui/input-money';
|
|
23
|
+
import {
|
|
24
|
+
Popover,
|
|
25
|
+
PopoverContent,
|
|
26
|
+
PopoverTrigger,
|
|
27
|
+
} from '@/components/ui/popover';
|
|
28
|
+
import { Progress } from '@/components/ui/progress';
|
|
29
|
+
import {
|
|
30
|
+
Select,
|
|
31
|
+
SelectContent,
|
|
32
|
+
SelectItem,
|
|
33
|
+
SelectTrigger,
|
|
34
|
+
SelectValue,
|
|
35
|
+
} from '@/components/ui/select';
|
|
36
|
+
import {
|
|
37
|
+
Sheet,
|
|
38
|
+
SheetContent,
|
|
39
|
+
SheetDescription,
|
|
40
|
+
SheetFooter,
|
|
41
|
+
SheetHeader,
|
|
42
|
+
SheetTitle,
|
|
43
|
+
} from '@/components/ui/sheet';
|
|
44
|
+
import { Switch } from '@/components/ui/switch';
|
|
45
|
+
import { Textarea } from '@/components/ui/textarea';
|
|
46
|
+
import { useApp, useQuery } from '@hed-hog/next-app-provider';
|
|
47
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
48
|
+
import { ChevronsUpDown, Loader2, Plus, Save, Upload, X } from 'lucide-react';
|
|
49
|
+
import { useTranslations } from 'next-intl';
|
|
50
|
+
import Image from 'next/image';
|
|
51
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
52
|
+
import { useForm } from 'react-hook-form';
|
|
53
|
+
import { toast } from 'sonner';
|
|
54
|
+
import { z } from 'zod';
|
|
55
|
+
import {
|
|
56
|
+
catalogResourceMap,
|
|
57
|
+
getCatalogLocalizedText,
|
|
58
|
+
getCatalogRecordLabel,
|
|
59
|
+
type CatalogFormFieldDefinition,
|
|
60
|
+
type CatalogResourceDefinition,
|
|
61
|
+
} from '../_lib/catalog-resources';
|
|
62
|
+
|
|
63
|
+
type CatalogRecord = Record<string, unknown>;
|
|
64
|
+
type CatalogFormValues = Record<string, unknown>;
|
|
65
|
+
type RelationOption = { id: number; label: string };
|
|
66
|
+
type FormSheetProps = {
|
|
67
|
+
open: boolean;
|
|
68
|
+
onOpenChange: (open: boolean) => void;
|
|
69
|
+
resource: string;
|
|
70
|
+
resourceConfig: CatalogResourceDefinition;
|
|
71
|
+
resourceTitle: string;
|
|
72
|
+
resourceDescription: string;
|
|
73
|
+
recordId: number | null;
|
|
74
|
+
onSuccess: (record: CatalogRecord) => Promise<void> | void;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
function toDateInputValue(value: unknown) {
|
|
78
|
+
if (!value) return '';
|
|
79
|
+
const date = new Date(String(value));
|
|
80
|
+
if (Number.isNaN(date.getTime())) return '';
|
|
81
|
+
return date.toISOString().slice(0, 10);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function toDateTimeInputValue(value: unknown) {
|
|
85
|
+
if (!value) return '';
|
|
86
|
+
const date = new Date(String(value));
|
|
87
|
+
if (Number.isNaN(date.getTime())) return '';
|
|
88
|
+
const offset = date.getTimezoneOffset();
|
|
89
|
+
const local = new Date(date.getTime() - offset * 60 * 1000);
|
|
90
|
+
return local.toISOString().slice(0, 16);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function buildFieldSchema(field: CatalogFormFieldDefinition) {
|
|
94
|
+
switch (field.type) {
|
|
95
|
+
case 'switch':
|
|
96
|
+
return z.boolean().default(false);
|
|
97
|
+
case 'number':
|
|
98
|
+
case 'currency':
|
|
99
|
+
case 'relation':
|
|
100
|
+
case 'upload':
|
|
101
|
+
return z.number().nullable().optional();
|
|
102
|
+
case 'json':
|
|
103
|
+
return z.string().superRefine((value, ctx) => {
|
|
104
|
+
if (!value.trim()) return;
|
|
105
|
+
try {
|
|
106
|
+
JSON.parse(value);
|
|
107
|
+
} catch {
|
|
108
|
+
ctx.addIssue({
|
|
109
|
+
code: z.ZodIssueCode.custom,
|
|
110
|
+
message: 'JSON inválido',
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
case 'url':
|
|
115
|
+
return z.string().superRefine((value, ctx) => {
|
|
116
|
+
const normalized = value.trim();
|
|
117
|
+
if (!normalized) return;
|
|
118
|
+
|
|
119
|
+
try {
|
|
120
|
+
new URL(normalized);
|
|
121
|
+
} catch {
|
|
122
|
+
ctx.addIssue({
|
|
123
|
+
code: z.ZodIssueCode.custom,
|
|
124
|
+
message: 'URL inválida',
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
default:
|
|
129
|
+
return z.string();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function buildFormSchema(resourceConfig: CatalogResourceDefinition) {
|
|
134
|
+
const shape: Record<string, z.ZodTypeAny> = {};
|
|
135
|
+
|
|
136
|
+
for (const section of resourceConfig.formSections) {
|
|
137
|
+
for (const field of section.fields) {
|
|
138
|
+
let schema: z.ZodTypeAny = buildFieldSchema(field);
|
|
139
|
+
|
|
140
|
+
if (field.required) {
|
|
141
|
+
if (
|
|
142
|
+
field.type === 'text' ||
|
|
143
|
+
field.type === 'url' ||
|
|
144
|
+
field.type === 'textarea' ||
|
|
145
|
+
field.type === 'richtext' ||
|
|
146
|
+
field.type === 'select' ||
|
|
147
|
+
field.type === 'date' ||
|
|
148
|
+
field.type === 'datetime' ||
|
|
149
|
+
field.type === 'json'
|
|
150
|
+
) {
|
|
151
|
+
schema = z.string().min(1, 'Campo obrigatório');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (
|
|
155
|
+
field.type === 'number' ||
|
|
156
|
+
field.type === 'currency' ||
|
|
157
|
+
field.type === 'relation' ||
|
|
158
|
+
field.type === 'upload'
|
|
159
|
+
) {
|
|
160
|
+
schema = z.number({
|
|
161
|
+
required_error: 'Campo obrigatório',
|
|
162
|
+
invalid_type_error: 'Campo obrigatório',
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
shape[field.key] = schema;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return z.object(shape);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function serializeInitialValue(
|
|
175
|
+
field: CatalogFormFieldDefinition,
|
|
176
|
+
rawValue: unknown
|
|
177
|
+
): unknown {
|
|
178
|
+
if (field.type === 'json') {
|
|
179
|
+
if (rawValue === null || rawValue === undefined || rawValue === '') {
|
|
180
|
+
return '{}';
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return JSON.stringify(rawValue, null, 2);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (field.type === 'switch') {
|
|
187
|
+
return Boolean(rawValue);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (field.type === 'currency' || field.type === 'number') {
|
|
191
|
+
return rawValue === null || rawValue === undefined || rawValue === ''
|
|
192
|
+
? null
|
|
193
|
+
: Number(rawValue);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (field.type === 'relation' || field.type === 'upload') {
|
|
197
|
+
return rawValue === null || rawValue === undefined || rawValue === ''
|
|
198
|
+
? null
|
|
199
|
+
: Number(rawValue);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (field.type === 'date') {
|
|
203
|
+
return toDateInputValue(rawValue);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (field.type === 'datetime') {
|
|
207
|
+
return toDateTimeInputValue(rawValue);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return rawValue === null || rawValue === undefined ? '' : String(rawValue);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function buildDefaultValues(
|
|
214
|
+
resourceConfig: CatalogResourceDefinition,
|
|
215
|
+
payload: CatalogRecord
|
|
216
|
+
) {
|
|
217
|
+
const defaults: CatalogFormValues = {};
|
|
218
|
+
|
|
219
|
+
for (const section of resourceConfig.formSections) {
|
|
220
|
+
for (const field of section.fields) {
|
|
221
|
+
defaults[field.key] = serializeInitialValue(field, payload[field.key]);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return defaults;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function normalizeSubmitValue(
|
|
229
|
+
field: CatalogFormFieldDefinition,
|
|
230
|
+
rawValue: unknown
|
|
231
|
+
) {
|
|
232
|
+
if (field.type === 'json') {
|
|
233
|
+
return String(rawValue || '').trim() ? JSON.parse(String(rawValue)) : {};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (field.type === 'switch') {
|
|
237
|
+
return Boolean(rawValue);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (
|
|
241
|
+
field.type === 'number' ||
|
|
242
|
+
field.type === 'currency' ||
|
|
243
|
+
field.type === 'relation' ||
|
|
244
|
+
field.type === 'upload'
|
|
245
|
+
) {
|
|
246
|
+
if (rawValue === null || rawValue === undefined || rawValue === '') {
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const parsed = Number(rawValue);
|
|
251
|
+
return Number.isNaN(parsed) ? null : parsed;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (
|
|
255
|
+
field.type === 'text' ||
|
|
256
|
+
field.type === 'url' ||
|
|
257
|
+
field.type === 'textarea' ||
|
|
258
|
+
field.type === 'richtext'
|
|
259
|
+
) {
|
|
260
|
+
return String(rawValue || '').trim() || null;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (
|
|
264
|
+
field.type === 'date' ||
|
|
265
|
+
field.type === 'datetime' ||
|
|
266
|
+
field.type === 'select'
|
|
267
|
+
) {
|
|
268
|
+
return String(rawValue || '').trim() || null;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return rawValue;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function extractRecordId(record: CatalogRecord) {
|
|
275
|
+
return Number(record.id ?? record.category_id ?? record.content_id ?? 0);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function extractRelationLabel(
|
|
279
|
+
item: CatalogRecord,
|
|
280
|
+
labelKeys: string[]
|
|
281
|
+
): string {
|
|
282
|
+
for (const key of labelKeys) {
|
|
283
|
+
const value = item[key];
|
|
284
|
+
|
|
285
|
+
if (value !== undefined && value !== null && String(value).trim() !== '') {
|
|
286
|
+
return String(value);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return String(getCatalogRecordLabel(item));
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function getLocalizedPlaceholder(
|
|
294
|
+
field: CatalogFormFieldDefinition,
|
|
295
|
+
localeCode?: string | null
|
|
296
|
+
) {
|
|
297
|
+
if (field.placeholder) {
|
|
298
|
+
return getCatalogLocalizedText(field.placeholder, localeCode);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const label = getCatalogLocalizedText(field.label, localeCode);
|
|
302
|
+
return localeCode?.startsWith('pt')
|
|
303
|
+
? `Preencha ${label.toLowerCase()}`
|
|
304
|
+
: `Enter ${label.toLowerCase()}`;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function CatalogRelationField({
|
|
308
|
+
field,
|
|
309
|
+
value,
|
|
310
|
+
onChange,
|
|
311
|
+
}: {
|
|
312
|
+
field: CatalogFormFieldDefinition;
|
|
313
|
+
value: unknown;
|
|
314
|
+
onChange: (value: number | null) => void;
|
|
315
|
+
}) {
|
|
316
|
+
const { request, currentLocaleCode } = useApp();
|
|
317
|
+
const [open, setOpen] = useState(false);
|
|
318
|
+
const [search, setSearch] = useState('');
|
|
319
|
+
const [createOpen, setCreateOpen] = useState(false);
|
|
320
|
+
const [selectedLabel, setSelectedLabel] = useState('');
|
|
321
|
+
const debounceRef = useRef<NodeJS.Timeout | null>(null);
|
|
322
|
+
const childResource =
|
|
323
|
+
field.relation?.createResource &&
|
|
324
|
+
catalogResourceMap.get(field.relation.createResource);
|
|
325
|
+
|
|
326
|
+
const [debouncedSearch, setDebouncedSearch] = useState('');
|
|
327
|
+
|
|
328
|
+
useEffect(() => {
|
|
329
|
+
if (debounceRef.current) {
|
|
330
|
+
clearTimeout(debounceRef.current);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
debounceRef.current = setTimeout(() => {
|
|
334
|
+
setDebouncedSearch(search);
|
|
335
|
+
}, 300);
|
|
336
|
+
|
|
337
|
+
return () => {
|
|
338
|
+
if (debounceRef.current) {
|
|
339
|
+
clearTimeout(debounceRef.current);
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
}, [search]);
|
|
343
|
+
|
|
344
|
+
const { data: options = [], isLoading } = useQuery<RelationOption[]>({
|
|
345
|
+
queryKey: [
|
|
346
|
+
'catalog-relation-options',
|
|
347
|
+
field.key,
|
|
348
|
+
field.relation?.endpoint,
|
|
349
|
+
debouncedSearch,
|
|
350
|
+
],
|
|
351
|
+
queryFn: async () => {
|
|
352
|
+
const relation = field.relation;
|
|
353
|
+
if (!relation) return [];
|
|
354
|
+
|
|
355
|
+
const params: Record<string, string | number> = {
|
|
356
|
+
page: 1,
|
|
357
|
+
pageSize: 20,
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
if (debouncedSearch.trim()) {
|
|
361
|
+
params[relation.searchParam || 'search'] = debouncedSearch.trim();
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const response = await request({
|
|
365
|
+
url: relation.endpoint,
|
|
366
|
+
method: 'GET',
|
|
367
|
+
params,
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
const payload = response.data as
|
|
371
|
+
| CatalogRecord[]
|
|
372
|
+
| { data?: CatalogRecord[] }
|
|
373
|
+
| undefined;
|
|
374
|
+
const items = Array.isArray(payload)
|
|
375
|
+
? payload
|
|
376
|
+
: Array.isArray(payload?.data)
|
|
377
|
+
? payload.data
|
|
378
|
+
: [];
|
|
379
|
+
|
|
380
|
+
return items.map((item) => ({
|
|
381
|
+
id: Number(item[relation.valueKey || 'id']),
|
|
382
|
+
label: extractRelationLabel(item, relation.labelKeys),
|
|
383
|
+
}));
|
|
384
|
+
},
|
|
385
|
+
enabled: Boolean(field.relation),
|
|
386
|
+
placeholderData: (previous) => previous ?? [],
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
const selectedOption = options.find((item) => item.id === Number(value));
|
|
390
|
+
const currentLabel =
|
|
391
|
+
selectedOption?.label ||
|
|
392
|
+
selectedLabel ||
|
|
393
|
+
(value ? `ID #${String(value)}` : '');
|
|
394
|
+
|
|
395
|
+
return (
|
|
396
|
+
<>
|
|
397
|
+
<div className="flex w-full items-center gap-2">
|
|
398
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
399
|
+
<PopoverTrigger asChild>
|
|
400
|
+
<Button
|
|
401
|
+
type="button"
|
|
402
|
+
variant="outline"
|
|
403
|
+
className="h-9 flex-1 justify-between overflow-hidden"
|
|
404
|
+
>
|
|
405
|
+
<span className="truncate text-left">
|
|
406
|
+
{currentLabel ||
|
|
407
|
+
getCatalogLocalizedText(
|
|
408
|
+
field.placeholder || field.label,
|
|
409
|
+
currentLocaleCode
|
|
410
|
+
)}
|
|
411
|
+
</span>
|
|
412
|
+
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
|
413
|
+
</Button>
|
|
414
|
+
</PopoverTrigger>
|
|
415
|
+
<PopoverContent
|
|
416
|
+
className="w-[var(--radix-popover-trigger-width)] p-0"
|
|
417
|
+
align="start"
|
|
418
|
+
>
|
|
419
|
+
<Command shouldFilter={false}>
|
|
420
|
+
<CommandInput
|
|
421
|
+
placeholder={
|
|
422
|
+
currentLocaleCode?.startsWith('pt')
|
|
423
|
+
? 'Buscar registro...'
|
|
424
|
+
: 'Search record...'
|
|
425
|
+
}
|
|
426
|
+
value={search}
|
|
427
|
+
onValueChange={setSearch}
|
|
428
|
+
/>
|
|
429
|
+
<CommandList>
|
|
430
|
+
<CommandEmpty>
|
|
431
|
+
{isLoading
|
|
432
|
+
? currentLocaleCode?.startsWith('pt')
|
|
433
|
+
? 'Carregando...'
|
|
434
|
+
: 'Loading...'
|
|
435
|
+
: currentLocaleCode?.startsWith('pt')
|
|
436
|
+
? 'Nenhum resultado.'
|
|
437
|
+
: 'No results.'}
|
|
438
|
+
</CommandEmpty>
|
|
439
|
+
<CommandGroup>
|
|
440
|
+
{options.map((option) => (
|
|
441
|
+
<CommandItem
|
|
442
|
+
key={option.id}
|
|
443
|
+
value={`${option.label}-${option.id}`}
|
|
444
|
+
onSelect={() => {
|
|
445
|
+
onChange(option.id);
|
|
446
|
+
setSelectedLabel(option.label);
|
|
447
|
+
setOpen(false);
|
|
448
|
+
}}
|
|
449
|
+
>
|
|
450
|
+
{option.label}
|
|
451
|
+
</CommandItem>
|
|
452
|
+
))}
|
|
453
|
+
</CommandGroup>
|
|
454
|
+
</CommandList>
|
|
455
|
+
</Command>
|
|
456
|
+
</PopoverContent>
|
|
457
|
+
</Popover>
|
|
458
|
+
|
|
459
|
+
{value ? (
|
|
460
|
+
<Button
|
|
461
|
+
type="button"
|
|
462
|
+
variant="outline"
|
|
463
|
+
size="icon"
|
|
464
|
+
onClick={() => {
|
|
465
|
+
onChange(null);
|
|
466
|
+
setSelectedLabel('');
|
|
467
|
+
}}
|
|
468
|
+
>
|
|
469
|
+
<X className="h-4 w-4" />
|
|
470
|
+
</Button>
|
|
471
|
+
) : null}
|
|
472
|
+
|
|
473
|
+
{field.relation?.allowCreate && childResource ? (
|
|
474
|
+
<Button
|
|
475
|
+
type="button"
|
|
476
|
+
variant="outline"
|
|
477
|
+
size="icon"
|
|
478
|
+
onClick={() => setCreateOpen(true)}
|
|
479
|
+
>
|
|
480
|
+
<Plus className="h-4 w-4" />
|
|
481
|
+
</Button>
|
|
482
|
+
) : null}
|
|
483
|
+
</div>
|
|
484
|
+
|
|
485
|
+
{childResource ? (
|
|
486
|
+
<CatalogResourceFormSheet
|
|
487
|
+
open={createOpen}
|
|
488
|
+
onOpenChange={setCreateOpen}
|
|
489
|
+
resource={childResource.resource}
|
|
490
|
+
resourceConfig={childResource}
|
|
491
|
+
resourceTitle={childResource.singularLabel.pt}
|
|
492
|
+
resourceDescription=""
|
|
493
|
+
recordId={null}
|
|
494
|
+
onSuccess={(created) => {
|
|
495
|
+
const createdId = extractRecordId(created);
|
|
496
|
+
if (createdId) {
|
|
497
|
+
onChange(createdId);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
setSelectedLabel(String(getCatalogRecordLabel(created)));
|
|
501
|
+
}}
|
|
502
|
+
/>
|
|
503
|
+
) : null}
|
|
504
|
+
</>
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
function CatalogUploadField({
|
|
509
|
+
field,
|
|
510
|
+
value,
|
|
511
|
+
onChange,
|
|
512
|
+
}: {
|
|
513
|
+
field: CatalogFormFieldDefinition;
|
|
514
|
+
value: unknown;
|
|
515
|
+
onChange: (value: number | null) => void;
|
|
516
|
+
}) {
|
|
517
|
+
const { request } = useApp();
|
|
518
|
+
const [isUploading, setIsUploading] = useState(false);
|
|
519
|
+
const [progress, setProgress] = useState(0);
|
|
520
|
+
const [previewUrl, setPreviewUrl] = useState('/placeholder.png');
|
|
521
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
522
|
+
|
|
523
|
+
useEffect(() => {
|
|
524
|
+
const loadPreview = async () => {
|
|
525
|
+
if (!value || Number(value) <= 0) {
|
|
526
|
+
setPreviewUrl('/placeholder.png');
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
try {
|
|
531
|
+
const response = await request<{ url?: string }>({
|
|
532
|
+
url: `/file/open/${Number(value)}`,
|
|
533
|
+
method: 'PUT',
|
|
534
|
+
});
|
|
535
|
+
const nextUrl = String(response.data?.url || '').trim();
|
|
536
|
+
setPreviewUrl(
|
|
537
|
+
/^https?:\/\//i.test(nextUrl)
|
|
538
|
+
? nextUrl
|
|
539
|
+
: `${String(process.env.NEXT_PUBLIC_API_BASE_URL || '')}${nextUrl}`
|
|
540
|
+
);
|
|
541
|
+
} catch {
|
|
542
|
+
setPreviewUrl('/placeholder.png');
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
void loadPreview();
|
|
547
|
+
}, [request, value]);
|
|
548
|
+
|
|
549
|
+
const handleUpload = async (file: File) => {
|
|
550
|
+
setIsUploading(true);
|
|
551
|
+
setProgress(0);
|
|
552
|
+
|
|
553
|
+
try {
|
|
554
|
+
const formData = new FormData();
|
|
555
|
+
formData.append('file', file);
|
|
556
|
+
formData.append('destination', field.uploadDestination || 'catalog/file');
|
|
557
|
+
|
|
558
|
+
const response = await request<{ id?: number }>({
|
|
559
|
+
url: '/file',
|
|
560
|
+
method: 'POST',
|
|
561
|
+
data: formData,
|
|
562
|
+
headers: {
|
|
563
|
+
'Content-Type': 'multipart/form-data',
|
|
564
|
+
},
|
|
565
|
+
onUploadProgress: (event) => {
|
|
566
|
+
if (!event.total) return;
|
|
567
|
+
setProgress(Math.round((event.loaded * 100) / event.total));
|
|
568
|
+
},
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
onChange(Number(response.data?.id || 0) || null);
|
|
572
|
+
setProgress(100);
|
|
573
|
+
} catch (error) {
|
|
574
|
+
toast.error(error instanceof Error ? error.message : 'Falha no upload');
|
|
575
|
+
setProgress(0);
|
|
576
|
+
} finally {
|
|
577
|
+
setIsUploading(false);
|
|
578
|
+
if (inputRef.current) {
|
|
579
|
+
inputRef.current.value = '';
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
const handleRemove = async () => {
|
|
585
|
+
if (value) {
|
|
586
|
+
try {
|
|
587
|
+
await request({
|
|
588
|
+
url: '/file',
|
|
589
|
+
method: 'DELETE',
|
|
590
|
+
data: { ids: [Number(value)] },
|
|
591
|
+
});
|
|
592
|
+
} catch {
|
|
593
|
+
// Ignore cleanup errors to keep the form stable.
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
onChange(null);
|
|
598
|
+
setProgress(0);
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
return (
|
|
602
|
+
<div className="w-full space-y-3">
|
|
603
|
+
<input
|
|
604
|
+
ref={inputRef}
|
|
605
|
+
type="file"
|
|
606
|
+
accept={field.accept}
|
|
607
|
+
className="hidden"
|
|
608
|
+
onChange={(event) => {
|
|
609
|
+
const file = event.target.files?.[0];
|
|
610
|
+
if (file) {
|
|
611
|
+
void handleUpload(file);
|
|
612
|
+
}
|
|
613
|
+
}}
|
|
614
|
+
/>
|
|
615
|
+
|
|
616
|
+
<div className="flex items-start gap-3">
|
|
617
|
+
<div className="relative size-24 shrink-0 overflow-hidden rounded-md border bg-muted/20">
|
|
618
|
+
<Image
|
|
619
|
+
src={previewUrl}
|
|
620
|
+
alt={String(value ? 'Preview do arquivo' : 'Placeholder de upload')}
|
|
621
|
+
fill
|
|
622
|
+
unoptimized
|
|
623
|
+
className="object-cover"
|
|
624
|
+
/>
|
|
625
|
+
</div>
|
|
626
|
+
|
|
627
|
+
<div className="flex min-w-0 flex-1 flex-col gap-2">
|
|
628
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
629
|
+
<Button
|
|
630
|
+
type="button"
|
|
631
|
+
variant="outline"
|
|
632
|
+
onClick={() => inputRef.current?.click()}
|
|
633
|
+
disabled={isUploading}
|
|
634
|
+
>
|
|
635
|
+
<Upload className="mr-2 h-4 w-4" />
|
|
636
|
+
{value ? 'Trocar arquivo' : 'Enviar arquivo'}
|
|
637
|
+
</Button>
|
|
638
|
+
|
|
639
|
+
{value ? (
|
|
640
|
+
<Button
|
|
641
|
+
type="button"
|
|
642
|
+
variant="ghost"
|
|
643
|
+
onClick={() => void handleRemove()}
|
|
644
|
+
disabled={isUploading}
|
|
645
|
+
>
|
|
646
|
+
Remover
|
|
647
|
+
</Button>
|
|
648
|
+
) : null}
|
|
649
|
+
</div>
|
|
650
|
+
|
|
651
|
+
<p className="text-xs text-muted-foreground">
|
|
652
|
+
{value
|
|
653
|
+
? `Arquivo vinculado: #${String(value)}`
|
|
654
|
+
: 'Nenhuma imagem enviada. O placeholder será usado até o upload.'}
|
|
655
|
+
</p>
|
|
656
|
+
</div>
|
|
657
|
+
</div>
|
|
658
|
+
|
|
659
|
+
{isUploading ? <Progress value={progress} /> : null}
|
|
660
|
+
</div>
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
export function CatalogResourceFormSheet({
|
|
665
|
+
open,
|
|
666
|
+
onOpenChange,
|
|
667
|
+
resource,
|
|
668
|
+
resourceConfig,
|
|
669
|
+
resourceTitle,
|
|
670
|
+
resourceDescription,
|
|
671
|
+
recordId,
|
|
672
|
+
onSuccess,
|
|
673
|
+
}: FormSheetProps) {
|
|
674
|
+
const { request, currentLocaleCode } = useApp();
|
|
675
|
+
const t = useTranslations('catalog');
|
|
676
|
+
const isEditing = Boolean(recordId);
|
|
677
|
+
const formSchema = useMemo(
|
|
678
|
+
() => buildFormSchema(resourceConfig),
|
|
679
|
+
[resourceConfig]
|
|
680
|
+
);
|
|
681
|
+
|
|
682
|
+
const form = useForm<CatalogFormValues>({
|
|
683
|
+
resolver: zodResolver(formSchema),
|
|
684
|
+
defaultValues: buildDefaultValues(resourceConfig, resourceConfig.template),
|
|
685
|
+
});
|
|
686
|
+
|
|
687
|
+
const { data: currentRecord, isLoading } = useQuery<CatalogRecord>({
|
|
688
|
+
queryKey: ['catalog-record-details', resource, recordId],
|
|
689
|
+
queryFn: async () => {
|
|
690
|
+
const response = await request({
|
|
691
|
+
url: `/catalog/${resource}/${recordId}`,
|
|
692
|
+
method: 'GET',
|
|
693
|
+
});
|
|
694
|
+
|
|
695
|
+
return response.data as CatalogRecord;
|
|
696
|
+
},
|
|
697
|
+
enabled: open && Boolean(recordId),
|
|
698
|
+
});
|
|
699
|
+
|
|
700
|
+
useEffect(() => {
|
|
701
|
+
if (!open) {
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
const payload = currentRecord || resourceConfig.template;
|
|
706
|
+
form.reset(buildDefaultValues(resourceConfig, payload));
|
|
707
|
+
}, [currentRecord, form, open, resourceConfig]);
|
|
708
|
+
|
|
709
|
+
const submitLabel = isEditing
|
|
710
|
+
? getCatalogLocalizedText(resourceConfig.editActionLabel, currentLocaleCode)
|
|
711
|
+
: getCatalogLocalizedText(
|
|
712
|
+
resourceConfig.createActionLabel,
|
|
713
|
+
currentLocaleCode
|
|
714
|
+
);
|
|
715
|
+
|
|
716
|
+
const handleSubmit = async (values: CatalogFormValues) => {
|
|
717
|
+
try {
|
|
718
|
+
const payload: CatalogRecord = {};
|
|
719
|
+
|
|
720
|
+
for (const section of resourceConfig.formSections) {
|
|
721
|
+
for (const field of section.fields) {
|
|
722
|
+
payload[field.key] = normalizeSubmitValue(field, values[field.key]);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
const response = await request({
|
|
727
|
+
url: isEditing
|
|
728
|
+
? `/catalog/${resource}/${recordId}`
|
|
729
|
+
: `/catalog/${resource}`,
|
|
730
|
+
method: isEditing ? 'PATCH' : 'POST',
|
|
731
|
+
data: payload,
|
|
732
|
+
});
|
|
733
|
+
|
|
734
|
+
const savedRecord = (response.data || payload) as CatalogRecord;
|
|
735
|
+
toast.success(t('toasts.saveSuccess', { resource: resourceTitle }));
|
|
736
|
+
onOpenChange(false);
|
|
737
|
+
await onSuccess(savedRecord);
|
|
738
|
+
} catch (error) {
|
|
739
|
+
toast.error(
|
|
740
|
+
error instanceof Error ? error.message : t('toasts.saveError')
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
};
|
|
744
|
+
|
|
745
|
+
return (
|
|
746
|
+
<Sheet open={open} onOpenChange={onOpenChange}>
|
|
747
|
+
<SheetContent className="w-full overflow-x-hidden overflow-y-auto sm:max-w-2xl">
|
|
748
|
+
<SheetHeader>
|
|
749
|
+
<SheetTitle>{submitLabel}</SheetTitle>
|
|
750
|
+
<SheetDescription>{resourceDescription}</SheetDescription>
|
|
751
|
+
</SheetHeader>
|
|
752
|
+
|
|
753
|
+
{isEditing && isLoading ? (
|
|
754
|
+
<div className="flex items-center gap-2 p-4 text-sm text-muted-foreground">
|
|
755
|
+
<Loader2 className="h-4 w-4 animate-spin" />
|
|
756
|
+
Carregando dados do registro...
|
|
757
|
+
</div>
|
|
758
|
+
) : (
|
|
759
|
+
<Form {...form}>
|
|
760
|
+
<form
|
|
761
|
+
id={`catalog-form-${resource}`}
|
|
762
|
+
className="min-w-0 space-y-6 px-4 pb-4"
|
|
763
|
+
onSubmit={form.handleSubmit(handleSubmit)}
|
|
764
|
+
>
|
|
765
|
+
{resourceConfig.formSections.map((section) => (
|
|
766
|
+
<section
|
|
767
|
+
key={section.title.en}
|
|
768
|
+
className="min-w-0 max-w-full space-y-4"
|
|
769
|
+
>
|
|
770
|
+
<div>
|
|
771
|
+
<h3 className="text-sm font-semibold">
|
|
772
|
+
{getCatalogLocalizedText(
|
|
773
|
+
section.title,
|
|
774
|
+
currentLocaleCode
|
|
775
|
+
)}
|
|
776
|
+
</h3>
|
|
777
|
+
{section.description ? (
|
|
778
|
+
<p className="text-sm text-muted-foreground">
|
|
779
|
+
{getCatalogLocalizedText(
|
|
780
|
+
section.description,
|
|
781
|
+
currentLocaleCode
|
|
782
|
+
)}
|
|
783
|
+
</p>
|
|
784
|
+
) : null}
|
|
785
|
+
</div>
|
|
786
|
+
|
|
787
|
+
<div className="grid min-w-0 grid-cols-1 gap-4 sm:grid-cols-2">
|
|
788
|
+
{section.fields.map((field) => (
|
|
789
|
+
<div
|
|
790
|
+
key={field.key}
|
|
791
|
+
className={`min-w-0 ${
|
|
792
|
+
field.span === 2 ? 'sm:col-span-2' : ''
|
|
793
|
+
}`}
|
|
794
|
+
>
|
|
795
|
+
<FormField
|
|
796
|
+
control={form.control}
|
|
797
|
+
name={field.key}
|
|
798
|
+
render={({ field: formField }) => (
|
|
799
|
+
<FormItem>
|
|
800
|
+
<FormLabel>
|
|
801
|
+
{getCatalogLocalizedText(
|
|
802
|
+
field.label,
|
|
803
|
+
currentLocaleCode
|
|
804
|
+
)}
|
|
805
|
+
</FormLabel>
|
|
806
|
+
<FormControl>
|
|
807
|
+
{field.type === 'text' ||
|
|
808
|
+
field.type === 'url' ||
|
|
809
|
+
field.type === 'date' ||
|
|
810
|
+
field.type === 'datetime' ? (
|
|
811
|
+
<Input
|
|
812
|
+
type={
|
|
813
|
+
field.type === 'url'
|
|
814
|
+
? 'url'
|
|
815
|
+
: field.type === 'date'
|
|
816
|
+
? 'date'
|
|
817
|
+
: field.type === 'datetime'
|
|
818
|
+
? 'datetime-local'
|
|
819
|
+
: 'text'
|
|
820
|
+
}
|
|
821
|
+
placeholder={getLocalizedPlaceholder(
|
|
822
|
+
field,
|
|
823
|
+
currentLocaleCode
|
|
824
|
+
)}
|
|
825
|
+
className="w-full"
|
|
826
|
+
value={String(formField.value ?? '')}
|
|
827
|
+
onChange={formField.onChange}
|
|
828
|
+
/>
|
|
829
|
+
) : field.type === 'textarea' ||
|
|
830
|
+
field.type === 'json' ? (
|
|
831
|
+
<Textarea
|
|
832
|
+
placeholder={getLocalizedPlaceholder(
|
|
833
|
+
field,
|
|
834
|
+
currentLocaleCode
|
|
835
|
+
)}
|
|
836
|
+
value={String(formField.value ?? '')}
|
|
837
|
+
onChange={formField.onChange}
|
|
838
|
+
className={
|
|
839
|
+
field.type === 'json'
|
|
840
|
+
? 'min-h-40 w-full font-mono text-xs'
|
|
841
|
+
: 'min-h-28 w-full'
|
|
842
|
+
}
|
|
843
|
+
/>
|
|
844
|
+
) : field.type === 'richtext' ? (
|
|
845
|
+
<div className="min-w-0 w-full max-w-full overflow-x-hidden space-y-2">
|
|
846
|
+
{!String(formField.value ?? '').trim() ? (
|
|
847
|
+
<p className="text-xs text-muted-foreground">
|
|
848
|
+
{getLocalizedPlaceholder(
|
|
849
|
+
field,
|
|
850
|
+
currentLocaleCode
|
|
851
|
+
)}
|
|
852
|
+
</p>
|
|
853
|
+
) : null}
|
|
854
|
+
<RichTextEditor
|
|
855
|
+
value={String(formField.value ?? '')}
|
|
856
|
+
onChange={formField.onChange}
|
|
857
|
+
className="min-w-0 w-full max-w-full"
|
|
858
|
+
/>
|
|
859
|
+
</div>
|
|
860
|
+
) : field.type === 'number' ? (
|
|
861
|
+
<Input
|
|
862
|
+
type="number"
|
|
863
|
+
className={'w-full'}
|
|
864
|
+
placeholder={getLocalizedPlaceholder(
|
|
865
|
+
field,
|
|
866
|
+
currentLocaleCode
|
|
867
|
+
)}
|
|
868
|
+
value={
|
|
869
|
+
formField.value === null ||
|
|
870
|
+
formField.value === undefined
|
|
871
|
+
? ''
|
|
872
|
+
: String(formField.value)
|
|
873
|
+
}
|
|
874
|
+
onChange={(event) =>
|
|
875
|
+
formField.onChange(
|
|
876
|
+
event.target.value === ''
|
|
877
|
+
? null
|
|
878
|
+
: Number(event.target.value)
|
|
879
|
+
)
|
|
880
|
+
}
|
|
881
|
+
/>
|
|
882
|
+
) : field.type === 'currency' ? (
|
|
883
|
+
<InputMoney
|
|
884
|
+
className="w-full"
|
|
885
|
+
value={
|
|
886
|
+
typeof formField.value === 'number'
|
|
887
|
+
? formField.value
|
|
888
|
+
: undefined
|
|
889
|
+
}
|
|
890
|
+
onValueChange={formField.onChange}
|
|
891
|
+
/>
|
|
892
|
+
) : field.type === 'switch' ? (
|
|
893
|
+
<div className="flex h-9 w-full items-center">
|
|
894
|
+
<Switch
|
|
895
|
+
checked={Boolean(formField.value)}
|
|
896
|
+
onCheckedChange={formField.onChange}
|
|
897
|
+
/>
|
|
898
|
+
</div>
|
|
899
|
+
) : field.type === 'select' ? (
|
|
900
|
+
<Select
|
|
901
|
+
value={String(formField.value ?? '')}
|
|
902
|
+
onValueChange={formField.onChange}
|
|
903
|
+
>
|
|
904
|
+
<SelectTrigger className="w-full">
|
|
905
|
+
<SelectValue
|
|
906
|
+
placeholder={getLocalizedPlaceholder(
|
|
907
|
+
field,
|
|
908
|
+
currentLocaleCode
|
|
909
|
+
)}
|
|
910
|
+
/>
|
|
911
|
+
</SelectTrigger>
|
|
912
|
+
<SelectContent>
|
|
913
|
+
{field.options?.map((option) => (
|
|
914
|
+
<SelectItem
|
|
915
|
+
key={option.value}
|
|
916
|
+
value={option.value}
|
|
917
|
+
>
|
|
918
|
+
{getCatalogLocalizedText(
|
|
919
|
+
option.label,
|
|
920
|
+
currentLocaleCode
|
|
921
|
+
)}
|
|
922
|
+
</SelectItem>
|
|
923
|
+
))}
|
|
924
|
+
</SelectContent>
|
|
925
|
+
</Select>
|
|
926
|
+
) : field.type === 'relation' ? (
|
|
927
|
+
<CatalogRelationField
|
|
928
|
+
field={field}
|
|
929
|
+
value={formField.value}
|
|
930
|
+
onChange={formField.onChange}
|
|
931
|
+
/>
|
|
932
|
+
) : field.type === 'upload' ? (
|
|
933
|
+
<CatalogUploadField
|
|
934
|
+
field={field}
|
|
935
|
+
value={formField.value}
|
|
936
|
+
onChange={formField.onChange}
|
|
937
|
+
/>
|
|
938
|
+
) : null}
|
|
939
|
+
</FormControl>
|
|
940
|
+
<FormMessage />
|
|
941
|
+
</FormItem>
|
|
942
|
+
)}
|
|
943
|
+
/>
|
|
944
|
+
</div>
|
|
945
|
+
))}
|
|
946
|
+
</div>
|
|
947
|
+
</section>
|
|
948
|
+
))}
|
|
949
|
+
</form>
|
|
950
|
+
</Form>
|
|
951
|
+
)}
|
|
952
|
+
|
|
953
|
+
<SheetFooter className="border-t">
|
|
954
|
+
<div className="w-full">
|
|
955
|
+
<Button
|
|
956
|
+
type="submit"
|
|
957
|
+
form={`catalog-form-${resource}`}
|
|
958
|
+
className="w-full"
|
|
959
|
+
disabled={form.formState.isSubmitting || isLoading}
|
|
960
|
+
>
|
|
961
|
+
{form.formState.isSubmitting ? (
|
|
962
|
+
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
|
963
|
+
) : (
|
|
964
|
+
<Save className="mr-2 h-4 w-4" />
|
|
965
|
+
)}
|
|
966
|
+
{isEditing ? 'Salvar alterações' : 'Salvar'}
|
|
967
|
+
</Button>
|
|
968
|
+
</div>
|
|
969
|
+
</SheetFooter>
|
|
970
|
+
</SheetContent>
|
|
971
|
+
</Sheet>
|
|
972
|
+
);
|
|
973
|
+
}
|