-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from SOPT-all/develop
merge to main
- Loading branch information
Showing
16 changed files
with
167 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,26 @@ | ||
import instance from '@apis/instance'; | ||
|
||
interface ProductResponse { | ||
interface ProductInfoType { | ||
productId: number; | ||
productImage: string; | ||
detail: string; | ||
priceOriginal: number; | ||
percent: number; | ||
priceDiscount: number; | ||
percent: number; | ||
isCoupon: boolean; | ||
categoryName: string; | ||
reviewCount: number; | ||
rating: number; | ||
} | ||
|
||
interface RelatedProductsResponse { | ||
interface ProductResponse { | ||
success: boolean; | ||
data: { | ||
products: ProductResponse[]; | ||
}; | ||
data: ProductInfoType; | ||
error: string | null; | ||
} | ||
|
||
const fetchRelatedProducts = async (productId: number): Promise<ProductResponse[]> => { | ||
const response = await instance.get<RelatedProductsResponse>(`/api/products/${productId}/related`); | ||
return response.data.data.products; | ||
const fetchProduct = async (productId: number): Promise<ProductResponse> => { | ||
const response = await instance.get<ProductResponse>(`/api/products/${productId}`); | ||
return response.data; | ||
}; | ||
|
||
export default fetchRelatedProducts; | ||
export default fetchProduct; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import instance from '@apis/instance'; | ||
|
||
interface ProductResponse { | ||
productId: number; | ||
productImage: string; | ||
detail: string; | ||
priceOriginal: number; | ||
percent: number; | ||
priceDiscount: number; | ||
isCoupon: boolean; | ||
categoryName: string; | ||
reviewCount: number; | ||
rating: number; | ||
} | ||
|
||
interface RelatedProductsResponse { | ||
success: boolean; | ||
data: { | ||
products: ProductResponse[]; | ||
}; | ||
error: string | null; | ||
} | ||
|
||
const fetchRelatedProducts = async (productId: number): Promise<ProductResponse[]> => { | ||
const response = await instance.get<RelatedProductsResponse>(`/api/products/${productId}/related`); | ||
return response.data.data.products; | ||
}; | ||
|
||
export default fetchRelatedProducts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import fetchProduct from '@apis/productPage/product/getProduct'; | ||
import dummyProductResponse from '@constants/dummyProductResponse'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import fetchRelatedProducts from './getProduct'; | ||
|
||
const useRelatedProducts = (productId: number) => { | ||
return useQuery({ | ||
queryKey: ['relatedProducts', productId], | ||
queryFn: () => fetchRelatedProducts(productId), | ||
initialData: [], | ||
const useProductDetail = (productId: number) => | ||
useQuery({ | ||
queryKey: ['product', productId], | ||
queryFn: () => fetchProduct(productId), | ||
initialData: dummyProductResponse, // 더미데이터를 initialData로 설정해 서버 요청 실패시에도 해당 데이터로 유지하도록 설정 | ||
}); | ||
}; | ||
|
||
export default useRelatedProducts; | ||
export default useProductDetail; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import fetchRelatedProducts from './getRelatedProducts'; | ||
|
||
const useRelatedProducts = (productId: number) => { | ||
return useQuery({ | ||
queryKey: ['relatedProducts', productId], | ||
queryFn: () => fetchRelatedProducts(productId), | ||
initialData: [], | ||
}); | ||
}; | ||
|
||
export default useRelatedProducts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const dummyProductResponse = { | ||
success: true, | ||
data: { | ||
productId: 1, | ||
productImage: 'https://ae01.alicdn.com/kf/S709d4d4778ea430c87c0bf0a6574fa8dz.jpg_220x220q75.jpg_.webp', | ||
detail: | ||
'Toocki C타입 to C타입 케이블, 100W PD 고속 충전 충전기, USB C to USB C 디스플레이 케이블, 샤오미 POCO F3 리얼미 맥북 아이패드용', | ||
priceOriginal: 6812, | ||
percent: 60, | ||
priceDiscount: 2700, | ||
isCoupon: true, | ||
categoryName: 'Electronics', | ||
reviewCount: 8, | ||
rating: 3.25, | ||
}, | ||
error: null, | ||
}; | ||
|
||
export default dummyProductResponse; |
This file was deleted.
Oops, something went wrong.