@hedhog/setting 0.0.6 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/setting/dto/create.dto.d.ts +8 -0
- package/dist/setting/dto/create.dto.d.ts.map +1 -0
- package/dist/setting/dto/create.dto.js +36 -0
- package/dist/setting/dto/create.dto.js.map +1 -0
- package/dist/setting/dto/delete.dto.d.ts.map +1 -0
- package/dist/setting/dto/delete.dto.js.map +1 -0
- package/dist/setting/dto/setting-user.dto.d.ts +4 -0
- package/dist/setting/dto/setting-user.dto.d.ts.map +1 -0
- package/dist/{dto/create.dto.js → setting/dto/setting-user.dto.js} +6 -7
- package/dist/setting/dto/setting-user.dto.js.map +1 -0
- package/dist/setting/dto/setting.dto.d.ts +9 -0
- package/dist/setting/dto/setting.dto.d.ts.map +1 -0
- package/dist/setting/dto/setting.dto.js +34 -0
- package/dist/setting/dto/setting.dto.js.map +1 -0
- package/dist/setting/dto/update.dto.d.ts +6 -0
- package/dist/setting/dto/update.dto.d.ts.map +1 -0
- package/dist/{dto → setting/dto}/update.dto.js +2 -1
- package/dist/setting/dto/update.dto.js.map +1 -0
- package/dist/setting/setting.controller.d.ts +25 -0
- package/dist/setting/setting.controller.d.ts.map +1 -0
- package/dist/setting/setting.controller.js +149 -0
- package/dist/setting/setting.controller.js.map +1 -0
- package/dist/setting/setting.service.d.ts +28 -0
- package/dist/setting/setting.service.d.ts.map +1 -0
- package/dist/setting/setting.service.js +296 -0
- package/dist/setting/setting.service.js.map +1 -0
- package/dist/setting.module.d.ts +3 -0
- package/dist/setting.module.d.ts.map +1 -0
- package/dist/{settings.module.js → setting.module.js} +8 -8
- package/dist/setting.module.js.map +1 -0
- package/frontend/setting/components/create-panel.tsx +83 -0
- package/frontend/setting/components/setting.screen.tsx +105 -0
- package/frontend/setting/components/update-panel.tsx +96 -0
- package/frontend/setting/locales/en/setting.setting.json +11 -0
- package/frontend/setting/locales/pt/setting.setting.json +11 -0
- package/frontend/setting/react-query/handlers.ts +28 -0
- package/frontend/setting/react-query/requests.ts +55 -0
- package/frontend/setting-group/components/create-panel.tsx +62 -0
- package/frontend/setting-group/components/setting-group.screen.tsx +107 -0
- package/frontend/setting-group/components/update-panel.tsx +76 -0
- package/frontend/setting-group/locales/en/setting.setting-group.json +11 -0
- package/frontend/setting-group/locales/pt/setting.setting-group.json +11 -0
- package/frontend/setting-group/react-query/handlers.ts +28 -0
- package/frontend/setting-group/react-query/requests.ts +58 -0
- package/frontend/setting-user/components/create-panel.tsx +71 -0
- package/frontend/setting-user/components/setting-user.screen.tsx +107 -0
- package/frontend/setting-user/components/update-panel.tsx +85 -0
- package/frontend/setting-user/locales/en/setting.setting-user.json +11 -0
- package/frontend/setting-user/locales/pt/setting.setting-user.json +11 -0
- package/frontend/setting-user/react-query/handlers.ts +28 -0
- package/frontend/setting-user/react-query/requests.ts +57 -0
- package/hedhog.yaml +380 -0
- package/package.json +37 -29
- package/README.md +0 -108
- package/dist/dto/create.dto.d.ts +0 -4
- package/dist/dto/create.dto.d.ts.map +0 -1
- package/dist/dto/create.dto.js.map +0 -1
- package/dist/dto/delete.dto.d.ts.map +0 -1
- package/dist/dto/delete.dto.js.map +0 -1
- package/dist/dto/update.dto.d.ts +0 -4
- package/dist/dto/update.dto.d.ts.map +0 -1
- package/dist/dto/update.dto.js.map +0 -1
- package/dist/migrations/index.d.ts +0 -6
- package/dist/migrations/index.d.ts.map +0 -1
- package/dist/migrations/index.js +0 -67
- package/dist/migrations/index.js.map +0 -1
- package/dist/settings.controller.d.ts +0 -14
- package/dist/settings.controller.d.ts.map +0 -1
- package/dist/settings.controller.js +0 -95
- package/dist/settings.controller.js.map +0 -1
- package/dist/settings.module.d.ts +0 -3
- package/dist/settings.module.d.ts.map +0 -1
- package/dist/settings.module.js.map +0 -1
- package/dist/settings.service.d.ts +0 -19
- package/dist/settings.service.d.ts.map +0 -1
- package/dist/settings.service.js +0 -70
- package/dist/settings.service.js.map +0 -1
- package/src/dto/create.dto.ts +0 -7
- package/src/dto/delete.dto.ts +0 -8
- package/src/dto/update.dto.ts +0 -3
- package/src/index.ts +0 -2
- package/src/migrations/index.ts +0 -78
- package/src/settings.controller.ts +0 -65
- package/src/settings.module.ts +0 -18
- package/src/settings.service.ts +0 -75
- package/tsconfig.lib.json +0 -9
- package/tsconfig.production.json +0 -20
- /package/dist/{dto → setting/dto}/delete.dto.d.ts +0 -0
- /package/dist/{dto → setting/dto}/delete.dto.js +0 -0
@@ -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 = "setting";
|
6
|
+
|
7
|
+
export function useSettingCreate() {
|
8
|
+
const { settingCreate } = requests();
|
9
|
+
return useDefaultMutation(scope, "create", settingCreate);
|
10
|
+
}
|
11
|
+
|
12
|
+
export function useSettingDelete() {
|
13
|
+
const { settingDelete } = requests();
|
14
|
+
return useDefaultMutation(scope, "delete", settingDelete);
|
15
|
+
}
|
16
|
+
|
17
|
+
export function useSettingUpdate() {
|
18
|
+
const { settingUpdate } = requests();
|
19
|
+
return useDefaultMutation(scope, "update", settingUpdate);
|
20
|
+
}
|
21
|
+
|
22
|
+
export function useSettingGet(id: number) {
|
23
|
+
const { settingGet } = requests();
|
24
|
+
return useQuery({
|
25
|
+
queryKey: [scope, "get"],
|
26
|
+
queryFn: () => settingGet(id),
|
27
|
+
});
|
28
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import { useApp } from "@/hooks/use-app";
|
2
|
+
import { Delete, PaginationParams, PaginationResult } from "@/types";
|
3
|
+
import { Setting } 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 settingList = async (params: PaginationParams) => {
|
11
|
+
return request<PaginationResult<Setting>>({
|
12
|
+
url: "/setting",
|
13
|
+
params,
|
14
|
+
}).then((res) => res.data);
|
15
|
+
};
|
16
|
+
|
17
|
+
const settingGet = async (id: number) => {
|
18
|
+
return request<Setting>({
|
19
|
+
url: `/setting/${id}`,
|
20
|
+
}).then((res) => res.data);
|
21
|
+
};
|
22
|
+
|
23
|
+
const settingCreate = async (data: Setting) => {
|
24
|
+
return request<Setting>({
|
25
|
+
url: "/setting",
|
26
|
+
method: HttpMethod.POST,
|
27
|
+
data: formatDataWithLocale(data),
|
28
|
+
}).then((res) => res.data);
|
29
|
+
};
|
30
|
+
|
31
|
+
const settingDelete = async (ids: number[]) => {
|
32
|
+
return request<Delete>({
|
33
|
+
url: "/setting",
|
34
|
+
data: { ids },
|
35
|
+
method: HttpMethod.DELETE,
|
36
|
+
}).then((res) => res.data);
|
37
|
+
};
|
38
|
+
|
39
|
+
const settingUpdate = async (params: { id: number; data: Setting }) => {
|
40
|
+
const { id, data } = params;
|
41
|
+
return request<Setting>({
|
42
|
+
url: `/setting/${id}`,
|
43
|
+
method: HttpMethod.PATCH,
|
44
|
+
data: formatDataWithLocale(data),
|
45
|
+
}).then((res) => res.data);
|
46
|
+
};
|
47
|
+
|
48
|
+
return {
|
49
|
+
settingCreate,
|
50
|
+
settingUpdate,
|
51
|
+
settingDelete,
|
52
|
+
settingList,
|
53
|
+
settingGet,
|
54
|
+
};
|
55
|
+
}
|
@@ -0,0 +1,62 @@
|
|
1
|
+
import FormPanel, {
|
2
|
+
FormPanelRef,
|
3
|
+
getFieldsLocale,
|
4
|
+
} from "@/components/panels/form-panel";
|
5
|
+
import { EnumFieldType } from "@/enums/EnumFieldType";
|
6
|
+
import { useSettingGroupCreate } from "@/features/blog/setting-group";
|
7
|
+
import { SettingGroup } from "@/types/models";
|
8
|
+
import { forwardRef, useImperativeHandle, useRef } from "react";
|
9
|
+
import { useTranslation } from "react-i18next";
|
10
|
+
|
11
|
+
export type SettingGroupCreatePanelRef = {
|
12
|
+
submit: () => void;
|
13
|
+
};
|
14
|
+
|
15
|
+
export type SettingGroupCreatePanelProps = {
|
16
|
+
onCreated?: (data: SettingGroup) => void;
|
17
|
+
};
|
18
|
+
|
19
|
+
const SettingGroupCreatePanel = forwardRef(
|
20
|
+
({ onCreated }: SettingGroupCreatePanelProps, ref) => {
|
21
|
+
const formRef = useRef<FormPanelRef>(null);
|
22
|
+
const { t } = useTranslation(["actions"]);
|
23
|
+
const { mutateAsync: createSettingGroup } = useSettingGroupCreate();
|
24
|
+
|
25
|
+
useImperativeHandle(
|
26
|
+
ref,
|
27
|
+
() => ({
|
28
|
+
submit: () => {
|
29
|
+
formRef.current?.submit();
|
30
|
+
},
|
31
|
+
}),
|
32
|
+
[formRef],
|
33
|
+
);
|
34
|
+
|
35
|
+
return (
|
36
|
+
<FormPanel
|
37
|
+
ref={formRef}
|
38
|
+
fields={[
|
39
|
+
{
|
40
|
+
name: "icon",
|
41
|
+
label: { text: t("icon", { ns: "translation" }) },
|
42
|
+
type: EnumFieldType.TEXT,
|
43
|
+
required: true,
|
44
|
+
},
|
45
|
+
|
46
|
+
...getFieldsLocale([{ name: "name" }]),
|
47
|
+
]}
|
48
|
+
button={{ text: t("create", { ns: "actions" }) }}
|
49
|
+
onSubmit={async (data) => {
|
50
|
+
const createdData = await createSettingGroup(data);
|
51
|
+
if (typeof onCreated === "function") {
|
52
|
+
onCreated(createdData);
|
53
|
+
}
|
54
|
+
}}
|
55
|
+
/>
|
56
|
+
);
|
57
|
+
},
|
58
|
+
);
|
59
|
+
|
60
|
+
SettingGroupCreatePanel.displayName = "SettingGroupCreatePanel";
|
61
|
+
|
62
|
+
export default SettingGroupCreatePanel;
|
@@ -0,0 +1,107 @@
|
|
1
|
+
import { PageTitle } from "@/components/custom/page-title";
|
2
|
+
import DataPanel from "@/components/panels/data-panel";
|
3
|
+
import { useSettingGroupDelete } from "@/features/blog/setting-group";
|
4
|
+
import { useApp } from "@/hooks/use-app";
|
5
|
+
import { isPlural } from "@/lib/utils";
|
6
|
+
import { SettingGroup } 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 SettingGroupCreatePanel from "./components/setting-group-create-panel";
|
11
|
+
import SettingGroupUpdatePanel from "./components/setting-group-update-panel";
|
12
|
+
|
13
|
+
export default function Page() {
|
14
|
+
const [selectedItems, setSelectedItems] = useState<SettingGroup[]>([]);
|
15
|
+
const { mutate: deleteSettingGroup } = useSettingGroupDelete();
|
16
|
+
const { openSheet, confirm, closeSheet } = useApp();
|
17
|
+
const { t } = useTranslation(["setting-group", "modules", "actions"]);
|
18
|
+
|
19
|
+
const openCreate = () => {
|
20
|
+
const id = openSheet({
|
21
|
+
title: t("create", { ns: "actions" }),
|
22
|
+
description: t("createText", { ns: "setting-group" }),
|
23
|
+
children: () => (
|
24
|
+
<SettingGroupCreatePanel onCreated={() => closeSheet(id)} />
|
25
|
+
),
|
26
|
+
});
|
27
|
+
|
28
|
+
return id;
|
29
|
+
};
|
30
|
+
|
31
|
+
const openDelete = (items: SettingGroup[]) => {
|
32
|
+
return confirm({
|
33
|
+
title: `${t("delete", { ns: "actions" })} ${items.length} ${isPlural(items.length) ? t("items", { ns: "actions" }) : t("item", { ns: "actions" })}`,
|
34
|
+
description: t("deleteText", { ns: "setting-group" }),
|
35
|
+
})
|
36
|
+
.then(() =>
|
37
|
+
deleteSettingGroup(
|
38
|
+
items.map((item) => item.id).filter((id) => id !== undefined),
|
39
|
+
),
|
40
|
+
)
|
41
|
+
.catch(() => setSelectedItems(items));
|
42
|
+
};
|
43
|
+
|
44
|
+
const openUpdate = (item: SettingGroup) => {
|
45
|
+
const id = openSheet({
|
46
|
+
children: () => (
|
47
|
+
<SettingGroupUpdatePanel data={item} onUpdated={() => closeSheet(id)} />
|
48
|
+
),
|
49
|
+
title: t("edit", { ns: "setting-group" }),
|
50
|
+
description: t("editText", { ns: "setting-group" }),
|
51
|
+
});
|
52
|
+
|
53
|
+
return id;
|
54
|
+
};
|
55
|
+
|
56
|
+
return (
|
57
|
+
<>
|
58
|
+
<PageTitle title={t("settingGroup", { ns: "modules" })} />
|
59
|
+
<DataPanel
|
60
|
+
url="/setting-group"
|
61
|
+
layout="table"
|
62
|
+
id="setting-group"
|
63
|
+
selectable
|
64
|
+
columns={[
|
65
|
+
{ key: "id", header: "ID", width: 64 },
|
66
|
+
{ key: "name", header: t("name", { ns: "setting-group" }) },
|
67
|
+
]}
|
68
|
+
selected={selectedItems as SettingGroup[]}
|
69
|
+
multiple
|
70
|
+
hasSearch
|
71
|
+
sortable
|
72
|
+
onItemDoubleClick={(item) => openUpdate(item)}
|
73
|
+
menuActions={[
|
74
|
+
{
|
75
|
+
icon: <IconEdit className="mr-1 w-8 cursor-pointer" />,
|
76
|
+
label: t("edit", { ns: "actions" }),
|
77
|
+
tooltip: t("editTooltip", { ns: "setting-group" }),
|
78
|
+
handler: (items: SettingGroup[]) => {
|
79
|
+
if (items.length === 1) openUpdate(items[0]);
|
80
|
+
},
|
81
|
+
show: "once",
|
82
|
+
},
|
83
|
+
{
|
84
|
+
icon: <IconTrash className="mr-1 w-8 cursor-pointer" />,
|
85
|
+
label: t("delete", { ns: "actions" }),
|
86
|
+
tooltip: t("deleteTooltip", { ns: "setting-group" }),
|
87
|
+
variant: "destructive",
|
88
|
+
handler: (items: SettingGroup[]) => {
|
89
|
+
openDelete(items);
|
90
|
+
},
|
91
|
+
show: "some",
|
92
|
+
},
|
93
|
+
{
|
94
|
+
icon: <IconPlus className="mr-1 w-8 cursor-pointer" />,
|
95
|
+
label: t("create", { ns: "actions" }),
|
96
|
+
tooltip: t("createTooltip", { ns: "setting-group" }),
|
97
|
+
variant: "default",
|
98
|
+
handler: () => {
|
99
|
+
openCreate();
|
100
|
+
},
|
101
|
+
show: "none",
|
102
|
+
},
|
103
|
+
]}
|
104
|
+
/>
|
105
|
+
</>
|
106
|
+
);
|
107
|
+
}
|
@@ -0,0 +1,76 @@
|
|
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 { EnumFieldType } from "@/enums/EnumFieldType";
|
8
|
+
import {
|
9
|
+
useSettingGroupGet,
|
10
|
+
useSettingGroupUpdate,
|
11
|
+
} from "@/features/blog/setting-group";
|
12
|
+
import useEffectAfterFirstUpdate from "@/hooks/use-effect-after-first-update";
|
13
|
+
import { SettingGroup } from "@/types/models";
|
14
|
+
import { forwardRef, useImperativeHandle, useRef } from "react";
|
15
|
+
import { useTranslation } from "react-i18next";
|
16
|
+
|
17
|
+
export type SettingGroupUpdatePanelProps = {
|
18
|
+
data: SettingGroup;
|
19
|
+
onUpdated?: (data: SettingGroup) => void;
|
20
|
+
};
|
21
|
+
|
22
|
+
const SettingGroupUpdatePanel = forwardRef(
|
23
|
+
({ data, onUpdated }: SettingGroupUpdatePanelProps, ref) => {
|
24
|
+
const { t } = useTranslation(["actions"]);
|
25
|
+
const { data: item, isLoading } = useSettingGroupGet(data.id as number);
|
26
|
+
const { mutate: settingGroupUpdate } = useSettingGroupUpdate();
|
27
|
+
const formRef = useRef<FormPanelRef>(null);
|
28
|
+
|
29
|
+
useEffectAfterFirstUpdate(() => {
|
30
|
+
if (item && formRef.current) {
|
31
|
+
formRef.current.setValuesFromItem(item);
|
32
|
+
}
|
33
|
+
}, [item]);
|
34
|
+
|
35
|
+
useImperativeHandle(ref, () => ({}));
|
36
|
+
|
37
|
+
return (
|
38
|
+
<TabPanel
|
39
|
+
activeTabIndex={0}
|
40
|
+
tabs={[
|
41
|
+
{
|
42
|
+
title: t("details", { ns: "actions" }),
|
43
|
+
children: (
|
44
|
+
<Overlay loading={isLoading}>
|
45
|
+
<FormPanel
|
46
|
+
ref={formRef}
|
47
|
+
fields={[
|
48
|
+
{
|
49
|
+
name: "icon",
|
50
|
+
label: { text: t("icon", { ns: "translation" }) },
|
51
|
+
type: EnumFieldType.TEXT,
|
52
|
+
required: true,
|
53
|
+
},
|
54
|
+
|
55
|
+
...getFieldsLocale([{ name: "name" }]),
|
56
|
+
]}
|
57
|
+
button={{ text: t("save", { ns: "actions" }) }}
|
58
|
+
onSubmit={(data) => {
|
59
|
+
settingGroupUpdate({ id: data.id, data });
|
60
|
+
if (typeof onUpdated === "function") {
|
61
|
+
onUpdated(data);
|
62
|
+
}
|
63
|
+
}}
|
64
|
+
/>
|
65
|
+
</Overlay>
|
66
|
+
),
|
67
|
+
},
|
68
|
+
]}
|
69
|
+
/>
|
70
|
+
);
|
71
|
+
},
|
72
|
+
);
|
73
|
+
|
74
|
+
SettingGroupUpdatePanel.displayName = "SettingGroupUpdatePanel";
|
75
|
+
|
76
|
+
export default SettingGroupUpdatePanel;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
{
|
2
|
+
"create": "Create setting group",
|
3
|
+
"createText": "Fill the setting group informations.",
|
4
|
+
"createTooltip": "Create new setting group",
|
5
|
+
"delete": "Delete setting group",
|
6
|
+
"deleteText": "Are you sure to delete these setting group?",
|
7
|
+
"deleteTooltip": "Delete the selected setting group",
|
8
|
+
"edit": "Edit setting group",
|
9
|
+
"editText": "View and edit setting group information.",
|
10
|
+
"editTooltip": "Edit the selected setting group"
|
11
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
{
|
2
|
+
"create": "Criar grupo de configurações",
|
3
|
+
"createText": "Preencha as informações do grupo de configurações.",
|
4
|
+
"createTooltip": "Criar novo grupo de configurações",
|
5
|
+
"delete": "Excluir grupo de configurações",
|
6
|
+
"deleteText": "Você tem certeza de que deseja excluir esses grupos de configurações?",
|
7
|
+
"deleteTooltip": "Excluir o grupo de configurações selecionado",
|
8
|
+
"edit": "Editar grupo de configurações",
|
9
|
+
"editText": "Visualizar e editar informações do grupo de configurações.",
|
10
|
+
"editTooltip": "Editar o grupo de configurações 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 = "setting-group";
|
6
|
+
|
7
|
+
export function useSettingGroupCreate() {
|
8
|
+
const { settingGroupCreate } = requests();
|
9
|
+
return useDefaultMutation(scope, "create", settingGroupCreate);
|
10
|
+
}
|
11
|
+
|
12
|
+
export function useSettingGroupDelete() {
|
13
|
+
const { settingGroupDelete } = requests();
|
14
|
+
return useDefaultMutation(scope, "delete", settingGroupDelete);
|
15
|
+
}
|
16
|
+
|
17
|
+
export function useSettingGroupUpdate() {
|
18
|
+
const { settingGroupUpdate } = requests();
|
19
|
+
return useDefaultMutation(scope, "update", settingGroupUpdate);
|
20
|
+
}
|
21
|
+
|
22
|
+
export function useSettingGroupGet(id: number) {
|
23
|
+
const { settingGroupGet } = requests();
|
24
|
+
return useQuery({
|
25
|
+
queryKey: [scope, "get"],
|
26
|
+
queryFn: () => settingGroupGet(id),
|
27
|
+
});
|
28
|
+
}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import { useApp } from "@/hooks/use-app";
|
2
|
+
import { Delete, PaginationParams, PaginationResult } from "@/types";
|
3
|
+
import { SettingGroup } 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 settingGroupList = async (params: PaginationParams) => {
|
11
|
+
return request<PaginationResult<SettingGroup>>({
|
12
|
+
url: "/setting-group",
|
13
|
+
params,
|
14
|
+
}).then((res) => res.data);
|
15
|
+
};
|
16
|
+
|
17
|
+
const settingGroupGet = async (id: number) => {
|
18
|
+
return request<SettingGroup>({
|
19
|
+
url: `/setting-group/${id}`,
|
20
|
+
}).then((res) => res.data);
|
21
|
+
};
|
22
|
+
|
23
|
+
const settingGroupCreate = async (data: SettingGroup) => {
|
24
|
+
return request<SettingGroup>({
|
25
|
+
url: "/setting-group",
|
26
|
+
method: HttpMethod.POST,
|
27
|
+
data: formatDataWithLocale(data),
|
28
|
+
}).then((res) => res.data);
|
29
|
+
};
|
30
|
+
|
31
|
+
const settingGroupDelete = async (ids: number[]) => {
|
32
|
+
return request<Delete>({
|
33
|
+
url: "/setting-group",
|
34
|
+
data: { ids },
|
35
|
+
method: HttpMethod.DELETE,
|
36
|
+
}).then((res) => res.data);
|
37
|
+
};
|
38
|
+
|
39
|
+
const settingGroupUpdate = async (params: {
|
40
|
+
id: number;
|
41
|
+
data: SettingGroup;
|
42
|
+
}) => {
|
43
|
+
const { id, data } = params;
|
44
|
+
return request<SettingGroup>({
|
45
|
+
url: `/setting-group/${id}`,
|
46
|
+
method: HttpMethod.PATCH,
|
47
|
+
data: formatDataWithLocale(data),
|
48
|
+
}).then((res) => res.data);
|
49
|
+
};
|
50
|
+
|
51
|
+
return {
|
52
|
+
settingGroupCreate,
|
53
|
+
settingGroupUpdate,
|
54
|
+
settingGroupDelete,
|
55
|
+
settingGroupList,
|
56
|
+
settingGroupGet,
|
57
|
+
};
|
58
|
+
}
|
@@ -0,0 +1,71 @@
|
|
1
|
+
import FormPanel, { FormPanelRef } from "@/components/panels/form-panel";
|
2
|
+
import { EnumFieldType } from "@/enums/EnumFieldType";
|
3
|
+
import { useSettingUserCreate } from "@/features/blog/setting-user";
|
4
|
+
import { SettingUser } from "@/types/models";
|
5
|
+
import { forwardRef, useImperativeHandle, useRef } from "react";
|
6
|
+
import { useTranslation } from "react-i18next";
|
7
|
+
|
8
|
+
export type SettingUserCreatePanelRef = {
|
9
|
+
submit: () => void;
|
10
|
+
};
|
11
|
+
|
12
|
+
export type SettingUserCreatePanelProps = {
|
13
|
+
onCreated?: (data: SettingUser) => void;
|
14
|
+
};
|
15
|
+
|
16
|
+
const SettingUserCreatePanel = forwardRef(
|
17
|
+
({ onCreated }: SettingUserCreatePanelProps, ref) => {
|
18
|
+
const formRef = useRef<FormPanelRef>(null);
|
19
|
+
const { t } = useTranslation(["actions"]);
|
20
|
+
const { mutateAsync: createSettingUser } = useSettingUserCreate();
|
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: "user_id",
|
38
|
+
label: { text: t("user_id", { ns: "translation" }) },
|
39
|
+
type: EnumFieldType.TEXT,
|
40
|
+
required: true,
|
41
|
+
},
|
42
|
+
|
43
|
+
{
|
44
|
+
name: "setting_id",
|
45
|
+
label: { text: t("setting_id", { ns: "translation" }) },
|
46
|
+
type: EnumFieldType.TEXT,
|
47
|
+
required: true,
|
48
|
+
},
|
49
|
+
|
50
|
+
{
|
51
|
+
name: "value",
|
52
|
+
label: { text: t("value", { ns: "translation" }) },
|
53
|
+
type: EnumFieldType.TEXT,
|
54
|
+
required: true,
|
55
|
+
},
|
56
|
+
]}
|
57
|
+
button={{ text: t("create", { ns: "actions" }) }}
|
58
|
+
onSubmit={async (data) => {
|
59
|
+
const createdData = await createSettingUser(data);
|
60
|
+
if (typeof onCreated === "function") {
|
61
|
+
onCreated(createdData);
|
62
|
+
}
|
63
|
+
}}
|
64
|
+
/>
|
65
|
+
);
|
66
|
+
},
|
67
|
+
);
|
68
|
+
|
69
|
+
SettingUserCreatePanel.displayName = "SettingUserCreatePanel";
|
70
|
+
|
71
|
+
export default SettingUserCreatePanel;
|
@@ -0,0 +1,107 @@
|
|
1
|
+
import { PageTitle } from "@/components/custom/page-title";
|
2
|
+
import DataPanel from "@/components/panels/data-panel";
|
3
|
+
import { useSettingUserDelete } from "@/features/blog/setting-user";
|
4
|
+
import { useApp } from "@/hooks/use-app";
|
5
|
+
import { isPlural } from "@/lib/utils";
|
6
|
+
import { SettingUser } 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 SettingUserCreatePanel from "./components/setting-user-create-panel";
|
11
|
+
import SettingUserUpdatePanel from "./components/setting-user-update-panel";
|
12
|
+
|
13
|
+
export default function Page() {
|
14
|
+
const [selectedItems, setSelectedItems] = useState<SettingUser[]>([]);
|
15
|
+
const { mutate: deleteSettingUser } = useSettingUserDelete();
|
16
|
+
const { openSheet, confirm, closeSheet } = useApp();
|
17
|
+
const { t } = useTranslation(["setting-user", "modules", "actions"]);
|
18
|
+
|
19
|
+
const openCreate = () => {
|
20
|
+
const id = openSheet({
|
21
|
+
title: t("create", { ns: "actions" }),
|
22
|
+
description: t("createText", { ns: "setting-user" }),
|
23
|
+
children: () => (
|
24
|
+
<SettingUserCreatePanel onCreated={() => closeSheet(id)} />
|
25
|
+
),
|
26
|
+
});
|
27
|
+
|
28
|
+
return id;
|
29
|
+
};
|
30
|
+
|
31
|
+
const openDelete = (items: SettingUser[]) => {
|
32
|
+
return confirm({
|
33
|
+
title: `${t("delete", { ns: "actions" })} ${items.length} ${isPlural(items.length) ? t("items", { ns: "actions" }) : t("item", { ns: "actions" })}`,
|
34
|
+
description: t("deleteText", { ns: "setting-user" }),
|
35
|
+
})
|
36
|
+
.then(() =>
|
37
|
+
deleteSettingUser(
|
38
|
+
items.map((item) => item.id).filter((id) => id !== undefined),
|
39
|
+
),
|
40
|
+
)
|
41
|
+
.catch(() => setSelectedItems(items));
|
42
|
+
};
|
43
|
+
|
44
|
+
const openUpdate = (item: SettingUser) => {
|
45
|
+
const id = openSheet({
|
46
|
+
children: () => (
|
47
|
+
<SettingUserUpdatePanel data={item} onUpdated={() => closeSheet(id)} />
|
48
|
+
),
|
49
|
+
title: t("edit", { ns: "setting-user" }),
|
50
|
+
description: t("editText", { ns: "setting-user" }),
|
51
|
+
});
|
52
|
+
|
53
|
+
return id;
|
54
|
+
};
|
55
|
+
|
56
|
+
return (
|
57
|
+
<>
|
58
|
+
<PageTitle title={t("settingUser", { ns: "modules" })} />
|
59
|
+
<DataPanel
|
60
|
+
url="/setting-user"
|
61
|
+
layout="table"
|
62
|
+
id="setting-user"
|
63
|
+
selectable
|
64
|
+
columns={[
|
65
|
+
{ key: "id", header: "ID", width: 64 },
|
66
|
+
{ key: "name", header: t("name", { ns: "setting-user" }) },
|
67
|
+
]}
|
68
|
+
selected={selectedItems as SettingUser[]}
|
69
|
+
multiple
|
70
|
+
hasSearch
|
71
|
+
sortable
|
72
|
+
onItemDoubleClick={(item) => openUpdate(item)}
|
73
|
+
menuActions={[
|
74
|
+
{
|
75
|
+
icon: <IconEdit className="mr-1 w-8 cursor-pointer" />,
|
76
|
+
label: t("edit", { ns: "actions" }),
|
77
|
+
tooltip: t("editTooltip", { ns: "setting-user" }),
|
78
|
+
handler: (items: SettingUser[]) => {
|
79
|
+
if (items.length === 1) openUpdate(items[0]);
|
80
|
+
},
|
81
|
+
show: "once",
|
82
|
+
},
|
83
|
+
{
|
84
|
+
icon: <IconTrash className="mr-1 w-8 cursor-pointer" />,
|
85
|
+
label: t("delete", { ns: "actions" }),
|
86
|
+
tooltip: t("deleteTooltip", { ns: "setting-user" }),
|
87
|
+
variant: "destructive",
|
88
|
+
handler: (items: SettingUser[]) => {
|
89
|
+
openDelete(items);
|
90
|
+
},
|
91
|
+
show: "some",
|
92
|
+
},
|
93
|
+
{
|
94
|
+
icon: <IconPlus className="mr-1 w-8 cursor-pointer" />,
|
95
|
+
label: t("create", { ns: "actions" }),
|
96
|
+
tooltip: t("createTooltip", { ns: "setting-user" }),
|
97
|
+
variant: "default",
|
98
|
+
handler: () => {
|
99
|
+
openCreate();
|
100
|
+
},
|
101
|
+
show: "none",
|
102
|
+
},
|
103
|
+
]}
|
104
|
+
/>
|
105
|
+
</>
|
106
|
+
);
|
107
|
+
}
|