@hed-hog/core 0.0.237 → 0.0.238
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/dist/dashboard/dashboard/dashboard.controller.d.ts +102 -0
- package/dist/dashboard/dashboard/dashboard.controller.d.ts.map +1 -1
- package/dist/dashboard/dashboard/dashboard.service.d.ts +102 -0
- package/dist/dashboard/dashboard/dashboard.service.d.ts.map +1 -1
- package/dist/dashboard/dashboard/dashboard.service.js +26 -0
- package/dist/dashboard/dashboard/dashboard.service.js.map +1 -1
- package/dist/dashboard/dashboard-component/dashboard-component.service.d.ts.map +1 -1
- package/dist/dashboard/dashboard-component/dashboard-component.service.js +39 -0
- package/dist/dashboard/dashboard-component/dashboard-component.service.js.map +1 -1
- package/dist/dashboard/dashboard-component-role/dashboard-component-role.controller.d.ts +7 -1
- package/dist/dashboard/dashboard-component-role/dashboard-component-role.controller.d.ts.map +1 -1
- package/dist/dashboard/dashboard-component-role/dashboard-component-role.controller.js +11 -0
- package/dist/dashboard/dashboard-component-role/dashboard-component-role.controller.js.map +1 -1
- package/dist/dashboard/dashboard-component-role/dashboard-component-role.service.d.ts +7 -1
- package/dist/dashboard/dashboard-component-role/dashboard-component-role.service.d.ts.map +1 -1
- package/dist/dashboard/dashboard-component-role/dashboard-component-role.service.js +31 -0
- package/dist/dashboard/dashboard-component-role/dashboard-component-role.service.js.map +1 -1
- package/dist/dashboard/dashboard-component-role/dto/create-batch.dto.d.ts +5 -0
- package/dist/dashboard/dashboard-component-role/dto/create-batch.dto.d.ts.map +1 -0
- package/dist/dashboard/dashboard-component-role/dto/create-batch.dto.js +27 -0
- package/dist/dashboard/dashboard-component-role/dto/create-batch.dto.js.map +1 -0
- package/dist/dashboard/dashboard-component-role/dto/index.d.ts +1 -0
- package/dist/dashboard/dashboard-component-role/dto/index.d.ts.map +1 -1
- package/dist/dashboard/dashboard-component-role/dto/index.js +1 -0
- package/dist/dashboard/dashboard-component-role/dto/index.js.map +1 -1
- package/dist/dashboard/dashboard-role/dashboard-role.controller.d.ts +7 -1
- package/dist/dashboard/dashboard-role/dashboard-role.controller.d.ts.map +1 -1
- package/dist/dashboard/dashboard-role/dashboard-role.controller.js +11 -0
- package/dist/dashboard/dashboard-role/dashboard-role.controller.js.map +1 -1
- package/dist/dashboard/dashboard-role/dashboard-role.service.d.ts +7 -1
- package/dist/dashboard/dashboard-role/dashboard-role.service.d.ts.map +1 -1
- package/dist/dashboard/dashboard-role/dashboard-role.service.js +31 -0
- package/dist/dashboard/dashboard-role/dashboard-role.service.js.map +1 -1
- package/dist/dashboard/dashboard-role/dto/create-batch.dto.d.ts +5 -0
- package/dist/dashboard/dashboard-role/dto/create-batch.dto.d.ts.map +1 -0
- package/dist/dashboard/dashboard-role/dto/create-batch.dto.js +27 -0
- package/dist/dashboard/dashboard-role/dto/create-batch.dto.js.map +1 -0
- package/dist/dashboard/dashboard-role/dto/index.d.ts +1 -0
- package/dist/dashboard/dashboard-role/dto/index.d.ts.map +1 -1
- package/dist/dashboard/dashboard-role/dto/index.js +1 -0
- package/dist/dashboard/dashboard-role/dto/index.js.map +1 -1
- package/dist/file/file.controller.d.ts +4 -1
- package/dist/file/file.controller.d.ts.map +1 -1
- package/dist/file/file.controller.js +47 -8
- package/dist/file/file.controller.js.map +1 -1
- package/dist/file/file.service.d.ts +1 -0
- package/dist/file/file.service.d.ts.map +1 -1
- package/dist/file/file.service.js +7 -0
- package/dist/file/file.service.js.map +1 -1
- package/dist/user/user.controller.d.ts +1 -0
- package/dist/user/user.controller.d.ts.map +1 -1
- package/dist/user/user.controller.js +13 -0
- package/dist/user/user.controller.js.map +1 -1
- package/dist/user/user.service.d.ts +1 -0
- package/dist/user/user.service.d.ts.map +1 -1
- package/dist/user/user.service.js +20 -0
- package/dist/user/user.service.js.map +1 -1
- package/hedhog/data/route.yaml +24 -0
- package/hedhog/frontend/app/configurations/[slug]/components/setting-field.tsx.ejs +21 -3
- package/hedhog/frontend/app/dashboard/management/tabs/components-tab.tsx.ejs +344 -5
- package/hedhog/frontend/app/dashboard/management/tabs/dashboards-tab.tsx.ejs +358 -2
- package/hedhog/frontend/messages/en.json +19 -0
- package/hedhog/frontend/messages/pt.json +19 -0
- package/package.json +4 -4
- package/src/dashboard/dashboard/dashboard.service.ts +26 -0
- package/src/dashboard/dashboard-component/dashboard-component.service.ts +39 -0
- package/src/dashboard/dashboard-component-role/dashboard-component-role.controller.ts +12 -1
- package/src/dashboard/dashboard-component-role/dashboard-component-role.service.ts +44 -1
- package/src/dashboard/dashboard-component-role/dto/create-batch.dto.ts +11 -0
- package/src/dashboard/dashboard-component-role/dto/index.ts +2 -0
- package/src/dashboard/dashboard-role/dashboard-role.controller.ts +22 -11
- package/src/dashboard/dashboard-role/dashboard-role.service.ts +48 -5
- package/src/dashboard/dashboard-role/dto/create-batch.dto.ts +11 -0
- package/src/dashboard/dashboard-role/dto/index.ts +2 -0
- package/src/file/file.controller.ts +50 -7
- package/src/file/file.service.ts +10 -0
- package/src/user/user.controller.ts +12 -1
- package/src/user/user.service.ts +32 -5
|
@@ -10,7 +10,9 @@ import {
|
|
|
10
10
|
AlertDialogHeader,
|
|
11
11
|
AlertDialogTitle,
|
|
12
12
|
} from '@/components/ui/alert-dialog';
|
|
13
|
+
import { Badge } from '@/components/ui/badge';
|
|
13
14
|
import { Button } from '@/components/ui/button';
|
|
15
|
+
import { Checkbox } from '@/components/ui/checkbox';
|
|
14
16
|
import {
|
|
15
17
|
Dialog,
|
|
16
18
|
DialogContent,
|
|
@@ -29,6 +31,14 @@ import {
|
|
|
29
31
|
SelectTrigger,
|
|
30
32
|
SelectValue,
|
|
31
33
|
} from '@/components/ui/select';
|
|
34
|
+
import {
|
|
35
|
+
Sheet,
|
|
36
|
+
SheetContent,
|
|
37
|
+
SheetDescription,
|
|
38
|
+
SheetFooter,
|
|
39
|
+
SheetHeader,
|
|
40
|
+
SheetTitle,
|
|
41
|
+
} from '@/components/ui/sheet';
|
|
32
42
|
import {
|
|
33
43
|
Table,
|
|
34
44
|
TableBody,
|
|
@@ -37,6 +47,11 @@ import {
|
|
|
37
47
|
TableHeader,
|
|
38
48
|
TableRow,
|
|
39
49
|
} from '@/components/ui/table';
|
|
50
|
+
import {
|
|
51
|
+
Tooltip,
|
|
52
|
+
TooltipContent,
|
|
53
|
+
TooltipTrigger,
|
|
54
|
+
} from '@/components/ui/tooltip';
|
|
40
55
|
import { useDebounce } from '@/hooks/use-debounce';
|
|
41
56
|
import { useApp, useQuery } from '@hed-hog/next-app-provider';
|
|
42
57
|
import {
|
|
@@ -48,6 +63,7 @@ import {
|
|
|
48
63
|
IconGlobe,
|
|
49
64
|
IconPlus,
|
|
50
65
|
IconTrash,
|
|
66
|
+
IconX,
|
|
51
67
|
} from '@tabler/icons-react';
|
|
52
68
|
import { useTranslations } from 'next-intl';
|
|
53
69
|
import { useState } from 'react';
|
|
@@ -60,6 +76,25 @@ interface Dashboard {
|
|
|
60
76
|
locale: { code: string };
|
|
61
77
|
name: string;
|
|
62
78
|
}>;
|
|
79
|
+
dashboard_role?: Array<{
|
|
80
|
+
role_id?: number;
|
|
81
|
+
role: {
|
|
82
|
+
id?: number;
|
|
83
|
+
role_id?: number;
|
|
84
|
+
slug: string;
|
|
85
|
+
role_locale?: Array<{
|
|
86
|
+
locale: { code: string };
|
|
87
|
+
name: string;
|
|
88
|
+
}>;
|
|
89
|
+
};
|
|
90
|
+
}>;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
interface RoleOption {
|
|
94
|
+
id?: number;
|
|
95
|
+
role_id?: number;
|
|
96
|
+
slug: string;
|
|
97
|
+
name?: string;
|
|
63
98
|
}
|
|
64
99
|
|
|
65
100
|
export function DashboardsTab() {
|
|
@@ -73,9 +108,20 @@ export function DashboardsTab() {
|
|
|
73
108
|
const [dashboardToDelete, setDashboardToDelete] = useState<number | null>(
|
|
74
109
|
null
|
|
75
110
|
);
|
|
111
|
+
const [removeRoleDialogOpen, setRemoveRoleDialogOpen] = useState(false);
|
|
112
|
+
const [roleToRemove, setRoleToRemove] = useState<{
|
|
113
|
+
dashboardId: number;
|
|
114
|
+
roleId: number;
|
|
115
|
+
roleName: string;
|
|
116
|
+
} | null>(null);
|
|
117
|
+
const [roleSheetOpen, setRoleSheetOpen] = useState(false);
|
|
118
|
+
const [dashboardForRoleSheet, setDashboardForRoleSheet] =
|
|
119
|
+
useState<Dashboard | null>(null);
|
|
120
|
+
const [selectedRoleIds, setSelectedRoleIds] = useState<number[]>([]);
|
|
76
121
|
const [page, setPage] = useState(1);
|
|
77
122
|
const [pageSize, setPageSize] = useState(10);
|
|
78
123
|
const [searchQuery, setSearchQuery] = useState('');
|
|
124
|
+
const [roleSearchQuery, setRoleSearchQuery] = useState('');
|
|
79
125
|
const debouncedSearch = useDebounce(searchQuery, 500);
|
|
80
126
|
|
|
81
127
|
const {
|
|
@@ -105,6 +151,33 @@ export function DashboardsTab() {
|
|
|
105
151
|
});
|
|
106
152
|
|
|
107
153
|
const dashboards = paginatedData?.data ?? [];
|
|
154
|
+
|
|
155
|
+
const { data: rolesData, isLoading: isLoadingRoles } = useQuery<{
|
|
156
|
+
data: RoleOption[];
|
|
157
|
+
total: number;
|
|
158
|
+
}>({
|
|
159
|
+
queryKey: ['roles-for-dashboard-sheet', currentLocaleCode],
|
|
160
|
+
queryFn: async () => {
|
|
161
|
+
const response = await request<{ data: RoleOption[]; total: number }>({
|
|
162
|
+
url: '/role?page=1&pageSize=1000',
|
|
163
|
+
method: 'GET',
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
return response.data;
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
const availableRoles = rolesData?.data ?? [];
|
|
171
|
+
const filteredAvailableRoles = availableRoles.filter((role) => {
|
|
172
|
+
const roleName = role.name || role.slug;
|
|
173
|
+
if (!roleSearchQuery.trim()) return true;
|
|
174
|
+
|
|
175
|
+
const query = roleSearchQuery.toLowerCase();
|
|
176
|
+
return (
|
|
177
|
+
roleName.toLowerCase().includes(query) ||
|
|
178
|
+
role.slug.toLowerCase().includes(query)
|
|
179
|
+
);
|
|
180
|
+
});
|
|
108
181
|
const total = paginatedData?.total ?? 0;
|
|
109
182
|
const totalPages = Math.ceil(total / pageSize);
|
|
110
183
|
|
|
@@ -220,6 +293,83 @@ export function DashboardsTab() {
|
|
|
220
293
|
}
|
|
221
294
|
};
|
|
222
295
|
|
|
296
|
+
const handleOpenRoleSheet = (dashboard: Dashboard) => {
|
|
297
|
+
setDashboardForRoleSheet(dashboard);
|
|
298
|
+
setSelectedRoleIds([]);
|
|
299
|
+
setRoleSearchQuery('');
|
|
300
|
+
setRoleSheetOpen(true);
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
const handleRoleSelection = (roleId: number, checked: boolean) => {
|
|
304
|
+
setSelectedRoleIds((prev) => {
|
|
305
|
+
if (checked) {
|
|
306
|
+
if (prev.includes(roleId)) return prev;
|
|
307
|
+
return [...prev, roleId];
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return prev.filter((id) => id !== roleId);
|
|
311
|
+
});
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
const handleAddRolesToDashboard = async () => {
|
|
315
|
+
if (!dashboardForRoleSheet) return;
|
|
316
|
+
|
|
317
|
+
if (selectedRoleIds.length === 0) {
|
|
318
|
+
toast.error(t('selectRoleRequired'));
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
try {
|
|
323
|
+
await request({
|
|
324
|
+
url: '/dashboard-role/batch',
|
|
325
|
+
method: 'POST',
|
|
326
|
+
data: {
|
|
327
|
+
dashboard_id: dashboardForRoleSheet.id,
|
|
328
|
+
role_ids: selectedRoleIds,
|
|
329
|
+
},
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
toast.success(t('roleAdded'));
|
|
333
|
+
setRoleSheetOpen(false);
|
|
334
|
+
setDashboardForRoleSheet(null);
|
|
335
|
+
setSelectedRoleIds([]);
|
|
336
|
+
setRoleSearchQuery('');
|
|
337
|
+
refetch();
|
|
338
|
+
} catch (error: any) {
|
|
339
|
+
console.error('Erro ao adicionar permissões ao dashboard:', error);
|
|
340
|
+
toast.error(t('errorAddingRole'));
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
const handleRoleRemoveClick = (
|
|
345
|
+
dashboardId: number,
|
|
346
|
+
roleId: number,
|
|
347
|
+
roleName: string
|
|
348
|
+
) => {
|
|
349
|
+
setRoleToRemove({ dashboardId, roleId, roleName });
|
|
350
|
+
setRemoveRoleDialogOpen(true);
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
const handleRoleRemoveConfirm = async () => {
|
|
354
|
+
if (!roleToRemove) return;
|
|
355
|
+
|
|
356
|
+
try {
|
|
357
|
+
await request({
|
|
358
|
+
url: `/dashboard-role/dashboard/${roleToRemove.dashboardId}/role/${roleToRemove.roleId}`,
|
|
359
|
+
method: 'DELETE',
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
toast.success(t('roleDeleted'));
|
|
363
|
+
refetch();
|
|
364
|
+
} catch (error) {
|
|
365
|
+
console.error('Erro ao remover permissão do dashboard:', error);
|
|
366
|
+
toast.error(t('errorDeletingRole'));
|
|
367
|
+
} finally {
|
|
368
|
+
setRemoveRoleDialogOpen(false);
|
|
369
|
+
setRoleToRemove(null);
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
|
|
223
373
|
return (
|
|
224
374
|
<div className="space-y-4">
|
|
225
375
|
<div className="flex justify-between items-center">
|
|
@@ -329,13 +479,14 @@ export function DashboardsTab() {
|
|
|
329
479
|
<TableHead>ID</TableHead>
|
|
330
480
|
<TableHead>{t('slug')}</TableHead>
|
|
331
481
|
<TableHead>{t('name')}</TableHead>
|
|
482
|
+
<TableHead>{t('role')}</TableHead>
|
|
332
483
|
<TableHead className="w-[100px]">{t('actions')}</TableHead>
|
|
333
484
|
</TableRow>
|
|
334
485
|
</TableHeader>
|
|
335
486
|
<TableBody>
|
|
336
487
|
{isLoading ? (
|
|
337
488
|
<TableRow>
|
|
338
|
-
<TableCell colSpan={
|
|
489
|
+
<TableCell colSpan={5} className="text-center">
|
|
339
490
|
{t('loading')}
|
|
340
491
|
</TableCell>
|
|
341
492
|
</TableRow>
|
|
@@ -345,6 +496,37 @@ export function DashboardsTab() {
|
|
|
345
496
|
dashboard.dashboard_locale.find(
|
|
346
497
|
(l) => l.locale.code === currentLocaleCode
|
|
347
498
|
)?.name || dashboard.slug;
|
|
499
|
+
|
|
500
|
+
const roleEntries = (
|
|
501
|
+
dashboard.dashboard_role?.map((dashboardRole) => {
|
|
502
|
+
const roleId =
|
|
503
|
+
dashboardRole.role_id ??
|
|
504
|
+
dashboardRole.role.role_id ??
|
|
505
|
+
dashboardRole.role.id;
|
|
506
|
+
|
|
507
|
+
if (!roleId) return null;
|
|
508
|
+
|
|
509
|
+
const localeRoleName = dashboardRole.role.role_locale?.find(
|
|
510
|
+
(roleLocale) =>
|
|
511
|
+
roleLocale.locale.code === currentLocaleCode
|
|
512
|
+
)?.name;
|
|
513
|
+
|
|
514
|
+
return {
|
|
515
|
+
id: roleId,
|
|
516
|
+
name: localeRoleName || dashboardRole.role.slug,
|
|
517
|
+
};
|
|
518
|
+
}) || []
|
|
519
|
+
).filter(
|
|
520
|
+
(
|
|
521
|
+
roleEntry,
|
|
522
|
+
index,
|
|
523
|
+
array
|
|
524
|
+
): roleEntry is { id: number; name: string } =>
|
|
525
|
+
!!roleEntry &&
|
|
526
|
+
array.findIndex((item) => item?.id === roleEntry.id) ===
|
|
527
|
+
index
|
|
528
|
+
);
|
|
529
|
+
|
|
348
530
|
return (
|
|
349
531
|
<TableRow key={dashboard.id}>
|
|
350
532
|
<TableCell>{dashboard.id}</TableCell>
|
|
@@ -352,6 +534,60 @@ export function DashboardsTab() {
|
|
|
352
534
|
{dashboard.slug}
|
|
353
535
|
</TableCell>
|
|
354
536
|
<TableCell>{name}</TableCell>
|
|
537
|
+
<TableCell>
|
|
538
|
+
<div className="flex flex-wrap items-center gap-1">
|
|
539
|
+
{roleEntries.length > 0 ? (
|
|
540
|
+
roleEntries.map((roleEntry) => (
|
|
541
|
+
<Badge
|
|
542
|
+
key={`${dashboard.id}-${roleEntry.id}`}
|
|
543
|
+
variant="outline"
|
|
544
|
+
className="gap-1 pr-1"
|
|
545
|
+
>
|
|
546
|
+
<span>{roleEntry.name}</span>
|
|
547
|
+
<Tooltip>
|
|
548
|
+
<TooltipTrigger asChild>
|
|
549
|
+
<button
|
|
550
|
+
type="button"
|
|
551
|
+
className="rounded-sm p-0.5 hover:bg-muted"
|
|
552
|
+
onClick={() =>
|
|
553
|
+
handleRoleRemoveClick(
|
|
554
|
+
dashboard.id,
|
|
555
|
+
roleEntry.id,
|
|
556
|
+
roleEntry.name
|
|
557
|
+
)
|
|
558
|
+
}
|
|
559
|
+
aria-label={`${t('delete')} ${roleEntry.name}`}
|
|
560
|
+
>
|
|
561
|
+
<IconX className="size-3" />
|
|
562
|
+
</button>
|
|
563
|
+
</TooltipTrigger>
|
|
564
|
+
<TooltipContent>
|
|
565
|
+
{`${t('delete')} ${roleEntry.name}`}
|
|
566
|
+
</TooltipContent>
|
|
567
|
+
</Tooltip>
|
|
568
|
+
</Badge>
|
|
569
|
+
))
|
|
570
|
+
) : (
|
|
571
|
+
<span className="text-muted-foreground text-xs mr-1">
|
|
572
|
+
{t('noRoles')}
|
|
573
|
+
</span>
|
|
574
|
+
)}
|
|
575
|
+
<Tooltip>
|
|
576
|
+
<TooltipTrigger asChild>
|
|
577
|
+
<Button
|
|
578
|
+
type="button"
|
|
579
|
+
size="icon"
|
|
580
|
+
variant="outline"
|
|
581
|
+
className="size-6"
|
|
582
|
+
onClick={() => handleOpenRoleSheet(dashboard)}
|
|
583
|
+
>
|
|
584
|
+
<IconPlus className="size-3" />
|
|
585
|
+
</Button>
|
|
586
|
+
</TooltipTrigger>
|
|
587
|
+
<TooltipContent>{t('addRole')}</TooltipContent>
|
|
588
|
+
</Tooltip>
|
|
589
|
+
</div>
|
|
590
|
+
</TableCell>
|
|
355
591
|
<TableCell>
|
|
356
592
|
<div className="flex gap-2">
|
|
357
593
|
<Button
|
|
@@ -377,7 +613,7 @@ export function DashboardsTab() {
|
|
|
377
613
|
})
|
|
378
614
|
) : (
|
|
379
615
|
<TableRow>
|
|
380
|
-
<TableCell colSpan={
|
|
616
|
+
<TableCell colSpan={5} className="text-center">
|
|
381
617
|
{t('noDashboards')}
|
|
382
618
|
</TableCell>
|
|
383
619
|
</TableRow>
|
|
@@ -484,6 +720,126 @@ export function DashboardsTab() {
|
|
|
484
720
|
</AlertDialogFooter>
|
|
485
721
|
</AlertDialogContent>
|
|
486
722
|
</AlertDialog>
|
|
723
|
+
|
|
724
|
+
<Dialog
|
|
725
|
+
open={removeRoleDialogOpen}
|
|
726
|
+
onOpenChange={setRemoveRoleDialogOpen}
|
|
727
|
+
>
|
|
728
|
+
<DialogContent className="max-w-md">
|
|
729
|
+
<DialogHeader>
|
|
730
|
+
<DialogTitle>{t('confirmDelete')}</DialogTitle>
|
|
731
|
+
<DialogDescription>
|
|
732
|
+
{roleToRemove
|
|
733
|
+
? `${t('deleteDescription')} (${roleToRemove.roleName})`
|
|
734
|
+
: t('deleteDescription')}
|
|
735
|
+
</DialogDescription>
|
|
736
|
+
</DialogHeader>
|
|
737
|
+
<DialogFooter>
|
|
738
|
+
<Button
|
|
739
|
+
variant="outline"
|
|
740
|
+
onClick={() => setRemoveRoleDialogOpen(false)}
|
|
741
|
+
>
|
|
742
|
+
{t('cancel')}
|
|
743
|
+
</Button>
|
|
744
|
+
<Button variant="destructive" onClick={handleRoleRemoveConfirm}>
|
|
745
|
+
{t('delete')}
|
|
746
|
+
</Button>
|
|
747
|
+
</DialogFooter>
|
|
748
|
+
</DialogContent>
|
|
749
|
+
</Dialog>
|
|
750
|
+
|
|
751
|
+
<Sheet
|
|
752
|
+
open={roleSheetOpen}
|
|
753
|
+
onOpenChange={(openValue) => {
|
|
754
|
+
setRoleSheetOpen(openValue);
|
|
755
|
+
if (!openValue) {
|
|
756
|
+
setDashboardForRoleSheet(null);
|
|
757
|
+
setSelectedRoleIds([]);
|
|
758
|
+
setRoleSearchQuery('');
|
|
759
|
+
}
|
|
760
|
+
}}
|
|
761
|
+
>
|
|
762
|
+
<SheetContent side="right" className="sm:max-w-lg overflow-y-auto">
|
|
763
|
+
<SheetHeader>
|
|
764
|
+
<SheetTitle>{t('addRole')}</SheetTitle>
|
|
765
|
+
<SheetDescription>
|
|
766
|
+
{dashboardForRoleSheet
|
|
767
|
+
? `${t('dashboard')}: ${dashboardForRoleSheet.slug}`
|
|
768
|
+
: t('manageComponentRoles')}
|
|
769
|
+
</SheetDescription>
|
|
770
|
+
</SheetHeader>
|
|
771
|
+
|
|
772
|
+
<div className="px-6 py-4">
|
|
773
|
+
<Input
|
|
774
|
+
placeholder={t('searchPlaceholder')}
|
|
775
|
+
value={roleSearchQuery}
|
|
776
|
+
onChange={(event) => setRoleSearchQuery(event.target.value)}
|
|
777
|
+
/>
|
|
778
|
+
</div>
|
|
779
|
+
|
|
780
|
+
<div className="space-y-3 px-6 pb-4">
|
|
781
|
+
{isLoadingRoles ? (
|
|
782
|
+
<p className="text-sm text-muted-foreground">{t('loading')}</p>
|
|
783
|
+
) : filteredAvailableRoles.length > 0 ? (
|
|
784
|
+
filteredAvailableRoles.map((role) => {
|
|
785
|
+
const roleId = role.role_id ?? role.id;
|
|
786
|
+
if (!roleId) return null;
|
|
787
|
+
|
|
788
|
+
const roleName = role.name || role.slug;
|
|
789
|
+
const alreadyLinked =
|
|
790
|
+
dashboardForRoleSheet?.dashboard_role?.some(
|
|
791
|
+
(dashboardRole) =>
|
|
792
|
+
(dashboardRole.role_id ??
|
|
793
|
+
dashboardRole.role.role_id ??
|
|
794
|
+
dashboardRole.role.id) === roleId
|
|
795
|
+
) ?? false;
|
|
796
|
+
|
|
797
|
+
const isSelected = selectedRoleIds.includes(roleId);
|
|
798
|
+
|
|
799
|
+
return (
|
|
800
|
+
<div
|
|
801
|
+
key={`available-dashboard-role-${roleId}`}
|
|
802
|
+
className={`flex items-center gap-3 rounded-md border p-3 transition-colors ${
|
|
803
|
+
alreadyLinked
|
|
804
|
+
? 'cursor-not-allowed opacity-70'
|
|
805
|
+
: 'cursor-pointer hover:bg-muted/40'
|
|
806
|
+
} ${isSelected ? 'border-primary bg-primary/5' : ''}`}
|
|
807
|
+
onClick={() => {
|
|
808
|
+
if (alreadyLinked) return;
|
|
809
|
+
handleRoleSelection(roleId, !isSelected);
|
|
810
|
+
}}
|
|
811
|
+
>
|
|
812
|
+
<div onClick={(event) => event.stopPropagation()}>
|
|
813
|
+
<Checkbox
|
|
814
|
+
checked={alreadyLinked || isSelected}
|
|
815
|
+
onCheckedChange={(checked) =>
|
|
816
|
+
handleRoleSelection(roleId, checked === true)
|
|
817
|
+
}
|
|
818
|
+
disabled={alreadyLinked}
|
|
819
|
+
/>
|
|
820
|
+
</div>
|
|
821
|
+
<div className="min-w-0">
|
|
822
|
+
<p className="text-sm font-medium truncate">{roleName}</p>
|
|
823
|
+
<p className="text-xs text-muted-foreground truncate">
|
|
824
|
+
{role.slug}
|
|
825
|
+
</p>
|
|
826
|
+
</div>
|
|
827
|
+
</div>
|
|
828
|
+
);
|
|
829
|
+
})
|
|
830
|
+
) : (
|
|
831
|
+
<p className="text-sm text-muted-foreground">{t('noRoles')}</p>
|
|
832
|
+
)}
|
|
833
|
+
</div>
|
|
834
|
+
|
|
835
|
+
<SheetFooter>
|
|
836
|
+
<Button variant="outline" onClick={() => setRoleSheetOpen(false)}>
|
|
837
|
+
{t('cancel')}
|
|
838
|
+
</Button>
|
|
839
|
+
<Button onClick={handleAddRolesToDashboard}>{t('save')}</Button>
|
|
840
|
+
</SheetFooter>
|
|
841
|
+
</SheetContent>
|
|
842
|
+
</Sheet>
|
|
487
843
|
</div>
|
|
488
844
|
);
|
|
489
845
|
}
|
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
{
|
|
2
|
+
"TagSelectorSheet": {
|
|
3
|
+
"addTag": "Add tag",
|
|
4
|
+
"sheetTitle": "Manage tags",
|
|
5
|
+
"sheetDescription": "Select existing tags or create a new one.",
|
|
6
|
+
"createLabel": "New tag",
|
|
7
|
+
"createPlaceholder": "Type the tag name",
|
|
8
|
+
"createAction": "Create tag",
|
|
9
|
+
"popularTitle": "Most used tags",
|
|
10
|
+
"selectedTitle": "Selected tags",
|
|
11
|
+
"noTags": "No tags",
|
|
12
|
+
"cancel": "Cancel",
|
|
13
|
+
"apply": "Apply",
|
|
14
|
+
"removeTagAria": "Remove tag {tag}",
|
|
15
|
+
"messages": {
|
|
16
|
+
"createSuccess": "Tag created successfully",
|
|
17
|
+
"createError": "Could not create the tag",
|
|
18
|
+
"updateError": "Could not update tags"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
2
21
|
"SearchBar": {
|
|
3
22
|
"searchPlaceholder": "Search...",
|
|
4
23
|
"btnBuscar": "Search"
|
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
{
|
|
2
|
+
"TagSelectorSheet": {
|
|
3
|
+
"addTag": "Adicionar tag",
|
|
4
|
+
"sheetTitle": "Gerenciar tags",
|
|
5
|
+
"sheetDescription": "Selecione tags existentes ou crie uma nova.",
|
|
6
|
+
"createLabel": "Nova tag",
|
|
7
|
+
"createPlaceholder": "Digite o nome da tag",
|
|
8
|
+
"createAction": "Criar tag",
|
|
9
|
+
"popularTitle": "Tags mais usadas",
|
|
10
|
+
"selectedTitle": "Tags selecionadas",
|
|
11
|
+
"noTags": "Sem tags",
|
|
12
|
+
"cancel": "Cancelar",
|
|
13
|
+
"apply": "Aplicar",
|
|
14
|
+
"removeTagAria": "Remover tag {tag}",
|
|
15
|
+
"messages": {
|
|
16
|
+
"createSuccess": "Tag criada com sucesso",
|
|
17
|
+
"createError": "Não foi possível criar a tag",
|
|
18
|
+
"updateError": "Não foi possível atualizar as tags"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
2
21
|
"SearchBar": {
|
|
3
22
|
"searchPlaceholder": "Pesquisar...",
|
|
4
23
|
"btnBuscar": "Buscar"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hed-hog/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.238",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
"speakeasy": "^2.0.0",
|
|
32
32
|
"uuid": "^11.1.0",
|
|
33
33
|
"@hed-hog/api-prisma": "0.0.4",
|
|
34
|
-
"@hed-hog/api": "0.0.3",
|
|
35
34
|
"@hed-hog/api-types": "0.0.1",
|
|
35
|
+
"@hed-hog/api": "0.0.3",
|
|
36
36
|
"@hed-hog/api-pagination": "0.0.5",
|
|
37
|
-
"@hed-hog/api-
|
|
38
|
-
"@hed-hog/api-
|
|
37
|
+
"@hed-hog/api-mail": "0.0.7",
|
|
38
|
+
"@hed-hog/api-locale": "0.0.11"
|
|
39
39
|
},
|
|
40
40
|
"exports": {
|
|
41
41
|
".": {
|
|
@@ -42,6 +42,19 @@ export class DashboardService {
|
|
|
42
42
|
locale: true,
|
|
43
43
|
},
|
|
44
44
|
},
|
|
45
|
+
dashboard_role: {
|
|
46
|
+
include: {
|
|
47
|
+
role: {
|
|
48
|
+
include: {
|
|
49
|
+
role_locale: {
|
|
50
|
+
include: {
|
|
51
|
+
locale: true,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
45
58
|
},
|
|
46
59
|
where: {
|
|
47
60
|
OR
|
|
@@ -63,6 +76,19 @@ export class DashboardService {
|
|
|
63
76
|
locale: true,
|
|
64
77
|
},
|
|
65
78
|
},
|
|
79
|
+
dashboard_role: {
|
|
80
|
+
include: {
|
|
81
|
+
role: {
|
|
82
|
+
include: {
|
|
83
|
+
role_locale: {
|
|
84
|
+
include: {
|
|
85
|
+
locale: true,
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
66
92
|
dashboard_item: {
|
|
67
93
|
include: {
|
|
68
94
|
dashboard_component: {
|
|
@@ -50,6 +50,19 @@ export class DashboardComponentService {
|
|
|
50
50
|
locale: true,
|
|
51
51
|
},
|
|
52
52
|
},
|
|
53
|
+
dashboard_component_role: {
|
|
54
|
+
include: {
|
|
55
|
+
role: {
|
|
56
|
+
include: {
|
|
57
|
+
role_locale: {
|
|
58
|
+
include: {
|
|
59
|
+
locale: true,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
53
66
|
},
|
|
54
67
|
where: {
|
|
55
68
|
OR,
|
|
@@ -99,6 +112,19 @@ export class DashboardComponentService {
|
|
|
99
112
|
locale: true,
|
|
100
113
|
},
|
|
101
114
|
},
|
|
115
|
+
dashboard_component_role: {
|
|
116
|
+
include: {
|
|
117
|
+
role: {
|
|
118
|
+
include: {
|
|
119
|
+
role_locale: {
|
|
120
|
+
include: {
|
|
121
|
+
locale: true,
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
102
128
|
},
|
|
103
129
|
where: {
|
|
104
130
|
AND: [
|
|
@@ -169,6 +195,19 @@ export class DashboardComponentService {
|
|
|
169
195
|
locale: true,
|
|
170
196
|
},
|
|
171
197
|
},
|
|
198
|
+
dashboard_component_role: {
|
|
199
|
+
include: {
|
|
200
|
+
role: {
|
|
201
|
+
include: {
|
|
202
|
+
role_locale: {
|
|
203
|
+
include: {
|
|
204
|
+
locale: true,
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
},
|
|
172
211
|
},
|
|
173
212
|
});
|
|
174
213
|
|
|
@@ -14,7 +14,10 @@ import {
|
|
|
14
14
|
forwardRef,
|
|
15
15
|
} from '@nestjs/common';
|
|
16
16
|
import { DashboardComponentRoleService } from './dashboard-component-role.service';
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
CreateDashboardComponentRoleBatchDTO,
|
|
19
|
+
CreateDashboardComponentRoleDTO,
|
|
20
|
+
} from './dto';
|
|
18
21
|
|
|
19
22
|
@Role()
|
|
20
23
|
@Controller('dashboard-component-role')
|
|
@@ -41,6 +44,14 @@ export class DashboardComponentRoleController {
|
|
|
41
44
|
return this.service.create(data, locale);
|
|
42
45
|
}
|
|
43
46
|
|
|
47
|
+
@Post('batch')
|
|
48
|
+
createBatch(
|
|
49
|
+
@Body() data: CreateDashboardComponentRoleBatchDTO,
|
|
50
|
+
@Locale() locale: string,
|
|
51
|
+
) {
|
|
52
|
+
return this.service.createBatch(data, locale);
|
|
53
|
+
}
|
|
54
|
+
|
|
44
55
|
@Delete(':id')
|
|
45
56
|
delete(@Param('id', ParseIntPipe) id: number, @Locale() locale: string) {
|
|
46
57
|
return this.service.delete(id, locale);
|