forked from IT-Cotato/12th-OnGil-FE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproduct-detail-view.tsx
More file actions
181 lines (169 loc) · 5.18 KB
/
product-detail-view.tsx
File metadata and controls
181 lines (169 loc) · 5.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
'use client';
import { useState } from 'react';
import {
ProductImageSlider,
ProductInfo,
ProductBottomBar,
ProductTab,
ProductInteractionProvider,
ProductStickyContainer,
ProductHeader,
} from '@/components/product';
import { ScrollToTop } from '@/components/ui/scroll-to-top';
import ProductDescription from '@/components/product/descriptions/product-description';
import { ProductSizeContent } from '@/components/product/size/product-size-content';
import ProductReviewContent from '@/components/product/review/review-section';
import {
Product,
ProductWithWishlist,
MaterialDescription,
ProductOption,
} from '@/types/domain/product';
import { ReviewStatsData } from '@/types/domain/review';
import { UserBodyInfo, SizeAnalysisResult } from '@/types/domain/size';
const ProductInquiryContent = () => (
<div className="rounded-lg bg-gray-50 py-20 text-center text-gray-500">
<p>문의 영역입니다.</p>
<p className="mt-2 text-sm">이곳에 문의 리스트 컴포넌트가 들어갑니다.</p>
</div>
);
interface ProductDetailProps extends Omit<
Product,
'viewCount' | 'purchaseCount' | 'reviewCount'
> {
viewCount?: number;
purchaseCount?: number;
reviewCount?: number;
materialDescription?: MaterialDescription;
materialOriginal?: string;
reviewSummary?: ReviewStatsData;
monthReviewSummary?: ReviewStatsData;
categoryId?: string | number;
options?: ProductOption[];
imageUrls?: string[];
}
type ProductDetailViewProps = {
product: ProductDetailProps;
similarProducts: Product[];
userInfo: UserBodyInfo | null;
analysisData: SizeAnalysisResult | null;
productReviewSummary?: ReviewStatsData;
backHref?: string;
} & Pick<ProductWithWishlist, 'isLiked' | 'wishlistId'>;
export default function ProductDetailView({
product,
similarProducts,
userInfo,
analysisData,
productReviewSummary,
backHref,
isLiked = false,
wishlistId,
}: ProductDetailViewProps) {
const [activeTab, setActiveTab] = useState('desc');
const availableSizes = [
...new Set((product.options ?? []).map((option) => option.size)),
];
const availableColors = [
...new Set((product.options ?? []).map((option) => option.color)),
];
const recommendedSize =
analysisData?.recommendedSizes.find((size) =>
availableSizes.includes(size),
) ?? undefined;
// 리뷰 섹션에 전달할 상품 정보 구성
const reviewProductInfo = {
productId: Number(product.id),
name: product.name,
materialDescription: product.materialDescription,
materialName: product.materialOriginal,
availableOptions: {
sizes: availableSizes,
colors: availableColors,
},
recommendedSize,
};
// 리뷰 통계 데이터 (없을 경우 기본값 설정)
const reviewStats = productReviewSummary ||
product.reviewSummary || {
averageRating: 0,
initialReviewCount: 0,
oneMonthReviewCount: 0,
sizeSummary: {
category: '사이즈',
totalCount: 0,
topAnswer: null,
topAnswerCount: 0,
answerStats: [],
},
colorSummary: {
category: '색감',
totalCount: 0,
topAnswer: null,
topAnswerCount: 0,
answerStats: [],
},
materialSummary: {
category: '소재',
totalCount: 0,
topAnswer: null,
topAnswerCount: 0,
answerStats: [],
},
};
return (
<div className="relative min-h-screen bg-white pb-32">
<ProductInteractionProvider key={product.id}>
<ProductHeader categoryID={product.categoryId} backHref={backHref} />
{/* 상단: 이미지 슬라이더 & 기본 정보 */}
<ProductImageSlider
imageUrls={product.imageUrls ?? [product.thumbnailImageUrl]}
/>
<ProductInfo product={product} />
{/* 중단: Sticky 탭 & 가변 컨텐츠 */}
<ProductStickyContainer
tabBarSlot={
<ProductTab
activateTab={activeTab}
onTabChange={setActiveTab}
reviewCount={
reviewStats.initialReviewCount + reviewStats.oneMonthReviewCount
}
/>
}
>
{/* 탭 상태에 따른 조건부 렌더링 */}
<div className="min-h-[500px]">
{activeTab === 'desc' && (
<ProductDescription
product={product}
similarProducts={similarProducts}
/>
)}
{activeTab === 'size' && (
<ProductSizeContent
userInfo={userInfo}
analysisData={analysisData}
/>
)}
{activeTab === 'inquiry' && <ProductInquiryContent />}
{activeTab === 'review' && (
<ProductReviewContent
productInfo={reviewProductInfo}
stats={reviewStats}
monthStats={product.monthReviewSummary}
/>
)}
</div>
</ProductStickyContainer>
{/* 플로팅 요소 */}
<ProductBottomBar
product={product}
initialIsLiked={isLiked}
initialWishlistId={wishlistId}
/>
<ScrollToTop />
</ProductInteractionProvider>
</div>
);
}