Skip to content

Commit 1a6a11d

Browse files
authored
fix: 내 정보 변경 오류 수정 (#152)
* feat: 내 정보 관련 api 변경 * feat: 내 정보 변경 api 이용 하는 곳 코드 변경 * fix: 닉네임 변경시 클라이언트 오류 수정
1 parent 7f83b9f commit 1a6a11d

File tree

4 files changed

+22
-27
lines changed

4 files changed

+22
-27
lines changed

src/app/my/modify/MyInfoModifyForm.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
import { useRouter } from "next/navigation";
44
import { useState } from "react";
55

6-
import { updateMyNicknameApi } from "@/services/myInfo";
6+
import { updateMyInfoApi } from "@/services/myInfo";
77

88
import BlockBtn from "@/components/button/BlockBtn";
99
import ConfirmCancelModal from "@/components/modal/ConfirmCancelModal";
1010

1111
import { MyInfo } from "@/types/myInfo";
1212

13-
import { useAlert } from "@/context/AlertContext";
14-
1513
type MyInfoModifyFormProps = {
1614
myInfo: MyInfo;
1715
};
@@ -20,12 +18,11 @@ const MyInfoModifyForm = ({ myInfo }: MyInfoModifyFormProps) => {
2018
const [nickname, setNickname] = useState<string>(myInfo.nickname);
2119
const [isChangeModalOpen, setIsChangeModalOpen] = useState<boolean>(false);
2220
const router = useRouter();
23-
const { alert } = useAlert();
2421

2522
const updateNickname = async (newNickname: string) => {
23+
setIsChangeModalOpen(false);
2624
try {
27-
setIsChangeModalOpen(false);
28-
await updateMyNicknameApi(newNickname);
25+
await updateMyInfoApi({ nickname: newNickname });
2926
await alert("닉네임이 변경되었습니다");
3027
router.refresh();
3128
} catch (err) {

src/app/my/modify/MyProfileImageModify.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { useRouter } from "next/navigation";
44
import { useRef } from "react";
55

6-
import { updateMyProfileImage } from "@/services/myInfo";
6+
import { updateMyInfoApi } from "@/services/myInfo";
77

88
import { MyInfo } from "@/types/myInfo";
99

@@ -17,7 +17,7 @@ const MyProfileImageModify = ({ myInfo }: MyProfileImageModifyProps) => {
1717

1818
const updateProfileImage = async (imageFile: File) => {
1919
try {
20-
await updateMyProfileImage(imageFile);
20+
await updateMyInfoApi({ file: imageFile });
2121
alert("프로필 이미지가 변경되었습니다");
2222
router.refresh();
2323
} catch (err) {

src/services/myInfo.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@ import { AxiosResponse } from "axios";
22

33
import { axiosInstance } from "@/utils/axiosInstance";
44

5-
import { MyInfo, MyInfoSimple, MyNickname, MyProfileImage } from "@/types/myInfo";
5+
import { MyInfo, MyInfoPatchRequest, MyInfoSimple } from "@/types/myInfo";
66
import { ListUniversity } from "@/types/university";
77

88
export const getMyInfoApi = (): Promise<AxiosResponse<MyInfo>> => axiosInstance.get("/my");
99

10-
export const getMyInfoSimpleApi = (): Promise<AxiosResponse<MyInfoSimple>> => axiosInstance.get("/my/update");
10+
export const updateMyInfoApi = (request: MyInfoPatchRequest): Promise<AxiosResponse<MyInfoSimple>> => {
11+
const convertedRequest: FormData = new FormData();
12+
if (request.nickname) {
13+
convertedRequest.append("nickname", request.nickname);
14+
}
15+
if (request.file) {
16+
convertedRequest.append("file", request.file);
17+
}
1118

12-
export const updateMyInfoApi = (data: MyInfoSimple): Promise<AxiosResponse<MyInfoSimple>> =>
13-
axiosInstance.patch("/my/update", data);
19+
return axiosInstance.patch("/my", convertedRequest, {
20+
headers: { "Content-Type": "multipart/form-data" },
21+
});
22+
};
1423

1524
export const getMyWishUniversityApi = (): Promise<AxiosResponse<ListUniversity[]>> =>
1625
axiosInstance.get("/universities/like");
17-
18-
export const updateMyNicknameApi = (nickname: string): Promise<AxiosResponse<MyNickname>> =>
19-
// DEPRECATED: Use updateMyInfoApi instead
20-
axiosInstance.patch("/my/update/nickname", { nickname });
21-
22-
export const updateMyProfileImage = (file: File): Promise<AxiosResponse<MyProfileImage>> =>
23-
// DEPRECATED: Use updateMyInfoApi instead
24-
axiosInstance.patch("/my/update/profileImage", { file }, { headers: { "Content-Type": "multipart/form-data" } });

src/types/myInfo.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,12 @@ export interface MyInfo {
1111
}
1212

1313
export interface MyInfoSimple {
14-
// 내 정보 수정 페이지에서 사용
1514
nickname: string;
1615
profileImageUrl: string;
1716
}
1817

19-
export interface MyNickname {
20-
nickname: string;
21-
}
22-
23-
export interface MyProfileImage {
24-
profileImageUrl: string;
18+
export interface MyInfoPatchRequest {
19+
// 내 정보 수정 페이지에서 사용
20+
nickname?: string;
21+
file?: Blob; // 프로필 이미지
2522
}

0 commit comments

Comments
 (0)