forked from IT-Cotato/12th-OnGil-FE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecommended-product-card.tsx
More file actions
88 lines (85 loc) · 3.2 KB
/
recommended-product-card.tsx
File metadata and controls
88 lines (85 loc) · 3.2 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
import Image from 'next/image';
import Link from 'next/link';
import { ProductWithWishlist } from '@/types/domain/product';
import { WishlistButton } from '../product/wishlist-button';
export default function RecommendedProductCard({
productInfo,
}: {
productInfo: ProductWithWishlist;
}) {
const href = `/product/${productInfo.id}?from=${encodeURIComponent('/')}`;
const hasDiscount = productInfo.discountRate && productInfo.discountRate > 0;
const isAuction = productInfo.productType === 'SPECIAL_SALE';
const rating = Number.isFinite(productInfo.reviewRating)
? productInfo.reviewRating.toFixed(1)
: '-';
let priceDisplay;
if (hasDiscount) {
if (isAuction) {
// For AUCTION, show final and original price. Discount is on the image.
priceDisplay = (
<div className="flex items-baseline gap-2">
<span className="text-ongil-teal text-xl font-bold">
{productInfo.finalPrice.toLocaleString('ko-KR')}
</span>
{productInfo.price > 0 && (
<span className="font-normal text-black/50 line-through">
{productInfo.price.toLocaleString('ko-KR')}
</span>
)}
</div>
);
} else {
// For NORMAL with discount, show rate and final price.
priceDisplay = (
<div className="text-ongil-teal flex gap-2 text-xl font-bold">
<span>{productInfo.discountRate}%</span>
<span>{productInfo.finalPrice.toLocaleString('ko-KR')}</span>
</div>
);
}
} else {
// For any product with no discount.
priceDisplay = (
<span className="text-ongil-teal text-xl font-bold">
{productInfo.finalPrice.toLocaleString('ko-KR')}
</span>
);
}
return (
<Link href={href} className="block">
<div className="font-pretendard flex flex-col rounded-[10px] border border-[#d9d9d9] pt-6 shadow-md">
<div className="relative self-center">
<Image
src={productInfo.thumbnailImageUrl}
alt={`${productInfo.name} 이미지`}
width={236}
height={264}
className="h-[264px] w-[236px] object-cover"
/>
{isAuction && hasDiscount && (
<div className="absolute right-6 -bottom-7 flex h-14 w-14 items-center justify-center rounded-full bg-transparent text-center text-[40px] font-bold text-red-500">
{productInfo.discountRate}%
</div>
)}
<WishlistButton
productId={productInfo.id}
initialIsLiked={productInfo.isLiked || false}
initialWishlistId={productInfo.wishlistId}
className="absolute top-2 right-2"
/>
</div>
<div className="flex flex-col gap-2 px-4 py-2.5">
<span className="font-bold">{productInfo.brandName}</span>
<span className="truncate text-lg">{productInfo.name}</span>
{priceDisplay}
<div className="font-poppins flex gap-1 text-sm font-semibold text-gray-500">
<img src={'/icons/star.svg'} width={20} height={20} alt="후기" />
<span>{rating}</span>
<span>({productInfo.reviewCount})</span>
</div>
</div>
</div>
</Link>
);
}