EctorKim 2023-03-02
230302 김동준 qna 조회 일부 수정
@991021546b1e82c411bc98eaca64eaecc60cad32
client/views/pages/callcenter/QuestionSelect.jsx
--- client/views/pages/callcenter/QuestionSelect.jsx
+++ client/views/pages/callcenter/QuestionSelect.jsx
@@ -1,11 +1,11 @@
-import React, {useState } from "react";
+import React from "react";
 import Button from "../../component/Button.jsx";
 import Table from "../../component/Table.jsx";
 import QnAModal from "../../component/QnAModal.jsx";
 import { useNavigate } from "react-router";
 import ContentTitle from "../../component/ContentTitle.jsx";
-import RestoreFromTrashIcon from '@mui/icons-material/RestoreFromTrash';
-
+import RestoreFromTrashIcon from "@mui/icons-material/RestoreFromTrash";
+import Pagination from "../../component/Pagination.jsx";
 
 export default function QuestionSelect() {
   const navigate = useNavigate();
@@ -16,95 +16,100 @@
   const closeModal = () => {
     setModalOpen(false);
   };
-  
-  const [qnalist, setQnaList] = useState();
 
-  const [state, setState] = useState();
-  const [title, setTitle] = useState();
-  const [username, setUsername] = useState();
-  const [datetime, setDatetime] = useState();
+  const [qnaList, setQnaList] = React.useState();
 
-    //-------- 페이징 작업 설정 시작 --------//
-    const limit = 15; // 페이지당 보여줄 공지 개수
-    const [page, setPage] = React.useState(1); //page index
-    const offset = (page - 1) * limit; //게시물 위치 계산
-    const [myQnaTotal, setMyQnaTotal] = React.useState(0); //최대길이 넣을 변수
-  
+  const [state, setState] = React.useState();
+  const [title, setTitle] = React.useState();
+  const [username, setUsername] = React.useState();
+  const [datetime, setDatetime] = React.useState();
+
+  //-------- 페이징 작업 설정 시작 --------//
+  const limit = 15; // 페이지당 보여줄 공지 개수
+  const [page, setPage] = React.useState(1); //page index
+  const offset = (page - 1) * limit; //게시물 위치 계산
+  const [myQnaTotal, setMyQnaTotal] = React.useState(0); //최대길이 넣을 변수
+
   //qna 조회
-    const getQnaList = () => {
-      fetch("/qna/qnaSelectList.json", {
-        method: "POST",
-        headers: {
-          'Content-Type': 'application/json; charset=UTF-8'
-        },
-        body: JSON.stringify({
-          
-          qna_state : state,
-          qna_title : title,
-          qna_insert_user_id : username,
-          qna_insert_datetime : datetime
+  const getQnaList = () => {
+    fetch("/qna/qnaSelectList.json", {
+      method: "POST",
+      headers: {
+        "Content-Type": "application/json; charset=UTF-8;"
+      },
+      body: JSON.stringify({
 
-        }),
-      }).then((response) => response.json()).then((data) => {
-       
-          console.log(data);
-          setQnaList(data);
-          setMyQnaTotal(data.length);
-  
-  
-      }).catch((error) => {
-        console.log('getSelectSeniorList() /user/selectUserList.json error : ', error);
+        qna_state: state,
+        qna_title: title,
+        qna_insert_user_id: username,
+        qna_insert_datetime: datetime,
+      }),
+    })
+      .then((response) => response.json())
+      .then((data) => {
+        console.log(data);
+        setQnaList(data);
+        // setMyQnaTotal(data.length);
+      })
+      .catch((error) => {
+        console.log(
+          "qna error : ",
+          error
+        );
       });
-    };
-  
+  };
+
   //게시판
-  const thead = [
-    "No",
-    "답변상태",
-    "제목",
-    "작성자",
-    "작성일자",
-  ];
-  const key = [
-    "No",
-    "answer",
-    "title",
-    "writer",
-    "date",
-  ];
+  const thead = ["No", "답변상태", "제목", "작성자", "작성일자"];
+  const key = ["idx", "state", "title", "username", "datetime"];
   const content = [
     {
       No: 1,
       answer: "답변완료",
       title: (
-        <div className="title" onClick={() => {
-          navigate("/QuestionConfirm");
-        }}>담당자 바꿔주세요</div>
+        <div
+          className="title"
+          onClick={() => {
+            navigate("/QuestionConfirm");
+          }}
+        >
+          담당자 바꿔주세요
+        </div>
       ),
       writer: "홍길동",
       date: "2023-01-27",
     },
-
   ];
+
+  React.useEffect(() => {
+
+    getQnaList();
+
+  }, [])
+
   return (
     <main>
-      <QnAModal open={modalOpen} close={closeModal} header="기관 등록">      
-      </QnAModal>
+      <QnAModal
+        open={modalOpen}
+        close={closeModal}
+        header="기관 등록"
+      ></QnAModal>
       <div className="content-wrap">
         <ContentTitle contentTitle={"Q&A"} />
         <div className="board-wrap">
           <div className="btn-wrap flex-end margin-bottom question-select">
-            <input type="checkbox" /><label htmlFor="">내 Q&A 보기</label>
-          <select name="" id="">
-            <option value="답변상태">답변상태</option>
-            <option value="미답변">미답변</option>
-            <option value="답변완료">답변완료</option>
-          </select>
-          <Button
-            className={"btn-small gray-btn"}
-            btnName={"작성하기"}
-            onClick={openModal}
-          />
+            <input type="checkbox" />
+            <label htmlFor="">내 Q&A 보기</label>
+            <select name="" id="">
+              <option value="답변상태">답변상태</option>
+              <option value="미답변">미답변</option>
+              <option value="답변완료">답변완료</option>
+            </select>
+            <Button
+              className={"btn-small gray-btn"}
+              btnName={"작성하기"}
+              onClick={openModal}
+            />
           </div>
         </div>
         <Table
@@ -114,7 +119,16 @@
           contentKey={key}
           view={"qna"}
           offset={offset}
-          limit={limit}/>
+          limit={limit}
+        />
+      </div>
+      <div>
+        <Pagination
+          total={myQnaTotal}
+          limit={limit}
+          page={page}
+          setPage={setPage}
+        />
       </div>
     </main>
   );
Add a comment
List