diff --git a/src/hooks/usePrintHandler.jsx b/src/hooks/usePrintHandler.jsx index 80d8caf..d00b2ea 100644 --- a/src/hooks/usePrintHandler.jsx +++ b/src/hooks/usePrintHandler.jsx @@ -1,22 +1,24 @@ -import { useContext, useState } from "react"; +import { useContext, useEffect, useState } from "react"; import { render } from "react-thermal-printer"; -// import { useContext } from "react"; -// import { useRecoilState } from "recoil"; -// import { portState } from "../Atom/status"; import UserReceipt from "../components/UserReceipt"; import { HomeContext } from "../pages/OrderManage/Home"; +import useMypageStoreInformation from "./Mypage/useMypageStoreInformation"; const usePrintHandler = () => { + const { getCafeInfo } = useMypageStoreInformation(); + const [cafeInfo, setCafeInfo] = useState({}); const context = useContext(HomeContext); const selectedInfo = context.selectedMenu; console.log(selectedInfo); // const [savePort, setSavePort] = useRecoilState(portState); const [savePort, setSavePort] = useState(null); console.log(savePort); + useEffect(() => { + setCafeInfo(getCafeInfo); + },[getCafeInfo]) const onClickPrintHandler = async () => { const data = await render(UserReceipt(selectedInfo[0])); - // const port = await window.navigator.serial.requestPort(); let port; if (savePort === null) { port = await window.navigator?.serial?.requestPort(); @@ -27,9 +29,13 @@ const usePrintHandler = () => { console.log(port); if (port.writable === null) { - // await port.open({ baudRate: 38400 }); - await port.open({ baudRate: 9600 }); + if (cafeInfo?.storeName === "카페 오르다") { + await port.open({ baudRate: 38400 }); + } else { + await port.open({ baudRate: 9600 }); + } } + const writer = port.writable?.getWriter(); if (writer !== null) { await writer.write(data).then(() => setTimeout(() => port.close(), 500)); // ←