From 31d2c8677041578e3c9824a0845227a8b1c523bc Mon Sep 17 00:00:00 2001 From: AlexSserb Date: Mon, 30 Sep 2024 00:44:15 +0400 Subject: [PATCH] fix: print deal's barcodes button moved from deals table to deal page --- .../tabs/DealEditDrawerGeneralTab.tsx | 66 +++++++++++++------ src/pages/LeadsPage/ui/LeadsPage.tsx | 38 +---------- 2 files changed, 48 insertions(+), 56 deletions(-) diff --git a/src/pages/LeadsPage/drawers/DealEditDrawer/tabs/DealEditDrawerGeneralTab.tsx b/src/pages/LeadsPage/drawers/DealEditDrawer/tabs/DealEditDrawerGeneralTab.tsx index 6d21c26..64a8a40 100644 --- a/src/pages/LeadsPage/drawers/DealEditDrawer/tabs/DealEditDrawerGeneralTab.tsx +++ b/src/pages/LeadsPage/drawers/DealEditDrawer/tabs/DealEditDrawerGeneralTab.tsx @@ -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 = ({ 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 = ({ deal }) => { placeholder={"Дата создания"} label={"Дата создания"} value={new Date(deal.createdAt).toLocaleString( - "ru-RU" + "ru-RU", )} /> = ({ deal }) => { value={ DealStatusDictionary[ deal.currentStatus as DealStatus - ] + ] } /> {deal.category && ( @@ -159,7 +154,7 @@ const Content: FC = ({ deal }) => { label={"Склад отгрузки"} value={ isShippingWarehouse( - form.values.shippingWarehouse + form.values.shippingWarehouse, ) ? form.values.shippingWarehouse : undefined @@ -167,12 +162,12 @@ const Content: FC = ({ 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 = ({ deal }) => { gap={rem(10)} align={"center"} justify={"space-between"}> + + { + 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"}> + + + + { 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 = ({ 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} diff --git a/src/pages/LeadsPage/ui/LeadsPage.tsx b/src/pages/LeadsPage/ui/LeadsPage.tsx index 6a71fda..1f7b975 100644 --- a/src/pages/LeadsPage/ui/LeadsPage.tsx +++ b/src/pages/LeadsPage/ui/LeadsPage.tsx @@ -9,17 +9,16 @@ import DealEditDrawer from "../drawers/DealEditDrawer/DealEditDrawer.tsx"; import { DealPageContextProvider } from "../contexts/DealPageContext.tsx"; import { modals } from "@mantine/modals"; 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 { 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 DealStatusSelect from "../../DealsPage/components/DealStatusSelect/DealStatusSelect.tsx"; import BaseMarketplaceSelect from "../../../components/Selects/BaseMarketplaceSelect/BaseMarketplaceSelect.tsx"; import ClientSelectNew from "../../../components/Selects/ClientSelectNew/ClientSelectNew.tsx"; import DealsTable from "../../DealsPage/components/DealsTable/DealsTable.tsx"; import { motion } from "framer-motion"; -import { base64ToBlob } from "../../../shared/lib/utils.ts"; enum DisplayMode { BOARD, @@ -346,39 +345,6 @@ export const LeadsPage: FC = () => { ? "flex" : "none", }}> - { - selectedDeals.length === 1 && - - { - 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"}> - - - - }