fix: resolve slug fallback rendering for demo/gusto-brasserie and add root [slug] routing
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,4 @@
|
|||||||
|
import PublicMenuPage, { generateMetadata } from "@/app/menu/[slug]/page";
|
||||||
|
|
||||||
|
export { generateMetadata };
|
||||||
|
export default PublicMenuPage;
|
||||||
@@ -2,6 +2,7 @@ import type { Metadata } from "next";
|
|||||||
import { notFound } from "next/navigation";
|
import { notFound } from "next/navigation";
|
||||||
import { supabase } from "@/lib/supabase";
|
import { supabase } from "@/lib/supabase";
|
||||||
import { PublicMenuClient, type MenuCategory, type MenuItem, type RestaurantData } from "@/components/PublicMenuClient";
|
import { PublicMenuClient, type MenuCategory, type MenuItem, type RestaurantData } from "@/components/PublicMenuClient";
|
||||||
|
import { DEMO_RESTAURANT, DEMO_CATEGORIES } from "@/lib/demo-data";
|
||||||
import type { ThemeConfig } from "@menulio/shared";
|
import type { ThemeConfig } from "@menulio/shared";
|
||||||
|
|
||||||
type PageProps = {
|
type PageProps = {
|
||||||
@@ -37,6 +38,8 @@ export async function generateMetadata({ params }: PageProps): Promise<Metadata>
|
|||||||
|
|
||||||
if (bySlug) {
|
if (bySlug) {
|
||||||
restaurant = bySlug;
|
restaurant = bySlug;
|
||||||
|
} else if (slug === "demo" || slug === "gusto-brasserie") {
|
||||||
|
restaurant = DEMO_RESTAURANT;
|
||||||
} else {
|
} else {
|
||||||
const { data: domainRow } = await supabase
|
const { data: domainRow } = await supabase
|
||||||
.from("domains")
|
.from("domains")
|
||||||
@@ -93,24 +96,66 @@ export default async function PublicMenuPage({ params, searchParams }: PageProps
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!restaurant) notFound();
|
if (!restaurant) {
|
||||||
|
if (slug === "demo" || slug === "gusto-brasserie") {
|
||||||
|
return (
|
||||||
|
<PublicMenuClient
|
||||||
|
restaurant={DEMO_RESTAURANT}
|
||||||
|
categories={DEMO_CATEGORIES}
|
||||||
|
initialThemeKey={themeParam || "coastal"}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
notFound();
|
||||||
|
}
|
||||||
|
|
||||||
const { data: menu } = await supabase
|
// Find menu (published or any available menu)
|
||||||
|
let { data: menu } = await supabase
|
||||||
.from("menus")
|
.from("menus")
|
||||||
.select("id, name, locations!inner(restaurant_id)")
|
.select("id, name, locations!inner(restaurant_id)")
|
||||||
.eq("locations.restaurant_id", restaurant.id)
|
.eq("locations.restaurant_id", restaurant.id)
|
||||||
.eq("is_published", true)
|
.eq("is_published", true)
|
||||||
.maybeSingle();
|
.maybeSingle();
|
||||||
|
|
||||||
if (!menu) notFound();
|
if (!menu) {
|
||||||
|
const { data: anyMenu } = await supabase
|
||||||
|
.from("menus")
|
||||||
|
.select("id, name, locations!inner(restaurant_id)")
|
||||||
|
.eq("locations.restaurant_id", restaurant.id)
|
||||||
|
.maybeSingle();
|
||||||
|
menu = anyMenu;
|
||||||
|
}
|
||||||
|
|
||||||
const { data: rawCategories } = await supabase
|
let categories: MenuCategory[] = [];
|
||||||
.from("menu_categories")
|
|
||||||
.select("id, name, description, is_active, menu_items(id, name, description, price, image_url, is_active)")
|
if (menu) {
|
||||||
.eq("menu_id", menu.id)
|
const { data: rawCategories } = await supabase
|
||||||
.eq("is_active", true)
|
.from("menu_categories")
|
||||||
.order("sort_order", { ascending: true })
|
.select("id, name, description, is_active, menu_items(id, name, description, price, image_url, is_active)")
|
||||||
.returns<MenuCategoryRow[]>();
|
.eq("menu_id", menu.id)
|
||||||
|
.eq("is_active", true)
|
||||||
|
.order("sort_order", { ascending: true })
|
||||||
|
.returns<MenuCategoryRow[]>();
|
||||||
|
|
||||||
|
categories = (rawCategories ?? []).map((cat) => ({
|
||||||
|
id: cat.id,
|
||||||
|
name: cat.name,
|
||||||
|
description: cat.description,
|
||||||
|
is_active: cat.is_active,
|
||||||
|
menu_items: (cat.menu_items ?? [])
|
||||||
|
.filter((item) => item.is_active)
|
||||||
|
.map((item): MenuItem => ({
|
||||||
|
id: item.id,
|
||||||
|
name: item.name,
|
||||||
|
description: item.description,
|
||||||
|
price: item.price,
|
||||||
|
image_url: item.image_url,
|
||||||
|
is_active: item.is_active,
|
||||||
|
})),
|
||||||
|
}));
|
||||||
|
} else if (slug === "demo" || slug === "gusto-brasserie") {
|
||||||
|
categories = DEMO_CATEGORIES;
|
||||||
|
}
|
||||||
|
|
||||||
const { data: themeRow } = await supabase
|
const { data: themeRow } = await supabase
|
||||||
.from("restaurant_themes")
|
.from("restaurant_themes")
|
||||||
@@ -122,23 +167,6 @@ export default async function PublicMenuPage({ params, searchParams }: PageProps
|
|||||||
const themeKey = themeParam || themeRelation?.key || "elegant";
|
const themeKey = themeParam || themeRelation?.key || "elegant";
|
||||||
const customConfig = (themeRow?.overrides as Partial<ThemeConfig>) || themeRelation?.config;
|
const customConfig = (themeRow?.overrides as Partial<ThemeConfig>) || themeRelation?.config;
|
||||||
|
|
||||||
const categories: MenuCategory[] = (rawCategories ?? []).map((cat) => ({
|
|
||||||
id: cat.id,
|
|
||||||
name: cat.name,
|
|
||||||
description: cat.description,
|
|
||||||
is_active: cat.is_active,
|
|
||||||
menu_items: (cat.menu_items ?? [])
|
|
||||||
.filter((item) => item.is_active)
|
|
||||||
.map((item): MenuItem => ({
|
|
||||||
id: item.id,
|
|
||||||
name: item.name,
|
|
||||||
description: item.description,
|
|
||||||
price: item.price,
|
|
||||||
image_url: item.image_url,
|
|
||||||
is_active: item.is_active,
|
|
||||||
})),
|
|
||||||
}));
|
|
||||||
|
|
||||||
const restaurantData: RestaurantData = {
|
const restaurantData: RestaurantData = {
|
||||||
id: restaurant.id,
|
id: restaurant.id,
|
||||||
name: restaurant.name,
|
name: restaurant.name,
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"cli": {
|
||||||
|
"version": ">= 22.0.0",
|
||||||
|
"appVersionSource": "remote"
|
||||||
|
},
|
||||||
|
"build": {
|
||||||
|
"development": {
|
||||||
|
"developmentClient": true,
|
||||||
|
"distribution": "internal"
|
||||||
|
},
|
||||||
|
"preview": {
|
||||||
|
"distribution": "internal"
|
||||||
|
},
|
||||||
|
"production": {
|
||||||
|
"autoIncrement": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"submit": {
|
||||||
|
"production": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user