Initial commit: Hoomat storefront with Meshkee API and static-image slots.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import type { Metadata } from "next";
|
||||
import { notFound } from "next/navigation";
|
||||
import { StoreDetailClient } from "@/app/components/store-detail-client";
|
||||
import {
|
||||
getProductById,
|
||||
getProductTechnicalInfo,
|
||||
getStoreItemVariant,
|
||||
listComments,
|
||||
listStoreItems,
|
||||
} from "@/lib/meshkee/api";
|
||||
import { storeItemName } from "@/lib/meshkee/format";
|
||||
|
||||
type PageProps = {
|
||||
params: Promise<{ variantId: string; slug?: string[] }>;
|
||||
};
|
||||
|
||||
export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
|
||||
const { variantId } = await params;
|
||||
try {
|
||||
const variant = await getStoreItemVariant(variantId);
|
||||
const name = storeItemName(variant);
|
||||
return {
|
||||
title: `${name} | مبلمان هومت`,
|
||||
description: `خرید ${name} از فروشگاه مبلمان هومت`,
|
||||
};
|
||||
} catch {
|
||||
return { title: "محصول | مبلمان هومت" };
|
||||
}
|
||||
}
|
||||
|
||||
export default async function StoreDetailPage({ params }: PageProps) {
|
||||
const { variantId } = await params;
|
||||
|
||||
let variant;
|
||||
try {
|
||||
variant = await getStoreItemVariant(variantId);
|
||||
} catch {
|
||||
notFound();
|
||||
}
|
||||
|
||||
const [{ product }, technical, comments] = await Promise.all([
|
||||
getProductById(variant.productId),
|
||||
getProductTechnicalInfo(variant.productId).catch(() => ({
|
||||
form: null,
|
||||
values: [],
|
||||
})),
|
||||
listComments({ entityType: "product", entityId: variant.productId }).catch(
|
||||
() => [],
|
||||
),
|
||||
]);
|
||||
|
||||
const similarResponse = await listStoreItems({
|
||||
page: 1,
|
||||
pageSize: 8,
|
||||
categoryId: product.categoryId || undefined,
|
||||
}).catch(() => ({ items: [] as Awaited<ReturnType<typeof listStoreItems>>["items"] }));
|
||||
|
||||
const similar = similarResponse.items
|
||||
.filter((item) => item.id !== variant.id)
|
||||
.slice(0, 4);
|
||||
|
||||
return (
|
||||
<main className="container">
|
||||
<StoreDetailClient
|
||||
variant={variant}
|
||||
product={product}
|
||||
technical={technical}
|
||||
comments={comments}
|
||||
similar={similar}
|
||||
/>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user