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:
Janpeter Visser 2026-04-26 17:56:50 +02:00
parent bc91e3c169
commit 29ed4f2773
5 changed files with 69 additions and 2 deletions

View file

@ -1,3 +1,4 @@
import { cache } from 'react'
import { prisma } from '@/lib/prisma'
const accessFilter = (userId: string) => ({
@ -7,11 +8,11 @@ const accessFilter = (userId: string) => ({
],
})
export async function getAccessibleProduct(productId: string, userId: string) {
export const getAccessibleProduct = cache(async (productId: string, userId: string) => {
return prisma.product.findFirst({
where: { id: productId, ...accessFilter(userId) },
})
}
})
export function productAccessFilter(userId: string) {
return accessFilter(userId)