Skip to content
Open
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
7ff20b1
init : 5주차 과제 코드 옮겨오기
seorinnn Jul 31, 2024
6cd9b5c
feat : ServerProvider.js 추가
seorinnn Aug 1, 2024
8e6d944
feat : ServerProvider 적용
seorinnn Aug 1, 2024
89e850a
feat : 선택한 서버 주소로 카테고리 목록 조회하도록 변경
seorinnn Aug 1, 2024
2706b6f
feat : 상단 네비게이션 바에 API 선택하는 select 추가
seorinnn Aug 1, 2024
d7b4d80
feat : 첫 번째 API 선택 시 카테고리 목록 조회되도록 임시 모킹 핸들러 설정
seorinnn Aug 1, 2024
0167b7b
delete : 주석 삭제
seorinnn Aug 1, 2024
430c021
feat : 선택한 서버 주소로 상품 목록 조회하도록 변경
seorinnn Aug 1, 2024
7b7b30d
feat : 첫 번째 API 선택 시 상품 목록 조회되도록 임시 모킹 핸들러 설정
seorinnn Aug 1, 2024
ec0a6b0
feat : 선택한 서버 주소로 상품 상세 정보 조회하도록 변경
seorinnn Aug 1, 2024
436a227
feat : 첫 번째 API 선택 시 상품 상세 정보 및 옵션 조회되도록 임시 모킹 핸들러 설정
seorinnn Aug 1, 2024
d6122f0
feat : 선택한 서버 주소로 상품 옵션 조회하도록 변경
seorinnn Aug 1, 2024
b60dadc
feat : 로그인 페이지에 카카오로그인 버튼 추가
seorinnn Aug 2, 2024
b753794
feat : 카카오로그인 임시 구현
seorinnn Aug 2, 2024
b4f83cc
chore : gh-pages 패키지 설치
seorinnn Aug 2, 2024
d6a5eb0
chore : package.json homepage 속성 추가 및 deploy 설정 추가
seorinnn Aug 2, 2024
6641190
docs : 4단계 질문 README.md에 답변 작성
seorinnn Aug 6, 2024
ee75565
feat : 사용자별 포인트 조회 기능 구현
seorinnn Aug 6, 2024
043cfd5
docs : 포인트 기능 API 명세 README.md에 추가
seorinnn Aug 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/api/hooks/useGetProductDetail.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useSuspenseQuery } from '@tanstack/react-query';
import { useServer } from '@/provider/ServerProvider';

import type { ProductData } from '@/types';

import { BASE_URL, fetchInstance } from '../instance';
import { fetchInstance } from '../instance';

export type ProductDetailRequestParams = {
productId: string;
Expand All @@ -12,19 +13,25 @@ type Props = ProductDetailRequestParams;

export type GoodsDetailResponseData = ProductData;

export const getProductDetailPath = (productId: string) => `${BASE_URL}/api/products/${productId}`;
export const getProductDetailPath = (serverURL: string, productId: string) =>
`${serverURL}/api/products/${productId}`;

export const getProductDetail = async (params: ProductDetailRequestParams) => {
export const getProductDetail = async (
serverURL: string,
params: ProductDetailRequestParams
) => {
const response = await fetchInstance.get<GoodsDetailResponseData>(
getProductDetailPath(params.productId),
getProductDetailPath(serverURL, params.productId)
);

return response.data;
};

export const useGetProductDetail = ({ productId }: Props) => {
const { serverURL } = useServer();

return useSuspenseQuery({
queryKey: [getProductDetailPath(productId)],
queryFn: () => getProductDetail({ productId }),
queryKey: [serverURL, 'product', productId],
queryFn: () => getProductDetail(serverURL, { productId }),
});
};