From 5c6e7cf5f58925e3319ae46cb6ee6e1e0d7bf2ba Mon Sep 17 00:00:00 2001 From: fakz9 Date: Thu, 18 Jul 2024 04:56:20 +0300 Subject: [PATCH] feat: shipping warehouse and cost --- src/client/index.ts | 3 + src/client/models/DealQuickCreateRequest.ts | 1 + src/client/models/DealSchema.ts | 2 + .../GetAllShippingWarehousesResponse.ts | 9 +++ src/client/models/ServiceSchema.ts | 1 + src/client/models/ShippingWarehouseSchema.ts | 9 +++ .../services/ShippingWarehouseService.ts | 21 ++++++ .../Dnd/CreateDealForm/CreateDealFrom.tsx | 12 +++- .../ObjectAutocomplete/ObjectAutocomplete.tsx | 65 +++++++++++++++++++ .../ShippingWarehouseAutocomplete.tsx | 17 +++++ .../hooks/useShippingWarehousesList.tsx | 13 ++++ src/main.tsx | 2 - .../components/DealServicesTable/columns.tsx | 13 ++-- .../drawers/DealEditDrawer/DealEditDrawer.tsx | 7 -- .../tabs/DealEditDrawerGeneralTab.tsx | 8 ++- .../ProductAndServiceTab.tsx | 2 +- .../ProductServicesTable/columns.tsx | 8 ++- .../components/ServicesTable/columns.tsx | 8 ++- .../modals/CreateServiceModal.tsx | 11 +++- src/routes/test.lazy.tsx | 2 +- src/types/QuickDeal.ts | 11 ++-- 21 files changed, 192 insertions(+), 33 deletions(-) create mode 100644 src/client/models/GetAllShippingWarehousesResponse.ts create mode 100644 src/client/models/ShippingWarehouseSchema.ts create mode 100644 src/client/services/ShippingWarehouseService.ts create mode 100644 src/components/ObjectAutocomplete/ObjectAutocomplete.tsx create mode 100644 src/components/Selects/ShippingWarehouseAutocomplete/ShippingWarehouseAutocomplete.tsx create mode 100644 src/components/Selects/ShippingWarehouseAutocomplete/hooks/useShippingWarehousesList.tsx diff --git a/src/client/index.ts b/src/client/index.ts index 807b3dc..723c215 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -80,6 +80,7 @@ export type { DealUpdateServiceResponse } from './models/DealUpdateServiceRespon export type { GetAllBarcodeTemplateAttributesResponse } from './models/GetAllBarcodeTemplateAttributesResponse'; export type { GetAllBarcodeTemplateSizesResponse } from './models/GetAllBarcodeTemplateSizesResponse'; export type { GetAllBarcodeTemplatesResponse } from './models/GetAllBarcodeTemplatesResponse'; +export type { GetAllShippingWarehousesResponse } from './models/GetAllShippingWarehousesResponse'; export type { GetBarcodeTemplateByIdRequest } from './models/GetBarcodeTemplateByIdRequest'; export type { GetBarcodeTemplateByIdResponse } from './models/GetBarcodeTemplateByIdResponse'; export type { GetProductBarcodePdfRequest } from './models/GetProductBarcodePdfRequest'; @@ -116,6 +117,7 @@ export type { ServicePriceRangeSchema } from './models/ServicePriceRangeSchema'; export type { ServiceSchema } from './models/ServiceSchema'; export type { ServiceUpdateRequest } from './models/ServiceUpdateRequest'; export type { ServiceUpdateResponse } from './models/ServiceUpdateResponse'; +export type { ShippingWarehouseSchema } from './models/ShippingWarehouseSchema'; export type { UserSchema } from './models/UserSchema'; export type { ValidationError } from './models/ValidationError'; @@ -125,3 +127,4 @@ export { ClientService } from './services/ClientService'; export { DealService } from './services/DealService'; export { ProductService } from './services/ProductService'; export { ServiceService } from './services/ServiceService'; +export { ShippingWarehouseService } from './services/ShippingWarehouseService'; diff --git a/src/client/models/DealQuickCreateRequest.ts b/src/client/models/DealQuickCreateRequest.ts index e6adbdb..c8e293d 100644 --- a/src/client/models/DealQuickCreateRequest.ts +++ b/src/client/models/DealQuickCreateRequest.ts @@ -7,5 +7,6 @@ export type DealQuickCreateRequest = { clientName: string; comment: string; acceptanceDate: string; + shippingWarehouse: string; }; diff --git a/src/client/models/DealSchema.ts b/src/client/models/DealSchema.ts index 996d47a..3abf04b 100644 --- a/src/client/models/DealSchema.ts +++ b/src/client/models/DealSchema.ts @@ -6,6 +6,7 @@ import type { ClientSchema } from './ClientSchema'; import type { DealProductSchema } from './DealProductSchema'; import type { DealServiceSchema } from './DealServiceSchema'; import type { DealStatusHistorySchema } from './DealStatusHistorySchema'; +import type { ShippingWarehouseSchema } from './ShippingWarehouseSchema'; export type DealSchema = { id: number; name: string; @@ -19,5 +20,6 @@ export type DealSchema = { isCompleted: boolean; client: ClientSchema; comment: string; + shippingWarehouse?: (ShippingWarehouseSchema | null); }; diff --git a/src/client/models/GetAllShippingWarehousesResponse.ts b/src/client/models/GetAllShippingWarehousesResponse.ts new file mode 100644 index 0000000..a4bed1f --- /dev/null +++ b/src/client/models/GetAllShippingWarehousesResponse.ts @@ -0,0 +1,9 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { ShippingWarehouseSchema } from './ShippingWarehouseSchema'; +export type GetAllShippingWarehousesResponse = { + shippingWarehouses: Array; +}; + diff --git a/src/client/models/ServiceSchema.ts b/src/client/models/ServiceSchema.ts index 61b45dc..1831007 100644 --- a/src/client/models/ServiceSchema.ts +++ b/src/client/models/ServiceSchema.ts @@ -11,5 +11,6 @@ export type ServiceSchema = { price: number; serviceType: number; priceRanges: Array; + cost: (number | null); }; diff --git a/src/client/models/ShippingWarehouseSchema.ts b/src/client/models/ShippingWarehouseSchema.ts new file mode 100644 index 0000000..5ddd398 --- /dev/null +++ b/src/client/models/ShippingWarehouseSchema.ts @@ -0,0 +1,9 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type ShippingWarehouseSchema = { + id: number; + name: string; +}; + diff --git a/src/client/services/ShippingWarehouseService.ts b/src/client/services/ShippingWarehouseService.ts new file mode 100644 index 0000000..7b28480 --- /dev/null +++ b/src/client/services/ShippingWarehouseService.ts @@ -0,0 +1,21 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { GetAllShippingWarehousesResponse } from '../models/GetAllShippingWarehousesResponse'; +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; +export class ShippingWarehouseService { + /** + * Get All + * @returns GetAllShippingWarehousesResponse Successful Response + * @throws ApiError + */ + public static getAllShippingWarehouses(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/shipping-warehouse/get-all', + }); + } +} diff --git a/src/components/Dnd/CreateDealForm/CreateDealFrom.tsx b/src/components/Dnd/CreateDealForm/CreateDealFrom.tsx index fcd9106..9d04706 100644 --- a/src/components/Dnd/CreateDealForm/CreateDealFrom.tsx +++ b/src/components/Dnd/CreateDealForm/CreateDealFrom.tsx @@ -5,19 +5,22 @@ import {useForm} from "@mantine/form"; import styles from './CreateDealForm.module.css'; import ClientAutocomplete from "../../Selects/ClientAutocomplete/ClientAutocomplete.tsx"; import {DateTimePicker} from "@mantine/dates"; +import ShippingWarehouseAutocomplete + from "../../Selects/ShippingWarehouseAutocomplete/ShippingWarehouseAutocomplete.tsx"; type Props = { onSubmit: (quickDeal: QuickDeal) => void onCancel: () => void; } const CreateDealFrom: FC = ({onSubmit, onCancel}) => { - const form = useForm({ + const form = useForm({ initialValues: { name: '', clientName: '', clientAddress: '', comment: '', - acceptanceDate: new Date() + acceptanceDate: new Date(), + shippingWarehouse: '' } }); return ( @@ -25,7 +28,6 @@ const CreateDealFrom: FC = ({onSubmit, onCancel}) => { style={{width: '100%'}} onSubmit={form.onSubmit((values) => onSubmit(values))} > -
= ({onSubmit, onCancel}) => { +
diff --git a/src/components/ObjectAutocomplete/ObjectAutocomplete.tsx b/src/components/ObjectAutocomplete/ObjectAutocomplete.tsx new file mode 100644 index 0000000..31caf64 --- /dev/null +++ b/src/components/ObjectAutocomplete/ObjectAutocomplete.tsx @@ -0,0 +1,65 @@ +import {Autocomplete, AutocompleteProps} from "@mantine/core"; +import {useEffect, useMemo, useState} from "react"; +import {ObjectWithNameAndId} from "../../types/utils.ts"; +import {omit} from "lodash"; + + +export type AutocompleteObjectType = T; + +type ControlledValueProps = { + value: AutocompleteObjectType, + onChange: (value: string) => void; +} + +type RestProps = { + defaultValue?: AutocompleteObjectType + onChange: (value: string) => void; + data: AutocompleteObjectType[]; + filterBy?: (item: AutocompleteObjectType) => boolean; +} + +export type ObjectAutocompleteProps = + (RestProps & Partial>) + & Omit; + +const ObjectAutocomplete = (props: ObjectAutocompleteProps) => { + + const isControlled = 'value' in props; + const [internalValue, setInternalValue] = useState(props.defaultValue); + + const value = isControlled ? props.value?.name : internalValue; + + const data = useMemo(() => { + const propsData = props.filterBy ? props.data.filter(props.filterBy) : props.data; + + return propsData.map(item => ({ + label: item.name, + value: item.id.toString() + })); + }, [props.data]); + + const handleOnChange = (event: string | null) => { + if (!event) return; + if (isControlled) { + props.onChange(event); + return; + } + setInternalValue(event); + } + + useEffect(() => { + if (isControlled || !internalValue) return; + props.onChange(internalValue); + }, [internalValue]); + const restProps = omit(props, ['filterBy', 'groupBy']); + return ( + + ) +} + +export default ObjectAutocomplete; \ No newline at end of file diff --git a/src/components/Selects/ShippingWarehouseAutocomplete/ShippingWarehouseAutocomplete.tsx b/src/components/Selects/ShippingWarehouseAutocomplete/ShippingWarehouseAutocomplete.tsx new file mode 100644 index 0000000..b63adf5 --- /dev/null +++ b/src/components/Selects/ShippingWarehouseAutocomplete/ShippingWarehouseAutocomplete.tsx @@ -0,0 +1,17 @@ +import ObjectAutocomplete, {ObjectAutocompleteProps} from "../../ObjectAutocomplete/ObjectAutocomplete.tsx"; +import useShippingWarehousesList from "./hooks/useShippingWarehousesList.tsx"; +import {FC} from "react"; +import {ShippingWarehouseSchema} from "../../../client"; + +type Props = Omit, 'data'>; +const ShippingWarehouseAutocomplete: FC = (props) => { + const {shippingWarehouses} = useShippingWarehousesList(); + return ( + + ) +} + +export default ShippingWarehouseAutocomplete; \ No newline at end of file diff --git a/src/components/Selects/ShippingWarehouseAutocomplete/hooks/useShippingWarehousesList.tsx b/src/components/Selects/ShippingWarehouseAutocomplete/hooks/useShippingWarehousesList.tsx new file mode 100644 index 0000000..318e848 --- /dev/null +++ b/src/components/Selects/ShippingWarehouseAutocomplete/hooks/useShippingWarehousesList.tsx @@ -0,0 +1,13 @@ +import {useQuery} from "@tanstack/react-query"; +import {ShippingWarehouseService} from "../../../../client"; + +const useShippingWarehousesList = () => { + const {isPending, error, data, refetch} = useQuery({ + queryKey: ['getAllShippingWarehouses'], + queryFn: ShippingWarehouseService.getAllShippingWarehouses + }); + const shippingWarehouses = isPending || error || !data ? [] : data.shippingWarehouses; + + return {shippingWarehouses, refetch} +} +export default useShippingWarehousesList; \ No newline at end of file diff --git a/src/main.tsx b/src/main.tsx index 80b98aa..e6e6414 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -41,7 +41,6 @@ const queryClient = new QueryClient(); OpenAPI.BASE = import.meta.env.VITE_API_URL OpenAPI.TOKEN = JSON.parse(localStorage.getItem('authState') || "{}")['accessToken']; ReactDOM.createRoot(document.getElementById('root')!).render( - // @@ -54,5 +53,4 @@ ReactDOM.createRoot(document.getElementById('root')!).render( - // , ) diff --git a/src/pages/LeadsPage/components/DealServicesTable/columns.tsx b/src/pages/LeadsPage/components/DealServicesTable/columns.tsx index beab5dc..577f518 100644 --- a/src/pages/LeadsPage/components/DealServicesTable/columns.tsx +++ b/src/pages/LeadsPage/components/DealServicesTable/columns.tsx @@ -30,18 +30,15 @@ export const useDealServicesTableColumns = (props: Props) => { accessorKey: "price", header: "Цена", }, + { + enableGrouping: false, + accessorKey: "service.cost", + header: "Себестоимость" + }, { enableGrouping: false, accessorKey: "quantity", header: "Количество", - // Cell: ({row}) => { - // return ( - // onChange(row.original, value)} - // /> - // ) - // } }, { enableGrouping: false, diff --git a/src/pages/LeadsPage/drawers/DealEditDrawer/DealEditDrawer.tsx b/src/pages/LeadsPage/drawers/DealEditDrawer/DealEditDrawer.tsx index 80c5df1..9daff19 100644 --- a/src/pages/LeadsPage/drawers/DealEditDrawer/DealEditDrawer.tsx +++ b/src/pages/LeadsPage/drawers/DealEditDrawer/DealEditDrawer.tsx @@ -287,7 +287,6 @@ const DealEditDrawerProductsTable = () => { const useDealStatusChangeState = () => { const {selectedDeal} = useDealPageContext(); - return { statusHistory: selectedDeal?.statusHistory || [] } @@ -342,12 +341,6 @@ const DealEditDrawer: FC = () => { }> Товары и услуги - {/*}>*/} - {/* Услуги*/} - {/**/} - {/*}>*/} - {/* Товары*/} - {/**/} diff --git a/src/pages/LeadsPage/drawers/DealEditDrawer/tabs/DealEditDrawerGeneralTab.tsx b/src/pages/LeadsPage/drawers/DealEditDrawer/tabs/DealEditDrawerGeneralTab.tsx index b1d83f0..ed7e5e8 100644 --- a/src/pages/LeadsPage/drawers/DealEditDrawer/tabs/DealEditDrawerGeneralTab.tsx +++ b/src/pages/LeadsPage/drawers/DealEditDrawer/tabs/DealEditDrawerGeneralTab.tsx @@ -64,7 +64,6 @@ const Content: FC = ({deal}) => { return (
handleSubmit(values))}> -
= ({deal}) => { placeholder={"Текущий статус"} label={"Текущий статус"} value={DealStatusDictionary[deal.currentStatus as DealStatus]}/> -