Skip to content

Commit 2434cf7

Browse files
authored
Merge pull request #103 from Stack-Knowledge/feature/approveList
[Admin] approve list
2 parents e3262b3 + 67e053b commit 2434cf7

File tree

18 files changed

+229
-8
lines changed

18 files changed

+229
-8
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export * from './useGetApprovedList';
12
export * from './useGetScoringList';
23
export * from './useGetSolveDetail';
4+
export * from './usePatchApprovalStatus';
35
export * from './usePostScoringResult';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { useQuery } from '@tanstack/react-query';
2+
3+
import { userQueryKeys, userUrl, get } from 'api/common';
4+
5+
import type { UseQueryOptions } from '@tanstack/react-query';
6+
import type { ApprovalStatusType } from 'types';
7+
8+
export const useGetApprovedList = (
9+
options?: UseQueryOptions<ApprovalStatusType[]>
10+
) =>
11+
useQuery<ApprovalStatusType[]>(
12+
userQueryKeys.getApprovedList(),
13+
() => get(userUrl.approvedList()),
14+
options
15+
);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { useMutation } from '@tanstack/react-query';
2+
3+
import { userQueryKeys, userUrl, patch } from 'api/common';
4+
5+
interface ApprovedStatus {
6+
approveStatus: 'REJECT' | 'APPROVED';
7+
}
8+
9+
export const usePatchApprovalStatus = (userId: string) =>
10+
useMutation<void, Error, ApprovedStatus>(
11+
userQueryKeys.patchApprovedStatus(userId),
12+
(data) => patch(userUrl.approvedStatus(userId), data)
13+
);

packages/api/common/src/hooks/auth/usePostLoginCode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useMutation } from '@tanstack/react-query';
22

3-
import { post, authQueryKeys, authUrl } from 'api/common';
3+
import { authQueryKeys, authUrl, post } from 'api/common';
44

55
import type { TokenResponseLoginType } from 'types';
66

packages/api/common/src/libs/queryKeys.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@ export const userQueryKeys = {
3434
getScoringList: () => ['user', 'scoring'],
3535
postScoringResult: (solveId: string) => ['user', 'scoring', solveId],
3636
getSolveDetail: (solveId: string) => ['user', 'solve', solveId],
37+
getApprovedList: () => ['user', 'list', 'approval'],
38+
patchApprovedStatus: (userId: string) => ['user', 'approved', userId],
3739
};

packages/api/common/src/libs/urlController.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,6 @@ export const userUrl = {
3131
scoring: () => '/user/scoring',
3232
scoringResult: (solveId: string) => `/user/scoring/${solveId}`,
3333
solveDetail: (solveId: string) => `/user/scoring/${solveId}`,
34+
approvedList: () => '/user/teacher',
35+
approvedStatus: (userId: string) => `/user/${userId}`,
3436
};

packages/common/src/components/Header/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const Header: React.FC<HeaderProps> = ({ role }) => {
5353
toast.success('로그아웃 되었습니다.');
5454
}
5555

56-
if (isError) toast.success('로그아웃에 실패했습니다.');
56+
if (isError) toast.error('로그아웃에 실패했습니다.');
5757

5858
return (
5959
<S.HeaderWrapper>

packages/types/src/approvalStatus.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface ApprovalStatusType {
2+
name: string;
3+
createdAt: string; // LocalDateTime
4+
userId: string; // UUID
5+
}

packages/types/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ export * from './solveStatusType';
99
export * from './missionDetail';
1010
export * from './studentType';
1111
export * from './uploadProfile';
12+
export * from './approvalStatus';

projects/admin/src/PageContainer/MainPage/index.tsx

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,58 @@
22

33
import { useRef, useState } from 'react';
44

5-
import { XIcon } from 'admin/assets';
6-
import { ApproveModalButton } from 'admin/components';
5+
import { toast } from 'react-toastify';
6+
7+
import { CapIcon, XIcon } from 'admin/assets';
8+
import { ModalItem, ApproveModalButton } from 'admin/components';
9+
10+
import { useGetApprovedList } from 'api/admin';
711

812
import { MainPage } from 'common';
913

1014
import * as S from './style';
1115

1216
const MainPageComponent = () => {
13-
const dialog = useRef<HTMLDialogElement>(null);
17+
const { data, refetch } = useGetApprovedList();
1418

19+
const dialog = useRef<HTMLDialogElement>(null);
1520
const [isOpen, setIsOpen] = useState<boolean>(false);
1621

1722
const handleModalOpen = () => {
1823
dialog.current?.showModal();
1924
setIsOpen(true);
2025
};
2126

27+
const handleSuccessApproved = (isAccepted: boolean) => {
28+
refetch();
29+
isAccepted
30+
? toast.success('수락되었습니다.')
31+
: toast.error('거절되었습니다.');
32+
};
33+
2234
return (
2335
<>
2436
<S.Modal ref={dialog} isOpen={isOpen}>
2537
<form method='dialog'>
2638
<S.ModalButton onClick={() => setIsOpen(false)}>
2739
<XIcon />
2840
</S.ModalButton>
41+
<S.ModalWrapper>
42+
{data && data.length > 0 ? (
43+
data.map((item) => (
44+
<ModalItem
45+
key={item.userId}
46+
teacherItem={item}
47+
onSuccessApproved={handleSuccessApproved}
48+
/>
49+
))
50+
) : (
51+
<S.ApprovedNone>
52+
<CapIcon />
53+
<span>대기중인 선생님이 없습니다..</span>
54+
</S.ApprovedNone>
55+
)}
56+
</S.ModalWrapper>
2957
</form>
3058
</S.Modal>
3159
<S.Wrapper onClick={handleModalOpen}>

0 commit comments

Comments
 (0)