@hedhog/admin 0.48.6 → 0.48.8

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 (176) hide show
  1. package/dist/admin.module.d.ts.map +1 -1
  2. package/dist/admin.module.js +2 -0
  3. package/dist/admin.module.js.map +1 -1
  4. package/dist/auth/consts/body.d.ts.map +1 -1
  5. package/dist/core/core.controller.d.ts +8 -1
  6. package/dist/core/core.controller.d.ts.map +1 -1
  7. package/dist/core/core.service.d.ts +8 -1
  8. package/dist/core/core.service.d.ts.map +1 -1
  9. package/dist/dashboard/dashboard/dashboard.controller.d.ts +22 -0
  10. package/dist/dashboard/dashboard/dashboard.controller.d.ts.map +1 -0
  11. package/dist/dashboard/dashboard/dashboard.controller.js +88 -0
  12. package/dist/dashboard/dashboard/dashboard.controller.js.map +1 -0
  13. package/dist/dashboard/dashboard/dashboard.module.d.ts +3 -0
  14. package/dist/dashboard/dashboard/dashboard.module.d.ts.map +1 -0
  15. package/dist/dashboard/dashboard/dashboard.module.js +26 -0
  16. package/dist/dashboard/dashboard/dashboard.module.js.map +1 -0
  17. package/dist/dashboard/dashboard/dashboard.service.d.ts +30 -0
  18. package/dist/dashboard/dashboard/dashboard.service.d.ts.map +1 -0
  19. package/dist/dashboard/dashboard/dashboard.service.js +61 -0
  20. package/dist/dashboard/dashboard/dashboard.service.js.map +1 -0
  21. package/dist/dashboard/dashboard/dto/create.dto.d.ts +5 -0
  22. package/dist/dashboard/dashboard/dto/create.dto.d.ts.map +1 -0
  23. package/dist/dashboard/dashboard/dto/create.dto.js +23 -0
  24. package/dist/dashboard/dashboard/dto/create.dto.js.map +1 -0
  25. package/dist/dashboard/dashboard/dto/update.dto.d.ts +6 -0
  26. package/dist/dashboard/dashboard/dto/update.dto.d.ts.map +1 -0
  27. package/dist/dashboard/dashboard/dto/update.dto.js +9 -0
  28. package/dist/dashboard/dashboard/dto/update.dto.js.map +1 -0
  29. package/dist/dashboard/dashboard-component/dashboard-component.controller.d.ts +22 -0
  30. package/dist/dashboard/dashboard-component/dashboard-component.controller.d.ts.map +1 -0
  31. package/dist/dashboard/dashboard-component/dashboard-component.controller.js +90 -0
  32. package/dist/dashboard/dashboard-component/dashboard-component.controller.js.map +1 -0
  33. package/dist/dashboard/dashboard-component/dashboard-component.module.d.ts +3 -0
  34. package/dist/dashboard/dashboard-component/dashboard-component.module.d.ts.map +1 -0
  35. package/dist/dashboard/dashboard-component/dashboard-component.module.js +26 -0
  36. package/dist/dashboard/dashboard-component/dashboard-component.module.js.map +1 -0
  37. package/dist/dashboard/dashboard-component/dashboard-component.service.d.ts +30 -0
  38. package/dist/dashboard/dashboard-component/dashboard-component.service.d.ts.map +1 -0
  39. package/dist/dashboard/dashboard-component/dashboard-component.service.js +59 -0
  40. package/dist/dashboard/dashboard-component/dashboard-component.service.js.map +1 -0
  41. package/dist/dashboard/dashboard-component/dto/create.dto.d.ts +13 -0
  42. package/dist/dashboard/dashboard-component/dto/create.dto.d.ts.map +1 -0
  43. package/dist/dashboard/dashboard-component/dto/create.dto.js +59 -0
  44. package/dist/dashboard/dashboard-component/dto/create.dto.js.map +1 -0
  45. package/dist/dashboard/dashboard-component/dto/update.dto.d.ts +6 -0
  46. package/dist/dashboard/dashboard-component/dto/update.dto.d.ts.map +1 -0
  47. package/dist/dashboard/dashboard-component/dto/update.dto.js +9 -0
  48. package/dist/dashboard/dashboard-component/dto/update.dto.js.map +1 -0
  49. package/dist/dashboard/dashboard-item/dashboard-item.controller.d.ts +52 -0
  50. package/dist/dashboard/dashboard-item/dashboard-item.controller.d.ts.map +1 -0
  51. package/dist/dashboard/dashboard-item/dashboard-item.controller.js +88 -0
  52. package/dist/dashboard/dashboard-item/dashboard-item.controller.js.map +1 -0
  53. package/dist/dashboard/dashboard-item/dashboard-item.module.d.ts +3 -0
  54. package/dist/dashboard/dashboard-item/dashboard-item.module.d.ts.map +1 -0
  55. package/dist/dashboard/dashboard-item/dashboard-item.module.js +26 -0
  56. package/dist/dashboard/dashboard-item/dashboard-item.module.js.map +1 -0
  57. package/dist/dashboard/dashboard-item/dashboard-item.service.d.ts +57 -0
  58. package/dist/dashboard/dashboard-item/dashboard-item.service.d.ts.map +1 -0
  59. package/dist/dashboard/dashboard-item/dashboard-item.service.js +77 -0
  60. package/dist/dashboard/dashboard-item/dashboard-item.service.js.map +1 -0
  61. package/dist/dashboard/dashboard-item/dto/create.dto.d.ts +9 -0
  62. package/dist/dashboard/dashboard-item/dto/create.dto.d.ts.map +1 -0
  63. package/dist/dashboard/dashboard-item/dto/create.dto.js +41 -0
  64. package/dist/dashboard/dashboard-item/dto/create.dto.js.map +1 -0
  65. package/dist/dashboard/dashboard-item/dto/update.dto.d.ts +6 -0
  66. package/dist/dashboard/dashboard-item/dto/update.dto.d.ts.map +1 -0
  67. package/dist/dashboard/dashboard-item/dto/update.dto.js +9 -0
  68. package/dist/dashboard/dashboard-item/dto/update.dto.js.map +1 -0
  69. package/dist/dashboard/dashboard-user/dashboard-user.controller.d.ts +52 -0
  70. package/dist/dashboard/dashboard-user/dashboard-user.controller.d.ts.map +1 -0
  71. package/dist/dashboard/dashboard-user/dashboard-user.controller.js +88 -0
  72. package/dist/dashboard/dashboard-user/dashboard-user.controller.js.map +1 -0
  73. package/dist/dashboard/dashboard-user/dashboard-user.module.d.ts +3 -0
  74. package/dist/dashboard/dashboard-user/dashboard-user.module.d.ts.map +1 -0
  75. package/dist/dashboard/dashboard-user/dashboard-user.module.js +26 -0
  76. package/dist/dashboard/dashboard-user/dashboard-user.module.js.map +1 -0
  77. package/dist/dashboard/dashboard-user/dashboard-user.service.d.ts +59 -0
  78. package/dist/dashboard/dashboard-user/dashboard-user.service.d.ts.map +1 -0
  79. package/dist/dashboard/dashboard-user/dashboard-user.service.js +83 -0
  80. package/dist/dashboard/dashboard-user/dashboard-user.service.js.map +1 -0
  81. package/dist/dashboard/dashboard-user/dto/create.dto.d.ts +10 -0
  82. package/dist/dashboard/dashboard-user/dto/create.dto.d.ts.map +1 -0
  83. package/dist/dashboard/dashboard-user/dto/create.dto.js +42 -0
  84. package/dist/dashboard/dashboard-user/dto/create.dto.js.map +1 -0
  85. package/dist/dashboard/dashboard-user/dto/update.dto.d.ts +6 -0
  86. package/dist/dashboard/dashboard-user/dto/update.dto.d.ts.map +1 -0
  87. package/dist/dashboard/dashboard-user/dto/update.dto.js +9 -0
  88. package/dist/dashboard/dashboard-user/dto/update.dto.js.map +1 -0
  89. package/dist/dashboard/dashboard.module.d.ts +3 -0
  90. package/dist/dashboard/dashboard.module.d.ts.map +1 -0
  91. package/dist/dashboard/dashboard.module.js +35 -0
  92. package/dist/dashboard/dashboard.module.js.map +1 -0
  93. package/dist/dashboard/index.d.ts +2 -0
  94. package/dist/dashboard/index.d.ts.map +1 -0
  95. package/dist/dashboard/index.js +18 -0
  96. package/dist/dashboard/index.js.map +1 -0
  97. package/dist/emails/lib.d.ts.map +1 -1
  98. package/dist/menu/menu.controller.d.ts +3 -3
  99. package/dist/menu/menu.service.d.ts +3 -3
  100. package/frontend/dashboard/components/create-panel.tsx.ejs +63 -0
  101. package/frontend/dashboard/components/dashboard.screen.tsx.ejs +116 -0
  102. package/frontend/dashboard/components/update-panel.tsx.ejs +80 -0
  103. package/frontend/dashboard/locales/en/dashboard.dashboard.json +11 -0
  104. package/frontend/dashboard/locales/pt/dashboard.dashboard.json +11 -0
  105. package/frontend/dashboard/react-query/handlers.ts.ejs +28 -0
  106. package/frontend/dashboard/react-query/requests.ts.ejs +56 -0
  107. package/frontend/dashboard-component/components/create-panel.tsx.ejs +130 -0
  108. package/frontend/dashboard-component/components/dashboard-component.screen.tsx.ejs +135 -0
  109. package/frontend/dashboard-component/components/update-panel.tsx.ejs +164 -0
  110. package/frontend/dashboard-component/locales/en/dashboard.dashboard-component.json +11 -0
  111. package/frontend/dashboard-component/locales/pt/dashboard.dashboard-component.json +11 -0
  112. package/frontend/dashboard-component/react-query/handlers.ts.ejs +28 -0
  113. package/frontend/dashboard-component/react-query/requests.ts.ejs +61 -0
  114. package/frontend/dashboard-item/components/create-panel.tsx.ejs +108 -0
  115. package/frontend/dashboard-item/components/dashboard-item.screen.tsx.ejs +133 -0
  116. package/frontend/dashboard-item/components/update-panel.tsx.ejs +141 -0
  117. package/frontend/dashboard-item/locales/en/dashboard.dashboard-item.json +11 -0
  118. package/frontend/dashboard-item/locales/pt/dashboard.dashboard-item.json +11 -0
  119. package/frontend/dashboard-item/react-query/handlers.ts.ejs +28 -0
  120. package/frontend/dashboard-item/react-query/requests.ts.ejs +58 -0
  121. package/frontend/dashboard-user/components/create-panel.tsx.ejs +108 -0
  122. package/frontend/dashboard-user/components/dashboard-user.screen.tsx.ejs +131 -0
  123. package/frontend/dashboard-user/components/update-panel.tsx.ejs +138 -0
  124. package/frontend/dashboard-user/locales/en/dashboard.dashboard-user.json +11 -0
  125. package/frontend/dashboard-user/locales/pt/dashboard.dashboard-user.json +11 -0
  126. package/frontend/dashboard-user/react-query/handlers.ts.ejs +28 -0
  127. package/frontend/dashboard-user/react-query/requests.ts.ejs +58 -0
  128. package/frontend/translation/fields/en.json +23 -1
  129. package/frontend/translation/fields/pt.json +27 -1
  130. package/frontend/translation/modules/en.json +6 -1
  131. package/frontend/translation/modules/pt.json +6 -1
  132. package/hedhog.yaml +439 -0
  133. package/package.json +2 -2
  134. package/src/admin.module.ts +2 -0
  135. package/src/dashboard/dashboard/dashboard.controller.ts +49 -0
  136. package/src/dashboard/dashboard/dashboard.module.ts +13 -0
  137. package/src/dashboard/dashboard/dashboard.service.ts +71 -0
  138. package/src/dashboard/dashboard/dto/create.dto.ts +8 -0
  139. package/src/dashboard/dashboard/dto/update.dto.ts +4 -0
  140. package/src/dashboard/dashboard-component/dashboard-component.controller.ts +55 -0
  141. package/src/dashboard/dashboard-component/dashboard-component.module.ts +14 -0
  142. package/src/dashboard/dashboard-component/dashboard-component.service.ts +70 -0
  143. package/src/dashboard/dashboard-component/dto/create.dto.ts +36 -0
  144. package/src/dashboard/dashboard-component/dto/update.dto.ts +4 -0
  145. package/src/dashboard/dashboard-item/dashboard-item.controller.ts +55 -0
  146. package/src/dashboard/dashboard-item/dashboard-item.module.ts +13 -0
  147. package/src/dashboard/dashboard-item/dashboard-item.service.ts +82 -0
  148. package/src/dashboard/dashboard-item/dto/create.dto.ts +22 -0
  149. package/src/dashboard/dashboard-item/dto/update.dto.ts +4 -0
  150. package/src/dashboard/dashboard-user/dashboard-user.controller.ts +55 -0
  151. package/src/dashboard/dashboard-user/dashboard-user.module.ts +13 -0
  152. package/src/dashboard/dashboard-user/dashboard-user.service.ts +89 -0
  153. package/src/dashboard/dashboard-user/dto/create.dto.ts +22 -0
  154. package/src/dashboard/dashboard-user/dto/update.dto.ts +4 -0
  155. package/src/dashboard/dashboard.module.ts +22 -0
  156. package/src/dashboard/index.ts +1 -0
  157. package/frontend/menu-locale/locales/en/admin.menu-locale.json +0 -11
  158. package/frontend/menu-locale/locales/pt/admin.menu-locale.json +0 -11
  159. package/frontend/menu-screen/locales/en/admin.menu-screen.json +0 -11
  160. package/frontend/menu-screen/locales/pt/admin.menu-screen.json +0 -11
  161. package/frontend/multifactor-locale/locales/en/admin.multifactor-locale.json +0 -11
  162. package/frontend/multifactor-locale/locales/pt/admin.multifactor-locale.json +0 -11
  163. package/frontend/screen-locale/locales/en/admin.screen-locale.json +0 -11
  164. package/frontend/screen-locale/locales/pt/admin.screen-locale.json +0 -11
  165. package/frontend/translation/components/create-panel.tsx.ejs +0 -52
  166. package/frontend/translation/components/update-panel.tsx.ejs +0 -67
  167. package/frontend/translation/locales/en/admin.translation.json +0 -11
  168. package/frontend/translation/locales/pt/admin.translation.json +0 -11
  169. package/frontend/translation/react-query/handlers.ts.ejs +0 -28
  170. package/frontend/translation/react-query/requests.ts.ejs +0 -58
  171. package/frontend/translation-namespace/components/create-panel.tsx.ejs +0 -53
  172. package/frontend/translation-namespace/components/update-panel.tsx.ejs +0 -70
  173. package/frontend/translation-namespace/locales/en/admin.translation-namespace.json +0 -11
  174. package/frontend/translation-namespace/locales/pt/admin.translation-namespace.json +0 -11
  175. package/frontend/translation-namespace/react-query/handlers.ts.ejs +0 -28
  176. package/frontend/translation-namespace/react-query/requests.ts.ejs +0 -60
