From 7bebd40f8152279f8a1e4adfd408e8e4f0104a2c Mon Sep 17 00:00:00 2001 From: AlexSserb Date: Sun, 17 Nov 2024 13:55:58 +0400 Subject: [PATCH] feat: setting manager for a deal --- src/client/index.ts | 1 + src/client/models/DealGeneralInfoSchema.ts | 2 ++ src/client/models/DealSchema.ts | 2 ++ src/client/services/UserService.ts | 12 ++++++++++ .../ManagerSelect/ManagerSelect.tsx | 23 +++++++++++++++++++ .../tabs/DealEditDrawerGeneralTab.tsx | 6 +++++ src/pages/LeadsPage/hooks/useManagersList.tsx | 11 +++++++++ 7 files changed, 57 insertions(+) create mode 100644 src/components/ManagerSelect/ManagerSelect.tsx create mode 100644 src/pages/LeadsPage/hooks/useManagersList.tsx diff --git a/src/client/index.ts b/src/client/index.ts index d97ce91..d76b9ea 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -161,6 +161,7 @@ export type { GetClientMarketplacesResponse } from './models/GetClientMarketplac export type { GetDealBillById } from './models/GetDealBillById'; export type { GetDealProductsBarcodesPdfRequest } from './models/GetDealProductsBarcodesPdfRequest'; export type { GetDealProductsBarcodesPdfResponse } from './models/GetDealProductsBarcodesPdfResponse'; +export type { GetManagersResponse } from './models/GetManagersResponse'; export type { GetPaymentRecordsResponse } from './models/GetPaymentRecordsResponse'; export type { GetProductBarcodePdfRequest } from './models/GetProductBarcodePdfRequest'; export type { GetProductBarcodePdfResponse } from './models/GetProductBarcodePdfResponse'; diff --git a/src/client/models/DealGeneralInfoSchema.ts b/src/client/models/DealGeneralInfoSchema.ts index 210cbb2..4d5906c 100644 --- a/src/client/models/DealGeneralInfoSchema.ts +++ b/src/client/models/DealGeneralInfoSchema.ts @@ -2,6 +2,7 @@ /* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import type { UserSchema } from './UserSchema'; export type DealGeneralInfoSchema = { name: string; isDeleted: boolean; @@ -10,5 +11,6 @@ export type DealGeneralInfoSchema = { shippingWarehouse?: (string | null); deliveryDate?: (string | null); receivingSlotDate?: (string | null); + manager?: (UserSchema | null); }; diff --git a/src/client/models/DealSchema.ts b/src/client/models/DealSchema.ts index da00c3c..6856353 100644 --- a/src/client/models/DealSchema.ts +++ b/src/client/models/DealSchema.ts @@ -9,6 +9,7 @@ import type { DealServiceSchema } from './DealServiceSchema'; import type { DealStatusHistorySchema } from './DealStatusHistorySchema'; import type { ServicePriceCategorySchema } from './ServicePriceCategorySchema'; import type { ShippingWarehouseSchema } from './ShippingWarehouseSchema'; +import type { UserSchema } from './UserSchema'; export type DealSchema = { id: number; name: string; @@ -26,6 +27,7 @@ export type DealSchema = { shippingWarehouse?: (ShippingWarehouseSchema | string | null); billRequest?: (DealBillRequestSchema | null); category?: (ServicePriceCategorySchema | null); + manager?: (UserSchema | null); deliveryDate?: (string | null); receivingSlotDate?: (string | null); }; diff --git a/src/client/services/UserService.ts b/src/client/services/UserService.ts index b1037fa..3339e4d 100644 --- a/src/client/services/UserService.ts +++ b/src/client/services/UserService.ts @@ -5,6 +5,7 @@ import type { CreateUserRequest } from '../models/CreateUserRequest'; import type { CreateUserResponse } from '../models/CreateUserResponse'; import type { GetAllUsersResponse } from '../models/GetAllUsersResponse'; +import type { GetManagersResponse } from '../models/GetManagersResponse'; import type { UpdateUserRequest } from '../models/UpdateUserRequest'; import type { UpdateUserResponse } from '../models/UpdateUserResponse'; import type { CancelablePromise } from '../core/CancelablePromise'; @@ -62,4 +63,15 @@ export class UserService { }, }); } + /** + * Get Managers + * @returns GetManagersResponse Successful Response + * @throws ApiError + */ + public static getManagers(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/user/get-managers', + }); + } } diff --git a/src/components/ManagerSelect/ManagerSelect.tsx b/src/components/ManagerSelect/ManagerSelect.tsx new file mode 100644 index 0000000..6cdb7d9 --- /dev/null +++ b/src/components/ManagerSelect/ManagerSelect.tsx @@ -0,0 +1,23 @@ +import { FC } from "react"; +import ObjectSelect, { ObjectSelectProps } from "../ObjectSelect/ObjectSelect.tsx"; +import { UserSchema } from "../../client"; +import useManagersList from "../../pages/LeadsPage/hooks/useManagersList.tsx"; + +type Props = Omit< + ObjectSelectProps, + "data" | "getValueFn" | "getLabelFn" +>; +const UserSelect: FC = props => { + const { objects: managers } = useManagersList(); + return ( + `${manager.firstName} ${manager.secondName}`} + getValueFn={(manager: UserSchema) => manager.id.toString()} + clearable + {...props} + onClear={() => props.onChange(null)} + /> + ); +}; +export default UserSelect; diff --git a/src/pages/LeadsPage/drawers/DealEditDrawer/tabs/DealEditDrawerGeneralTab.tsx b/src/pages/LeadsPage/drawers/DealEditDrawer/tabs/DealEditDrawerGeneralTab.tsx index 70d253e..2a63e8f 100644 --- a/src/pages/LeadsPage/drawers/DealEditDrawer/tabs/DealEditDrawerGeneralTab.tsx +++ b/src/pages/LeadsPage/drawers/DealEditDrawer/tabs/DealEditDrawerGeneralTab.tsx @@ -30,6 +30,7 @@ import { IconBarcode, IconPrinter } from "@tabler/icons-react"; import styles from "../../../ui/LeadsPage.module.css"; import { base64ToBlob } from "../../../../../shared/lib/utils.ts"; import { DatePickerInput } from "@mantine/dates"; +import ManagerSelect from "../../../../../components/ManagerSelect/ManagerSelect.tsx"; type Props = { deal: DealSchema; @@ -209,6 +210,11 @@ const Content: FC = ({ deal }) => { {...form.getInputProps("receivingSlotDate")} /> + + ObjectList({ + queryFn: UserService.getManagers, + getObjectsFn: response => response.managers, + queryKey: "getManagers", + }); + +export default useManagersList;