방선주 방선주 2023-02-24
230224 방선주 user 및 Table.jsx 수정
@4745d685ae73595cd6bb65a61cac38b55a1de2f7
client/views/component/Table.jsx
--- client/views/component/Table.jsx
+++ client/views/component/Table.jsx
@@ -1,7 +1,52 @@
 import React from "react";
+import Button from "./Button.jsx";
 // import styled from "styled-components";
 
-export default function Table({ head, contents, contentKey, onClick, className}) {
+export default function Table({ head, contents, contentKey, onClick, className, page}) {
+  const [modalOpen, setModalOpen] = React.useState(false);
+  const openModal = () => {
+    setModalOpen(true);
+  };
+
+  const [modalOpen2, setModalOpen2] = React.useState(false);
+  const openModal2 = () => {
+    setModalOpen2(true);
+  };
+  
+
+  const buttonPrint = () => {
+    if(page == 'mySenior'){
+      return(
+      <td>
+        <Button
+          className={"btn-small gray-btn"}
+          btnName={"보기"}
+          onClick={openModal}
+        />
+      </td>)
+    }
+    else if(page == 'allSenior'){
+      return(
+        <>
+          <td>
+          <Button
+              className={"btn-small gray-btn"}
+              btnName={"선택"}
+              onClick={openModal2}
+            />
+          </td>
+          <td>
+            <Button
+              className={"btn-small gray-btn"}
+              btnName={"보기"}
+              onClick={openModal}
+            />
+            </td>
+          </>
+      )
+    }
+  }
+  
   return (
     <table className={className}>
       <thead>
@@ -15,14 +60,27 @@
         {contents.map((i, index) => {
           return (
             <tr key={index}>
-              {contentKey.map((kes) => {
-                return <td onClick={onClick}>{i[kes]}</td>;
-              })}
+            {/* //   <td>{i.rn}</td>
+            //   <td>{i.user_name}</td>
+            //   <td>{i.user_phonenumber}</td>
+            //   <td>{i.user_gender}</td>
+            //   <td>{i.user_birth}</td>
+            //   <td>{i.user_address}</td>
+            //   {buttonPrint()} */}
+            {contentKey.map((kes) => {
+                return (
+                  <>
+                  <td onClick={onClick}>{i[kes]}</td>
+                  </>
+                )
+            })}
+            {buttonPrint()}
             </tr>
           );
         })}
       </tbody>
     </table>
+    
   );
 }
 
client/views/pages/user_management/UserAuthoriySelect_agency.jsx
--- client/views/pages/user_management/UserAuthoriySelect_agency.jsx
+++ client/views/pages/user_management/UserAuthoriySelect_agency.jsx
@@ -9,9 +9,10 @@
   // 화면 진입 시 탭 별 노출될ㄹ 리스트 초기화 
   const [subjectList, setSubjectList] = React.useState([]);
   const [subjectMyList, setSubjectMyList] = React.useState([]);
-  
+
   // ------ 등록 버튼 클릭 시 노출되는 모달 데이터 ------//
   // 사용자 등록 시 초기값 세팅
+  
   const [userName, setUserName] = React.useState("");
   const [gender, setGender] = React.useState("");
   const [brith, setBrith] = React.useState("");
@@ -22,10 +23,25 @@
   const [medicineD, setMedicineD] = React.useState(false);
   const [medication, setMedication] = React.useState("");
   const [note, setNote] = React.useState("");
-
+  
+  // 등록 후 초기화 진행
+  const dataReset = () => {
+    setUserName("");
+    setGender("");
+    setBrith("");
+    setTelNum("");
+    setHomeAddress("");
+    setMedicineM("");
+    setMedicineL("");
+    setMedicineD("");
+    setMedication("");
+    setNote("");
+  }
   // 변경되는 데이터 Handler
   const handleUserName = (e) => {
+
     setUserName(e.target.value);
+
   };
   const handleGender = (e) => {
     setGender(e.target.value);
@@ -34,7 +50,7 @@
     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`);
+    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 handleHomeAddress = (e) => {
@@ -57,82 +73,100 @@
   };
 
   // 대상자 등록 함수 
-  const seniorInsert = () => {
-    // userName,gender,brith, telNum, homeAddress, note, medicineM, medicineL, medicineD
-    // console.log("userName : ",userName);
-    // console.log("gender : ",gender);
-    // console.log("brith : ",brith);
-    // console.log("telNum : ",telNum);
-    // console.log("homeAddress : ",homeAddress);
-    // console.log("note : ",note);
-    // console.log("medicineM : ",medicineM);
-    // console.log("medicineL : ",medicineL);
-    // console.log("medicineD : ",medicineD);
+  const InsertSenior = () => {
     var insertBtn = confirm("등록하시겠습니까?");
-    if(insertBtn){
-      fetch("/user/userInsert_userMadicationInsert.json", {
-        method: "POST",
-        headers: {
-          'Content-Type': 'application/json; charset=UTF-8'
-        },
-        body: JSON.stringify({
-          userName:userName,
-          gender:gender,
-          brith :brith,
-          userTel :telNum,
-          homeAddress:homeAddress,
-          medicineM:medicineM,
-          medicineL:medicineL,
-          medicineD:medicineD,
-          medication:medication,
-          note:note,
-          agancyId:'agency1',
-          govId:'government1',
-          userCode : '4'
-        }),
-      }).then((response) => response.json()).then((data) => {
-        alert("등록 되었습니다.");
-      }).catch((error) => {
-        console.log('selectNotice() /Notice/selectNotice.json error : ', error);
-      });
-    }else{
-        return;
+    if (insertBtn) {
+      InsertUserData();
+      alert("등록 되었습니다.");
+      dataReset();
+      closeModal3();
+    } else {
+      return;
     }
-    
+
+  };
+  // 대상자 정보 등록을 위한 함수 
+  const InsertUserData = () => {
+    fetch("/user/insertSeniorData.json", {
+      method: "POST",
+      headers: {
+        'Content-Type': 'application/json; charset=UTF-8'
+      },
+      body: JSON.stringify({
+        userName: userName,
+        gender: gender,
+        brith: brith,
+        userTel: telNum,
+        homeAddress: homeAddress,
+        agancyId: 'agency1',
+        govId: 'government1',
+        userCode: '4'
+      }),
+    }).then((response) => response.json()).then((data) => {
+      console.log("대상자 정보 등록");
+      InsertUserPillData();
+    }).catch((error) => {
+      console.log('insertSeniorData() /Notice/insertSeniorData.json error : ', error);
+    });
+  };
+  // 대상자 약 복용 정보 등록을 위한 함수 
+  const InsertUserPillData = () => {
+    fetch("/user/insertSeniorMadication.json", {
+      method: "POST",
+      headers: {
+        'Content-Type': 'application/json; charset=UTF-8'
+      },
+      body: JSON.stringify({
+        userTel: telNum,
+        medicineM: medicineM,
+        medicineL: medicineL,
+        medicineD: medicineD,
+        medication: medication,
+        note: note,
+      }),
+    }).then((response) => response.json()).then((data) => {
+      console.log("약 정보 등록");
+    }).catch((error) => {
+      console.log('InsertUserPillData() /user/insertSeniorMadication.json error : ', error);
+    });
   };
 
   const getSelectSubjectList = () => {
-    fetch("/user/selectSubjectList.json", {
-          method: "POST",
-          headers: {
-            'Content-Type': 'application/json; charset=UTF-8'
-          },
-        }).then((response) => response.json()).then((data) => {
-          const rowData = data;
-          console.log(data);
-          setSubjectList(rowData)
+    fetch("/user/selectUserList.json", {
+      method: "POST",
+      headers: {
+        'Content-Type': 'application/json; charset=UTF-8'
+      },
+      body: JSON.stringify({
+        userCode: '4',
+      }),
+    }).then((response) => response.json()).then((data) => {
+      const rowData = data;
+      console.log(data);
+      setSubjectList(rowData)
 
-        }).catch((error) => {
-          console.log('getSelectSubjectList() /user/selectSubjectList.json error : ', error);
-        });
+    }).catch((error) => {
+      console.log('getSelectSubjectList() /user/selectUserList.json error : ', error);
+    });
   };
 
   const getSelectMySubjectList = () => {
-    fetch("/user/selectMySubjectList.json", {
-          method: "POST",
-          headers: {
-            'Content-Type': 'application/json; charset=UTF-8'
-          },
-          body: JSON.stringify({
-            agancyId: 'agency1',
-          }),
-        }).then((response) => response.json()).then((data) => {
-          const rowData = data;
-          console.log(data);
-          setSubjectMyList(rowData)
-        }).catch((error) => {
-          console.log('getSubjectMySelect() /user/selectMySubjectList.json error : ', error);
-        });
+    fetch("/user/selectMyUserList.json", {
+      method: "POST",
+      headers: {
+        'Content-Type': 'application/json; charset=UTF-8'
+      },
+      body: JSON.stringify({
+        agancyId: 'agency1',
+        userCode: '4',
+      }),
+    }).then((response) => response.json()).then((data) => {
+      const rowData = data;
+      console.log(data);
+      setSubjectMyList(rowData)
+    }).catch((error) => {
+      console.log('getSubjectMySelect() /user/selectMyUserList.json error : ', error);
+    });
   };
 
   const navigate = useNavigate();
@@ -181,7 +215,7 @@
     "생년월일",
     "주소",
     "보호자",
-    
+
   ];
   const key1 = [
     // "No", "name", "Id", "call", "gender", "birth", "address", "management"
@@ -339,12 +373,13 @@
       id: 1,
       title: "내가 관리하는 대상자",
       description: (
-        
+
         <Table
           className={"protector-user"}
           head={thead1}
           contents={subjectMyList}
           contentKey={key1}
+          page={"mySenior"}
         />
       ),
     },
@@ -357,6 +392,7 @@
           head={thead2}
           contents={subjectList}
           contentKey={key2}
+          page={"allSenior"}
         />
       ),
     },
@@ -429,7 +465,7 @@
       </Modal>
       <Modal open={modalOpen2} close={closeModal2} header="담당자 배정">
         <div className="board-wrap">
-          <SubTitle explanation={"담당자 선택"} className="margin-bottom"/>
+          <SubTitle explanation={"담당자 선택"} className="margin-bottom" />
           <div className="flex-start protectorlist margin-bottom5">
             <input type="text" list="protectorlist" />
             <datalist id="protectorlist">
@@ -456,9 +492,9 @@
       </Modal>
       <Modal open={modalOpen3} close={closeModal3} header="대상자 등록">
         <div className="board-wrap">
-          <SubTitle explanation={"회원 등록 시 ID는 연락처, 패스워드는 생년월일 8자리입니다."} className="margin-bottom"/>
+          <SubTitle explanation={"회원 등록 시 ID는 연락처, 패스워드는 생년월일 8자리입니다."} className="margin-bottom" />
           <table className="margin-bottom2 senior-insert">
-          {/* <tr>
+            {/* <tr>
               <th>대상자등록번호</th>
               <td colSpan={3} className="flex">
                 <input type="text" placeholder="생성하기 버튼 클릭 시 자동으로 생성됩니다."/>
@@ -486,7 +522,7 @@
               </td>
             </tr>
             <tr>
-            <th>생년월일</th>
+              <th>생년월일</th>
               <td>
                 <div className="flex">
                   <input type='date' value={brith} onChange={handleBrithday} />
@@ -496,7 +532,7 @@
               <td>
               <input type="text" />
               </td> */}
-              
+
             </tr>
             <tr>
               <th>연락처</th>
@@ -513,10 +549,10 @@
             <tr>
               <th>필요 복약</th>
               <td>
-              <div className="flex">
-                  <input type="checkbox" name="medicationSelect" checked={medicineM} onClick={(e) => {handleMedicineM(e)}} /><label for="medicationTime">아침</label>
-                  <input type="checkbox" name="medicationSelect" checked={medicineL} onClick={(e) => {handleMedicineL(e)}}/><label for="medicationTime">점심</label>
-                  <input type="checkbox" name="medicationSelect" checked={medicineD} onClick={(e) => {handleMedicineD(e)}}/><label for="medicationTime">저녁</label>
+                <div className="flex">
+                  <input type="checkbox" name="medicationSelect" checked={medicineM} onClick={(e) => { handleMedicineM(e) }} /><label for="medicationTime">아침</label>
+                  <input type="checkbox" name="medicationSelect" checked={medicineL} onClick={(e) => { handleMedicineL(e) }} /><label for="medicationTime">점심</label>
+                  <input type="checkbox" name="medicationSelect" checked={medicineD} onClick={(e) => { handleMedicineD(e) }} /><label for="medicationTime">저녁</label>
                 </div>
               </td>
             </tr>
@@ -532,7 +568,7 @@
                 <textarea className="note" cols="30" rows="2" value={note} onChange={handleNote}></textarea>
               </td>
             </tr>
-            
+
             {/* <tr>
               <th>기저질환</th>
               <td colSpan={3}>
@@ -540,15 +576,15 @@
               </td>
             </tr> */}
           </table>
-            <div className="btn-wrap flex-center">
-              <Button
-                className={"btn-small green-btn"}
-                btnName={"등록"}
-                onClick={() => {
-                  seniorInsert(userName,gender,brith, telNum, homeAddress, note, medicineM, medicineL, medicineD)
-                }}
-              />
-            </div>
+          <div className="btn-wrap flex-center">
+            <Button
+              className={"btn-small green-btn"}
+              btnName={"등록"}
+              onClick={() => {
+                InsertSenior(userName, gender, brith, telNum, homeAddress, note, medicineM, medicineL, medicineD)
+              }}
+            />
+          </div>
         </div>
       </Modal>
 
@@ -584,7 +620,7 @@
             />
           </div>
           <div className="btn-wrap flex-end">
-            <Button className={"btn-small green-btn"} btnName={"등록"} onClick={openModal3}/>
+            <Button className={"btn-small green-btn"} btnName={"등록"} onClick={openModal3} />
           </div>
           <ul className="tab-content">
             {data
Add a comment
List