feat: empty boxes, ids for shipping pdfs
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
export type CreateBoxInDealSchema = {
|
||||
productId: (number | null);
|
||||
quantity: (number | null);
|
||||
dealId: (number | null);
|
||||
};
|
||||
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
export type CreateBoxInPalletSchema = {
|
||||
productId: (number | null);
|
||||
quantity: (number | null);
|
||||
palletId: (number | null);
|
||||
};
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ type Props = {
|
||||
}
|
||||
|
||||
const BoxesTable = ({ items }: Props) => {
|
||||
const columns = useShippingTableColumns<BoxSchema>();
|
||||
const columns = useShippingTableColumns<BoxSchema>({ 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 }) => (
|
||||
<Flex gap="md">
|
||||
|
||||
@@ -15,7 +15,7 @@ type Props = {
|
||||
}
|
||||
|
||||
const ShippingProductsTable = ({ items }: Props) => {
|
||||
const columns = useShippingTableColumns<ShippingProductSchema>();
|
||||
const columns = useShippingTableColumns<ShippingProductSchema>({ 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,
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -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 (
|
||||
<Accordion.Item key={pallet.id} value={pallet.id.toString()}>
|
||||
<Center>
|
||||
<Accordion.Control icon={<IconSpace />}>
|
||||
Паллет {index + 1}
|
||||
Паллет - П{pallet.id}
|
||||
</Accordion.Control>
|
||||
{removePalletButton(pallet.id)}
|
||||
</Center>
|
||||
|
||||
@@ -1,20 +1,34 @@
|
||||
import { useMemo } from "react";
|
||||
import { MRT_ColumnDef, MRT_RowData } from "mantine-react-table";
|
||||
|
||||
const useShippingTableColumns = <T extends MRT_RowData>() => {
|
||||
type Props = {
|
||||
isBox: boolean;
|
||||
}
|
||||
|
||||
const useShippingTableColumns = <T extends MRT_RowData>({ isBox }: Props) => {
|
||||
const hideBoxColumns = ["id"];
|
||||
|
||||
return useMemo<MRT_ColumnDef<T>[]>(
|
||||
() => [
|
||||
{
|
||||
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 = <T extends MRT_RowData>() => {
|
||||
},
|
||||
],
|
||||
[],
|
||||
).filter(
|
||||
columnDef => isBox || !hideBoxColumns.includes(columnDef.accessorKey || ""),
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user