fix: print deal's barcodes button moved from deals table to deal page
This commit is contained in:
@@ -14,26 +14,21 @@ import {
|
|||||||
Tooltip,
|
Tooltip,
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import { useForm } from "@mantine/form";
|
import { useForm } from "@mantine/form";
|
||||||
import {
|
import { ClientService, DealSchema, DealService, ShippingWarehouseSchema } from "../../../../../client";
|
||||||
ClientService,
|
import { DealStatus, DealStatusDictionary } from "../../../../../shared/enums/DealStatus.ts";
|
||||||
DealSchema,
|
|
||||||
DealService,
|
|
||||||
ShippingWarehouseSchema,
|
|
||||||
} from "../../../../../client";
|
|
||||||
import {
|
|
||||||
DealStatus,
|
|
||||||
DealStatusDictionary,
|
|
||||||
} from "../../../../../shared/enums/DealStatus.ts";
|
|
||||||
import { isEqual } from "lodash";
|
import { isEqual } from "lodash";
|
||||||
import { notifications } from "../../../../../shared/lib/notifications.ts";
|
import { notifications } from "../../../../../shared/lib/notifications.ts";
|
||||||
import { useQueryClient } from "@tanstack/react-query";
|
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 { ButtonCopyControlled } from "../../../../../components/ButtonCopyControlled/ButtonCopyControlled.tsx";
|
||||||
import { useClipboard } from "@mantine/hooks";
|
import { useClipboard } from "@mantine/hooks";
|
||||||
import ButtonCopy from "../../../../../components/ButtonCopy/ButtonCopy.tsx";
|
import ButtonCopy from "../../../../../components/ButtonCopy/ButtonCopy.tsx";
|
||||||
import FileSaver from "file-saver";
|
import FileSaver from "file-saver";
|
||||||
import { getCurrentDateTimeForFilename } from "../../../../../shared/lib/date.ts";
|
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 = {
|
type Props = {
|
||||||
deal: DealSchema;
|
deal: DealSchema;
|
||||||
@@ -93,7 +88,7 @@ const Content: FC<Props> = ({ deal }) => {
|
|||||||
await updateDealInfo(values);
|
await updateDealInfo(values);
|
||||||
};
|
};
|
||||||
const isShippingWarehouse = (
|
const isShippingWarehouse = (
|
||||||
value: ShippingWarehouseSchema | string | null | undefined
|
value: ShippingWarehouseSchema | string | null | undefined,
|
||||||
): value is ShippingWarehouseSchema => {
|
): value is ShippingWarehouseSchema => {
|
||||||
return !["string", "null", "undefined"].includes(typeof value);
|
return !["string", "null", "undefined"].includes(typeof value);
|
||||||
};
|
};
|
||||||
@@ -128,7 +123,7 @@ const Content: FC<Props> = ({ deal }) => {
|
|||||||
placeholder={"Дата создания"}
|
placeholder={"Дата создания"}
|
||||||
label={"Дата создания"}
|
label={"Дата создания"}
|
||||||
value={new Date(deal.createdAt).toLocaleString(
|
value={new Date(deal.createdAt).toLocaleString(
|
||||||
"ru-RU"
|
"ru-RU",
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
@@ -138,7 +133,7 @@ const Content: FC<Props> = ({ deal }) => {
|
|||||||
value={
|
value={
|
||||||
DealStatusDictionary[
|
DealStatusDictionary[
|
||||||
deal.currentStatus as DealStatus
|
deal.currentStatus as DealStatus
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
{deal.category && (
|
{deal.category && (
|
||||||
@@ -159,7 +154,7 @@ const Content: FC<Props> = ({ deal }) => {
|
|||||||
label={"Склад отгрузки"}
|
label={"Склад отгрузки"}
|
||||||
value={
|
value={
|
||||||
isShippingWarehouse(
|
isShippingWarehouse(
|
||||||
form.values.shippingWarehouse
|
form.values.shippingWarehouse,
|
||||||
)
|
)
|
||||||
? form.values.shippingWarehouse
|
? form.values.shippingWarehouse
|
||||||
: undefined
|
: undefined
|
||||||
@@ -167,12 +162,12 @@ const Content: FC<Props> = ({ deal }) => {
|
|||||||
onChange={event => {
|
onChange={event => {
|
||||||
if (isShippingWarehouse(event)) {
|
if (isShippingWarehouse(event)) {
|
||||||
form.getInputProps(
|
form.getInputProps(
|
||||||
"shippingWarehouse"
|
"shippingWarehouse",
|
||||||
).onChange(event.name);
|
).onChange(event.name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
form.getInputProps(
|
form.getInputProps(
|
||||||
"shippingWarehouse"
|
"shippingWarehouse",
|
||||||
).onChange(event);
|
).onChange(event);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@@ -191,11 +186,42 @@ const Content: FC<Props> = ({ deal }) => {
|
|||||||
gap={rem(10)}
|
gap={rem(10)}
|
||||||
align={"center"}
|
align={"center"}
|
||||||
justify={"space-between"}>
|
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={"Распечатать сделку"}>
|
<Tooltip label={"Распечатать сделку"}>
|
||||||
<ActionIcon
|
<ActionIcon
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
const pdfWindow = window.open(
|
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;
|
if (!pdfWindow) return;
|
||||||
pdfWindow.print();
|
pdfWindow.print();
|
||||||
@@ -221,7 +247,7 @@ const Content: FC<Props> = ({ deal }) => {
|
|||||||
getCurrentDateTimeForFilename();
|
getCurrentDateTimeForFilename();
|
||||||
FileSaver.saveAs(
|
FileSaver.saveAs(
|
||||||
`${import.meta.env.VITE_API_URL}/deal/document/${deal.id}`,
|
`${import.meta.env.VITE_API_URL}/deal/document/${deal.id}`,
|
||||||
`bill_${deal.id}_${date}.pdf`
|
`bill_${deal.id}_${date}.pdf`,
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
copied={false}
|
copied={false}
|
||||||
|
|||||||
@@ -9,17 +9,16 @@ import DealEditDrawer from "../drawers/DealEditDrawer/DealEditDrawer.tsx";
|
|||||||
import { DealPageContextProvider } from "../contexts/DealPageContext.tsx";
|
import { DealPageContextProvider } from "../contexts/DealPageContext.tsx";
|
||||||
import { modals } from "@mantine/modals";
|
import { modals } from "@mantine/modals";
|
||||||
import { DealService, DealSummary, DealSummaryReorderRequest } from "../../../client";
|
import { DealService, DealSummary, DealSummaryReorderRequest } from "../../../client";
|
||||||
import { ActionIcon, Flex, NumberInput, rem, Text, Tooltip } from "@mantine/core";
|
import { ActionIcon, Flex, NumberInput, rem, Text } from "@mantine/core";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import { notifications } from "../../../shared/lib/notifications.ts";
|
import { notifications } from "../../../shared/lib/notifications.ts";
|
||||||
import { IconBarcode, IconMenu2, IconMenuDeep } from "@tabler/icons-react";
|
import { IconMenu2, IconMenuDeep } from "@tabler/icons-react";
|
||||||
import useDealsPageState from "../../DealsPage/hooks/useDealsPageState.tsx";
|
import useDealsPageState from "../../DealsPage/hooks/useDealsPageState.tsx";
|
||||||
import DealStatusSelect from "../../DealsPage/components/DealStatusSelect/DealStatusSelect.tsx";
|
import DealStatusSelect from "../../DealsPage/components/DealStatusSelect/DealStatusSelect.tsx";
|
||||||
import BaseMarketplaceSelect from "../../../components/Selects/BaseMarketplaceSelect/BaseMarketplaceSelect.tsx";
|
import BaseMarketplaceSelect from "../../../components/Selects/BaseMarketplaceSelect/BaseMarketplaceSelect.tsx";
|
||||||
import ClientSelectNew from "../../../components/Selects/ClientSelectNew/ClientSelectNew.tsx";
|
import ClientSelectNew from "../../../components/Selects/ClientSelectNew/ClientSelectNew.tsx";
|
||||||
import DealsTable from "../../DealsPage/components/DealsTable/DealsTable.tsx";
|
import DealsTable from "../../DealsPage/components/DealsTable/DealsTable.tsx";
|
||||||
import { motion } from "framer-motion";
|
import { motion } from "framer-motion";
|
||||||
import { base64ToBlob } from "../../../shared/lib/utils.ts";
|
|
||||||
|
|
||||||
enum DisplayMode {
|
enum DisplayMode {
|
||||||
BOARD,
|
BOARD,
|
||||||
@@ -346,39 +345,6 @@ export const LeadsPage: FC = () => {
|
|||||||
? "flex"
|
? "flex"
|
||||||
: "none",
|
: "none",
|
||||||
}}>
|
}}>
|
||||||
{
|
|
||||||
selectedDeals.length === 1 &&
|
|
||||||
<Tooltip
|
|
||||||
className={styles["print-deals-button"]}
|
|
||||||
label={"Распечатать штрихкоды сделки"}
|
|
||||||
>
|
|
||||||
<ActionIcon
|
|
||||||
onClick={async () => {
|
|
||||||
const response =
|
|
||||||
await DealService.getDealProductsBarcodesPdf({
|
|
||||||
requestBody: {
|
|
||||||
dealId: selectedDeals[0].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>
|
|
||||||
}
|
|
||||||
<NumberInput
|
<NumberInput
|
||||||
min={1}
|
min={1}
|
||||||
placeholder={"Введите номер"}
|
placeholder={"Введите номер"}
|
||||||
|
|||||||
Reference in New Issue
Block a user