From 4566c61b425fa56bc2a775bf7e70d7fc380a1be5 Mon Sep 17 00:00:00 2001 From: syddl0 <137189866+shroqkf@users.noreply.github.com> Date: Sat, 15 Feb 2025 12:47:41 +0900 Subject: [PATCH 1/4] =?UTF-8?q?=EC=9E=91=ED=92=88=20=EA=B5=AC=EB=A7=A4?= =?UTF-8?q?=EC=9E=90=20=ED=86=A0=ED=81=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/axios.ts | 2 +- src/apis/mypage-buyer/myPage/myPage.ts | 21 ++++++--------- .../menuMyPage/MyCollection/index.tsx | 27 +++++++++++++++---- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/apis/axios.ts b/src/apis/axios.ts index 34dde46..ab9ae78 100644 --- a/src/apis/axios.ts +++ b/src/apis/axios.ts @@ -28,7 +28,7 @@ type TAuthResponse = { const DUMMY_ACCESS_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InJ5dXNlb25naG83QGRndS5hYy5rciIsImlhdCI6MTczOTIwNDY5NiwiZXhwIjoxNzQxNzk2Njk2fQ.iWwnAhIzse5UwvHpR5uWa2o0HRM5G14ikeAtYf_BDec'; -// localStorage.setItem('accessToken', DUMMY_ACCESS_TOKEN); +localStorage.setItem('accessToken', DUMMY_ACCESS_TOKEN); export const instance: AxiosInstance = axios.create({ baseURL: import.meta.env.VITE_APP_SERVER_URL, headers: { diff --git a/src/apis/mypage-buyer/myPage/myPage.ts b/src/apis/mypage-buyer/myPage/myPage.ts index ec4e0fa..28d2848 100644 --- a/src/apis/mypage-buyer/myPage/myPage.ts +++ b/src/apis/mypage-buyer/myPage/myPage.ts @@ -8,22 +8,17 @@ import { TGetResponse } from '@/apis/type'; * @author 노찬영 **/ export const getBuyerMypage = async (): Promise => { - const DUMMY_ACCESS_TOKEN = localStorage.getItem('accessToken'); // 기존 토큰 저장 const BUYER_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6Imh5c29uZzR1QGdtYWlsLmNvbSIsImlhdCI6MTczOTU1MzczMSwiZXhwIjoxNzQyMTQ1NzMxfQ.6ePJhRS1JUNK9BPIOk9oXrYoggois21uBtGsp4gvKrU'; + console.log('변경된 accessToken:', BUYER_TOKEN); - try { - // 기존 토큰 삭제 후 구매자 토큰 저장 - localStorage.removeItem('accessToken'); - localStorage.setItem('accessToken', BUYER_TOKEN); + // 구매자 토큰으로 변경 + localStorage.setItem('accessToken', BUYER_TOKEN); + instance.defaults.headers.common.Authorization = `Bearer ${BUYER_TOKEN}`; - const response = await instance.get>( - `/api/mypage` - ); + const response = await instance.get>( + `/api/mypage` + ); - return response.data.result; - } finally { - // 원래 있던 DUMMY_ACCESS_TOKEN으로 복원 - localStorage.setItem('accessToken', DUMMY_ACCESS_TOKEN ?? ''); - } + return response.data.result; }; diff --git a/src/pages/artBuyerPage/components/menuMyPage/MyCollection/index.tsx b/src/pages/artBuyerPage/components/menuMyPage/MyCollection/index.tsx index fc92839..f2b88da 100644 --- a/src/pages/artBuyerPage/components/menuMyPage/MyCollection/index.tsx +++ b/src/pages/artBuyerPage/components/menuMyPage/MyCollection/index.tsx @@ -11,6 +11,7 @@ import { import { Artwork } from '@/components/common/ArtWork'; +import { useNavigate } from 'react-router-dom'; import { useGetBuyerMypage } from '@/pages/artBuyerPage/hooks/useGetBuyerMypage'; /** @@ -18,13 +19,23 @@ import { useGetBuyerMypage } from '@/pages/artBuyerPage/hooks/useGetBuyerMypage' * @author 노찬영 */ const MyCollection = () => { + const navigate = useNavigate(); const { userMypageData } = useGetBuyerMypage(); // 작품 구매자 작품 데이터 - const artworks = userMypageData.myCollection.artworks; - + const artworks = userMypageData?.myCollection?.artworks || []; // 작품 구매자 전시 데이터 - const exhibitions = userMypageData.myCollection.exhibitions; + const exhibitions = userMypageData?.myCollection?.exhibitions || []; + + // 작품 클릭 시 작품 상세 페이지로 이동 + const handleArtworkClick = (artworkId: number) => { + navigate(`/artwork/${artworkId}`); + }; + + // 전시 클릭 시 전시 상세 페이지로 이동 + const handleExhibitionClick = (exhibitionId: number) => { + navigate(`/exhibition/${exhibitionId}`); + }; return ( @@ -33,7 +44,7 @@ const MyCollection = () => { 작품 - {artworks?.map((artwork) => ( + {artworks.map((artwork) => ( { artworkWidth={artwork.width} artworkHeight={artwork.height} artworkId={artwork.id} + isLiked={true} + onClick={() => handleArtworkClick(artwork.id)} /> ))} @@ -51,7 +64,11 @@ const MyCollection = () => { 전시 {exhibitions.map((exhibition) => ( - + handleExhibitionClick(exhibition.id)} + style={{ cursor: 'pointer' }} + > Date: Sat, 15 Feb 2025 13:02:02 +0900 Subject: [PATCH 2/4] =?UTF-8?q?Refactor:=20=EC=9E=91=EA=B0=80=20=EB=A7=88?= =?UTF-8?q?=EC=9D=B4=ED=8E=98=EC=9D=B4=EC=A7=80=20API=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/axios.ts | 1 - src/apis/mypage-author/myPage/myPage.ts | 7 ++++++ src/apis/mypage-buyer/myPage/myPage.ts | 2 +- src/constants/queryKeys.ts | 23 ++++++------------- .../artBuyerPage/hooks/useGetBuyerMypage.ts | 4 ++-- .../components/menuMyPage/Auction/index.tsx | 2 +- .../authorPage/hooks/useGetAuthorMypage.ts | 4 ++-- 7 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/apis/axios.ts b/src/apis/axios.ts index ab9ae78..fb2123a 100644 --- a/src/apis/axios.ts +++ b/src/apis/axios.ts @@ -25,7 +25,6 @@ type TAnotherToken = { type TAuthResponse = { accessToken: string; }; - const DUMMY_ACCESS_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InJ5dXNlb25naG83QGRndS5hYy5rciIsImlhdCI6MTczOTIwNDY5NiwiZXhwIjoxNzQxNzk2Njk2fQ.iWwnAhIzse5UwvHpR5uWa2o0HRM5G14ikeAtYf_BDec'; localStorage.setItem('accessToken', DUMMY_ACCESS_TOKEN); diff --git a/src/apis/mypage-author/myPage/myPage.ts b/src/apis/mypage-author/myPage/myPage.ts index 09aee22..9d69f16 100644 --- a/src/apis/mypage-author/myPage/myPage.ts +++ b/src/apis/mypage-author/myPage/myPage.ts @@ -8,6 +8,13 @@ import { TGetResponse } from '@/apis/type'; * @author 노찬영 **/ export const getAuthorMypage = async (): Promise => { + const AUTHOR_TOKEN = + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InJ5dXNlb25naG83QGRndS5hYy5rciIsImlhdCI6MTczOTIwNDY5NiwiZXhwIjoxNzQxNzk2Njk2fQ.iWwnAhIzse5UwvHpR5uWa2o0HRM5G14ikeAtYf_BDec'; + console.log('작가 accessToken:', AUTHOR_TOKEN); + + localStorage.setItem('accessToken', AUTHOR_TOKEN); + instance.defaults.headers.common.Authorization = `Bearer ${AUTHOR_TOKEN}`; + const response = await instance.get>( `/api/mypage` ); diff --git a/src/apis/mypage-buyer/myPage/myPage.ts b/src/apis/mypage-buyer/myPage/myPage.ts index 28d2848..310751c 100644 --- a/src/apis/mypage-buyer/myPage/myPage.ts +++ b/src/apis/mypage-buyer/myPage/myPage.ts @@ -10,7 +10,7 @@ import { TGetResponse } from '@/apis/type'; export const getBuyerMypage = async (): Promise => { const BUYER_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6Imh5c29uZzR1QGdtYWlsLmNvbSIsImlhdCI6MTczOTU1MzczMSwiZXhwIjoxNzQyMTQ1NzMxfQ.6ePJhRS1JUNK9BPIOk9oXrYoggois21uBtGsp4gvKrU'; - console.log('변경된 accessToken:', BUYER_TOKEN); + console.log('구매자 accessToken:', BUYER_TOKEN); // 구매자 토큰으로 변경 localStorage.setItem('accessToken', BUYER_TOKEN); diff --git a/src/constants/queryKeys.ts b/src/constants/queryKeys.ts index e3ddda4..cc0695a 100644 --- a/src/constants/queryKeys.ts +++ b/src/constants/queryKeys.ts @@ -36,42 +36,33 @@ export const getArtistListQuery = () => { }; /** - * 작품 구매자 마이페이지 조회를 위한 쿼리 키 반환 함수 - * @returns 쿼리 키 배열 ['userMypage']을 반환하여 캐시를 사용자별로 관리할 수 있도록 설정 + * 마이페이지 조회를 위한 쿼리 키 반환 함수 + * @returns 쿼리 키 배열 ['Mypage']을 반환하여 캐시를 사용자별로 관리할 수 있도록 설정 * @author 노찬영 */ -export const getBuyerMypageQueryKey = () => ['buyerMypage']; +export const getMypageQueryKey = (role: 'author' | 'buyer') => ['Mypage', role]; /** * 작품 구매자 마이페이지 조회 API를 위한 React Query 설정 함수 * @returns queryKey와 queryFn을 포함한 객체를 반환하여 React Query에서 사용 가능하도록 설정 - * @example - const { data } = useQuery(getUserMypageQuery(123)); * @author 노찬영 */ export const getBuyerMypageQuery = () => { return { - queryKey: getBuyerMypageQueryKey(), - queryFn: () => getBuyerMypage(), // 마이페이지 데이터를 조회하는 함수 + queryKey: getMypageQueryKey('buyer'), + queryFn: () => getBuyerMypage(), // 작품 구매자 마이페이지 데이터를 조회하는 함수 }; }; -/** - * 작가 마이페이지 조회를 위한 쿼리 키 반환 함수 - * @returns 쿼리 키 배열 ['userMypage']을 반환하여 캐시를 사용자별로 관리할 수 있도록 설정 - * @author 노찬영 - */ -export const getAuthorMypageQueryKey = () => ['authorMypage']; - /** * 작가 마이페이지 조회 API를 위한 React Query 설정 함수 * @returns queryKey와 queryFn을 포함한 객체를 반환하여 React Query에서 사용 가능하도록 설정 - * @example - const { data } = useQuery(getUserMypageQuery(123)); * @author 노찬영 */ export const getAuthorMypageQuery = () => { return { - queryKey: getAuthorMypageQueryKey(), - queryFn: () => getAuthorMypage(), // 마이페이지 데이터를 조회하는 함수 + queryKey: getMypageQueryKey('author'), + queryFn: () => getAuthorMypage(), }; }; diff --git a/src/pages/artBuyerPage/hooks/useGetBuyerMypage.ts b/src/pages/artBuyerPage/hooks/useGetBuyerMypage.ts index 2576a32..878f529 100644 --- a/src/pages/artBuyerPage/hooks/useGetBuyerMypage.ts +++ b/src/pages/artBuyerPage/hooks/useGetBuyerMypage.ts @@ -1,7 +1,7 @@ import { useSuspenseQuery } from '@tanstack/react-query'; import { toast } from 'sonner'; import { AxiosError } from 'axios'; -import { getBuyerMypageQuery } from '@/constants/queryKeys'; +import { getMypageQueryKey } from '@/constants/queryKeys'; import { TBuyerMypage } from '@/apis/mypage-buyer/myPage/type'; import { getBuyerMypage } from '@/apis/mypage-buyer/myPage/myPage'; @@ -19,7 +19,7 @@ export const useGetBuyerMypage = () => { isLoading, error, } = useSuspenseQuery({ - queryKey: getBuyerMypageQuery().queryKey, + queryKey: getMypageQueryKey('buyer'), queryFn: () => getBuyerMypage(), staleTime: 1000 * 60 * 30, // 30분 gcTime: 1000 * 60 * 60, // 1시간 diff --git a/src/pages/authorPage/components/menuMyPage/Auction/index.tsx b/src/pages/authorPage/components/menuMyPage/Auction/index.tsx index 70263ea..f7018db 100644 --- a/src/pages/authorPage/components/menuMyPage/Auction/index.tsx +++ b/src/pages/authorPage/components/menuMyPage/Auction/index.tsx @@ -9,7 +9,7 @@ import { import { useGetAuthorMypage } from '@/pages/authorPage/hooks/useGetAuthorMypage'; /** - * @description 작품 구매자의 경매 내역을 표시하는 컴포넌트 + * @description 작가의 경매 내역을 표시하는 컴포넌트 * @author 노찬영 */ diff --git a/src/pages/authorPage/hooks/useGetAuthorMypage.ts b/src/pages/authorPage/hooks/useGetAuthorMypage.ts index 6f9b1c7..b2e158b 100644 --- a/src/pages/authorPage/hooks/useGetAuthorMypage.ts +++ b/src/pages/authorPage/hooks/useGetAuthorMypage.ts @@ -1,7 +1,7 @@ import { useSuspenseQuery } from '@tanstack/react-query'; import { toast } from 'sonner'; import { AxiosError } from 'axios'; -import { getAuthorMypageQuery } from '@/constants/queryKeys'; +import { getMypageQueryKey } from '@/constants/queryKeys'; import { getAuthorMypage } from '@/apis/mypage-author/myPage/myPage'; import { TArtistMypage } from '@/apis/mypage-author/myPage/type'; @@ -19,7 +19,7 @@ export const useGetAuthorMypage = () => { isLoading, error, } = useSuspenseQuery({ - queryKey: getAuthorMypageQuery().queryKey, + queryKey: getMypageQueryKey('author'), queryFn: () => getAuthorMypage(), staleTime: 1000 * 60 * 30, // 30분 gcTime: 1000 * 60 * 60, // 1시간 From c14ac09ac48cf3a1487f44012dcb374683503f85 Mon Sep 17 00:00:00 2001 From: syddl0 <137189866+shroqkf@users.noreply.github.com> Date: Sat, 15 Feb 2025 14:09:45 +0900 Subject: [PATCH 3/4] =?UTF-8?q?Chore:=20=EC=9E=91=EA=B0=80=20=EB=A7=88?= =?UTF-8?q?=EC=9D=B4=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants/queryKeys.ts | 2 +- src/router.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/constants/queryKeys.ts b/src/constants/queryKeys.ts index cc0695a..0e5edf4 100644 --- a/src/constants/queryKeys.ts +++ b/src/constants/queryKeys.ts @@ -62,7 +62,7 @@ export const getBuyerMypageQuery = () => { export const getAuthorMypageQuery = () => { return { queryKey: getMypageQueryKey('author'), - queryFn: () => getAuthorMypage(), + queryFn: () => getAuthorMypage(), // 작가 마이페이지 데이터를 조회하는 함수 }; }; diff --git a/src/router.tsx b/src/router.tsx index 929fc55..6ffa654 100644 --- a/src/router.tsx +++ b/src/router.tsx @@ -35,7 +35,7 @@ type TRoutes = { export const routes: TRoutes[] = [ { path: '/', element:
, isTabBar: true }, { path: '/mypage/art-buyer', element: , isTabBar: true }, - { path: '/mypqge/author', element: , isTabBar: true }, + { path: '/mypage/author', element: , isTabBar: true }, { path: '/test', element: , isTabBar: true }, { path: '/login', element: , isTabBar: true }, From 7b079b83700d9ce3b0f8758b067df592696e2c61 Mon Sep 17 00:00:00 2001 From: syddl0 <137189866+shroqkf@users.noreply.github.com> Date: Sat, 15 Feb 2025 14:20:18 +0900 Subject: [PATCH 4/4] =?UTF-8?q?Fix:=20build=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/router.tsx b/src/router.tsx index a78835e..5d88822 100644 --- a/src/router.tsx +++ b/src/router.tsx @@ -1,7 +1,6 @@ import { Route, Routes } from 'react-router-dom'; -import NotFound from '@pages/notFound.tsx'; import { AuthCheckRoute } from '@components/common/AuthCheckRoute'; -import Home from '@pages/home.tsx'; +import NotFound from './pages/not-found'; import Test from '@pages/test.tsx'; import ArtBuyerPage from './pages/artBuyerPage/ArtBuyerPage'; import AuthorPage from './pages/authorPage/AuthorPage';