forked from IT-Cotato/12th-OnGil-FE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecommend-product-container.tsx
More file actions
46 lines (41 loc) · 1.39 KB
/
recommend-product-container.tsx
File metadata and controls
46 lines (41 loc) · 1.39 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
import { api } from '@/lib/api-client';
import { Product } from '@/types/domain/product';
import RecommendedProductCard from './recommended-product-card';
import { RecommendCarouselItem } from './recommend-carousel-item';
import { RecommendCarousel } from './recommend-carousel';
import { getMyWishlist } from '@/app/actions/wishlist';
interface RecommendProductContainerProps {
endpoint: string;
heading: string;
}
export default async function RecommendProductContainer({
endpoint,
heading,
}: RecommendProductContainerProps) {
const [productsResult, wishlistResult] = await Promise.allSettled([
api.get<Product[]>(endpoint),
getMyWishlist(),
]);
const products =
productsResult.status === 'fulfilled' ? productsResult.value : [];
const wishlistItems =
wishlistResult.status === 'fulfilled' ? wishlistResult.value : [];
const wishlistByProductId = new Map(
wishlistItems.map((item) => [item.productId, item.wishlistId]),
);
return (
<RecommendCarousel heading={heading}>
{products.map((product) => (
<RecommendCarouselItem key={product.id}>
<RecommendedProductCard
productInfo={{
...product,
isLiked: wishlistByProductId.has(product.id),
wishlistId: wishlistByProductId.get(product.id),
}}
/>
</RecommendCarouselItem>
))}
</RecommendCarousel>
);
}