-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
106 additions
and
17 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
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,17 +1,5 @@ | ||
import { Text } from '@/shared/components/shadcn/Text'; | ||
import React from 'react'; | ||
|
||
export default function Layout({ children }: { children: React.ReactNode }) { | ||
return ( | ||
<div className="flex-1 w-full flex flex-col py-4"> | ||
<Text typography="h2" className="mb-6 text-center"> | ||
상세페이지 | ||
</Text> | ||
<Text typography="h4">오늘의 할인율 TOP5</Text> | ||
<Text typography="p" className="md:text-lg text-gray-500"> | ||
오늘 할인율이 가장 높은 상품리스트 | ||
</Text> | ||
{children} | ||
</div> | ||
); | ||
return <div className="flex-1 w-full flex flex-col py-4">{children}</div>; | ||
} |
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,13 @@ | ||
import { ProductDetail } from '@/features/productDetail/components/ProductDetail'; | ||
import { Text } from '@/shared/components/shadcn/Text'; | ||
|
||
export default function ProductDetail({ params }: { params: { productId: number } }) { | ||
console.log(params); | ||
export default function ProductDetailPage({ params }: { params: { productId: number } }) { | ||
return ( | ||
<main> | ||
<Text typography="h4" className="md:text-2xl"> | ||
상페에지이 입니다. | ||
ID: {params.productId} 제품에 대한 상세페이지 입니다. | ||
</Text> | ||
<ProductDetail productId={params.productId} /> | ||
</main> | ||
); | ||
} |
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,26 @@ | ||
import { Macbook } from '@/features/product/api/getProductList'; | ||
|
||
export type GetProductDetailResponse = Macbook & ProductDetailInfo; | ||
|
||
export type ProductDetailInfo = { | ||
allTimeHighPrice: number; | ||
allTimeLowPrice: number; | ||
averagePrice: number; | ||
priceInfos: { | ||
date: string; | ||
currentPrice: number; | ||
}[]; | ||
}; | ||
|
||
// 클라이언트 상태 관리를 위한 api 호출함수 | ||
// export const getProductDetailUrl = (productId: number) => `/api/products/${productId}`; | ||
|
||
// export const getProductDetail = async (productId: number): Promise<GetProductDetailResponse> => { | ||
// const url = `${getProductDetailUrl(productId)}`; | ||
|
||
// const response = await fetch(url); | ||
|
||
// const data = (await response.json()) as GetProductDetailResponse; | ||
|
||
// return data; | ||
// }; |
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,32 @@ | ||
'use client'; | ||
|
||
import dynamic from 'next/dynamic'; | ||
import 'chart.js/auto'; | ||
|
||
const Line = dynamic(() => import('react-chartjs-2').then((mod) => mod.Line), { | ||
ssr: false, | ||
}); | ||
|
||
const LineChart = ({ priceInfos }: { priceInfos: { date: string; currentPrice: number }[] }) => { | ||
const data = { | ||
labels: priceInfos.map((info) => info.date), | ||
datasets: [ | ||
{ | ||
label: '가격 변동 추이', | ||
data: priceInfos.map((info) => info.currentPrice), | ||
fill: false, | ||
borderColor: 'rgb(75, 192, 192)', | ||
tension: 0.1, | ||
stepped: true, | ||
}, | ||
], | ||
}; | ||
|
||
return ( | ||
<div className="w-full h-auto"> | ||
<h1>Example 1: Line Chart</h1> | ||
<Line data={data} /> | ||
</div> | ||
); | ||
}; | ||
export default LineChart; |
36 changes: 36 additions & 0 deletions
36
src/features/productDetail/components/ProductDetail/index.tsx
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,36 @@ | ||
import { Text } from '@/shared/components/shadcn/Text'; | ||
import LineChart from '../LineChart'; | ||
import { API_BASE_URL } from '@/shared/api/constants'; | ||
import { GetProductDetailResponse } from '../../api/getProductDetail'; | ||
|
||
// server component | ||
|
||
export const ProductDetail = async ({ productId }: { productId: number }) => { | ||
try { | ||
const response = await fetch(`${API_BASE_URL}/api/v1/products/macbook_pro/${productId}`); | ||
if (!response.ok) { | ||
throw new Error(`서버에서 데이터를 가져오는 데 실패했습니다. 상태 코드: ${response.status}`); | ||
} | ||
|
||
const data = (await response.json()) as GetProductDetailResponse; | ||
|
||
return ( | ||
<div> | ||
<div> | ||
<Text>{data?.category}</Text> | ||
<Text>{data?.title}</Text> | ||
<Text>평균가: {data?.averagePrice}</Text> | ||
<Text>최고가: {data?.allTimeHighPrice}</Text> | ||
<Text>최저가: {data?.allTimeLowPrice}</Text> | ||
</div> | ||
<Text typography="h3" className="mt-12"> | ||
그래프 | ||
</Text> | ||
{data?.priceInfos && <LineChart priceInfos={data.priceInfos} />} | ||
</div> | ||
); | ||
} catch (error) { | ||
console.error(error); | ||
return <Text>제품 정보를 불러오는 중 오류가 발생했습니다.</Text>; | ||
} | ||
}; |
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