feat: a few shipping products in box
This commit is contained in:
@@ -3,14 +3,11 @@ import { ContextModalProps } from "@mantine/modals";
|
||||
import { Button, Flex, NumberInput, rem, Text } from "@mantine/core";
|
||||
import getRestProducts from "../utils/getRestProducts.tsx";
|
||||
import {
|
||||
CreateBoxInCardSchema,
|
||||
CreateBoxInPalletSchema,
|
||||
CreateShippingProductSchema,
|
||||
CardProductSchema,
|
||||
CardSchema,
|
||||
CreateShippingProductSchema,
|
||||
ProductSchema,
|
||||
ShippingService,
|
||||
UpdateBoxSchema,
|
||||
UpdateShippingProductSchema,
|
||||
} from "../../../../../client";
|
||||
import { notifications } from "../../../../../shared/lib/notifications.ts";
|
||||
@@ -22,7 +19,6 @@ import ShippingProductSelect from "../components/ShippingProductSelect.tsx";
|
||||
type Props = {
|
||||
updateOnSubmit: () => void;
|
||||
card: CardSchema;
|
||||
isBox: boolean;
|
||||
shippingData: Partial<ShippingData>;
|
||||
}
|
||||
|
||||
@@ -65,31 +61,13 @@ const ShippingProductModal = ({
|
||||
useEffect(() => {
|
||||
const data = getRestProducts({
|
||||
card: innerProps.card,
|
||||
unaccountedValues: innerProps.shippingData as UpdateShippingProductSchema | UpdateBoxSchema,
|
||||
shippingProductId: (innerProps.shippingData as UpdateShippingProductSchema).shippingProductId,
|
||||
});
|
||||
setRestProducts(data.restProducts);
|
||||
setRestProductSelectData(data.restProductsSelectData);
|
||||
}, [innerProps.card]);
|
||||
|
||||
const updateBox = () => {
|
||||
const data = {
|
||||
...innerProps.shippingData,
|
||||
...form.values,
|
||||
productId: form.values.product?.id,
|
||||
} as CreateBoxInPalletSchema | CreateBoxInCardSchema | UpdateBoxSchema;
|
||||
|
||||
ShippingService.updateBox({
|
||||
requestBody: { data },
|
||||
})
|
||||
.then(({ ok, message }) => {
|
||||
notifications.guess(ok, { message: message });
|
||||
innerProps.updateOnSubmit();
|
||||
if (ok) context.closeContextModal(id);
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
};
|
||||
|
||||
const updateShippingProduct = () => {
|
||||
const onSubmit = () => {
|
||||
const data = {
|
||||
...innerProps.shippingData,
|
||||
...form.values,
|
||||
@@ -107,14 +85,6 @@ const ShippingProductModal = ({
|
||||
.catch(err => console.log(err));
|
||||
};
|
||||
|
||||
const onSubmit = () => {
|
||||
if (innerProps.isBox) {
|
||||
updateBox();
|
||||
} else {
|
||||
updateShippingProduct();
|
||||
}
|
||||
};
|
||||
|
||||
const getRestQuantityText = () => {
|
||||
if (!form.values.product) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user