feat: cards, attributes and modules

This commit is contained in:
2025-02-19 14:46:13 +04:00
parent cc3e72bf94
commit dc9455966e
286 changed files with 2355 additions and 2168 deletions

View File

@@ -0,0 +1,44 @@
import { useMemo } from "react";
import { MRT_ColumnDef, MRT_RowData } from "mantine-react-table";
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: "Количество",
accessorKey: "quantity",
},
],
[],
).filter(
columnDef => isBox || !hideBoxColumns.includes(columnDef.accessorKey || ""),
);
};
export default useShippingTableColumns;

View 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;

View File

@@ -0,0 +1,35 @@
import { useCardPageContext } from "../../../contexts/CardPageContext.tsx";
const useShippingQrs = () => {
const { selectedCard: card } = useCardPageContext();
const basePdfUrl = `${import.meta.env.VITE_API_URL}/shipping/pdf`;
const getPdf = (url: string) => {
if (!card) return;
const pdfWindow = window.open(url);
if (!pdfWindow) return;
pdfWindow.print();
};
const onGetDealQrPdfClick = () => {
getPdf(`${basePdfUrl}/deal/${card?.id}`);
};
const onGetPalletsPdfClick = () => {
getPdf(`${basePdfUrl}/pallets/${card?.id}`);
};
const onGetBoxesPdfClick = () => {
getPdf(`${basePdfUrl}/boxes/${card?.id}`);
};
return {
onGetDealQrPdfClick,
onGetPalletsPdfClick,
onGetBoxesPdfClick,
};
};
export default useShippingQrs;

View File

@@ -0,0 +1,18 @@
import { useCardPageContext } from "../../../contexts/CardPageContext.tsx";
import { CardService } from "../../../../../client";
const useUpdateCard = () => {
const { selectedCard, setSelectedCard } = useCardPageContext();
const update = () => {
if (!selectedCard) return;
CardService.getCardById({ cardId: selectedCard.id })
.then(data => {
setSelectedCard(data);
});
};
return { update };
};
export default useUpdateCard;