first commit

This commit is contained in:
mstfyldz
2026-06-03 04:11:30 +03:00
parent d369c9e258
commit 7b4b3a85af
20 changed files with 3446 additions and 442 deletions
+2 -1
View File
@@ -1,6 +1,6 @@
import { notFound } from 'next/navigation'
import { getDictionary, hasLocale } from './dictionaries'
import { categories } from '@/data/menu'
import { getCategories } from '@/data/menu'
import Header from '@/components/Header'
import CategorySection from '@/components/CategorySection'
import BottomTabBar from '@/components/BottomTabBar'
@@ -15,6 +15,7 @@ export default async function MenuPage({
if (!hasLocale(lang)) notFound()
const dict = await getDictionary(lang)
const categories = await getCategories()
return (
<>
+33
View File
@@ -0,0 +1,33 @@
'use server'
import { cookies } from 'next/headers'
import { redirect } from 'next/navigation'
export async function login(prevState: any, formData: FormData) {
const username = formData.get('username')
const password = formData.get('password')
if (
username === process.env.ADMIN_USERNAME &&
password === process.env.ADMIN_PASSWORD
) {
const cookieStore = await cookies()
cookieStore.set('admin_session', process.env.ADMIN_SECRET || 'secret', {
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
sameSite: 'lax',
path: '/',
maxAge: 60 * 60 * 24 * 7 // 1 week
})
redirect('/admin')
} else {
return { error: 'Geçersiz kullanıcı adı veya şifre' }
}
}
export async function logout() {
const cookieStore = await cookies()
cookieStore.delete('admin_session')
redirect('/admin/login')
}
+22
View File
@@ -0,0 +1,22 @@
'use server'
import { saveCategories, type Category } from '@/data/menu'
import { revalidatePath } from 'next/cache'
import { cookies } from 'next/headers'
async function checkAuth() {
const cookieStore = await cookies()
const session = cookieStore.get('admin_session')?.value
if (!session || session !== (process.env.ADMIN_SECRET || 'secret')) {
throw new Error('Unauthorized')
}
}
export async function saveEntireMenu(categories: Category[]) {
await checkAuth()
await saveCategories(categories)
// Revalidate both language paths
revalidatePath('/tr')
revalidatePath('/en')
return { success: true }
}
+34
View File
@@ -0,0 +1,34 @@
'use server'
import { promises as fs } from 'fs'
import path from 'path'
import { cookies } from 'next/headers'
export async function uploadImage(formData: FormData) {
const cookieStore = await cookies()
const session = cookieStore.get('admin_session')?.value
const secret = process.env.ADMIN_SECRET || 'secret'
if (!session || session !== secret) {
throw new Error('Unauthorized')
}
const file = formData.get('file') as File
if (!file) {
throw new Error('No file uploaded')
}
const bytes = await file.arrayBuffer()
const buffer = Buffer.from(bytes)
const extension = path.extname(file.name) || '.jpg'
const filename = `${Date.now()}-${Math.random().toString(36).substring(7)}${extension}`
const uploadDir = path.join(process.cwd(), 'public', 'uploads')
await fs.mkdir(uploadDir, { recursive: true })
const filePath = path.join(uploadDir, filename)
await fs.writeFile(filePath, buffer)
return { url: `/uploads/${filename}` }
}
+25
View File
@@ -0,0 +1,25 @@
import { ReactNode } from 'react'
import { logout } from '@/app/actions/auth'
export default function AdminLayout({ children }: { children: ReactNode }) {
return (
<div className="min-h-screen bg-cream flex flex-col" style={{ backgroundColor: '#F5F0E8' }}>
<header className="bg-coffee-dark px-6 py-4 flex justify-between items-center" style={{ backgroundColor: '#3D2B1F' }}>
<h1 className="text-xl font-display font-bold text-cream" style={{ color: '#F5F0E8' }}>Kozmos Yönetim</h1>
<form action={logout}>
<button
type="submit"
className="px-4 py-1.5 rounded bg-cream/10 text-cream text-sm font-medium hover:bg-cream/20 transition-colors"
>
Çıkış Yap
</button>
</form>
</header>
<main className="flex-1 p-4 md:p-6 lg:p-8 max-w-5xl mx-auto w-full">
{children}
</main>
</div>
)
}
+61
View File
@@ -0,0 +1,61 @@
'use client'
import { useActionState } from 'react'
import { login } from '@/app/actions/auth'
export default function LoginPage() {
const [state, formAction, isPending] = useActionState(login, null)
return (
<div className="min-h-screen flex items-center justify-center bg-cream px-4" style={{ backgroundColor: '#F5F0E8' }}>
<div className="w-full max-w-sm bg-white rounded-2xl shadow-xl overflow-hidden">
<div className="bg-coffee-dark px-6 py-8 text-center" style={{ backgroundColor: '#3D2B1F' }}>
<h1 className="text-2xl font-display font-bold text-cream" style={{ color: '#F5F0E8' }}>Kozmos Admin</h1>
<p className="text-cream/70 text-sm mt-2">Yönetim paneline giriş yapın</p>
</div>
<form action={formAction} className="px-6 py-8 space-y-5">
{state?.error && (
<div className="bg-red-50 text-red-600 p-3 rounded-lg text-sm font-medium border border-red-100">
{state.error}
</div>
)}
<div>
<label className="block text-sm font-medium text-coffee mb-1.5">Kullanıcı Adı</label>
<input
type="text"
name="username"
required
className="w-full px-4 py-2.5 rounded-lg border border-beige/60 bg-cream/30 focus:outline-none focus:ring-2 focus:ring-teal/50"
placeholder="admin"
/>
</div>
<div>
<label className="block text-sm font-medium text-coffee mb-1.5">Şifre</label>
<input
type="password"
name="password"
required
className="w-full px-4 py-2.5 rounded-lg border border-beige/60 bg-cream/30 focus:outline-none focus:ring-2 focus:ring-teal/50"
placeholder="••••••••"
/>
</div>
<button
type="submit"
disabled={isPending}
className="w-full py-3 rounded-lg text-white font-medium transition-all"
style={{
backgroundColor: '#4AAFA8',
opacity: isPending ? 0.7 : 1
}}
>
{isPending ? 'Giriş yapılıyor...' : 'Giriş Yap'}
</button>
</form>
</div>
</div>
)
}
+10
View File
@@ -0,0 +1,10 @@
import { getCategories } from '@/data/menu'
import AdminDashboard from '@/components/admin/AdminDashboard'
export const dynamic = 'force-dynamic'
export default async function AdminPage() {
const categories = await getCategories()
return <AdminDashboard initialCategories={categories} />
}