diff --git a/src/api/inquiry.js b/src/api/inquiry.js index b76112e..cbda1b3 100644 --- a/src/api/inquiry.js +++ b/src/api/inquiry.js @@ -26,4 +26,18 @@ export const getInquiry = async ({ page, size, inquiryType, inquiryStatus }) => console.error(error); throw error; } +} + +export const patchInquiryStatus = async ({ inquiryId, answer, status }) => { + try { + const response = await client.patch(`/api/v1/admin/inquiry/${inquiryId}`, { + answer: answer, + status: status, + }); + return response; + } + catch (error) { + console.error(error); + throw error; + } } \ No newline at end of file diff --git a/src/api/report.js b/src/api/report.js index 721733f..54effa2 100644 --- a/src/api/report.js +++ b/src/api/report.js @@ -20,12 +20,15 @@ export const getReport = async ({ postType, startDate, endDate, nickname, pageab export const patchReport = async ({ reportId, reportStatus }) => { try { - const response = await client.patch(`/api/v1/admin/report/${reportId}`, null, { - params: { - reportStatus: reportStatus, - }, - }); - return response.data; + const response = await client.patch(`/api/v1/admin/report/${reportId}`, + null, + { + params: { + reportStatus: reportStatus, + }, + } + ); + return response; } catch (error) { console.error(error); throw error; diff --git a/src/components/common/table.jsx b/src/components/common/table.jsx index 8d45a97..50d4eaf 100644 --- a/src/components/common/table.jsx +++ b/src/components/common/table.jsx @@ -5,7 +5,13 @@ export default function Table({ columns, data, renderAction, onRowClick, origina {columns.map((col) => ( - {col.value} + + {col.value} + ))} @@ -17,7 +23,11 @@ export default function Table({ columns, data, renderAction, onRowClick, origina onClick={() => onRowClick && onRowClick(row, originalData && originalData[idx])} > {columns.map((col) => ( - + {col.render ? col.render(row[col.key], row) : row[col.key]} ))} diff --git a/src/pages/inquiry.jsx b/src/pages/inquiry.jsx index 7cc0744..6fced7e 100644 --- a/src/pages/inquiry.jsx +++ b/src/pages/inquiry.jsx @@ -1,4 +1,4 @@ -import { getInquiry } from "../api/inquiry"; +import { getInquiry, patchInquiryStatus } from "../api/inquiry"; import AdminLayout from "../components/layout/adminLayout"; import Table from "../components/common/table"; import Pagination from "../components/common/pagination"; @@ -11,12 +11,29 @@ export default function Inquiry() { const pageSize = 10; const [inquiryType, setInquiryType] = useState("ALL"); const [inquiryStatus, setInquiryStatus] = useState("ALL"); + const [selectedInquiry, setSelectedInquiry] = useState(null); + const [showModal, setShowModal] = useState(false); + const [selectedStatus, setSelectedStatus] = useState(null); + const [answer, setAnswer] = useState(""); const columns = [ { key: "문의 유형", value: "문의 유형" }, { key: "문의 제목", value: "문의 제목" }, - { key: "문의 내용", value: "문의 내용" }, + { + key: "문의 내용", + value: "문의 내용", + maxWidth: "600px", + render: (content) => { + if (!content) return ""; + const truncated = content.length > 40 ? content.substring(0, 40) + "..." : content; + return ( +
+ {truncated} +
+ ); + } + }, { key: "문의 상태", value: "문의 상태" }, { key: "작성자", value: "작성자" }, { key: "문의 작성일", value: "문의 작성일" }, @@ -31,7 +48,8 @@ export default function Inquiry() { setInquiryStatus(value); setCurrentPage(0); }; - + + const getInquiryData = async () => { try { const params = { @@ -121,6 +139,54 @@ useEffect(() => { getInquiryData(); }, [currentPage, inquiryType, inquiryStatus]); +const handleRowClick = (inquiry, originalData) => { + const inquiryData = originalData || inquiry; + setSelectedInquiry(inquiry); + setShowModal(true); + setSelectedStatus(null); + setAnswer(""); +}; + + +const handleProcessingChange = (value) => { + setSelectedStatus(value); +}; + +const handleProcessComplete = async () => { + if (!selectedInquiry || !selectedStatus) { + alert('상태를 선택해주세요.'); + return; + } + + try { + const inquiryId = selectedInquiry.inquiryId || (selectedInquiry.originalData && selectedInquiry.originalData.inquiryId); + if (!inquiryId) { + alert('문의 ID를 찾을 수 없습니다.'); + return; + } + + await patchInquiryStatus({ + inquiryId: inquiryId, + answer: answer, + status: selectedStatus, + }); + + alert('문의 답변이 작성되었습니다.'); + handleCloseModal(); + getInquiryData(); + } catch (error) { + console.error('문의 답변 실패:', error); + alert('문의 답변에 실패했습니다.'); + } +}; + +const handleCloseModal = () => { + setShowModal(false); + setSelectedInquiry(null); + setSelectedStatus(null); + setAnswer(""); +}; + return ( { ]} >
- +
item.originalData)} + /> + + {/* 문의 상세 모달 */} + {showModal && selectedInquiry && ( +
+
e.stopPropagation()} + > +
+

문의 상세

+ +
+ +
+ {/* 왼쪽: 문의 정보 */} +
+
+ +
{selectedInquiry["문의 유형"]}
+
+ +
+ +
{selectedInquiry["문의 제목"]}
+
+ +
+ +
+ {selectedInquiry["문의 내용"]} +
+
+ +
+ +
{selectedInquiry["작성자"]}
+
+ +
+ +
{selectedInquiry["문의 작성일"]}
+
+ +
+ +
{selectedInquiry["문의 상태"]}
+
+ +

이미지

+
+ 이미지가 없습니다. +
+ + +
+ + {/* 오른쪽: 답변 처리 (답변 대기 상태일 때만 표시) */} +
+ {selectedInquiry["문의 상태"] === "답변 대기" ? ( + <> +

문의 상태 처리

+
+ + + +
+ +

답변 작성

+