feat: show active product name in navbar, links to product page
Sub-layout sets product in Zustand store; NavBar reads it. getAccessibleProduct wrapped with React cache to avoid double DB call. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
bc91e3c169
commit
29ed4f2773
5 changed files with 69 additions and 2 deletions
25
app/(app)/products/[id]/layout.tsx
Normal file
25
app/(app)/products/[id]/layout.tsx
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { redirect, notFound } from 'next/navigation'
|
||||
import { getSession } from '@/lib/auth'
|
||||
import { getAccessibleProduct } from '@/lib/product-access'
|
||||
import { SetCurrentProduct } from '@/components/shared/set-current-product'
|
||||
|
||||
interface Props {
|
||||
children: React.ReactNode
|
||||
params: Promise<{ id: string }>
|
||||
}
|
||||
|
||||
export default async function ProductLayout({ children, params }: Props) {
|
||||
const { id } = await params
|
||||
const session = await getSession()
|
||||
if (!session.userId) redirect('/login')
|
||||
|
||||
const product = await getAccessibleProduct(id, session.userId)
|
||||
if (!product) notFound()
|
||||
|
||||
return (
|
||||
<>
|
||||
<SetCurrentProduct id={id} name={product.name} />
|
||||
{children}
|
||||
</>
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue