kcscDev/egovframe-template-simple-r.../src/pages/admin/users/UserInfoModal.jsx

201 lines
7.9 KiB
React
Raw Normal View History

2024-01-11 09:41:42 +00:00
import React, {useCallback, useEffect, useState} from "react"
2024-01-10 07:38:38 +00:00
import Modal from "react-bootstrap/Modal";
2024-01-11 09:41:42 +00:00
import * as EgovNet from "api/egovFetch";
2024-01-10 07:38:38 +00:00
import Form from "react-bootstrap/Form";
import Row from "react-bootstrap/Row";
import Col from "react-bootstrap/Col";
import Button from "react-bootstrap/Button";
2024-01-11 09:41:42 +00:00
import SelectOption from "components/commonCode/SelectOption";
import CheckBox from "components/commonCode/CheckBox";
2024-01-12 08:54:46 +00:00
import CODE from "../../../constants/code";
2024-01-10 07:38:38 +00:00
function UserInfoModal({userSeq}){
2024-01-12 08:54:46 +00:00
const [userInfo, setUserInfo] = useState({ userSeq: '', userId: '', password: '', passwordChk: '', userNm: '', email: '', phoneNum: '', userSe:'', userRole:'', status:''});
2024-01-10 07:38:38 +00:00
function getModalContent(){
EgovNet.requestFetch(
'/admin/users/info?userSeq='+userSeq,
{
method: "GET"
},
(resp) => {
2024-01-12 08:54:46 +00:00
const respInfo = resp.result.userInfo;
const info = {
userSeq: respInfo.userSeq,
userId: respInfo.userId,
userNm: respInfo.userNm,
email: respInfo.email,
phoneNum: respInfo.phoneNum,
2024-01-10 07:38:38 +00:00
password: "",
passwordChk: "",
2024-01-12 08:54:46 +00:00
userSe: respInfo.userSe,
userRole: respInfo.userRole,
status: respInfo.status
2024-01-10 07:38:38 +00:00
}
2024-01-12 08:54:46 +00:00
setUserInfo(info);
2024-01-10 07:38:38 +00:00
},
(resp) => {
console.log("err response : ", resp);
}
);
}
2024-01-11 09:41:42 +00:00
function userInfoChange(e){
2024-01-12 08:54:46 +00:00
e.preventDefault();
e.stopPropagation();
const form = e.target;
const info = {
userSeq: form.userSeq.value,
userId: form.userId.value,
password: form.password.value,
passwordChk: form.passwordChk.value,
userNm: form.userNm.value,
email: form.email.value,
phoneNum: form.phoneNum.value,
userSe: form.userSe.value,
userRole: '',
status: form.status.value,
}
let userRole = '';
form.userRole.forEach(function (input){
if(input.checked){
userRole += input.value+','
}
})
if(userRole){
info.userRole = userRole.slice(0, -1)
}
EgovNet.requestFetch(
'/admin/users/info',
{
method: "PUT",
headers: {
'Content-type': 'application/json'
},
body: JSON.stringify(info)
},
(resp) => {
if (Number(resp.resultCode) === Number(CODE.RCV_SUCCESS)) {
alert("저장되었습니다.")
}else if(Number(resp.resultCode) === Number(CODE.RCV_ERROR_AUTH)){
console.log("토큰 갱신중.")
}else{
alert(resp.result.resultMessage)
}
}
)
2024-01-10 07:38:38 +00:00
}
useEffect(() => {
getModalContent();
}, []);
2024-01-12 08:54:46 +00:00
useEffect(()=>{
const checkBoxDiv = document.querySelector("#ROLE_checkBoxDiv")
const userRole = userInfo.userRole;
if(userRole){
checkBoxDiv.childNodes.forEach(function (div){
const input = div.children[0];
if(userRole.includes(input.value)){
input.checked = true;
}
})
}
}, [userInfo]);
2024-01-10 07:38:38 +00:00
return (
<>
2024-01-11 09:41:42 +00:00
<Modal.Header closeButton>
2024-01-10 07:38:38 +00:00
<Modal.Title>
{userInfo.userNm} 상세정보
</Modal.Title>
</Modal.Header>
<Modal.Body>
2024-01-11 09:41:42 +00:00
<Form onSubmit={(e) =>{userInfoChange(e)}} noValidate>
2024-01-12 08:54:46 +00:00
<input type={"hidden"} name={"userSeq"} defaultValue={userInfo.userSeq} />
2024-01-11 09:41:42 +00:00
<Form.Group as={Row} className="mb-3">
2024-01-10 07:38:38 +00:00
<Form.Label column sm={3}>
아이디
</Form.Label>
<Col sm={9}>
2024-01-12 08:54:46 +00:00
<Form.Control type="text" name="userId" placeholder="아이디" required defaultValue={userInfo?.userId} readOnly/>
2024-01-10 07:38:38 +00:00
</Col>
</Form.Group>
2024-01-11 09:41:42 +00:00
<Form.Group as={Row} className="mb-3">
2024-01-10 07:38:38 +00:00
<Form.Label column sm={3}>
2024-01-11 09:41:42 +00:00
비밀번호
2024-01-10 07:38:38 +00:00
</Form.Label>
<Col sm={9}>
2024-01-11 09:41:42 +00:00
<Form.Control type="password" name="password" placeholder="비밀번호 변경 시 입력" />
2024-01-10 07:38:38 +00:00
</Col>
</Form.Group>
2024-01-11 09:41:42 +00:00
<Form.Group as={Row} className="mb-3">
2024-01-10 07:38:38 +00:00
<Form.Label column sm={3}>
2024-01-11 09:41:42 +00:00
비밀번호 확인
2024-01-10 07:38:38 +00:00
</Form.Label>
<Col sm={9}>
2024-01-11 09:41:42 +00:00
<Form.Control type="password" name="passwordChk" placeholder="비밀번호 변경 시 입력" />
2024-01-10 07:38:38 +00:00
</Col>
</Form.Group>
2024-01-11 09:41:42 +00:00
<Form.Group as={Row} className="mb-3">
2024-01-10 07:38:38 +00:00
<Form.Label column sm={3}>
2024-01-11 09:41:42 +00:00
이름
2024-01-10 07:38:38 +00:00
</Form.Label>
<Col sm={9}>
2024-01-11 09:41:42 +00:00
<Form.Control type="text" name="userNm" placeholder="이름" required defaultValue={userInfo?.userNm} />
2024-01-10 07:38:38 +00:00
</Col>
</Form.Group>
2024-01-11 09:41:42 +00:00
<Form.Group as={Row} className="mb-3">
2024-01-10 07:38:38 +00:00
<Form.Label column sm={3}>
2024-01-11 09:41:42 +00:00
이메일
2024-01-10 07:38:38 +00:00
</Form.Label>
<Col sm={9}>
2024-01-11 09:41:42 +00:00
<Form.Control type="email" name="email" placeholder="email" required defaultValue={userInfo?.email} />
2024-01-10 07:38:38 +00:00
</Col>
</Form.Group>
2024-01-11 09:41:42 +00:00
<Form.Group as={Row} className="mb-3">
2024-01-10 07:38:38 +00:00
<Form.Label column sm={3}>
2024-01-11 09:41:42 +00:00
연락처
2024-01-10 07:38:38 +00:00
</Form.Label>
<Col sm={9}>
2024-01-11 09:41:42 +00:00
<Form.Control type="text" name="phoneNum" placeholder="연락처" required defaultValue={userInfo?.phoneNum} />
2024-01-10 07:38:38 +00:00
</Col>
</Form.Group>
2024-01-11 09:41:42 +00:00
<Form.Group as={Row} className="mb-3">
2024-01-10 07:38:38 +00:00
<Form.Label column sm={3}>
사용자 유형
</Form.Label>
<Col sm={9}>
2024-01-11 09:41:42 +00:00
<SelectOption name={"userSe"} grpCd={"ACC_TYPE"} selectedValue={userInfo?.userSe} />
2024-01-10 07:38:38 +00:00
</Col>
</Form.Group>
2024-01-11 09:41:42 +00:00
<Form.Group as={Row} className="mb-3">
2024-01-10 07:38:38 +00:00
<Form.Label column sm={3}>
사용자 권한
</Form.Label>
<Col sm={9}>
2024-01-12 08:54:46 +00:00
<CheckBox name={"userRole"} grpCd={"ROLE"} />
2024-01-10 07:38:38 +00:00
</Col>
</Form.Group>
2024-01-11 09:41:42 +00:00
<Form.Group as={Row} className="mb-3">
2024-01-10 07:38:38 +00:00
<Form.Label column sm={3}>
상태
</Form.Label>
<Col sm={9}>
2024-01-11 09:41:42 +00:00
<SelectOption name={"status"} grpCd={"ACC_STUS"} selectedValue={userInfo?.status} />
2024-01-10 07:38:38 +00:00
</Col>
</Form.Group>
<Row className="mb-3">
<Form.Label column xs={{span:8, offset:2}} id="findResultLabel"></Form.Label>
<Col xs={2}>
<Button type="submit">저장</Button>
</Col>
</Row>
</Form>
</Modal.Body>
</>
)
}
export default UserInfoModal;