방선주 방선주 2023-02-28
230228 방선주 보호자 등록 및 매칭 진행 중
@cd6e5cd5781907ef9e18efe737fc3f9e04d65ae9
 
.vscode/launch.json (deleted)
--- .vscode/launch.json
@@ -1,16 +0,0 @@
-{
-    // Use IntelliSense to learn about possible attributes.
-    // Hover to view descriptions of existing attributes.
-    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
-    "version": "0.2.0",
-    "configurations": [
-        
-        {
-            "type": "chrome",
-            "request": "launch",
-            "name": "Launch Chrome against localhost",
-            "url": "http://localhost:8080",
-            "webRoot": "${workspaceFolder}"
-        }
-    ]
-}(No newline at end of file)
client/views/component/Table.jsx
--- client/views/component/Table.jsx
+++ client/views/component/Table.jsx
@@ -3,11 +3,52 @@
 import Modal from "./MatchingModal.jsx";
 import Modal2 from "./Modal.jsx";
 import SubTitle from "./SubTitle.jsx";
-
+import { useNavigate } from "react-router";
+import TableTest from "./TableTest.jsx"
 // import styled from "styled-components";
 
 export default function Table({ head, contents, contentKey, onClick, className, view, offset, limit }) {
+  const navigate = useNavigate();
+  // 모달 title에 대상자 명 출력을 위함
+  const [useName, setUseUserName] = React.useState("");
+  // 매칭을 위해 대상자 ID 값 전달을 위함
+  const [useseniorId, setUseSeniorId] = React.useState("");
+
+  //대상자 - 보호자 매칭 리스트 
+  const [sgMatchList, setSgMatchList] = React.useState([]);
+  
+  //사용자 등록 초기값 설정
   const [userName, setUserName] = React.useState("");
+  const [gender, setGender] = React.useState("");
+  const [brith, setBrith] = React.useState("");
+  const [telNum, setTelNum] = React.useState("");
+  const [homeAddress, setHomeAddress] = React.useState("");
+  const [relationship, setRelationship] = React.useState("");
+  const [matchState, setMatchState] = React.useState(true);
+
+  //-------- 변경되는 데이터 Handler 설정 --------//
+  const handleUserName = (e) => {
+    setUserName(e.target.value);
+  };
+  const handleBrithday = (e) => {
+    setBrith(e.target.value);
+  };
+  const handleTelNum = (e) => {
+    e.target.value = e.target.value.replace(/[^0-9]/g, '').replace(/^(\d{2,3})(\d{3,4})(\d{4})$/, `$1-$2-$3`);
+    setTelNum(e.target.value);
+  };
+  const handelRelationship = (e) => {
+    setRelationship(e.target.value);
+  };
+  
+
+  const dataReset = () => {
+    setUserName("");
+    setBrith("");
+    setTelNum("");
+    relationship("")
+  }
+
   const [modalOpen, setModalOpen] = React.useState(false);
   const openModal = () => {
     setModalOpen(true);
@@ -16,6 +57,7 @@
   const [modalOpen2, setModalOpen2] = React.useState(false);
   const openModal2 = () => {
     setModalOpen2(true);
+    dataReset();
   };
 
   const closeModal = () => {
@@ -24,6 +66,95 @@
 
   const closeModal2 = () => {
     setModalOpen2(false);
+  };
+  // 매칭 리스트 출력 영역
+  const getselectMatchList = () => {
+    fetch("/user/selectSeniorGuardianMatch.json", {
+      method: "POST",
+      headers: {
+        'Content-Type': 'application/json; charset=UTF-8'
+      },
+      body: JSON.stringify({
+        senior_id: useseniorId,
+      }),
+    }).then((response) => response.json()).then((data) => {
+      console.log("getselectMatchList : ", data);
+      setSgMatchList(data);
+      openModal();
+    }).catch((error) => {
+      console.log('getselectMatchList() /user/selectSeniorGuardianMatch.json error : ', error);
+    });
+  };
+ // 보호자 등록 영역
+ const test = () => {
+  console.log("userName : ", userName);
+  console.log("gender : ", gender);
+  console.log("brith : ", brith);
+  console.log("telNum : ", telNum);
+  console.log("homeAddress : ", homeAddress);
+  console.log("relationship : ", relationship);
+  console.log("matchState : ", matchState);
+ }
+  const insertUser = () => {
+    fetch("/user/insertSeniorData.json", {
+      method: "POST",
+      headers: {
+        'Content-Type': 'application/json; charset=UTF-8'
+      },
+      body: JSON.stringify({
+        user_name: userName,
+        user_gender: gender != "" ? gender:null,
+        user_birth: brith,
+        user_phonenumber: telNum,
+        user_address: homeAddress != "" ? homeAddress:null,
+        agency_id: 'agency01',
+        government_id: 'government01',
+        user_code: '3',
+        
+      }),
+    }).then((response) => response.json()).then((data) => {
+      console.log("보호자 등록");
+      insertGuadian();
+    }).catch((error) => {
+      console.log('insertUser() /user/insertSeniorData.json error : ', error);
+    });
+  };
+
+  const insertGuadian = () => {
+    fetch("/user/insertGuardian.json", {
+      method: "POST",
+      headers: {
+        'Content-Type': 'application/json; charset=UTF-8'
+      },
+      body: JSON.stringify({
+        user_phonenumber: telNum,
+      }),
+    }).then((response) => response.json()).then((data) => {
+      console.log("보호자 테이블 데이터 등록");
+      matchSeniorGuadian();
+    }).catch((error) => {
+      console.log('insertGuadian() /user/insertGuardian.json error : ', error);
+    });
+  };
+
+  const matchSeniorGuadian = () => {
+    fetch("/user/insertSeniorGuardianMatch.json", {
+      method: "POST",
+      headers: {
+        'Content-Type': 'application/json; charset=UTF-8'
+      },
+      body: JSON.stringify({
+        senior_id:useseniorId,
+        user_phonenumber: telNum,
+        senior_relationship:relationship,
+        guardian_match_state:matchState,
+      }),
+    }).then((response) => response.json()).then((data) => {
+      console.log("매칭 등록");
+      dataReset();
+    }).catch((error) => {
+      console.log('matchSeniorGuadian() /user/insertSeniorGuardianMatch.json error : ', error);
+    });
   };
 
   // 보호자 등록페이지 데이터
@@ -35,31 +166,25 @@
     "대상자와의 관계",
   ];
   const key3 = [
-    "No",
-    "name",
-    "birth",
-    "phone",
-    "relationship",
+    "rn",
+    "guardian_name",
+    "user_birth",
+    "user_phonenumber",
+    "senior_relationship",
   ];
-  const content3 = [
-    {
-      No: 1,
-      name: "김훈",
-      birth: "1965.01.01",
-      relationship: "아들",
-      phone: "010-1234-1234",
-    },
-  ];
-
   
-  const buttonPrint = () => {
+  const buttonPrint = (name, id) => {
     if (view == 'mySenior') {
       return (
         <td>
           <Button
             className={"btn-small gray-btn"}
             btnName={"보기"}
-            onClick={openModal}
+            onClick={() =>{
+              setUseUserName(name);
+              setUseSeniorId(id);
+              getselectMatchList();
+              }}
           />
         </td>)
     }
@@ -70,58 +195,56 @@
             <Button
               className={"btn-small gray-btn"}
               btnName={"선택"}
-              onClick={openModal2}
+              onClick={()=>{setUseSeniorId(id); openModal2}}
             />
           </td>
           <td>
             <Button
               className={"btn-small gray-btn"}
               btnName={"보기"}
-              onClick={openModal}
-            />
+              onClick={(e) =>{
+              setUseUserName(name);
+              setUseSeniorId(id);
+              getselectMatchList();
+              }}
+          />
           </td>
         </>
       )
     }
   }
-
+  React.useEffect(() => {
+  }, [])
   return (
     <>
       <Modal open={modalOpen2} close={closeModal2} header="담당자 배정" />
-      <Modal2 open={modalOpen} close={closeModal} header={userName+"님의 가족"}>
+      {/* 보호자 보기 모달창  */}
+      <Modal2 open={modalOpen} close={closeModal} header={useName+"님의 가족"} >
         <div className="board-wrap">
           <SubTitle explanation={"최초 ID는 연락처, PW는 생년월일 8자리입니다."} className="margin-bottom" />
           <table className="margin-bottom2 senior-insert">
             <tr>
               <th>이름</th>
               <td>
-                <input type="text" />
+                <input type="text" value={userName} onChange={handleUserName} />
               </td>
               <th>생년월일</th>
               <td>
                 <div className="flex">
-                  <select name="year" id="year">
-                    <option value="">년</option>
-                  </select>
-                  <select name="month" id="month">
-                    <option value="">월</option>
-                  </select>
-                  <select name="days" id="days">
-                    <option value="">일</option>
-                  </select>
+                    <input type='date' value={brith} onChange={handleBrithday} />
                 </div>
               </td>
             </tr>
             <tr>
               <th>연락처</th>
               <td colSpan={3}>
-                <input type="input" maxLength="11" />
+                <input type="input" maxLength="13"  value={telNum} onChange={handleTelNum} />
               </td>
             </tr>
             <tr>
               <th>대상자와의 관계</th>
               <td colSpan={3}>
-                <input type="text" />
+                <input type="text" value={relationship} onChange={handelRelationship}/>
               </td>
             </tr>
           </table>
@@ -130,15 +253,17 @@
               className={"btn-small green-btn"}
               btnName={"추가"}
               onClick={() => {
-                navigate("/SeniorInsert");
+                test();
+                insertUser()
+                getselectMatchList();
               }}
             />
           </div>
           <div>
-            <Table
+            <TableTest
               className={"caregiver-user"}
               head={thead3}
-              contents={content3}
+              contents={sgMatchList}
               contentKey={key3}
             />
           </div>
@@ -154,18 +279,20 @@
         </thead>
         <tbody>
           {contents.slice(offset, offset + limit).map((i, index) => {
-            const name = i.user_name;
+            const userName = i.user_name;
+            const userId = i.user_id
             return (
               <tr key={index}>
                 {contentKey.map((kes) => {
                   return (
                     <>
-                      <td onClick={onClick}>{i[kes]}</td>
-                      {console.log("userName : ", userName)}
+                      <td onClick={() => {
+                        navigate("/SeniorSelectOne")}}>{i[kes]}
+                      </td>
                     </>
                   )
                 })}
-                {buttonPrint()}
+                {buttonPrint(userName, userId)}
               </tr>
             );
           })}
 
client/views/component/TableTest.jsx (added)
+++ client/views/component/TableTest.jsx
@@ -0,0 +1,72 @@
+import React from "react";
+import Button from "./Button.jsx";
+import Modal from "./MatchingModal.jsx";
+import Modal2 from "./Modal.jsx";
+import SubTitle from "./SubTitle.jsx";
+import { useNavigate } from "react-router";
+// import styled from "styled-components";
+
+export default function TableTest({ head, contents, contentKey, onClick, className }) {
+  
+  return (
+    <>
+      <table className={className}>
+        <thead>
+          <tr>
+            {head.map((i) => {
+              return <th>{i}</th>;
+            })}
+          </tr>
+        </thead>
+        <tbody>
+          {contents.map((i, index) => {
+            const userName = i.user_name;
+            const userId = i.user_id
+            return (
+              <tr key={index}>
+                {contentKey.map((kes) => {
+                  return (
+                    <>
+                      <td >
+                        {i[kes]}
+                      </td>
+                    </>
+                  )
+                })}
+              </tr>
+            );
+          })}
+        </tbody>
+      </table>
+    </>
+  );
+}
+
+
+// const TableStyled = styled.table`
+//   border-top: 2px solid #2d303f;
+//   border-bottom: 1px solid #e4dccf;
+//   /* &:hover {
+//     background-color: #e4dccf;
+//   } */
+// `;
+
+// const TrStyled = styled.tr`
+//   cursor: pointer;
+// `;
+
+// const ThStyled = styled.th`
+//   padding: 1rem 0;
+//   font-weight: bold;
+//   background-color: #f0ebe3;
+//   font-size: 1.4rem;
+//   text-align: center;
+// `;
+
+// const TdStyled = styled.td`
+//   padding: 1rem 0;
+//   border-top: 1px solid #ececec;
+//   text-align: center;
+//   font-size: 1.3rem;
+//   background-color: #ffffff;
+// `;
client/views/pages/user_management/UserAuthoriySelect_agency.jsx
--- client/views/pages/user_management/UserAuthoriySelect_agency.jsx
+++ client/views/pages/user_management/UserAuthoriySelect_agency.jsx
@@ -483,7 +483,7 @@
             <tr>
               <th>연락처</th>
               <td colSpan={3}>
-                <input type="text" value={telNum} onChange={handleTelNum} />
+                <input type="text" maxLength="13" value={telNum} onChange={handleTelNum} />
               </td>
             </tr>
             <tr>
@@ -557,7 +557,6 @@
             <select onChange={handleSelectUserData} value={selectUserData}>
               <option value="이름">이름</option>
               <option value="아이디">아이디</option>
-              <option value="등록번호">등록번호</option>
             </select>
             <input type="text" />
             <Button
Add a comment
List