diff --git a/src/client/index.ts b/src/client/index.ts index c9ea611..c1c6cbc 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -189,6 +189,8 @@ export type { ServiceCreateCategoryRequest } from './models/ServiceCreateCategor export type { ServiceCreateCategoryResponse } from './models/ServiceCreateCategoryResponse'; export type { ServiceCreateRequest } from './models/ServiceCreateRequest'; export type { ServiceCreateResponse } from './models/ServiceCreateResponse'; +export type { ServiceDeleteCategoryRequest } from './models/ServiceDeleteCategoryRequest'; +export type { ServiceDeleteCategoryResponse } from './models/ServiceDeleteCategoryResponse'; export type { ServiceDeleteRequest } from './models/ServiceDeleteRequest'; export type { ServiceDeleteResponse } from './models/ServiceDeleteResponse'; export type { ServiceGetAllCategoriesResponse } from './models/ServiceGetAllCategoriesResponse'; diff --git a/src/client/models/ServiceDeleteCategoryRequest.ts b/src/client/models/ServiceDeleteCategoryRequest.ts new file mode 100644 index 0000000..8d5d936 --- /dev/null +++ b/src/client/models/ServiceDeleteCategoryRequest.ts @@ -0,0 +1,8 @@ +/* generated using openapi-typescript-codegen -- do not edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type ServiceDeleteCategoryRequest = { + categoryId: number; +}; + diff --git a/src/client/models/ServiceDeleteCategoryResponse.ts b/src/client/models/ServiceDeleteCategoryResponse.ts new file mode 100644 index 0000000..557c8d2 --- /dev/null +++ b/src/client/models/ServiceDeleteCategoryResponse.ts @@ -0,0 +1,9 @@ +/* generated using openapi-typescript-codegen -- do not edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type ServiceDeleteCategoryResponse = { + ok: boolean; + message: string; +}; + diff --git a/src/client/services/ServiceService.ts b/src/client/services/ServiceService.ts index 2f25169..c9479e9 100644 --- a/src/client/services/ServiceService.ts +++ b/src/client/services/ServiceService.ts @@ -17,6 +17,8 @@ import type { ServiceCreateCategoryRequest } from '../models/ServiceCreateCatego import type { ServiceCreateCategoryResponse } from '../models/ServiceCreateCategoryResponse'; import type { ServiceCreateRequest } from '../models/ServiceCreateRequest'; import type { ServiceCreateResponse } from '../models/ServiceCreateResponse'; +import type { ServiceDeleteCategoryRequest } from '../models/ServiceDeleteCategoryRequest'; +import type { ServiceDeleteCategoryResponse } from '../models/ServiceDeleteCategoryResponse'; import type { ServiceDeleteRequest } from '../models/ServiceDeleteRequest'; import type { ServiceDeleteResponse } from '../models/ServiceDeleteResponse'; import type { ServiceGetAllCategoriesResponse } from '../models/ServiceGetAllCategoriesResponse'; @@ -207,6 +209,26 @@ export class ServiceService { }, }); } + /** + * Delete Category + * @returns ServiceDeleteCategoryResponse Successful Response + * @throws ApiError + */ + public static deleteServiceCategory({ + requestBody, + }: { + requestBody: ServiceDeleteCategoryRequest, + }): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/service/categories/delete', + body: requestBody, + mediaType: 'application/json', + errors: { + 422: `Validation Error`, + }, + }); + } /** * Get All Service Types * @returns BaseEnumListSchema Successful Response diff --git a/src/pages/ServicesPage/components/ServicesTable/ServicesTable.tsx b/src/pages/ServicesPage/components/ServicesTable/ServicesTable.tsx index 1cb2e7b..297a53f 100644 --- a/src/pages/ServicesPage/components/ServicesTable/ServicesTable.tsx +++ b/src/pages/ServicesPage/components/ServicesTable/ServicesTable.tsx @@ -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 = ({ }, "mrt-row-actions": { AggregatedCell: ({ row }) => editMode && ( - - { - modals.openContextModal({ - modal: "createServiceCategory", - title: "Создание категории", - withCloseButton: false, - innerProps: { - element: row.original.category, - onChange: newCategory => { - ServiceService.updateServiceCategory({ requestBody: { category: newCategory } }).then(({ - ok, - message, - }) => { + + + { + 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"}> + + + + + { + 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"}> - - - + }); + }, + }); + }} + variant={"default"} + > + + + + + ), }, },