feat: cards, attributes and modules
This commit is contained in:
98
src/pages/CardsPage/tabs/ShippingTab/hooks/useShipping.tsx
Normal file
98
src/pages/CardsPage/tabs/ShippingTab/hooks/useShipping.tsx
Normal file
@@ -0,0 +1,98 @@
|
||||
import { useCardPageContext } from "../../../contexts/CardPageContext.tsx";
|
||||
import { CreateBoxInCardSchema, CreateBoxInPalletSchema, 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";
|
||||
|
||||
const useShipping = () => {
|
||||
const { selectedCard: card } = useCardPageContext();
|
||||
const { update } = useUpdateCard();
|
||||
const palletIds: string[] = [];
|
||||
|
||||
const onCreatePalletClick = () => {
|
||||
if (!card) return;
|
||||
|
||||
ShippingService.createPallet({
|
||||
cardId: card.id,
|
||||
})
|
||||
.then(({ ok, message }) => {
|
||||
notifications.guess(ok, { message });
|
||||
update();
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
};
|
||||
|
||||
const onDeletePallet = (palletId: number) => {
|
||||
ShippingService.deletePallet({
|
||||
palletId: palletId,
|
||||
})
|
||||
.then(({ ok, message }) => {
|
||||
if (!ok) notifications.guess(ok, { message });
|
||||
update();
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
};
|
||||
|
||||
const onDeletePalletClick = (palletId: number) => {
|
||||
if (!card) return;
|
||||
modals.openConfirmModal({
|
||||
title: "Удаление паллета",
|
||||
children: <Text size="sm">Вы уверены что хотите удалить паллет?</Text>,
|
||||
labels: { confirm: "Да", cancel: "Нет" },
|
||||
confirmProps: { color: "red" },
|
||||
onConfirm: () => onDeletePallet(palletId),
|
||||
});
|
||||
};
|
||||
|
||||
const onCreateBox = (data: CreateBoxInPalletSchema | CreateBoxInCardSchema) => {
|
||||
ShippingService.updateBox({
|
||||
requestBody: {
|
||||
data,
|
||||
},
|
||||
})
|
||||
.then(({ ok, message }) => {
|
||||
notifications.guess(ok, { message });
|
||||
update();
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
};
|
||||
|
||||
const onCreateBoxInCardClick = () => {
|
||||
onCreateBox({ cardId: card?.id ?? -1 });
|
||||
};
|
||||
|
||||
const onCreateBoxInPallet = (palletId: number) => {
|
||||
onCreateBox({ palletId });
|
||||
};
|
||||
|
||||
const onCreateShippingProduct = (palletId: number) => {
|
||||
if (!card) return;
|
||||
modals.openContextModal({
|
||||
modal: "shippingProductModal",
|
||||
title: "Добавление товара на паллет",
|
||||
withCloseButton: false,
|
||||
innerProps: {
|
||||
card,
|
||||
updateOnSubmit: update,
|
||||
isBox: false,
|
||||
shippingData: {
|
||||
palletId,
|
||||
productId: null,
|
||||
quantity: null,
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
onCreateBoxInCardClick,
|
||||
onCreateBoxInPallet,
|
||||
onCreateShippingProduct,
|
||||
onCreatePalletClick,
|
||||
onDeletePalletClick,
|
||||
palletIds,
|
||||
};
|
||||
};
|
||||
|
||||
export default useShipping;
|
||||
Reference in New Issue
Block a user