@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,58 +0,0 @@
1
- import { useWidgetData } from '@/hooks/use-widget-data';
2
- import { LayoutList } from 'lucide-react';
3
- import { useTranslations } from 'next-intl';
4
- import StatCard from '../stats';
5
- import { WidgetWrapper } from '../widget-wrapper';
6
-
7
- interface MenusCardProps {
8
- widget?: any;
9
- onRemove?: () => void;
10
- }
11
-
12
- interface SystemStatsData {
13
- cards?: {
14
- menus?: {
15
- value: number;
16
- change: number | null;
17
- };
18
- };
19
- }
20
-
21
- export default function MenusCard({ widget, onRemove }: MenusCardProps) {
22
- const t = useTranslations('core.Dashboard');
23
-
24
- const { data, isLoading, isAccessDenied, isError } =
25
- useWidgetData<SystemStatsData>({
26
- endpoint: '/dashboard-core/stats/overview/system',
27
- queryKey: 'dashboard-stats-system',
28
- });
29
-
30
- const value = data?.cards?.menus?.value?.toLocaleString('pt-BR') || '0';
31
- const change = data?.cards?.menus?.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('menus')}
41
- onRemove={onRemove}
42
- >
43
- <StatCard
44
- title={t('menus')}
45
- value={value}
46
- change={
47
- change !== null && change !== undefined
48
- ? `${change > 0 ? '+' : ''}${change}%`
49
- : undefined
50
- }
51
- changeType={changeType}
52
- icon={<LayoutList className="h-6 w-6 text-green-500" />}
53
- iconBg="bg-green-500/10"
54
- delay={50}
55
- />
56
- </WidgetWrapper>
57
- );
58
- }
@@ -1,175 +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 { useWidgetData } from '@/hooks/use-widget-data';
12
- import type {
13
- DashboardCoreConfigOverviewData,
14
- OAuthConfigWidgetData,
15
- } from '@/types/widget-data';
16
- import { CheckCircle2, KeyRound, XCircle } from 'lucide-react';
17
- import { useTranslations } from 'next-intl';
18
- import { WidgetWrapper } from '../widget-wrapper';
19
-
20
- const defaultOAuthConfigData: OAuthConfigWidgetData = {
21
- status: {
22
- isConfigured: false,
23
- enabledProviderCount: 0,
24
- configuredProviderCount: 0,
25
- connectedAccountCount: 0,
26
- },
27
- providers: [],
28
- };
29
-
30
- interface OAuthConfigProps {
31
- widget?: { name?: string };
32
- onRemove?: () => void;
33
- }
34
-
35
- export default function OAuthConfig({ widget, onRemove }: OAuthConfigProps) {
36
- const t = useTranslations('core.DashboardPage.oauthConfig');
37
-
38
- const { data, isLoading, isError, isAccessDenied } = useWidgetData<
39
- DashboardCoreConfigOverviewData,
40
- OAuthConfigWidgetData
41
- >({
42
- endpoint: '/dashboard-core/config/overview',
43
- queryKey: 'dashboard-core-config-overview',
44
- select: (d) => d.oauthConfig,
45
- });
46
-
47
- const oauthData = data ?? defaultOAuthConfigData;
48
-
49
- return (
50
- <WidgetWrapper
51
- isLoading={isLoading}
52
- isError={isError}
53
- isAccessDenied={isAccessDenied}
54
- widgetName={widget?.name ?? t('title')}
55
- onRemove={onRemove}
56
- >
57
- <Card className="flex h-full min-h-0 flex-col overflow-hidden">
58
- <CardHeader className="shrink-0">
59
- <div className="flex items-center justify-between gap-3">
60
- <div className="flex items-center gap-3">
61
- <div className="flex h-10 w-10 items-center justify-center rounded-lg bg-amber-50">
62
- <KeyRound className="h-5 w-5 text-amber-600" />
63
- </div>
64
- <div>
65
- <CardTitle className="text-base">{t('title')}</CardTitle>
66
- <CardDescription>{t('description')}</CardDescription>
67
- </div>
68
- </div>
69
- <Badge
70
- variant="secondary"
71
- className={
72
- oauthData.status.isConfigured
73
- ? 'bg-emerald-50 text-emerald-700'
74
- : 'bg-amber-50 text-amber-700'
75
- }
76
- >
77
- {oauthData.status.isConfigured ? t('configured') : t('pending')}
78
- </Badge>
79
- </div>
80
- </CardHeader>
81
- <CardContent className="flex min-h-0 flex-1 flex-col gap-4 overflow-hidden pt-0">
82
- <div className="grid grid-cols-3 gap-2">
83
- <div className="rounded-lg border bg-muted/30 p-3 text-center">
84
- <p className="text-[11px] text-muted-foreground">
85
- {t('enabled')}
86
- </p>
87
- <p className="mt-1 text-lg font-semibold">
88
- {oauthData.status.enabledProviderCount}
89
- </p>
90
- </div>
91
- <div className="rounded-lg border bg-muted/30 p-3 text-center">
92
- <p className="text-[11px] text-muted-foreground">
93
- {t('configuredProviders')}
94
- </p>
95
- <p className="mt-1 text-lg font-semibold">
96
- {oauthData.status.configuredProviderCount}
97
- </p>
98
- </div>
99
- <div className="rounded-lg border bg-muted/30 p-3 text-center">
100
- <p className="text-[11px] text-muted-foreground">
101
- {t('connectedAccounts')}
102
- </p>
103
- <p className="mt-1 text-lg font-semibold">
104
- {oauthData.status.connectedAccountCount}
105
- </p>
106
- </div>
107
- </div>
108
-
109
- <div className="min-h-0 flex-1 space-y-2 overflow-auto">
110
- {oauthData.providers.length > 0 ? (
111
- oauthData.providers.map((provider) => (
112
- <div key={provider.id} className="rounded-lg border p-3">
113
- <div className="flex items-center justify-between gap-2">
114
- <p className="text-sm font-medium">{provider.label}</p>
115
- <div className="flex items-center gap-1.5">
116
- <Badge
117
- variant="secondary"
118
- className={
119
- provider.enabled
120
- ? 'bg-emerald-50 text-emerald-700'
121
- : 'bg-muted text-muted-foreground'
122
- }
123
- >
124
- {provider.enabled ? (
125
- <>
126
- <CheckCircle2 className="mr-1 h-3 w-3" />
127
- {t('enabled')}
128
- </>
129
- ) : (
130
- <>
131
- <XCircle className="mr-1 h-3 w-3" />
132
- {t('disabled')}
133
- </>
134
- )}
135
- </Badge>
136
- <Badge
137
- variant="outline"
138
- className={
139
- provider.configured
140
- ? 'border-emerald-200 text-emerald-700'
141
- : 'text-muted-foreground'
142
- }
143
- >
144
- {provider.configured ? t('configured') : t('pending')}
145
- </Badge>
146
- </div>
147
- </div>
148
- <div className="mt-2 flex flex-wrap gap-3 text-[11px] text-muted-foreground">
149
- <span>
150
- {t('scopesCount', { count: provider.scopesCount })}
151
- </span>
152
- <span>
153
- {t('connectedUsers', { count: provider.connectedUsers })}
154
- </span>
155
- <span>
156
- {provider.missingKeys.length > 0
157
- ? t('missingKeys', {
158
- count: provider.missingKeys.length,
159
- })
160
- : t('allKeysPresent')}
161
- </span>
162
- </div>
163
- </div>
164
- ))
165
- ) : (
166
- <p className="text-xs text-muted-foreground">
167
- {t('noProviders')}
168
- </p>
169
- )}
170
- </div>
171
- </CardContent>
172
- </Card>
173
- </WidgetWrapper>
174
- );
175
- }
@@ -1,61 +0,0 @@
1
- import { useWidgetData } from '@/hooks/use-widget-data';
2
- import { Shield } from 'lucide-react';
3
- import { useTranslations } from 'next-intl';
4
- import StatCard from '../stats';
5
- import { WidgetWrapper } from '../widget-wrapper';
6
-
7
- interface PermissionsCardProps {
8
- widget?: any;
9
- onRemove?: () => void;
10
- }
11
-
12
- interface UserStatsData {
13
- cards?: {
14
- roles?: {
15
- value: number;
16
- change: number | null;
17
- };
18
- };
19
- }
20
-
21
- export default function PermissionsCard({
22
- widget,
23
- onRemove,
24
- }: PermissionsCardProps) {
25
- const t = useTranslations('core.Dashboard');
26
-
27
- const { data, isLoading, isAccessDenied, isError } =
28
- useWidgetData<UserStatsData>({
29
- endpoint: '/dashboard-core/stats/overview/users',
30
- queryKey: 'dashboard-stats-users',
31
- });
32
-
33
- const value = data?.cards?.roles?.value?.toLocaleString('pt-BR') || '0';
34
- const change = data?.cards?.roles?.change;
35
- const changeType =
36
- change !== null && change !== undefined && change >= 0 ? 'up' : 'down';
37
-
38
- return (
39
- <WidgetWrapper
40
- isLoading={isLoading}
41
- isAccessDenied={isAccessDenied}
42
- isError={isError}
43
- widgetName={widget?.name || t('permissions')}
44
- onRemove={onRemove}
45
- >
46
- <StatCard
47
- title={t('permissions')}
48
- value={value}
49
- change={
50
- change !== null && change !== undefined
51
- ? `${change > 0 ? '+' : ''}${change}%`
52
- : undefined
53
- }
54
- changeType={changeType}
55
- icon={<Shield className="h-6 w-6 text-rose-500" />}
56
- iconBg="bg-rose-500/10"
57
- delay={200}
58
- />
59
- </WidgetWrapper>
60
- );
61
- }
@@ -1,156 +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 { useWidgetData } from '@/hooks/use-widget-data';
11
- import { IconGripVertical } from '@tabler/icons-react';
12
- import { useTranslations } from 'next-intl';
13
- import { Cell, Pie, PieChart, ResponsiveContainer, Tooltip } from 'recharts';
14
- import { WidgetWrapper } from '../widget-wrapper';
15
-
16
- function CustomTooltip({
17
- active,
18
- payload,
19
- }: {
20
- active?: boolean;
21
- payload?: Array<{ name: string; value: number; payload: { color: string } }>;
22
- }) {
23
- const t = useTranslations('core.Dashboard');
24
- if (!active || !payload?.length) return null;
25
-
26
- const entry = payload[0];
27
- return (
28
- <div className="rounded-lg border bg-card px-3 py-2 shadow-xl">
29
- <p className="text-xs text-muted-foreground">
30
- <span
31
- className="mr-1.5 inline-block h-2 w-2 rounded-full"
32
- style={{ backgroundColor: entry?.payload.color }}
33
- />
34
- {entry?.name}: {entry?.value} {t('permissionsLowercase')}
35
- </p>
36
- </div>
37
- );
38
- }
39
-
40
- interface PermissionsChartProps {
41
- widget?: {
42
- name?: string;
43
- } | null;
44
- onRemove?: () => void;
45
- }
46
-
47
- interface PermissionDistributionItem {
48
- name: string;
49
- value: number;
50
- color: string;
51
- }
52
-
53
- interface UserStatsData {
54
- charts?: {
55
- permissionDistribution?: PermissionDistributionItem[];
56
- };
57
- }
58
-
59
- export default function PermissionsChart({
60
- widget,
61
- onRemove,
62
- }: PermissionsChartProps) {
63
- const t = useTranslations('core.Dashboard');
64
-
65
- const {
66
- data: statsData,
67
- isLoading,
68
- isAccessDenied,
69
- isError,
70
- } = useWidgetData<UserStatsData>({
71
- endpoint: '/dashboard-core/stats/overview/users',
72
- queryKey: 'dashboard-stats-users',
73
- });
74
-
75
- const data = statsData?.charts?.permissionDistribution || [];
76
- const total = data.reduce((sum, item) => sum + item.value, 0);
77
-
78
- return (
79
- <WidgetWrapper
80
- isLoading={isLoading}
81
- isAccessDenied={isAccessDenied}
82
- isError={isError}
83
- widgetName={widget?.name || t('permissionsDistributionTitle')}
84
- onRemove={onRemove}
85
- >
86
- <Card className="h-full flex flex-col group">
87
- <div
88
- className="drag-handle absolute top-3 left-4 z-10"
89
- style={{ cursor: 'grab' }}
90
- >
91
- <IconGripVertical className="text-muted-foreground/50 size-4 shrink-0" />
92
- </div>
93
- <CardHeader className="pb-2 pt-4 pl-10">
94
- <CardTitle className="text-base font-semibold">
95
- {t('permissionsDistributionTitle')}
96
- </CardTitle>
97
- <CardDescription>
98
- {t('permissionsDistributionDescription')}
99
- </CardDescription>
100
- </CardHeader>
101
- <CardContent className="flex-1 pt-0">
102
- <div className="flex h-full items-center justify-between gap-4 overflow-hidden">
103
- <div className="relative h-[280px] w-[280px] shrink-0">
104
- <ResponsiveContainer width="100%" height="100%">
105
- <PieChart>
106
- <Pie
107
- data={data}
108
- cx="50%"
109
- cy="50%"
110
- innerRadius={70}
111
- outerRadius={110}
112
- paddingAngle={4}
113
- dataKey="value"
114
- animationDuration={1200}
115
- strokeWidth={0}
116
- >
117
- {data.map((entry, index: number) => (
118
- <Cell key={`cell-${index}`} fill={entry.color} />
119
- ))}
120
- </Pie>
121
- <Tooltip content={<CustomTooltip />} />
122
- </PieChart>
123
- </ResponsiveContainer>
124
- <div className="absolute inset-0 flex flex-col items-center justify-center">
125
- <span className="text-2xl font-bold text-foreground">
126
- {total}
127
- </span>
128
- <span className="text-[10px] text-muted-foreground">
129
- {t('total')}
130
- </span>
131
- </div>
132
- </div>
133
- <div className="grid max-h-[280px] min-w-0 flex-1 grid-cols-2 content-start gap-x-4 gap-y-2 overflow-y-auto pr-2">
134
- {data.map((item) => (
135
- <div key={item.name} className="flex min-w-0 items-start gap-2.5">
136
- <div
137
- className="mt-1 h-2.5 w-2.5 shrink-0 rounded-sm"
138
- style={{ backgroundColor: item.color }}
139
- />
140
- <div className="flex min-w-0 flex-col">
141
- <span className="break-words text-xs font-medium leading-tight text-foreground">
142
- {item.name}
143
- </span>
144
- <span className="text-[11px] text-muted-foreground">
145
- {item.value} ({total ? Math.round((item.value / total) * 100) : 0}%)
146
- </span>
147
- </div>
148
- </div>
149
- ))}
150
- </div>
151
- </div>
152
- </CardContent>
153
- </Card>
154
- </WidgetWrapper>
155
- );
156
- }
@@ -1,186 +0,0 @@
1
- 'use client';
2
-
3
- import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
4
- import { Badge } from '@/components/ui/badge';
5
- import { Button } from '@/components/ui/button';
6
- import { Card, CardContent } from '@/components/ui/card';
7
- import { Separator } from '@/components/ui/separator';
8
- import { useWidgetData } from '@/hooks/use-widget-data';
9
- import { formatDateTime } from '@/lib/format-date';
10
- import { getPhotoUrl } from '@/lib/get-photo-url';
11
- import type { AllWidgetsData, ProfileData } from '@/types/widget-data';
12
- import { useApp } from '@hed-hog/next-app-provider';
13
- import {
14
- Calendar,
15
- CheckCircle2,
16
- Clock,
17
- Edit3,
18
- Globe,
19
- Mail,
20
- Shield,
21
- } from 'lucide-react';
22
- import { useTranslations } from 'next-intl';
23
- import { useRouter } from 'next/navigation';
24
- import { WidgetWrapper } from '../widget-wrapper';
25
-
26
- function getInitials(name: string): string {
27
- return name
28
- .split(' ')
29
- .filter(Boolean)
30
- .slice(0, 2)
31
- .map((n) => n[0]?.toUpperCase() ?? '')
32
- .join('');
33
- }
34
-
35
- function ProfileContent({ profile }: { profile: ProfileData }) {
36
- const { getSettingValue } = useApp();
37
- const router = useRouter();
38
- const t = useTranslations('core.DashboardPage.profileCard');
39
-
40
- return (
41
- <Card className="relative flex h-full flex-col overflow-hidden">
42
- <div className="absolute inset-x-0 top-0 h-28 bg-linear-to-br from-muted to-muted/50" />
43
- <CardContent className="relative flex flex-1 flex-col overflow-hidden pt-7 pb-12">
44
- <div className="flex flex-col items-center gap-4 sm:flex-row sm:items-end">
45
- <div className="relative">
46
- <Avatar className="h-20 w-20 border-4 border-card shadow-md">
47
- {profile.photo_id && (
48
- <AvatarImage
49
- src={getPhotoUrl(profile.photo_id)}
50
- alt={profile.name}
51
- />
52
- )}
53
- <AvatarFallback className="bg-foreground text-background text-xl font-bold">
54
- {getInitials(profile.name)}
55
- </AvatarFallback>
56
- </Avatar>
57
- <div className="absolute -bottom-0.5 -right-0.5 h-5 w-5 rounded-full border-2 border-card bg-emerald-500" />
58
- </div>
59
- <div className="flex flex-1 flex-col items-center gap-1 text-center sm:items-start sm:text-left">
60
- <div className="flex items-center gap-2">
61
- <h2 className="text-xl font-bold text-foreground">
62
- {profile.name}
63
- </h2>
64
- <CheckCircle2 className="h-4 w-4 text-blue-500" />
65
- </div>
66
- <p className="text-sm text-muted-foreground">{profile.role}</p>
67
- <div className="flex flex-wrap items-center gap-2 pt-1">
68
- <Badge
69
- variant="outline"
70
- className="border-emerald-200 bg-emerald-50 text-xs text-emerald-700 dark:border-emerald-800 dark:bg-emerald-950/40 dark:text-emerald-400"
71
- >
72
- {t('online')}
73
- </Badge>
74
- </div>
75
- </div>
76
- <Button
77
- onClick={() => router.push('/core/account/profile')}
78
- variant="outline"
79
- size="sm"
80
- className="shrink-0 gap-1.5"
81
- >
82
- <Edit3 className="h-3.5 w-3.5" />
83
- {t('editProfile')}
84
- </Button>
85
- </div>
86
-
87
- <Separator className="my-6" />
88
-
89
- <div className="grid grid-cols-1 gap-2 sm:grid-cols-2">
90
- <div className="flex items-center gap-2.5 rounded-lg p-2 transition-colors hover:bg-muted/50">
91
- <div className="flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-muted">
92
- <Mail className="h-4 w-4 text-muted-foreground" />
93
- </div>
94
- <div className="flex min-w-0 flex-col">
95
- <span className="text-[11px] text-muted-foreground">
96
- {t('email')}
97
- </span>
98
- <span className="truncate text-xs font-medium text-foreground">
99
- {profile.email}
100
- </span>
101
- </div>
102
- </div>
103
-
104
- <div className="flex items-center gap-2.5 rounded-lg p-2 transition-colors hover:bg-muted/50">
105
- <div className="flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-muted">
106
- <Calendar className="h-4 w-4 text-muted-foreground" />
107
- </div>
108
- <div className="flex min-w-0 flex-col">
109
- <span className="text-[11px] text-muted-foreground">
110
- {t('memberSinceLabel')}
111
- </span>
112
- <span className="truncate text-xs font-medium text-foreground">
113
- {formatDateTime(profile.memberSince, getSettingValue)}
114
- </span>
115
- </div>
116
- </div>
117
-
118
- <div className="flex items-center gap-2.5 rounded-lg p-2 transition-colors hover:bg-muted/50">
119
- <div className="flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-blue-50 dark:bg-blue-950/40">
120
- <Globe className="h-4 w-4 text-blue-600 dark:text-blue-400" />
121
- </div>
122
- <div className="flex min-w-0 flex-col">
123
- <span className="text-[11px] text-muted-foreground">
124
- {t('activeSessions')}
125
- </span>
126
- <span className="text-xs font-semibold text-foreground">
127
- {profile.totalSessions}
128
- </span>
129
- </div>
130
- </div>
131
-
132
- <div className="flex items-center gap-2.5 rounded-lg p-2 transition-colors hover:bg-muted/50">
133
- <div className="flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-amber-50 dark:bg-amber-950/40">
134
- <Shield className="h-4 w-4 text-amber-600 dark:text-amber-400" />
135
- </div>
136
- <div className="flex min-w-0 flex-col">
137
- <span className="text-[11px] text-muted-foreground">
138
- {t('roles')}
139
- </span>
140
- <span className="text-xs font-semibold text-foreground">
141
- {profile.totalRoles}
142
- </span>
143
- </div>
144
- </div>
145
- </div>
146
- </CardContent>
147
-
148
- <div className="absolute bottom-0 inset-x-0 flex items-center gap-2 border-t bg-card px-4 py-2">
149
- <Clock className="h-3.5 w-3.5 shrink-0 text-muted-foreground" />
150
- <span className="truncate text-xs text-muted-foreground">
151
- {t('lastLogin', {
152
- date: formatDateTime(profile.lastLogin, getSettingValue),
153
- })}
154
- </span>
155
- </div>
156
- </Card>
157
- );
158
- }
159
-
160
- interface ProfileCardProps {
161
- widget?: { name?: string };
162
- onRemove?: () => void;
163
- }
164
-
165
- export default function ProfileCard({ widget, onRemove }: ProfileCardProps) {
166
- const { data, isLoading, isError, isAccessDenied } = useWidgetData<
167
- AllWidgetsData,
168
- ProfileData
169
- >({
170
- endpoint: '/dashboard-core/widgets/me',
171
- queryKey: 'widget-me',
172
- select: (d) => d.profile,
173
- });
174
-
175
- return (
176
- <WidgetWrapper
177
- isLoading={isLoading}
178
- isError={isError}
179
- isAccessDenied={isAccessDenied}
180
- widgetName={widget?.name ?? 'profile-card'}
181
- onRemove={onRemove}
182
- >
183
- {data && <ProfileContent profile={data} />}
184
- </WidgetWrapper>
185
- );
186
- }
@@ -1,58 +0,0 @@
1
- import { useWidgetData } from '@/hooks/use-widget-data';
2
- import { Route } from 'lucide-react';
3
- import { useTranslations } from 'next-intl';
4
- import StatCard from '../stats';
5
- import { WidgetWrapper } from '../widget-wrapper';
6
-
7
- interface RoutesCardProps {
8
- widget?: any;
9
- onRemove?: () => void;
10
- }
11
-
12
- interface SystemStatsData {
13
- cards?: {
14
- routes?: {
15
- value: number;
16
- change: number | null;
17
- };
18
- };
19
- }
20
-
21
- export default function RoutesCard({ widget, onRemove }: RoutesCardProps) {
22
- const t = useTranslations('core.Dashboard');
23
-
24
- const { data, isLoading, isAccessDenied, isError } =
25
- useWidgetData<SystemStatsData>({
26
- endpoint: '/dashboard-core/stats/overview/system',
27
- queryKey: 'dashboard-stats-system',
28
- });
29
-
30
- const value = data?.cards?.routes?.value?.toLocaleString('pt-BR') || '0';
31
- const change = data?.cards?.routes?.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('routes')}
41
- onRemove={onRemove}
42
- >
43
- <StatCard
44
- title={t('routes')}
45
- value={value}
46
- change={
47
- change !== null && change !== undefined
48
- ? `${change > 0 ? '+' : ''}${change}%`
49
- : undefined
50
- }
51
- changeType={changeType}
52
- icon={<Route className="h-6 w-6 text-orange-500" />}
53
- iconBg="bg-orange-500/10"
54
- delay={50}
55
- />
56
- </WidgetWrapper>
57
- );
58
- }