Skip to content

Commit dc893fe

Browse files
authored
Merge pull request #242 from manNomi/refactor/mentee_pages
Refactor : mentee pages API 연결 및 디자인 요소 수정
2 parents 0826746 + 84deb05 commit dc893fe

39 files changed

Lines changed: 749 additions & 628 deletions

File tree

public/svgs/mentor/modify.svg

Lines changed: 4 additions & 3 deletions
Loading

src/api/article/client/queryKey.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export enum QueryKeys {
2+
articleList = "articleList",
3+
}
Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
1-
import useFetch from "@/utils/apiUtils";
1+
import { AxiosResponse } from "axios";
22

3-
const useDeleteArticle = (articleId: number | null) => {
4-
const { loading, error, fetchData } = useFetch<void>();
3+
import { axiosInstance } from "@/utils/axiosInstance";
54

6-
const deleteArticle = () => {
7-
if (articleId === null) return;
5+
import { QueryKeys } from "./queryKey";
86

9-
fetchData({
10-
method: "delete",
11-
url: `/news/${articleId}`,
12-
body: undefined,
13-
isToken: true,
14-
});
15-
};
7+
import { useMutation, useQueryClient } from "@tanstack/react-query";
168

17-
return { deleteArticle, loading, error };
9+
const deleteArticle = async (articleId: number): Promise<void> => {
10+
const response: AxiosResponse<void> = await axiosInstance.delete(`/news/${articleId}`);
11+
return response.data;
12+
};
13+
14+
const useDeleteArticle = () => {
15+
const queryClient = useQueryClient();
16+
17+
return useMutation({
18+
mutationFn: deleteArticle,
19+
onSuccess: () => {
20+
// 아티클 목록 쿼리를 무효화하여 새로 고침
21+
queryClient.invalidateQueries({ queryKey: [QueryKeys.articleList] });
22+
},
23+
onError: (error) => {
24+
console.error("Failed to delete article:", error);
25+
},
26+
});
1827
};
1928

2029
export default useDeleteArticle;

src/api/article/client/useGetAriticleList.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,30 @@
1-
import { useEffect, useState } from "react";
1+
import { AxiosResponse } from "axios";
22

3-
import useFetch from "@/utils/apiUtils";
3+
import { axiosInstance } from "@/utils/axiosInstance";
44

55
import { ArticleResponse } from "../types/response";
6+
import { QueryKeys } from "./queryKey";
7+
8+
import { useQuery } from "@tanstack/react-query";
69

710
/* ---------- 타입 ---------- */
811

912
interface ArticleListResponse {
1013
news: ArticleResponse[]; // 최대 5개
1114
}
1215

16+
const getArticleList = async (userId: number): Promise<ArticleListResponse> => {
17+
const response: AxiosResponse<ArticleListResponse> = await axiosInstance.get(`/news?site-user-id=${userId}`);
18+
return response.data;
19+
};
20+
1321
const useGetArticleList = (userId: number | null) => {
14-
const { result, loading, error, fetchData } = useFetch<ArticleListResponse>();
15-
16-
const [articleList, setArticleList] = useState<ArticleResponse[]>([]);
17-
18-
/* 페이지 변경 시 데이터 요청 */
19-
useEffect(() => {
20-
if (userId === null) return;
21-
22-
fetchData({
23-
method: "get",
24-
url: `/news?site-user-id=${userId}`,
25-
body: undefined,
26-
isToken: true,
27-
});
28-
}, [userId, fetchData]);
29-
30-
/* 응답 처리 */
31-
useEffect(() => {
32-
if (result) {
33-
setArticleList(result.data.news);
34-
}
35-
}, [result]);
36-
37-
return { articleList, loading, error };
22+
return useQuery({
23+
queryKey: [QueryKeys.articleList, userId],
24+
queryFn: () => getArticleList(userId!),
25+
enabled: userId !== null,
26+
select: (data: ArticleListResponse) => data.news,
27+
});
3828
};
3929

4030
export default useGetArticleList;

src/api/auth/client/usePostEmailAuth.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { useRouter } from "next/navigation";
2+
13
import { AxiosResponse } from "axios";
24

35
import { publicAxiosInstance } from "@/utils/axiosInstance";
@@ -19,11 +21,16 @@ const postEmailAuth = ({ email, password }: LoginRequest): Promise<AxiosResponse
1921
publicAxiosInstance.post("/auth/email/sign-in", { email, password });
2022

2123
const usePostEmailAuth = () => {
24+
const router = useRouter();
2225
return useMutation({
2326
mutationFn: postEmailAuth,
2427
onSuccess: (data) => {
2528
const { accessToken } = data.data;
2629
setAccessToken(accessToken);
30+
router.replace("/"); // 로그인 성공 후 홈으로 리다이렉트
31+
},
32+
onError: (error) => {
33+
alert("이메일 또는 비밀번호가 올바르지 않습니다. 다시 시도해주세요.");
2734
},
2835
});
2936
};

src/api/auth/client/usePostKakaoAuth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { setAccessToken } from "@/lib/zustand/useTokenStore";
88
import { useMutation } from "@tanstack/react-query";
99

1010
// Kakao
11-
interface RegisteredKakaoAuthResponse {
11+
interface RegisteredKakaoAuthReponse {
1212
isRegistered: true;
1313
accessToken: string;
1414
refreshToken: string;
@@ -28,7 +28,7 @@ interface KakaoAuthRequest {
2828

2929
const postKakaoAuth = ({
3030
code,
31-
}: KakaoAuthRequest): Promise<AxiosResponse<RegisteredKakaoAuthResponse | UnregisteredKakaoAuthReponse>> =>
31+
}: KakaoAuthRequest): Promise<AxiosResponse<RegisteredKakaoAuthReponse | UnregisteredKakaoAuthReponse>> =>
3232
publicAxiosInstance.post("/auth/kakao", { code });
3333

3434
const usePostKakaoAuth = () => {

src/api/mentee/client/usePostApplyMentoring.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
import { useRouter } from "next/navigation";
2+
13
import { axiosInstance } from "@/utils/axiosInstance";
24

5+
import { customConfirm } from "@/lib/zustand/useConfirmModalStore";
6+
import { IconCheck } from "@/public/svgs/mentor";
37
import { useMutation } from "@tanstack/react-query";
48

59
interface UsePostApplyMentoringRequest {
@@ -15,8 +19,26 @@ const postApplyMentoring = async (body: UsePostApplyMentoringRequest): Promise<U
1519
};
1620

1721
const usePostApplyMentoring = () => {
22+
const router = useRouter();
1823
return useMutation({
1924
mutationFn: postApplyMentoring,
25+
onSuccess: async () => {
26+
const ok = await customConfirm({
27+
title: "멘토 신청",
28+
content: "멘토 신청이 완료되었습니다.",
29+
icon: IconCheck,
30+
rejectMessage: "홈으로",
31+
approveMessage: "다른 멘토 찾기",
32+
});
33+
if (ok) {
34+
router.push("/mentor");
35+
return;
36+
}
37+
router.push("/");
38+
},
39+
onError: (error) => {
40+
alert("멘토 신청에 실패했습니다. 다시 시도해주세요.");
41+
},
2042
});
2143
};
2244

src/api/mentor/client/queryKey.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export enum QueryKeys {
22
mentoringNewCount = "mentoringNewCount",
3+
mentoringList = "mentoringList",
34
myMentorProfile = "myMentorProfile",
45
}

src/api/mentor/client/useGetMentorMyProfile.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import { MentorCardPreview } from "@/types/mentor";
77
// 학업 학기 (예: "2026-1")
88
import { useQuery } from "@tanstack/react-query";
99

10-
type GetMyMentorProfileResponse = MentorCardPreview;
10+
type UseGetMyMentorProfileResponse = MentorCardPreview;
1111

12-
const getMentorMyProfile = async (): Promise<GetMyMentorProfileResponse> => {
13-
const res = await axiosInstance.get<GetMyMentorProfileResponse>("/mentor/my");
12+
const getMentorMyProfile = async (): Promise<UseGetMyMentorProfileResponse> => {
13+
const res = await axiosInstance.get<UseGetMyMentorProfileResponse>("/mentor/my");
1414
return res.data;
1515
};
1616

0 commit comments

Comments
 (0)