@hed-hog/core 0.0.299 → 0.0.301

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.
Files changed (133) hide show
  1. package/dist/ai/ai.service.d.ts +13 -2
  2. package/dist/ai/ai.service.d.ts.map +1 -1
  3. package/dist/ai/ai.service.js +104 -2
  4. package/dist/ai/ai.service.js.map +1 -1
  5. package/dist/dashboard/dashboard/dashboard.controller.d.ts +6 -0
  6. package/dist/dashboard/dashboard/dashboard.controller.d.ts.map +1 -1
  7. package/dist/dashboard/dashboard/dashboard.service.d.ts +6 -0
  8. package/dist/dashboard/dashboard/dashboard.service.d.ts.map +1 -1
  9. package/dist/dashboard/dashboard-component/dashboard-component.controller.d.ts +2 -1
  10. package/dist/dashboard/dashboard-component/dashboard-component.controller.d.ts.map +1 -1
  11. package/dist/dashboard/dashboard-component/dashboard-component.controller.js +6 -3
  12. package/dist/dashboard/dashboard-component/dashboard-component.controller.js.map +1 -1
  13. package/dist/dashboard/dashboard-component/dashboard-component.service.d.ts +7 -1
  14. package/dist/dashboard/dashboard-component/dashboard-component.service.d.ts.map +1 -1
  15. package/dist/dashboard/dashboard-component/dashboard-component.service.js +76 -33
  16. package/dist/dashboard/dashboard-component/dashboard-component.service.js.map +1 -1
  17. package/dist/dashboard/dashboard-core/dashboard-core.controller.d.ts +82 -0
  18. package/dist/dashboard/dashboard-core/dashboard-core.controller.d.ts.map +1 -1
  19. package/dist/dashboard/dashboard-core/dashboard-core.controller.js +117 -0
  20. package/dist/dashboard/dashboard-core/dashboard-core.controller.js.map +1 -1
  21. package/dist/dashboard/dashboard-core/dashboard-core.service.d.ts +93 -0
  22. package/dist/dashboard/dashboard-core/dashboard-core.service.d.ts.map +1 -1
  23. package/dist/dashboard/dashboard-core/dashboard-core.service.js +654 -20
  24. package/dist/dashboard/dashboard-core/dashboard-core.service.js.map +1 -1
  25. package/dist/dashboard/dashboard-item/dashboard-item.controller.d.ts +2 -0
  26. package/dist/dashboard/dashboard-item/dashboard-item.controller.d.ts.map +1 -1
  27. package/dist/dashboard/dashboard-item/dashboard-item.service.d.ts +2 -0
  28. package/dist/dashboard/dashboard-item/dashboard-item.service.d.ts.map +1 -1
  29. package/dist/dashboard/dashboard-role/dashboard-role.controller.d.ts +2 -0
  30. package/dist/dashboard/dashboard-role/dashboard-role.controller.d.ts.map +1 -1
  31. package/dist/dashboard/dashboard-role/dashboard-role.service.d.ts +2 -0
  32. package/dist/dashboard/dashboard-role/dashboard-role.service.d.ts.map +1 -1
  33. package/dist/index.d.ts +1 -0
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +1 -0
  36. package/dist/index.js.map +1 -1
  37. package/dist/mail/mail.service.d.ts +9 -2
  38. package/dist/mail/mail.service.d.ts.map +1 -1
  39. package/dist/mail/mail.service.js +56 -4
  40. package/dist/mail/mail.service.js.map +1 -1
  41. package/dist/setting/setting.service.d.ts +6 -1
  42. package/dist/setting/setting.service.d.ts.map +1 -1
  43. package/dist/setting/setting.service.js +188 -15
  44. package/dist/setting/setting.service.js.map +1 -1
  45. package/hedhog/data/dashboard.yaml +12 -6
  46. package/hedhog/data/dashboard_component_role.yaml +66 -0
  47. package/hedhog/data/dashboard_role.yaml +2 -8
  48. package/hedhog/data/route.yaml +72 -0
  49. package/hedhog/data/setting_group.yaml +28 -0
  50. package/hedhog/frontend/app/dashboard/[slug]/dashboard-content.tsx.ejs +333 -128
  51. package/hedhog/frontend/app/dashboard/[slug]/widget-renderer.tsx.ejs +277 -53
  52. package/hedhog/frontend/app/dashboard/components/add-widget-selector-dialog.tsx.ejs +179 -231
  53. package/hedhog/frontend/app/dashboard/components/draggable-grid.tsx.ejs +64 -18
  54. package/hedhog/frontend/app/dashboard/dashboard-home-tabs.tsx.ejs +1619 -0
  55. package/hedhog/frontend/app/dashboard/dashboard.css.ejs +37 -0
  56. package/hedhog/frontend/app/dashboard/management/page.tsx.ejs +1 -1
  57. package/hedhog/frontend/app/dashboard/management/tabs/components-tab.tsx.ejs +6 -6
  58. package/hedhog/frontend/app/dashboard/management/tabs/dashboards-tab.tsx.ejs +8 -8
  59. package/hedhog/frontend/app/dashboard/management/tabs/items-tab.tsx.ejs +3 -3
  60. package/hedhog/frontend/app/dashboard/page.tsx.ejs +3 -25
  61. package/hedhog/frontend/messages/en.json +124 -2
  62. package/hedhog/frontend/messages/pt.json +123 -1
  63. package/hedhog/frontend/widgets/account-security.tsx.ejs +1 -1
  64. package/hedhog/frontend/widgets/active-users-card.tsx.ejs +2 -2
  65. package/hedhog/frontend/widgets/activity-timeline.tsx.ejs +1 -1
  66. package/hedhog/frontend/widgets/email-notifications.tsx.ejs +1 -1
  67. package/hedhog/frontend/widgets/locale-config.tsx.ejs +1 -1
  68. package/hedhog/frontend/widgets/login-history-chart.tsx.ejs +1 -1
  69. package/hedhog/frontend/widgets/mail-config.tsx.ejs +1 -1
  70. package/hedhog/frontend/widgets/mail-sent-card.tsx.ejs +2 -2
  71. package/hedhog/frontend/widgets/mail-sent-chart.tsx.ejs +1 -1
  72. package/hedhog/frontend/widgets/menus-card.tsx.ejs +2 -2
  73. package/hedhog/frontend/widgets/oauth-config.tsx.ejs +1 -1
  74. package/hedhog/frontend/widgets/permissions-card.tsx.ejs +2 -2
  75. package/hedhog/frontend/widgets/permissions-chart.tsx.ejs +1 -1
  76. package/hedhog/frontend/widgets/profile-card.tsx.ejs +1 -1
  77. package/hedhog/frontend/widgets/routes-card.tsx.ejs +2 -2
  78. package/hedhog/frontend/widgets/session-activity-chart.tsx.ejs +1 -1
  79. package/hedhog/frontend/widgets/sessions-today-card.tsx.ejs +2 -2
  80. package/hedhog/frontend/widgets/stat-access-level.tsx.ejs +1 -1
  81. package/hedhog/frontend/widgets/stat-actions-today.tsx.ejs +1 -1
  82. package/hedhog/frontend/widgets/stat-consecutive-days.tsx.ejs +1 -1
  83. package/hedhog/frontend/widgets/stat-online-time.tsx.ejs +1 -1
  84. package/hedhog/frontend/widgets/storage-config.tsx.ejs +1 -1
  85. package/hedhog/frontend/widgets/theme-config.tsx.ejs +1 -1
  86. package/hedhog/frontend/widgets/user-growth-chart.tsx.ejs +1 -1
  87. package/hedhog/frontend/widgets/user-roles.tsx.ejs +1 -1
  88. package/hedhog/frontend/widgets/user-sessions.tsx.ejs +1 -1
  89. package/hedhog/table/dashboard.yaml +6 -0
  90. package/package.json +3 -3
  91. package/src/ai/ai.service.ts +129 -1
  92. package/src/dashboard/dashboard-component/dashboard-component.controller.ts +15 -2
  93. package/src/dashboard/dashboard-component/dashboard-component.service.ts +107 -43
  94. package/src/dashboard/dashboard-core/dashboard-core.controller.ts +119 -1
  95. package/src/dashboard/dashboard-core/dashboard-core.service.ts +876 -20
  96. package/src/index.ts +7 -6
  97. package/src/mail/mail.service.ts +67 -3
  98. package/src/setting/setting.service.ts +222 -15
  99. package/hedhog/frontend/app/dashboard/components/widgets/core..gitkeep.ejs +0 -11
  100. package/hedhog/frontend/app/dashboard/components/widgets/core.account-security.tsx.ejs +0 -192
  101. package/hedhog/frontend/app/dashboard/components/widgets/core.active-users-card.tsx.ejs +0 -58
  102. package/hedhog/frontend/app/dashboard/components/widgets/core.activity-timeline.tsx.ejs +0 -223
  103. package/hedhog/frontend/app/dashboard/components/widgets/core.email-notifications.tsx.ejs +0 -226
  104. package/hedhog/frontend/app/dashboard/components/widgets/core.locale-config.tsx.ejs +0 -168
  105. package/hedhog/frontend/app/dashboard/components/widgets/core.login-history-chart.tsx.ejs +0 -115
  106. package/hedhog/frontend/app/dashboard/components/widgets/core.mail-config.tsx.ejs +0 -199
  107. package/hedhog/frontend/app/dashboard/components/widgets/core.mail-sent-card.tsx.ejs +0 -58
  108. package/hedhog/frontend/app/dashboard/components/widgets/core.mail-sent-chart.tsx.ejs +0 -149
  109. package/hedhog/frontend/app/dashboard/components/widgets/core.menus-card.tsx.ejs +0 -58
  110. package/hedhog/frontend/app/dashboard/components/widgets/core.oauth-config.tsx.ejs +0 -175
  111. package/hedhog/frontend/app/dashboard/components/widgets/core.permissions-card.tsx.ejs +0 -61
  112. package/hedhog/frontend/app/dashboard/components/widgets/core.permissions-chart.tsx.ejs +0 -156
  113. package/hedhog/frontend/app/dashboard/components/widgets/core.profile-card.tsx.ejs +0 -186
  114. package/hedhog/frontend/app/dashboard/components/widgets/core.routes-card.tsx.ejs +0 -58
  115. package/hedhog/frontend/app/dashboard/components/widgets/core.session-activity-chart.tsx.ejs +0 -183
  116. package/hedhog/frontend/app/dashboard/components/widgets/core.sessions-today-card.tsx.ejs +0 -62
  117. package/hedhog/frontend/app/dashboard/components/widgets/core.stat-access-level.tsx.ejs +0 -57
  118. package/hedhog/frontend/app/dashboard/components/widgets/core.stat-actions-today.tsx.ejs +0 -57
  119. package/hedhog/frontend/app/dashboard/components/widgets/core.stat-consecutive-days.tsx.ejs +0 -57
  120. package/hedhog/frontend/app/dashboard/components/widgets/core.stat-online-time.tsx.ejs +0 -57
  121. package/hedhog/frontend/app/dashboard/components/widgets/core.storage-config.tsx.ejs +0 -196
  122. package/hedhog/frontend/app/dashboard/components/widgets/core.theme-config.tsx.ejs +0 -213
  123. package/hedhog/frontend/app/dashboard/components/widgets/core.user-growth-chart.tsx.ejs +0 -210
  124. package/hedhog/frontend/app/dashboard/components/widgets/core.user-roles.tsx.ejs +0 -132
  125. package/hedhog/frontend/app/dashboard/components/widgets/core.user-sessions.tsx.ejs +0 -236
  126. package/hedhog/frontend/app/dashboard/components/widgets/finance.alerts.tsx.ejs +0 -108
  127. package/hedhog/frontend/app/dashboard/components/widgets/finance.cash-balance-kpi.tsx.ejs +0 -66
  128. package/hedhog/frontend/app/dashboard/components/widgets/finance.cash-flow-chart.tsx.ejs +0 -122
  129. package/hedhog/frontend/app/dashboard/components/widgets/finance.default-kpi.tsx.ejs +0 -63
  130. package/hedhog/frontend/app/dashboard/components/widgets/finance.payable-30d-kpi.tsx.ejs +0 -73
  131. package/hedhog/frontend/app/dashboard/components/widgets/finance.receivable-30d-kpi.tsx.ejs +0 -73
  132. package/hedhog/frontend/app/dashboard/components/widgets/finance.upcoming-payable.tsx.ejs +0 -123
  133. package/hedhog/frontend/app/dashboard/components/widgets/finance.upcoming-receivable.tsx.ejs +0 -118
