diff --git a/src/client/models/BoxSchema.ts b/src/client/models/BoxSchema.ts index 541ae96..b7a71ac 100644 --- a/src/client/models/BoxSchema.ts +++ b/src/client/models/BoxSchema.ts @@ -6,7 +6,7 @@ import type { ProductSchema } from './ProductSchema'; export type BoxSchema = { id: number; quantity: number; - product: ProductSchema; + product: (ProductSchema | null); palletId: (number | null); dealId: (number | null); }; diff --git a/src/client/models/CreateBoxInDealSchema.ts b/src/client/models/CreateBoxInDealSchema.ts index dea6305..373942e 100644 --- a/src/client/models/CreateBoxInDealSchema.ts +++ b/src/client/models/CreateBoxInDealSchema.ts @@ -3,8 +3,6 @@ /* tslint:disable */ /* eslint-disable */ export type CreateBoxInDealSchema = { - productId: (number | null); - quantity: (number | null); dealId: (number | null); }; diff --git a/src/client/models/CreateBoxInPalletSchema.ts b/src/client/models/CreateBoxInPalletSchema.ts index 8bb8e42..902740e 100644 --- a/src/client/models/CreateBoxInPalletSchema.ts +++ b/src/client/models/CreateBoxInPalletSchema.ts @@ -3,8 +3,6 @@ /* tslint:disable */ /* eslint-disable */ export type CreateBoxInPalletSchema = { - productId: (number | null); - quantity: (number | null); palletId: (number | null); }; diff --git a/src/pages/LeadsPage/tabs/ShippingTab/components/BoxesTable.tsx b/src/pages/LeadsPage/tabs/ShippingTab/components/BoxesTable.tsx index cfeb4bf..cee0bdf 100644 --- a/src/pages/LeadsPage/tabs/ShippingTab/components/BoxesTable.tsx +++ b/src/pages/LeadsPage/tabs/ShippingTab/components/BoxesTable.tsx @@ -15,7 +15,7 @@ type Props = { } const BoxesTable = ({ items }: Props) => { - const columns = useShippingTableColumns(); + const columns = useShippingTableColumns({ isBox: true }); const { update } = useUpdateDeal(); const { selectedDeal: deal } = useDealPageContext(); @@ -42,7 +42,7 @@ const BoxesTable = ({ items }: Props) => { isBox: true, shippingData: { boxId: box.id, - productId: box.product.id, + productId: box.product?.id, quantity: box.quantity, }, }, @@ -58,7 +58,6 @@ const BoxesTable = ({ items }: Props) => { enableSorting: false, enableColumnActions: false, enableRowActions: true, - enableRowNumbers: true, positionActionsColumn: "last", renderRowActions: ({ row }) => ( diff --git a/src/pages/LeadsPage/tabs/ShippingTab/components/ShippingProductsTable.tsx b/src/pages/LeadsPage/tabs/ShippingTab/components/ShippingProductsTable.tsx index e26903a..d07f887 100644 --- a/src/pages/LeadsPage/tabs/ShippingTab/components/ShippingProductsTable.tsx +++ b/src/pages/LeadsPage/tabs/ShippingTab/components/ShippingProductsTable.tsx @@ -15,7 +15,7 @@ type Props = { } const ShippingProductsTable = ({ items }: Props) => { - const columns = useShippingTableColumns(); + const columns = useShippingTableColumns({ isBox: false }); const { update } = useUpdateDeal(); const { selectedDeal: deal } = useDealPageContext(); @@ -44,7 +44,7 @@ const ShippingProductsTable = ({ items }: Props) => { shippingProductId: shippingProduct.id, productId: shippingProduct.product.id, quantity: shippingProduct.quantity, - } + }, }, }); }; diff --git a/src/pages/LeadsPage/tabs/ShippingTab/components/ShippingTree.tsx b/src/pages/LeadsPage/tabs/ShippingTab/components/ShippingTree.tsx index a0e176a..182faf3 100644 --- a/src/pages/LeadsPage/tabs/ShippingTab/components/ShippingTree.tsx +++ b/src/pages/LeadsPage/tabs/ShippingTab/components/ShippingTree.tsx @@ -22,13 +22,13 @@ const ShippingTree = () => { const getPallets = () => { const sortedPallets = sortById(deal?.pallets) as PalletSchema[]; - const pallets = sortedPallets?.map(((pallet, index) => { + const pallets = sortedPallets?.map((pallet => { palletIds.push(pallet.id.toString()); return (
}> - Паллет {index + 1} + Паллет - П{pallet.id} {removePalletButton(pallet.id)}
diff --git a/src/pages/LeadsPage/tabs/ShippingTab/hooks/shippingTableColumns.tsx b/src/pages/LeadsPage/tabs/ShippingTab/hooks/shippingTableColumns.tsx index 9c8f4b9..ec38504 100644 --- a/src/pages/LeadsPage/tabs/ShippingTab/hooks/shippingTableColumns.tsx +++ b/src/pages/LeadsPage/tabs/ShippingTab/hooks/shippingTableColumns.tsx @@ -1,20 +1,34 @@ import { useMemo } from "react"; import { MRT_ColumnDef, MRT_RowData } from "mantine-react-table"; -const useShippingTableColumns = () => { +type Props = { + isBox: boolean; +} + +const useShippingTableColumns = ({ isBox }: Props) => { + const hideBoxColumns = ["id"]; + return useMemo[]>( () => [ + { + header: "ID", + accessorKey: "id", + Cell: ({ row }) => `K${row.original.id}`, + }, { header: "Название", accessorKey: "product.name", + Cell: ({ row }) => row.original.product?.name ?? "-", }, { header: "Артикул", accessorKey: "product.article", + Cell: ({ row }) => row.original.product?.article ?? "-", }, { header: "Размер", accessorKey: "product.size", + Cell: ({ row }) => row.original.product?.size ?? "-", }, { header: "Количество", @@ -22,6 +36,8 @@ const useShippingTableColumns = () => { }, ], [], + ).filter( + columnDef => isBox || !hideBoxColumns.includes(columnDef.accessorKey || ""), ); }; diff --git a/src/pages/LeadsPage/tabs/ShippingTab/hooks/useShipping.tsx b/src/pages/LeadsPage/tabs/ShippingTab/hooks/useShipping.tsx index a8eb5cb..7253e98 100644 --- a/src/pages/LeadsPage/tabs/ShippingTab/hooks/useShipping.tsx +++ b/src/pages/LeadsPage/tabs/ShippingTab/hooks/useShipping.tsx @@ -1,5 +1,5 @@ import { useDealPageContext } from "../../../contexts/DealPageContext.tsx"; -import { ShippingService } from "../../../../../client"; +import { CreateBoxInDealSchema, CreateBoxInPalletSchema, ShippingService } from "../../../../../client"; import { notifications } from "../../../../../shared/lib/notifications.ts"; import { modals } from "@mantine/modals"; import { Text } from "@mantine/core"; @@ -45,23 +45,38 @@ const useShipping = () => { }); }; - const openShippingModal = ( - title: string, - isBox: boolean, - palletId?: number, - dealId?: number, - ) => { + const onCreateBox = (data: CreateBoxInPalletSchema | CreateBoxInDealSchema) => { + ShippingService.updateBox({ + requestBody: { + data, + }, + }) + .then(({ ok, message }) => { + notifications.guess(ok, { message }); + update(); + }) + .catch(err => console.log(err)); + }; + + const onCreateBoxInDealClick = () => { + onCreateBox({ dealId: deal?.id ?? -1 }); + }; + + const onCreateBoxInPallet = (palletId: number) => { + onCreateBox({ palletId }); + }; + + const onCreateShippingProduct = (palletId: number) => { if (!deal) return; modals.openContextModal({ modal: "shippingProductModal", - title, + title: "Добавление товара на паллет", withCloseButton: false, innerProps: { deal, updateOnSubmit: update, - isBox, + isBox: false, shippingData: { - dealId, palletId, productId: null, quantity: null, @@ -70,31 +85,6 @@ const useShipping = () => { }); }; - const onCreateBoxInDealClick = () => { - openShippingModal( - "Добавление короба", - true, - undefined, - deal?.id, - ); - }; - - const onCreateBoxInPallet = (palletId: number) => { - openShippingModal( - "Добавление короба", - true, - palletId, - ); - }; - - const onCreateShippingProduct = (palletId: number) => { - openShippingModal( - "Добавление товара на паллет", - false, - palletId, - ); - }; - return { onCreateBoxInDealClick, onCreateBoxInPallet, diff --git a/src/pages/LeadsPage/tabs/ShippingTab/types/ShippingProductData.tsx b/src/pages/LeadsPage/tabs/ShippingTab/types/ShippingProductData.tsx index cad0ea6..1acfea9 100644 --- a/src/pages/LeadsPage/tabs/ShippingTab/types/ShippingProductData.tsx +++ b/src/pages/LeadsPage/tabs/ShippingTab/types/ShippingProductData.tsx @@ -1,10 +1,4 @@ -import { - CreateBoxInDealSchema, - CreateBoxInPalletSchema, - CreateShippingProductSchema, - UpdateBoxSchema, - UpdateShippingProductSchema, -} from "../../../../../client"; +import { CreateShippingProductSchema, UpdateBoxSchema, UpdateShippingProductSchema } from "../../../../../client"; export type ShippingModalForm = { quantity: number; @@ -17,8 +11,6 @@ export type ShippingProductOption = { } export type ShippingData = - CreateBoxInDealSchema - | CreateBoxInPalletSchema - | UpdateBoxSchema + UpdateBoxSchema | CreateShippingProductSchema | UpdateShippingProductSchema; \ No newline at end of file diff --git a/src/pages/LeadsPage/tabs/ShippingTab/utils/getRestProducts.tsx b/src/pages/LeadsPage/tabs/ShippingTab/utils/getRestProducts.tsx index 56a91b6..4088e0b 100644 --- a/src/pages/LeadsPage/tabs/ShippingTab/utils/getRestProducts.tsx +++ b/src/pages/LeadsPage/tabs/ShippingTab/utils/getRestProducts.tsx @@ -16,7 +16,7 @@ const getRestProducts = ({ unaccountedValues, }: Props) => { const totalProducts = new Map( - deal?.products.map(product => [product.product.id, product]), + deal?.products.map(product => product && [product.product.id, product]), ); const distributedProducts = new Map(); @@ -32,7 +32,7 @@ const getRestProducts = ({ }; deal?.boxes?.forEach((box) => { - if (box.id === unaccountedValues.boxId) return; + if (!box.product || box.id === unaccountedValues.boxId) return; accountProduct(box.product, box.quantity); }); @@ -42,7 +42,7 @@ const getRestProducts = ({ accountProduct(shippingProduct.product, shippingProduct.quantity); }); pallet.boxes.forEach((box) => { - if (box.id === unaccountedValues.boxId) return; + if (!box.product || box.id === unaccountedValues.boxId) return; accountProduct(box.product, box.quantity); }); });