Skip to content

Commit

Permalink
Merge pull request #126 from PoolC/pre-release
Browse files Browse the repository at this point in the history
승인 전 회원 전체 삭제 기능 추가 & 회원가입 오류 수정
  • Loading branch information
mingd1023 authored Sep 19, 2021
2 parents 242a287 + 014573e commit 7a5fa89
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ yarn-debug.log*
yarn-error.log*

.idea
public/data/제목-없는-디자인.png
src/lib/utils/seeders.js
19 changes: 18 additions & 1 deletion src/components/admin/AdminMember/AdminMember.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { MENU } from '../../../constants/menus';
import useInput from '../../../hooks/useInput';
import { notEmptyValidation } from '../../../lib/utils/validation';
import { WhiteNarrowBlock } from '../../../styles/common/Block.styles';
import { StyledDeleteButton } from '../../activity/ActivityCard/ActivityCard.styles';
import Input from '../../common/Input/Input';
import { StyledSearchActionButton } from '../AdminProjectForm/AdminProjectForm.styles';
import {
Expand Down Expand Up @@ -145,6 +146,7 @@ const AdminMember = ({
onUpdateMemberRole,
onSearchMember,
searchMembers,
onDeleteUnacceptedMembers,
roles,
history,
}) => {
Expand All @@ -154,25 +156,40 @@ const AdminMember = ({
e.preventDefault();
onWithdrawMember(loginID);
};

const handleAcceptMember = (e, loginID) => {
e.preventDefault();
onAcceptMember(loginID);
};

const handleToggleAdmin = (e, loginID, isAdmin) => {
e.preventDefault();
onToggleAdmin({ loginID, isAdmin });
};

const handleUpdateMemberRole = (e, loginID, role) => {
e.preventDefault();
onUpdateMemberRole({ loginID, role });
};

const handleDeleteUnacceptedMembers = (e) => {
e.preventDefault();
let result = window.confirm(
`[주의] 승인 전 회원들을 모두 탈퇴 처리 하시겠습니까? 정보는 모두 DB에서 삭제되며 복구할 수 없습니다.`,
);
if (result) {
onDeleteUnacceptedMembers();
}
}

const onClickSearch = (e) => {
e.preventDefault();
onSearchMember(searchMember);
e.target.value = '';
onChangeSearchMember(e);
};


return (
<WhiteNarrowBlock>
<TitleContainer>회원 관리</TitleContainer>
Expand Down Expand Up @@ -211,7 +228,7 @@ const AdminMember = ({
</tbody>
</Table>
)}
<SearchHeader>승인 전 회원 목록</SearchHeader>
<SearchHeader>승인 전 회원 목록<span><StyledDeleteButton onClick={handleDeleteUnacceptedMembers}>전체 삭제</StyledDeleteButton></span></SearchHeader>
<Table>
<MemberTableHead />
<tbody>
Expand Down
15 changes: 8 additions & 7 deletions src/constants/statusCode.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
export const SUCCESS = {
OK: 200,
OK: 200,
ACCEPTED: 202
};

export const CLIENT_ERROR = {
BAD_REQUEST: 400,
UNAUTHORIZED: 401,
FORBIDDEN: 403,
NOT_FOUND: 404,
CONFLICT: 409,
};
BAD_REQUEST: 400,
UNAUTHORIZED: 401,
FORBIDDEN: 403,
NOT_FOUND: 404,
CONFLICT: 409,
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import AdminMember from '../../../components/admin/AdminMember/AdminMember';
import React, { useEffect, useState } from 'react';
import * as memberAPI from '../../../lib/api/member';
import Spinner from '../../../components/common/Spinner/Spinner';
import { SUCCESS } from '../../../constants/statusCode';
import { CLIENT_ERROR, SUCCESS } from '../../../constants/statusCode';
import { MEMBER_ROLE } from '../../../constants/memberRoles';

const AdminMemberContainer = ({ history }) => {
const [memberLoading, setMemberLoading] = useState(true);
Expand Down Expand Up @@ -108,6 +109,23 @@ const AdminMemberContainer = ({ history }) => {
});
};

const onDeleteUnacceptedMembers = () => {
memberAPI.deleteUnacceptedMembers().then((res) => {
if (res.status === SUCCESS.OK) {
alert('승인 전 회원들을 모두 탈퇴 처리 하였습니다.');
setMembers(
members.filter(m => m.role !== MEMBER_ROLE.UNACCEPTED)
);
} else if (res.status === CLIENT_ERROR.FORBIDDEN) {
alert('권한이 없습니다.');
} else {
alert('오류가 발생하여 요청을 수행할 수 없습니다.');
}
});
};



const onSearchMember = (name) => {
setSearchMembers(members.filter((member) => member.name.includes(name)));
};
Expand All @@ -128,6 +146,7 @@ const AdminMemberContainer = ({ history }) => {
onUpdateMemberRole={onUpdateMemberRole}
onSearchMember={onSearchMember}
searchMembers={searchMembers}
onDeleteUnacceptedMembers={onDeleteUnacceptedMembers}
roles={roles}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useEffect, useState } from 'react';
import { withRouter } from 'react-router-dom';
import * as authAPI from '../../../lib/api/auth';
import { removeHeaderAccessToken } from '../../../lib/utils/axiosUtil';
import { SUCCESS } from '../../../constants/statusCode';
import { CLIENT_ERROR, SUCCESS } from '../../../constants/statusCode';

const RegisterFormContainer = ({ location, history }) => {
const [message, setMessage] = useState(null);
Expand Down Expand Up @@ -46,20 +46,20 @@ const RegisterFormContainer = ({ location, history }) => {
});
response
.then((res) => {
if (res.status === SUCCESS.OK) {
if (res.status === SUCCESS.ACCEPTED) {
setMessage(null);
history.push('/register/success');
}
})
.catch((e) => {
console.error(e);
if (e.response.status === 409) {
if (e.response.status === CLIENT_ERROR.CONFLICT) {
setMessage('이미 가입된 아이디/이메일/학번입니다.');
handleModalOpen();
return;
}

if (e.response.status === 400) {
if (e.response.status === CLIENT_ERROR.BAD_REQUEST) {
setMessage('모든 값을 올바르게 입력해주세요.');
handleModalOpen();
return;
Expand Down
14 changes: 8 additions & 6 deletions src/lib/api/member.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import client from './client';

export const searchMember = ({ name }) =>
client.get(`/member/name?name=${name}`);
client.get(`/member/name?name=${name}`);

export const getMembers = () => client.get('/member');

Expand All @@ -10,20 +10,22 @@ export const getMember = (loginID) => client.get(`/member/${loginID}`);
export const getMemberActivityHours = () => client.get(`/member/hour`);

export const acceptMember = (loginID) =>
client.put(`/member/activate/${loginID}`);
client.put(`/member/activate/${loginID}`);

export const withdrawMember = (loginID) => client.delete(`/member/${loginID}`);

export const toggleAdmin = ({ loginID, isAdmin }) =>
client.put(`/member/admin/${loginID}`, { toAdmin: !isAdmin });
client.put(`/member/admin/${loginID}`, { toAdmin: !isAdmin });

export const updateMemberRole = ({ loginID, role }) =>
client.put(`/member/role/${loginID}`, { role });
client.put(`/member/role/${loginID}`, { role });

export const updateMemberRoleBySelf = ({ role }) =>
client.put('/member/role', { role });
client.put('/member/role', { role });

export const getMemberRole = () => client.get('/member/role');

export const updateMemberIsExcepted = (loginId) =>
client.put(`/member/excepted/${loginId}`);
client.put(`/member/excepted/${loginId}`);

export const deleteUnacceptedMembers = () => client.delete('/member/unaccepted');

0 comments on commit 7a5fa89

Please sign in to comment.