@@ -1,192 +0,0 @@
1
- 'use client';
2
- import {
3
- Card,
4
- CardContent,
5
- CardDescription,
6
- CardHeader,
7
- CardTitle,
8
- } from '@/components/ui/card';
9
- import { Progress } from '@/components/ui/progress';
10
- import { useWidgetData } from '@/hooks/use-widget-data';
11
- import type { AllWidgetsData } from '@/types/widget-data';
12
- import {
13
- AlertTriangle,
14
- CheckCircle2,
15
- ChevronRight,
16
- Lock,
17
- Mail,
18
- ShieldCheck,
19
- Smartphone,
20
- } from 'lucide-react';
21
- import { useTranslations } from 'next-intl';
22
- import { useEffect, useState } from 'react';
23
-
24
- import type { AccountSecurityData } from '@/types/widget-data';
25
- import { useRouter } from 'next/navigation';
26
- import { WidgetWrapper } from '../widget-wrapper';
27
-
28
- const ICON_MAP: Record<string, React.ElementType> = {
29
- password: Lock,
30
- '2fa': Smartphone,
31
- email: Mail,
32
- sessions: AlertTriangle,
33
- };
34
-
35
- const CHECK_ROUTE_MAP: Record<string, string> = {
36
- password: '/core/account/password',
37
- '2fa': '/core/account/2fa',
38
- email: '/core/account/email',
39
- sessions: '/core/account/sessions',
40
- };
41
-
42
- function AccountSecurityContent({ data }: { data: AccountSecurityData }) {
43
- const t = useTranslations('core.DashboardPage.accountSecurity');
44
- const router = useRouter();
45
- const [score, setScore] = useState(0);
46
-
47
- useEffect(() => {
48
- const timer = setTimeout(() => setScore(data.score), 300);
49
- return () => clearTimeout(timer);
50
- }, [data.score]);
51
-
52
- const scoreColor =
53
- score >= 80
54
- ? 'text-emerald-600'
55
- : score >= 50
56
- ? 'text-amber-600'
57
- : 'text-red-600';
58
-
59
- const progressColor =
60
- score >= 80
61
- ? 'hsl(160, 84%, 39%)'
62
- : score >= 50
63
- ? 'hsl(38, 92%, 50%)'
64
- : 'hsl(0, 84%, 60%)';
65
-
66
- return (
67
- <Card className="flex h-full min-h-0 flex-col overflow-hidden">
68
- <CardHeader className="shrink-0 px-4 pb-2 pt-4 sm:px-5">
69
- <div className="flex items-center gap-2">
70
- <ShieldCheck className="h-5 w-5 text-emerald-600 dark:text-emerald-400" />
71
- <div>
72
- <CardTitle className="text-base font-semibold">
73
- {t('title')}
74
- </CardTitle>
75
- <CardDescription className="text-xs sm:text-sm">
76
- {t('description')}
77
- </CardDescription>
78
- </div>
79
- </div>
80
- </CardHeader>
81
- <CardContent className="flex min-h-0 flex-1 flex-col overflow-auto px-4 pb-3 pt-0 sm:px-5 sm:pb-4">
82
- <div className="mb-2 flex flex-col items-center gap-1.5 rounded-xl bg-muted/50 p-2 sm:mb-3 sm:gap-2 sm:p-3">
83
- <div className="flex items-baseline gap-1">
84
- <span
85
- className={`text-2xl font-bold tracking-tight sm:text-3xl ${scoreColor}`}
86
- >
87
- {score}
88
- </span>
89
- <span className="text-xs text-muted-foreground sm:text-sm">
90
- /100
91
- </span>
92
- </div>
93
- <Progress
94
- value={score}
95
- className="h-1.5 w-full max-w-70"
96
- style={
97
- {
98
- '--progress-foreground': progressColor,
99
- } as any
100
- }
101
- />
102
- <p className="text-[10px] text-muted-foreground sm:text-[11px]">
103
- {score >= 80 ? t('wellProtected') : t('recommendProtections')}
104
- </p>
105
- </div>
106
-
107
- <div className="flex flex-col gap-1">
108
- {data.checks.map((item) => {
109
- const Icon = ICON_MAP[item.id] ?? ShieldCheck;
110
- return (
111
- <button
112
- type="button"
113
- key={item.id}
114
- onClick={() =>
115
- router.push(CHECK_ROUTE_MAP[item.id] ?? '/core/account')
116
- }
117
- className="group flex w-full cursor-pointer flex-wrap items-start gap-2 rounded-lg p-2 text-left transition-colors hover:bg-muted/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring sm:items-center sm:gap-2.5 sm:p-2.5"
118
- >
119
- <div
120
- className={`flex h-7 w-7 shrink-0 items-center justify-center rounded-lg sm:h-8 sm:w-8 ${
121
- item.enabled
122
- ? 'bg-emerald-50 dark:bg-emerald-950/40'
123
- : 'bg-muted'
124
- }`}
125
- >
126
- <Icon
127
- className={`h-3.5 w-3.5 ${
128
- item.enabled
129
- ? 'text-emerald-600 dark:text-emerald-400'
130
- : 'text-muted-foreground'
131
- }`}
132
- />
133
- </div>
134
- <div className="flex min-w-0 flex-1 flex-col">
135
- <div className="flex flex-wrap items-center gap-2">
136
- <span className="wrap-break-word text-[12px] font-medium text-foreground sm:text-[13px]">
137
- {t(`labels.${item.labelKey}` as any) || item.labelKey}
138
- </span>
139
- {item.enabled ? (
140
- <CheckCircle2 className="h-3.5 w-3.5 text-emerald-500" />
141
- ) : (
142
- <AlertTriangle className="h-3.5 w-3.5 text-amber-500" />
143
- )}
144
- </div>
145
- <span className="text-[10px] text-muted-foreground sm:text-[11px]">
146
- {t(`descriptions.${item.descriptionKey}` as any) ||
147
- item.descriptionKey}
148
- </span>
149
- </div>
150
- <div className="mt-0.5 flex w-full shrink-0 items-center justify-end gap-1 text-[11px] font-medium text-foreground sm:mt-0 sm:w-auto sm:text-xs">
151
- {!item.enabled && <span>{t('activate')}</span>}
152
- <ChevronRight className="h-3 w-3" />
153
- </div>
154
- </button>
155
- );
156
- })}
157
- </div>
158
- </CardContent>
159
- </Card>
160
- );
161
- }
162
-
163
- interface AccountSecurityProps {
164
- widget?: { name?: string };
165
- onRemove?: () => void;
166
- }
167
-
168
- export default function AccountSecurity({
169
- widget,
170
- onRemove,
171
- }: AccountSecurityProps) {
172
- const { data, isLoading, isError, isAccessDenied } = useWidgetData<
173
- AllWidgetsData,
174
- AccountSecurityData
175
- >({
176
- endpoint: '/dashboard-core/widgets/me',
177
- queryKey: 'widget-me',
178
- select: (d) => d.accountSecurity,
179
- });
180
-
181
- return (
182
- <WidgetWrapper
183
- isLoading={isLoading}
184
- isError={isError}
185
- isAccessDenied={isAccessDenied}
186
- widgetName={widget?.name ?? 'account-security'}
187
- onRemove={onRemove}
188
- >
189
- {data && <AccountSecurityContent data={data} />}
190
- </WidgetWrapper>
191
- );
192
- }
@@ -1,58 +0,0 @@
1
- import { useWidgetData } from '@/hooks/use-widget-data';
2
- import { Users } from 'lucide-react';
3
- import { useTranslations } from 'next-intl';
4
- import StatCard from '../stats';
5
- import { WidgetWrapper } from '../widget-wrapper';
6
-
7
- interface ActiveUsersProps {
8
- widget?: any;
9
- onRemove?: () => void;
10
- }
11
-
12
- interface UserStatsData {
13
- cards?: {
14
- activeUsers?: {
15
- value: number;
16
- change: number | null;
17
- };
18
- };
19
- }
20
-
21
- export default function ActiveUsers({ widget, onRemove }: ActiveUsersProps) {
22
- const t = useTranslations('core.Dashboard');
23
-
24
- const { data, isLoading, isAccessDenied, isError } =
25
- useWidgetData<UserStatsData>({
26
- endpoint: '/dashboard-core/stats/overview/users',
27
- queryKey: 'dashboard-stats-users',
28
- });
29
-
30
- const value = data?.cards?.activeUsers?.value?.toLocaleString('pt-BR') || '0';
31
- const change = data?.cards?.activeUsers?.change;
32
- const changeType =
33
- change !== null && change !== undefined && change >= 0 ? 'up' : 'down';
34
-
35
- return (
36
- <WidgetWrapper
37
- isLoading={isLoading}
38
- isAccessDenied={isAccessDenied}
39
- isError={isError}
40
- widgetName={widget?.name || t('activeUsers')}
41
- onRemove={onRemove}
42
- >
43
- <StatCard
44
- title={t('activeUsers')}
45
- value={value}
46
- change={
47
- change !== null && change !== undefined
48
- ? `${change > 0 ? '+' : ''}${change}%`
49
- : undefined
50
- }
51
- changeType={changeType}
52
- icon={<Users className="h-6 w-6 text-blue-500" />}
53
- iconBg="bg-blue-500/10"
54
- delay={50}
55
- />
56
- </WidgetWrapper>
57
- );
58
- }
@@ -1,223 +0,0 @@
1
- 'use client';
2
-
3
- import { Badge } from '@/components/ui/badge';
4
- import {
5
- Card,
6
- CardContent,
7
- CardDescription,
8
- CardHeader,
9
- CardTitle,
10
- } from '@/components/ui/card';
11
- import { ScrollArea } from '@/components/ui/scroll-area';
12
- import { useWidgetData } from '@/hooks/use-widget-data';
13
- import type { ActivityEvent, AllWidgetsData } from '@/types/widget-data';
14
- import {
15
- FileEdit,
16
- LogIn,
17
- LogOut,
18
- Mail,
19
- Settings,
20
- ShieldAlert,
21
- UserCheck,
22
- } from 'lucide-react';
23
- import { useTranslations } from 'next-intl';
24
- import { WidgetWrapper } from '../widget-wrapper';
25
-
26
- const typeIconMap: Record<string, React.ElementType> = {
27
- login: LogIn,
28
- logout: LogOut,
29
- security: ShieldAlert,
30
- settings: Settings,
31
- edit: FileEdit,
32
- permission: UserCheck,
33
- email: Mail,
34
- };
35
-
36
- const typeColorMap: Record<string, { color: string; bg: string }> = {
37
- login: {
38
- color: 'text-blue-600 dark:text-blue-400',
39
- bg: 'bg-blue-50 dark:bg-blue-950/40',
40
- },
41
- logout: { color: 'text-muted-foreground', bg: 'bg-muted' },
42
- security: {
43
- color: 'text-amber-600 dark:text-amber-400',
44
- bg: 'bg-amber-50 dark:bg-amber-950/40',
45
- },
46
- settings: { color: 'text-foreground', bg: 'bg-muted' },
47
- edit: {
48
- color: 'text-indigo-600 dark:text-indigo-400',
49
- bg: 'bg-indigo-50 dark:bg-indigo-950/40',
50
- },
51
- permission: {
52
- color: 'text-emerald-600 dark:text-emerald-400',
53
- bg: 'bg-emerald-50 dark:bg-emerald-950/40',
54
- },
55
- email: {
56
- color: 'text-rose-600 dark:text-rose-400',
57
- bg: 'bg-rose-50 dark:bg-rose-950/40',
58
- },
59
- };
60
-
61
- function detectType(action: string): string {
62
- const a = action.toLowerCase();
63
- if (a.includes('login') || a.includes('entrou') || a.includes('acesso'))
64
- return 'login';
65
- if (a.includes('logout') || a.includes('saiu') || a.includes('encerr'))
66
- return 'logout';
67
- if (
68
- a.includes('senha') ||
69
- a.includes('2fa') ||
70
- a.includes('mfa') ||
71
- a.includes('segur')
72
- )
73
- return 'security';
74
- if (a.includes('config') || a.includes('idioma') || a.includes('preferên'))
75
- return 'settings';
76
- if (
77
- a.includes('edit') ||
78
- a.includes('atualiz') ||
79
- a.includes('alter') ||
80
- a.includes('perfil')
81
- )
82
- return 'edit';
83
- if (a.includes('permiss') || a.includes('acesso') || a.includes('role'))
84
- return 'permission';
85
- if (a.includes('email') || a.includes('e-mail') || a.includes('notif'))
86
- return 'email';
87
- return 'settings';
88
- }
89
-
90
- function formatDate(
91
- dateStr: string,
92
- tToday: string,
93
- tYesterday: string
94
- ): string {
95
- const date = new Date(dateStr);
96
- const now = new Date();
97
- const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
98
- const yesterday = new Date(today);
99
- yesterday.setDate(yesterday.getDate() - 1);
100
- const eventDay = new Date(
101
- date.getFullYear(),
102
- date.getMonth(),
103
- date.getDate()
104
- );
105
- if (eventDay.getTime() === today.getTime()) return tToday;
106
- if (eventDay.getTime() === yesterday.getTime()) return tYesterday;
107
- return date.toLocaleDateString(undefined, { day: '2-digit', month: 'short' });
108
- }
109
-
110
- function formatTime(dateStr: string): string {
111
- return new Date(dateStr).toLocaleTimeString('pt-BR', {
112
- hour: '2-digit',
113
- minute: '2-digit',
114
- });
115
- }
116
-
117
- function TimelineContent({ events }: { events: ActivityEvent[] }) {
118
- const t = useTranslations('core.DashboardPage.activityTimeline');
119
- let lastDate = '';
120
-
121
- return (
122
- <Card className="flex h-full min-h-0 flex-col overflow-hidden">
123
- <CardHeader className="shrink-0 pb-3">
124
- <div className="flex items-center justify-between">
125
- <div>
126
- <CardTitle className="text-sm font-semibold sm:text-base">
127
- {t('title')}
128
- </CardTitle>
129
- <CardDescription className="text-xs sm:text-sm">
130
- {t('description')}
131
- </CardDescription>
132
- </div>
133
- <Badge variant="secondary" className="text-[10px] sm:text-xs">
134
- {t('events', { count: events.length })}
135
- </Badge>
136
- </div>
137
- </CardHeader>
138
- <CardContent className="flex min-h-0 flex-1 flex-col overflow-hidden pt-0">
139
- <ScrollArea className="h-full pr-2 sm:pr-3">
140
- <div className="relative flex flex-col pb-2">
141
- <div className="absolute bottom-0 left-[13px] top-0 w-px bg-border/60 sm:left-[15px]" />
142
- {events.map((event, index) => {
143
- const type = detectType(event.action);
144
- const config =
145
- typeColorMap[type] ??
146
- (typeColorMap.settings as { color: string; bg: string });
147
- const Icon = (typeIconMap[type] ?? Settings) as React.ElementType;
148
- const dateLabel = formatDate(
149
- event.created_at,
150
- t('today'),
151
- t('yesterday')
152
- );
153
- const showDate = dateLabel !== lastDate;
154
- lastDate = dateLabel;
155
-
156
- return (
157
- <div key={event.id}>
158
- {showDate && (
159
- <div className="relative z-10 mb-1 mt-4 first:mt-0">
160
- <span className="ml-9 inline-block rounded-md border border-border bg-muted px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground sm:ml-11 sm:px-2 sm:text-[11px]">
161
- {dateLabel}
162
- </span>
163
- </div>
164
- )}
165
- <div className="group relative flex items-start gap-3 py-1.5">
166
- <div
167
- className={`relative z-10 mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-lg sm:h-8 sm:w-8 ${config.bg}`}
168
- >
169
- <Icon
170
- className={`h-3 w-3 sm:h-3.5 sm:w-3.5 ${config.color}`}
171
- />
172
- </div>
173
- <div className="flex min-w-0 flex-1 flex-col gap-0.5 rounded-lg px-1.5 py-1.5 transition-colors group-hover:bg-muted/40 sm:px-2">
174
- <div className="flex items-center justify-between gap-2">
175
- <span className="min-w-0 wrap-break-word text-xs font-medium leading-snug text-foreground sm:text-sm">
176
- {event.action}
177
- </span>
178
- <span className="shrink-0 text-[10px] tabular-nums text-muted-foreground sm:text-[11px]">
179
- {formatTime(event.created_at)}
180
- </span>
181
- </div>
182
- </div>
183
- </div>
184
- </div>
185
- );
186
- })}
187
- </div>
188
- </ScrollArea>
189
- </CardContent>
190
- </Card>
191
- );
192
- }
193
-
194
- interface ActivityTimelineProps {
195
- widget?: { name?: string };
196
- onRemove?: () => void;
197
- }
198
-
199
- export default function ActivityTimeline({
200
- widget,
201
- onRemove,
202
- }: ActivityTimelineProps) {
203
- const { data, isLoading, isError, isAccessDenied } = useWidgetData<
204
- AllWidgetsData,
205
- ActivityEvent[]
206
- >({
207
- endpoint: '/dashboard-core/widgets/me',
208
- queryKey: 'widget-me',
209
- select: (d) => d.activityTimeline,
210
- });
211
-
212
- return (
213
- <WidgetWrapper
214
- isLoading={isLoading}
215
- isError={isError}
216
- isAccessDenied={isAccessDenied}
217
- widgetName={widget?.name ?? 'activity-timeline'}
218
- onRemove={onRemove}
219
- >
220
- {data && <TimelineContent events={data} />}
221
- </WidgetWrapper>
222
- );
223
- }
@@ -1,226 +0,0 @@
1
- 'use client';
2
-
3
- import {
4
- Card,
5
- CardContent,
6
- CardDescription,
7
- CardHeader,
8
- CardTitle,
9
- } from '@/components/ui/card';
10
- import {
11
- ChartContainer,
12
- ChartTooltip,
13
- ChartTooltipContent,
14
- } from '@/components/ui/chart';
15
- import { useWidgetData } from '@/hooks/use-widget-data';
16
- import type {
17
- AllWidgetsData,
18
- EmailNotificationsData,
19
- } from '@/types/widget-data';
20
- import { Mail, MailCheck, MailWarning, MailX } from 'lucide-react';
21
- import { useTranslations } from 'next-intl';
22
- import { Area, AreaChart, CartesianGrid, XAxis, YAxis } from 'recharts';
23
- import { WidgetWrapper } from '../widget-wrapper';
24
-
25
- const defaultEmailNotificationsData: EmailNotificationsData = {
26
- cards: {
27
- received: 0,
28
- read: 0,
29
- unread: 0,
30
- error: 0,
31
- },
32
- chart: [],
33
- };
34
-
35
- interface EmailNotificationsProps {
36
- widget?: { name?: string };
37
- onRemove?: () => void;
38
- }
39
-
40
- export default function EmailNotifications({
41
- widget,
42
- onRemove,
43
- }: EmailNotificationsProps) {
44
- const t = useTranslations('core.DashboardPage.emailNotifications');
45
-
46
- const chartConfig = {
47
- recebidos: {
48
- label: t('received'),
49
- color: 'hsl(221, 83%, 53%)',
50
- },
51
- lidos: {
52
- label: t('read'),
53
- color: 'hsl(160, 84%, 39%)',
54
- },
55
- };
56
-
57
- const { data, isLoading, isError, isAccessDenied } = useWidgetData<
58
- AllWidgetsData,
59
- EmailNotificationsData
60
- >({
61
- endpoint: '/dashboard-core/widgets/me',
62
- queryKey: 'widget-me',
63
- select: (d) => d.emailNotifications,
64
- });
65
-
66
- const widgetData = data ?? defaultEmailNotificationsData;
67
- const chartData = widgetData.chart.map((point) => ({
68
- date: point.date,
69
- recebidos: point.received ?? 0,
70
- lidos: point.read ?? 0,
71
- }));
72
-
73
- const emailStats = [
74
- {
75
- label: t('received'),
76
- shortLabel: t('receivedShort'),
77
- value: widgetData.cards.received ?? 0,
78
- icon: Mail,
79
- color: 'text-blue-600 dark:text-blue-400',
80
- bg: 'bg-blue-50 dark:bg-blue-950/40',
81
- },
82
- {
83
- label: t('read'),
84
- shortLabel: t('readShort'),
85
- value: widgetData.cards.read ?? 0,
86
- icon: MailCheck,
87
- color: 'text-emerald-600 dark:text-emerald-400',
88
- bg: 'bg-emerald-50 dark:bg-emerald-950/40',
89
- },
90
- {
91
- label: t('unread'),
92
- shortLabel: t('unreadShort'),
93
- value: widgetData.cards.unread ?? 0,
94
- icon: MailWarning,
95
- color: 'text-amber-600 dark:text-amber-400',
96
- bg: 'bg-amber-50 dark:bg-amber-950/40',
97
- },
98
- {
99
- label: t('error'),
100
- shortLabel: t('errorShort'),
101
- value: widgetData.cards.error ?? 0,
102
- icon: MailX,
103
- color: 'text-red-600 dark:text-red-400',
104
- bg: 'bg-red-50 dark:bg-red-950/40',
105
- },
106
- ];
107
-
108
- return (
109
- <WidgetWrapper
110
- isLoading={isLoading}
111
- isError={isError}
112
- isAccessDenied={isAccessDenied}
113
- widgetName={widget?.name ?? t('title')}
114
- onRemove={onRemove}
115
- >
116
- <Card className="flex h-full min-h-0 flex-col overflow-hidden">
117
- <CardHeader className="shrink-0 pb-2">
118
- <div className="flex items-center gap-2">
119
- <Mail className="h-4 w-4 text-rose-600 dark:text-rose-400 sm:h-5 sm:w-5" />
120
- <div>
121
- <CardTitle className="text-sm font-semibold sm:text-base">
122
- {t('title')}
123
- </CardTitle>
124
- <CardDescription className="text-xs sm:text-sm">
125
- {t('description')}
126
- </CardDescription>
127
- </div>
128
- </div>
129
- </CardHeader>
130
- <CardContent className="flex min-h-0 flex-1 flex-col gap-4 overflow-hidden pt-0">
131
- <div className="grid grid-cols-2 gap-1.5 sm:gap-2 md:grid-cols-4">
132
- {emailStats.map((stat) => {
133
- const Icon = stat.icon;
134
- return (
135
- <div
136
- key={stat.label}
137
- className="flex min-w-0 flex-col items-center gap-1 rounded-lg border p-2 text-center transition-colors hover:bg-muted/30 sm:p-2.5"
138
- >
139
- <div
140
- className={`flex h-6 w-6 items-center justify-center rounded-md sm:h-7 sm:w-7 ${stat.bg}`}
141
- >
142
- <Icon
143
- className={`h-3 w-3 sm:h-3.5 sm:w-3.5 ${stat.color}`}
144
- />
145
- </div>
146
- <span className="text-base font-bold text-foreground sm:text-lg">
147
- {stat.value}
148
- </span>
149
- <span className="truncate text-[9px] text-muted-foreground sm:text-[10px]">
150
- <span className="sm:hidden">{stat.shortLabel}</span>
151
- <span className="hidden sm:inline">{stat.label}</span>
152
- </span>
153
- </div>
154
- );
155
- })}
156
- </div>
157
-
158
- <ChartContainer
159
- config={chartConfig}
160
- className="min-h-42.5 w-full flex-1 overflow-hidden sm:min-h-55"
161
- >
162
- <AreaChart data={chartData}>
163
- <CartesianGrid vertical={false} strokeDasharray="3 3" />
164
- <XAxis
165
- dataKey="date"
166
- tickLine={false}
167
- axisLine={false}
168
- fontSize={10}
169
- tickMargin={4}
170
- minTickGap={20}
171
- />
172
- <YAxis
173
- tickLine={false}
174
- axisLine={false}
175
- fontSize={10}
176
- tickMargin={4}
177
- allowDecimals={false}
178
- />
179
- <ChartTooltip content={<ChartTooltipContent />} />
180
- <defs>
181
- <linearGradient id="fillRecebidos" x1="0" y1="0" x2="0" y2="1">
182
- <stop
183
- offset="5%"
184
- stopColor="hsl(221, 83%, 53%)"
185
- stopOpacity={0.2}
186
- />
187
- <stop
188
- offset="95%"
189
- stopColor="hsl(221, 83%, 53%)"
190
- stopOpacity={0}
191
- />
192
- </linearGradient>
193
- <linearGradient id="fillLidos" x1="0" y1="0" x2="0" y2="1">
194
- <stop
195
- offset="5%"
196
- stopColor="hsl(160, 84%, 39%)"
197
- stopOpacity={0.2}
198
- />
199
- <stop
200
- offset="95%"
201
- stopColor="hsl(160, 84%, 39%)"
202
- stopOpacity={0}
203
- />
204
- </linearGradient>
205
- </defs>
206
- <Area
207
- type="monotone"
208
- dataKey="recebidos"
209
- stroke="hsl(221, 83%, 53%)"
210
- fill="url(#fillRecebidos)"
211
- strokeWidth={2}
212
- />
213
- <Area
214
- type="monotone"
215
- dataKey="lidos"
216
- stroke="hsl(160, 84%, 39%)"
217
- fill="url(#fillLidos)"
218
- strokeWidth={2}
219
- />
220
- </AreaChart>
221
- </ChartContainer>
222
- </CardContent>
223
- </Card>
224
- </WidgetWrapper>
225
- );
226
- }