diff --git a/src/apis/Example/artist.ts b/src/apis/Example/artist.ts deleted file mode 100644 index 94fd3fb..0000000 --- a/src/apis/Example/artist.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { instance } from '@/apis/axios'; -import { TGetResponse } from '@/apis/type'; -import { TGetArtistListRequestParams, TGetArtistListResponse } from './type'; - -export const getArtistList = async ({ - page, - keyword, -}: TGetArtistListRequestParams): Promise => { - const response = await instance.get>( - `/api/v1/artist/list?page=${page}&keyword=${keyword}` - ); - return response.data.result; -}; diff --git a/src/apis/Example/type.ts b/src/apis/Example/type.ts deleted file mode 100644 index 194deaf..0000000 --- a/src/apis/Example/type.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { TArtist } from '@/types/artist'; - -export type TGetArtistListResponse = TArtist[]; - -export type TGetArtistListRequestParams = { - page?: number; - keyword?: string; -}; diff --git a/src/apis/artwork-detail/artwork.ts b/src/apis/artworkDetail/artwork.ts similarity index 100% rename from src/apis/artwork-detail/artwork.ts rename to src/apis/artworkDetail/artwork.ts diff --git a/src/apis/artwork-detail/postMySpace.ts b/src/apis/artworkDetail/postMySpace.ts similarity index 100% rename from src/apis/artwork-detail/postMySpace.ts rename to src/apis/artworkDetail/postMySpace.ts diff --git a/src/apis/artwork-detail/type.ts b/src/apis/artworkDetail/type.ts similarity index 100% rename from src/apis/artwork-detail/type.ts rename to src/apis/artworkDetail/type.ts diff --git a/src/apis/artwork-like/like.ts b/src/apis/artworkLike/like.ts similarity index 100% rename from src/apis/artwork-like/like.ts rename to src/apis/artworkLike/like.ts diff --git a/src/apis/artwork-like/type.ts b/src/apis/artworkLike/type.ts similarity index 100% rename from src/apis/artwork-like/type.ts rename to src/apis/artworkLike/type.ts diff --git a/src/apis/auctionRegister/postAuctionRegister.ts b/src/apis/auctionRegister/postAuctionRegister.ts index 9559b5d..9f71537 100644 --- a/src/apis/auctionRegister/postAuctionRegister.ts +++ b/src/apis/auctionRegister/postAuctionRegister.ts @@ -11,6 +11,10 @@ import { TAuctionRegisterFormData } from './type'; export const postAuctionRegister = async ( data: TAuctionRegisterFormData ): Promise> => { - const response = await instance.post('/api/auction/register', data); + const formData = new FormData(); + formData.append('artwork_id', data.artwork_id.toString()); + formData.append('start_price', data.start_price.toString()); + + const response = await instance.post('/api/auction/register', formData); return response.data; }; diff --git a/src/apis/auctionRegister/type.ts b/src/apis/auctionRegister/type.ts index e6779ec..29fc85d 100644 --- a/src/apis/auctionRegister/type.ts +++ b/src/apis/auctionRegister/type.ts @@ -13,6 +13,6 @@ export type TGetAvailableArtworksResponse = { * @author 홍규진 */ export type TAuctionRegisterFormData = { - artwork_id: number | null; - start_price: number | null; + artwork_id: number; + start_price: number; }; diff --git a/src/apis/exhibit-register/getExhibitAvailableArtwork.ts b/src/apis/exhibitRegister/getExhibitAvailableArtwork.ts similarity index 100% rename from src/apis/exhibit-register/getExhibitAvailableArtwork.ts rename to src/apis/exhibitRegister/getExhibitAvailableArtwork.ts diff --git a/src/apis/exhibit-register/getExhibitBackgroundImages.ts b/src/apis/exhibitRegister/getExhibitBackgroundImages.ts similarity index 100% rename from src/apis/exhibit-register/getExhibitBackgroundImages.ts rename to src/apis/exhibitRegister/getExhibitBackgroundImages.ts diff --git a/src/apis/exhibitRegister/postExhibitRegister.ts b/src/apis/exhibitRegister/postExhibitRegister.ts new file mode 100644 index 0000000..c86a19b --- /dev/null +++ b/src/apis/exhibitRegister/postExhibitRegister.ts @@ -0,0 +1,22 @@ +/** + * 전시 등록 API 호출 + * 멀티파트로 제공해야하는 데이터는 다음과 같이 제공해야합니다. + * @author 홍규진 + */ + +import { instance } from '../axios'; +import { TPostExhibitionRegisterFormData } from './types'; + +export const postExhibitionRegister = async ( + data: TPostExhibitionRegisterFormData +) => { + const formData = new FormData(); + formData.append('title', data.title); + formData.append('exhibit_image', data.exhibit_image); + + await instance.post('/api/exhibition', formData, { + headers: { + 'Content-Type': 'multipart/form-data', + }, + }); +}; diff --git a/src/apis/exhibit-register/types.ts b/src/apis/exhibitRegister/types.ts similarity index 70% rename from src/apis/exhibit-register/types.ts rename to src/apis/exhibitRegister/types.ts index f776f57..20f357b 100644 --- a/src/apis/exhibit-register/types.ts +++ b/src/apis/exhibitRegister/types.ts @@ -8,3 +8,8 @@ export type TGetExhibitAvailableArtworksResponse = { title: string; thumbnail_image_url: string; }; + +export type TPostExhibitionRegisterFormData = { + title: string; + exhibit_image: File; +}; diff --git a/src/apis/mypage-author/account.ts b/src/apis/mypageAuthor/account.ts similarity index 100% rename from src/apis/mypage-author/account.ts rename to src/apis/mypageAuthor/account.ts diff --git a/src/apis/mypage-author/author.ts b/src/apis/mypageAuthor/author.ts similarity index 100% rename from src/apis/mypage-author/author.ts rename to src/apis/mypageAuthor/author.ts diff --git a/src/apis/mypage-author/myPage/myPage.ts b/src/apis/mypageAuthor/myPage/myPage.ts similarity index 100% rename from src/apis/mypage-author/myPage/myPage.ts rename to src/apis/mypageAuthor/myPage/myPage.ts diff --git a/src/apis/mypage-author/myPage/type.ts b/src/apis/mypageAuthor/myPage/type.ts similarity index 100% rename from src/apis/mypage-author/myPage/type.ts rename to src/apis/mypageAuthor/myPage/type.ts diff --git a/src/apis/mypage-author/profile.ts b/src/apis/mypageAuthor/profile.ts similarity index 100% rename from src/apis/mypage-author/profile.ts rename to src/apis/mypageAuthor/profile.ts diff --git a/src/apis/mypage-author/type.ts b/src/apis/mypageAuthor/type.ts similarity index 100% rename from src/apis/mypage-author/type.ts rename to src/apis/mypageAuthor/type.ts diff --git a/src/apis/mypage-buyer/artBuyer.ts b/src/apis/mypageBuyer/artBuyer.ts similarity index 54% rename from src/apis/mypage-buyer/artBuyer.ts rename to src/apis/mypageBuyer/artBuyer.ts index 29cc50b..f0c8603 100644 --- a/src/apis/mypage-buyer/artBuyer.ts +++ b/src/apis/mypageBuyer/artBuyer.ts @@ -6,20 +6,10 @@ import { TUpdateUserInfo } from './type'; * 사용자 정보 수정 API 호출 함수 * @param userInfo - 수정할 사용자 정보 (nickname, address, birth) * @returns API 응답(TGetResponse) - * @author 노찬영 + * @author 노찬영, 홍규진 */ - export const updateUserInfo = async ( userInfo: TUpdateUserInfo -): Promise> => { - try { - const response = await instance.patch>( - `/api/user/update`, - userInfo - ); - return response.data; - } catch (error) { - console.error('사용자 정보 수정 실패:', error); - throw error; - } +): Promise => { + await instance.patch>(`/api/user/update`, userInfo); }; diff --git a/src/apis/mypage-buyer/artWork.ts b/src/apis/mypageBuyer/artWork.ts similarity index 100% rename from src/apis/mypage-buyer/artWork.ts rename to src/apis/mypageBuyer/artWork.ts diff --git a/src/apis/mypage-buyer/myPage/myPage.ts b/src/apis/mypageBuyer/myPage/myPage.ts similarity index 100% rename from src/apis/mypage-buyer/myPage/myPage.ts rename to src/apis/mypageBuyer/myPage/myPage.ts diff --git a/src/apis/mypage-buyer/myPage/type.ts b/src/apis/mypageBuyer/myPage/type.ts similarity index 100% rename from src/apis/mypage-buyer/myPage/type.ts rename to src/apis/mypageBuyer/myPage/type.ts diff --git a/src/apis/mypage-buyer/type.ts b/src/apis/mypageBuyer/type.ts similarity index 100% rename from src/apis/mypage-buyer/type.ts rename to src/apis/mypageBuyer/type.ts diff --git a/src/apis/register/oAuthLogin.ts b/src/apis/register/oAuthLogin.ts index dd2a3ac..1db6a7b 100644 --- a/src/apis/register/oAuthLogin.ts +++ b/src/apis/register/oAuthLogin.ts @@ -1,6 +1,13 @@ import { instance } from '../axios'; import { TGetResponse } from '../type'; import { TOauthLoginWithCode } from './type'; + +/** + * 소셜 로그인 완료 응답 데이터 타입 + * isComplete: 회원가입 완료 여부 + * token: 인가 토큰 + * @author 홍규진 + */ type TAuthResponse = { isComplete: boolean; token: string; diff --git a/src/apis/register/postAuthRegister.ts b/src/apis/register/postAuthRegister.ts index d539100..51cdd51 100644 --- a/src/apis/register/postAuthRegister.ts +++ b/src/apis/register/postAuthRegister.ts @@ -2,6 +2,12 @@ import { instance } from '@/apis/axios'; import { TGetResponse } from '@/apis/type'; import { TRegisterFormData, TAuthResponse } from './type.ts'; +/** + * 회원가입 완료 API 호출 + * @param authData 회원가입 완료 폼 데이터 + * @returns 회원가입 완료 응답 데이터 + * @author 홍규진 + */ export const postAuthRegister = async ( authData: TRegisterFormData ): Promise => { diff --git a/src/apis/register/type.ts b/src/apis/register/type.ts index a0a7ca3..d342a5d 100644 --- a/src/apis/register/type.ts +++ b/src/apis/register/type.ts @@ -1,3 +1,7 @@ +/** + * 회원가입 폼 데이터 타입 + * @author 홍규진 + */ export type TRegisterFormData = { role: 'BUYER' | 'AUTHOR'; // 사용자 유형 name: string; // 이름 @@ -5,11 +9,19 @@ export type TRegisterFormData = { nickname: string; // 닉네임 }; +/** + * 소셜 로그인 코드 타입 + * @author 홍규진 + */ export type TOauthLoginWithCode = { code: string; social_type: string; }; +/** + * 회원가입 완료 응답 데이터 타입 + * @author 홍규진 + */ export type TAuthResponse = { isComplete: boolean; token: string; diff --git a/src/components/common/Error/DefaultErrorFallbackUI/index.tsx b/src/components/common/Error/DefaultErrorFallbackUI/index.tsx index 3f942b8..5c10cdc 100644 --- a/src/components/common/Error/DefaultErrorFallbackUI/index.tsx +++ b/src/components/common/Error/DefaultErrorFallbackUI/index.tsx @@ -24,10 +24,9 @@ export default function DefaultErrorFallbackUI({ ⚠️ 잠시 문제가 발생했어요 + {error.name} {error.message} - - 다시 시도하기 - + 다시 시도하기 ); diff --git a/src/components/common/PageLayout/index.tsx b/src/components/common/PageLayout/index.tsx index b5fa3f8..f98e03c 100644 --- a/src/components/common/PageLayout/index.tsx +++ b/src/components/common/PageLayout/index.tsx @@ -29,7 +29,7 @@ export const PageLayout = ({ children }: PageLayoutProps) => { } function handleLinkMypageFn() { - navigate('/mypage/art-buyer'); + navigate('/mypage/buyer'); } return ( diff --git a/src/constants/mutationKey.ts b/src/constants/mutationKey.ts index 5cdc8d3..49e6558 100644 --- a/src/constants/mutationKey.ts +++ b/src/constants/mutationKey.ts @@ -1,17 +1,41 @@ import { postAuthRegister } from '@/apis/register/postAuthRegister'; import { postAuctionRegister } from '@/apis/auctionRegister/postAuctionRegister'; import { postArtworkRegister } from '@/apis/artworkRegister/postArtworkRegister'; -import { getAvailableArtworksQuery } from '@/constants/queryKeys'; +import { + getArtworkDetailQuery, + getAuctionListQuery, + getBuyerMypageQuery, + getExhibitionListQuery, +} from '@/constants/queryKeys'; import { postAuctionBid } from '@/apis/auction/postAuctionBid'; -import { toggleArtworkLike } from '@/apis/artwork-like/like'; -import { postMySpace } from '@/apis/artwork-detail/postMySpace'; +import { postAuctionLike } from '@/apis/auction/postAuctionLike'; +import { postAuctionUnlike } from '@/apis/auction/postAuctionUnlike'; +import { toggleArtworkLike } from '@/apis/artworkLike/like'; +import { postMySpace } from '@/apis/artworkDetail/postMySpace'; +import { getMainDataQuery } from '@/constants/queryKeys'; +import { requestKakaoPay } from '@/apis/kakaoPay/paymentPreparation'; +import { approveKakaoPay } from '@/apis/kakaoPay/paymentAuthorization'; +import { updateUserInfo } from '@/apis/mypageBuyer/artBuyer'; +import { TUpdateUserInfo } from '@/apis/mypageBuyer/type'; +import { postExhibitionRegister } from '@/apis/exhibitRegister/postExhibitRegister'; +import { TAuctionRegisterFormData } from '@/apis/auctionRegister/type'; +/** + * 뮤테이션 키 관리를 위한 상수 정의 - 상수값을 사용해 mutation 성공 여부, 실패등에 따른 값 선언을 위한 유지보수성을 높이기 위해 사용합니다. (param은 넣지 않습니다. 하위 함수에서 넣어줍니다.) + * @mutationKey - 뮤테이션 함수 구분을 위한 키 값입니다. + * @successMutationKey - 뮤테이션 성공 후 호출될 쿼리 키 값 (쿼리 키 무효화를 통해 refetch를 위해 사용할 값입니다.) + * @mutationFn - 뮤테이션 함수입니다. + * @author 홍규진 + */ +/*-----------------------------------------------------------*/ + /** * 인증 회원가입 뮤테이션 * @author 홍규진 * */ export const postAuthRegisterMutation = () => { return { - mutationKey: ['auth'], + mutationKey: ['postAuthRegister'], + successMutationKey: [...getMainDataQuery().queryKey], mutationFn: postAuthRegister, }; }; @@ -22,72 +46,137 @@ export const postAuthRegisterMutation = () => { * */ export const postAuctionRegisterMutation = () => { return { - mutationKey: [...getAvailableArtworksQuery().queryKey], - mutationFn: postAuctionRegister, + mutationKey: ['postAuctionRegister'], + successMutationKey: [...getAuctionListQuery('').queryKey], + mutationFn: (data: TAuctionRegisterFormData) => postAuctionRegister(data), + }; +}; +/** + * 전시 등록 뮤테이션 + * 전시 등록후 전시 목록 조회 쿼리 키 무효화 + * @author 홍규진 + * */ +export const postExhibitionRegisterMutation = () => { + return { + mutationKey: ['postExhibitionRegister'], + successMutationKey: [...getExhibitionListQuery('').queryKey], + mutationFn: postExhibitionRegister, }; }; /** * 작품 등록 뮤테이션 - * TODO-[홍규진] 작품 등록 후, 홈 화면 내 작품 쿼리 키 지정시 해당 키로 수정 필요 + *작품 등록 후, 메인 화면 내 작품 쿼리 키 무효화 * @author 홍규진 * */ export const postArtworkRegisterMutation = () => { return { - mutationKey: ['artwork'], + mutationKey: ['postArtworkRegister'], + successMutationKey: [...getMainDataQuery().queryKey], mutationFn: postArtworkRegister, }; }; /** * 경매 입찰 뮤테이션 - * @author 이하늘 + * 경매 입찰 후 경매 목록 조회 쿼리 키 무효화 + * @author 이하늘, 홍규진 * */ export const postAuctionBidMutation = () => { return { - mutationKey: ['auctionBid'], + mutationKey: ['postAuctionBid'], + successMutationKey: [...getAuctionListQuery('').queryKey], mutationFn: postAuctionBid, }; }; -/* +/** * 작품 좋아요 뮤테이션 - * @author 김서윤 - */ + * 작품 좋아요 후 작품 상세 조회 쿼리 키 무효화 + * @author 김서윤, 홍규진 + * */ export const toggleArtworkLikeMutation = (artworkId: number) => { return { - mutationKey: ['artworkDetail', artworkId], + mutationKey: ['toggleArtworkLike'], + successMutationKey: [...getArtworkDetailQuery(artworkId).queryKey], mutationFn: () => toggleArtworkLike(artworkId), }; }; +/** + * 카카오페이 결제 준비 뮤테이션 + * @author 노찬영, 홍규진 + * */ +export const requestKakaoPayMutation = () => { + return { + mutationKey: ['requestKakaoPay'], + successMutationKey: [...getAuctionListQuery('').queryKey], + mutationFn: (paymentId: number) => requestKakaoPay(paymentId), + }; +}; + +/** + * 카카오페이 결제 승인 뮤테이션 + * 카카오페이 결제 승인 후 경매 목록 조회 쿼리 키 무효화 + * @author 노찬영, 홍규진 + */ +export const approveKakaoPayMutation = () => { + return { + mutationKey: ['approveKakaoPay'], + successMutationKey: [...getAuctionListQuery('').queryKey], + mutationFn: (paymentId: number, pgToken: string) => + approveKakaoPay(paymentId, pgToken), + }; +}; + +/** + * 사용자 정보 수정 뮤테이션 + * 사용자 정보 수정 후 사용자 마이페이지 조회 쿼리 키 무효화 + * @author 노찬영, 홍규진 + */ +export const updateUserInfoMutation = () => { + return { + mutationKey: ['updateUserInfo'], + successMutationKey: [...getBuyerMypageQuery().queryKey], + mutationFn: (userInfo: TUpdateUserInfo) => updateUserInfo(userInfo), + }; +}; + /** * 내 공간 등록 뮤테이션 - * @author 김서윤 + * 내 공간 등록 후 사용자 마이페이지 조회 쿼리 키 무효화 + * @author 김서윤, 홍규진 * */ export const postMySpaceMutation = () => { return { - mutationKey: ['new_userspace'], + mutationKey: ['postMySpace'], + successMutationKey: [...getBuyerMypageQuery().queryKey], mutationFn: postMySpace, }; }; /** * 경매 좋아요 뮤테이션 - * @author 이하늘 + * 경매 좋아요 후 경매 목록 조회 쿼리 키 무효화 + * @author 이하늘, 홍규진 * */ export const postAuctionLikeMutation = () => { return { - mutationKey: ['auctionLike'], + mutationKey: ['postAuctionLike'], + successMutationKey: [...getAuctionListQuery('').queryKey], + mutationFn: postAuctionLike, }; }; /** * 경매 좋아요 취소 뮤테이션 - * @author 이하늘 + * 경매 좋아요 취소 후 경매 목록 조회 쿼리 키 무효화 + * @author 이하늘, 홍규진 * */ export const postAuctionUnlikeMutation = () => { return { - mutationKey: ['auctionUnlike'], + mutationKey: ['postAuctionUnlike'], + successMutationKey: [...getAuctionListQuery('').queryKey], + mutationFn: postAuctionUnlike, }; }; diff --git a/src/constants/queryKeys.ts b/src/constants/queryKeys.ts index 0e5edf4..0e5fb60 100644 --- a/src/constants/queryKeys.ts +++ b/src/constants/queryKeys.ts @@ -1,47 +1,26 @@ import { getAuctionDetail } from '@/apis/auction/getAuctionDetail'; import { getAuctionLists } from '@/apis/auction/getAuctionList'; -import { getPurchasedArtworks } from '@/apis/mypage-buyer/artWork'; +import { getPurchasedArtworks } from '@/apis/mypageBuyer/artWork'; import { getAuthorArtworksExhibitions, getAuthorProfile, -} from '@/apis/mypage-author/author'; -import { AuthorProfileType } from '@/apis/mypage-author/type'; +} from '@/apis/mypageAuthor/author'; +import { AuthorProfileType } from '@/apis/mypageAuthor/type'; import { getAvailableArtworks } from '@/apis/auctionRegister/getAvailableArtworks'; import { getAuthorDetail } from '@/apis/author/getAuthorDetail'; import { getAuthorLists } from '@/apis/author/getAuthorLists'; -import { getArtistList } from '@/apis/Example/artist'; -import { TGetArtistListRequestParams } from '@/apis/Example/type'; import { getMainData } from '@/apis/main/main'; -import { getBuyerMypage } from '@/apis/mypage-buyer/myPage/myPage'; -import { getAuthorMypage } from '@/apis/mypage-author/myPage/myPage'; +import { getBuyerMypage } from '@/apis/mypageBuyer/myPage/myPage'; +import { getAuthorMypage } from '@/apis/mypageAuthor/myPage/myPage'; import { getExhibitions } from '@/apis/exhibition/getExhibitionList'; import { getExhibitionDetail } from '@/apis/exhibition/getExhibitionDetail'; -import { getExhibitAvailableArtwork } from '@/apis/exhibit-register/getExhibitAvailableArtwork'; -import { getExhibitBackgroundImages } from '@/apis/exhibit-register/getExhibitBackgroundImages'; - -/** - * 아티스트들의 정보를 받아오고, 관리하기 위한 쿼리 키로 함수와 묶어서 사용합니다. - * 단, pagenation 이 필요한 경우엔 다음과 같이 page 와 keyword 를 이용해 작성합니다. 이 때, queryKey 지정 여부에 따라서 데이터를 다시 못 받아오는 경우도 있으니, 검색이 필요한 경우엔 keyword 와 연관되게 키를 지정 후 데이터를 가져옵니다. - * @author 홍규진 - * */ - -export const getArtistListQuery = () => { - return { - queryKey: ['artistList'], - queryFn: ({ page, keyword }: TGetArtistListRequestParams) => - getArtistList({ page, keyword }), - }; -}; - -/** - * 마이페이지 조회를 위한 쿼리 키 반환 함수 - * @returns 쿼리 키 배열 ['Mypage']을 반환하여 캐시를 사용자별로 관리할 수 있도록 설정 - * @author 노찬영 - */ -export const getMypageQueryKey = (role: 'author' | 'buyer') => ['Mypage', role]; - +import { getExhibitAvailableArtwork } from '@/apis/exhibitRegister/getExhibitAvailableArtwork'; +import { getExhibitBackgroundImages } from '@/apis/exhibitRegister/getExhibitBackgroundImages'; +import { getArtworkDetail } from '@/apis/artworkDetail/artwork'; +import { getArtworks } from '@/apis/artwork/artwork'; +import { saveAuthorBankInfo } from '@/apis/mypageAuthor/account'; /** * 작품 구매자 마이페이지 조회 API를 위한 React Query 설정 함수 * @returns queryKey와 queryFn을 포함한 객체를 반환하여 React Query에서 사용 가능하도록 설정 @@ -49,7 +28,7 @@ export const getMypageQueryKey = (role: 'author' | 'buyer') => ['Mypage', role]; */ export const getBuyerMypageQuery = () => { return { - queryKey: getMypageQueryKey('buyer'), + queryKey: ['Mypage', 'buyer'], queryFn: () => getBuyerMypage(), // 작품 구매자 마이페이지 데이터를 조회하는 함수 }; }; @@ -61,7 +40,7 @@ export const getBuyerMypageQuery = () => { */ export const getAuthorMypageQuery = () => { return { - queryKey: getMypageQueryKey('author'), + queryKey: ['Mypage', 'author'], queryFn: () => getAuthorMypage(), // 작가 마이페이지 데이터를 조회하는 함수 }; }; @@ -101,14 +80,6 @@ export const getAuthorArtworksExhibitionsQuery = () => { }; }; -/** - * 작품 구매자 계정 정보 수정 쿼리 키 함수 - * @returns ['updateUserInfo'] 형태의 배열 반환 - * @example - queryClient.invalidateQueries(getUpdateUserInfoQueryKey()); - * @author 노찬영 - */ -export const getUpdateUserInfoQueryKey = () => ['updateUserInfo']; - /** * 작가 계정 정보 수정 쿼리 키 함수 * @returns ['updateAuthorInfo'] 형태의 배열 반환 @@ -133,6 +104,21 @@ export const getUpdateAuthorProfileQueryKey = () => ['updateAuthorProfile']; * @author 노찬영 */ +/** + * 작가 은행 정보 수정 쿼리 + * @param type + * @returns + * @author 홍규진 + */ +export const saveAuthorBankInfoMutation = () => { + return { + mutationKey: ['saveAuthorBankInfo'], + mutationFn: saveAuthorBankInfo, + }; +}; + + + export const getAuthorProfileQuery = (type: AuthorProfileType) => { return { queryKey: ['authorProfile'], @@ -272,3 +258,33 @@ export const getExhibitAvailableArtworkQuery = () => { queryFn: getExhibitAvailableArtwork, }; }; + +/** + * 작품 상세 조회 쿼리 + * @author 홍규진 + * */ +export const getArtworkDetailQuery = (artworkId: number) => { + return { + queryKey: ['artworkDetail', artworkId], + queryFn: () => getArtworkDetail(artworkId), + }; +}; + +/** + * 작품 리스트 조회 쿼리 + * @author 홍규진 + * */ +export const getArtworkListQuery = ( + page: number, + pageSize: number, + themes: string[], + sizes: string[], + forms: string[], + sortingKey?: 'latest' | 'popular' +) => { + return { + queryKey: ['artworkList', page, pageSize, themes, sizes, forms, sortingKey], + queryFn: () => + getArtworks(page, pageSize, themes, sizes, forms, sortingKey), + }; +}; diff --git a/src/hooks/apis/useGetArtistList.ts b/src/hooks/apis/useGetArtistList.ts deleted file mode 100644 index 706ae1d..0000000 --- a/src/hooks/apis/useGetArtistList.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { - TGetArtistListRequestParams, - TGetArtistListResponse, -} from '@apis/Example/type.ts'; -import { getArtistListQuery } from '@constants/queryKeys.ts'; -import { useSuspenseQuery } from '@tanstack/react-query'; -import { toast } from 'sonner'; -import { getArtistList } from '@apis/Example/artist.ts'; - -export const useGetArtistList = ({ - page, - keyword, -}: TGetArtistListRequestParams) => { - const { - data: artistListData, - isLoading, - error, - } = useSuspenseQuery({ - queryKey: getArtistListQuery().queryKey, - queryFn: () => getArtistList({ page, keyword }), - staleTime: 1000 * 60 * 60, // 1시간 - gcTime: 1000 * 60 * 40, // 40분 - }); - - if (error) { - toast.error(error.message); - } - - return { artistListData, isLoading, error }; -}; diff --git a/src/pages/artBuyerPage/hooks/useKakaoPay.ts b/src/pages/artBuyerPage/hooks/useKakaoPay.ts deleted file mode 100644 index b1f2695..0000000 --- a/src/pages/artBuyerPage/hooks/useKakaoPay.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { useMutation } from '@tanstack/react-query'; -import { requestKakaoPay } from '@/apis/kakaoPay/paymentPreparation'; -import { approveKakaoPay } from '@/apis/kakaoPay/paymentAuthorization'; - -/** - * 카카오페이 결제 Hook - * @returns 카카오페이 결제 관련 함수 및 상태값 - * @author 노찬영 - */ - -export const useKakaoPay = () => { - // 결제 준비 (결제 URL 요청) - const initiatePaymentMutation = useMutation({ - mutationKey: ['requestKakaoPay'], - mutationFn: requestKakaoPay, - onSuccess: (result) => { - console.log('결제 준비 성공:', result); - window.location.href = result.next_redirect_pc_url; // PC 결제창으로 이동 - }, - onError: (error) => { - console.error('결제 준비 실패:', error); - }, - }); - - // 결제 승인 (pgToken을 받아 결제 승인 요청) - const confirmPaymentMutation = useMutation({ - mutationKey: ['approveKakaoPay'], - mutationFn: ({ - paymentId, - pgToken, - }: { - paymentId: number; - pgToken: string; - }) => approveKakaoPay(paymentId, pgToken), - onSuccess: (approvedPaymentId) => { - console.log(`결제 승인 완료! Payment ID: ${approvedPaymentId}`); - alert( - `결제가 성공적으로 완료되었습니다. Payment ID: ${approvedPaymentId}` - ); - }, - onError: (error) => { - console.error('결제 승인 실패:', error); - alert('결제 승인 중 오류가 발생했습니다.'); - }, - }); - - return { - initiatePayment: initiatePaymentMutation.mutate, - confirmPayment: confirmPaymentMutation.mutate, - }; -}; diff --git a/src/pages/artwork-detail/components/MySpaceModal/index.tsx b/src/pages/artwork-detail/components/MySpaceModal/index.tsx index d32ca5d..664011d 100644 --- a/src/pages/artwork-detail/components/MySpaceModal/index.tsx +++ b/src/pages/artwork-detail/components/MySpaceModal/index.tsx @@ -22,7 +22,7 @@ import { } from './index.style.ts'; import { Text } from '@/styles/text'; import useMySpaceForm from '@/pages/artwork-detail/hooks/useMySpaceForm.ts'; -import { TMySpaceFormData } from '@/apis/artwork-detail/type'; +import { TMySpaceFormData } from '@/apis/artworkDetail/type.ts'; import Close from '@/assets/svg/icon-close.svg'; import Upload from '@/assets/svg/space-register.svg'; diff --git a/src/pages/artwork-detail/hooks/useGetArtworkDetail.ts b/src/pages/artwork-detail/hooks/useGetArtworkDetail.ts index 2618e6f..e4cf7e4 100644 --- a/src/pages/artwork-detail/hooks/useGetArtworkDetail.ts +++ b/src/pages/artwork-detail/hooks/useGetArtworkDetail.ts @@ -1,12 +1,12 @@ import { useSuspenseQuery } from '@tanstack/react-query'; -import { getArtworkDetail } from '@/apis/artwork-detail/artwork'; -import { TArtworkDetailResult } from '@/apis/artwork-detail/type'; - +import { TArtworkDetailResult } from '@/apis/artworkDetail/type'; +import { getArtworkDetailQuery } from '@/constants/queryKeys'; +import { handleError } from '@/utils/handleError'; /** * 특정 작품의 상세 정보를 가져오는 React Query 커스텀 훅 * @param artworkId 작품 ID * @returns {object} artworkData, isLoading, error 상태 반환 - * @author 김서윤 + * @author 김서윤, 홍규진 */ export const useGetArtworkDetail = (artworkId: number) => { const { @@ -14,11 +14,15 @@ export const useGetArtworkDetail = (artworkId: number) => { isLoading, error, } = useSuspenseQuery({ - queryKey: ['artworkDetail', artworkId], - queryFn: () => getArtworkDetail(artworkId), + queryKey: [...getArtworkDetailQuery(artworkId).queryKey], + queryFn: getArtworkDetailQuery(artworkId).queryFn, staleTime: 1000 * 60 * 30, // 30분 gcTime: 1000 * 60 * 15, // 15분 }); + if (error) { + handleError(error); + } + return { artworkData, isLoading, error }; }; diff --git a/src/pages/artwork-detail/hooks/useMySpaceForm.ts b/src/pages/artwork-detail/hooks/useMySpaceForm.ts index 8009811..8687ef4 100644 --- a/src/pages/artwork-detail/hooks/useMySpaceForm.ts +++ b/src/pages/artwork-detail/hooks/useMySpaceForm.ts @@ -1,9 +1,11 @@ import { useMutation, useQueryClient } from '@tanstack/react-query'; import { postMySpaceMutation } from '@/constants/mutationKey'; -import { TMySpaceFormData } from '@/apis/artwork-detail/type'; +import { TMySpaceFormData } from '@/apis/artworkDetail/type'; import { toast } from 'sonner'; import { useState } from 'react'; import { getAvailableArtworksQuery } from '@/constants/queryKeys'; +import { handleError } from '@/utils/handleError'; + const useMySpaceForm = () => { const queryClient = useQueryClient(); const [formData, setFormData] = useState({ @@ -39,12 +41,12 @@ const useMySpaceForm = () => { onSuccess: async () => { toast.success('공간 등록이 성공적으로 완료되었습니다.'); queryClient.invalidateQueries({ - queryKey: postMySpaceMutation().mutationKey, + queryKey: postMySpaceMutation().successMutationKey, }); await getAvailableArtworksQuery().queryFn(); }, onError: (error: Error) => { - toast.error(`공간 등록 실패: ${error.message}`); + handleError(error); }, }); diff --git a/src/pages/artwork-detail/hooks/useToggleArtworkLike.ts b/src/pages/artwork-detail/hooks/useToggleArtworkLike.ts index 83e303b..464fd2b 100644 --- a/src/pages/artwork-detail/hooks/useToggleArtworkLike.ts +++ b/src/pages/artwork-detail/hooks/useToggleArtworkLike.ts @@ -1,6 +1,6 @@ import { useMutation, useQueryClient } from '@tanstack/react-query'; -import { toggleArtworkLike } from '@/apis/artwork-like/like'; -import { TToggleLikeResult } from '@/apis/artwork-like/type'; +import { toggleArtworkLike } from '@/apis/artworkLike/like'; +import { TToggleLikeResult } from '@/apis/artworkLike/type'; import { toast } from 'sonner'; import { toggleArtworkLikeMutation } from '@/constants/mutationKey'; @@ -25,10 +25,12 @@ export const useToggleArtworkLike = () => { }, onSuccess: (data, { artworkId }) => { toast.success(data.message); - queryClient.invalidateQueries({ queryKey: ['artworkDetail', artworkId] }); + queryClient.invalidateQueries({ + queryKey: [...toggleArtworkLikeMutation(artworkId).mutationKey], + }); }, - onError: () => { - toast.error('좋아요를 변경하는 데 실패했습니다.'); + onError: (error: Error) => { + toast.error(`좋아요 변경에 실패했습니다. ${error.message}`); }, }); diff --git a/src/pages/artwork-register/hooks/useArtworkRegisterForm.ts b/src/pages/artwork-register/hooks/useArtworkRegisterForm.ts index 36a36e1..370e562 100644 --- a/src/pages/artwork-register/hooks/useArtworkRegisterForm.ts +++ b/src/pages/artwork-register/hooks/useArtworkRegisterForm.ts @@ -3,11 +3,31 @@ import { postArtworkRegisterMutation } from '@/constants/mutationKey'; import { TArtworkRegisterFormData } from '@/apis/artworkRegister/type'; import { toast } from 'sonner'; import { useState } from 'react'; -import { getAvailableArtworksQuery } from '@/constants/queryKeys'; import { useNavigate } from 'react-router-dom'; const useArtworkRegisterForm = () => { const queryClient = useQueryClient(); const navigate = useNavigate(); + + /** + * 작품 등록 뮤테이션 + * @author 홍규진 + */ + const mutation = useMutation({ + mutationKey: postArtworkRegisterMutation().mutationKey, + mutationFn: (data: TArtworkRegisterFormData) => + postArtworkRegisterMutation().mutationFn(data), + onSuccess: async () => { + toast.success('작품 등록이 성공적으로 완료되었습니다.'); + queryClient.invalidateQueries({ + queryKey: postArtworkRegisterMutation().successMutationKey, + }); + navigate('/'); + }, + onError: (error: Error) => { + toast.error(`작품 등록 실패: ${error.message}`); + }, + }); + const [formData, setFormData] = useState({ images: [], theme: '', @@ -61,27 +81,6 @@ const useArtworkRegisterForm = () => { return true; }; - /** - * 작품 등록 뮤테이션 - * @author 홍규진 - */ - const mutation = useMutation({ - mutationKey: postArtworkRegisterMutation().mutationKey, - mutationFn: (data: TArtworkRegisterFormData) => - postArtworkRegisterMutation().mutationFn(data), - onSuccess: async () => { - toast.success('작품 등록이 성공적으로 완료되었습니다.'); - queryClient.invalidateQueries({ - queryKey: postArtworkRegisterMutation().mutationKey, - }); - await getAvailableArtworksQuery().queryFn(); - navigate('/'); - }, - onError: (error: Error) => { - toast.error(`작품 등록 실패: ${error.message}`); - }, - }); - /** * 작품 등록 폼 제출 함수 * 비어있는 것도 알려주기 diff --git a/src/pages/artwork/hooks/useGetArtworks.ts b/src/pages/artwork/hooks/useGetArtworks.ts index 8889afc..296b629 100644 --- a/src/pages/artwork/hooks/useGetArtworks.ts +++ b/src/pages/artwork/hooks/useGetArtworks.ts @@ -1,10 +1,10 @@ import { useSuspenseQuery } from '@tanstack/react-query'; -import { getArtworks } from '@/apis/artwork/artwork'; import { TArtWorkResult } from '@/apis/artwork/type'; - +import { getArtworkListQuery } from '@/constants/queryKeys'; +import { handleError } from '@/utils/handleError'; /** * 특정 작품의 상세 정보를 가져오는 React Query 커스텀 훅 - * @author 김서윤 + * @author 김서윤, 홍규진 */ export const useGetArtworks = ( page: number, @@ -26,12 +26,29 @@ export const useGetArtworks = ( isLoading, error, } = useSuspenseQuery({ - queryKey: ['artworks', page, pageSize, themes, sizes, forms, sortingKey], - queryFn: () => - getArtworks(page, pageSize, themes, sizes, forms, sortingKey), + queryKey: getArtworkListQuery( + page, + pageSize, + themes, + sizes, + forms, + sortingKey + ).queryKey, + queryFn: getArtworkListQuery( + page, + pageSize, + themes, + sizes, + forms, + sortingKey + ).queryFn, staleTime: 1000 * 60 * 30, gcTime: 1000 * 60 * 15, }); + if (error) { + handleError(error); + } + return { artworkData, isLoading, error }; }; diff --git a/src/pages/auction-detail/hooks/useGetAuctionDtail.ts b/src/pages/auction-detail/hooks/useGetAuctionDtail.ts index 5351853..b3ed126 100644 --- a/src/pages/auction-detail/hooks/useGetAuctionDtail.ts +++ b/src/pages/auction-detail/hooks/useGetAuctionDtail.ts @@ -1,9 +1,7 @@ import { getAuctionDetailQuery } from '@/constants/queryKeys'; import { useSuspenseQuery } from '@tanstack/react-query'; -import { toast } from 'sonner'; -import { AxiosError } from 'axios'; import { TGetAuctionDetailResponse } from '@/apis/auction/type'; - +import { handleError } from '@/utils/handleError'; /** * 경매 상세 정보를 가져오는 커스텀 훅 * React Query의 useSuspenseQuery를 활용해 데이터를 가져오고, 오류 발생 시 toast 알림을 띄움 @@ -11,7 +9,7 @@ import { TGetAuctionDetailResponse } from '@/apis/auction/type'; * @param {number} auctionId - 경매 ID * @returns {object} data, error 상태 반환 * @example const { data } = useGetAuctionDetail(145); - * @author 이하늘 + * @author 이하늘, 홍규진 **/ export const useGetAuctionDetail = (auctionId: number) => { const { data, isLoading, error } = @@ -23,11 +21,7 @@ export const useGetAuctionDetail = (auctionId: number) => { }); if (error) { - const axiosError = error as AxiosError<{ message?: string }>; - const errorMessage = - axiosError.response?.data?.message || - '경매 상세 정보를 불러오는데 실패했습니다.'; - toast.error(errorMessage); + handleError(error); } return { data, isLoading, error }; diff --git a/src/pages/auction-detail/hooks/usePostAuctionBid.ts b/src/pages/auction-detail/hooks/usePostAuctionBid.ts index 8a0db97..09da3b1 100644 --- a/src/pages/auction-detail/hooks/usePostAuctionBid.ts +++ b/src/pages/auction-detail/hooks/usePostAuctionBid.ts @@ -4,10 +4,10 @@ import { } from '@/apis/auction/type'; import { postAuctionBidMutation } from '@/constants/mutationKey'; import { useMutation, useQueryClient } from '@tanstack/react-query'; -import axios from 'axios'; import { useState } from 'react'; import { toast } from 'sonner'; +//TODO-[규진] 폼데이터 및 뮤테이션 관심사 분리 필요 export const usePostAuctionBid = () => { const [formData, setFormData] = useState({ auction_id: null, @@ -25,22 +25,11 @@ export const usePostAuctionBid = () => { onSuccess: (data: TPostAuctionBidResponse) => { toast.success(`입찰 성공: ${data.message}`); queryClient.invalidateQueries({ - queryKey: ['auctionDetails', data.current_price], + queryKey: postAuctionBidMutation().mutationKey, }); }, onError: (error: Error) => { - if (axios.isAxiosError(error)) { - // AxiosError인 경우 - if (error.response) { - // 서버 응답에서 message를 추출하여 사용 - const message = error.response.data.message; - toast.error(`입찰 실패: ${message}`); // 사용자에게 오류 메시지 표시 - } else { - toast.error('서버 응답을 받을 수 없습니다.'); - } - } else { - toast.error('입찰에 실패했습니다. 다시 시도해주세요.'); - } + toast.error(`입찰 실패: ${error.message}`); }, }); @@ -70,10 +59,9 @@ export const usePostAuctionBid = () => { if (validateForm(data)) { try { await mutation.mutateAsync(data); // 입찰 요청 - console.log('입찰 성공1'); + toast.success('입찰 성공'); } catch (error) { - console.error('입찰 실패', error); - alert('입찰에 실패했습니다. 다시 시도해주세요.'); + console.log(error); } } else { console.log('유효성 검사 실패'); diff --git a/src/pages/auction-detail/index.tsx b/src/pages/auction-detail/index.tsx index 05fc465..f866f68 100644 --- a/src/pages/auction-detail/index.tsx +++ b/src/pages/auction-detail/index.tsx @@ -77,13 +77,6 @@ export const AuctionDetail = () => { } }, [currentPrice]); - // 입찰 실패 시 오류 메시지 표시 - // useEffect(() => { - // if (isError && bidError?.response?.data?.message) { - // toast.error(`입찰 실패: ${bidError.response.data.message}`); - // } - // }, [isError, bidError]); - if (!auctionId) { return ( diff --git a/src/pages/auction-register/hooks/useAuctionRegisterForm.ts b/src/pages/auction-register/hooks/useAuctionRegisterForm.ts index ecfdf78..5b77fdd 100644 --- a/src/pages/auction-register/hooks/useAuctionRegisterForm.ts +++ b/src/pages/auction-register/hooks/useAuctionRegisterForm.ts @@ -3,10 +3,12 @@ import { TAuctionRegisterFormData } from '@/apis/auctionRegister/type'; import { toast } from 'sonner'; import { useState } from 'react'; import { postAuctionRegisterMutation } from '@/constants/mutationKey'; +import { useNavigate } from 'react-router-dom'; const useAuctionRegisterForm = () => { + const navigate = useNavigate(); const [formData, setFormData] = useState({ - artwork_id: null, - start_price: null, + artwork_id: 0, + start_price: 0, }); const queryClient = useQueryClient(); @@ -21,8 +23,9 @@ const useAuctionRegisterForm = () => { onSuccess: () => { toast.success('경매 등록이 성공적으로 완료되었습니다.'); queryClient.invalidateQueries({ - queryKey: postAuctionRegisterMutation().mutationKey, + queryKey: postAuctionRegisterMutation().successMutationKey, }); + navigate('/auction'); }, onError: (error: Error) => { toast.error(`경매 등록 실패: ${error.message}`); @@ -35,12 +38,12 @@ const useAuctionRegisterForm = () => { * @author 홍규진 */ const validateForm = (data: TAuctionRegisterFormData) => { - if (data.artwork_id === null) { + if (data.artwork_id === 0) { toast.error('작품을 선택해주세요.'); return false; } - if (data.start_price === null) { - toast.error('시작 금액을 입력해주세요.'); + if (data.start_price === 0) { + toast.error('시작 금액을 입력해주세요. 0원은 입력할 수 없습니다.'); return false; } return true; diff --git a/src/pages/auction-register/hooks/useGetAvailableArtwork.ts b/src/pages/auction-register/hooks/useGetAvailableArtwork.ts index d2d4ebf..77c4196 100644 --- a/src/pages/auction-register/hooks/useGetAvailableArtwork.ts +++ b/src/pages/auction-register/hooks/useGetAvailableArtwork.ts @@ -1,7 +1,7 @@ import { TGetAvailableArtworksResponse } from '@/apis/auctionRegister/type'; import { getAvailableArtworksQuery } from '@/constants/queryKeys'; -import { useQuery } from '@tanstack/react-query'; - +import { useSuspenseQuery } from '@tanstack/react-query'; +import { handleError } from '@/utils/handleError'; /** * 경매 가능 작품 조회 훅 * @author 홍규진 @@ -12,14 +12,14 @@ export const useGetAvailableArtwork = () => { isLoading, refetch, error, - } = useQuery({ + } = useSuspenseQuery({ queryKey: getAvailableArtworksQuery().queryKey, queryFn: getAvailableArtworksQuery().queryFn, staleTime: 1000 * 60 * 60 * 2, // 2시간 gcTime: 1000 * 60 * 60 * 1.5, // 1.5시간 }); if (error) { - console.error(error); + handleError(error); } return { availableArtworks, diff --git a/src/pages/auction/hooks/useAuctionLike.ts b/src/pages/auction/hooks/useAuctionLike.ts index 406b592..1ec54e9 100644 --- a/src/pages/auction/hooks/useAuctionLike.ts +++ b/src/pages/auction/hooks/useAuctionLike.ts @@ -17,11 +17,11 @@ export const useAuctionLike = () => { onSuccess: () => { toast.success(`좋아요 변경 성공`); queryClient.invalidateQueries({ - queryKey: ['auctionDetails'], + queryKey: postAuctionLikeMutation().successMutationKey, }); }, - onError: () => { - toast.error('좋아요를 변경하는 데 실패했습니다.'); + onError: (error) => { + toast.error(`좋아요 변경에 실패했습니다. ${error.message}`); }, }); diff --git a/src/pages/auction/hooks/useAuctionUnlike.ts b/src/pages/auction/hooks/useAuctionUnlike.ts index 10cee5a..4382b55 100644 --- a/src/pages/auction/hooks/useAuctionUnlike.ts +++ b/src/pages/auction/hooks/useAuctionUnlike.ts @@ -6,7 +6,7 @@ import { postAuctionUnlike } from '@/apis/auction/postAuctionUnlike'; /** * 경매 좋아요 취소 커스텀 훅 * @returns null - * @author 이하늘 + * @author 이하늘, 홍규진 */ export const useAuctionUnlike = () => { const queryClient = useQueryClient(); @@ -17,11 +17,11 @@ export const useAuctionUnlike = () => { onSuccess: () => { toast.success(`좋아요 변경 성공`); queryClient.invalidateQueries({ - queryKey: ['auctionDetails'], + queryKey: postAuctionUnlikeMutation().successMutationKey, }); }, - onError: () => { - toast.error('좋아요를 변경하는 데 실패했습니다.'); + onError: (error) => { + toast.error(`좋아요 변경에 실패했습니다. ${error.message}`); }, }); diff --git a/src/pages/auction/hooks/useGetAuctionLists.ts b/src/pages/auction/hooks/useGetAuctionLists.ts index 0496558..f12b207 100644 --- a/src/pages/auction/hooks/useGetAuctionLists.ts +++ b/src/pages/auction/hooks/useGetAuctionLists.ts @@ -1,9 +1,7 @@ import { getAuctionListQuery } from '@/constants/queryKeys'; import { useSuspenseQuery } from '@tanstack/react-query'; -import { toast } from 'sonner'; -import { AxiosError } from 'axios'; import { TGetAuctionListResponse } from '@/apis/auction/type'; - +import { handleError } from '@/utils/handleError'; /** * 경매 리스트를 가져오는 커스텀 훅 * React Query의 useSuspenseQuery를 활용해 데이터를 가져오고, 오류 발생 시 toast 알림을 띄움 @@ -11,7 +9,7 @@ import { TGetAuctionListResponse } from '@/apis/auction/type'; * @param { 'title' | 'popular' | 'latest' } sort - 정렬 기준 * @returns {object} data, error 상태 반환 * @example const { data } = useGetAuctionLists('title'); - * @author 이하늘 + * @author 이하늘, 홍규진 **/ export const useGetAuctionLists = (sort: string) => { const { data, isLoading, error } = useSuspenseQuery< @@ -24,11 +22,7 @@ export const useGetAuctionLists = (sort: string) => { }); if (error) { - const axiosError = error as AxiosError<{ message?: string }>; - const errorMessage = - axiosError.response?.data?.message || - '경매 목록을 불러오는데 실패했습니다.'; - toast.error(errorMessage); + handleError(error); } return { data, isLoading, error }; diff --git a/src/pages/author-detail/hooks/useGetAuthorDetail.ts b/src/pages/author-detail/hooks/useGetAuthorDetail.ts index e2a40e2..a6b8d79 100644 --- a/src/pages/author-detail/hooks/useGetAuthorDetail.ts +++ b/src/pages/author-detail/hooks/useGetAuthorDetail.ts @@ -1,7 +1,6 @@ import { getAuthorDetailQuery } from '@/constants/queryKeys'; import { useSuspenseQuery } from '@tanstack/react-query'; import { toast } from 'sonner'; -import { AxiosError } from 'axios'; import { TGetAuthorDetailApiResponse } from '@/apis/author/type'; /** @@ -15,7 +14,7 @@ import { TGetAuthorDetailApiResponse } from '@/apis/author/type'; * @param {number} exhibitionLimit - 전시 한 페이지에 표시할 개수 (기본값: 4) * @returns {object} data, isLoading, error 상태 반환 * @example const { data } = useGetAuthorDetail(1); - * @author 이하늘 + * @author 이하늘, 홍규진 **/ export const useGetAuthorDetail = ({ authorId, @@ -50,11 +49,7 @@ export const useGetAuthorDetail = ({ gcTime: 1000 * 60 * 30, // 30분 }); if (error) { - const axiosError = error as AxiosError<{ message?: string }>; - const errorMessage = - axiosError.response?.data?.message || - '작가 정보를 불러오는데 실패했습니다.'; - toast.error(errorMessage); + toast.error(`작가 상세 정보 조회에 실패했습니다. ${error.message}`); } return { data, isLoading, error }; diff --git a/src/pages/author/hooks/useGetAuthorLists.ts b/src/pages/author/hooks/useGetAuthorLists.ts index 10692e2..851aed0 100644 --- a/src/pages/author/hooks/useGetAuthorLists.ts +++ b/src/pages/author/hooks/useGetAuthorLists.ts @@ -1,9 +1,7 @@ import { getAuthorListQuery } from '@/constants/queryKeys'; import { useSuspenseQuery } from '@tanstack/react-query'; -import { toast } from 'sonner'; -import { AxiosError } from 'axios'; import { TGetAuthorListApiResponse } from '@/apis/author/type'; - +import { handleError } from '@/utils/handleError'; /** * 작가 리스트를 가져오는 커스텀 훅 * React Query의 useSuspenseQuery를 활용해 데이터를 가져오고, 오류 발생 시 toast 알림을 띄움 @@ -13,7 +11,7 @@ import { TGetAuthorListApiResponse } from '@/apis/author/type'; * @param {number} limit - 페이지당 항목 수 * @returns {object} data, isLoading, error 상태 반환 * @example const { data } = useGetAuthorLists('popularity', 1, 5); - * @author 이하늘 + * @author 이하늘, 홍규진 **/ export const useGetAuthorLists = ( sort: string, @@ -29,11 +27,7 @@ export const useGetAuthorLists = ( }); if (error) { - const axiosError = error as AxiosError<{ message?: string }>; - const errorMessage = - axiosError.response?.data?.message || - '작가 목록을 불러오는데 실패했습니다.'; - toast.error(errorMessage); + handleError(error); } return { data, isLoading, error }; diff --git a/src/pages/authorPage/hooks/useGetAuthorProfile.ts b/src/pages/authorPage/hooks/useGetAuthorProfile.ts deleted file mode 100644 index fc50664..0000000 --- a/src/pages/authorPage/hooks/useGetAuthorProfile.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { useSuspenseQuery } from '@tanstack/react-query'; -import { toast } from 'sonner'; -import { AxiosError } from 'axios'; -import { getAuthorProfile } from '@/apis/mypage-author/author'; -import { getAuthorProfileQuery } from '@/constants/queryKeys'; -import { TAuthorProfile, AuthorProfileType } from '@/apis/mypage-author/type'; - -/** - * 작가 프로필 조회를 위한 React Query 훅 - * @param type - 조회할 프로필 타입 ('default', 'intro', 'info') - * @returns 작가 프로필 데이터와 쿼리 상태 반환 - * @example - * const { data, isLoading, error } = useGetAuthorProfile('intro'); - * @author 노찬영 - */ -export const useGetAuthorProfile = (type: AuthorProfileType) => { - const { data, isLoading, error } = useSuspenseQuery< - TAuthorProfile, - AxiosError - >({ - queryKey: getAuthorProfileQuery(type).queryKey, - queryFn: async () => { - const response = await getAuthorProfile(type); - - // result가 undefined인 경우 예외 처리 - if (!response) { - throw new Error('작가 프로필 데이터를 불러올 수 없습니다.'); - } - - return response; - }, - staleTime: 1000 * 60 * 30, // 30분 - gcTime: 1000 * 60 * 60, // 1시간 - retry: 1, // 실패 시 1회 재시도 - }); - - if (error) { - const axiosError = error as AxiosError<{ message: string }>; - const errorMessage = - axiosError.response?.data?.message || - '작가 프로필 정보를 불러오는데 실패했습니다.'; - toast.error(errorMessage); - } - - return { data, isLoading, error }; -}; diff --git a/src/pages/exhibition-detail/GalleryBox/index.style.ts b/src/pages/exhibition-detail/components/GalleryBox/index.style.ts similarity index 100% rename from src/pages/exhibition-detail/GalleryBox/index.style.ts rename to src/pages/exhibition-detail/components/GalleryBox/index.style.ts diff --git a/src/pages/exhibition-detail/GalleryBox/index.tsx b/src/pages/exhibition-detail/components/GalleryBox/index.tsx similarity index 100% rename from src/pages/exhibition-detail/GalleryBox/index.tsx rename to src/pages/exhibition-detail/components/GalleryBox/index.tsx diff --git a/src/pages/exhibition-detail/hooks/useGetExhibitionDetail.ts b/src/pages/exhibition-detail/hooks/useGetExhibitionDetail.ts index 154a88c..92a022a 100644 --- a/src/pages/exhibition-detail/hooks/useGetExhibitionDetail.ts +++ b/src/pages/exhibition-detail/hooks/useGetExhibitionDetail.ts @@ -1,7 +1,6 @@ import { getExhibitionDetailQeury } from '@/constants/queryKeys'; import { useSuspenseQuery } from '@tanstack/react-query'; -import { toast } from 'sonner'; -import { AxiosError } from 'axios'; +import { handleError } from '@/utils/handleError'; import { TGetExhibitionDetailResponse } from '@/apis/exhibition/type'; /** @@ -11,7 +10,7 @@ import { TGetExhibitionDetailResponse } from '@/apis/exhibition/type'; * @param exhibitionId - 전시 id * @returns {object} data, error 상태 반환 * @example const { data } = useGetAuctionLists('title'); - * @author 이하늘 + * @author 이하늘, 홍규진 **/ export const useGetExhibitionDetail = (exhibitionId: number) => { const { data, isLoading, error } = @@ -23,11 +22,7 @@ export const useGetExhibitionDetail = (exhibitionId: number) => { }); if (error) { - const axiosError = error as AxiosError<{ message?: string }>; - const errorMessage = - axiosError.response?.data?.message || - '전시 상세를를 불러오는데 실패했습니다.'; - toast.error(errorMessage); + handleError(error); } return { data, isLoading, error }; diff --git a/src/pages/exhibition-detail/index.tsx b/src/pages/exhibition-detail/index.tsx index 94bddb9..d3e4250 100644 --- a/src/pages/exhibition-detail/index.tsx +++ b/src/pages/exhibition-detail/index.tsx @@ -12,8 +12,8 @@ import { SubTitle, } from './index.style'; import { useNavigate, useParams } from 'react-router-dom'; -import { GalleryBox } from './GalleryBox'; -import { useGetExhibitionDetail } from './hooks/useGetExhibitionDetail'; +import { GalleryBox } from '@/pages/exhibition-detail/components/GalleryBox'; +import { useGetExhibitionDetail } from '@/pages/exhibition-detail/hooks/useGetExhibitionDetail'; // const exhibitionData = { // id: 1, diff --git a/src/pages/exhibit-register/components/StepOne/index.style.ts b/src/pages/exhibition-register/components/StepOne/index.style.ts similarity index 100% rename from src/pages/exhibit-register/components/StepOne/index.style.ts rename to src/pages/exhibition-register/components/StepOne/index.style.ts diff --git a/src/pages/exhibit-register/components/StepOne/index.tsx b/src/pages/exhibition-register/components/StepOne/index.tsx similarity index 100% rename from src/pages/exhibit-register/components/StepOne/index.tsx rename to src/pages/exhibition-register/components/StepOne/index.tsx diff --git a/src/pages/exhibit-register/components/StepThree/index.style.ts b/src/pages/exhibition-register/components/StepThree/index.style.ts similarity index 100% rename from src/pages/exhibit-register/components/StepThree/index.style.ts rename to src/pages/exhibition-register/components/StepThree/index.style.ts diff --git a/src/pages/exhibit-register/components/StepThree/index.tsx b/src/pages/exhibition-register/components/StepThree/index.tsx similarity index 100% rename from src/pages/exhibit-register/components/StepThree/index.tsx rename to src/pages/exhibition-register/components/StepThree/index.tsx diff --git a/src/pages/exhibit-register/components/StepTwo/index.style.ts b/src/pages/exhibition-register/components/StepTwo/index.style.ts similarity index 100% rename from src/pages/exhibit-register/components/StepTwo/index.style.ts rename to src/pages/exhibition-register/components/StepTwo/index.style.ts diff --git a/src/pages/exhibit-register/components/StepTwo/index.tsx b/src/pages/exhibition-register/components/StepTwo/index.tsx similarity index 98% rename from src/pages/exhibit-register/components/StepTwo/index.tsx rename to src/pages/exhibition-register/components/StepTwo/index.tsx index dee134b..261c7cf 100644 --- a/src/pages/exhibit-register/components/StepTwo/index.tsx +++ b/src/pages/exhibition-register/components/StepTwo/index.tsx @@ -8,7 +8,7 @@ import { DisplayImage, Container, } from './index.style.ts'; -import { TGetExhibitAvailableArtworksResponse } from '@/apis/exhibit-register/types'; +import { TGetExhibitAvailableArtworksResponse } from '@/apis/exhibitRegister/types.ts'; import { Link } from 'react-router-dom'; interface StepTwoProps { diff --git a/src/pages/exhibit-register/hooks/useExhibitRegister.ts b/src/pages/exhibition-register/hooks/useExhibitionRegister.ts similarity index 73% rename from src/pages/exhibit-register/hooks/useExhibitRegister.ts rename to src/pages/exhibition-register/hooks/useExhibitionRegister.ts index 1830e5f..c535e16 100644 --- a/src/pages/exhibit-register/hooks/useExhibitRegister.ts +++ b/src/pages/exhibition-register/hooks/useExhibitionRegister.ts @@ -1,8 +1,7 @@ import { useState } from 'react'; import { toast } from 'sonner'; -import { instance } from '@/apis/axios'; -import { TGetResponse } from '@/apis/type'; -import { useNavigate } from 'react-router-dom'; +import { usePostExhibitionRegisterMutation } from './usePostExhibitionRegister'; +import { TPostExhibitionRegisterFormData } from '@/apis/exhibitRegister/types'; interface ExhibitState { step: number; selectedBackground: string | null; // 배경 이미지 @@ -11,8 +10,8 @@ interface ExhibitState { finalImage: File | null; } -export const useExhibitRegister = () => { - const navigate = useNavigate(); +export const useExhibitionRegister = () => { + const { postExhibitionRegister } = usePostExhibitionRegisterMutation(); const [state, setState] = useState({ step: 0, selectedBackground: null, @@ -59,20 +58,12 @@ export const useExhibitRegister = () => { return; } - const formData = new FormData(); - formData.append('exhibition_image', combinedImageFile); - formData.append('title', title); + const exhibitionData: TPostExhibitionRegisterFormData = { + title, + exhibit_image: combinedImageFile, + }; - const response = await instance.post>( - '/api/exhibition', - formData - ); - if (response.data.isSuccess) { - toast.success('전시 등록이 완료되었습니다.'); - navigate('/'); - } else { - toast.error('전시 등록에 실패했습니다.'); - } + postExhibitionRegister(exhibitionData); }; return { diff --git a/src/pages/exhibit-register/hooks/useGetExhibitAvailableArtwork.ts b/src/pages/exhibition-register/hooks/useGetExhibitAvailableArtwork.ts similarity index 72% rename from src/pages/exhibit-register/hooks/useGetExhibitAvailableArtwork.ts rename to src/pages/exhibition-register/hooks/useGetExhibitAvailableArtwork.ts index 4c0f2ee..374cfb6 100644 --- a/src/pages/exhibit-register/hooks/useGetExhibitAvailableArtwork.ts +++ b/src/pages/exhibition-register/hooks/useGetExhibitAvailableArtwork.ts @@ -1,19 +1,19 @@ import { getExhibitAvailableArtworkQuery } from '@/constants/queryKeys'; -import { useQuery } from '@tanstack/react-query'; -import { toast } from 'sonner'; +import { useSuspenseQuery } from '@tanstack/react-query'; +import { handleError } from '@/utils/handleError'; /** * 전시 등록시 등록 가능 작품 조회 훅 * @author 홍규진 * */ export const useGetExhibitAvailableArtwork = () => { - const { data, error } = useQuery({ + const { data, error } = useSuspenseQuery({ queryKey: getExhibitAvailableArtworkQuery().queryKey, queryFn: getExhibitAvailableArtworkQuery().queryFn, staleTime: 1000 * 60 * 60 * 2, // 2시간 gcTime: 1000 * 60 * 60 * 1.5, // 1.5시간 }); if (error) { - toast.error(error.message); + handleError(error); } return { data, diff --git a/src/pages/exhibit-register/hooks/useGetExhibitBackground.ts b/src/pages/exhibition-register/hooks/useGetExhibitBackground.ts similarity index 72% rename from src/pages/exhibit-register/hooks/useGetExhibitBackground.ts rename to src/pages/exhibition-register/hooks/useGetExhibitBackground.ts index a3e7941..4b9981f 100644 --- a/src/pages/exhibit-register/hooks/useGetExhibitBackground.ts +++ b/src/pages/exhibition-register/hooks/useGetExhibitBackground.ts @@ -1,19 +1,19 @@ import { getExhibitBackgroundImagesQuery } from '@/constants/queryKeys'; -import { useQuery } from '@tanstack/react-query'; -import { toast } from 'sonner'; +import { useSuspenseQuery } from '@tanstack/react-query'; +import { handleError } from '@/utils/handleError'; /** * 전시 등록시 최초 배경 이미지 조회 훅 * @author 홍규진 * */ export const useGetExhibitBackgroundImages = () => { - const { data, error } = useQuery({ + const { data, error } = useSuspenseQuery({ queryKey: getExhibitBackgroundImagesQuery().queryKey, queryFn: getExhibitBackgroundImagesQuery().queryFn, staleTime: 1000 * 60 * 60 * 2, // 2시간 gcTime: 1000 * 60 * 60 * 1.5, // 1.5시간 }); if (error) { - toast.error(error.message); + handleError(error); } return { data, diff --git a/src/pages/exhibition-register/hooks/usePostExhibitionRegister.ts b/src/pages/exhibition-register/hooks/usePostExhibitionRegister.ts new file mode 100644 index 0000000..6cdc5a5 --- /dev/null +++ b/src/pages/exhibition-register/hooks/usePostExhibitionRegister.ts @@ -0,0 +1,36 @@ +/** + * 전시 등록 API 호출 + * @author 홍규진 + */ + +import { useMutation, useQueryClient } from '@tanstack/react-query'; +import { TPostExhibitionRegisterFormData } from '@/apis/exhibitRegister/types'; +import { postExhibitionRegisterMutation } from '@/constants/mutationKey'; +import { toast } from 'sonner'; +/** + * 전시 등록 관련 Mutation 훅 + * @author 홍규진 + */ +export const usePostExhibitionRegisterMutation = () => { + const queryClient = useQueryClient(); + const { + mutate: postExhibitionRegister, + isPending, + error, + } = useMutation({ + mutationKey: postExhibitionRegisterMutation().mutationKey, + mutationFn: (formData: TPostExhibitionRegisterFormData) => + postExhibitionRegisterMutation().mutationFn(formData), + onSuccess: () => { + toast.success('전시 등록이 완료되었습니다.'); + queryClient.invalidateQueries({ + queryKey: postExhibitionRegisterMutation().successMutationKey, + }); + }, + onError: (error) => { + toast.error(`전시 등록에 실패했습니다. ${error.message}`); + }, + }); + + return { postExhibitionRegister, isPending, error }; +}; diff --git a/src/pages/exhibit-register/index.style.ts b/src/pages/exhibition-register/index.style.ts similarity index 100% rename from src/pages/exhibit-register/index.style.ts rename to src/pages/exhibition-register/index.style.ts diff --git a/src/pages/exhibit-register/index.tsx b/src/pages/exhibition-register/index.tsx similarity index 77% rename from src/pages/exhibit-register/index.tsx rename to src/pages/exhibition-register/index.tsx index 7347110..a4305dd 100644 --- a/src/pages/exhibit-register/index.tsx +++ b/src/pages/exhibition-register/index.tsx @@ -1,14 +1,14 @@ import { PageLayout } from '@/components/common/PageLayout'; import { ButtonContainer, Container } from './index.style.ts'; -import { StepOne } from './components/StepOne'; -import { StepTwo } from './components/StepTwo'; -import { useExhibitRegister } from './hooks/useExhibitRegister'; +import { StepOne } from '@/pages/exhibition-register/components/StepOne/index.tsx'; +import { StepTwo } from '@/pages/exhibition-register/components/StepTwo/index.tsx'; +import { useExhibitionRegister } from '@/pages/exhibition-register/hooks/useExhibitionRegister.ts'; import { CommonButton } from '@/components/common/CommonButton/index.tsx'; -import { useGetExhibitAvailableArtwork } from './hooks/useGetExhibitAvailableArtwork.ts'; -import StepThree from './components/StepThree/index.tsx'; +import { useGetExhibitAvailableArtwork } from '@/pages/exhibition-register/hooks/useGetExhibitAvailableArtwork.ts'; +import StepThree from '@/pages/exhibition-register/components/StepThree/index.tsx'; // 최상위 컴포넌트 통합 -export const ExhibitRegister = () => { +export const ExhibitionRegister = () => { const { step, setStep, @@ -17,7 +17,7 @@ export const ExhibitRegister = () => { handleBackgroundSelect, handleOverlaySelect, handleSubmit, - } = useExhibitRegister(); + } = useExhibitionRegister(); const { data: availableArtworks } = useGetExhibitAvailableArtwork(); return ( diff --git a/src/pages/exhibition/hooks/useGetExhibitionList.ts b/src/pages/exhibition/hooks/useGetExhibitionList.ts index 95323e4..56d7aa1 100644 --- a/src/pages/exhibition/hooks/useGetExhibitionList.ts +++ b/src/pages/exhibition/hooks/useGetExhibitionList.ts @@ -1,8 +1,7 @@ import { getExhibitionListQuery } from '@/constants/queryKeys'; import { useSuspenseQuery } from '@tanstack/react-query'; -import { toast } from 'sonner'; -import { AxiosError } from 'axios'; import { TExhibition } from '@/apis/exhibition/type'; +import { handleError } from '@/utils/handleError'; /** * 전시 리스트를 가져오는 커스텀 훅 @@ -11,7 +10,7 @@ import { TExhibition } from '@/apis/exhibition/type'; * @param { 'title' | 'popular' | 'latest' } sort - 정렬 기준 * @returns {object} data, error 상태 반환 * @example const { data } = useGetAuctionLists('title'); - * @author 이하늘 + * @author 이하늘, 홍규진 **/ export const useGetExhibitionList = (sort: string) => { const { data, isLoading, error } = useSuspenseQuery({ @@ -22,11 +21,7 @@ export const useGetExhibitionList = (sort: string) => { }); if (error) { - const axiosError = error as AxiosError<{ message?: string }>; - const errorMessage = - axiosError.response?.data?.message || - '전시 목록을 불러오는데 실패했습니다.'; - toast.error(errorMessage); + handleError(error); } return { data, isLoading, error }; diff --git a/src/pages/login/hooks/useOauthLogin.ts b/src/pages/login/hooks/useOauthLogin.ts index 5d123aa..9b8afc5 100644 --- a/src/pages/login/hooks/useOauthLogin.ts +++ b/src/pages/login/hooks/useOauthLogin.ts @@ -1,10 +1,12 @@ import { postOauthLoginWithCode } from '@/apis/register/oAuthLogin'; import { useMutation } from '@tanstack/react-query'; +import { handleError } from '@/utils/handleError'; import { toast } from 'sonner'; /** * 소셜 로그인 뮤테이션 훅입니다. * 인가 코드를 사용하여 소셜 로그인 요청을 처리합니다. * @returns {object} mutate, isLoading, isError 상태 반환 + * @author 홍규진 */ export const useOauthLoginMutation = (code: string, social_type: string) => { const mutation = useMutation({ @@ -23,8 +25,7 @@ export const useOauthLoginMutation = (code: string, social_type: string) => { }, onError: (error: Error) => { // 로그인 실패 시 처리 - console.error('로그인 실패:', error); - toast.error(`로그인 실패: ${error.message}`); + handleError(error); }, }); diff --git a/src/pages/main/hooks/useGetMainData.ts b/src/pages/main/hooks/useGetMainData.ts index 07e92c9..c9fe5a8 100644 --- a/src/pages/main/hooks/useGetMainData.ts +++ b/src/pages/main/hooks/useGetMainData.ts @@ -1,14 +1,13 @@ import { useSuspenseQuery } from '@tanstack/react-query'; -import { getMainData } from '@/apis/main/main'; import { getMainDataQuery } from '@/constants/queryKeys'; import { TMainResult } from '@/apis/main/type'; - +import { handleError } from '@/utils/handleError'; /** * 메인 페이지 데이터를 가져오는 커스텀 훅 * React Query의 useSuspenseQuery를 활용해 데이터를 가져옵니다. * 오류 발생 시 toast 알림을 통해 사용자에게 에러 메시지를 표시합니다. * @returns {object} mainData, isLoading, error 상태 반환 - * @author 김서윤 + * @author 김서윤, 홍규진 **/ export const useGetMainData = () => { const { @@ -17,10 +16,14 @@ export const useGetMainData = () => { error, } = useSuspenseQuery({ queryKey: getMainDataQuery().queryKey, - queryFn: getMainData, + queryFn: getMainDataQuery().queryFn, staleTime: 1000 * 60 * 60, // 1시간 gcTime: 1000 * 60 * 30, // 30분 }); + if (error) { + handleError(error); + } + return { mainData, isLoading, error }; }; diff --git a/src/pages/authorPage/components/accountSettings/account/index.style.ts b/src/pages/mypage-author-page/components/accountSettings/account/index.style.ts similarity index 100% rename from src/pages/authorPage/components/accountSettings/account/index.style.ts rename to src/pages/mypage-author-page/components/accountSettings/account/index.style.ts diff --git a/src/pages/authorPage/components/accountSettings/account/index.tsx b/src/pages/mypage-author-page/components/accountSettings/account/index.tsx similarity index 95% rename from src/pages/authorPage/components/accountSettings/account/index.tsx rename to src/pages/mypage-author-page/components/accountSettings/account/index.tsx index 8284851..cd80700 100644 --- a/src/pages/authorPage/components/accountSettings/account/index.tsx +++ b/src/pages/mypage-author-page/components/accountSettings/account/index.tsx @@ -7,7 +7,7 @@ import { SectionTitle, StyledButton, } from './index.style'; -import { useSaveAuthorBankInfo } from '@/pages/authorPage/hooks/useSaveAuthorBankInfo'; +import { useSaveAuthorBankInfo } from '@/pages/mypage-author-page/hooks/useSaveAuthorBankInfo'; export const Account = () => { const [bankName, setBankName] = useState(''); diff --git a/src/pages/authorPage/components/accountSettings/basicInfo/index.style.ts b/src/pages/mypage-author-page/components/accountSettings/basicInfo/index.style.ts similarity index 100% rename from src/pages/authorPage/components/accountSettings/basicInfo/index.style.ts rename to src/pages/mypage-author-page/components/accountSettings/basicInfo/index.style.ts diff --git a/src/pages/authorPage/components/accountSettings/basicInfo/index.tsx b/src/pages/mypage-author-page/components/accountSettings/basicInfo/index.tsx similarity index 100% rename from src/pages/authorPage/components/accountSettings/basicInfo/index.tsx rename to src/pages/mypage-author-page/components/accountSettings/basicInfo/index.tsx diff --git a/src/pages/artBuyerPage/components/accountSettings/index.style.ts b/src/pages/mypage-author-page/components/accountSettings/index.style.ts similarity index 100% rename from src/pages/artBuyerPage/components/accountSettings/index.style.ts rename to src/pages/mypage-author-page/components/accountSettings/index.style.ts diff --git a/src/pages/authorPage/components/accountSettings/index.tsx b/src/pages/mypage-author-page/components/accountSettings/index.tsx similarity index 100% rename from src/pages/authorPage/components/accountSettings/index.tsx rename to src/pages/mypage-author-page/components/accountSettings/index.tsx diff --git a/src/pages/artBuyerPage/components/accountSettings/withdraw/index.style.ts b/src/pages/mypage-author-page/components/accountSettings/withdraw/index.style.ts similarity index 100% rename from src/pages/artBuyerPage/components/accountSettings/withdraw/index.style.ts rename to src/pages/mypage-author-page/components/accountSettings/withdraw/index.style.ts diff --git a/src/pages/artBuyerPage/components/accountSettings/withdraw/index.tsx b/src/pages/mypage-author-page/components/accountSettings/withdraw/index.tsx similarity index 100% rename from src/pages/artBuyerPage/components/accountSettings/withdraw/index.tsx rename to src/pages/mypage-author-page/components/accountSettings/withdraw/index.tsx diff --git a/src/pages/authorPage/components/managementWorks/artWorks/index.style.ts b/src/pages/mypage-author-page/components/managementWorks/artWorks/index.style.ts similarity index 100% rename from src/pages/authorPage/components/managementWorks/artWorks/index.style.ts rename to src/pages/mypage-author-page/components/managementWorks/artWorks/index.style.ts diff --git a/src/pages/authorPage/components/managementWorks/artWorks/index.tsx b/src/pages/mypage-author-page/components/managementWorks/artWorks/index.tsx similarity index 91% rename from src/pages/authorPage/components/managementWorks/artWorks/index.tsx rename to src/pages/mypage-author-page/components/managementWorks/artWorks/index.tsx index 32b9bd3..b5a3c0a 100644 --- a/src/pages/authorPage/components/managementWorks/artWorks/index.tsx +++ b/src/pages/mypage-author-page/components/managementWorks/artWorks/index.tsx @@ -9,7 +9,7 @@ import { StyledButton, } from './index.style'; -import { useGetAuthorArtworksExhibitions } from '@/pages/authorPage/hooks/useGetAuthorArtworksExhibitions'; +import { useGetAuthorArtworksExhibitions } from '@/pages/mypage-author-page/hooks/useGetAuthorArtworksExhibitions'; const ArtWorks = () => { const navigate = useNavigate(); diff --git a/src/pages/authorPage/components/managementWorks/auctioningWorks/index.style.ts b/src/pages/mypage-author-page/components/managementWorks/auctioningWorks/index.style.ts similarity index 100% rename from src/pages/authorPage/components/managementWorks/auctioningWorks/index.style.ts rename to src/pages/mypage-author-page/components/managementWorks/auctioningWorks/index.style.ts diff --git a/src/pages/authorPage/components/managementWorks/auctioningWorks/index.tsx b/src/pages/mypage-author-page/components/managementWorks/auctioningWorks/index.tsx similarity index 91% rename from src/pages/authorPage/components/managementWorks/auctioningWorks/index.tsx rename to src/pages/mypage-author-page/components/managementWorks/auctioningWorks/index.tsx index b7ba5e3..5a7f7e7 100644 --- a/src/pages/authorPage/components/managementWorks/auctioningWorks/index.tsx +++ b/src/pages/mypage-author-page/components/managementWorks/auctioningWorks/index.tsx @@ -9,7 +9,7 @@ import { StyledButton, } from './index.style'; -import { useGetAuthorArtworksExhibitions } from '@/pages/authorPage/hooks/useGetAuthorArtworksExhibitions'; +import { useGetAuthorArtworksExhibitions } from '@/pages/mypage-author-page/hooks/useGetAuthorArtworksExhibitions'; const AuctioningWorks = () => { const navigate = useNavigate(); diff --git a/src/pages/authorPage/components/managementWorks/exhibitions/index.style.ts b/src/pages/mypage-author-page/components/managementWorks/exhibitions/index.style.ts similarity index 100% rename from src/pages/authorPage/components/managementWorks/exhibitions/index.style.ts rename to src/pages/mypage-author-page/components/managementWorks/exhibitions/index.style.ts diff --git a/src/pages/authorPage/components/managementWorks/exhibitions/index.tsx b/src/pages/mypage-author-page/components/managementWorks/exhibitions/index.tsx similarity index 90% rename from src/pages/authorPage/components/managementWorks/exhibitions/index.tsx rename to src/pages/mypage-author-page/components/managementWorks/exhibitions/index.tsx index d250f61..c543026 100644 --- a/src/pages/authorPage/components/managementWorks/exhibitions/index.tsx +++ b/src/pages/mypage-author-page/components/managementWorks/exhibitions/index.tsx @@ -10,7 +10,7 @@ import { StyledButton, } from './index.style'; -import { useGetAuthorArtworksExhibitions } from '@/pages/authorPage/hooks/useGetAuthorArtworksExhibitions'; +import { useGetAuthorArtworksExhibitions } from '@/pages/mypage-author-page/hooks/useGetAuthorArtworksExhibitions'; const Exhibitions = () => { const navigate = useNavigate(); @@ -53,4 +53,4 @@ const Exhibitions = () => { ); }; -export default Exhibitions; \ No newline at end of file +export default Exhibitions; diff --git a/src/pages/authorPage/components/accountSettings/index.style.ts b/src/pages/mypage-author-page/components/managementWorks/index.style.ts similarity index 100% rename from src/pages/authorPage/components/accountSettings/index.style.ts rename to src/pages/mypage-author-page/components/managementWorks/index.style.ts diff --git a/src/pages/authorPage/components/managementWorks/index.tsx b/src/pages/mypage-author-page/components/managementWorks/index.tsx similarity index 100% rename from src/pages/authorPage/components/managementWorks/index.tsx rename to src/pages/mypage-author-page/components/managementWorks/index.tsx diff --git a/src/pages/authorPage/components/managingProfiles/allInfo/index.style.ts b/src/pages/mypage-author-page/components/managingProfiles/allInfo/index.style.ts similarity index 100% rename from src/pages/authorPage/components/managingProfiles/allInfo/index.style.ts rename to src/pages/mypage-author-page/components/managingProfiles/allInfo/index.style.ts diff --git a/src/pages/authorPage/components/managingProfiles/allInfo/index.tsx b/src/pages/mypage-author-page/components/managingProfiles/allInfo/index.tsx similarity index 97% rename from src/pages/authorPage/components/managingProfiles/allInfo/index.tsx rename to src/pages/mypage-author-page/components/managingProfiles/allInfo/index.tsx index 469604f..915c123 100644 --- a/src/pages/authorPage/components/managingProfiles/allInfo/index.tsx +++ b/src/pages/mypage-author-page/components/managingProfiles/allInfo/index.tsx @@ -13,7 +13,7 @@ import { Td, } from './index.style'; -import { useGetAuthorProfile } from '@/pages/authorPage/hooks/useGetAuthorProfile'; +import { useGetAuthorProfile } from '@/pages/mypage-author-page/hooks/useGetAuthorProfile'; export const AllInfo = () => { // useGetAuthorProfile 훅을 사용하여 'default' 프로필 데이터 가져오기 diff --git a/src/pages/authorPage/components/managementWorks/index.style.ts b/src/pages/mypage-author-page/components/managingProfiles/index.style.ts similarity index 100% rename from src/pages/authorPage/components/managementWorks/index.style.ts rename to src/pages/mypage-author-page/components/managingProfiles/index.style.ts diff --git a/src/pages/authorPage/components/managingProfiles/index.tsx b/src/pages/mypage-author-page/components/managingProfiles/index.tsx similarity index 100% rename from src/pages/authorPage/components/managingProfiles/index.tsx rename to src/pages/mypage-author-page/components/managingProfiles/index.tsx diff --git a/src/pages/authorPage/components/managingProfiles/introduce/index.style.ts b/src/pages/mypage-author-page/components/managingProfiles/introduce/index.style.ts similarity index 100% rename from src/pages/authorPage/components/managingProfiles/introduce/index.style.ts rename to src/pages/mypage-author-page/components/managingProfiles/introduce/index.style.ts diff --git a/src/pages/authorPage/components/managingProfiles/introduce/index.tsx b/src/pages/mypage-author-page/components/managingProfiles/introduce/index.tsx similarity index 93% rename from src/pages/authorPage/components/managingProfiles/introduce/index.tsx rename to src/pages/mypage-author-page/components/managingProfiles/introduce/index.tsx index 85d94af..622cfd2 100644 --- a/src/pages/authorPage/components/managingProfiles/introduce/index.tsx +++ b/src/pages/mypage-author-page/components/managingProfiles/introduce/index.tsx @@ -9,7 +9,7 @@ import { import EditIcon from '@assets/svg/Icon_Edit.svg?react'; -import { useGetAuthorProfile } from '@/pages/authorPage/hooks/useGetAuthorProfile'; +import { useGetAuthorProfile } from '@/pages/mypage-author-page/hooks/useGetAuthorProfile'; export const Introduce = () => { // useGetAuthorProfile 훅을 사용하여 'intro' 프로필 데이터 가져오기 diff --git a/src/pages/authorPage/components/managingProfiles/myInformation/index.style.ts b/src/pages/mypage-author-page/components/managingProfiles/myInformation/index.style.ts similarity index 100% rename from src/pages/authorPage/components/managingProfiles/myInformation/index.style.ts rename to src/pages/mypage-author-page/components/managingProfiles/myInformation/index.style.ts diff --git a/src/pages/authorPage/components/managingProfiles/myInformation/index.tsx b/src/pages/mypage-author-page/components/managingProfiles/myInformation/index.tsx similarity index 97% rename from src/pages/authorPage/components/managingProfiles/myInformation/index.tsx rename to src/pages/mypage-author-page/components/managingProfiles/myInformation/index.tsx index 014ad1c..e487f00 100644 --- a/src/pages/authorPage/components/managingProfiles/myInformation/index.tsx +++ b/src/pages/mypage-author-page/components/managingProfiles/myInformation/index.tsx @@ -13,7 +13,7 @@ import FallbackUI from '@/components/common/FallbackUI'; import EditIcon from '@assets/svg/Icon_Edit.svg?react'; -import { useGetAuthorProfile } from '@/pages/authorPage/hooks/useGetAuthorProfile'; +import { useGetAuthorProfile } from '@/pages/mypage-author-page/hooks/useGetAuthorProfile'; export const MyInformation = () => { // useGetAuthorProfile 훅을 사용하여 'info' 프로필 데이터 가져오기 diff --git a/src/pages/artBuyerPage/components/menuChooser/index.style.ts b/src/pages/mypage-author-page/components/menuChooser/index.style.ts similarity index 100% rename from src/pages/artBuyerPage/components/menuChooser/index.style.ts rename to src/pages/mypage-author-page/components/menuChooser/index.style.ts diff --git a/src/pages/authorPage/components/menuChooser/index.tsx b/src/pages/mypage-author-page/components/menuChooser/index.tsx similarity index 100% rename from src/pages/authorPage/components/menuChooser/index.tsx rename to src/pages/mypage-author-page/components/menuChooser/index.tsx diff --git a/src/pages/authorPage/components/menuMyPage/Auction/index.style.ts b/src/pages/mypage-author-page/components/menuMyPage/Auction/index.style.ts similarity index 100% rename from src/pages/authorPage/components/menuMyPage/Auction/index.style.ts rename to src/pages/mypage-author-page/components/menuMyPage/Auction/index.style.ts diff --git a/src/pages/authorPage/components/menuMyPage/Auction/index.tsx b/src/pages/mypage-author-page/components/menuMyPage/Auction/index.tsx similarity index 94% rename from src/pages/authorPage/components/menuMyPage/Auction/index.tsx rename to src/pages/mypage-author-page/components/menuMyPage/Auction/index.tsx index d95ba56..29a4fd3 100644 --- a/src/pages/authorPage/components/menuMyPage/Auction/index.tsx +++ b/src/pages/mypage-author-page/components/menuMyPage/Auction/index.tsx @@ -6,7 +6,7 @@ import { TableRow, } from './index.style'; -import { useGetAuthorMypage } from '@/pages/authorPage/hooks/useGetAuthorMypage'; +import { useGetAuthorMypage } from '@/pages/mypage-author-page/hooks/useGetAuthorMypage'; /** * @description 작가의 경매 내역을 표시하는 컴포넌트 diff --git a/src/pages/artBuyerPage/components/menuMyPage/MyCollection/index.style.ts b/src/pages/mypage-author-page/components/menuMyPage/artworkCollection/index.style.ts similarity index 100% rename from src/pages/artBuyerPage/components/menuMyPage/MyCollection/index.style.ts rename to src/pages/mypage-author-page/components/menuMyPage/artworkCollection/index.style.ts diff --git a/src/pages/authorPage/components/menuMyPage/artworkCollection/index.tsx b/src/pages/mypage-author-page/components/menuMyPage/artworkCollection/index.tsx similarity index 94% rename from src/pages/authorPage/components/menuMyPage/artworkCollection/index.tsx rename to src/pages/mypage-author-page/components/menuMyPage/artworkCollection/index.tsx index 86e9926..d011bfd 100644 --- a/src/pages/authorPage/components/menuMyPage/artworkCollection/index.tsx +++ b/src/pages/mypage-author-page/components/menuMyPage/artworkCollection/index.tsx @@ -11,7 +11,7 @@ import { import { Artwork } from '@/components/common/ArtWork'; -import { useGetAuthorMypage } from '@/pages/authorPage/hooks/useGetAuthorMypage'; +import { useGetAuthorMypage } from '@/pages/mypage-author-page/hooks/useGetAuthorMypage'; const ArtworkCollection = () => { const { userMypageData } = useGetAuthorMypage(); diff --git a/src/pages/artBuyerPage/components/menuMyPage/index.style.ts b/src/pages/mypage-author-page/components/menuMyPage/index.style.ts similarity index 100% rename from src/pages/artBuyerPage/components/menuMyPage/index.style.ts rename to src/pages/mypage-author-page/components/menuMyPage/index.style.ts diff --git a/src/pages/authorPage/components/menuMyPage/index.tsx b/src/pages/mypage-author-page/components/menuMyPage/index.tsx similarity index 100% rename from src/pages/authorPage/components/menuMyPage/index.tsx rename to src/pages/mypage-author-page/components/menuMyPage/index.tsx diff --git a/src/pages/authorPage/components/menuMyPage/profile/index.style.ts b/src/pages/mypage-author-page/components/menuMyPage/profile/index.style.ts similarity index 100% rename from src/pages/authorPage/components/menuMyPage/profile/index.style.ts rename to src/pages/mypage-author-page/components/menuMyPage/profile/index.style.ts diff --git a/src/pages/authorPage/components/menuMyPage/profile/index.tsx b/src/pages/mypage-author-page/components/menuMyPage/profile/index.tsx similarity index 92% rename from src/pages/authorPage/components/menuMyPage/profile/index.tsx rename to src/pages/mypage-author-page/components/menuMyPage/profile/index.tsx index 9b53ba9..0eee464 100644 --- a/src/pages/authorPage/components/menuMyPage/profile/index.tsx +++ b/src/pages/mypage-author-page/components/menuMyPage/profile/index.tsx @@ -8,7 +8,7 @@ import { import RightArrow from '@assets/svg/right-arrow.svg?react'; import NoneProfile from '@assets/svg/Icon_Profile.svg'; -import { useGetAuthorMypage } from '@/pages/authorPage/hooks/useGetAuthorMypage'; +import { useGetAuthorMypage } from '@/pages/mypage-author-page/hooks/useGetAuthorMypage'; interface AuthorProfileProps { onEditProfile: () => void; diff --git a/src/pages/authorPage/hooks/useGetAuthorArtworksExhibitions.ts b/src/pages/mypage-author-page/hooks/useGetAuthorArtworksExhibitions.ts similarity index 62% rename from src/pages/authorPage/hooks/useGetAuthorArtworksExhibitions.ts rename to src/pages/mypage-author-page/hooks/useGetAuthorArtworksExhibitions.ts index aae8a84..5d61707 100644 --- a/src/pages/authorPage/hooks/useGetAuthorArtworksExhibitions.ts +++ b/src/pages/mypage-author-page/hooks/useGetAuthorArtworksExhibitions.ts @@ -1,10 +1,7 @@ import { useSuspenseQuery } from '@tanstack/react-query'; -import { toast } from 'sonner'; -import { AxiosError } from 'axios'; import { getAuthorArtworksExhibitionsQuery } from '@/constants/queryKeys'; -import { getAuthorArtworksExhibitions } from '@/apis/mypage-author/author'; -import { TAuthorArtworksExhibitions } from '@/apis/mypage-author/type'; - +import { TAuthorArtworksExhibitions } from '@/apis/mypageAuthor/type'; +import { handleError } from '@/utils/handleError'; /** * 작가의 작품, 경매 작품, 전시 정보를 가져오는 커스텀 훅 * React Query의 useSuspenseQuery를 활용해 데이터를 가져옵니다. @@ -12,23 +9,19 @@ import { TAuthorArtworksExhibitions } from '@/apis/mypage-author/type'; * * @returns {object} data, isLoading, error 상태 반환 * @example const { data } = useGetAuthorArtworksExhibitions(); - * @author 노찬영 + * @author 노찬영, 홍규진 **/ export const useGetAuthorArtworksExhibitions = () => { const { data, isLoading, error } = useSuspenseQuery({ queryKey: getAuthorArtworksExhibitionsQuery().queryKey, - queryFn: getAuthorArtworksExhibitions, + queryFn: getAuthorArtworksExhibitionsQuery().queryFn, staleTime: 1000 * 60 * 30, // 30분 gcTime: 1000 * 60 * 60, // 1시간 }); if (error) { - const axiosError = error as AxiosError<{ message: string }>; - const errorMessage = - axiosError.response?.data?.message || - '작가 작품/전시 정보를 불러오는데 실패했습니다.'; - toast.error(errorMessage); + handleError(error); } return { data, isLoading, error }; diff --git a/src/pages/authorPage/hooks/useGetAuthorMypage.ts b/src/pages/mypage-author-page/hooks/useGetAuthorMypage.ts similarity index 52% rename from src/pages/authorPage/hooks/useGetAuthorMypage.ts rename to src/pages/mypage-author-page/hooks/useGetAuthorMypage.ts index b2e158b..18a76bc 100644 --- a/src/pages/authorPage/hooks/useGetAuthorMypage.ts +++ b/src/pages/mypage-author-page/hooks/useGetAuthorMypage.ts @@ -1,16 +1,13 @@ import { useSuspenseQuery } from '@tanstack/react-query'; -import { toast } from 'sonner'; -import { AxiosError } from 'axios'; -import { getMypageQueryKey } from '@/constants/queryKeys'; -import { getAuthorMypage } from '@/apis/mypage-author/myPage/myPage'; -import { TArtistMypage } from '@/apis/mypage-author/myPage/type'; - +import { TArtistMypage } from '@/apis/mypageAuthor/myPage/type'; +import { getAuthorMypageQuery } from '@/constants/queryKeys'; +import { handleError } from '@/utils/handleError'; /** * 작가의 마이페이지 정보를 가져오는 커스텀 훅 * React Query의 useSuspenseQuery를 활용해 데이터를 가져옵니다. * 오류 발생 시 toast 알림을 통해 사용자에게 에러 메시지를 표시합니다. * @returns {object} userMypageData, isLoading, error 상태 반환 - * @author 노찬영 + * @author 노찬영, 홍규진 */ export const useGetAuthorMypage = () => { @@ -19,18 +16,14 @@ export const useGetAuthorMypage = () => { isLoading, error, } = useSuspenseQuery({ - queryKey: getMypageQueryKey('author'), - queryFn: () => getAuthorMypage(), + queryKey: getAuthorMypageQuery().queryKey, + queryFn: getAuthorMypageQuery().queryFn, staleTime: 1000 * 60 * 30, // 30분 gcTime: 1000 * 60 * 60, // 1시간 }); if (error) { - const axiosError = error as AxiosError<{ message: string }>; - const errorMessage = - axiosError.response?.data?.message || - '마이페이지 정보를 불러오는데 실패했습니다.'; - toast.error(errorMessage); + handleError(error); } return { userMypageData, isLoading, error }; diff --git a/src/pages/mypage-author-page/hooks/useGetAuthorProfile.ts b/src/pages/mypage-author-page/hooks/useGetAuthorProfile.ts new file mode 100644 index 0000000..6c5d229 --- /dev/null +++ b/src/pages/mypage-author-page/hooks/useGetAuthorProfile.ts @@ -0,0 +1,27 @@ +import { useSuspenseQuery } from '@tanstack/react-query'; +import { getAuthorProfileQuery } from '@/constants/queryKeys'; +import { TAuthorProfile, AuthorProfileType } from '@/apis/mypageAuthor/type'; +import { handleError } from '@/utils/handleError'; +/** + * 작가 프로필 조회를 위한 React Query 훅 + * @param type - 조회할 프로필 타입 ('default', 'intro', 'info') + * @returns 작가 프로필 데이터와 쿼리 상태 반환 + * @example + * const { data, isLoading, error } = useGetAuthorProfile('intro'); + * @author 노찬영, 홍규진 + */ +export const useGetAuthorProfile = (type: AuthorProfileType) => { + const { data, isLoading, error } = useSuspenseQuery({ + queryKey: getAuthorProfileQuery(type).queryKey, + queryFn: getAuthorProfileQuery(type).queryFn, + staleTime: 1000 * 60 * 30, // 30분 + gcTime: 1000 * 60 * 60, // 1시간 + retry: 1, // 실패 시 1회 재시도 + }); + + if (error) { + handleError(error); + } + + return { data, isLoading, error }; +}; diff --git a/src/pages/authorPage/hooks/useSaveAuthorBankInfo.ts b/src/pages/mypage-author-page/hooks/useSaveAuthorBankInfo.ts similarity index 56% rename from src/pages/authorPage/hooks/useSaveAuthorBankInfo.ts rename to src/pages/mypage-author-page/hooks/useSaveAuthorBankInfo.ts index f2e8793..d5c7e59 100644 --- a/src/pages/authorPage/hooks/useSaveAuthorBankInfo.ts +++ b/src/pages/mypage-author-page/hooks/useSaveAuthorBankInfo.ts @@ -1,24 +1,25 @@ import { useMutation, useQueryClient } from '@tanstack/react-query'; -import { saveAuthorBankInfo } from '@/apis/mypage-author/account'; +import { saveAuthorBankInfoMutation } from '@/constants/queryKeys'; +import { toast } from 'sonner'; /** * 작가 계좌 정보 저장을 위한 커스텀 뮤테이션 훅 * @returns 뮤테이션 객체와 상태(onSuccess, onError 핸들링 포함) - * @author 노찬영 + * @author 노찬영, 홍규진 */ export const useSaveAuthorBankInfo = () => { const queryClient = useQueryClient(); return useMutation({ - mutationKey: ['saveAuthorBankInfo'], - mutationFn: saveAuthorBankInfo, + mutationKey: saveAuthorBankInfoMutation().mutationKey, + mutationFn: saveAuthorBankInfoMutation().mutationFn, onSuccess: () => { // 저장 성공 시, 관련 쿼리 캐시 무효화 queryClient.invalidateQueries({ queryKey: ['authorProfile'] }); - console.log('계좌 정보가 성공적으로 저장되었습니다.'); + toast.success('계좌 정보가 성공적으로 저장되었습니다.'); }, onError: (error) => { - console.error('계좌 정보 저장 중 오류 발생:', error); + toast.error(`계좌 정보 저장 중 오류 발생: ${error.message}`); }, }); }; diff --git a/src/pages/authorPage/hooks/useUpdateAuthorInfo.ts b/src/pages/mypage-author-page/hooks/useUpdateAuthorInfo.ts similarity index 74% rename from src/pages/authorPage/hooks/useUpdateAuthorInfo.ts rename to src/pages/mypage-author-page/hooks/useUpdateAuthorInfo.ts index 82a5cae..1f5d084 100644 --- a/src/pages/authorPage/hooks/useUpdateAuthorInfo.ts +++ b/src/pages/mypage-author-page/hooks/useUpdateAuthorInfo.ts @@ -1,15 +1,14 @@ import { useMutation } from '@tanstack/react-query'; import { toast } from 'sonner'; -import { AxiosError } from 'axios'; -import { updateAuthorInfo } from '@/apis/mypage-author/author'; +import { updateAuthorInfo } from '@/apis/mypageAuthor/author'; import { getUpdateAuthorInfoQueryKey } from '@/constants/queryKeys'; import { getQueryClient } from '@/contexts/query/getQueryClient'; -import { TUpdateAuthorInfo } from '@/apis/mypage-author/type'; +import { TUpdateAuthorInfo } from '@/apis/mypageAuthor/type'; /** * 작가 계정 정보 수정을 위한 React Query 훅 * @returns mutate 함수와 상태를 반환하여 작가 계정 정보 수정 요청 가능 - * @author 노찬영 + * @author 노찬영, 홍규진 **/ export const useUpdateAuthorInfo = () => { const queryClient = getQueryClient(); @@ -20,7 +19,7 @@ export const useUpdateAuthorInfo = () => { error, } = useMutation< void, - AxiosError<{ message: string }>, + Error, { authorId: number; authorInfo: TUpdateAuthorInfo } >({ mutationKey: getUpdateAuthorInfoQueryKey(), @@ -33,9 +32,7 @@ export const useUpdateAuthorInfo = () => { }); }, onError: (error) => { - const errorMessage = - error.response?.data?.message || '계정 정보 수정에 실패했습니다.'; - toast.error(errorMessage); + toast.error(`계정 정보 수정에 실패했습니다. ${error.message}`); }, }); diff --git a/src/pages/authorPage/hooks/useUpdateAuthorProfile.ts b/src/pages/mypage-author-page/hooks/useUpdateAuthorProfile.ts similarity index 77% rename from src/pages/authorPage/hooks/useUpdateAuthorProfile.ts rename to src/pages/mypage-author-page/hooks/useUpdateAuthorProfile.ts index 52b2d55..5b7d29e 100644 --- a/src/pages/authorPage/hooks/useUpdateAuthorProfile.ts +++ b/src/pages/mypage-author-page/hooks/useUpdateAuthorProfile.ts @@ -1,15 +1,15 @@ import { useMutation } from '@tanstack/react-query'; import { toast } from 'sonner'; import { AxiosError } from 'axios'; -import { updateAuthorProfile } from '@/apis/mypage-author/profile'; -import { TUpdateAuthorProfile } from '@/apis/mypage-author/type'; +import { updateAuthorProfile } from '@/apis/mypageAuthor/profile'; +import { TUpdateAuthorProfile } from '@/apis/mypageAuthor/type'; import { getUpdateAuthorProfileQueryKey } from '@/constants/queryKeys'; import { getQueryClient } from '@/contexts/query/getQueryClient'; /** * 작가 프로필 개별 정보를 수정하는 React Query 훅 * @returns mutate 함수와 상태를 반환하여 작가 정보 수정 요청 가능 - * @author 노찬영 + * @author 노찬영, 홍규진 **/ export const useUpdateAuthorProfile = () => { const queryClient = getQueryClient(); @@ -28,9 +28,7 @@ export const useUpdateAuthorProfile = () => { }); }, onError: (error) => { - const errorMessage = - error.response?.data?.message || '작가 프로필 수정에 실패했습니다.'; - toast.error(errorMessage); + toast.error(`작가 프로필 수정에 실패했습니다. ${error.message}`); }, }); diff --git a/src/pages/artBuyerPage/ArtBuyerPage.style.ts b/src/pages/mypage-author-page/index.style.ts similarity index 100% rename from src/pages/artBuyerPage/ArtBuyerPage.style.ts rename to src/pages/mypage-author-page/index.style.ts diff --git a/src/pages/authorPage/AuthorPage.tsx b/src/pages/mypage-author-page/index.tsx similarity index 93% rename from src/pages/authorPage/AuthorPage.tsx rename to src/pages/mypage-author-page/index.tsx index 9eb07b9..1313093 100644 --- a/src/pages/authorPage/AuthorPage.tsx +++ b/src/pages/mypage-author-page/index.tsx @@ -7,9 +7,9 @@ import ManagingProfiles from './components/managingProfiles'; import AccountSettings from './components/accountSettings'; import ManagementWorks from './components/managementWorks'; -import { MenuWrapper, MyPageWrapper } from './AuthorPage.style'; +import { MenuWrapper, MyPageWrapper } from './index.style.ts'; -export default function AuthorPage() { +export const MypageAuthorPage = () => { const [selectedMenu, setSelectedMenu] = useState< '마이페이지' | '프로필 관리' | '계정설정' | '작품/전시 관리' >('마이페이지'); diff --git a/src/pages/artBuyerPage/components/accountSettings/basicInfo/index.style.ts b/src/pages/mypage-buyer-page/components/accountSettings/basicInfo/index.style.ts similarity index 100% rename from src/pages/artBuyerPage/components/accountSettings/basicInfo/index.style.ts rename to src/pages/mypage-buyer-page/components/accountSettings/basicInfo/index.style.ts diff --git a/src/pages/artBuyerPage/components/accountSettings/basicInfo/index.tsx b/src/pages/mypage-buyer-page/components/accountSettings/basicInfo/index.tsx similarity index 79% rename from src/pages/artBuyerPage/components/accountSettings/basicInfo/index.tsx rename to src/pages/mypage-buyer-page/components/accountSettings/basicInfo/index.tsx index 7a1a94c..c79f6b3 100644 --- a/src/pages/artBuyerPage/components/accountSettings/basicInfo/index.tsx +++ b/src/pages/mypage-buyer-page/components/accountSettings/basicInfo/index.tsx @@ -16,32 +16,23 @@ import { import DefaultImage from '@assets/svg/Icon_Profile.svg'; import EditButton from '@assets/svg/Icon_Edit.svg?react'; -import { useGetBuyerMypage } from '@/pages/artBuyerPage/hooks/useGetBuyerMypage'; -import { useUpdateUserInfo } from '@/pages/artBuyerPage/hooks/useUpdateUserInfo'; +import { useGetBuyerMypage } from '@/pages/mypage-buyer-page/hooks/useGetBuyerMypage'; +import { useUpdateUserInfo } from '@/pages/mypage-buyer-page/hooks/useUpdateUserInfo'; export const BasicInfo = () => { const { userMypageData } = useGetBuyerMypage(); - // 사용자 데이터 확인 - const buyer = userMypageData.buyer; + // 사용자 데이터 객체 추출 + const { profile_image_url, name } = userMypageData.buyer; - // TODO[찬영] - 로그인 API Response 데이터 연결 const [nickname, setNickname] = useState(''); const [birth, setBirth] = useState(''); const [address, setAddress] = useState(''); - const [isSaved, setIsSaved] = useState(false); const { updateUser, isPending } = useUpdateUserInfo(); const handleSave = () => { - updateUser( - { nickname, birth, address }, - { - onSuccess: () => { - setIsSaved(true); - }, - } - ); + updateUser({ nickname, birth, address }); }; return ( @@ -51,7 +42,7 @@ export const BasicInfo = () => { 계정 정보 - + @@ -74,7 +65,7 @@ export const BasicInfo = () => { 기본 정보
이름
-
{buyer?.name || '사용자 이름'}
+
{name || '사용자 이름'}
휴대전화 @@ -119,9 +110,6 @@ export const BasicInfo = () => { {isPending ? '저장 중...' : '저장하기'} - {isSaved && ( - 저장 완료! - )} ); diff --git a/src/pages/authorPage/components/managingProfiles/index.style.ts b/src/pages/mypage-buyer-page/components/accountSettings/index.style.ts similarity index 100% rename from src/pages/authorPage/components/managingProfiles/index.style.ts rename to src/pages/mypage-buyer-page/components/accountSettings/index.style.ts diff --git a/src/pages/artBuyerPage/components/accountSettings/index.tsx b/src/pages/mypage-buyer-page/components/accountSettings/index.tsx similarity index 100% rename from src/pages/artBuyerPage/components/accountSettings/index.tsx rename to src/pages/mypage-buyer-page/components/accountSettings/index.tsx diff --git a/src/pages/authorPage/components/accountSettings/withdraw/index.style.ts b/src/pages/mypage-buyer-page/components/accountSettings/withdraw/index.style.ts similarity index 100% rename from src/pages/authorPage/components/accountSettings/withdraw/index.style.ts rename to src/pages/mypage-buyer-page/components/accountSettings/withdraw/index.style.ts diff --git a/src/pages/authorPage/components/accountSettings/withdraw/index.tsx b/src/pages/mypage-buyer-page/components/accountSettings/withdraw/index.tsx similarity index 100% rename from src/pages/authorPage/components/accountSettings/withdraw/index.tsx rename to src/pages/mypage-buyer-page/components/accountSettings/withdraw/index.tsx diff --git a/src/pages/authorPage/components/menuChooser/index.style.ts b/src/pages/mypage-buyer-page/components/menuChooser/index.style.ts similarity index 100% rename from src/pages/authorPage/components/menuChooser/index.style.ts rename to src/pages/mypage-buyer-page/components/menuChooser/index.style.ts diff --git a/src/pages/artBuyerPage/components/menuChooser/index.tsx b/src/pages/mypage-buyer-page/components/menuChooser/index.tsx similarity index 100% rename from src/pages/artBuyerPage/components/menuChooser/index.tsx rename to src/pages/mypage-buyer-page/components/menuChooser/index.tsx diff --git a/src/pages/artBuyerPage/components/menuMyPage/Auction/index.style.ts b/src/pages/mypage-buyer-page/components/menuMyPage/Auction/index.style.ts similarity index 100% rename from src/pages/artBuyerPage/components/menuMyPage/Auction/index.style.ts rename to src/pages/mypage-buyer-page/components/menuMyPage/Auction/index.style.ts diff --git a/src/pages/artBuyerPage/components/menuMyPage/Auction/index.tsx b/src/pages/mypage-buyer-page/components/menuMyPage/Auction/index.tsx similarity index 96% rename from src/pages/artBuyerPage/components/menuMyPage/Auction/index.tsx rename to src/pages/mypage-buyer-page/components/menuMyPage/Auction/index.tsx index 87249cd..790e2c4 100644 --- a/src/pages/artBuyerPage/components/menuMyPage/Auction/index.tsx +++ b/src/pages/mypage-buyer-page/components/menuMyPage/Auction/index.tsx @@ -7,7 +7,7 @@ import { TableRow, } from './index.style'; import { useNavigate } from 'react-router-dom'; -import { useGetBuyerMypage } from '@/pages/artBuyerPage/hooks/useGetBuyerMypage'; +import { useGetBuyerMypage } from '@/pages/mypage-buyer-page/hooks/useGetBuyerMypage'; /** * @description 작품 구매자의 경매 내역을 표시하는 컴포넌트 diff --git a/src/pages/authorPage/components/menuMyPage/artworkCollection/index.style.ts b/src/pages/mypage-buyer-page/components/menuMyPage/MyCollection/index.style.ts similarity index 100% rename from src/pages/authorPage/components/menuMyPage/artworkCollection/index.style.ts rename to src/pages/mypage-buyer-page/components/menuMyPage/MyCollection/index.style.ts diff --git a/src/pages/artBuyerPage/components/menuMyPage/MyCollection/index.tsx b/src/pages/mypage-buyer-page/components/menuMyPage/MyCollection/index.tsx similarity index 96% rename from src/pages/artBuyerPage/components/menuMyPage/MyCollection/index.tsx rename to src/pages/mypage-buyer-page/components/menuMyPage/MyCollection/index.tsx index f2b88da..f7da5cc 100644 --- a/src/pages/artBuyerPage/components/menuMyPage/MyCollection/index.tsx +++ b/src/pages/mypage-buyer-page/components/menuMyPage/MyCollection/index.tsx @@ -12,7 +12,7 @@ import { import { Artwork } from '@/components/common/ArtWork'; import { useNavigate } from 'react-router-dom'; -import { useGetBuyerMypage } from '@/pages/artBuyerPage/hooks/useGetBuyerMypage'; +import { useGetBuyerMypage } from '@/pages/mypage-buyer-page/hooks/useGetBuyerMypage'; /** * @description 작품 구매자의 작품과 전시를 표시하는 컴포넌트 diff --git a/src/pages/artBuyerPage/components/menuMyPage/Payment/index.style.ts b/src/pages/mypage-buyer-page/components/menuMyPage/Payment/index.style.ts similarity index 100% rename from src/pages/artBuyerPage/components/menuMyPage/Payment/index.style.ts rename to src/pages/mypage-buyer-page/components/menuMyPage/Payment/index.style.ts diff --git a/src/pages/artBuyerPage/components/menuMyPage/Payment/index.tsx b/src/pages/mypage-buyer-page/components/menuMyPage/Payment/index.tsx similarity index 92% rename from src/pages/artBuyerPage/components/menuMyPage/Payment/index.tsx rename to src/pages/mypage-buyer-page/components/menuMyPage/Payment/index.tsx index dd494cd..457b446 100644 --- a/src/pages/artBuyerPage/components/menuMyPage/Payment/index.tsx +++ b/src/pages/mypage-buyer-page/components/menuMyPage/Payment/index.tsx @@ -7,8 +7,8 @@ import { PaymentButton, } from './index.style'; -import { useGetBuyerMypage } from '@/pages/artBuyerPage/hooks/useGetBuyerMypage'; -import { useKakaoPay } from '@/pages/artBuyerPage/hooks/useKakaoPay'; +import { useGetBuyerMypage } from '@/pages/mypage-buyer-page/hooks/useGetBuyerMypage'; +import { useKakaoPay } from '@/pages/mypage-buyer-page/hooks/useKakaoPay'; /** * @description 작품 구매자의 결제 내역을 표시하는 컴포넌트 diff --git a/src/pages/authorPage/components/menuMyPage/index.style.ts b/src/pages/mypage-buyer-page/components/menuMyPage/index.style.ts similarity index 100% rename from src/pages/authorPage/components/menuMyPage/index.style.ts rename to src/pages/mypage-buyer-page/components/menuMyPage/index.style.ts diff --git a/src/pages/artBuyerPage/components/menuMyPage/index.tsx b/src/pages/mypage-buyer-page/components/menuMyPage/index.tsx similarity index 100% rename from src/pages/artBuyerPage/components/menuMyPage/index.tsx rename to src/pages/mypage-buyer-page/components/menuMyPage/index.tsx diff --git a/src/pages/artBuyerPage/components/menuMyPage/profile/index.style.ts b/src/pages/mypage-buyer-page/components/menuMyPage/profile/index.style.ts similarity index 100% rename from src/pages/artBuyerPage/components/menuMyPage/profile/index.style.ts rename to src/pages/mypage-buyer-page/components/menuMyPage/profile/index.style.ts diff --git a/src/pages/artBuyerPage/components/menuMyPage/profile/index.tsx b/src/pages/mypage-buyer-page/components/menuMyPage/profile/index.tsx similarity index 90% rename from src/pages/artBuyerPage/components/menuMyPage/profile/index.tsx rename to src/pages/mypage-buyer-page/components/menuMyPage/profile/index.tsx index 6572b2b..6b4f8c2 100644 --- a/src/pages/artBuyerPage/components/menuMyPage/profile/index.tsx +++ b/src/pages/mypage-buyer-page/components/menuMyPage/profile/index.tsx @@ -12,7 +12,7 @@ import { import RightArrow from '@assets/svg/right-arrow.svg?react'; import NoneProfile from '@assets/svg/Icon_Profile.svg'; -import { useGetBuyerMypage } from '@/pages/artBuyerPage/hooks/useGetBuyerMypage'; +import { useGetBuyerMypage } from '@/pages/mypage-buyer-page/hooks/useGetBuyerMypage'; interface ArtBuyerProfileProps { onEditProfile: () => void; @@ -29,7 +29,11 @@ export const ArtBuyerProfile = ({ onEditProfile }: ArtBuyerProfileProps) => { const { userMypageData } = useGetBuyerMypage(); const { buyer, paymentCounts } = userMypageData; - const paymentData = paymentCounts?.[0] ?? { pending: 0, completed: 0, received: 0 }; + const paymentData = paymentCounts?.[0] ?? { + pending: 0, + completed: 0, + received: 0, + }; return ( diff --git a/src/pages/artBuyerPage/components/purchasedWorks/index.style.ts b/src/pages/mypage-buyer-page/components/purchasedWorks/index.style.ts similarity index 100% rename from src/pages/artBuyerPage/components/purchasedWorks/index.style.ts rename to src/pages/mypage-buyer-page/components/purchasedWorks/index.style.ts diff --git a/src/pages/artBuyerPage/components/purchasedWorks/index.tsx b/src/pages/mypage-buyer-page/components/purchasedWorks/index.tsx similarity index 100% rename from src/pages/artBuyerPage/components/purchasedWorks/index.tsx rename to src/pages/mypage-buyer-page/components/purchasedWorks/index.tsx diff --git a/src/pages/artBuyerPage/hooks/useGetBuyerMypage.ts b/src/pages/mypage-buyer-page/hooks/useGetBuyerMypage.ts similarity index 53% rename from src/pages/artBuyerPage/hooks/useGetBuyerMypage.ts rename to src/pages/mypage-buyer-page/hooks/useGetBuyerMypage.ts index 878f529..cae93a2 100644 --- a/src/pages/artBuyerPage/hooks/useGetBuyerMypage.ts +++ b/src/pages/mypage-buyer-page/hooks/useGetBuyerMypage.ts @@ -1,16 +1,13 @@ import { useSuspenseQuery } from '@tanstack/react-query'; -import { toast } from 'sonner'; -import { AxiosError } from 'axios'; -import { getMypageQueryKey } from '@/constants/queryKeys'; -import { TBuyerMypage } from '@/apis/mypage-buyer/myPage/type'; -import { getBuyerMypage } from '@/apis/mypage-buyer/myPage/myPage'; - +import { getBuyerMypageQuery } from '@/constants/queryKeys'; +import { TBuyerMypage } from '@/apis/mypageBuyer/myPage/type'; +import { handleError } from '@/utils/handleError'; /** * 특정 사용자의 마이페이지 정보를 가져오는 커스텀 훅 * React Query의 useSuspenseQuery를 활용해 데이터를 가져옵니다. * 오류 발생 시 toast 알림을 통해 사용자에게 에러 메시지를 표시합니다. * @returns {object} userMypageData, isLoading, error 상태 반환 - * @author 노찬영 + * @author 노찬영, 홍규진 */ export const useGetBuyerMypage = () => { @@ -19,19 +16,13 @@ export const useGetBuyerMypage = () => { isLoading, error, } = useSuspenseQuery({ - queryKey: getMypageQueryKey('buyer'), - queryFn: () => getBuyerMypage(), + queryKey: getBuyerMypageQuery().queryKey, + queryFn: getBuyerMypageQuery().queryFn, staleTime: 1000 * 60 * 30, // 30분 gcTime: 1000 * 60 * 60, // 1시간 }); - if (error) { - const axiosError = error as AxiosError<{ message: string }>; - const errorMessage = - axiosError.response?.data?.message || - '마이페이지 정보를 불러오는데 실패했습니다.'; - toast.error(errorMessage); + handleError(error); } - return { userMypageData, isLoading, error }; }; diff --git a/src/pages/artBuyerPage/hooks/useGetPurchasedArtworks.ts b/src/pages/mypage-buyer-page/hooks/useGetPurchasedArtworks.ts similarity index 62% rename from src/pages/artBuyerPage/hooks/useGetPurchasedArtworks.ts rename to src/pages/mypage-buyer-page/hooks/useGetPurchasedArtworks.ts index ba4efbd..210df18 100644 --- a/src/pages/artBuyerPage/hooks/useGetPurchasedArtworks.ts +++ b/src/pages/mypage-buyer-page/hooks/useGetPurchasedArtworks.ts @@ -1,16 +1,13 @@ import { useSuspenseQuery } from '@tanstack/react-query'; -import { toast } from 'sonner'; -import { AxiosError } from 'axios'; -import { getPurchasedArtworks } from '@/apis/mypage-buyer/artWork'; import { getPurchasedArtworksQuery } from '@/constants/queryKeys'; -import { TPurchasedArtwork } from '@/apis/mypage-buyer/type'; - +import { TPurchasedArtwork } from '@/apis/mypageBuyer/type'; +import { handleError } from '@/utils/handleError'; /** * 구매한 작품 리스트를 가져오는 커스텀 훅 * React Query의 useSuspenseQuery를 활용해 데이터를 가져옵니다. * 오류 발생 시 toast 알림을 통해 사용자에게 에러 메시지를 표시합니다. * @returns {object} purchasedArtworksData, isLoading, error 상태 반환 - * @author 노찬영 + * @author 노찬영, 홍규진 **/ export const useGetPurchasedArtworks = () => { const { @@ -19,18 +16,14 @@ export const useGetPurchasedArtworks = () => { error, } = useSuspenseQuery({ queryKey: getPurchasedArtworksQuery().queryKey, - queryFn: getPurchasedArtworks, + queryFn: getPurchasedArtworksQuery().queryFn, staleTime: 1000 * 60 * 60, // 1시간 gcTime: 1000 * 60 * 30, // 30분 }); if (error) { - const axiosError = error as AxiosError<{ message?: string }>; - const errorMessage = - axiosError.response?.data?.message || - '구매한 작품 리스트를 불러오는데 실패했습니다.'; - toast.error(errorMessage); + handleError(error); } return { purchasedArtworksData, isLoading, error }; -}; \ No newline at end of file +}; diff --git a/src/pages/mypage-buyer-page/hooks/useKakaoPay.ts b/src/pages/mypage-buyer-page/hooks/useKakaoPay.ts new file mode 100644 index 0000000..bb04271 --- /dev/null +++ b/src/pages/mypage-buyer-page/hooks/useKakaoPay.ts @@ -0,0 +1,59 @@ +import { useMutation, useQueryClient } from '@tanstack/react-query'; +import { + requestKakaoPayMutation, + approveKakaoPayMutation, +} from '@/constants/mutationKey'; +import { toast } from 'sonner'; +/** + * 카카오페이 결제 Hook + * @returns 카카오페이 결제 관련 함수 및 상태값 + * @author 노찬영, 홍규진 + */ + +export const useKakaoPay = () => { + const queryClient = useQueryClient(); + // 결제 준비 (결제 URL 요청) + const initiatePaymentMutation = useMutation({ + mutationKey: [...requestKakaoPayMutation().mutationKey], + mutationFn: (paymentId: number) => + requestKakaoPayMutation().mutationFn(paymentId), + onSuccess: (result) => { + toast.success('결제 준비 성공!'); + window.location.href = result.next_redirect_pc_url; // PC 결제창으로 이동 + queryClient.invalidateQueries({ + queryKey: requestKakaoPayMutation().successMutationKey, + }); + }, + onError: (error) => { + toast.error(`결제 준비에 실패했습니다. ${error.message}`); + }, + }); + + // 결제 승인 (pgToken을 받아 결제 승인 요청) + const confirmPaymentMutation = useMutation({ + mutationKey: approveKakaoPayMutation().mutationKey, + mutationFn: ({ + paymentId, + pgToken, + }: { + paymentId: number; + pgToken: string; + }) => approveKakaoPayMutation().mutationFn(paymentId, pgToken), + onSuccess: (approvedPaymentId) => { + toast.success( + `결제가 성공적으로 완료되었습니다. Payment ID: ${approvedPaymentId}` + ); + queryClient.invalidateQueries({ + queryKey: approveKakaoPayMutation().successMutationKey, + }); + }, + onError: (error) => { + toast.error(`결제 승인에 실패했습니다. ${error.message}`); + }, + }); + + return { + initiatePayment: initiatePaymentMutation.mutate, + confirmPayment: confirmPaymentMutation.mutate, + }; +}; diff --git a/src/pages/artBuyerPage/hooks/useUpdateUserInfo.ts b/src/pages/mypage-buyer-page/hooks/useUpdateUserInfo.ts similarity index 50% rename from src/pages/artBuyerPage/hooks/useUpdateUserInfo.ts rename to src/pages/mypage-buyer-page/hooks/useUpdateUserInfo.ts index cd99547..74c1ffd 100644 --- a/src/pages/artBuyerPage/hooks/useUpdateUserInfo.ts +++ b/src/pages/mypage-buyer-page/hooks/useUpdateUserInfo.ts @@ -1,47 +1,35 @@ import { useMutation } from '@tanstack/react-query'; import { toast } from 'sonner'; -import { AxiosError } from 'axios'; -import { updateUserInfo } from '@/apis/mypage-buyer/artBuyer'; -import { getUpdateUserInfoQueryKey } from '@/constants/queryKeys'; +import { updateUserInfoMutation } from '@/constants/mutationKey'; import { getQueryClient } from '@/contexts/query/getQueryClient'; -import { TGetResponse } from '@/apis/type'; - +import { TUpdateUserInfo } from '@/apis/mypageBuyer/type'; const queryClient = getQueryClient(); -interface UpdateUserInfoParams { - nickname?: string; - address?: string; - birth?: string; -} - /** * 작품 구매자 계정 정보 수정을 위한 React Query 훅 * @returns mutate 함수와 상태를 반환하여 사용자 정보 수정 요청 가능 * @example * const { mutate: updateUser } = useUpdateUserInfo(); * updateUser({ nickname: '새 닉네임' }); - * @author 노찬영 + * @author 노찬영, 홍규진 **/ export const useUpdateUserInfo = () => { const { mutate: updateUser, isPending, error, - } = useMutation< - TGetResponse, - AxiosError<{ message: string }>, - UpdateUserInfoParams - >({ - mutationKey: getUpdateUserInfoQueryKey(), - mutationFn: updateUserInfo, + } = useMutation({ + mutationKey: updateUserInfoMutation().mutationKey, + mutationFn: (userInfo: TUpdateUserInfo) => + updateUserInfoMutation().mutationFn(userInfo), onSuccess: () => { toast.success('계정 정보가 성공적으로 업데이트되었습니다.'); - queryClient.invalidateQueries({ queryKey: getUpdateUserInfoQueryKey() }); + queryClient.invalidateQueries({ + queryKey: updateUserInfoMutation().successMutationKey, + }); }, onError: (error) => { - const errorMessage = - error.response?.data?.message || '계정 정보 수정에 실패했습니다.'; - toast.error(errorMessage); + toast.error(`계정 정보 수정에 실패했습니다. ${error.message}`); }, }); diff --git a/src/pages/authorPage/AuthorPage.style.ts b/src/pages/mypage-buyer-page/index.style.ts similarity index 100% rename from src/pages/authorPage/AuthorPage.style.ts rename to src/pages/mypage-buyer-page/index.style.ts diff --git a/src/pages/artBuyerPage/ArtBuyerPage.tsx b/src/pages/mypage-buyer-page/index.tsx similarity index 74% rename from src/pages/artBuyerPage/ArtBuyerPage.tsx rename to src/pages/mypage-buyer-page/index.tsx index 6ab7d28..cfe5f21 100644 --- a/src/pages/artBuyerPage/ArtBuyerPage.tsx +++ b/src/pages/mypage-buyer-page/index.tsx @@ -1,14 +1,14 @@ import { useState } from 'react'; -import { MenuChooser } from './components/menuChooser'; +import { MenuChooser } from './components/menuChooser/index.tsx'; import { PageLayout } from '@/components/common/PageLayout'; -import { MenuMyPage } from './components/menuMyPage'; -import AccountSettings from './components/accountSettings'; -import PurchasedWorks from './components/purchasedWorks'; +import { MenuMyPage } from './components/menuMyPage/index.tsx'; +import AccountSettings from './components/accountSettings/index.tsx'; +import PurchasedWorks from './components/purchasedWorks/index.tsx'; -import { MyPageWrapper, MenuWrapper } from './ArtBuyerPage.style'; +import { MyPageWrapper, MenuWrapper } from './index.style.ts'; -export default function ArtBuyerPage() { +export const MypageBuyerPage = () => { const [selectedMenu, setSelectedMenu] = useState< '마이페이지' | '계정설정' | '구매 작품' >('마이페이지'); @@ -42,4 +42,4 @@ export default function ArtBuyerPage() { {renderSelectedMenu()}
); -} \ No newline at end of file +}; diff --git a/src/pages/register/hooks/usePostAuthRegister.ts b/src/pages/register/hooks/usePostAuthRegister.ts index b5f6167..68349eb 100644 --- a/src/pages/register/hooks/usePostAuthRegister.ts +++ b/src/pages/register/hooks/usePostAuthRegister.ts @@ -21,7 +21,7 @@ export const usePostAuthRegister = () => { navigate('/'); // 성공 페이지로 이동 }, onError: (error: Error) => { - toast.error(error.message); // 오류 메시지 표시 + toast.error(`회원가입에 실패했습니다. ${error.message}`); }, }); }; diff --git a/src/router.tsx b/src/router.tsx index 79c2b37..d1dc915 100644 --- a/src/router.tsx +++ b/src/router.tsx @@ -2,8 +2,8 @@ import { Route, Routes } from 'react-router-dom'; import { AuthCheckRoute } from '@components/common/AuthCheckRoute'; import NotFound from './pages/not-found'; import Test from '@pages/test.tsx'; -import ArtBuyerPage from './pages/artBuyerPage/ArtBuyerPage'; -import AuthorPage from './pages/authorPage/AuthorPage'; +import { MypageBuyerPage } from './pages/mypage-buyer-page'; +import { MypageAuthorPage } from './pages/mypage-author-page'; import { Login } from '@/pages/login'; import { ArtworkRegister } from '@/pages/artwork-register'; @@ -13,7 +13,7 @@ import { AuthorDetail } from './pages/author-detail'; import { Exhibition } from './pages/exhibition'; import { ExhibitionDetail } from './pages/exhibition-detail'; import { Register } from '@/pages/register'; -import { ExhibitRegister } from '@/pages/exhibit-register'; +import { ExhibitionRegister } from '@/pages/exhibition-register'; import { Auction } from './pages/auction'; import { Main } from '@/pages/main'; import { ArtWork } from '@/pages/artwork'; @@ -32,16 +32,16 @@ type TRoutes = { * */ /** - * 작품구매자_마이페이지는 /artBuyerPage 이고, - * 작가_마이페이지는 /authorPage 로 구분했습니다. - * @author 노찬영 + * 작품구매자_마이페이지는 /mypage/buyer 이고, + * 작가_마이페이지는 /mypage/author 로 구분했습니다. + * @author 노찬영, 홍규진 * */ // eslint-disable-next-line react-refresh/only-export-components export const routes: TRoutes[] = [ { path: '/', element:
, isTabBar: true }, - { path: '/mypage/art-buyer', element: , isTabBar: true }, - { path: '/mypage/author', element: , isTabBar: true }, + { path: '/mypage/buyer', element: , isTabBar: true }, + { path: '/mypage/author', element: , isTabBar: true }, { path: '/test', element: , isTabBar: true }, { path: '/login', element: , isTabBar: true }, @@ -79,8 +79,8 @@ export const routes: TRoutes[] = [ isTabBar: true, }, { - path: '/exhibit-register', - element: , + path: '/exhibition-register', + element: , isTabBar: true, }, { diff --git a/src/types/artist.ts b/src/types/artist.ts deleted file mode 100644 index af215bb..0000000 --- a/src/types/artist.ts +++ /dev/null @@ -1,4 +0,0 @@ -export type TArtist = { - artistId: number; - name: string; -}; diff --git a/src/utils/handleError.ts b/src/utils/handleError.ts new file mode 100644 index 0000000..ccf5390 --- /dev/null +++ b/src/utils/handleError.ts @@ -0,0 +1,15 @@ +import { toast } from 'sonner'; + +/** + * 페이지 전체를 표시하는 API 호출중 에러가 발생할 경우 사용 or 치명적인 에러 발생시 사용 + * 예시) 메인 페이지 데이터 조회 중 에러가 발생할 경우 + * ErrorBoundary 컴포넌트에서 DefaultFallBack UI 사용 + * @param error 에러 객체 + * @author 홍규진 + */ +export const handleError = (error: Error) => { + const errorMessage = error.message; + console.log(errorMessage); + toast.error(errorMessage); + throw new Error(errorMessage); +};