@@ -0,0 +1,164 @@
1
+ import FormPanel, {
2
+ FormPanelRef,
3
+ getFieldsLocale,
4
+ } from '@/components/panels/form-panel'
5
+ import { Overlay } from '@/components/custom/overlay'
6
+ import { TabPanel } from '@/components/panels/tab-panel'
7
+ import {
8
+ useDashboardComponentGet,
9
+ useDashboardComponentUpdate,
10
+ } from '@/features/admin/dashboard-component'
11
+ import useEffectAfterFirstUpdate from '@/hooks/use-effect-after-first-update'
12
+ import { DashboardComponent } from '@/types/models'
13
+ import { forwardRef, useImperativeHandle, useRef } from 'react'
14
+ import { useTranslation } from 'react-i18next'
15
+ import { EnumFieldType } from '@/enums/EnumFieldType'
16
+
17
+ export type DashboardComponentUpdatePanelProps = {
18
+ data: DashboardComponent
19
+ onUpdated?: (data: DashboardComponent) => void
20
+ }
21
+
22
+ const DashboardComponentUpdatePanel = forwardRef(
23
+ ({ data, onUpdated }: DashboardComponentUpdatePanelProps, ref) => {
24
+ const { t } = useTranslation(['actions', 'fields', 'translations'])
25
+ const { data: item, isLoading } = useDashboardComponentGet(
26
+ (data as any).component_id as number
27
+ )
28
+ const { mutate: dashboardComponentUpdate } = useDashboardComponentUpdate()
29
+ const formRef = useRef<FormPanelRef>(null)
30
+
31
+ useEffectAfterFirstUpdate(() => {
32
+ if (item && formRef.current) {
33
+ formRef.current.setValuesFromItem(item)
34
+ }
35
+ }, [item])
36
+
37
+ useImperativeHandle(ref, () => ({}))
38
+
39
+ return (
40
+ <TabPanel
41
+ activeTabIndex={0}
42
+ tabs={[
43
+ {
44
+ title: t('details', { ns: 'actions' }),
45
+ children: (
46
+ <Overlay loading={isLoading}>
47
+ <FormPanel
48
+ ref={formRef}
49
+ fields={[
50
+ ...getFieldsLocale([{ name: 'name' }], item),
51
+ {
52
+ name: 'slug',
53
+ label: {
54
+ text: t('dashboard-component.slug', { ns: 'fields' }),
55
+ },
56
+ type: EnumFieldType.TEXT,
57
+ required: true,
58
+ },
59
+ {
60
+ name: 'path',
61
+ label: {
62
+ text: t('dashboard-component.path', { ns: 'fields' }),
63
+ },
64
+ type: EnumFieldType.TEXT,
65
+ required: true,
66
+ },
67
+ {
68
+ name: 'min_width',
69
+ label: {
70
+ text: t('dashboard-component.min_width', {
71
+ ns: 'fields',
72
+ }),
73
+ },
74
+ type: EnumFieldType.NUMBER,
75
+ required: true,
76
+ },
77
+ {
78
+ name: 'width',
79
+ label: {
80
+ text: t('dashboard-component.width', { ns: 'fields' }),
81
+ },
82
+ type: EnumFieldType.NUMBER,
83
+ required: true,
84
+ },
85
+ {
86
+ name: 'max_width',
87
+ label: {
88
+ text: t('dashboard-component.max_width', {
89
+ ns: 'fields',
90
+ }),
91
+ },
92
+ type: EnumFieldType.NUMBER,
93
+ required: true,
94
+ },
95
+ {
96
+ name: 'min_height',
97
+ label: {
98
+ text: t('dashboard-component.min_height', {
99
+ ns: 'fields',
100
+ }),
101
+ },
102
+ type: EnumFieldType.NUMBER,
103
+ required: true,
104
+ },
105
+ {
106
+ name: 'height',
107
+ label: {
108
+ text: t('dashboard-component.height', { ns: 'fields' }),
109
+ },
110
+ type: EnumFieldType.NUMBER,
111
+ required: true,
112
+ },
113
+ {
114
+ name: 'max_height',
115
+ label: {
116
+ text: t('dashboard-component.max_height', {
117
+ ns: 'fields',
118
+ }),
119
+ },
120
+ type: EnumFieldType.NUMBER,
121
+ required: true,
122
+ },
123
+ {
124
+ name: 'is_resizable',
125
+ label: {
126
+ text: t('dashboard-component.is_resizable', {
127
+ ns: 'fields',
128
+ }),
129
+ },
130
+ type: EnumFieldType.SWITCH,
131
+ required: true,
132
+ },
133
+ ]}
134
+ button={{ text: t('save', { ns: 'actions' }) }}
135
+ onSubmit={(data) => {
136
+ dashboardComponentUpdate({
137
+ id: data.id,
138
+ data: {
139
+ ...data,
140
+ min_width: Number(data.min_width),
141
+ width: Number(data.width),
142
+ max_width: Number(data.max_width),
143
+ min_height: Number(data.min_height),
144
+ height: Number(data.height),
145
+ max_height: Number(data.max_height),
146
+ },
147
+ })
148
+ if (typeof onUpdated === 'function') {
149
+ onUpdated(data)
150
+ }
151
+ }}
152
+ />
153
+ </Overlay>
154
+ ),
155
+ },
156
+ ]}
157
+ />
158
+ )
159
+ }
160
+ )
161
+
162
+ DashboardComponentUpdatePanel.displayName = 'DashboardComponentUpdatePanel'
163
+
164
+ export default DashboardComponentUpdatePanel
@@ -0,0 +1,11 @@
1
+ {
2
+ "create": "Create dashboard component",
3
+ "createText": "Fill the dashboard component informations.",
4
+ "createTooltip": "Create new dashboard component",
5
+ "delete": "Delete dashboard component",
6
+ "deleteText": "Are you sure to delete these dashboard components?",
7
+ "deleteTooltip": "Delete the selected dashboard component",
8
+ "edit": "Edit dashboard component",
9
+ "editText": "View and edit dashboard component information.",
10
+ "editTooltip": "Edit the selected dashboard component"
11
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "create": "Criar componente do dashboard",
3
+ "createText": "Preencha as informações do componente do dashboard.",
4
+ "createTooltip": "Criar novo componente do dashboard",
5
+ "delete": "Excluir componente do dashboard",
6
+ "deleteText": "Você tem certeza de que deseja excluir esses componentes do dashboard?",
7
+ "deleteTooltip": "Excluir o componente do dashboard selecionado",
8
+ "edit": "Editar componente do dashboard",
9
+ "editText": "Ver e editar as informações do componente do dashboard.",
10
+ "editTooltip": "Editar o componente do dashboard selecionado"
11
+ }
@@ -0,0 +1,28 @@
1
+ import { useDefaultMutation } from "@/hooks/use-default-mutation";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { requests } from "./requests";
4
+
5
+ const scope = "dashboard-component";
6
+
7
+ export function useDashboardComponentCreate() {
8
+ const { dashboardComponentCreate } = requests();
9
+ return useDefaultMutation(scope, "create", dashboardComponentCreate);
10
+ }
11
+
12
+ export function useDashboardComponentDelete() {
13
+ const { dashboardComponentDelete } = requests();
14
+ return useDefaultMutation(scope, "delete", dashboardComponentDelete);
15
+ }
16
+
17
+ export function useDashboardComponentUpdate() {
18
+ const { dashboardComponentUpdate } = requests();
19
+ return useDefaultMutation(scope, "update", dashboardComponentUpdate);
20
+ }
21
+
22
+ export function useDashboardComponentGet(id: number) {
23
+ const { dashboardComponentGet } = requests();
24
+ return useQuery({
25
+ queryKey: [scope, "get"],
26
+ queryFn: () => dashboardComponentGet(id),
27
+ });
28
+ }
@@ -0,0 +1,61 @@
1
+ import { useApp } from "@/hooks/use-app";
2
+ import { Delete, PaginationParams, PaginationResult } from "@/types";
3
+ import { DashboardComponent } from "@/types/models";
4
+ import { HttpMethod } from "@/types/http-method";
5
+ import { formatDataWithLocale } from "@hedhog/utils";
6
+
7
+ export function requests() {
8
+ const { request } = useApp();
9
+
10
+ const dashboardComponentList = async (params: PaginationParams) => {
11
+ return request<PaginationResult<DashboardComponent>>({
12
+ url: "/dashboard-component",
13
+ params,
14
+ }).then((res) => res.data);
15
+ };
16
+
17
+ const dashboardComponentGet = async (id: number) => {
18
+ return request<DashboardComponent>({
19
+ url: `/dashboard-component/${id}`,
20
+ }).then((res) => res.data);
21
+ };
22
+
23
+ const dashboardComponentCreate = async (params: {
24
+ data: DashboardComponent;
25
+ }) => {
26
+ const { data } = params;
27
+ return request<DashboardComponent>({
28
+ url: "/dashboard-component",
29
+ method: HttpMethod.POST,
30
+ data: formatDataWithLocale(data),
31
+ }).then((res) => res.data);
32
+ };
33
+
34
+ const dashboardComponentDelete = async (ids: number[]) => {
35
+ return request<Delete>({
36
+ url: "/dashboard-component",
37
+ data: { ids },
38
+ method: HttpMethod.DELETE,
39
+ }).then((res) => res.data);
40
+ };
41
+
42
+ const dashboardComponentUpdate = async (params: {
43
+ id: number;
44
+ data: DashboardComponent;
45
+ }) => {
46
+ const { id, data } = params;
47
+ return request<DashboardComponent>({
48
+ url: `/dashboard-component/${id}`,
49
+ method: HttpMethod.PATCH,
50
+ data: formatDataWithLocale(data),
51
+ }).then((res) => res.data);
52
+ };
53
+
54
+ return {
55
+ dashboardComponentCreate,
56
+ dashboardComponentUpdate,
57
+ dashboardComponentDelete,
58
+ dashboardComponentList,
59
+ dashboardComponentGet,
60
+ };
61
+ }
@@ -0,0 +1,108 @@
1
+ import FormPanel, { FormPanelRef } from '@/components/panels/form-panel'
2
+ import { EnumFieldType } from '@/enums/EnumFieldType'
3
+ import { useDashboardItemCreate } from '@/features/admin/dashboard-item'
4
+ import { DashboardItem } from '@/types/models'
5
+ import { forwardRef, useImperativeHandle, useRef } from 'react'
6
+ import { useTranslation } from 'react-i18next'
7
+
8
+ export type DashboardItemCreatePanelRef = {
9
+ submit: () => void
10
+ }
11
+
12
+ export type DashboardItemCreatePanelProps = {
13
+ onCreated?: (data: DashboardItem) => void
14
+ }
15
+
16
+ const DashboardItemCreatePanel = forwardRef(
17
+ ({ onCreated }: DashboardItemCreatePanelProps, ref) => {
18
+ const formRef = useRef<FormPanelRef>(null)
19
+ const { t } = useTranslation(['actions', 'fields', 'translations'])
20
+ const { mutateAsync: createDashboardItem } = useDashboardItemCreate()
21
+
22
+ useImperativeHandle(
23
+ ref,
24
+ () => ({
25
+ submit: () => {
26
+ formRef.current?.submit()
27
+ },
28
+ }),
29
+ [formRef]
30
+ )
31
+
32
+ return (
33
+ <FormPanel
34
+ ref={formRef}
35
+ fields={[
36
+ {
37
+ name: 'component_id',
38
+ label: { text: t('dashboard-item.component_id', { ns: 'fields' }) },
39
+ type: EnumFieldType.COMBOBOX,
40
+ required: true,
41
+ url: '/dashboard-component',
42
+ displayName: 'component',
43
+ valueName: 'id',
44
+ },
45
+
46
+ {
47
+ name: 'dashboard_id',
48
+ label: { text: t('dashboard-item.dashboard_id', { ns: 'fields' }) },
49
+ type: EnumFieldType.COMBOBOX,
50
+ required: true,
51
+ url: '/dashboard',
52
+ displayName: 'dashboard',
53
+ valueName: 'id',
54
+ },
55
+
56
+ {
57
+ name: 'width',
58
+ label: { text: t('dashboard-user.width', { ns: 'fields' }) },
59
+ type: EnumFieldType.NUMBER,
60
+ required: true,
61
+ },
62
+
63
+ {
64
+ name: 'height',
65
+ label: { text: t('dashboard-user.height', { ns: 'fields' }) },
66
+ type: EnumFieldType.NUMBER,
67
+ required: true,
68
+ },
69
+
70
+ {
71
+ name: 'x_axis',
72
+ label: { text: t('dashboard-user.x_axis', { ns: 'fields' }) },
73
+ type: EnumFieldType.NUMBER,
74
+ required: true,
75
+ },
76
+
77
+ {
78
+ name: 'y_axis',
79
+ label: { text: t('dashboard-user.y_axis', { ns: 'fields' }) },
80
+ type: EnumFieldType.NUMBER,
81
+ required: true,
82
+ },
83
+ ]}
84
+ button={{ text: t('create', { ns: 'actions' }) }}
85
+ onSubmit={async (data) => {
86
+ const createdData = await createDashboardItem({
87
+ data: {
88
+ ...data,
89
+ component_id: Number(data.component_id),
90
+ dashboard_id: Number(data.dashboard_id),
91
+ width: Number(data.width),
92
+ height: Number(data.height),
93
+ x_axis: Number(data.x_axis),
94
+ y_axis: Number(data.y_axis),
95
+ },
96
+ })
97
+ if (typeof onCreated === 'function') {
98
+ onCreated(createdData as any)
99
+ }
100
+ }}
101
+ />
102
+ )
103
+ }
104
+ )
105
+
106
+ DashboardItemCreatePanel.displayName = 'DashboardItemCreatePanel'
107
+
108
+ export default DashboardItemCreatePanel
@@ -0,0 +1,133 @@
1
+ import { PageTitle } from '@/components/custom/page-title'
2
+ import DataPanel from '@/components/panels/data-panel'
3
+ import { useDashboardItemDelete } from '@/features/admin/dashboard-item'
4
+ import { useApp } from '@/hooks/use-app'
5
+ import { isPlural } from '@/lib/utils'
6
+ import { DashboardItem } from '@/types/models'
7
+ import { IconEdit, IconPlus, IconTrash } from '@tabler/icons-react'
8
+ import { useState } from 'react'
9
+ import { useTranslation } from 'react-i18next'
10
+ import DashboardItemCreatePanel from './components/dashboard-item-create-panel'
11
+ import DashboardItemUpdatePanel from './components/dashboard-item-update-panel'
12
+ import DashboardItemCard from '@/components/cards/dashboard-item-card'
13
+
14
+ export default function Page() {
15
+ const [selectedItems, setSelectedItems] = useState<DashboardItem[]>([])
16
+ const { mutate: deleteDashboarditem } = useDashboardItemDelete()
17
+ const { openSheet, confirm, closeSheet } = useApp()
18
+ const { t } = useTranslation([
19
+ 'dashboard.dashboard-item',
20
+ 'modules',
21
+ 'actions',
22
+ 'fields',
23
+ ])
24
+
25
+ const openCreate = () => {
26
+ const id = openSheet({
27
+ title: t('create', { ns: 'dashboard.dashboard-item' }),
28
+ description: t('createText', {
29
+ ns: 'dashboard.dashboard-item',
30
+ }),
31
+ children: () => (
32
+ <DashboardItemCreatePanel onCreated={() => closeSheet(id)} />
33
+ ),
34
+ })
35
+
36
+ return id
37
+ }
38
+
39
+ const openDelete = (items: DashboardItem[]) => {
40
+ return confirm({
41
+ title: `${t('delete', { ns: 'dashboard.dashboard-item' })} ${items.length} ${isPlural(items.length) ? t('items', { ns: 'actions' }) : t('item', { ns: 'actions' })}`,
42
+ description: t('deleteText', {
43
+ ns: 'dashboard.dashboard-item',
44
+ }),
45
+ })
46
+ .then(() =>
47
+ deleteDashboarditem(
48
+ items
49
+ .map((item) => (item as any).item_id)
50
+ .filter((id) => id !== undefined)
51
+ )
52
+ )
53
+ .catch(() => setSelectedItems(items))
54
+ }
55
+
56
+ const openUpdate = (item: DashboardItem) => {
57
+ const id = openSheet({
58
+ children: () => (
59
+ <DashboardItemUpdatePanel
60
+ data={item}
61
+ onUpdated={() => closeSheet(id)}
62
+ />
63
+ ),
64
+ title: t('edit', { ns: 'dashboard.dashboard-item' }),
65
+ description: t('editText', {
66
+ ns: 'dashboard.dashboard-item',
67
+ }),
68
+ })
69
+
70
+ return id
71
+ }
72
+
73
+ return (
74
+ <>
75
+ <PageTitle title={t('dashboard_item', { ns: 'modules' })} />
76
+ <DataPanel
77
+ url='/dashboard-item'
78
+ layout='grid'
79
+ id='dashboard-item'
80
+ selectable
81
+ render={(item: DashboardItem) => <DashboardItemCard item={item} />}
82
+ responsiveColumns={{
83
+ default: 1,
84
+ sm: 2,
85
+ md: 1,
86
+ lg: 2,
87
+ xl: 3,
88
+ }}
89
+ selected={selectedItems as DashboardItem[]}
90
+ multiple
91
+ hasSearch
92
+ onItemDoubleClick={(item) => openUpdate(item)}
93
+ menuActions={[
94
+ {
95
+ icon: <IconEdit className='mr-1 w-8 cursor-pointer' />,
96
+ label: t('edit', { ns: 'actions' }),
97
+ tooltip: t('editTooltip', {
98
+ ns: 'dashboard.dashboard-item',
99
+ }),
100
+ handler: (items: DashboardItem[]) => {
101
+ if (items.length === 1) openUpdate(items[0])
102
+ },
103
+ show: 'once',
104
+ },
105
+ {
106
+ icon: <IconTrash className='mr-1 w-8 cursor-pointer' />,
107
+ label: t('delete', { ns: 'actions' }),
108
+ tooltip: t('deleteTooltip', {
109
+ ns: 'dashboard.dashboard-item',
110
+ }),
111
+ variant: 'destructive',
112
+ handler: (items: DashboardItem[]) => {
113
+ openDelete(items)
114
+ },
115
+ show: 'some',
116
+ },
117
+ {
118
+ icon: <IconPlus className='mr-1 w-8 cursor-pointer' />,
119
+ label: t('create', { ns: 'actions' }),
120
+ tooltip: t('createTooltip', {
121
+ ns: 'dashboard.dashboard-item',
122
+ }),
123
+ variant: 'default',
124
+ handler: () => {
125
+ openCreate()
126
+ },
127
+ show: 'none',
128
+ },
129
+ ]}
130
+ />
131
+ </>
132
+ )
133
+ }
@@ -0,0 +1,141 @@
1
+ import FormPanel, { FormPanelRef } from '@/components/panels/form-panel'
2
+ import { Overlay } from '@/components/custom/overlay'
3
+ import { TabPanel } from '@/components/panels/tab-panel'
4
+ import {
5
+ useDashboardItemGet,
6
+ useDashboardItemUpdate,
7
+ } from '@/features/admin/dashboard-item'
8
+ import useEffectAfterFirstUpdate from '@/hooks/use-effect-after-first-update'
9
+ import { DashboardItem } from '@/types/models'
10
+ import { forwardRef, useImperativeHandle, useRef } from 'react'
11
+ import { useTranslation } from 'react-i18next'
12
+ import { EnumFieldType } from '@/enums/EnumFieldType'
13
+
14
+ export type DashboardItemUpdatePanelProps = {
15
+ data: DashboardItem
16
+ onUpdated?: (data: DashboardItem) => void
17
+ }
18
+
19
+ const DashboardItemUpdatePanel = forwardRef(
20
+ ({ data, onUpdated }: DashboardItemUpdatePanelProps, ref) => {
21
+ const { t } = useTranslation(['actions', 'fields', 'translations'])
22
+ const { data: item, isLoading } = useDashboardItemGet(
23
+ (data as any).id as number
24
+ )
25
+ const { mutate: dashboardItemUpdate } = useDashboardItemUpdate()
26
+ const formRef = useRef<FormPanelRef>(null)
27
+
28
+ useEffectAfterFirstUpdate(() => {
29
+ if (item && formRef.current) {
30
+ formRef.current.setValuesFromItem(item)
31
+ }
32
+ }, [item])
33
+
34
+ useImperativeHandle(ref, () => ({}))
35
+
36
+ return (
37
+ <TabPanel
38
+ activeTabIndex={0}
39
+ tabs={[
40
+ {
41
+ title: t('details', { ns: 'actions' }),
42
+ children: (
43
+ <Overlay loading={isLoading}>
44
+ <FormPanel
45
+ ref={formRef}
46
+ fields={[
47
+ {
48
+ name: 'component_id',
49
+ label: {
50
+ text: t('dashboard-item.component_id', {
51
+ ns: 'fields',
52
+ }),
53
+ },
54
+ type: EnumFieldType.COMBOBOX,
55
+ required: true,
56
+ url: '/dashboard-component',
57
+ displayName: 'component',
58
+ valueName: 'id',
59
+ },
60
+
61
+ {
62
+ name: 'dashboard_id',
63
+ label: {
64
+ text: t('dashboard-item.dashboard_id', {
65
+ ns: 'fields',
66
+ }),
67
+ },
68
+ type: EnumFieldType.COMBOBOX,
69
+ required: true,
70
+ url: '/dashboard',
71
+ displayName: 'dashboard',
72
+ valueName: 'id',
73
+ },
74
+
75
+ {
76
+ name: 'width',
77
+ label: {
78
+ text: t('dashboard-user.width', { ns: 'fields' }),
79
+ },
80
+ type: EnumFieldType.NUMBER,
81
+ required: true,
82
+ },
83
+
84
+ {
85
+ name: 'height',
86
+ label: {
87
+ text: t('dashboard-user.height', { ns: 'fields' }),
88
+ },
89
+ type: EnumFieldType.NUMBER,
90
+ required: true,
91
+ },
92
+
93
+ {
94
+ name: 'x_axis',
95
+ label: {
96
+ text: t('dashboard-user.x_axis', { ns: 'fields' }),
97
+ },
98
+ type: EnumFieldType.NUMBER,
99
+ required: true,
100
+ },
101
+
102
+ {
103
+ name: 'y_axis',
104
+ label: {
105
+ text: t('dashboard-user.y_axis', { ns: 'fields' }),
106
+ },
107
+ type: EnumFieldType.NUMBER,
108
+ required: true,
109
+ },
110
+ ]}
111
+ button={{ text: t('save', { ns: 'actions' }) }}
112
+ onSubmit={(data) => {
113
+ dashboardItemUpdate({
114
+ id: data.id,
115
+ data: {
116
+ ...data,
117
+ component_id: Number(data.component_id),
118
+ dashboard_id: Number(data.dashboard_id),
119
+ width: Number(data.width),
120
+ height: Number(data.height),
121
+ x_axis: Number(data.x_axis),
122
+ y_axis: Number(data.y_axis),
123
+ },
124
+ })
125
+ if (typeof onUpdated === 'function') {
126
+ onUpdated(data)
127
+ }
128
+ }}
129
+ />
130
+ </Overlay>
131
+ ),
132
+ },
133
+ ]}
134
+ />
135
+ )
136
+ }
137
+ )
138
+
139
+ DashboardItemUpdatePanel.displayName = 'DashboardItemUpdatePanel'
140
+
141
+ export default DashboardItemUpdatePanel
@@ -0,0 +1,11 @@
1
+ {
2
+ "create": "Create dashboard item",
3
+ "createText": "Fill the dashboard item informations.",
4
+ "createTooltip": "Create new dashboard item",
5
+ "delete": "Delete dashboard item",
6
+ "deleteText": "Are you sure to delete these dashboard item?",
7
+ "deleteTooltip": "Delete the selected dashboard item",
8
+ "edit": "Edit dashboard item",
9
+ "editText": "View and edit dashboard item information.",
10
+ "editTooltip": "Edit the selected dashboard item"
11
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "create": "Criar item do painel",
3
+ "createText": "Preencha as informações do item do painel.",
4
+ "createTooltip": "Criar novo item do painel",
5
+ "delete": "Excluir item do painel",
6
+ "deleteText": "Você tem certeza que deseja excluir esses itens do painel?",
7
+ "deleteTooltip": "Excluir o(s) item(ns) do painel selecionado(s)",
8
+ "edit": "Editar item do painel",
9
+ "editText": "Visualizar e editar informações do item do painel.",
10
+ "editTooltip": "Editar o item do painel selecionado"
11
+ }