feat: service category deleting

This commit is contained in:
2024-10-09 02:25:37 +03:00
parent 891b6cff9f
commit 35951c7019
5 changed files with 93 additions and 23 deletions

View File

@@ -7,7 +7,7 @@ import { useServicesTableColumns } from "./columns.tsx";
import { BaseTable } from "../../../../components/BaseTable/BaseTable.tsx";
import { MRT_TableOptions } from "mantine-react-table";
import { CRUDTableProps } from "../../../../types/CRUDTable.tsx";
import { ActionIcon, Flex, Tooltip } from "@mantine/core";
import { ActionIcon, Flex, rem, Tooltip } from "@mantine/core";
import { IconArrowDown, IconArrowUp, IconEdit, IconTrash } from "@tabler/icons-react";
import { modals } from "@mantine/modals";
import { notifications } from "../../../../shared/lib/notifications.ts";
@@ -151,34 +151,63 @@ const ServicesTable: FC<Props> = ({
},
"mrt-row-actions": {
AggregatedCell: ({ row }) => editMode && (
<Tooltip label={"Редактировать категорию"}>
<ActionIcon onClick={() => {
modals.openContextModal({
modal: "createServiceCategory",
title: "Создание категории",
withCloseButton: false,
innerProps: {
element: row.original.category,
onChange: newCategory => {
ServiceService.updateServiceCategory({ requestBody: { category: newCategory } }).then(({
ok,
message,
}) => {
<Flex gap={"xs"}>
<Tooltip label={"Редактировать категорию"}>
<ActionIcon onClick={() => {
modals.openContextModal({
modal: "createServiceCategory",
title: "Создание категории",
withCloseButton: false,
innerProps: {
element: row.original.category,
onChange: newCategory => {
ServiceService.updateServiceCategory({ requestBody: { category: newCategory } }).then(({
ok,
message,
}) => {
notifications.guess(ok, { message });
if (!ok) return;
queryClient.invalidateQueries({
queryKey: ["getAllServices"],
}).then(() => {
});
},
);
},
},
});
}} variant={"default"}>
<IconEdit />
</ActionIcon>
</Tooltip>
<Tooltip label={"Удалить категорию"}>
<ActionIcon
onClick={() => {
modals.openConfirmModal({
title: "Удаление категории",
children: `Вы уверены, что хотите удалить категорию: ${row.original.category.name}?`,
onConfirm: () => {
ServiceService.deleteServiceCategory({ requestBody: { categoryId: row.original.category.id } }).then(({
ok,
message,
}) => {
notifications.guess(ok, { message });
if (!ok) return;
queryClient.invalidateQueries({
queryKey: ["getAllServices"],
}).then(() => {
});
},
);
},
},
});
}} variant={"default"}>
<IconEdit />
</ActionIcon>
</Tooltip>
});
},
});
}}
variant={"default"}
>
<IconTrash />
</ActionIcon>
</Tooltip>
</Flex>
),
},
},