EctorKim 2023-03-06
230306 김동준 QnA 등록 수정
@1c2ea7a21dae8384a123724bd7a759716cf316fc
client/views/component/QnAModal.jsx
--- client/views/component/QnAModal.jsx
+++ client/views/component/QnAModal.jsx
@@ -4,45 +4,106 @@
 import SubTitle from "./SubTitle.jsx";
 import { useNavigate } from "react-router";
 
-export default function QaAModal({ open, close, }) {
+export default function QnAModal({ open, close }) {
+  const [qnaRegisteringList, setQnaRegisteringList] = React.useState([]);
+
+  const [idx, setIdx] = React.useState();
+  const [title, setTitle] = React.useState("");
+  const [datetime, setDatetime] = React.useState("");
+  const [contents, setContents] = React.useState("");
+
+  //qna등록
+  const getQnaRegisteringList = () => {
+    fetch("/qna/qnaInsert.json", {
+      method: "POST",
+      headers: {
+        "Content-Type": "application/json; charset=UTF-8;",
+      },
+      body: JSON.stringify({
+        qna_idx: idx,
+        qna_title: title,
+        qna_insert_user_id: "gym1004",
+        qna_insert_datetime: datetime,
+      }),
+    })
+      .then((response) => response.json())
+      .then((data) => {
+        if (data > 0) {
+          console.log(data);
+          alert("등록완료");
+          close(true);
+        } else {
+          alert("등록실패, 관리자에게 문의해주세요.");
+        }
+      })
+      .catch((error) => {
+        console.log("qna error : ", error);
+      });
+  };
+
+  //게시판
+  const thead = ["제목", "작성자", "작성일자"];
+  const key = ["qna_title", "qna_insert_user_name", "qna_insert_datetime"];
+
   return (
     <div class={open ? "openModal modal" : "modal"}>
-    {open ? (
-      <div className="modal-inner">
-        <div className="modal-header flex">
-          Q&A등록
-          <Button className={"close"} onClick={close} btnName={"X"} />
-        </div>
-        <div className="modal-main"><div className="board-wrap">        
-        <div>
-        <SubTitle explanation={"작성자 정보"} />
-        <table className="margin-bottom2 qna-insert">
-          <tr>
-            <th>작성자</th>
-            <td>
-              <input type="text" placeholder="자동입력부분" />
-            </td>
-          </tr>
+      {open ? (
+        <div className="modal-inner">
+          <div className="modal-header flex">
+            Q&A등록
+            <Button className={"close"} onClick={close} btnName={"X"} />
+          </div>
+          <div className="modal-main">
+            <div className="board-wrap">
+              <div>
+                <SubTitle explanation={"작성자 정보"} />
+                <table className="margin-bottom2 qna-insert">
+                  <tr>
+                    <th>작성자</th>
+                    <td>
+                      <input type="text" placeholder="자동입력부분" />
+                    </td>
+                  </tr>
 
-          <tr>
-            <th>제목</th>
-            <td colSpan={3}>
-              <input type="text" />
-            </td>
-          </tr>
-          <tr>
-              <th>내용</th>
-              <td colSpan={3}>
-                <textarea className="medicine" cols="30" rows="2"></textarea>
-              </td>
-            </tr>
-        </table>
+                  <tr>
+                    <th>제목</th>
+                    <td colSpan={3}>
+                      <input
+                        type="text"
+                        value={title}
+                        onInput={(e) => {
+                          setTitle(e.target.value);
+                        }}
+                      />
+                    </td>
+                  </tr>
+                  <tr>
+                    <th>내용</th>
+                    <td colSpan={3}>
+                      <textarea
+                        className="medicine"
+                        cols="30"
+                        rows="2"
+                        value={contents}
+                        onInput={(e) => {
+                          setContents(e.target.value);
+                        }}
+                      ></textarea>
+                    </td>
+                  </tr>
+                </table>
+              </div>
+              <div className="flex-center">
+                <Button
+                  className={"btn-small red-btn"}
+                  btnName={"저장"}
+                  onClick={() => getQnaRegisteringList()}
+                />
+              </div>
+            </div>
+          </div>
         </div>
-        <div className="flex-center"><Button className={"btn-small red-btn"} btnName={"저장"} /></div >
-      </div></div>
-      </div>
-    ) : null}
-  </div>
-    
+      ) : null}
+    </div>
   );
 }
client/views/pages/App.jsx
--- client/views/pages/App.jsx
+++ client/views/pages/App.jsx
@@ -26,8 +26,8 @@
   };
 
 
