Skip to content

Commit

Permalink
Merge pull request #137 from PLADI-ALM/feat/PDW-90-my-info
Browse files Browse the repository at this point in the history
[PDW-90/feat] 내 정보 수정
  • Loading branch information
psyeon1120 authored Nov 19, 2023
2 parents 0125a08 + 016e835 commit 4564597
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 18 deletions.
3 changes: 3 additions & 0 deletions src/components/capsule/DropBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const Select = styled.select`
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
&:disabled {
background: #FAFAFA;
}
`

const ManagerSelect = styled(Select)`
Expand Down
3 changes: 3 additions & 0 deletions src/components/modal/BigModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ export const AttrInput = styled.input`
padding: 0 10px;
outline: none;
box-sizing: border-box;
&:disabled {
color: #9E9E9E;
}
`

// 하단 버튼 컨테이너
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {SelectToggleInModal} from 'components/capsule/DropBox';
import React, {useState, useEffect, useRef} from 'react';
import {AdminUsersAxios} from 'api/AxiosApi';
import {AdminUsersAxios, UsersAxios} from 'api/AxiosApi';
import {getToken} from 'utils/IsLoginUtil';
import {basicError} from 'utils/ErrorHandlerUtil';
import {
Expand All @@ -21,7 +21,7 @@ import {
BasicRadioInput
} from 'components/capsule/RoleCapsule';
import BigSquareButton, {InputPurpleButton} from 'components/button/BigSquareButton';
import {AffiliationList} from "../../../constants/ToggleList";
import {AffiliationList} from "../../constants/ToggleList";

export function UserModal(props) {
const [affiliationOptionList, setAffiliationOptionList] = useState([]);
Expand All @@ -32,7 +32,8 @@ export function UserModal(props) {
const [userInfo, setUserInfo] = useState(null);
let departments;

function getUserInfo() {
// 관리자 직원 정보 조회
function getUserInfoByAdmin() {
if (props.id !== undefined) {
AdminUsersAxios.get(`/${props.id}`, {
headers: {
Expand All @@ -56,6 +57,7 @@ export function UserModal(props) {
}
}

// 부서 목록 조회
function getDepartmentsList() {
AdminUsersAxios.get("/departments", {
headers: {
Expand All @@ -81,8 +83,30 @@ export function UserModal(props) {
value={affiliation}>{affiliation}</option>)))
}

// 내 정보 조회
function getMyInfo() {
UsersAxios.get("", {
headers: {
Authorization: getToken()
}
})
.then((response) => {
setUserInfo(response.data.data)
currentDepartment.current = response.data.data.department
currentAffiliation.current = response.data.data.affiliation
setDepartmentOptionList(<option value={currentDepartment.current}
selected>{currentDepartment.current}</option>)
setAffiliationOptionList(<option value={currentAffiliation.current}
selected>{currentAffiliation.current}</option>)
})
.catch((error) => {
basicError(error)
})
}

useEffect(() => {
getUserInfo()
if (props.my) getMyInfo()
else getUserInfoByAdmin()
}, [])

const handleRoleChange = (e) => {
Expand All @@ -106,6 +130,7 @@ export function UserModal(props) {
.replace(/^(\d{2,3})(\d{3,4})(\d{4})$/, `$1-$2-$3`);
}

// 관리자 직원 등록
const registerUser = (e) => {
e.preventDefault()
const inputName = e.target.name.value
Expand All @@ -125,7 +150,7 @@ export function UserModal(props) {
phone: inputPhone,
affiliation: inputAffiliation,
department: inputDepartment,
asserts: inputAsset,
assets: inputAsset,
role: inputRole
}, {
headers: {
Expand All @@ -141,6 +166,7 @@ export function UserModal(props) {
})
};

// 관리자 직원 수정
const editUser = (e) => {
e.preventDefault()
const inputName = e.target.name.value
Expand All @@ -156,7 +182,7 @@ export function UserModal(props) {
phone: inputPhone,
affiliation: inputAffiliation,
department: inputDepartment,
asserts: inputAsset,
assets: inputAsset,
role: inputRole
}, {
headers: {
Expand All @@ -172,14 +198,42 @@ export function UserModal(props) {
})
};

// 내 정보 수정
const editMyInfo = (e) => {
e.preventDefault()
const inputName = e.target.name.value
const inputPhone = e.target.phone.value
const inputAsset = e.target.asset.value
// todo: 입력값 정규식 확인

UsersAxios.patch("", {
name: inputName,
phone: inputPhone,
assets: inputAsset,
}, {
headers: {
Authorization: getToken()
}
})
.then((response) => {
alert("수정되었습니다.")
props.handler();
})
.catch((error) => {
basicError(error)
})
};


return (
<ModalBackdrop onClick={props.handler}>
<ModalView onClick={(e) => e.stopPropagation()}>
<TitleContainer>
<ModalTitle>{props.title}</ModalTitle>
</TitleContainer>
<AttrsForm method="post" id="register-user-form" onSubmit={userInfo !== null ? editUser : registerUser}>
<AttrsForm method="post" id="register-user-form"
onSubmit={props.my ? editMyInfo :
userInfo !== null ? editUser : registerUser}>
<AttrContainer>
<AttrLabel>성명</AttrLabel>
<AttrInput type='text' name='name'
Expand All @@ -189,13 +243,13 @@ export function UserModal(props) {
<AttrLabel>이메일</AttrLabel>
<AttrInput type='text' name='email'
value={userInfo !== null ? userInfo.email : null}
disabled={userInfo !== null ? 'disabled' : null}/>
disabled={userInfo !== null}/>
</AttrContainer>
<AttrContainer>
<AttrLabel>비밀번호</AttrLabel>
<AttrInput type='text' name='password'
value={userInfo !== null ? '⁕⁕⁕⁕⁕⁕⁕⁕⁕⁕⁕⁕⁕⁕⁕' : null}
disabled={userInfo !== null ? 'disabled' : null}/>
disabled={userInfo !== null}/>
</AttrContainer>
<AttrContainer>
<AttrLabel>연락처</AttrLabel>
Expand All @@ -206,21 +260,22 @@ export function UserModal(props) {
<AttrLabel>소속</AttrLabel>
<SelectToggleInModal name='affiliation' items={affiliationOptionList}
value={currentAffiliation.current}
onChange={handleAffiliationChange}/>
onChange={handleAffiliationChange}
disabled={props.my}/>
</AttrContainer>
<AttrContainer>
<AttrLabel>부서</AttrLabel>
<SelectToggleInModal name='department' items={departmentOptionList}
value={currentDepartment.current}
onChange={handleDepartmentChange}/>
onChange={handleDepartmentChange}
disabled={props.my}/>
</AttrContainer>
<AttrContainer>
<AttrLabel>부여자산</AttrLabel>
<AttrInput type='text' name='asset'
defaultValue={userInfo !== null ? userInfo.asset : null}/>
defaultValue={userInfo !== null ? userInfo.assets : null}/>
</AttrContainer>
{/*<AttrContainer style={userInfo !== null ? {display: 'none'} : null}>*/}
<AttrContainer>
<AttrContainer style={props.my ? {display: 'none'} : null}>
<AttrLabel>권한</AttrLabel>
<BasicRadioInput type="radio" id="basic"
name="role"
Expand Down
2 changes: 1 addition & 1 deletion src/components/officeBooking/BookingTimeBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {OfficesAxios} from "../../api/AxiosApi";
import {getToken} from "../../utils/IsLoginUtil";
import {basicError} from "../../utils/ErrorHandlerUtil";
import {useParams} from "react-router-dom";
import {UserModal} from "../../pages/admin/user/UserModal";
import {UserModal} from "../modal/UserModal";
import moment from "moment/moment";

let bookingState = [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false,];
Expand Down
12 changes: 11 additions & 1 deletion src/components/sidebar/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { removeAllCookies } from 'utils/CookiesUtil';
import { getToken, isManager, navigateToLogin } from 'utils/IsLoginUtil';
import { UsersAxios } from 'api/AxiosApi';
import { basicError } from 'utils/ErrorHandlerUtil';
import {UserModal} from "../modal/UserModal";

const Container = styled.div`
width: 250px;
Expand Down Expand Up @@ -103,6 +104,11 @@ function Sidebar() {
navigateToLogin()

const [userName, setUserName] = useState("")
const [isOpen, setIsOpen] = useState(false)

const openModalHandler = () => {
setIsOpen(!isOpen)
}

// 이름
const getUserInfo = () => {
Expand Down Expand Up @@ -159,10 +165,14 @@ function Sidebar() {

<div>
{/* 사원 정보 */}
<MyInfo><Icon src={MyInfoIcon} />{userName}<ManageBtn>관리</ManageBtn></MyInfo>
<MyInfo><Icon src={MyInfoIcon} />{userName}<ManageBtn onClick={openModalHandler}>관리</ManageBtn></MyInfo>
{/* 로그아웃 */}
<Logout onClick={logout}><Icon src={LogoutIcon} />로그아웃</Logout>
</div>
{isOpen ?
<UserModal handler={openModalHandler} my={true} title={"내 정보 수정"}/>
: null
}
</Container>
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/admin/user/UserManage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ManageSearchBar from "components/searchBar/ManageSearchBar";
import {AdminUsersAxios} from "api/AxiosApi";
import {basicError} from "utils/ErrorHandlerUtil";
import {getToken} from "utils/IsLoginUtil";
import {UserModal} from "./UserModal";
import {UserModal} from "../../../components/modal/UserModal";
import {AffiliationList} from "../../../constants/ToggleList";
import styled from "styled-components";

Expand Down
2 changes: 1 addition & 1 deletion src/pages/admin/user/UserMoreModal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {useState} from 'react';
import {MenuText, MoreModalView, NormalDiv, RedDiv} from "../../../components/modal/MoreModal";
import {UserModal} from "./UserModal";
import {UserModal} from "../../../components/modal/UserModal";
import {AdminUsersAxios} from "../../../api/AxiosApi";
import {getToken} from "../../../utils/IsLoginUtil";
import {basicError} from "../../../utils/ErrorHandlerUtil";
Expand Down

0 comments on commit 4564597

Please sign in to comment.