diff --git a/src/client/index.ts b/src/client/index.ts index 173f1e2..c9ea611 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -198,6 +198,8 @@ export type { ServicePriceRangeSchema } from './models/ServicePriceRangeSchema'; export type { ServiceReorderRequest } from './models/ServiceReorderRequest'; export type { ServiceReorderResponse } from './models/ServiceReorderResponse'; export type { ServiceSchema } from './models/ServiceSchema'; +export type { ServiceUpdateCategoryRequest } from './models/ServiceUpdateCategoryRequest'; +export type { ServiceUpdateCategoryResponse } from './models/ServiceUpdateCategoryResponse'; export type { ServiceUpdateRequest } from './models/ServiceUpdateRequest'; export type { ServiceUpdateResponse } from './models/ServiceUpdateResponse'; export type { ShippingWarehouseSchema } from './models/ShippingWarehouseSchema'; diff --git a/src/client/models/ServiceUpdateCategoryRequest.ts b/src/client/models/ServiceUpdateCategoryRequest.ts new file mode 100644 index 0000000..6589102 --- /dev/null +++ b/src/client/models/ServiceUpdateCategoryRequest.ts @@ -0,0 +1,9 @@ +/* generated using openapi-typescript-codegen -- do not edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { ServiceCategorySchema } from './ServiceCategorySchema'; +export type ServiceUpdateCategoryRequest = { + category: ServiceCategorySchema; +}; + diff --git a/src/client/models/ServiceUpdateCategoryResponse.ts b/src/client/models/ServiceUpdateCategoryResponse.ts new file mode 100644 index 0000000..e06cea6 --- /dev/null +++ b/src/client/models/ServiceUpdateCategoryResponse.ts @@ -0,0 +1,9 @@ +/* generated using openapi-typescript-codegen -- do not edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type ServiceUpdateCategoryResponse = { + ok: boolean; + message: string; +}; + diff --git a/src/client/services/ServiceService.ts b/src/client/services/ServiceService.ts index 0b36681..abf492b 100644 --- a/src/client/services/ServiceService.ts +++ b/src/client/services/ServiceService.ts @@ -23,6 +23,8 @@ import type { ServiceGetAllCategoriesResponse } from '../models/ServiceGetAllCat import type { ServiceGetAllResponse } from '../models/ServiceGetAllResponse'; import type { ServiceReorderRequest } from '../models/ServiceReorderRequest'; import type { ServiceReorderResponse } from '../models/ServiceReorderResponse'; +import type { ServiceUpdateCategoryRequest } from '../models/ServiceUpdateCategoryRequest'; +import type { ServiceUpdateCategoryResponse } from '../models/ServiceUpdateCategoryResponse'; import type { ServiceUpdateRequest } from '../models/ServiceUpdateRequest'; import type { ServiceUpdateResponse } from '../models/ServiceUpdateResponse'; import type { UpdatePriceCategoryRequest } from '../models/UpdatePriceCategoryRequest'; @@ -155,6 +157,26 @@ export class ServiceService { }, }); } + /** + * Update Category + * @returns ServiceUpdateCategoryResponse Successful Response + * @throws ApiError + */ + public static updateServiceCategory({ + requestBody, + }: { + requestBody: ServiceUpdateCategoryRequest, + }): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/service/categories/update', + body: requestBody, + mediaType: 'application/json', + errors: { + 422: `Validation Error`, + }, + }); + } /** * Reorder Category * @returns ServiceCategoryReorderResponse Successful Response diff --git a/src/pages/ServicesPage/components/ServicesTable/ServicesTable.tsx b/src/pages/ServicesPage/components/ServicesTable/ServicesTable.tsx index 35ad119..0ae201f 100644 --- a/src/pages/ServicesPage/components/ServicesTable/ServicesTable.tsx +++ b/src/pages/ServicesPage/components/ServicesTable/ServicesTable.tsx @@ -150,6 +150,38 @@ 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, + }) => { + notifications.guess(ok, { message }); + if (!ok) return; + queryClient.invalidateQueries({ + queryKey: ["getAllServices"], + }).then(() => { + }); + }, + ); + }, + }, + }); + }} variant={"default"}> + + + + ), + }, }, enableRowActions: true, renderRowActions: ({ row }) => ( diff --git a/src/pages/ServicesPage/modals/CreateServiceCategoryModal.tsx b/src/pages/ServicesPage/modals/CreateServiceCategoryModal.tsx index 3022301..86f609a 100644 --- a/src/pages/ServicesPage/modals/CreateServiceCategoryModal.tsx +++ b/src/pages/ServicesPage/modals/CreateServiceCategoryModal.tsx @@ -2,19 +2,18 @@ import { ServiceCategorySchema } from "../../../client"; import { Button, Flex, rem, TextInput } from "@mantine/core"; import { useForm } from "@mantine/form"; import { ContextModalProps } from "@mantine/modals"; +import { CreateEditFormProps } from "../../ClientsPage/modals/BaseFormModal/BaseFormModal.tsx"; -type Props = { - onCreate: (category: ServiceCategorySchema) => void; -}; +type Props = CreateEditFormProps; const CreateServiceCategoryModal = ({ - context, - id, - innerProps, -}: ContextModalProps) => { + context, + id, + innerProps, + }: ContextModalProps) => { + const isEditing = "onChange" in innerProps; + const initialValues = isEditing ? innerProps.element : { name: "" }; const form = useForm({ - initialValues: { - name: "", - }, + initialValues, validate: { name: name => name.trim() !== "" @@ -23,7 +22,15 @@ const CreateServiceCategoryModal = ({ }, }); const onSubmit = (values: { name: string }) => { - innerProps.onCreate({ name: values.name, id: -1 }); + if (isEditing) { + innerProps.onChange({ ...innerProps.element, ...values }); + } else { + innerProps.onCreate({ + ...values, + dealServiceRank: "", + productServiceRank: "", id: -1, + }); + } context.closeContextModal(id); }; const onCancelClick = () => {