forked from IT-Cotato/12th-OnGil-FE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecommended-brand-client.tsx
More file actions
54 lines (46 loc) · 1.59 KB
/
recommended-brand-client.tsx
File metadata and controls
54 lines (46 loc) · 1.59 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
'use client';
import { useState } from 'react';
import { BrandWithProducts } from '@/types/domain/brand';
import RecommendedBrandHeader from './recommended-brand-header';
import RecommendedBrandGridCard from './recommended-brand-grid-card';
import { getLocaleFromDocument, t } from '@/lib/i18n';
import { ProductWithWishlist } from '@/types/domain/product';
type BrandWithWishlistProducts = Omit<BrandWithProducts, 'products'> & {
products: ProductWithWishlist[];
};
interface RecommendedBrandClientProps {
brands: BrandWithWishlistProducts[];
}
export default function RecommendedBrandClient({
brands,
}: RecommendedBrandClientProps) {
const [selectedIndex, setSelectedIndex] = useState<number>(0);
const locale = getLocaleFromDocument();
if (brands.length === 0) return null;
const currentBrand = brands[selectedIndex];
const currentProducts = currentBrand?.products || [];
return (
<div className="flex w-full flex-col p-5">
<RecommendedBrandHeader
brands={brands}
onClick={setSelectedIndex}
selectedIndex={selectedIndex}
/>
<div className="mt-4">
<div className="mt-2 w-full">
{currentProducts.length > 0 ? (
<ul className="grid w-full grid-cols-2 justify-items-center gap-4">
{currentProducts.map((product) => (
<li key={product.id}>
<RecommendedBrandGridCard product={product} />
</li>
))}
</ul>
) : (
<p>{t(locale, 'recommendedBrand.noProducts')}</p>
)}
</div>
</div>
</div>
);
}