-  const menuItems = GuardianApp.menuItems;  //AdminApp, GovernmentApp, AllApp, AgencyApp, GuardianApp 
-  const AppRoute = GuardianApp.AppRoute;
+  const menuItems = AllApp.menuItems;  //AdminApp, GovernmentApp, AllApp, AgencyApp, GuardianApp 
+  const AppRoute = AllApp.AppRoute;
 
 
   const { title } = menuItems.find(
client/views/pages/callcenter/QuestionConfirm.jsx
--- client/views/pages/callcenter/QuestionConfirm.jsx
+++ client/views/pages/callcenter/QuestionConfirm.jsx
@@ -5,7 +5,10 @@
 import { useNavigate } from "react-router";
 
 export default function QuestionConfirm() {
+
   const navigate = useNavigate();
+
+
   return (
     <main>
       <div className="content-wrap row">
@@ -44,14 +47,14 @@
             className={"btn-large gray-btn"}
             btnName={"이전"}
             onClick={() => {
-              navigate("/QandASelect");
+              navigate("/QuestionSelect");
             }}
           />
           <Button
             className={"btn-large green-btn"}
             btnName={"등록"}
             onClick={() => {
-              navigate("/QandASelect");
+              navigate("/QuestionSelect");
             }}
           />
         </div>
client/views/pages/callcenter/QuestionSelect.jsx
--- client/views/pages/callcenter/QuestionSelect.jsx
+++ client/views/pages/callcenter/QuestionSelect.jsx
@@ -13,16 +13,16 @@
   const openModal = () => {
     setModalOpen(true);
   };
-  const closeModal = () => {
+  const closeModal = (isInsertComplete) => {
     setModalOpen(false);
+    if (isInsertComplete == true) {
+      getQnaList();
+    }
   };
 
-  const [qnaList, setQnaList] = React.useState();
+  const [qnaList, setQnaList] = React.useState([]);
 
-  const [state, setState] = React.useState();
-  const [title, setTitle] = React.useState();
-  const [username, setUsername] = React.useState();
-  const [datetime, setDatetime] = React.useState();
+  const [idx, setIdx] = React.useState();
 
   //-------- 페이징 작업 설정 시작 --------//
   const limit = 15; // 페이지당 보여줄 공지 개수
@@ -39,17 +39,15 @@
       },
       body: JSON.stringify({
 
-        qna_state: state,
-        qna_title: title,
-        qna_insert_user_id: username,
-        qna_insert_datetime: datetime,
+        qna_idx: idx,
+
       }),
     })
       .then((response) => response.json())
       .then((data) => {
         console.log(data);
         setQnaList(data);
-        // setMyQnaTotal(data.length);
+        setMyQnaTotal(data.length);
       })
       .catch((error) => {
         console.log(
@@ -61,25 +59,8 @@
 
   //게시판
   const thead = ["No", "답변상태", "제목", "작성자", "작성일자"];
-  const key = ["idx", "state", "title", "username", "datetime"];
-  const content = [
-    {
-      No: 1,
-      answer: "답변완료",
-      title: (
-        <div
-          className="title"
-          onClick={() => {
-            navigate("/QuestionConfirm");
-          }}
-        >
-          담당자 바꿔주세요
-        </div>
-      ),
-      writer: "홍길동",
-      date: "2023-01-27",
-    },
-  ];
+  const key = ["qna_idx", "qna_state", "qna_title", "qna_insert_user_name", "qna_insert_datetime"];
+  
 
   React.useEffect(() => {
 
@@ -115,7 +96,7 @@
         <Table
           className="equipment-detail"
           head={thead}
-          contents={content}
+          contents={qnaList}
           contentKey={key}
           view={"qna"}
           offset={offset}
server/modules/web/Server.js
--- server/modules/web/Server.js
+++ server/modules/web/Server.js
@@ -96,17 +96,19 @@
 webServer.get('*', function (request, response, next) {
     response.sendFile(`${BASE_DIR}/client/views/index.html`);
 })
+
 /**
 + * @author : 방선주
 + * @since : 2023.02.14
 + * @dscription : REST API 서버에 데이터 요청 보내기(Proxy)
 + */
-+webServer.use('*.json', expressProxy(API_SERVER_HOST, {
-        proxyReqPathResolver: function (request) {
-            //console.log('request : ', request.url, request.params[0]);
-            return `${request.params['0']}.json`;
-        }
-    }));
+webServer.use('*.json', expressProxy(API_SERVER_HOST, {
+    proxyReqPathResolver: function (request) {
+        //console.log('request : ', request.url, request.params[0]);
+        return `${request.params['0']}.json`;
+    }
+}));
+    
 /**
  * @author : 최정우
  * @since : 2022.09.21
Add a comment
List