Skip to content

Commit

Permalink
refactor:#345 비밀번호 초기화 로직 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
dalzzy committed Feb 11, 2025
1 parent a32954e commit 796f59f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 32 deletions.
1 change: 0 additions & 1 deletion src/api/admin/member/patchUserManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const resetPwdApi = async (userId: number | number[]) => {
},
},
);
console.log('API 응답: ', response);
return response.data;
} catch (error: any) {
throw new Error(error.response?.data?.message || '비밀번호 초기화 실패');
Expand Down
30 changes: 7 additions & 23 deletions src/components/Admin/Modal/MemberDetailModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import dropdownIcon from '@/assets/images/ic_admin_column_meatball.svg';
import ButtonGroup from '@/components/Admin/ButtonGroup';
import StatusIndicator from '@/components/Admin/StatusIndicator';
import CommonModal from '@/components/Admin/Modal/CommonModal';
import resetPwdApi from '@/api/patchUserManagement';
import useAdminActions from '@/hooks/useAdminActions';

interface MemberDetailModalProps {
data: MemberData;
Expand Down Expand Up @@ -79,40 +79,24 @@ const MemberDetailModal: React.FC<MemberDetailModalProps> = ({
data,
onClose,
}) => {
const handleAction = async (action: string) => {
if (
!window.confirm(`"${data.name}" 멤버의 ${action}을(를) 진행하시겠습니까?`)
)
return;

try {
console.log(`${action} API 요청 시작...`);
if (action === '비밀번호 초기화') {
console.log(` 비밀번호 초기화 요청 대상 ID: ${data.id}`);
const response = await resetPwdApi(data.id);
console.log('비밀번호 초기화 API 응답:', response);
alert('비밀번호 초기화가 완료되었습니다.');
}
} catch (error: any) {
console.error('오류 발생 : ', error.message);
}
};
const { handleAction } = useAdminActions();

const buttons = [
{
label: '가입 승인',
onClick: () => handleAction('가입 승인'),
onClick: () => handleAction('가입 승인', [data.id]),
},
{
label: '관리자로 변경',
onClick: () => handleAction('관리자로 변경'),
onClick: () => handleAction('관리자로 변경', [data.id]),
},
{
label: '비밀번호 초기화',
onClick: () => handleAction('비밀번호 초기화'),
onClick: () => handleAction('비밀번호 초기화', [data.id]),
},
{
label: '유저 추방',
onClick: () => handleAction('유저 추방'),
onClick: () => handleAction('유저 추방', [data.id]),
},
{
label: '직접 입력',
Expand Down
7 changes: 4 additions & 3 deletions src/components/Admin/SelectedTopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useMemberContext } from './context/MemberContext';
import { Title } from './TopBar';
import ButtonGroup from './ButtonGroup';
import CardinalEditModal from './Modal/CardinalEditModal';
import useAdminActions from '@/hooks/useAdminActions';

const SelectedTopBarWrapper = styled.div`
width: 100%;
Expand Down Expand Up @@ -34,6 +35,8 @@ const SelectedTopBar: React.FC = () => {
const { selectedMembers, setSelectedMembers } = useMemberContext();
const [isModalOpen, setIsModalOpen] = useState(false);

const { handleAction } = useAdminActions();

const handleBackClick = () => {
setSelectedMembers([]);
};
Expand Down Expand Up @@ -71,9 +74,7 @@ const SelectedTopBar: React.FC = () => {
{
label: '비밀번호 초기화',
onClick: () =>
window.confirm(
`${selectedMembers.length}명의 멤버 비밀번호를 초기화하시겠습니까?`,
),
handleAction('비밀번호 초기화', selectedMembers.map(Number)),
disabled: false,
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/components/Admin/context/MemberContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createContext, useContext, useEffect, useMemo, useState } from 'react';
import { getAllUsers } from '@/api/getAdminUser';
import { getAllUsers } from '@/api/admin/member/getAdminUser';

export type MemberData = {
id: number;
Expand Down
4 changes: 0 additions & 4 deletions src/hooks/useAdminActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,11 @@ const useAdminActions = () => {
if (!window.confirm(confirmMessage)) return;

try {
console.log(`${action} API 요청 시작...`, targetIds);

if (action === '비밀번호 초기화') {
const response = await resetPwdApi(targetIds);
console.log('비밀번호 초기화 API 응답:', response);
alert('비밀번호 초기화가 완료되었습니다.');
}

// 다른 API 요청 로직 추가 가능
} catch (error: any) {
console.error('오류 발생:', error.message);
}
Expand Down

0 comments on commit 796f59f

Please sign in to comment.