feat: a few shipping products in box
This commit is contained in:
@@ -1,14 +1,20 @@
|
||||
import { useCardPageContext } from "../../../contexts/CardPageContext.tsx";
|
||||
import { CreateBoxInCardSchema, CreateBoxInPalletSchema, ShippingService } from "../../../../../client";
|
||||
import {
|
||||
CreateBoxInCardSchema,
|
||||
CreateBoxInPalletSchema, PalletSchema,
|
||||
ShippingService,
|
||||
} from "../../../../../client";
|
||||
import { notifications } from "../../../../../shared/lib/notifications.ts";
|
||||
import { modals } from "@mantine/modals";
|
||||
import { Text } from "@mantine/core";
|
||||
import useUpdateCard from "./useUpdateCard.tsx";
|
||||
import { useState } from "react";
|
||||
import { ShippingProductParentData } from "../types/ShippingProductData.tsx";
|
||||
|
||||
const useShipping = () => {
|
||||
const { selectedCard: card } = useCardPageContext();
|
||||
const { update } = useUpdateCard();
|
||||
const palletIds: string[] = [];
|
||||
const [palletIds, setPalletIds] = useState<number[]>([]);
|
||||
|
||||
const onCreatePalletClick = () => {
|
||||
if (!card) return;
|
||||
@@ -34,19 +40,24 @@ const useShipping = () => {
|
||||
.catch(err => console.log(err));
|
||||
};
|
||||
|
||||
const onDeletePalletClick = (palletId: number) => {
|
||||
const onDeletePalletClick = (pallet: PalletSchema) => {
|
||||
if (!card) return;
|
||||
if (pallet.shippingProducts.length === 0 && pallet.boxes.length === 0) {
|
||||
onDeletePallet(pallet.id);
|
||||
return;
|
||||
}
|
||||
|
||||
modals.openConfirmModal({
|
||||
title: "Удаление паллета",
|
||||
children: <Text size="sm">Вы уверены что хотите удалить паллет?</Text>,
|
||||
labels: { confirm: "Да", cancel: "Нет" },
|
||||
confirmProps: { color: "red" },
|
||||
onConfirm: () => onDeletePallet(palletId),
|
||||
onConfirm: () => onDeletePallet(pallet.id),
|
||||
});
|
||||
};
|
||||
|
||||
const onCreateBox = (data: CreateBoxInPalletSchema | CreateBoxInCardSchema) => {
|
||||
ShippingService.updateBox({
|
||||
ShippingService.createBox({
|
||||
requestBody: {
|
||||
data,
|
||||
},
|
||||
@@ -66,18 +77,20 @@ const useShipping = () => {
|
||||
onCreateBox({ palletId });
|
||||
};
|
||||
|
||||
const onCreateShippingProduct = (palletId: number) => {
|
||||
const onCreateShippingProduct = ({ palletId, boxId }: ShippingProductParentData) => {
|
||||
if (!card) return;
|
||||
const postfix = palletId ? "на паллет" : "в короб";
|
||||
|
||||
modals.openContextModal({
|
||||
modal: "shippingProductModal",
|
||||
title: "Добавление товара на паллет",
|
||||
title: "Добавление товара " + postfix,
|
||||
withCloseButton: false,
|
||||
innerProps: {
|
||||
card,
|
||||
updateOnSubmit: update,
|
||||
isBox: false,
|
||||
shippingData: {
|
||||
palletId,
|
||||
boxId,
|
||||
productId: null,
|
||||
quantity: null,
|
||||
},
|
||||
@@ -92,6 +105,7 @@ const useShipping = () => {
|
||||
onCreatePalletClick,
|
||||
onDeletePalletClick,
|
||||
palletIds,
|
||||
setPalletIds,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user