feat: implement dynamic categories, admin category CRUD, fix routing and cleanup
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
import { mockDb } from '@/lib/mockDb'
|
||||
import { createOrUpdateCategoryAction } from '@/app/actions'
|
||||
import { Link } from '@/i18n/routing'
|
||||
import { ArrowLeft } from 'lucide-react'
|
||||
import { redirect } from 'next/navigation'
|
||||
|
||||
export default async function CategoryFormPage({ params }: { params: Promise<{ id: string, locale: string }> }) {
|
||||
const resolvedParams = await params
|
||||
const isNew = resolvedParams.id === 'new'
|
||||
let category = null
|
||||
|
||||
if (!isNew) {
|
||||
category = await mockDb.getCategoryById(resolvedParams.id)
|
||||
if (!category) {
|
||||
redirect(`/${resolvedParams.locale}/admin/categories`)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="max-w-2xl mx-auto space-y-6">
|
||||
<div className="flex items-center gap-4">
|
||||
<Link href="/admin/categories" className="p-2 hover:bg-stone-deep rounded-full transition-colors text-shutter hover:text-ink">
|
||||
<ArrowLeft className="w-5 h-5" />
|
||||
</Link>
|
||||
<div>
|
||||
<h2 className="text-2xl font-heading font-extrabold text-pine lowercase">
|
||||
{isNew ? 'yeni kategori' : 'kategoriyi düzenle'}
|
||||
</h2>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-paper p-6 rounded-2xl shadow-sm border border-pine/8">
|
||||
<form action={createOrUpdateCategoryAction} className="space-y-5">
|
||||
<input type="hidden" name="id" value={resolvedParams.id} />
|
||||
|
||||
<div>
|
||||
<label className="block text-xs font-bold text-pine uppercase tracking-wider mb-1.5">Slug (URL)</label>
|
||||
<input
|
||||
type="text"
|
||||
name="slug"
|
||||
defaultValue={category?.slug || ''}
|
||||
required
|
||||
className="w-full bg-stone-deep/30 border border-pine/10 rounded-xl px-4 py-3 text-sm focus:outline-none focus:ring-2 focus:ring-turquoise/50"
|
||||
placeholder="orn: restoran"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-xs font-bold text-pine uppercase tracking-wider mb-1.5">Adı (TR)</label>
|
||||
<input
|
||||
type="text"
|
||||
name="nameTr"
|
||||
defaultValue={category?.nameTr || ''}
|
||||
required
|
||||
className="w-full bg-stone-deep/30 border border-pine/10 rounded-xl px-4 py-3 text-sm focus:outline-none focus:ring-2 focus:ring-turquoise/50"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-xs font-bold text-pine uppercase tracking-wider mb-1.5">Adı (EN)</label>
|
||||
<input
|
||||
type="text"
|
||||
name="nameEn"
|
||||
defaultValue={category?.nameEn || ''}
|
||||
required
|
||||
className="w-full bg-stone-deep/30 border border-pine/10 rounded-xl px-4 py-3 text-sm focus:outline-none focus:ring-2 focus:ring-turquoise/50"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-xs font-bold text-pine uppercase tracking-wider mb-1.5">Adı (RU)</label>
|
||||
<input
|
||||
type="text"
|
||||
name="nameRu"
|
||||
defaultValue={category?.nameRu || ''}
|
||||
required
|
||||
className="w-full bg-stone-deep/30 border border-pine/10 rounded-xl px-4 py-3 text-sm focus:outline-none focus:ring-2 focus:ring-turquoise/50"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="pt-4 flex items-center justify-end gap-3 border-t border-dashed border-pine/10">
|
||||
<Link
|
||||
href="/admin/categories"
|
||||
className="px-6 py-2.5 rounded-xl font-bold text-xs text-shutter hover:text-ink hover:bg-stone-deep transition-colors"
|
||||
>
|
||||
İptal
|
||||
</Link>
|
||||
<button
|
||||
type="submit"
|
||||
className="bg-turquoise hover:bg-turquoise/90 text-paper px-6 py-2.5 rounded-xl font-bold text-xs transition-colors shadow-sm"
|
||||
>
|
||||
{isNew ? 'Oluştur' : 'Kaydet'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
import { mockDb } from '@/lib/mockDb'
|
||||
import { Link } from '@/i18n/routing'
|
||||
import { Plus, Edit2, Trash2 } from 'lucide-react'
|
||||
import { deleteCategoryAction } from '@/app/actions'
|
||||
import DeleteButton from '@/components/DeleteButton'
|
||||
|
||||
export default async function AdminCategoriesPage() {
|
||||
const categories = await mockDb.getCategories()
|
||||
@@ -6,12 +10,19 @@ export default async function AdminCategoriesPage() {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<div>
|
||||
<h2 className="text-3xl font-heading font-extrabold text-pine lowercase">kategoriler</h2>
|
||||
<p className="text-ink/65 text-xs font-medium mt-1">
|
||||
Sistemde listelenen işletmelerin sınıflandırıldığı ana kategoriler.
|
||||
</p>
|
||||
</div>
|
||||
<Link
|
||||
href="/admin/categories/new"
|
||||
className="flex items-center gap-2 bg-turquoise hover:bg-turquoise/90 text-paper px-4 py-2.5 rounded-xl font-bold text-sm transition-colors shadow-sm"
|
||||
>
|
||||
<Plus className="w-4 h-4" />
|
||||
<span>Yeni Kategori</span>
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<div className="bg-paper border border-pine/8 rounded-2xl shadow-sm overflow-hidden max-w-4xl">
|
||||
@@ -23,6 +34,7 @@ export default async function AdminCategoriesPage() {
|
||||
<th className="px-6 py-4 text-left">Adı (TR)</th>
|
||||
<th className="px-6 py-4 text-left">Name (EN)</th>
|
||||
<th className="px-6 py-4 text-left">Имя (RU)</th>
|
||||
<th className="px-6 py-4 text-right">İşlemler</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-dashed divide-pine/8 text-ink/85 font-medium">
|
||||
@@ -33,6 +45,19 @@ export default async function AdminCategoriesPage() {
|
||||
<td className="px-6 py-4 font-heading font-bold text-pine lowercase text-sm">{cat.nameTr}</td>
|
||||
<td className="px-6 py-4 text-xs">{cat.nameEn}</td>
|
||||
<td className="px-6 py-4 text-xs">{cat.nameRu}</td>
|
||||
<td className="px-6 py-4 text-right space-x-2">
|
||||
<Link
|
||||
href={`/admin/categories/${cat.id}`}
|
||||
className="inline-flex items-center justify-center w-8 h-8 rounded-lg bg-stone hover:bg-turquoise/10 text-shutter hover:text-turquoise transition-colors"
|
||||
title="Düzenle"
|
||||
>
|
||||
<Edit2 className="w-4 h-4" />
|
||||
</Link>
|
||||
<form action={deleteCategoryAction} className="inline-block">
|
||||
<input type="hidden" name="id" value={cat.id} />
|
||||
<DeleteButton />
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user