@hedhog/blog 0.0.13 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/author/author.controller.d.ts +13 -5
- package/dist/author/author.controller.d.ts.map +1 -1
- package/dist/author/author.controller.js +7 -7
- package/dist/author/author.controller.js.map +1 -1
- package/dist/author/author.service.d.ts +9 -1
- package/dist/author/author.service.d.ts.map +1 -1
- package/dist/category/category.controller.d.ts +13 -5
- package/dist/category/category.controller.d.ts.map +1 -1
- package/dist/category/category.controller.js +9 -9
- package/dist/category/category.controller.js.map +1 -1
- package/dist/category/category.service.d.ts +9 -1
- package/dist/category/category.service.d.ts.map +1 -1
- package/dist/category/dto/create.dto.d.ts +1 -1
- package/dist/category/dto/create.dto.d.ts.map +1 -1
- package/dist/category/dto/create.dto.js +2 -2
- package/dist/category/dto/create.dto.js.map +1 -1
- package/dist/post/post.controller.d.ts +13 -5
- package/dist/post/post.controller.d.ts.map +1 -1
- package/dist/post/post.controller.js +7 -7
- package/dist/post/post.controller.js.map +1 -1
- package/dist/post/post.service.d.ts +9 -1
- package/dist/post/post.service.d.ts.map +1 -1
- package/hedhog.yaml +133 -133
- package/package.json +9 -5
- package/frontend/author/components/author.screen.ts +0 -105
- package/frontend/author/components/author.screen.tsx +0 -105
- package/frontend/author/components/create-panel.tsx +0 -64
- package/frontend/author/components/update-panel.tsx +0 -75
- package/frontend/author/locales/en/blog.author.json +0 -11
- package/frontend/author/locales/pt/blog.author.json +0 -11
- package/frontend/author/react-query/handlers.ts +0 -28
- package/frontend/author/react-query/requests.ts +0 -54
- package/frontend/category/components/category.screen.ts +0 -105
- package/frontend/category/components/category.screen.tsx +0 -105
- package/frontend/category/components/create-panel.tsx +0 -53
- package/frontend/category/components/update-panel.tsx +0 -64
- package/frontend/category/locales/en/blog.category.json +0 -11
- package/frontend/category/locales/pt/blog.category.json +0 -11
- package/frontend/category/react-query/handlers.ts +0 -28
- package/frontend/category/react-query/requests.ts +0 -55
- package/frontend/post/components/create-panel.tsx +0 -78
- package/frontend/post/components/post.screen.ts +0 -105
- package/frontend/post/components/post.screen.tsx +0 -105
- package/frontend/post/components/update-panel.tsx +0 -89
- package/frontend/post/locales/en/blog.post.json +0 -11
- package/frontend/post/locales/pt/blog.post.json +0 -11
- package/frontend/post/react-query/handlers.ts +0 -28
- package/frontend/post/react-query/requests.ts +0 -54
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@hedhog/blog",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.3.1",
|
4
4
|
"private": false,
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"scripts": {
|
@@ -23,13 +23,17 @@
|
|
23
23
|
"description": "",
|
24
24
|
"peerDependencies": {
|
25
25
|
"@hedhog/admin": "latest",
|
26
|
+
"@hedhog/locale": "latest",
|
26
27
|
"@hedhog/pagination": "latest",
|
27
|
-
"@hedhog/prisma": "latest"
|
28
|
+
"@hedhog/prisma": "latest",
|
29
|
+
"@hedhog/utils": "latest"
|
28
30
|
},
|
29
31
|
"devDependencies": {
|
30
|
-
"@hedhog/admin": "^0.0.
|
31
|
-
"@hedhog/
|
32
|
-
"@hedhog/
|
32
|
+
"@hedhog/admin": "^0.0.124",
|
33
|
+
"@hedhog/locale": "^0.0.24",
|
34
|
+
"@hedhog/pagination": "^0.0.18",
|
35
|
+
"@hedhog/prisma": "^0.0.12",
|
36
|
+
"@hedhog/utils": "^0.0.27",
|
33
37
|
"@nestjs/mapped-types": "^2.0.5"
|
34
38
|
}
|
35
39
|
}
|
@@ -1,105 +0,0 @@
|
|
1
|
-
import { PageTitle } from "@/components/custom/page-title";
|
2
|
-
import DataPanel from "@/components/panels/data-panel";
|
3
|
-
import { useAuthorDelete } from "@/features/blog/author";
|
4
|
-
import { useApp } from "@/hooks/use-app";
|
5
|
-
import { isPlural } from "@/lib/utils";
|
6
|
-
import { Author } 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 AuthorCreatePanel from "./components/author-create-panel";
|
11
|
-
import AuthorUpdatePanel from "./components/author-update-panel";
|
12
|
-
|
13
|
-
export default function Page() {
|
14
|
-
const [selectedItems, setSelectedItems] = useState<Author[]>([]);
|
15
|
-
const { mutate: deleteAuthor } = useAuthorDelete();
|
16
|
-
const { openSheet, confirm, closeSheet } = useApp();
|
17
|
-
const { t } = useTranslation(["author", "modules", "actions"]);
|
18
|
-
|
19
|
-
const openCreate = () => {
|
20
|
-
const id = openSheet({
|
21
|
-
title: t("create", { ns: "actions" }),
|
22
|
-
description: t("createText", { ns: "author" }),
|
23
|
-
children: () => <AuthorCreatePanel onCreated={() => closeSheet(id)} />,
|
24
|
-
});
|
25
|
-
|
26
|
-
return id;
|
27
|
-
};
|
28
|
-
|
29
|
-
const openDelete = (items: Author[]) => {
|
30
|
-
return confirm({
|
31
|
-
title: `${t("delete", { ns: "actions" })} ${items.length} ${isPlural(items.length) ? t("items", { ns: "actions" }) : t("item", { ns: "actions" })}`,
|
32
|
-
description: t("deleteText", { ns: "author" }),
|
33
|
-
})
|
34
|
-
.then(() =>
|
35
|
-
deleteAuthor(
|
36
|
-
items.map((item) => item.id).filter((id) => id !== undefined),
|
37
|
-
),
|
38
|
-
)
|
39
|
-
.catch(() => setSelectedItems(items));
|
40
|
-
};
|
41
|
-
|
42
|
-
const openUpdate = (item: Author) => {
|
43
|
-
const id = openSheet({
|
44
|
-
children: () => (
|
45
|
-
<AuthorUpdatePanel data={item} onUpdated={() => closeSheet(id)} />
|
46
|
-
),
|
47
|
-
title: t("edit", { ns: "author" }),
|
48
|
-
description: t("editText", { ns: "author" }),
|
49
|
-
});
|
50
|
-
|
51
|
-
return id;
|
52
|
-
};
|
53
|
-
|
54
|
-
return (
|
55
|
-
<>
|
56
|
-
<PageTitle title={t("author", { ns: "modules" })} />
|
57
|
-
<DataPanel
|
58
|
-
url="/author"
|
59
|
-
layout="table"
|
60
|
-
id="author"
|
61
|
-
selectable
|
62
|
-
columns={[
|
63
|
-
{ key: "id", header: "ID", width: 64 },
|
64
|
-
{ key: "name", header: t("name", { ns: "author" }) },
|
65
|
-
]}
|
66
|
-
selected={selectedItems as Author[]}
|
67
|
-
multiple
|
68
|
-
hasSearch
|
69
|
-
sortable
|
70
|
-
onItemDoubleClick={(item) => openUpdate(item)}
|
71
|
-
menuActions={[
|
72
|
-
{
|
73
|
-
icon: <IconEdit className="mr-1 w-8 cursor-pointer" />,
|
74
|
-
label: t("edit", { ns: "actions" }),
|
75
|
-
tooltip: t("editTooltip", { ns: "author" }),
|
76
|
-
handler: (items: Author[]) => {
|
77
|
-
if (items.length === 1) openUpdate(items[0]);
|
78
|
-
},
|
79
|
-
show: "once",
|
80
|
-
},
|
81
|
-
{
|
82
|
-
icon: <IconTrash className="mr-1 w-8 cursor-pointer" />,
|
83
|
-
label: t("delete", { ns: "actions" }),
|
84
|
-
tooltip: t("deleteTooltip", { ns: "author" }),
|
85
|
-
variant: "destructive",
|
86
|
-
handler: (items: Author[]) => {
|
87
|
-
openDelete(items);
|
88
|
-
},
|
89
|
-
show: "some",
|
90
|
-
},
|
91
|
-
{
|
92
|
-
icon: <IconPlus className="mr-1 w-8 cursor-pointer" />,
|
93
|
-
label: t("create", { ns: "actions" }),
|
94
|
-
tooltip: t("createTooltip", { ns: "author" }),
|
95
|
-
variant: "default",
|
96
|
-
handler: () => {
|
97
|
-
openCreate();
|
98
|
-
},
|
99
|
-
show: "none",
|
100
|
-
},
|
101
|
-
]}
|
102
|
-
/>
|
103
|
-
</>
|
104
|
-
);
|
105
|
-
}
|
@@ -1,105 +0,0 @@
|
|
1
|
-
import { PageTitle } from "@/components/custom/page-title";
|
2
|
-
import DataPanel from "@/components/panels/data-panel";
|
3
|
-
import { useAuthorDelete } from "@/features/blog/author";
|
4
|
-
import { useApp } from "@/hooks/use-app";
|
5
|
-
import { isPlural } from "@/lib/utils";
|
6
|
-
import { Author } 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 AuthorCreatePanel from "./components/author-create-panel";
|
11
|
-
import AuthorUpdatePanel from "./components/author-update-panel";
|
12
|
-
|
13
|
-
export default function Page() {
|
14
|
-
const [selectedItems, setSelectedItems] = useState<Author[]>([]);
|
15
|
-
const { mutate: deleteAuthor } = useAuthorDelete();
|
16
|
-
const { openSheet, confirm, closeSheet } = useApp();
|
17
|
-
const { t } = useTranslation(["author", "modules", "actions"]);
|
18
|
-
|
19
|
-
const openCreate = () => {
|
20
|
-
const id = openSheet({
|
21
|
-
title: t("create", { ns: "actions" }),
|
22
|
-
description: t("createText", { ns: "author" }),
|
23
|
-
children: () => <AuthorCreatePanel onCreated={() => closeSheet(id)} />,
|
24
|
-
});
|
25
|
-
|
26
|
-
return id;
|
27
|
-
};
|
28
|
-
|
29
|
-
const openDelete = (items: Author[]) => {
|
30
|
-
return confirm({
|
31
|
-
title: `${t("delete", { ns: "actions" })} ${items.length} ${isPlural(items.length) ? t("items", { ns: "actions" }) : t("item", { ns: "actions" })}`,
|
32
|
-
description: t("deleteText", { ns: "author" }),
|
33
|
-
})
|
34
|
-
.then(() =>
|
35
|
-
deleteAuthor(
|
36
|
-
items.map((item) => item.id).filter((id) => id !== undefined),
|
37
|
-
),
|
38
|
-
)
|
39
|
-
.catch(() => setSelectedItems(items));
|
40
|
-
};
|
41
|
-
|
42
|
-
const openUpdate = (item: Author) => {
|
43
|
-
const id = openSheet({
|
44
|
-
children: () => (
|
45
|
-
<AuthorUpdatePanel data={item} onUpdated={() => closeSheet(id)} />
|
46
|
-
),
|
47
|
-
title: t("edit", { ns: "author" }),
|
48
|
-
description: t("editText", { ns: "author" }),
|
49
|
-
});
|
50
|
-
|
51
|
-
return id;
|
52
|
-
};
|
53
|
-
|
54
|
-
return (
|
55
|
-
<>
|
56
|
-
<PageTitle title={t("author", { ns: "modules" })} />
|
57
|
-
<DataPanel
|
58
|
-
url="/author"
|
59
|
-
layout="table"
|
60
|
-
id="author"
|
61
|
-
selectable
|
62
|
-
columns={[
|
63
|
-
{ key: "id", header: "ID", width: 64 },
|
64
|
-
{ key: "name", header: t("name", { ns: "author" }) },
|
65
|
-
]}
|
66
|
-
selected={selectedItems as Author[]}
|
67
|
-
multiple
|
68
|
-
hasSearch
|
69
|
-
sortable
|
70
|
-
onItemDoubleClick={(item) => openUpdate(item)}
|
71
|
-
menuActions={[
|
72
|
-
{
|
73
|
-
icon: <IconEdit className="mr-1 w-8 cursor-pointer" />,
|
74
|
-
label: t("edit", { ns: "actions" }),
|
75
|
-
tooltip: t("editTooltip", { ns: "author" }),
|
76
|
-
handler: (items: Author[]) => {
|
77
|
-
if (items.length === 1) openUpdate(items[0]);
|
78
|
-
},
|
79
|
-
show: "once",
|
80
|
-
},
|
81
|
-
{
|
82
|
-
icon: <IconTrash className="mr-1 w-8 cursor-pointer" />,
|
83
|
-
label: t("delete", { ns: "actions" }),
|
84
|
-
tooltip: t("deleteTooltip", { ns: "author" }),
|
85
|
-
variant: "destructive",
|
86
|
-
handler: (items: Author[]) => {
|
87
|
-
openDelete(items);
|
88
|
-
},
|
89
|
-
show: "some",
|
90
|
-
},
|
91
|
-
{
|
92
|
-
icon: <IconPlus className="mr-1 w-8 cursor-pointer" />,
|
93
|
-
label: t("create", { ns: "actions" }),
|
94
|
-
tooltip: t("createTooltip", { ns: "author" }),
|
95
|
-
variant: "default",
|
96
|
-
handler: () => {
|
97
|
-
openCreate();
|
98
|
-
},
|
99
|
-
show: "none",
|
100
|
-
},
|
101
|
-
]}
|
102
|
-
/>
|
103
|
-
</>
|
104
|
-
);
|
105
|
-
}
|
@@ -1,64 +0,0 @@
|
|
1
|
-
import FormPanel, { FormPanelRef } from "@/components/panels/form-panel";
|
2
|
-
import { EnumFieldType } from "@/enums/EnumFieldType";
|
3
|
-
import { useAuthorCreate } from "@/features/blog/author";
|
4
|
-
import { Author } from "@/types/models";
|
5
|
-
import { forwardRef, useImperativeHandle, useRef } from "react";
|
6
|
-
import { useTranslation } from "react-i18next";
|
7
|
-
|
8
|
-
export type AuthorCreatePanelRef = {
|
9
|
-
submit: () => void;
|
10
|
-
};
|
11
|
-
|
12
|
-
export type AuthorCreatePanelProps = {
|
13
|
-
onCreated?: (data: Author) => void;
|
14
|
-
};
|
15
|
-
|
16
|
-
const AuthorCreatePanel = forwardRef(
|
17
|
-
({ onCreated }: AuthorCreatePanelProps, ref) => {
|
18
|
-
const formRef = useRef<FormPanelRef>(null);
|
19
|
-
const { t } = useTranslation(["actions"]);
|
20
|
-
const { mutateAsync: createAuthor } = useAuthorCreate();
|
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: "name",
|
38
|
-
label: { text: t("name", { ns: "translation" }) },
|
39
|
-
type: EnumFieldType.TEXT,
|
40
|
-
required: true,
|
41
|
-
},
|
42
|
-
|
43
|
-
{
|
44
|
-
name: "email",
|
45
|
-
label: { text: t("email", { ns: "translation" }) },
|
46
|
-
type: EnumFieldType.TEXT,
|
47
|
-
required: true,
|
48
|
-
},
|
49
|
-
]}
|
50
|
-
button={{ text: t("create", { ns: "actions" }) }}
|
51
|
-
onSubmit={async (data) => {
|
52
|
-
const createdData = await createAuthor(data);
|
53
|
-
if (typeof onCreated === "function") {
|
54
|
-
onCreated(createdData);
|
55
|
-
}
|
56
|
-
}}
|
57
|
-
/>
|
58
|
-
);
|
59
|
-
},
|
60
|
-
);
|
61
|
-
|
62
|
-
AuthorCreatePanel.displayName = "AuthorCreatePanel";
|
63
|
-
|
64
|
-
export default AuthorCreatePanel;
|
@@ -1,75 +0,0 @@
|
|
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 { EnumFieldType } from "@/enums/EnumFieldType";
|
5
|
-
import { useAuthorGet, useAuthorUpdate } from "@/features/blog/author";
|
6
|
-
import useEffectAfterFirstUpdate from "@/hooks/use-effect-after-first-update";
|
7
|
-
import { Author } from "@/types/models";
|
8
|
-
import { forwardRef, useImperativeHandle, useRef } from "react";
|
9
|
-
import { useTranslation } from "react-i18next";
|
10
|
-
|
11
|
-
export type AuthorUpdatePanelProps = {
|
12
|
-
data: Author;
|
13
|
-
onUpdated?: (data: Author) => void;
|
14
|
-
};
|
15
|
-
|
16
|
-
const AuthorUpdatePanel = forwardRef(
|
17
|
-
({ data, onUpdated }: AuthorUpdatePanelProps, ref) => {
|
18
|
-
const { t } = useTranslation(["actions"]);
|
19
|
-
const { data: item, isLoading } = useAuthorGet(data.id as number);
|
20
|
-
const { mutate: authorUpdate } = useAuthorUpdate();
|
21
|
-
const formRef = useRef<FormPanelRef>(null);
|
22
|
-
|
23
|
-
useEffectAfterFirstUpdate(() => {
|
24
|
-
if (item && formRef.current) {
|
25
|
-
formRef.current.setValuesFromItem(item);
|
26
|
-
}
|
27
|
-
}, [item]);
|
28
|
-
|
29
|
-
useImperativeHandle(ref, () => ({}));
|
30
|
-
|
31
|
-
return (
|
32
|
-
<TabPanel
|
33
|
-
activeTabIndex={0}
|
34
|
-
tabs={[
|
35
|
-
{
|
36
|
-
title: t("details", { ns: "actions" }),
|
37
|
-
children: (
|
38
|
-
<Overlay loading={isLoading}>
|
39
|
-
<FormPanel
|
40
|
-
ref={formRef}
|
41
|
-
fields={[
|
42
|
-
{
|
43
|
-
name: "name",
|
44
|
-
label: { text: t("name", { ns: "translation" }) },
|
45
|
-
type: EnumFieldType.TEXT,
|
46
|
-
required: true,
|
47
|
-
},
|
48
|
-
|
49
|
-
{
|
50
|
-
name: "email",
|
51
|
-
label: { text: t("email", { ns: "translation" }) },
|
52
|
-
type: EnumFieldType.TEXT,
|
53
|
-
required: true,
|
54
|
-
},
|
55
|
-
]}
|
56
|
-
button={{ text: t("save", { ns: "actions" }) }}
|
57
|
-
onSubmit={(data) => {
|
58
|
-
authorUpdate({ id: data.id, data });
|
59
|
-
if (typeof onUpdated === "function") {
|
60
|
-
onUpdated(data);
|
61
|
-
}
|
62
|
-
}}
|
63
|
-
/>
|
64
|
-
</Overlay>
|
65
|
-
),
|
66
|
-
},
|
67
|
-
]}
|
68
|
-
/>
|
69
|
-
);
|
70
|
-
},
|
71
|
-
);
|
72
|
-
|
73
|
-
AuthorUpdatePanel.displayName = "AuthorUpdatePanel";
|
74
|
-
|
75
|
-
export default AuthorUpdatePanel;
|
@@ -1,11 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"create": "Create author",
|
3
|
-
"createText": "Fill the author informations.",
|
4
|
-
"createTooltip": "Create new author",
|
5
|
-
"delete": "Delete author",
|
6
|
-
"deleteText": "Are you sure to delete these authors?",
|
7
|
-
"deleteTooltip": "Delete the selected author",
|
8
|
-
"edit": "Edit author",
|
9
|
-
"editText": "View and edit author information.",
|
10
|
-
"editTooltip": "Edit the selected author"
|
11
|
-
}
|
@@ -1,11 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"create": "Criar autor",
|
3
|
-
"createText": "Preencha as informações do autor.",
|
4
|
-
"createTooltip": "Criar novo autor",
|
5
|
-
"delete": "Deletar autor",
|
6
|
-
"deleteText": "Você tem certeza que deseja deletar estes autores?",
|
7
|
-
"deleteTooltip": "Deletar o autor selecionado",
|
8
|
-
"edit": "Editar autor",
|
9
|
-
"editText": "Ver e editar informações do autor.",
|
10
|
-
"editTooltip": "Editar o autor selecionado"
|
11
|
-
}
|
@@ -1,28 +0,0 @@
|
|
1
|
-
import { useDefaultMutation } from "@/hooks/use-default-mutation";
|
2
|
-
import { useQuery } from "@tanstack/react-query";
|
3
|
-
import { requests } from "./requests";
|
4
|
-
|
5
|
-
const scope = "author";
|
6
|
-
|
7
|
-
export function useAuthorCreate() {
|
8
|
-
const { authorCreate } = requests();
|
9
|
-
return useDefaultMutation(scope, "create", authorCreate);
|
10
|
-
}
|
11
|
-
|
12
|
-
export function useAuthorDelete() {
|
13
|
-
const { authorDelete } = requests();
|
14
|
-
return useDefaultMutation(scope, "delete", authorDelete);
|
15
|
-
}
|
16
|
-
|
17
|
-
export function useAuthorUpdate() {
|
18
|
-
const { authorUpdate } = requests();
|
19
|
-
return useDefaultMutation(scope, "update", authorUpdate);
|
20
|
-
}
|
21
|
-
|
22
|
-
export function useAuthorGet(id: number) {
|
23
|
-
const { authorGet } = requests();
|
24
|
-
return useQuery({
|
25
|
-
queryKey: [scope, "get"],
|
26
|
-
queryFn: () => authorGet(id),
|
27
|
-
});
|
28
|
-
}
|
@@ -1,54 +0,0 @@
|
|
1
|
-
import { useApp } from "@/hooks/use-app";
|
2
|
-
import { Delete, PaginationParams, PaginationResult } from "@/types";
|
3
|
-
import { Author } from "@/types/models";
|
4
|
-
import { HttpMethod } from "@/types/http-method";
|
5
|
-
|
6
|
-
export function requests() {
|
7
|
-
const { request } = useApp();
|
8
|
-
|
9
|
-
const authorList = async (params: PaginationParams) => {
|
10
|
-
return request<PaginationResult<Author>>({
|
11
|
-
url: "/author",
|
12
|
-
params,
|
13
|
-
}).then((res) => res.data);
|
14
|
-
};
|
15
|
-
|
16
|
-
const authorGet = async (id: number) => {
|
17
|
-
return request<Author>({
|
18
|
-
url: `/author/${id}`,
|
19
|
-
}).then((res) => res.data);
|
20
|
-
};
|
21
|
-
|
22
|
-
const authorCreate = async (data: Author) => {
|
23
|
-
return request<Author>({
|
24
|
-
url: "/author",
|
25
|
-
method: HttpMethod.POST,
|
26
|
-
data: data,
|
27
|
-
}).then((res) => res.data);
|
28
|
-
};
|
29
|
-
|
30
|
-
const authorDelete = async (ids: number[]) => {
|
31
|
-
return request<Delete>({
|
32
|
-
url: "/author",
|
33
|
-
data: { ids },
|
34
|
-
method: HttpMethod.DELETE,
|
35
|
-
}).then((res) => res.data);
|
36
|
-
};
|
37
|
-
|
38
|
-
const authorUpdate = async (params: { id: number; data: Author }) => {
|
39
|
-
const { id, data } = params;
|
40
|
-
return request<Author>({
|
41
|
-
url: `/author/${id}`,
|
42
|
-
method: HttpMethod.PATCH,
|
43
|
-
data: data,
|
44
|
-
}).then((res) => res.data);
|
45
|
-
};
|
46
|
-
|
47
|
-
return {
|
48
|
-
authorCreate,
|
49
|
-
authorUpdate,
|
50
|
-
authorDelete,
|
51
|
-
authorList,
|
52
|
-
authorGet,
|
53
|
-
};
|
54
|
-
}
|
@@ -1,105 +0,0 @@
|
|
1
|
-
import { PageTitle } from "@/components/custom/page-title";
|
2
|
-
import DataPanel from "@/components/panels/data-panel";
|
3
|
-
import { useCategoryDelete } from "@/features/blog/category";
|
4
|
-
import { useApp } from "@/hooks/use-app";
|
5
|
-
import { isPlural } from "@/lib/utils";
|
6
|
-
import { Category } 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 CategoryCreatePanel from "./components/category-create-panel";
|
11
|
-
import CategoryUpdatePanel from "./components/category-update-panel";
|
12
|
-
|
13
|
-
export default function Page() {
|
14
|
-
const [selectedItems, setSelectedItems] = useState<Category[]>([]);
|
15
|
-
const { mutate: deleteCategory } = useCategoryDelete();
|
16
|
-
const { openSheet, confirm, closeSheet } = useApp();
|
17
|
-
const { t } = useTranslation(["category", "modules", "actions"]);
|
18
|
-
|
19
|
-
const openCreate = () => {
|
20
|
-
const id = openSheet({
|
21
|
-
title: t("create", { ns: "actions" }),
|
22
|
-
description: t("createText", { ns: "category" }),
|
23
|
-
children: () => <CategoryCreatePanel onCreated={() => closeSheet(id)} />,
|
24
|
-
});
|
25
|
-
|
26
|
-
return id;
|
27
|
-
};
|
28
|
-
|
29
|
-
const openDelete = (items: Category[]) => {
|
30
|
-
return confirm({
|
31
|
-
title: `${t("delete", { ns: "actions" })} ${items.length} ${isPlural(items.length) ? t("items", { ns: "actions" }) : t("item", { ns: "actions" })}`,
|
32
|
-
description: t("deleteText", { ns: "category" }),
|
33
|
-
})
|
34
|
-
.then(() =>
|
35
|
-
deleteCategory(
|
36
|
-
items.map((item) => item.id).filter((id) => id !== undefined),
|
37
|
-
),
|
38
|
-
)
|
39
|
-
.catch(() => setSelectedItems(items));
|
40
|
-
};
|
41
|
-
|
42
|
-
const openUpdate = (item: Category) => {
|
43
|
-
const id = openSheet({
|
44
|
-
children: () => (
|
45
|
-
<CategoryUpdatePanel data={item} onUpdated={() => closeSheet(id)} />
|
46
|
-
),
|
47
|
-
title: t("edit", { ns: "category" }),
|
48
|
-
description: t("editText", { ns: "category" }),
|
49
|
-
});
|
50
|
-
|
51
|
-
return id;
|
52
|
-
};
|
53
|
-
|
54
|
-
return (
|
55
|
-
<>
|
56
|
-
<PageTitle title={t("category", { ns: "modules" })} />
|
57
|
-
<DataPanel
|
58
|
-
url="/category"
|
59
|
-
layout="table"
|
60
|
-
id="category"
|
61
|
-
selectable
|
62
|
-
columns={[
|
63
|
-
{ key: "id", header: "ID", width: 64 },
|
64
|
-
{ key: "name", header: t("name", { ns: "category" }) },
|
65
|
-
]}
|
66
|
-
selected={selectedItems as Category[]}
|
67
|
-
multiple
|
68
|
-
hasSearch
|
69
|
-
sortable
|
70
|
-
onItemDoubleClick={(item) => openUpdate(item)}
|
71
|
-
menuActions={[
|
72
|
-
{
|
73
|
-
icon: <IconEdit className="mr-1 w-8 cursor-pointer" />,
|
74
|
-
label: t("edit", { ns: "actions" }),
|
75
|
-
tooltip: t("editTooltip", { ns: "category" }),
|
76
|
-
handler: (items: Category[]) => {
|
77
|
-
if (items.length === 1) openUpdate(items[0]);
|
78
|
-
},
|
79
|
-
show: "once",
|
80
|
-
},
|
81
|
-
{
|
82
|
-
icon: <IconTrash className="mr-1 w-8 cursor-pointer" />,
|
83
|
-
label: t("delete", { ns: "actions" }),
|
84
|
-
tooltip: t("deleteTooltip", { ns: "category" }),
|
85
|
-
variant: "destructive",
|
86
|
-
handler: (items: Category[]) => {
|
87
|
-
openDelete(items);
|
88
|
-
},
|
89
|
-
show: "some",
|
90
|
-
},
|
91
|
-
{
|
92
|
-
icon: <IconPlus className="mr-1 w-8 cursor-pointer" />,
|
93
|
-
label: t("create", { ns: "actions" }),
|
94
|
-
tooltip: t("createTooltip", { ns: "category" }),
|
95
|
-
variant: "default",
|
96
|
-
handler: () => {
|
97
|
-
openCreate();
|
98
|
-
},
|
99
|
-
show: "none",
|
100
|
-
},
|
101
|
-
]}
|
102
|
-
/>
|
103
|
-
</>
|
104
|
-
);
|
105
|
-
}
|