feat: add prisma support, admin panel and auth
This commit is contained in:
73
app/admin/categories/CategoryManager.tsx
Normal file
73
app/admin/categories/CategoryManager.tsx
Normal file
@@ -0,0 +1,73 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import CategoryForm from '../components/CategoryForm';
|
||||
import DeleteButton from '../components/DeleteButton';
|
||||
import { deleteCategory } from '../actions';
|
||||
|
||||
interface CategoryManagerProps {
|
||||
categories: any[];
|
||||
}
|
||||
|
||||
export default function CategoryManager({ categories }: CategoryManagerProps) {
|
||||
const [showForm, setShowForm] = useState(false);
|
||||
const [editingCategory, setEditingCategory] = useState<any>(null);
|
||||
|
||||
const handleEdit = (category: any) => {
|
||||
setEditingCategory(category);
|
||||
setShowForm(true);
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
setShowForm(false);
|
||||
setEditingCategory(null);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="admin-categories">
|
||||
<div className="admin-page-header" style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '2rem' }}>
|
||||
<div>
|
||||
<h1>Kategoriler</h1>
|
||||
<p>Menü kategorilerini yönetin</p>
|
||||
</div>
|
||||
<button className="admin-btn" onClick={() => setShowForm(true)}>
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" style={{width: '16px'}}><line x1="12" y1="5" x2="12" y2="19" /><line x1="5" y1="12" x2="19" y2="12" /></svg>
|
||||
Yeni Kategori
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="admin-card">
|
||||
<table className="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Başlık</th>
|
||||
<th>Harici ID</th>
|
||||
<th>Ürün Sayısı</th>
|
||||
<th>İşlemler</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{categories.map((cat) => (
|
||||
<tr key={cat.id}>
|
||||
<td style={{ fontWeight: 500, color: '#fff' }}>{cat.title}</td>
|
||||
<td><code className="badge">{cat.externalId}</code></td>
|
||||
<td>{cat._count?.items || 0} Ürün</td>
|
||||
<td className="actions-cell">
|
||||
<button className="action-btn" onClick={() => handleEdit(cat)}>Düzenle</button>
|
||||
<DeleteButton onDelete={async () => { await deleteCategory(cat.id); }} />
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{showForm && (
|
||||
<CategoryForm
|
||||
initialData={editingCategory}
|
||||
onClose={handleClose}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
18
app/admin/categories/page.tsx
Normal file
18
app/admin/categories/page.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
import React from 'react';
|
||||
import { prisma } from '@/app/lib/prisma';
|
||||
import CategoryManager from './CategoryManager';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export default async function AdminCategoriesPage() {
|
||||
const categories = await prisma.category.findMany({
|
||||
include: {
|
||||
_count: {
|
||||
select: { items: true }
|
||||
}
|
||||
},
|
||||
orderBy: { createdAt: 'asc' }
|
||||
});
|
||||
|
||||
return <CategoryManager categories={categories} />;
|
||||
}
|
||||
Reference in New Issue
Block a user