-
2024.06.01
+
{props.userInfo.userImage.createdDate}
{
- return ;
+interface IMyPageHeaderContainer {
+ userInfo: userResponseDto;
+}
+const MyPageHeaderContainer = (props: IMyPageHeaderContainer) => {
+ return <>
+
+ >;
};
-
-export default MyPageHeaderContainer;
+export default MyPageHeaderContainer
\ No newline at end of file
diff --git a/src/containers/mypage/MyProfileContainer.tsx b/src/containers/mypage/MyProfileContainer.tsx
index e6b8f71b..9806b9be 100644
--- a/src/containers/mypage/MyProfileContainer.tsx
+++ b/src/containers/mypage/MyProfileContainer.tsx
@@ -1,13 +1,21 @@
"use client";
import MyProfile from "@/components/mypage/MyProfile";
+import { userResponseDto } from "@/types/UserDto";
+import { fetchWithAuth } from "@/utils/fetchWithAuth";
import { ChangeEvent, useRef, useState } from "react";
-const MyProfileContainer = () => {
+interface IMyProfileContainer {
+ userInfo: userResponseDto;
+}
+
+const MyProfileContainer = ({userInfo}: IMyProfileContainer) => {
const imageUploadRef = useRef(null);
const [, setIsDragging] = useState(false);
const [imageUrl, setImageUrl] = useState("/");
-
+ const [nickname, setNickname] = useState(userInfo.nickname);
+ const [defaultNickname, setDefaultNickname] = useState(userInfo.nickname);
+ const [message, setMessage] = useState("");
const onDragEnter = (e: React.DragEvent) => {
e.preventDefault();
e.stopPropagation();
@@ -48,8 +56,30 @@ const MyProfileContainer = () => {
const result = URL.createObjectURL(file);
setImageUrl(result);
};
+ const submitChangeNicknameHandler = async () => {
+ if (nickname == "" && nickname == defaultNickname) return;
+ const res = await fetchWithAuth("/api/mypage/change-nickname", {
+ method: "PUT",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({ nickname: nickname }),
+ })
+
+ const data = await res.json();
+ if (data.status == 200) {
+ setDefaultNickname(nickname);
+ setMessage("성공");
+ } else {
+ setMessage("실패");
+ }
+ }
+
+ const changeNickname = (value: string) => {
+ setNickname(value);
+ setMessage("");
+ }
- // TODO : 디폴트 이미지로 돌아가는 방법에 대해서도 코드 작성이 필요하다. 나중에 서버에 이미지 업로드 될 때 같이 변경해서 변경할 예정
return (
{
imageUploadRef={imageUploadRef}
imageUrl={imageUrl}
onChangeImageUploadInputHandler={onChangeImageUploadInputHandler}
+ userInfo={userInfo}
+ submitChangeNicknameHandler={submitChangeNicknameHandler}
+ nickname={nickname}
+ changeNickname={changeNickname}
+ defaultNickname={defaultNickname}
+ message={message}
/>
);
};
diff --git a/src/middleware.ts b/src/middleware.ts
index 8bdae95a..51f4d821 100644
--- a/src/middleware.ts
+++ b/src/middleware.ts
@@ -7,7 +7,8 @@ export async function middleware(request: NextRequest) {
pathname.startsWith("/informations/write") ||
pathname.startsWith("/informations/edit") ||
pathname.startsWith("/gathering/write") ||
- pathname.startsWith("/diary")
+ pathname.startsWith("/diary") ||
+ pathname.startsWith("/mypage")
) {
const token = request.cookies.get("access_token");
const refresh_token = request.cookies.get("refresh_token");
@@ -62,5 +63,6 @@ export const config = {
"/gathering/write",
"/diary/:path*",
"/auth/:path*",
+ "/mypage/:path*",
],
};