THE LAST ONE BEFORE THE RELEASE
This commit is contained in:
@@ -1,32 +1,36 @@
|
||||
import { notFound } from 'next/navigation'
|
||||
import { notFound } from "next/navigation"
|
||||
import { ProductDetail } from "@/components/product-detail"
|
||||
import { SAMPLE_PRODUCTS } from "@/lib/sample-products"
|
||||
import { draftMode } from 'next/headers'
|
||||
import { cookies } from "next/headers"
|
||||
|
||||
async function getProduct(id: string, isDraft: boolean) {
|
||||
// In a real application, you would fetch the product from an API or database
|
||||
// For this example, we'll use the SAMPLE_PRODUCTS
|
||||
const product = SAMPLE_PRODUCTS.find(p => p.id === parseInt(id))
|
||||
const product = SAMPLE_PRODUCTS.find((p) => p.id === Number.parseInt(id))
|
||||
|
||||
if (!product) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (isDraft) {
|
||||
// Simulate draft data
|
||||
return {
|
||||
...product,
|
||||
title: `[Draft] ${product.title}`,
|
||||
price: product.price * 0.9, // 10% discount in draft mode
|
||||
price: product.price * 0.9,
|
||||
}
|
||||
}
|
||||
|
||||
return product
|
||||
}
|
||||
|
||||
export default async function ProductPage({ params }: { params: { id: string } }) {
|
||||
const draftModeData = draftMode()
|
||||
const isDraftMode = draftModeData ? draftModeData.isEnabled : false
|
||||
interface ProductPageProps {
|
||||
params: { id: string }
|
||||
}
|
||||
|
||||
export default async function ProductPage({ params }: ProductPageProps) {
|
||||
// Get cookies first
|
||||
const cookieStore = await cookies()
|
||||
const isDraftMode = cookieStore.get("__prerender_bypass")?.value === process.env.PRERENDER_BYPASS_TOKEN
|
||||
|
||||
// Then get product
|
||||
const product = await getProduct(params.id, isDraftMode)
|
||||
|
||||
if (!product) {
|
||||
@@ -36,14 +40,7 @@ export default async function ProductPage({ params }: { params: { id: string } }
|
||||
return (
|
||||
<div className="container mx-auto px-4 py-8">
|
||||
<ProductDetail product={product} />
|
||||
{isDraftMode && (
|
||||
<div className="fixed bottom-0 left-0 w-full bg-yellow-400 text-black p-2 text-center">
|
||||
Preview Mode Enabled - {' '}
|
||||
<a className="underline" href={`/api/disable-preview?id=${params.id}`}>
|
||||
Exit Preview Mode
|
||||
</a>
|
||||
</div>
|
||||
)}
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user