fix: print deal's barcodes button moved from deals table to deal page

This commit is contained in:
2024-09-30 00:44:15 +04:00
parent cbb75f0110
commit 31d2c86770
2 changed files with 48 additions and 56 deletions

View File

@@ -14,26 +14,21 @@ import {
Tooltip,
} from "@mantine/core";
import { useForm } from "@mantine/form";
import {
ClientService,
DealSchema,
DealService,
ShippingWarehouseSchema,
} from "../../../../../client";
import {
DealStatus,
DealStatusDictionary,
} from "../../../../../shared/enums/DealStatus.ts";
import { ClientService, DealSchema, DealService, ShippingWarehouseSchema } from "../../../../../client";
import { DealStatus, DealStatusDictionary } from "../../../../../shared/enums/DealStatus.ts";
import { isEqual } from "lodash";
import { notifications } from "../../../../../shared/lib/notifications.ts";
import { useQueryClient } from "@tanstack/react-query";
import ShippingWarehouseAutocomplete from "../../../../../components/Selects/ShippingWarehouseAutocomplete/ShippingWarehouseAutocomplete.tsx";
import ShippingWarehouseAutocomplete
from "../../../../../components/Selects/ShippingWarehouseAutocomplete/ShippingWarehouseAutocomplete.tsx";
import { ButtonCopyControlled } from "../../../../../components/ButtonCopyControlled/ButtonCopyControlled.tsx";
import { useClipboard } from "@mantine/hooks";
import ButtonCopy from "../../../../../components/ButtonCopy/ButtonCopy.tsx";
import FileSaver from "file-saver";
import { getCurrentDateTimeForFilename } from "../../../../../shared/lib/date.ts";
import { IconPrinter } from "@tabler/icons-react";
import { IconBarcode, IconPrinter } from "@tabler/icons-react";
import styles from "../../../ui/LeadsPage.module.css";
import { base64ToBlob } from "../../../../../shared/lib/utils.ts";
type Props = {
deal: DealSchema;
@@ -93,7 +88,7 @@ const Content: FC<Props> = ({ deal }) => {
await updateDealInfo(values);
};
const isShippingWarehouse = (
value: ShippingWarehouseSchema | string | null | undefined
value: ShippingWarehouseSchema | string | null | undefined,
): value is ShippingWarehouseSchema => {
return !["string", "null", "undefined"].includes(typeof value);
};
@@ -128,7 +123,7 @@ const Content: FC<Props> = ({ deal }) => {
placeholder={"Дата создания"}
label={"Дата создания"}
value={new Date(deal.createdAt).toLocaleString(
"ru-RU"
"ru-RU",
)}
/>
<TextInput
@@ -138,7 +133,7 @@ const Content: FC<Props> = ({ deal }) => {
value={
DealStatusDictionary[
deal.currentStatus as DealStatus
]
]
}
/>
{deal.category && (
@@ -159,7 +154,7 @@ const Content: FC<Props> = ({ deal }) => {
label={"Склад отгрузки"}
value={
isShippingWarehouse(
form.values.shippingWarehouse
form.values.shippingWarehouse,
)
? form.values.shippingWarehouse
: undefined
@@ -167,12 +162,12 @@ const Content: FC<Props> = ({ deal }) => {
onChange={event => {
if (isShippingWarehouse(event)) {
form.getInputProps(
"shippingWarehouse"
"shippingWarehouse",
).onChange(event.name);
return;
}
form.getInputProps(
"shippingWarehouse"
"shippingWarehouse",
).onChange(event);
}}
/>
@@ -191,11 +186,42 @@ const Content: FC<Props> = ({ deal }) => {
gap={rem(10)}
align={"center"}
justify={"space-between"}>
<Tooltip
className={styles["print-deals-button"]}
label={"Распечатать штрихкоды сделки"}
>
<ActionIcon
onClick={async () => {
const response =
await DealService.getDealProductsBarcodesPdf({
requestBody: {
dealId: deal.id,
},
});
const pdfBlob = base64ToBlob(
response.base64String,
response.mimeType,
);
const pdfUrl = URL.createObjectURL(pdfBlob);
const pdfWindow = window.open(pdfUrl);
if (!pdfWindow) {
notifications.error({ message: "Ошибка" });
return;
}
pdfWindow.onload = () => {
pdfWindow.print();
};
}}
variant={"default"}>
<IconBarcode />
</ActionIcon>
</Tooltip>
<Tooltip label={"Распечатать сделку"}>
<ActionIcon
onClick={() => {
const pdfWindow = window.open(
`${import.meta.env.VITE_API_URL}/deal/detailedDocument/${deal.id}`
`${import.meta.env.VITE_API_URL}/deal/detailedDocument/${deal.id}`,
);
if (!pdfWindow) return;
pdfWindow.print();
@@ -221,7 +247,7 @@ const Content: FC<Props> = ({ deal }) => {
getCurrentDateTimeForFilename();
FileSaver.saveAs(
`${import.meta.env.VITE_API_URL}/deal/document/${deal.id}`,
`bill_${deal.id}_${date}.pdf`
`bill_${deal.id}_${date}.pdf`,
);
}}
copied={false}