80 lines
2.8 KiB
TypeScript
80 lines
2.8 KiB
TypeScript
import { prisma } from "@/app/lib/prisma";
|
||
import MenuView from "./components/MenuView";
|
||
|
||
export const dynamic = 'force-dynamic';
|
||
|
||
export default async function Page() {
|
||
try {
|
||
const restaurant = await prisma.restaurant.findFirst({
|
||
orderBy: { createdAt: 'desc' },
|
||
include: {
|
||
categories: {
|
||
include: {
|
||
items: true,
|
||
},
|
||
orderBy: {
|
||
createdAt: 'asc',
|
||
},
|
||
},
|
||
},
|
||
});
|
||
|
||
if (!restaurant) {
|
||
return (
|
||
<div style={{ background: '#000', color: '#fff', height: '100vh', display: 'flex', alignItems: 'center', justifyContent: 'center', textAlign: 'center', padding: '20px' }}>
|
||
<div>
|
||
<h1 style={{ color: 'var(--gold)' }}>LUNA</h1>
|
||
<p>Henüz menü verisi bulunamadı veya veritabanı bağlantısı kurulamadı.</p>
|
||
<p style={{ fontSize: '0.8rem', color: '#666' }}>Lütfen admin panelinden bir restoran ve kategori oluşturulduğundan emin olun.</p>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
// Map database structure to the structure expected by MenuView
|
||
const data = {
|
||
restaurant_name: restaurant.name,
|
||
footer_note: restaurant.footerNote || "",
|
||
categories: restaurant.categories.map(cat => ({
|
||
id: cat.id,
|
||
title: cat.title,
|
||
externalId: cat.externalId,
|
||
items: (cat.items || []).map(item => ({
|
||
name: item.name,
|
||
ingredients: item.ingredients,
|
||
tasteProfile: item.tasteProfile,
|
||
grapeVariety: item.grapeVariety,
|
||
price: item.price as any,
|
||
})),
|
||
})),
|
||
};
|
||
|
||
if (data.categories.length === 0) {
|
||
return (
|
||
<div style={{ background: '#000', color: '#fff', height: '100vh', display: 'flex', alignItems: 'center', justifyContent: 'center', textAlign: 'center', padding: '20px' }}>
|
||
<div>
|
||
<h1 style={{ color: 'var(--gold)' }}>LUNA</h1>
|
||
<p>Restoran bulundu ancak henüz hiç kategori eklenmemiş.</p>
|
||
<p style={{ fontSize: '0.8rem', color: '#666' }}>Lütfen admin panelinden kategori ve ürün ekleyin.</p>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
return <MenuView data={data} />;
|
||
} catch (error: any) {
|
||
console.error("Database error:", error);
|
||
return (
|
||
<div style={{ background: '#000', color: '#fff', height: '100vh', display: 'flex', alignItems: 'center', justifyContent: 'center', textAlign: 'center', padding: '20px' }}>
|
||
<div>
|
||
<h1 style={{ color: 'var(--gold)' }}>LUNA</h1>
|
||
<p>Veritabanı bağlantısı sırasında bir hata oluştu.</p>
|
||
<pre style={{ fontSize: '0.7rem', color: '#ff4d4d', marginTop: '10px', overflowX: 'auto', maxWidth: '80vw' }}>
|
||
{error.message || "Bilinmeyen hata"}
|
||
</pre>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
}
|