From 0b3390546f97006a49580c2e0a8bd8556890bc46 Mon Sep 17 00:00:00 2001 From: yoosangwook Date: Fri, 1 Nov 2024 17:43:15 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=8F=84=EB=A9=B4=EC=9D=84=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=EB=A1=9C=20=EC=BB=A8=EB=B2=84=ED=8C=85=20?= =?UTF-8?q?=ED=9B=84=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=97=85=EB=A1=9C?= =?UTF-8?q?=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../placementShape/PlacementShapeSetting.jsx | 4 +-- src/hooks/common/useRefFiles.js | 30 ++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/components/floor-plan/modal/placementShape/PlacementShapeSetting.jsx b/src/components/floor-plan/modal/placementShape/PlacementShapeSetting.jsx index 539dbdf1..2052bff9 100644 --- a/src/components/floor-plan/modal/placementShape/PlacementShapeSetting.jsx +++ b/src/components/floor-plan/modal/placementShape/PlacementShapeSetting.jsx @@ -19,7 +19,7 @@ export default function PlacementShapeSetting({ id, pos = { x: 50, y: 180 }, set const [canvasSetting, setCanvasSetting] = useRecoilState(canvasSettingState) const { closePopup } = usePopup() const [basicSetting, setBasicSettings] = useRecoilState(basicSettingState) - const { refImage, setRefImage } = useRefFiles() + const { refImage, setRefImage, handleRefFile } = useRefFiles() const { getMessage } = useMessage() const { get, post } = useAxios() @@ -490,7 +490,7 @@ export default function PlacementShapeSetting({ id, pos = { x: 50, y: 180 }, set {getMessage('common.input.file.load')} - setRefImage(e.target.files[0])} /> + handleRefFile(e.target.files[0])} />
diff --git a/src/hooks/common/useRefFiles.js b/src/hooks/common/useRefFiles.js index 8cb046d5..c241b1e0 100644 --- a/src/hooks/common/useRefFiles.js +++ b/src/hooks/common/useRefFiles.js @@ -1,11 +1,39 @@ import { useState } from 'react' +import { convertDwgToPng } from '@/lib/cadAction' +import { useSwal } from '@/hooks/useSwal' export default function useRefFiles() { - const [refImage, setRefImage] = useState(null) const converterUrl = process.env.NEXT_PUBLIC_CONVERTER_API_URL + const [refImage, setRefImage] = useState(null) + + const { swalFire } = useSwal() + + const handleRefFile = (file) => { + setRefImage(file) + console.log('๐Ÿš€ ~ handleRefFile ~ file:', file) + file.name.split('.').pop() === 'dwg' ? handleUploadRefFile(file) : () => {} + console.log("๐Ÿš€ ~ handleRefFile ~ file.name.split('.').pop():", file.name.split('.').pop()) + // handleUploadRefFile(file) + } + + // RefFile์ด ์บ๋“œ ๋„๋ฉด ํŒŒ์ผ์ผ ๊ฒฝ์šฐ ๋ณ€ํ™˜ํ•˜์—ฌ ์ด๋ฏธ์ง€๋กœ ์ €์žฅ + const handleUploadRefFile = async (file) => { + const formData = new FormData() + formData.append('file', file) + + await promisePost({ url: converterUrl, data: formData }) + .then((res) => { + convertDwgToPng(res.data.Files[0].FileName, res.data.Files[0].FileData) + swalFire({ text: 'ํŒŒ์ผ ๋ณ€ํ™˜ ์„ฑ๊ณต' }) + }) + .catch((err) => { + swalFire({ text: 'ํŒŒ์ผ ๋ณ€ํ™˜ ์‹คํŒจ', icon: 'error' }) + }) + } return { refImage, setRefImage, + handleRefFile, } }