diff --git a/src/apis/axiosInstance.ts b/src/apis/axiosInstance.ts index d9979de..ad3fcaa 100644 --- a/src/apis/axiosInstance.ts +++ b/src/apis/axiosInstance.ts @@ -9,14 +9,7 @@ export const axiosInstance = axios.create({ }, }); -export const axiosCertificationInstance = axios.create({ - baseURL: `${process.env.NEXT_PUBLIC_BASE_URL}api/`, - headers: { - "Content-Type": "application/json", - }, -}); - -axiosCertificationInstance.interceptors.request.use((config) => { +axiosInstance.interceptors.request.use((config) => { const accessToken = localStorage.getItem("accessToken"); if (accessToken) { config.headers.Authorization = `Bearer ${accessToken}`; @@ -24,7 +17,7 @@ axiosCertificationInstance.interceptors.request.use((config) => { return config; }); -axiosCertificationInstance.interceptors.response.use( +axiosInstance.interceptors.response.use( (response) => { return response; }, @@ -36,9 +29,7 @@ axiosCertificationInstance.interceptors.response.use( const newAccessToken = await getNewAccessToken(); if (newAccessToken) { - originalRequest.headers.Authorization = `Bearer ${newAccessToken}`; - - return axiosCertificationInstance(originalRequest); + return axiosInstance(originalRequest); } } diff --git a/src/apis/getNewAccessToken.ts b/src/apis/getNewAccessToken.ts index 3d511b2..4104b7f 100644 --- a/src/apis/getNewAccessToken.ts +++ b/src/apis/getNewAccessToken.ts @@ -1,7 +1,5 @@ import axios from "axios"; -import { ROUTE } from "@/constants/route"; - export const getNewAccessToken = async () => { try { const refreshToken = localStorage.getItem("refreshToken"); @@ -12,7 +10,7 @@ export const getNewAccessToken = async () => { }, }); - const { accessToken, refreshToken: newRefreshToken } = response.data; + const { accessToken, refreshToken: newRefreshToken } = response.data.data; localStorage.setItem("accessToken", accessToken); localStorage.setItem("refreshToken", newRefreshToken); @@ -20,7 +18,6 @@ export const getNewAccessToken = async () => { } catch (error) { localStorage.removeItem("accessToken"); localStorage.removeItem("refreshToken"); - window.location.href = ROUTE.LOGIN; return null; } }; diff --git a/src/components/common/Comment/apis/deleteComment.ts b/src/components/common/Comment/apis/deleteComment.ts index 4a806de..0e5fb72 100644 --- a/src/components/common/Comment/apis/deleteComment.ts +++ b/src/components/common/Comment/apis/deleteComment.ts @@ -1,6 +1,6 @@ -import { axiosCertificationInstance } from "@/apis/axiosInstance"; +import { axiosInstance } from "@/apis/axiosInstance"; export default async function deleteComment(id: number) { - const { data } = await axiosCertificationInstance.delete(`comments/${id}`); + const { data } = await axiosInstance.delete(`comments/${id}`); return data.data; } diff --git a/src/components/common/Comment/apis/postChatAccept.ts b/src/components/common/Comment/apis/postChatAccept.ts index f599f5c..2310922 100644 --- a/src/components/common/Comment/apis/postChatAccept.ts +++ b/src/components/common/Comment/apis/postChatAccept.ts @@ -1,4 +1,4 @@ -import { axiosCertificationInstance } from "@/apis/axiosInstance"; +import { axiosInstance } from "@/apis/axiosInstance"; interface PostChatAcceptType { body: { @@ -9,7 +9,7 @@ interface PostChatAcceptType { } export default async function postChatAccept({ body }: PostChatAcceptType) { - const { data } = await axiosCertificationInstance.post(`matching/accept`, { + const { data } = await axiosInstance.post(`matching/accept`, { ...body, }); diff --git a/src/components/common/Comment/apis/putComment.ts b/src/components/common/Comment/apis/putComment.ts index b9e6bdf..3136431 100644 --- a/src/components/common/Comment/apis/putComment.ts +++ b/src/components/common/Comment/apis/putComment.ts @@ -1,7 +1,7 @@ -import { axiosCertificationInstance } from "@/apis/axiosInstance"; +import { axiosInstance } from "@/apis/axiosInstance"; export default async function putComment(id: string, comment: string) { - const { data } = await axiosCertificationInstance.put(`comments/${id}`, { + const { data } = await axiosInstance.put(`comments/${id}`, { content: comment, }); diff --git a/src/components/common/Header/User/DropDown/DropDown.tsx b/src/components/common/Header/User/DropDown/DropDown.tsx index 0b6f621..5220685 100644 --- a/src/components/common/Header/User/DropDown/DropDown.tsx +++ b/src/components/common/Header/User/DropDown/DropDown.tsx @@ -36,12 +36,12 @@ export default function DropDown({ isNameClick }: DropDownProps) { openToast("success", "로그아웃되었습니다."); await router.push(ROUTE.HOME); - queryClient.invalidateQueries({ queryKey: ["user"] }); queryClient.invalidateQueries({ queryKey: ["userLogIn"] }); queryClient.invalidateQueries({ queryKey: ["giverPost"] }); queryClient.invalidateQueries({ queryKey: ["takerPost"] }); }, onError: () => { + queryClient.invalidateQueries({ queryKey: ["userLogIn"] }); openToast("error", "로그아웃이 실패하였습니다."); }, }); diff --git a/src/components/common/Header/apis/getLogIn.ts b/src/components/common/Header/apis/getLogIn.ts index 5ff45e4..b30f743 100644 --- a/src/components/common/Header/apis/getLogIn.ts +++ b/src/components/common/Header/apis/getLogIn.ts @@ -1,12 +1,6 @@ import { axiosInstance } from "@/apis/axiosInstance"; export default async function getLogIn() { - const accessToken = localStorage.getItem("accessToken"); - - const { data } = await axiosInstance.get("users/info", { - headers: { - Authorization: `Bearer ${accessToken}`, - }, - }); + const { data } = await axiosInstance.get("users/info"); return data.data; } diff --git a/src/components/common/Header/apis/getNotifications.ts b/src/components/common/Header/apis/getNotifications.ts index f5df716..e6d901d 100644 --- a/src/components/common/Header/apis/getNotifications.ts +++ b/src/components/common/Header/apis/getNotifications.ts @@ -1,11 +1,11 @@ -import { axiosCertificationInstance } from "@/apis/axiosInstance"; +import { axiosInstance } from "@/apis/axiosInstance"; export default async function getNotifications(limit: number, cursor: number) { if (cursor !== 0) { - const { data } = await axiosCertificationInstance.get(`notifications?limit=${limit}&cursor=${cursor}`); + const { data } = await axiosInstance.get(`notifications?limit=${limit}&cursor=${cursor}`); return data.data; } else { - const { data } = await axiosCertificationInstance.get(`notifications?limit=${limit}`); + const { data } = await axiosInstance.get(`notifications?limit=${limit}`); return data.data; } } diff --git a/src/components/common/Header/apis/postLogOut.ts b/src/components/common/Header/apis/postLogOut.ts index 46e15e9..23d7ccc 100644 --- a/src/components/common/Header/apis/postLogOut.ts +++ b/src/components/common/Header/apis/postLogOut.ts @@ -1,21 +1,6 @@ -import { AxiosRequestConfig } from "axios"; - import { axiosInstance } from "@/apis/axiosInstance"; export default async function postLogOut() { - const accessToken = localStorage.getItem("accessToken"); - - const config: AxiosRequestConfig = { - headers: {}, - }; - - if (accessToken) { - config.headers = { - ...config.headers, - Authorization: `Bearer ${accessToken}`, - }; - } - - const { data } = await axiosInstance.post("auth/logout", {}, config); + const { data } = await axiosInstance.post("auth/logout", {}); return data.data; } diff --git a/src/components/common/Header/apis/postReadAllNotification.ts b/src/components/common/Header/apis/postReadAllNotification.ts index 9bf47db..f0ffac6 100644 --- a/src/components/common/Header/apis/postReadAllNotification.ts +++ b/src/components/common/Header/apis/postReadAllNotification.ts @@ -1,6 +1,6 @@ -import { axiosCertificationInstance } from "@/apis/axiosInstance"; +import { axiosInstance } from "@/apis/axiosInstance"; export default async function postReadAllNotification() { - const { data } = await axiosCertificationInstance.post(`notifications/read-all`, {}); + const { data } = await axiosInstance.post(`notifications/read-all`, {}); return data; } diff --git a/src/components/common/Header/apis/postReadNotification.ts b/src/components/common/Header/apis/postReadNotification.ts index 8aa5591..1469c25 100644 --- a/src/components/common/Header/apis/postReadNotification.ts +++ b/src/components/common/Header/apis/postReadNotification.ts @@ -1,6 +1,6 @@ -import { axiosCertificationInstance } from "@/apis/axiosInstance"; +import { axiosInstance } from "@/apis/axiosInstance"; export default async function postReadNotification(notificationId: string) { - const { data } = await axiosCertificationInstance.post(`notifications/${notificationId}/read`, {}); + const { data } = await axiosInstance.post(`notifications/${notificationId}/read`, {}); return data; } diff --git a/src/components/common/Pagenation/apis/getHelpMeList.ts b/src/components/common/Pagenation/apis/getHelpMeList.ts index 126b3b2..ce42764 100644 --- a/src/components/common/Pagenation/apis/getHelpMeList.ts +++ b/src/components/common/Pagenation/apis/getHelpMeList.ts @@ -8,14 +8,9 @@ export default async function getPagenationItems( disabilityType: string, assistanceType: string, ) { - const accessToken = localStorage.getItem("accessToken"); const url = `posts?post-type=${postType}&page=${page}&size=${limit}&sorted=modifiedAt,DESC&post-status=${postStatus}&disability-type=${disabilityType}&assistance-type=${assistanceType}`; - const { data } = await axiosInstance.get(url, { - headers: { - Authorization: `Bearer ${accessToken}`, - }, - }); + const { data } = await axiosInstance.get(url); return data; } diff --git a/src/components/common/Post/apis/postLikes.ts b/src/components/common/Post/apis/postLikes.ts index b366fad..d95e6e8 100644 --- a/src/components/common/Post/apis/postLikes.ts +++ b/src/components/common/Post/apis/postLikes.ts @@ -1,6 +1,6 @@ -import { axiosCertificationInstance } from "@/apis/axiosInstance"; +import { axiosInstance } from "@/apis/axiosInstance"; export default async function postLikes(postId: number) { - const { data } = await axiosCertificationInstance.post(`posts/likes/${postId}`, {}); + const { data } = await axiosInstance.post(`posts/likes/${postId}`, {}); return data; } diff --git a/src/components/common/commentWrite/apis/postComment.ts b/src/components/common/commentWrite/apis/postComment.ts index 5e6cf39..0e1d389 100644 --- a/src/components/common/commentWrite/apis/postComment.ts +++ b/src/components/common/commentWrite/apis/postComment.ts @@ -1,7 +1,7 @@ -import { axiosCertificationInstance } from "@/apis/axiosInstance"; +import { axiosInstance } from "@/apis/axiosInstance"; export default async function postComment(id: string, comment: string) { - const { data } = await axiosCertificationInstance.post(`comments/${id}`, { + const { data } = await axiosInstance.post(`comments/${id}`, { content: comment, }); diff --git a/src/components/page-layout/HomeLayout/apis/getGiverPost.ts b/src/components/page-layout/HomeLayout/apis/getGiverPost.ts index f9519f7..d2002fe 100644 --- a/src/components/page-layout/HomeLayout/apis/getGiverPost.ts +++ b/src/components/page-layout/HomeLayout/apis/getGiverPost.ts @@ -1,24 +1,8 @@ -import { AxiosRequestConfig } from "axios"; - import { axiosInstance } from "@/apis/axiosInstance"; export default async function getGiverPost() { - const accessToken = localStorage.getItem("accessToken"); - - const config: AxiosRequestConfig = { - headers: {}, - }; - - if (accessToken) { - config.headers = { - ...config.headers, - Authorization: `Bearer ${accessToken}`, - }; - } - const { data } = await axiosInstance.get( "posts?post-type=GIVER&page=1&size=4&sorted=modifiedAt,DESC&post-status=RECRUITING", - config, ); return data.data.content; } diff --git a/src/components/page-layout/HomeLayout/apis/getTakerPost.ts b/src/components/page-layout/HomeLayout/apis/getTakerPost.ts index 76c29fa..228c16a 100644 --- a/src/components/page-layout/HomeLayout/apis/getTakerPost.ts +++ b/src/components/page-layout/HomeLayout/apis/getTakerPost.ts @@ -1,24 +1,8 @@ -import { AxiosRequestConfig } from "axios"; - import { axiosInstance } from "@/apis/axiosInstance"; export default async function getTakerPost() { - const accessToken = localStorage.getItem("accessToken"); - - const config: AxiosRequestConfig = { - headers: {}, - }; - - if (accessToken) { - config.headers = { - ...config.headers, - Authorization: `Bearer ${accessToken}`, - }; - } - const { data } = await axiosInstance.get( "posts?post-type=TAKER&page=1&size=4&sorted=modifiedAt,DESC&post-status=RECRUITING", - config, ); return data.data.content; } diff --git a/src/components/page-layout/chatLayout/apis/getAllChatList.ts b/src/components/page-layout/chatLayout/apis/getAllChatList.ts index c437249..31e3ede 100644 --- a/src/components/page-layout/chatLayout/apis/getAllChatList.ts +++ b/src/components/page-layout/chatLayout/apis/getAllChatList.ts @@ -1,25 +1,23 @@ -import { axiosCertificationInstance } from "@/apis/axiosInstance"; +import { axiosInstance } from "@/apis/axiosInstance"; export default async function getAllChatList(limit: number, cursor: number, matchingState: string) { if (matchingState == "ALL" && cursor !== 0) { - const { data } = await axiosCertificationInstance.get(`chat/matchings?limit=${limit}&cursor=${cursor}`); + const { data } = await axiosInstance.get(`chat/matchings?limit=${limit}&cursor=${cursor}`); return data.data; } if (matchingState == "ALL" && cursor === 0) { - const { data } = await axiosCertificationInstance.get(`chat/matchings?limit=${limit}`); + const { data } = await axiosInstance.get(`chat/matchings?limit=${limit}`); return data.data; } if (cursor !== 0) { - const { data } = await axiosCertificationInstance.get( + const { data } = await axiosInstance.get( `chat/matchings?limit=${limit}&cursor=${cursor}&matching-status=${matchingState}`, ); return data.data; } else { - const { data } = await axiosCertificationInstance.get( - `chat/matchings?limit=${limit}&matching-status=${matchingState}`, - ); + const { data } = await axiosInstance.get(`chat/matchings?limit=${limit}&matching-status=${matchingState}`); return data.data; } } diff --git a/src/components/page-layout/chatLayout/apis/getChatingRoom.ts b/src/components/page-layout/chatLayout/apis/getChatingRoom.ts index 3f18b42..8ad9800 100644 --- a/src/components/page-layout/chatLayout/apis/getChatingRoom.ts +++ b/src/components/page-layout/chatLayout/apis/getChatingRoom.ts @@ -1,13 +1,11 @@ -import { axiosCertificationInstance } from "@/apis/axiosInstance"; +import { axiosInstance } from "@/apis/axiosInstance"; export default async function getChatingRoom(limit: number, cursor: number, chatingRoomNumber: number) { if (cursor !== 0) { - const { data } = await axiosCertificationInstance.get( - `chat/matchings/${chatingRoomNumber}?limit=${limit}&cursor=${cursor}`, - ); + const { data } = await axiosInstance.get(`chat/matchings/${chatingRoomNumber}?limit=${limit}&cursor=${cursor}`); return data.data; } else { - const { data } = await axiosCertificationInstance.get(`chat/matchings/${chatingRoomNumber}?limit=${limit}`); + const { data } = await axiosInstance.get(`chat/matchings/${chatingRoomNumber}?limit=${limit}`); return data.data; } } diff --git a/src/components/page-layout/chatLayout/apis/putMatchingStatus.ts b/src/components/page-layout/chatLayout/apis/putMatchingStatus.ts index 2b8f9d5..547c757 100644 --- a/src/components/page-layout/chatLayout/apis/putMatchingStatus.ts +++ b/src/components/page-layout/chatLayout/apis/putMatchingStatus.ts @@ -1,7 +1,7 @@ -import { axiosCertificationInstance } from "@/apis/axiosInstance"; +import { axiosInstance } from "@/apis/axiosInstance"; export default async function putMatchingStatus(chatingRoomId: number, status: string) { - const { data } = await axiosCertificationInstance.put(`matching/${chatingRoomId}`, { + const { data } = await axiosInstance.put(`matching/${chatingRoomId}`, { matchingStatus: status, }); return data.data; diff --git a/src/components/page-layout/helpMeDetailLayout/apis/deletePost.ts b/src/components/page-layout/helpMeDetailLayout/apis/deletePost.ts index 700652c..38b1c56 100644 --- a/src/components/page-layout/helpMeDetailLayout/apis/deletePost.ts +++ b/src/components/page-layout/helpMeDetailLayout/apis/deletePost.ts @@ -1,6 +1,6 @@ -import { axiosCertificationInstance } from "@/apis/axiosInstance"; +import { axiosInstance } from "@/apis/axiosInstance"; export default async function deletePost(id: number) { - const { data } = await axiosCertificationInstance.delete(`posts/${id}`); + const { data } = await axiosInstance.delete(`posts/${id}`); return data.data; } diff --git a/src/components/page-layout/helpMeDetailLayout/apis/getTakerDetail.ts b/src/components/page-layout/helpMeDetailLayout/apis/getTakerDetail.ts index 0780a0f..1d0d767 100644 --- a/src/components/page-layout/helpMeDetailLayout/apis/getTakerDetail.ts +++ b/src/components/page-layout/helpMeDetailLayout/apis/getTakerDetail.ts @@ -1,6 +1,6 @@ -import { axiosCertificationInstance } from "@/apis/axiosInstance"; +import { axiosInstance } from "@/apis/axiosInstance"; export default async function getTakerDetail(id: string) { - const { data } = await axiosCertificationInstance.get(`posts/${id}`); + const { data } = await axiosInstance.get(`posts/${id}`); return data.data; } diff --git a/src/components/page-layout/helpMeRegisterLayout/apis/postHelpMeRegister.ts b/src/components/page-layout/helpMeRegisterLayout/apis/postHelpMeRegister.ts index 1372e17..cf1f7ae 100644 --- a/src/components/page-layout/helpMeRegisterLayout/apis/postHelpMeRegister.ts +++ b/src/components/page-layout/helpMeRegisterLayout/apis/postHelpMeRegister.ts @@ -1,9 +1,9 @@ -import { axiosCertificationInstance } from "@/apis/axiosInstance"; +import { axiosInstance } from "@/apis/axiosInstance"; import { helpMeFormData } from "../types"; export default async function postHelpMeRegister(content: helpMeFormData) { - const { data } = await axiosCertificationInstance.post(`posts`, { + const { data } = await axiosInstance.post(`posts`, { ...content, }); diff --git a/src/components/page-layout/loginLayout/apis/getTestLogin.ts b/src/components/page-layout/loginLayout/apis/getTestLogin.ts index 30843de..ab40088 100644 --- a/src/components/page-layout/loginLayout/apis/getTestLogin.ts +++ b/src/components/page-layout/loginLayout/apis/getTestLogin.ts @@ -1,6 +1,6 @@ -import { axiosCertificationInstance } from "@/apis/axiosInstance"; +import { axiosInstance } from "@/apis/axiosInstance"; export default async function getTestLogin(userId: string) { - const { data } = await axiosCertificationInstance.get(`oauth/login/${userId}`); + const { data } = await axiosInstance.get(`oauth/login/${userId}`); return data; } diff --git a/src/components/page-layout/myPageEditLayout/apis/getMyInfo.ts b/src/components/page-layout/myPageEditLayout/apis/getMyInfo.ts index 1380c92..dc68e3b 100644 --- a/src/components/page-layout/myPageEditLayout/apis/getMyInfo.ts +++ b/src/components/page-layout/myPageEditLayout/apis/getMyInfo.ts @@ -1,6 +1,6 @@ -import { axiosCertificationInstance } from "@/apis/axiosInstance"; +import { axiosInstance } from "@/apis/axiosInstance"; export default async function getMyInfo() { - const { data } = await axiosCertificationInstance.get(`users/info`); + const { data } = await axiosInstance.get(`users/info`); return data.data; } diff --git a/src/components/page-layout/myPageEditLayout/apis/putMyInfo.ts b/src/components/page-layout/myPageEditLayout/apis/putMyInfo.ts index 6c04e28..239e206 100644 --- a/src/components/page-layout/myPageEditLayout/apis/putMyInfo.ts +++ b/src/components/page-layout/myPageEditLayout/apis/putMyInfo.ts @@ -1,9 +1,9 @@ -import { axiosCertificationInstance } from "@/apis/axiosInstance"; +import { axiosInstance } from "@/apis/axiosInstance"; import { FormType } from "../components/MyInfoEditFrom/MyInfoEditForm"; export default async function putMyInfo(body: FormType) { - const { data } = await axiosCertificationInstance.put(`users/info`, { + const { data } = await axiosInstance.put(`users/info`, { ...body, }); return data.data; diff --git a/src/components/page-layout/myPageHelpMeLayout/apis/getMyComment.ts b/src/components/page-layout/myPageHelpMeLayout/apis/getMyComment.ts index 86d9aa1..a45d2c8 100644 --- a/src/components/page-layout/myPageHelpMeLayout/apis/getMyComment.ts +++ b/src/components/page-layout/myPageHelpMeLayout/apis/getMyComment.ts @@ -1,8 +1,6 @@ -import { axiosCertificationInstance } from "@/apis/axiosInstance"; +import { axiosInstance } from "@/apis/axiosInstance"; export default async function getMyComment(pageId: string, postType: string) { - const { data } = await axiosCertificationInstance.get( - `/comments/my-page?post-type=${postType}&page=${pageId}&size=4`, - ); + const { data } = await axiosInstance.get(`/comments/my-page?post-type=${postType}&page=${pageId}&size=4`); return data.data; } diff --git a/src/components/page-layout/myPageHelpMeLayout/apis/getMyPost.ts b/src/components/page-layout/myPageHelpMeLayout/apis/getMyPost.ts index 8bcc1df..308a595 100644 --- a/src/components/page-layout/myPageHelpMeLayout/apis/getMyPost.ts +++ b/src/components/page-layout/myPageHelpMeLayout/apis/getMyPost.ts @@ -1,6 +1,6 @@ -import { axiosCertificationInstance } from "@/apis/axiosInstance"; +import { axiosInstance } from "@/apis/axiosInstance"; export default async function getMyPost(pageId: string, postType: string) { - const { data } = await axiosCertificationInstance.get(`/posts/my-page?post-type=${postType}&page=${pageId}&size=4`); + const { data } = await axiosInstance.get(`/posts/my-page?post-type=${postType}&page=${pageId}&size=4`); return data.data; } diff --git a/src/components/page-layout/myPageLikesLayout/apis/getMyLikes.ts b/src/components/page-layout/myPageLikesLayout/apis/getMyLikes.ts index 8121ff5..ca2ebce 100644 --- a/src/components/page-layout/myPageLikesLayout/apis/getMyLikes.ts +++ b/src/components/page-layout/myPageLikesLayout/apis/getMyLikes.ts @@ -1,4 +1,4 @@ -import { axiosCertificationInstance } from "@/apis/axiosInstance"; +import { axiosInstance } from "@/apis/axiosInstance"; export interface MyLikesRes { content: { @@ -32,8 +32,6 @@ export interface MyLikesRes { } export default async function getMyLikes(pageId: string, postType: string): Promise { - const { data } = await axiosCertificationInstance.get( - `posts/likes/my-page?post-type=${postType}&page=${pageId}&size=4`, - ); + const { data } = await axiosInstance.get(`posts/likes/my-page?post-type=${postType}&page=${pageId}&size=4`); return data.data; } diff --git a/src/components/page-layout/signUpLayout/apis/postSignUp.ts b/src/components/page-layout/signUpLayout/apis/postSignUp.ts index a7e552e..8806add 100644 --- a/src/components/page-layout/signUpLayout/apis/postSignUp.ts +++ b/src/components/page-layout/signUpLayout/apis/postSignUp.ts @@ -1,14 +1,12 @@ import { axiosInstance } from "@/apis/axiosInstance"; interface SignUpRequest { - body: { - name: string; - nickname: string; - gender: string; - birthDate: Date; - email: string; - password: string; - }; + name: string; + nickname: string; + gender: string; + birthDate: Date; + email: string; + password: string; } interface SignUpResponse { @@ -23,7 +21,7 @@ interface SignUpResponse { success: boolean; } -export default async function postSignUp({ body }: SignUpRequest) { +export default async function postSignUp(body: SignUpRequest) { const birthDate = new Date(body.birthDate); birthDate.setDate(birthDate.getDate() + 1); diff --git a/src/components/page-layout/signUpLayout/components/signUpLayout.module.scss b/src/components/page-layout/signUpLayout/components/signUpLayout.module.scss index da6c503..52f8ac1 100644 --- a/src/components/page-layout/signUpLayout/components/signUpLayout.module.scss +++ b/src/components/page-layout/signUpLayout/components/signUpLayout.module.scss @@ -167,7 +167,8 @@ @include font(1.8rem, 500, normal); } -.modalBtnContent { +.modalConfirmBtn, +.modalCloseBtn { border-radius: 0.5rem; border: 0.1rem solid #d3d3d3; background: #d3d3d3; @@ -175,3 +176,12 @@ @include font(1.2rem, 300, normal); padding: 8px 21px 10px 21px; } + +.modalConfirmBtn { + background: #e7efff; + border: 0.1rem solid #e7efff; +} + +.btnBox { + @include flexSort(null, center, center, 1.2rem); +} diff --git a/src/components/page-layout/signUpLayout/components/signUpLayout.tsx b/src/components/page-layout/signUpLayout/components/signUpLayout.tsx index 71b5fba..d68c1df 100644 --- a/src/components/page-layout/signUpLayout/components/signUpLayout.tsx +++ b/src/components/page-layout/signUpLayout/components/signUpLayout.tsx @@ -67,14 +67,12 @@ interface SignUpInfoForm { } interface SignUpInfo { - body: { - name: string; - nickname: string; - gender: string; - birthDate: Date; - email: string; - password: string; - }; + name: string; + nickname: string; + gender: string; + birthDate: Date; + email: string; + password: string; } interface ErrorResponse { @@ -85,8 +83,9 @@ interface ErrorResponse { export default function SignUpLayout() { const router = useRouter(); - const [clickNumber, setClickNumber] = useState(0); const [isModalOpen, setIsModalOpen] = useState(false); + const [content, setContent] = useState(null); + const { register, handleSubmit, @@ -97,7 +96,7 @@ export default function SignUpLayout() { } = useForm({ resolver: zodResolver(signUpSchema), mode: "onChange" }); const signUp = useMutation({ - mutationFn: ({ body }: SignUpInfo) => postSignUp({ body }), + mutationFn: (content: SignUpInfo) => postSignUp(content), onSuccess: () => { router.push(ROUTE.LOGIN); openToast("success", "회원가입이 완료되었습니다."); @@ -112,21 +111,17 @@ export default function SignUpLayout() { }); const handleSignUpClick = (data: SignUpInfoForm) => { - if (clickNumber === 0) { - setIsModalOpen((prev) => !prev); - setClickNumber(1); - } else { - const body: SignUpInfo["body"] = { - name: data.name, - nickname: data.nickname, - gender: data.gender, - birthDate: data.birthDate, - email: data.email, - password: data.password, - }; + setIsModalOpen((prev) => !prev); + const body: SignUpInfo = { + name: data.name, + nickname: data.nickname, + gender: data.gender, + birthDate: data.birthDate, + email: data.email, + password: data.password, + }; - signUp.mutate({ body }); - } + setContent(body); }; return ( @@ -239,22 +234,34 @@ export default function SignUpLayout() { - {isModalOpen && } + {isModalOpen && } ); } interface ConfirmModalProps { setState: Dispatch>; + content: SignUpInfo; + mutate: (content: SignUpInfo) => void; } -function ConfirmModal({ setState }: ConfirmModalProps) { +function ConfirmModal({ setState, content, mutate }: ConfirmModalProps) { + const handleConfirm = () => { + setState((prev) => !prev); + mutate(content); + }; + return (

한 번 가입시 변경 할 수 없으니 꼭 확인해 주세요.

- +
+ + +
); }