Skip to content

Commit

Permalink
Feat: 승인 전 회원 전체 삭제 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
mingd1023 committed Sep 19, 2021
1 parent 84732ba commit 014573e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
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
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

0 comments on commit 014573e

Please sign in to comment.