diff --git a/src/api/bug/index.ts b/src/api/bug/index.ts index c03e687..2de129d 100644 --- a/src/api/bug/index.ts +++ b/src/api/bug/index.ts @@ -1,11 +1,11 @@ -import { useMutation, useQuery } from "@tanstack/react-query"; +import { useMutation } from "@tanstack/react-query"; import { instance } from ".."; import apiError from "@/hook/errorHandling"; interface BugProp { title: string; content: string; - file_name: string; + file_name: string[]; } export const BugPost = () => { @@ -28,11 +28,13 @@ export const BugPost = () => { export const BugImg = () => { const { handleError } = apiError(); - return useMutation({ + return useMutation({ mutationFn: async (param) => { try { const formData = new FormData(); - formData.append("file", param.file); + param.file.forEach((file) => { + formData.append("file", file); + }); const result = await instance.post(`/bug/upload`, formData); return result.data; } catch (error) { diff --git a/src/api/index.ts b/src/api/index.ts index 1eca8c3..895dbc1 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -34,7 +34,6 @@ refreshInstance.interceptors.request.use( }, (error: AxiosError) => Promise.reject(error) ); - instance.interceptors.response.use( (response) => response, async (error: AxiosError) => { @@ -42,22 +41,25 @@ instance.interceptors.response.use( const { status } = error.response; if (status === 401) { const refreshToken = cookie.get("refresh_token"); - if (refreshToken) { - try { - await axios - .put(`${BASEURL}/admin/refresh`, null, { - headers: { - "X-Refresh-Token": `${refreshToken}`, - }, - }) - .then((response) => { - const data = response.data; - cookie.set("access_token", data.access_token); - cookie.set("refresh_token", data.refresh_token); - }); - } catch (refreshError) { - return Promise.reject(refreshError); + try { + await axios + .put(`${BASEURL}/admin/refresh`, null, { + headers: { + "X-Refresh-Token": `${refreshToken}`, + }, + }) + .then((response) => { + const data = response.data; + cookie.set("access_token", data.access_token); + cookie.set("refresh_token", data.refresh_token); + }) + .catch(() => { + window.location.href = "login"; + }); + { } + } catch (refreshError) { + return Promise.reject(refreshError); } } } diff --git a/src/app/BugReport/page.tsx b/src/app/BugReport/page.tsx index 6f5787d..b8e727a 100644 --- a/src/app/BugReport/page.tsx +++ b/src/app/BugReport/page.tsx @@ -5,11 +5,13 @@ import Input from "@/components/input"; import TextArea from "@/components/input/textarea"; import Button from "@/components/button"; import { BugPost, BugImg } from "@/api/bug/index"; +import ImgModal from "@/components/modal/imgModal"; +import BugReportImg from "@/assets/svg/bugreport.svg"; interface bugProp { title: string; content: string; - file_name: string; + file_name: string[]; } const BugReport = () => { @@ -18,42 +20,32 @@ const BugReport = () => { const [data, setData] = useState({ title: "", content: "", - file_name: "", + file_name: [], }); - const [filename, setFilename] = useState(""); + const [modal, setModal] = useState(false); const handleContent = ({ text, name }: { text: string; name: string }) => { setData({ ...data, [name]: text }); }; - const handleFileChange = async (e: React.ChangeEvent) => { - const selectedFile = e.currentTarget.files?.[0]; - if (selectedFile) { - try { - await BugImgMutate( - { file: selectedFile }, - { - onSuccess: (data) => { - setFilename(data); - }, - onError: (error) => { - alert(error.message); - }, - } - ); - } catch (error) { - console.log(error); - } + const handleImgUpload = async (images: File[]) => { + try { + await BugImgMutate( + { file: images }, + { + onSuccess: (data) => { + setData((prevData) => ({ + ...prevData, + file_name: data, + })); + }, + } + ); + } catch (error) { + console.error("Upload failed:", error); } }; - useEffect(() => { - setData({ - ...data, - file_name: filename, - }); - }, [filename]); - const Bug = async () => { await BugPostMutate(data, { onSuccess: () => { @@ -61,7 +53,7 @@ const BugReport = () => { setData({ title: "", content: "", - file_name: filename ? filename : "", + file_name: [], }); }, onError: () => { @@ -98,9 +90,36 @@ const BugReport = () => { />
-
버그 사진을 첨부해주세요
- +
+ <> +

버그 사진을 첨부해주세요

+ +
{ + setModal(!modal); + }} + /> + +
+ { + setModal(!modal); + }} + />
+ +
+ + 또는 + +
+
+
+ 이미지를 붙여넣기 해주세요. +
+
+ {images.map((image, index) => ( +
+ {`Uploaded + +
+ ))} +
+
+ + +
+ + + ); +}; + +export default ImgModal; diff --git a/src/hook/errorHandling.ts b/src/hook/errorHandling.ts index e09c1cd..261c524 100644 --- a/src/hook/errorHandling.ts +++ b/src/hook/errorHandling.ts @@ -13,9 +13,7 @@ const apiError = () => { alert("400 잘못된 요청입니다"); }; - const handle401: ErrorHandler = () => { - router.push("login"); - }; + const handle401: ErrorHandler = () => {}; const handle403: ErrorHandler = () => { alert("403 권한이 없습니다"); diff --git a/tailwind.config.ts b/tailwind.config.ts index 3ebf9e6..90e4876 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -347,6 +347,7 @@ const config: Config = { }, spacing: { "4%": "4%", + "40%": "44%", }, }, },