feat: implement dynamic categories, admin category CRUD, fix routing and cleanup

This commit is contained in:
AyrisAI
2026-07-13 13:51:48 +03:00
parent 2f2dafcfb9
commit 5b44c78396
54 changed files with 3619 additions and 473 deletions
@@ -0,0 +1,23 @@
'use client'
import { deleteNeighborhoodAction } from '@/app/actions'
import { Trash } from 'lucide-react'
export function DeleteButton({ id }: { id: string }) {
return (
<button
type="button"
onClick={async () => {
if (!confirm('Bu mahalleyi silmek istediğinize emin misiniz?')) return
const res = await deleteNeighborhoodAction(id)
if (res?.error) {
alert(res.error)
}
}}
className="p-2 text-shutter hover:text-red-500 hover:bg-red-500/10 rounded-lg transition-colors"
title="Sil"
>
<Trash className="w-4 h-4" />
</button>
)
}
@@ -0,0 +1,99 @@
import { mockDb } from '@/lib/mockDb'
import { createOrUpdateNeighborhoodAction } from '@/app/actions'
import { Link } from '@/i18n/routing'
import { ArrowLeft } from 'lucide-react'
import { redirect } from 'next/navigation'
export default async function NeighborhoodFormPage({ params }: { params: Promise<{ id: string, locale: string }> }) {
const resolvedParams = await params
const isNew = resolvedParams.id === 'new'
let neighborhood = null
if (!isNew) {
neighborhood = await mockDb.getNeighborhoodById(resolvedParams.id)
if (!neighborhood) {
redirect(`/${resolvedParams.locale}/admin/neighborhoods`)
}
}
return (
<div className="max-w-2xl mx-auto space-y-6">
<div className="flex items-center gap-4">
<Link href="/admin/neighborhoods" 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 mahalle' : 'mahalleyi düzenle'}
</h2>
</div>
</div>
<div className="bg-paper p-6 rounded-2xl shadow-sm border border-pine/8">
<form action={createOrUpdateNeighborhoodAction} 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={neighborhood?.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: tepe-mahallesi"
/>
</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={neighborhood?.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={neighborhood?.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={neighborhood?.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 justify-end gap-3">
<Link
href="/admin/neighborhoods"
className="px-6 py-3 text-sm font-bold text-shutter hover:text-ink transition-colors"
>
İptal
</Link>
<button
type="submit"
className="px-6 py-3 bg-pine hover:bg-pine/90 text-paper text-sm font-bold rounded-xl transition-colors shadow-sm"
>
Kaydet
</button>
</div>
</form>
</div>
</div>
)
}
+48 -23
View File
@@ -1,42 +1,67 @@
import { mockDb } from '@/lib/mockDb'
import { Link } from '@/i18n/routing'
import { Plus, Edit } from 'lucide-react'
import { DeleteButton } from './DeleteButton'
export default async function AdminNeighborhoodsPage() {
const neighborhoods = await mockDb.getNeighborhoods()
return (
<div className="space-y-6">
<div className="flex items-center justify-between">
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
<div>
<h2 className="text-3xl font-heading font-extrabold text-pine lowercase">mahalleler</h2>
<p className="text-ink/65 text-xs font-medium mt-1">
Marmaris Local rehberindeki mekanların filtrelendiği mahalle/bölgeler.
</p>
</div>
<Link
href="/admin/neighborhoods/new"
className="inline-flex items-center gap-1.5 bg-turquoise hover:bg-turquoise/90 text-paper text-xs font-bold py-3 px-5 rounded-xl shadow-sm transition active:scale-95 duration-150"
>
<Plus className="w-4 h-4" />
Yeni Mahalle Ekle
</Link>
</div>
<div className="bg-paper border border-pine/8 rounded-2xl shadow-sm overflow-hidden max-w-4xl">
<table className="min-w-full divide-y divide-pine/8 text-sm">
<thead className="bg-stone-deep/40 text-shutter font-mono text-[10px] uppercase tracking-wider">
<tr>
<th className="px-6 py-4 text-left">ID</th>
<th className="px-6 py-4 text-left">Slug</th>
<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>
</tr>
</thead>
<tbody className="divide-y divide-dashed divide-pine/8 text-ink/85 font-medium">
{neighborhoods.map((neigh) => (
<tr key={neigh.id} className="hover:bg-stone/20 transition duration-150">
<td className="px-6 py-4 font-mono text-xs text-shutter">{neigh.id}</td>
<td className="px-6 py-4 font-mono text-xs font-bold text-turquoise">{neigh.slug}</td>
<td className="px-6 py-4 font-heading font-bold text-pine lowercase text-sm">{neigh.nameTr}</td>
<td className="px-6 py-4 text-xs">{neigh.nameEn}</td>
<td className="px-6 py-4 text-xs">{neigh.nameRu}</td>
<div className="bg-paper border border-pine/8 rounded-2xl shadow-sm overflow-hidden max-w-5xl">
<div className="overflow-x-auto">
<table className="min-w-full divide-y divide-pine/8 text-sm">
<thead className="bg-stone-deep/40 text-shutter font-mono text-[10px] uppercase tracking-wider">
<tr>
<th className="px-6 py-4 text-left">ID</th>
<th className="px-6 py-4 text-left">Slug</th>
<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>
))}
</tbody>
</table>
</thead>
<tbody className="divide-y divide-dashed divide-pine/8 text-ink/85 font-medium">
{neighborhoods.map((neigh) => (
<tr key={neigh.id} className="hover:bg-stone/20 transition duration-150">
<td className="px-6 py-4 font-mono text-xs text-shutter">{neigh.id}</td>
<td className="px-6 py-4 font-mono text-xs font-bold text-turquoise">{neigh.slug}</td>
<td className="px-6 py-4 font-heading font-bold text-pine lowercase text-sm">{neigh.nameTr}</td>
<td className="px-6 py-4 text-xs">{neigh.nameEn}</td>
<td className="px-6 py-4 text-xs">{neigh.nameRu}</td>
<td className="px-6 py-4 text-right">
<div className="flex justify-end gap-2">
<Link
href={`/admin/neighborhoods/${neigh.id}`}
className="p-2 text-shutter hover:text-turquoise hover:bg-turquoise/10 rounded-lg transition-colors"
title="Düzenle"
>
<Edit className="w-4 h-4" />
</Link>
<DeleteButton id={neigh.id} />
</div>
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
</div>
)