feat: admin panel CRUD, Cloudinary upload, logo, user management

This commit is contained in:
mstfyldz
2026-06-05 17:38:01 +03:00
parent 53eeeee474
commit 5e4e2f0db9
43 changed files with 3917 additions and 281 deletions
+48 -266
View File
@@ -1,271 +1,53 @@
"use client";
import prisma from "@/lib/prisma";
import MenuClient from "./MenuClient";
import { MenuCategory } from "@/data/menu";
import { useEffect, useState, useRef } from "react";
import { motion, AnimatePresence } from "framer-motion";
import { menuData, MenuItem as MenuItemType } from "@/data/menu";
import { CategoryNav } from "@/components/CategoryNav";
import { MenuItem } from "@/components/MenuItem";
async function getMenuData(): Promise<MenuCategory[]> {
const dbCategories = await prisma.categories.findMany({
where: { status: 1 },
orderBy: { order_num: "asc" },
});
export const CATEGORY_ICONS: Record<string, string> = {
"kahvaltiliklar": "🌅",
"kaseler": "🥗",
"burger-ve-sandvic": "🍔",
"pizzalar": "🍕",
"makarnalar": "🍝",
"baslangiclar": "🧆",
"salatalar": "🥬",
"ana-yemekler": "🍽️",
"tatlilar": "🍮",
"i̇mza-kokteyller": "🍹",
"klasik-kokteyller": "🍸",
"biralar": "🍺",
"shotlar": "🥃",
"sise-ve-kadeh-alkollu": "🥂",
"saraplar": "🍷",
"cerezler": "🥜",
"alkolsuz-i̇cecekler": "🧃",
"sicak-kahveler": "☕",
"soguk-kahveler": "🧊",
"ekstralar": "✨",
};
const dbProducts = await prisma.products.findMany({
where: { status: 1 },
orderBy: [{ category_id: "asc" }, { id: "asc" }],
});
export default function MenuPage() {
const [activeCategoryId, setActiveCategoryId] = useState<string>(
menuData[0]?.id || ""
);
const [selectedItem, setSelectedItem] = useState<MenuItemType | null>(null);
const sectionRefs = useRef<(HTMLElement | null)[]>([]);
useEffect(() => {
const observer = new IntersectionObserver(
(entries) => {
const hit = entries.find((e) => e.isIntersecting);
if (hit) setActiveCategoryId(hit.target.id);
},
{ root: null, rootMargin: "-100px 0px -62% 0px", threshold: 0 }
);
sectionRefs.current.forEach((ref) => ref && observer.observe(ref));
return () => observer.disconnect();
}, []);
useEffect(() => {
if (selectedItem) {
document.body.style.overflow = "hidden";
} else {
document.body.style.overflow = "unset";
}
return () => {
document.body.style.overflow = "unset";
return dbCategories.map((cat) => {
const categoryProducts = dbProducts.filter((p) => p.category_id === cat.id);
return {
id: cat.slug,
title: cat.name_tr,
items: categoryProducts.map((p) => ({
id: p.id.toString(),
name: p.name_tr,
description: p.description_tr,
price: p.price.toString() + " ₺",
image: p.image_url || '/default-product.png',
})),
};
}, [selectedItem]);
return (
<div className="min-h-screen" style={{ background: "var(--cream)" }}>
{/* ── Hero ─────────────────────────────────────── */}
<header className="relative overflow-hidden bg-stone-900">
{/* Background Image */}
<div
className="absolute inset-0 z-0 opacity-80"
style={{
backgroundImage: "url('/header-bg.jpg')",
backgroundSize: "cover",
backgroundPosition: "center"
}}
/>
{/* Dark overlay to make text readable */}
<div className="absolute inset-0 z-0 bg-gradient-to-b from-black/60 via-black/40 to-black/80" />
{/* hero content */}
<div className="relative z-10 flex flex-col items-center text-center px-6 pt-16 pb-20">
<motion.div
initial={{ opacity: 0, y: 24 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.9, ease: [0.16, 1, 0.3, 1] }}
className="flex flex-col items-center"
>
<p
className="text-[10px] tracking-[0.38em] uppercase mb-8 font-sans font-medium"
style={{ color: "rgba(255,220,160,1)" }}
>
Akyaka · Muğla
</p>
<h1
className="font-display text-[82px] font-light leading-none tracking-tight"
style={{ color: "#FFFAF2" }}
>
Moy
</h1>
<h2
className="font-display text-[28px] font-light tracking-[0.22em] uppercase"
style={{ color: "rgba(255,200,120,0.85)", marginTop: "-2px" }}
>
Beach
</h2>
<div
className="flex items-center gap-3 my-5"
style={{ color: "rgba(255,190,100,0.35)" }}
>
<div className="h-px w-14" style={{ background: "currentColor" }} />
<span className="text-base"></span>
<div className="h-px w-14" style={{ background: "currentColor" }} />
</div>
<p
className="text-xs font-sans tracking-wide"
style={{ color: "rgba(255,218,168,0.5)" }}
>
Akyaka&apos;nın en keyifli menüsü
</p>
</motion.div>
</div>
{/* wave transition */}
<div className="absolute bottom-0 left-0 right-0 translate-y-px">
<svg
viewBox="0 0 1440 52"
preserveAspectRatio="none"
className="w-full h-[52px]"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M0 52L80 44C160 36 320 20 480 18C640 16 800 28 960 32C1120 36 1280 32 1360 30L1440 28V52H1360C1280 52 1120 52 960 52C800 52 640 52 480 52C320 52 160 52 80 52H0Z"
fill="#FAF8F3"
/>
</svg>
</div>
</header>
{/* ── Category Nav ─────────────────────────────── */}
<CategoryNav
categories={menuData}
activeCategoryId={activeCategoryId}
icons={CATEGORY_ICONS}
/>
{/* ── Menu Sections ────────────────────────────── */}
<main className="pb-28">
{menuData.map((category, index) => (
<motion.section
key={category.id}
id={category.id}
ref={(el) => { sectionRefs.current[index] = el; }}
className="pt-10 px-4 max-w-lg mx-auto scroll-mt-[62px]"
initial={{ opacity: 0, y: 14 }}
whileInView={{ opacity: 1, y: 0 }}
viewport={{ once: true, margin: "-50px" }}
transition={{ duration: 0.5, ease: [0.16, 1, 0.3, 1] }}
>
{/* section header */}
<div
className="flex items-center gap-2.5 mb-4 pb-3 border-b"
style={{ borderColor: "var(--sand-border)" }}
>
<span className="text-xl leading-none select-none">
{CATEGORY_ICONS[category.id] ?? "🍽️"}
</span>
<h2
className="font-display text-[22px] leading-tight font-semibold italic"
style={{ color: "var(--stone-ink)" }}
>
{category.title}
</h2>
</div>
<div>
{category.items.map((item, idx) => (
<MenuItem key={idx} item={item} onClick={() => setSelectedItem(item)} />
))}
</div>
</motion.section>
))}
</main>
{/* ── Footer ───────────────────────────────────── */}
<footer
className="py-12 text-center"
style={{ background: "var(--hero-from)" }}
>
<div className="flex flex-col items-center gap-1">
<span
className="font-display text-3xl font-light italic"
style={{ color: "rgba(255,220,160,0.85)" }}
>
Moy Beach
</span>
<p
className="text-[10px] font-sans tracking-[0.3em] uppercase mt-1"
style={{ color: "rgba(255,200,130,0.35)" }}
>
Akyaka, Muğla
</p>
<div
className="flex items-center gap-3 my-4"
style={{ color: "rgba(160,100,50,0.4)" }}
>
<div className="h-px w-10" style={{ background: "currentColor" }} />
<span className="text-xs"></span>
<div className="h-px w-10" style={{ background: "currentColor" }} />
</div>
<p
className="text-[11px] font-sans"
style={{ color: "rgba(120,90,60,0.5)" }}
>
© 2026 Moy Beach. Tüm hakları saklıdır.
</p>
</div>
</footer>
{/* ── Modal ────────────────────────────────────── */}
<AnimatePresence>
{selectedItem && (
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/40 backdrop-blur-sm"
onClick={() => setSelectedItem(null)}
>
<motion.div
initial={{ y: 50, opacity: 0, scale: 0.95 }}
animate={{ y: 0, opacity: 1, scale: 1 }}
exit={{ y: 20, opacity: 0, scale: 0.95 }}
className="bg-white rounded-2xl overflow-hidden w-full max-w-sm shadow-xl"
onClick={(e) => e.stopPropagation()}
>
{selectedItem.image && (
<div className="w-full h-56 relative">
<img src={selectedItem.image} alt={selectedItem.name} className="w-full h-full object-cover" />
<button
className="absolute top-3 right-3 bg-black/50 text-white w-8 h-8 rounded-full flex items-center justify-center backdrop-blur-md transition-colors hover:bg-black/70"
onClick={() => setSelectedItem(null)}
>
</button>
</div>
)}
<div className="p-5">
<div className="flex justify-between items-start gap-4 mb-2">
<h3 className="text-xl font-semibold font-sans" style={{ color: "var(--stone-ink)" }}>
{selectedItem.name}
</h3>
<span className="shrink-0 text-lg font-semibold font-sans tabular-nums" style={{ color: "var(--amber)" }}>
{selectedItem.price}
</span>
</div>
<p className="text-[14px] leading-relaxed font-sans" style={{ color: "var(--stone-muted)" }}>
{selectedItem.description}
</p>
</div>
</motion.div>
</motion.div>
)}
</AnimatePresence>
</div>
);
});
}
async function getSiteSettings() {
const settingsData = await prisma.settings.findMany()
const settings = settingsData.reduce((acc, curr) => {
acc[curr.key] = curr.value
return acc
}, {} as Record<string, string>)
return {
logoUrl: settings['logo_url'] || '/logo.png',
location: settings['location'] || 'Akyaka · Muğla',
restaurantName: settings['restaurant_name'] || 'Moy Beach',
}
}
export default async function Page() {
const [menuData, siteSettings] = await Promise.all([
getMenuData(),
getSiteSettings(),
]);
return <MenuClient initialCategories={menuData} siteSettings={siteSettings} />;
}