main #3
23
PLANLAMA.md
Normal file
23
PLANLAMA.md
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# ParaKasa Geliştirme Planı (Revize Edildi)
|
||||||
|
|
||||||
|
**Vizyon:** Proje, tek bir çatı altında iki farklı uygulama gibi çalışacaktır.
|
||||||
|
|
||||||
|
## 1. Web Sitesi (Public)
|
||||||
|
- Herkese açık kurumsal web sitesi.
|
||||||
|
- Ürünler, kategoriler ve iletişim bilgileri sergilenecek.
|
||||||
|
- Veriler Yönetim Panelinden (CMS) çekilecek.
|
||||||
|
|
||||||
|
## 2. Yönetim Paneli (Private)
|
||||||
|
- Sadece firma yetkililerinin giriş yapabileceği kapalı devre sistem.
|
||||||
|
- **Fonksiyonlar:**
|
||||||
|
- **CMS:** Web sitesinin içeriğini (ürünler, slider, metinler) yönetme.
|
||||||
|
- **ERP (İç Yönetim):** Stok takibi, gelir/gider hesapları, sipariş yönetimi.
|
||||||
|
- **Durum:** Bu bölümün tasarımı ve akışı tamamen baştan kurgulanacak. Şimdilik mevcut haliyle donduruldu.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Mevcut Durum (Tamamlananlar)
|
||||||
|
- [x] Kullanıcı Yönetimi (Admin Ekle/Sil).
|
||||||
|
- [x] Temel Site Ayarları (Başlık, İletişim).
|
||||||
|
- [x] Ürün Yönetimi (Temel CRUD).
|
||||||
|
- [x] Kategori Yönetimi (Arayüz hazır, veritabanı bekleniyor).
|
||||||
22
app/(dashboard)/dashboard/categories/[id]/page.tsx
Normal file
22
app/(dashboard)/dashboard/categories/[id]/page.tsx
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { createClient } from "@/lib/supabase-server"
|
||||||
|
import { CategoryForm } from "@/components/dashboard/category-form"
|
||||||
|
import { notFound } from "next/navigation"
|
||||||
|
|
||||||
|
export default async function EditCategoryPage({ params }: { params: { id: string } }) {
|
||||||
|
const supabase = createClient()
|
||||||
|
const { data: category } = await supabase
|
||||||
|
.from('categories')
|
||||||
|
.select('*')
|
||||||
|
.eq('id', params.id)
|
||||||
|
.single()
|
||||||
|
|
||||||
|
if (!category) {
|
||||||
|
notFound()
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex-1 space-y-4 p-8 pt-6">
|
||||||
|
<CategoryForm initialData={category} />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
107
app/(dashboard)/dashboard/categories/actions.ts
Normal file
107
app/(dashboard)/dashboard/categories/actions.ts
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
"use server"
|
||||||
|
|
||||||
|
import { createClient } from "@/lib/supabase-server"
|
||||||
|
import { createClient as createSupabaseClient } from "@supabase/supabase-js"
|
||||||
|
import { revalidatePath } from "next/cache"
|
||||||
|
|
||||||
|
// Admin client for privileged operations
|
||||||
|
const supabaseAdmin = createSupabaseClient(
|
||||||
|
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
||||||
|
process.env.SUPABASE_SERVICE_ROLE_KEY!,
|
||||||
|
{
|
||||||
|
auth: {
|
||||||
|
autoRefreshToken: false,
|
||||||
|
persistSession: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
export async function createCategory(data: { name: string, description?: string, image_url?: string }) {
|
||||||
|
const supabase = createClient()
|
||||||
|
|
||||||
|
// Check admin
|
||||||
|
const { data: { user } } = await supabase.auth.getUser()
|
||||||
|
if (!user) return { error: "Oturum açmanız gerekiyor." }
|
||||||
|
|
||||||
|
// Check if current user is admin
|
||||||
|
const { data: profile } = await supabase.from('profiles').select('role').eq('id', user.id).single()
|
||||||
|
if (profile?.role !== 'admin') return { error: "Yetkisiz işlem." }
|
||||||
|
|
||||||
|
// Generate slug from name
|
||||||
|
const slug = data.name.toLowerCase()
|
||||||
|
.replace(/ğ/g, 'g')
|
||||||
|
.replace(/ü/g, 'u')
|
||||||
|
.replace(/ş/g, 's')
|
||||||
|
.replace(/ı/g, 'i')
|
||||||
|
.replace(/ö/g, 'o')
|
||||||
|
.replace(/ç/g, 'c')
|
||||||
|
.replace(/[^a-z0-9]/g, '-')
|
||||||
|
.replace(/-+/g, '-')
|
||||||
|
.replace(/^-|-$/g, '')
|
||||||
|
|
||||||
|
const { error } = await supabaseAdmin.from('categories').insert({
|
||||||
|
name: data.name,
|
||||||
|
slug: slug,
|
||||||
|
description: data.description,
|
||||||
|
image_url: data.image_url
|
||||||
|
})
|
||||||
|
|
||||||
|
if (error) return { error: "Kategori oluşturulamadı: " + error.message }
|
||||||
|
|
||||||
|
revalidatePath("/dashboard/categories")
|
||||||
|
return { success: true }
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateCategory(id: string, data: { name: string, description?: string, image_url?: string }) {
|
||||||
|
const supabase = createClient()
|
||||||
|
|
||||||
|
// Check admin
|
||||||
|
const { data: { user } } = await supabase.auth.getUser()
|
||||||
|
if (!user) return { error: "Oturum açmanız gerekiyor." }
|
||||||
|
|
||||||
|
// Check if current user is admin
|
||||||
|
const { data: profile } = await supabase.from('profiles').select('role').eq('id', user.id).single()
|
||||||
|
if (profile?.role !== 'admin') return { error: "Yetkisiz işlem." }
|
||||||
|
|
||||||
|
const slug = data.name.toLowerCase()
|
||||||
|
.replace(/ğ/g, 'g')
|
||||||
|
.replace(/ü/g, 'u')
|
||||||
|
.replace(/ş/g, 's')
|
||||||
|
.replace(/ı/g, 'i')
|
||||||
|
.replace(/ö/g, 'o')
|
||||||
|
.replace(/ç/g, 'c')
|
||||||
|
.replace(/[^a-z0-9]/g, '-')
|
||||||
|
.replace(/-+/g, '-')
|
||||||
|
.replace(/^-|-$/g, '')
|
||||||
|
|
||||||
|
const { error } = await supabaseAdmin.from('categories').update({
|
||||||
|
name: data.name,
|
||||||
|
slug: slug,
|
||||||
|
description: data.description,
|
||||||
|
image_url: data.image_url
|
||||||
|
}).eq('id', id)
|
||||||
|
|
||||||
|
if (error) return { error: "Kategori güncellenemedi: " + error.message }
|
||||||
|
|
||||||
|
revalidatePath("/dashboard/categories")
|
||||||
|
return { success: true }
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteCategory(id: string) {
|
||||||
|
const supabase = createClient()
|
||||||
|
|
||||||
|
// Check admin
|
||||||
|
const { data: { user } } = await supabase.auth.getUser()
|
||||||
|
if (!user) return { error: "Oturum açmanız gerekiyor." }
|
||||||
|
|
||||||
|
// Check if current user is admin
|
||||||
|
const { data: profile } = await supabase.from('profiles').select('role').eq('id', user.id).single()
|
||||||
|
if (profile?.role !== 'admin') return { error: "Yetkisiz işlem." }
|
||||||
|
|
||||||
|
const { error } = await supabaseAdmin.from('categories').delete().eq('id', id)
|
||||||
|
|
||||||
|
if (error) return { error: "Kategori silinemedi: " + error.message }
|
||||||
|
|
||||||
|
revalidatePath("/dashboard/categories")
|
||||||
|
return { success: true }
|
||||||
|
}
|
||||||
9
app/(dashboard)/dashboard/categories/new/page.tsx
Normal file
9
app/(dashboard)/dashboard/categories/new/page.tsx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { CategoryForm } from "@/components/dashboard/category-form"
|
||||||
|
|
||||||
|
export default function NewCategoryPage() {
|
||||||
|
return (
|
||||||
|
<div className="flex-1 space-y-4 p-8 pt-6">
|
||||||
|
<CategoryForm />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
78
app/(dashboard)/dashboard/categories/page.tsx
Normal file
78
app/(dashboard)/dashboard/categories/page.tsx
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
import { createClient } from "@/lib/supabase-server"
|
||||||
|
import { format } from "date-fns"
|
||||||
|
import { tr } from "date-fns/locale"
|
||||||
|
import Link from "next/link"
|
||||||
|
import { Plus } from "lucide-react"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "@/components/ui/table"
|
||||||
|
|
||||||
|
export default async function CategoriesPage() {
|
||||||
|
const supabase = createClient()
|
||||||
|
const { data: categories } = await supabase
|
||||||
|
.from('categories')
|
||||||
|
.select('*')
|
||||||
|
.order('created_at', { ascending: false })
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex-1 space-y-4 p-8 pt-6">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div>
|
||||||
|
<h2 className="text-3xl font-bold tracking-tight">Kategoriler ({categories?.length || 0})</h2>
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
Sitenizdeki ürün kategorilerini yönetin.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<Link href="/dashboard/categories/new">
|
||||||
|
<Button>
|
||||||
|
<Plus className="mr-2 h-4 w-4" /> Yeni Ekle
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="rounded-md border p-4">
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>Ad</TableHead>
|
||||||
|
<TableHead>Slug</TableHead>
|
||||||
|
<TableHead>Oluşturulma Tarihi</TableHead>
|
||||||
|
<TableHead className="text-right">İşlemler</TableHead>
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{categories?.map((category) => (
|
||||||
|
<TableRow key={category.id}>
|
||||||
|
<TableCell className="font-medium">{category.name}</TableCell>
|
||||||
|
<TableCell>{category.slug}</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
{format(new Date(category.created_at), "d MMMM yyyy", { locale: tr })}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="text-right">
|
||||||
|
<Link href={`/dashboard/categories/${category.id}`}>
|
||||||
|
<Button variant="ghost" size="sm">
|
||||||
|
Düzenle
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
{(!categories || categories.length === 0) && (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell colSpan={4} className="h-24 text-center">
|
||||||
|
Kategori bulunamadı.
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,126 +1,126 @@
|
|||||||
|
import { createClient } from "@/lib/supabase-server"
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||||
import { DollarSign, ShoppingCart, Users, CreditCard } from "lucide-react"
|
import { DollarSign, ShoppingCart, Users, CreditCard, Package } from "lucide-react"
|
||||||
|
import Link from "next/link"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
|
||||||
|
export default async function DashboardPage() {
|
||||||
|
const supabase = createClient()
|
||||||
|
|
||||||
|
// Fetch real data
|
||||||
|
const { data: products } = await supabase
|
||||||
|
.from("products")
|
||||||
|
.select("*")
|
||||||
|
.order("created_at", { ascending: false })
|
||||||
|
|
||||||
|
const totalProducts = products?.length || 0
|
||||||
|
const totalValue = products?.reduce((acc, product) => acc + (Number(product.price) || 0), 0) || 0
|
||||||
|
const recentProducts = products?.slice(0, 5) || []
|
||||||
|
|
||||||
|
// Calculate unique categories
|
||||||
|
const categories = new Set(products?.map(p => p.category)).size
|
||||||
|
|
||||||
export default function DashboardPage() {
|
|
||||||
return (
|
return (
|
||||||
<div className="flex-1 space-y-4">
|
<div className="flex-1 space-y-4 p-8 pt-6">
|
||||||
<div className="flex items-center justify-between space-y-2">
|
<div className="flex items-center justify-between space-y-2">
|
||||||
<h2 className="text-3xl font-bold tracking-tight">Genel Bakış</h2>
|
<h2 className="text-3xl font-bold tracking-tight">Genel Bakış</h2>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Link href="/dashboard/products/new">
|
||||||
|
<Button>Ürün Ekle</Button>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Stats Grid */}
|
|
||||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
|
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||||
<CardTitle className="text-sm font-medium">Toplam Gelir</CardTitle>
|
<CardTitle className="text-sm font-medium">Toplam Ürün Değeri</CardTitle>
|
||||||
<DollarSign className="h-4 w-4 text-muted-foreground" />
|
<DollarSign className="h-4 w-4 text-muted-foreground" />
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<div className="text-2xl font-bold">₺45,231.89</div>
|
<div className="text-2xl font-bold">₺{totalValue.toLocaleString('tr-TR', { minimumFractionDigits: 2 })}</div>
|
||||||
<p className="text-xs text-muted-foreground">+20.1% geçen aya göre</p>
|
<p className="text-xs text-muted-foreground">Stoktaki toplam varlık</p>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||||
<CardTitle className="text-sm font-medium">Abonelikler</CardTitle>
|
<CardTitle className="text-sm font-medium">Toplam Ürün</CardTitle>
|
||||||
|
<Package className="h-4 w-4 text-muted-foreground" />
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<div className="text-2xl font-bold">{totalProducts}</div>
|
||||||
|
<p className="text-xs text-muted-foreground">Kayıtlı ürün sayısı</p>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
<Card>
|
||||||
|
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||||
|
<CardTitle className="text-sm font-medium">Kategoriler</CardTitle>
|
||||||
|
<ShoppingCart className="h-4 w-4 text-muted-foreground" />
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<div className="text-2xl font-bold">{categories}</div>
|
||||||
|
<p className="text-xs text-muted-foreground">Aktif kategori</p>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
<Card>
|
||||||
|
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||||
|
<CardTitle className="text-sm font-medium">Son Güncelleme</CardTitle>
|
||||||
<Users className="h-4 w-4 text-muted-foreground" />
|
<Users className="h-4 w-4 text-muted-foreground" />
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<div className="text-2xl font-bold">+2350</div>
|
<div className="text-2xl font-bold">Şimdi</div>
|
||||||
<p className="text-xs text-muted-foreground">+180.1% geçen aya göre</p>
|
<p className="text-xs text-muted-foreground">Canlı veri akışı</p>
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
<Card>
|
|
||||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
|
||||||
<CardTitle className="text-sm font-medium">Satışlar</CardTitle>
|
|
||||||
<CreditCard className="h-4 w-4 text-muted-foreground" />
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent>
|
|
||||||
<div className="text-2xl font-bold">+12,234</div>
|
|
||||||
<p className="text-xs text-muted-foreground">+19% geçen aya göre</p>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
<Card>
|
|
||||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
|
||||||
<CardTitle className="text-sm font-medium">Aktif Şimdi</CardTitle>
|
|
||||||
<Users className="h-4 w-4 text-muted-foreground" />
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent>
|
|
||||||
<div className="text-2xl font-bold">+573</div>
|
|
||||||
<p className="text-xs text-muted-foreground">+201 son bir saatte</p>
|
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-7">
|
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-7">
|
||||||
{/* Recent Sales / Activity */}
|
|
||||||
<Card className="col-span-4">
|
<Card className="col-span-4">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Son Hareketler</CardTitle>
|
<CardTitle>Son Eklenen Ürünler</CardTitle>
|
||||||
<CardDescription>
|
<CardDescription>
|
||||||
Bu ay 265+ satış yaptınız.
|
En son eklenen {recentProducts.length} ürün.
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
{/* Mock List */}
|
|
||||||
<div className="space-y-8">
|
<div className="space-y-8">
|
||||||
<div className="flex items-center">
|
{recentProducts.map((product) => (
|
||||||
|
<div key={product.id} className="flex items-center">
|
||||||
<div className="h-9 w-9 rounded-full bg-slate-100 flex items-center justify-center">
|
<div className="h-9 w-9 rounded-full bg-slate-100 flex items-center justify-center">
|
||||||
<span className="font-bold text-xs">OM</span>
|
<span className="font-bold text-xs">{product.name.substring(0, 2).toUpperCase()}</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="ml-4 space-y-1">
|
<div className="ml-4 space-y-1">
|
||||||
<p className="text-sm font-medium leading-none">Ozan Mehmet</p>
|
<p className="text-sm font-medium leading-none">{product.name}</p>
|
||||||
<p className="text-sm text-muted-foreground">ozan@email.com</p>
|
<p className="text-sm text-muted-foreground">{product.category}</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="ml-auto font-medium">+₺1,999.00</div>
|
<div className="ml-auto font-medium">₺{Number(product.price).toLocaleString('tr-TR')}</div>
|
||||||
</div>
|
|
||||||
<div className="flex items-center">
|
|
||||||
<div className="h-9 w-9 rounded-full bg-slate-100 flex items-center justify-center">
|
|
||||||
<span className="font-bold text-xs">AÖ</span>
|
|
||||||
</div>
|
|
||||||
<div className="ml-4 space-y-1">
|
|
||||||
<p className="text-sm font-medium leading-none">Ayşe Özdemir</p>
|
|
||||||
<p className="text-sm text-muted-foreground">ayse@email.com</p>
|
|
||||||
</div>
|
|
||||||
<div className="ml-auto font-medium">+₺39.00</div>
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center">
|
|
||||||
<div className="h-9 w-9 rounded-full bg-slate-100 flex items-center justify-center">
|
|
||||||
<span className="font-bold text-xs">MK</span>
|
|
||||||
</div>
|
|
||||||
<div className="ml-4 space-y-1">
|
|
||||||
<p className="text-sm font-medium leading-none">Mehmet Kaya</p>
|
|
||||||
<p className="text-sm text-muted-foreground">mehmet@email.com</p>
|
|
||||||
</div>
|
|
||||||
<div className="ml-auto font-medium">+₺299.00</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
))}
|
||||||
|
{recentProducts.length === 0 && (
|
||||||
|
<div className="text-center py-4 text-muted-foreground">Henüz ürün yok.</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
{/* Recent Products or Other Info */}
|
{/* Placeholder for future features or quick actions */}
|
||||||
<Card className="col-span-3">
|
<Card className="col-span-3">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Son Eklenen Ürünler</CardTitle>
|
<CardTitle>Hızlı İşlemler</CardTitle>
|
||||||
<CardDescription>
|
<CardDescription>
|
||||||
Stoğa yeni giren ürünler.
|
Yönetim paneli kısayolları.
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<div className="space-y-4">
|
<div className="flex flex-col space-y-2">
|
||||||
<div className="flex justify-between items-center bg-slate-50 p-2 rounded">
|
<Link href="/dashboard/products/new">
|
||||||
<span className="text-sm font-medium">Çelik Kasa EV-100</span>
|
<Button variant="outline" className="w-full justify-start">
|
||||||
<span className="text-xs bg-green-100 text-green-700 px-2 py-1 rounded">Stokta</span>
|
<PlusIcon className="mr-2 h-4 w-4" /> Yeni Ürün Ekle
|
||||||
</div>
|
</Button>
|
||||||
<div className="flex justify-between items-center bg-slate-50 p-2 rounded">
|
</Link>
|
||||||
<span className="text-sm font-medium">Ofis Tipi XYZ</span>
|
<Button variant="outline" className="w-full justify-start" disabled>
|
||||||
<span className="text-xs bg-yellow-100 text-yellow-700 px-2 py-1 rounded">Azaldı</span>
|
<ShoppingCart className="mr-2 h-4 w-4" /> Siparişleri Yönet (Yakında)
|
||||||
</div>
|
</Button>
|
||||||
<div className="flex justify-between items-center bg-slate-50 p-2 rounded">
|
|
||||||
<span className="text-sm font-medium">Otel Kasası H-20</span>
|
|
||||||
<span className="text-xs bg-green-100 text-green-700 px-2 py-1 rounded">Stokta</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
@@ -128,3 +128,23 @@ export default function DashboardPage() {
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function PlusIcon(props: any) {
|
||||||
|
return (
|
||||||
|
<svg
|
||||||
|
{...props}
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
strokeWidth="2"
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
>
|
||||||
|
<path d="M5 12h14" />
|
||||||
|
<path d="M12 5v14" />
|
||||||
|
</svg>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
33
app/(dashboard)/dashboard/products/[productId]/page.tsx
Normal file
33
app/(dashboard)/dashboard/products/[productId]/page.tsx
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import { createClient } from "@/lib/supabase-server"
|
||||||
|
import { ProductForm } from "@/components/dashboard/product-form"
|
||||||
|
import { notFound } from "next/navigation"
|
||||||
|
|
||||||
|
interface ProductEditPageProps {
|
||||||
|
params: {
|
||||||
|
productId: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function ProductEditPage({ params }: ProductEditPageProps) {
|
||||||
|
const supabase = createClient()
|
||||||
|
const { data: product } = await supabase
|
||||||
|
.from("products")
|
||||||
|
.select("*")
|
||||||
|
.eq("id", params.productId)
|
||||||
|
.single()
|
||||||
|
|
||||||
|
if (!product) {
|
||||||
|
notFound()
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex-1 space-y-4 p-8 pt-6">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<h2 className="text-3xl font-bold tracking-tight">Ürün Düzenle</h2>
|
||||||
|
</div>
|
||||||
|
<div className="max-w-2xl">
|
||||||
|
<ProductForm initialData={product} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
51
app/(dashboard)/dashboard/products/actions.ts
Normal file
51
app/(dashboard)/dashboard/products/actions.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
"use server"
|
||||||
|
|
||||||
|
import { createClient } from "@/lib/supabase-server"
|
||||||
|
import { revalidatePath } from "next/cache"
|
||||||
|
|
||||||
|
export async function createProduct(data: any) {
|
||||||
|
const supabase = createClient()
|
||||||
|
|
||||||
|
// Validate data manually or use Zod schema here again securely
|
||||||
|
// For simplicity, we assume data is coming from the strongly typed Client Form
|
||||||
|
// In production, ALWAYS validate server-side strictly.
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { error } = await supabase.from("products").insert({
|
||||||
|
name: data.name,
|
||||||
|
category: data.category,
|
||||||
|
description: data.description,
|
||||||
|
price: data.price,
|
||||||
|
image_url: data.image_url,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (error) throw error
|
||||||
|
|
||||||
|
revalidatePath("/dashboard/products")
|
||||||
|
return { success: true }
|
||||||
|
} catch (error: any) {
|
||||||
|
return { success: false, error: error.message }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateProduct(id: number, data: any) {
|
||||||
|
const supabase = createClient()
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { error } = await supabase.from("products").update({
|
||||||
|
name: data.name,
|
||||||
|
category: data.category,
|
||||||
|
description: data.description,
|
||||||
|
price: data.price,
|
||||||
|
image_url: data.image_url,
|
||||||
|
}).eq("id", id)
|
||||||
|
|
||||||
|
if (error) throw error
|
||||||
|
|
||||||
|
revalidatePath("/dashboard/products")
|
||||||
|
revalidatePath(`/dashboard/products/${id}`)
|
||||||
|
return { success: true }
|
||||||
|
} catch (error: any) {
|
||||||
|
return { success: false, error: error.message }
|
||||||
|
}
|
||||||
|
}
|
||||||
14
app/(dashboard)/dashboard/products/new/page.tsx
Normal file
14
app/(dashboard)/dashboard/products/new/page.tsx
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { ProductForm } from "@/components/dashboard/product-form"
|
||||||
|
|
||||||
|
export default function NewProductPage() {
|
||||||
|
return (
|
||||||
|
<div className="flex-1 space-y-4 p-8 pt-6">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<h2 className="text-3xl font-bold tracking-tight">Yeni Ürün Ekle</h2>
|
||||||
|
</div>
|
||||||
|
<div className="max-w-2xl">
|
||||||
|
<ProductForm />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
75
app/(dashboard)/dashboard/products/page.tsx
Normal file
75
app/(dashboard)/dashboard/products/page.tsx
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
import { createClient } from "@/lib/supabase-server"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "@/components/ui/table"
|
||||||
|
import { Plus } from "lucide-react"
|
||||||
|
import Link from "next/link"
|
||||||
|
import { Badge } from "@/components/ui/badge"
|
||||||
|
|
||||||
|
export default async function ProductsPage() {
|
||||||
|
const supabase = createClient()
|
||||||
|
const { data: products } = await supabase
|
||||||
|
.from("products")
|
||||||
|
.select("*")
|
||||||
|
.order("created_at", { ascending: false })
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex-1 space-y-4 p-8 pt-6">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<h2 className="text-3xl font-bold tracking-tight">Ürünler</h2>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Link href="/dashboard/products/new">
|
||||||
|
<Button>
|
||||||
|
<Plus className="mr-2 h-4 w-4" /> Yeni Ekle
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="border rounded-md">
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>Ad</TableHead>
|
||||||
|
<TableHead>Kategori</TableHead>
|
||||||
|
<TableHead>Fiyat</TableHead>
|
||||||
|
<TableHead className="text-right">İşlemler</TableHead>
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{products?.length === 0 ? (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell colSpan={4} className="h-24 text-center">
|
||||||
|
Henüz ürün eklenmemiş.
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
) : (
|
||||||
|
products?.map((product) => (
|
||||||
|
<TableRow key={product.id}>
|
||||||
|
<TableCell className="font-medium">{product.name}</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Badge variant="secondary" className="capitalize">
|
||||||
|
{product.category}
|
||||||
|
</Badge>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>₺{product.price}</TableCell>
|
||||||
|
<TableCell className="text-right">
|
||||||
|
<Link href={`/dashboard/products/${product.id}`}>
|
||||||
|
<Button variant="ghost" size="sm">Düzenle</Button>
|
||||||
|
</Link>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
50
app/(dashboard)/dashboard/profile/page.tsx
Normal file
50
app/(dashboard)/dashboard/profile/page.tsx
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import { createClient } from "@/lib/supabase-server"
|
||||||
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||||
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Label } from "@/components/ui/label"
|
||||||
|
|
||||||
|
export default async function ProfilePage() {
|
||||||
|
const supabase = createClient()
|
||||||
|
const { data: { user } } = await supabase.auth.getUser()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex-1 space-y-4 p-8 pt-6">
|
||||||
|
<div className="flex items-center justify-between space-y-2">
|
||||||
|
<h2 className="text-3xl font-bold tracking-tight">Profil</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid gap-4 md:grid-cols-2">
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Genel Bilgiler</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
Kişisel profil bilgileriniz.
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-6">
|
||||||
|
<div className="flex items-center space-x-4">
|
||||||
|
<Avatar className="h-20 w-20">
|
||||||
|
<AvatarImage src="/avatars/01.png" alt="@parakasa" />
|
||||||
|
<AvatarFallback>PK</AvatarFallback>
|
||||||
|
</Avatar>
|
||||||
|
<Button variant="outline">Fotoğraf Değiştir</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-1">
|
||||||
|
<Label htmlFor="email">E-posta</Label>
|
||||||
|
<Input id="email" value={user?.email || ""} disabled />
|
||||||
|
<p className="text-xs text-muted-foreground">E-posta adresi değiştirilemez.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-1">
|
||||||
|
<Label htmlFor="role">Rol</Label>
|
||||||
|
<Input id="role" value={user?.role === 'authenticated' ? 'Yönetici' : 'Kullanıcı'} disabled />
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
42
app/(dashboard)/dashboard/settings/actions.ts
Normal file
42
app/(dashboard)/dashboard/settings/actions.ts
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
"use server"
|
||||||
|
|
||||||
|
import { createClient } from "@/lib/supabase-server"
|
||||||
|
import { revalidatePath } from "next/cache"
|
||||||
|
|
||||||
|
export async function updateSiteSettings(data: {
|
||||||
|
site_title: string
|
||||||
|
site_description: string
|
||||||
|
contact_email: string
|
||||||
|
contact_phone: string
|
||||||
|
currency: string
|
||||||
|
}) {
|
||||||
|
const supabase = createClient()
|
||||||
|
|
||||||
|
// Check admin is already handled by RLS on database level, but we can double check here
|
||||||
|
const { data: { user } } = await supabase.auth.getUser()
|
||||||
|
if (!user) return { error: "Oturum açmanız gerekiyor." }
|
||||||
|
|
||||||
|
// We update the single row where id is likely 1 or just the first row
|
||||||
|
// Since we initialized it with one row, we can just update match on something true or fetch id first.
|
||||||
|
// Easier: Update all rows (there should only be one) or fetch the specific ID first.
|
||||||
|
|
||||||
|
// Let's first get the ID just to be precise
|
||||||
|
const { data: existing } = await supabase.from('site_settings').select('id').single()
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
return { error: "Ayarlar bulunamadı." }
|
||||||
|
}
|
||||||
|
|
||||||
|
const { error } = await supabase
|
||||||
|
.from('site_settings')
|
||||||
|
.update(data)
|
||||||
|
.eq('id', existing.id)
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return { error: "Ayarlar güncellenemedi: " + error.message }
|
||||||
|
}
|
||||||
|
|
||||||
|
revalidatePath("/dashboard/settings")
|
||||||
|
revalidatePath("/") // Revalidate home as it might use these settings
|
||||||
|
return { success: true }
|
||||||
|
}
|
||||||
45
app/(dashboard)/dashboard/settings/page.tsx
Normal file
45
app/(dashboard)/dashboard/settings/page.tsx
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import { createClient } from "@/lib/supabase-server"
|
||||||
|
import { SiteSettingsForm } from "@/components/dashboard/site-settings-form"
|
||||||
|
import { AppearanceForm } from "@/components/dashboard/appearance-form"
|
||||||
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||||
|
import { Label } from "@/components/ui/label"
|
||||||
|
import { Switch } from "@/components/ui/switch"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
|
||||||
|
export default async function SettingsPage() {
|
||||||
|
const supabase = createClient()
|
||||||
|
|
||||||
|
// Fetch site settings
|
||||||
|
const { data: settings } = await supabase
|
||||||
|
.from('site_settings')
|
||||||
|
.select('*')
|
||||||
|
.single()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex-1 space-y-4 p-8 pt-6">
|
||||||
|
<h2 className="text-3xl font-bold tracking-tight">Ayarlar</h2>
|
||||||
|
|
||||||
|
{/* Site General Settings */}
|
||||||
|
<div className="grid gap-4">
|
||||||
|
<SiteSettingsForm initialData={settings} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid gap-4 grid-cols-1 md:grid-cols-2">
|
||||||
|
<AppearanceForm />
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Hesap Güvenliği</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
Şifre ve oturum yönetimi.
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-4">
|
||||||
|
<Button variant="outline" className="w-full">Şifre Değiştir</Button>
|
||||||
|
<Button variant="destructive" className="w-full">Hesabı Sil</Button>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
69
app/(dashboard)/dashboard/users/[userId]/page.tsx
Normal file
69
app/(dashboard)/dashboard/users/[userId]/page.tsx
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
import { createClient } from "@/lib/supabase-server"
|
||||||
|
import { UserForm } from "@/components/dashboard/user-form"
|
||||||
|
import { notFound } from "next/navigation"
|
||||||
|
|
||||||
|
export default async function EditUserPage({ params }: { params: { userId: string } }) {
|
||||||
|
const supabase = createClient()
|
||||||
|
|
||||||
|
// Fetch profile
|
||||||
|
const { data: profile } = await supabase
|
||||||
|
.from('profiles')
|
||||||
|
.select('*')
|
||||||
|
.eq('id', params.userId)
|
||||||
|
.single()
|
||||||
|
|
||||||
|
if (!profile) {
|
||||||
|
notFound()
|
||||||
|
}
|
||||||
|
|
||||||
|
// We also need the email, which is in auth.users, but we can't select from there easily with RLS/Client if not admin API
|
||||||
|
// However, our logged in user IS admin, but RLS on auth.users is usually strict.
|
||||||
|
// Let's see if we can get it via RPC or if the profile should store email (bad practice duplication, but helpful).
|
||||||
|
// Actually, `supabaseAdmin` in a server action can get it, but here we are in a Page (Server Component).
|
||||||
|
// We can use `supabaseAdmin` here too if we create a utility for it or just import createClient from supabase-js with admin key.
|
||||||
|
|
||||||
|
// WORKAROUND: For now, let's assume we might need a server function to fetch full user details including email
|
||||||
|
// OR we just update the profile part. But the user wants to update email probably.
|
||||||
|
// Let's write a small server action/function to fetch this data securely to render the form.
|
||||||
|
|
||||||
|
// Better: Helper function to get user details
|
||||||
|
const userDetails = await getUserDetails(params.userId)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex-1 space-y-4 p-8 pt-6">
|
||||||
|
<div className="flex items-center justify-between space-y-2">
|
||||||
|
<h2 className="text-3xl font-bold tracking-tight">Kullanıcı Düzenle</h2>
|
||||||
|
</div>
|
||||||
|
<UserForm initialData={userDetails} />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper to get admin-level data for the form
|
||||||
|
import { createClient as createSupabaseClient } from "@supabase/supabase-js"
|
||||||
|
|
||||||
|
async function getUserDetails(userId: string) {
|
||||||
|
const supabaseAdmin = createSupabaseClient(
|
||||||
|
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
||||||
|
process.env.SUPABASE_SERVICE_ROLE_KEY!,
|
||||||
|
{ auth: { autoRefreshToken: false, persistSession: false } }
|
||||||
|
)
|
||||||
|
|
||||||
|
const { data: { user }, error } = await supabaseAdmin.auth.admin.getUserById(userId)
|
||||||
|
const { data: profile } = await supabaseAdmin.from('profiles').select('*').eq('id', userId).single()
|
||||||
|
|
||||||
|
if (error || !user || !profile) return undefined
|
||||||
|
|
||||||
|
// Split full name
|
||||||
|
const parts = (profile.full_name || "").split(' ')
|
||||||
|
const firstName = parts[0] || ""
|
||||||
|
const lastName = parts.slice(1).join(' ') || ""
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: userId,
|
||||||
|
firstName,
|
||||||
|
lastName,
|
||||||
|
email: user.email || "",
|
||||||
|
role: profile.role as "admin" | "user"
|
||||||
|
}
|
||||||
|
}
|
||||||
133
app/(dashboard)/dashboard/users/actions.ts
Normal file
133
app/(dashboard)/dashboard/users/actions.ts
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
"use server"
|
||||||
|
|
||||||
|
import { createClient } from "@/lib/supabase-server"
|
||||||
|
import { createClient as createSupabaseClient } from "@supabase/supabase-js"
|
||||||
|
import { revalidatePath } from "next/cache"
|
||||||
|
import { redirect } from "next/navigation"
|
||||||
|
|
||||||
|
// WARNING: specialized client for admin actions only
|
||||||
|
// This requires SUPABASE_SERVICE_ROLE_KEY to be set in .env.local
|
||||||
|
const supabaseAdmin = createSupabaseClient(
|
||||||
|
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
||||||
|
process.env.SUPABASE_SERVICE_ROLE_KEY!,
|
||||||
|
{
|
||||||
|
auth: {
|
||||||
|
autoRefreshToken: false,
|
||||||
|
persistSession: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
export async function createUser(firstName: string, lastName: string, email: string, password: string, role: 'admin' | 'user') {
|
||||||
|
const supabase = createClient()
|
||||||
|
|
||||||
|
// 1. Check if current user is admin
|
||||||
|
const { data: { user: currentUser } } = await supabase.auth.getUser()
|
||||||
|
if (!currentUser) return { error: "Oturum açmanız gerekiyor." }
|
||||||
|
|
||||||
|
const { data: profile } = await supabase
|
||||||
|
.from('profiles')
|
||||||
|
.select('role')
|
||||||
|
.eq('id', currentUser.id)
|
||||||
|
.single()
|
||||||
|
|
||||||
|
if (!profile || profile.role !== 'admin') {
|
||||||
|
return { error: "Yetkisiz işlem. Sadece yöneticiler kullanıcı oluşturabilir." }
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Create user using Admin client
|
||||||
|
const { data: newUser, error: createError } = await supabaseAdmin.auth.admin.createUser({
|
||||||
|
email,
|
||||||
|
password,
|
||||||
|
email_confirm: true, // Auto confirm
|
||||||
|
user_metadata: {
|
||||||
|
full_name: `${firstName} ${lastName}`.trim()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (createError) {
|
||||||
|
return { error: createError.message }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!newUser.user) {
|
||||||
|
return { error: "Kullanıcı oluşturulamadı." }
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Create profile entry (if not handled by trigger, but we'll do it manually to be safe/explicit about role)
|
||||||
|
const { error: profileError } = await supabaseAdmin
|
||||||
|
.from('profiles')
|
||||||
|
.insert({
|
||||||
|
id: newUser.user.id,
|
||||||
|
full_name: `${firstName} ${lastName}`.trim(),
|
||||||
|
role: role
|
||||||
|
})
|
||||||
|
|
||||||
|
if (profileError) {
|
||||||
|
// Optional: delete auth user if profile creation fails?
|
||||||
|
// For now just return error
|
||||||
|
return { error: "Kullanıcı oluşturuldu ancak profil kaydedilemedi: " + profileError.message }
|
||||||
|
}
|
||||||
|
|
||||||
|
revalidatePath("/dashboard/users")
|
||||||
|
return { success: true }
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteUser(userId: string) {
|
||||||
|
const supabase = createClient()
|
||||||
|
|
||||||
|
// Check admin
|
||||||
|
const { data: { user: currentUser } } = await supabase.auth.getUser()
|
||||||
|
if (!currentUser) return { error: "Oturum açmanız gerekiyor." }
|
||||||
|
|
||||||
|
const { data: profile } = await supabase.from('profiles').select('role').eq('id', currentUser.id).single()
|
||||||
|
if (profile?.role !== 'admin') return { error: "Yetkisiz işlem." }
|
||||||
|
|
||||||
|
// Delete user
|
||||||
|
const { error } = await supabaseAdmin.auth.admin.deleteUser(userId)
|
||||||
|
|
||||||
|
if (error) return { error: error.message }
|
||||||
|
|
||||||
|
revalidatePath("/dashboard/users")
|
||||||
|
return { success: true }
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateUser(userId: string, data: { firstName: string, lastName: string, email: string, password?: string, role: 'admin' | 'user' }) {
|
||||||
|
const supabase = createClient()
|
||||||
|
|
||||||
|
// Check admin
|
||||||
|
const { data: { user: currentUser } } = await supabase.auth.getUser()
|
||||||
|
if (!currentUser) return { error: "Oturum açmanız gerekiyor." }
|
||||||
|
|
||||||
|
// Check if current user is admin
|
||||||
|
const { data: profile } = await supabase.from('profiles').select('role').eq('id', currentUser.id).single()
|
||||||
|
if (profile?.role !== 'admin') return { error: "Yetkisiz işlem." }
|
||||||
|
|
||||||
|
// 1. Update Profile (Role and Name)
|
||||||
|
const { error: profileError } = await supabaseAdmin
|
||||||
|
.from('profiles')
|
||||||
|
.update({
|
||||||
|
full_name: `${data.firstName} ${data.lastName}`.trim(),
|
||||||
|
role: data.role
|
||||||
|
})
|
||||||
|
.eq('id', userId)
|
||||||
|
|
||||||
|
if (profileError) return { error: "Profil güncellenemedi: " + profileError.message }
|
||||||
|
|
||||||
|
// 2. Update Auth (Email and Password)
|
||||||
|
const authUpdates: any = {
|
||||||
|
email: data.email,
|
||||||
|
user_metadata: {
|
||||||
|
full_name: `${data.firstName} ${data.lastName}`.trim()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (data.password && data.password.length >= 6) {
|
||||||
|
authUpdates.password = data.password
|
||||||
|
}
|
||||||
|
|
||||||
|
const { error: authError } = await supabaseAdmin.auth.admin.updateUserById(userId, authUpdates)
|
||||||
|
|
||||||
|
if (authError) return { error: "Kullanıcı giriş bilgileri güncellenemedi: " + authError.message }
|
||||||
|
|
||||||
|
revalidatePath("/dashboard/users")
|
||||||
|
return { success: true }
|
||||||
|
}
|
||||||
13
app/(dashboard)/dashboard/users/new/page.tsx
Normal file
13
app/(dashboard)/dashboard/users/new/page.tsx
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
import { UserForm } from "@/components/dashboard/user-form"
|
||||||
|
|
||||||
|
export default function NewUserPage() {
|
||||||
|
return (
|
||||||
|
<div className="flex-1 space-y-4 p-8 pt-6">
|
||||||
|
<div className="flex items-center justify-between space-y-2">
|
||||||
|
<h2 className="text-3xl font-bold tracking-tight">Yeni Kullanıcı Ekle</h2>
|
||||||
|
</div>
|
||||||
|
<UserForm />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
87
app/(dashboard)/dashboard/users/page.tsx
Normal file
87
app/(dashboard)/dashboard/users/page.tsx
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
import { createClient } from "@/lib/supabase-server"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import Link from "next/link"
|
||||||
|
import { Plus } from "lucide-react"
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "@/components/ui/table"
|
||||||
|
import { Badge } from "@/components/ui/badge"
|
||||||
|
|
||||||
|
export default async function UsersPage() {
|
||||||
|
const supabase = createClient()
|
||||||
|
const { data: { user } } = await supabase.auth.getUser()
|
||||||
|
|
||||||
|
// Protected Route Check (Simple)
|
||||||
|
const { data: currentUserProfile } = await supabase
|
||||||
|
.from('profiles')
|
||||||
|
.select('role')
|
||||||
|
.eq('id', user?.id)
|
||||||
|
.single()
|
||||||
|
|
||||||
|
// Only verify if we have profiles, if not (first run), maybe allow?
|
||||||
|
// But for safety, blocking non-admins.
|
||||||
|
if (currentUserProfile?.role !== 'admin') {
|
||||||
|
return (
|
||||||
|
<div className="flex-1 p-8 pt-6">
|
||||||
|
<h2 className="text-3xl font-bold tracking-tight text-red-600">Yetkisiz Erişim</h2>
|
||||||
|
<p>Bu sayfayı görüntüleme yetkiniz yok.</p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data: profiles } = await supabase
|
||||||
|
.from("profiles")
|
||||||
|
.select("*")
|
||||||
|
.order("created_at", { ascending: false })
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex-1 space-y-4 p-8 pt-6">
|
||||||
|
<div className="flex items-center justify-between space-y-2">
|
||||||
|
<h2 className="text-3xl font-bold tracking-tight">Kullanıcı Yönetimi</h2>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Link href="/dashboard/users/new">
|
||||||
|
<Button>
|
||||||
|
<Plus className="mr-2 h-4 w-4" /> Yeni Kullanıcı
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="rounded-md border">
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>Ad Soyad</TableHead>
|
||||||
|
<TableHead>Rol</TableHead>
|
||||||
|
<TableHead>Kayıt Tarihi</TableHead>
|
||||||
|
<TableHead className="text-right">İşlemler</TableHead>
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{profiles?.map((profile) => (
|
||||||
|
<TableRow key={profile.id}>
|
||||||
|
<TableCell className="font-medium">{profile.full_name}</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Badge variant={profile.role === 'admin' ? 'default' : 'secondary'}>
|
||||||
|
{profile.role === 'admin' ? 'Yönetici' : 'Kullanıcı'}
|
||||||
|
</Badge>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>{new Date(profile.created_at).toLocaleDateString('tr-TR')}</TableCell>
|
||||||
|
<TableCell className="text-right">
|
||||||
|
<Link href={`/dashboard/users/${profile.id}`}>
|
||||||
|
<Button variant="ghost" size="sm">Düzenle</Button>
|
||||||
|
</Link>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { useRouter } from "next/navigation"
|
import { useRouter } from "next/navigation"
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
import { supabase } from "@/lib/supabase"
|
import { createClient } from "@/lib/supabase-browser"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import { Input } from "@/components/ui/input"
|
import { Input } from "@/components/ui/input"
|
||||||
import { Label } from "@/components/ui/label"
|
import { Label } from "@/components/ui/label"
|
||||||
@@ -11,6 +11,7 @@ import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle }
|
|||||||
import { AlertCircle, Loader2 } from "lucide-react"
|
import { AlertCircle, Loader2 } from "lucide-react"
|
||||||
|
|
||||||
export default function LoginPage() {
|
export default function LoginPage() {
|
||||||
|
const supabase = createClient()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const [email, setEmail] = useState("")
|
const [email, setEmail] = useState("")
|
||||||
const [password, setPassword] = useState("")
|
const [password, setPassword] = useState("")
|
||||||
@@ -33,7 +34,7 @@ export default function LoginPage() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
router.push("/")
|
router.push("/dashboard")
|
||||||
router.refresh()
|
router.refresh()
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
setError("Bir hata oluştu. Lütfen tekrar deneyin.")
|
setError("Bir hata oluştu. Lütfen tekrar deneyin.")
|
||||||
|
|||||||
@@ -6,10 +6,20 @@ import "./globals.css";
|
|||||||
const inter = Inter({ subsets: ["latin"] });
|
const inter = Inter({ subsets: ["latin"] });
|
||||||
const outfit = Outfit({ subsets: ["latin"], variable: "--font-outfit" });
|
const outfit = Outfit({ subsets: ["latin"], variable: "--font-outfit" });
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
import { getSiteSettings } from "@/lib/site-settings";
|
||||||
title: "ParaKasa - Premium Çelik Kasalar",
|
|
||||||
description: "Eviniz ve iş yeriniz için en yüksek güvenlikli çelik kasa ve para sayma çözümleri.",
|
export async function generateMetadata() {
|
||||||
};
|
const settings = await getSiteSettings();
|
||||||
|
|
||||||
|
return {
|
||||||
|
title: settings?.site_title || "ParaKasa - Premium Çelik Kasalar",
|
||||||
|
description: settings?.site_description || "Eviniz ve iş yeriniz için en yüksek güvenlikli çelik kasa ve para sayma çözümleri.",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
import { ThemeProvider } from "@/components/theme-provider"
|
||||||
|
|
||||||
|
// ... imports
|
||||||
|
|
||||||
export default function RootLayout({
|
export default function RootLayout({
|
||||||
children,
|
children,
|
||||||
@@ -17,12 +27,19 @@ export default function RootLayout({
|
|||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}>) {
|
}>) {
|
||||||
return (
|
return (
|
||||||
<html lang="tr">
|
<html lang="tr" suppressHydrationWarning>
|
||||||
<body
|
<body
|
||||||
className={`${inter.className} ${outfit.variable} antialiased min-h-screen flex flex-col`}
|
className={`${inter.className} ${outfit.variable} antialiased min-h-screen flex flex-col`}
|
||||||
|
>
|
||||||
|
<ThemeProvider
|
||||||
|
attribute="class"
|
||||||
|
defaultTheme="system"
|
||||||
|
enableSystem
|
||||||
|
disableTransitionOnChange
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
<Toaster />
|
<Toaster />
|
||||||
|
</ThemeProvider>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
);
|
);
|
||||||
|
|||||||
57
components/dashboard/appearance-form.tsx
Normal file
57
components/dashboard/appearance-form.tsx
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useTheme } from "next-themes"
|
||||||
|
import { Card, CardContent, CardTitle, CardHeader } from "@/components/ui/card"
|
||||||
|
import { Label } from "@/components/ui/label"
|
||||||
|
import { Switch } from "@/components/ui/switch"
|
||||||
|
import { useEffect, useState } from "react"
|
||||||
|
|
||||||
|
export function AppearanceForm() {
|
||||||
|
const { theme, setTheme } = useTheme()
|
||||||
|
const [mounted, setMounted] = useState(false)
|
||||||
|
|
||||||
|
// Avoid hydration mismatch
|
||||||
|
useEffect(() => {
|
||||||
|
setMounted(true)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
if (!mounted) {
|
||||||
|
return (
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Görünüm</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-4">
|
||||||
|
<div className="flex items-center justify-between space-y-2">
|
||||||
|
<Label htmlFor="dark-mode" className="flex flex-col space-y-1">
|
||||||
|
<span>Karanlık Mod</span>
|
||||||
|
<span className="font-normal text-xs text-muted-foreground">Koyu temayı etkinleştir.</span>
|
||||||
|
</Label>
|
||||||
|
<Switch id="dark-mode" disabled />
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Görünüm</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-4">
|
||||||
|
<div className="flex items-center justify-between space-y-2">
|
||||||
|
<Label htmlFor="dark-mode" className="flex flex-col space-y-1">
|
||||||
|
<span>Karanlık Mod</span>
|
||||||
|
<span className="font-normal text-xs text-muted-foreground">Koyu temayı etkinleştir.</span>
|
||||||
|
</Label>
|
||||||
|
<Switch
|
||||||
|
id="dark-mode"
|
||||||
|
checked={theme === 'dark'}
|
||||||
|
onCheckedChange={(checked) => setTheme(checked ? 'dark' : 'light')}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
)
|
||||||
|
}
|
||||||
186
components/dashboard/category-form.tsx
Normal file
186
components/dashboard/category-form.tsx
Normal file
@@ -0,0 +1,186 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useState } from "react"
|
||||||
|
import { useForm } from "react-hook-form"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import * as z from "zod"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Textarea } from "@/components/ui/textarea"
|
||||||
|
import {
|
||||||
|
Form,
|
||||||
|
FormControl,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormMessage,
|
||||||
|
} from "@/components/ui/form"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
import { useRouter } from "next/navigation"
|
||||||
|
import { createCategory, updateCategory, deleteCategory } from "@/app/(dashboard)/dashboard/categories/actions"
|
||||||
|
import { Trash } from "lucide-react"
|
||||||
|
import { AlertModal } from "@/components/modals/alert-modal"
|
||||||
|
|
||||||
|
const formSchema = z.object({
|
||||||
|
name: z.string().min(2, "Kategori adı en az 2 karakter olmalıdır."),
|
||||||
|
description: z.string().optional(),
|
||||||
|
image_url: z.string().optional(),
|
||||||
|
})
|
||||||
|
|
||||||
|
type CategoryFormValues = z.infer<typeof formSchema>
|
||||||
|
|
||||||
|
interface CategoryFormProps {
|
||||||
|
initialData?: {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
description?: string
|
||||||
|
image_url?: string
|
||||||
|
} | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CategoryForm({ initialData }: CategoryFormProps) {
|
||||||
|
const router = useRouter()
|
||||||
|
const [open, setOpen] = useState(false)
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
|
||||||
|
const title = initialData ? "Kategoriyi Düzenle" : "Yeni Kategori"
|
||||||
|
const description = initialData ? "Kategori detaylarını düzenleyin." : "Yeni bir kategori ekleyin."
|
||||||
|
const toastMessage = initialData ? "Kategori güncellendi." : "Kategori oluşturuldu."
|
||||||
|
const action = initialData ? "Kaydet" : "Oluştur"
|
||||||
|
|
||||||
|
const form = useForm<CategoryFormValues>({
|
||||||
|
resolver: zodResolver(formSchema),
|
||||||
|
defaultValues: initialData || {
|
||||||
|
name: "",
|
||||||
|
description: "",
|
||||||
|
image_url: "",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const onSubmit = async (data: CategoryFormValues) => {
|
||||||
|
setLoading(true)
|
||||||
|
try {
|
||||||
|
if (initialData) {
|
||||||
|
const result = await updateCategory(initialData.id, data)
|
||||||
|
if ((result as any).error) {
|
||||||
|
toast.error((result as any).error)
|
||||||
|
} else {
|
||||||
|
toast.success(toastMessage)
|
||||||
|
router.push(`/dashboard/categories`)
|
||||||
|
router.refresh()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const result = await createCategory(data)
|
||||||
|
if ((result as any).error) {
|
||||||
|
toast.error((result as any).error)
|
||||||
|
} else {
|
||||||
|
toast.success(toastMessage)
|
||||||
|
router.push(`/dashboard/categories`)
|
||||||
|
router.refresh()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
toast.error("Bir hata oluştu.")
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const onDelete = async () => {
|
||||||
|
setLoading(true)
|
||||||
|
try {
|
||||||
|
const result = await deleteCategory(initialData!.id)
|
||||||
|
if ((result as any).error) {
|
||||||
|
toast.error((result as any).error)
|
||||||
|
} else {
|
||||||
|
toast.success("Kategori silindi.")
|
||||||
|
router.push(`/dashboard/categories`)
|
||||||
|
router.refresh()
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
toast.error("Silme işlemi başarısız.")
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
setOpen(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<AlertModal
|
||||||
|
isOpen={open}
|
||||||
|
onClose={() => setOpen(false)}
|
||||||
|
onConfirm={onDelete}
|
||||||
|
loading={loading}
|
||||||
|
/>
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div className="space-y-1">
|
||||||
|
<h2 className="text-2xl font-bold tracking-tight">{title}</h2>
|
||||||
|
<p className="text-sm text-muted-foreground">{description}</p>
|
||||||
|
</div>
|
||||||
|
{initialData && (
|
||||||
|
<Button
|
||||||
|
variant="destructive"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => setOpen(true)}
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
|
<Trash className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="p-4 border rounded-md mt-4">
|
||||||
|
<Form {...form}>
|
||||||
|
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8 w-full">
|
||||||
|
<div className="grid grid-cols-1 gap-8 md:grid-cols-2">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="name"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Başlık</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input disabled={loading} placeholder="Kategori adı..." {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="image_url"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Görsel URL (Opsiyonel)</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input disabled={loading} placeholder="https://..." {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<div className="col-span-1 md:col-span-2">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="description"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Açıklama</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Textarea disabled={loading} placeholder="Kategori açıklaması..." {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Button disabled={loading} className="ml-auto" type="submit">
|
||||||
|
{action}
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
200
components/dashboard/product-form.tsx
Normal file
200
components/dashboard/product-form.tsx
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useState } from "react"
|
||||||
|
import { useForm } from "react-hook-form"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import * as z from "zod"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Form,
|
||||||
|
FormControl,
|
||||||
|
FormDescription,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormMessage,
|
||||||
|
} from "@/components/ui/form"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Textarea } from "@/components/ui/textarea"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
|
import { useRouter } from "next/navigation"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
import { Loader2 } from "lucide-react"
|
||||||
|
|
||||||
|
const productSchema = z.object({
|
||||||
|
name: z.string().min(2, "Ürün adı en az 2 karakter olmalıdır"),
|
||||||
|
category: z.string().min(1, "Kategori seçiniz"),
|
||||||
|
description: z.string().optional(),
|
||||||
|
price: z.coerce.number().min(0, "Fiyat 0'dan küçük olamaz"),
|
||||||
|
image_url: z.string().optional(),
|
||||||
|
})
|
||||||
|
|
||||||
|
type ProductFormValues = z.infer<typeof productSchema>
|
||||||
|
|
||||||
|
import { createProduct, updateProduct } from "@/app/(dashboard)/dashboard/products/actions"
|
||||||
|
|
||||||
|
// Define the shape of data coming from Supabase
|
||||||
|
interface Product {
|
||||||
|
id: number
|
||||||
|
name: string
|
||||||
|
category: string
|
||||||
|
description: string | null
|
||||||
|
price: number
|
||||||
|
image_url: string | null
|
||||||
|
created_at: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ProductFormProps {
|
||||||
|
initialData?: Product
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ProductForm({ initialData }: ProductFormProps) {
|
||||||
|
const router = useRouter()
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
|
||||||
|
const form = useForm<ProductFormValues>({
|
||||||
|
resolver: zodResolver(productSchema) as any,
|
||||||
|
defaultValues: initialData ? {
|
||||||
|
name: initialData.name,
|
||||||
|
category: initialData.category,
|
||||||
|
description: initialData.description || "",
|
||||||
|
price: initialData.price,
|
||||||
|
image_url: initialData.image_url || "",
|
||||||
|
} : {
|
||||||
|
name: "",
|
||||||
|
category: "",
|
||||||
|
description: "",
|
||||||
|
price: 0,
|
||||||
|
image_url: "",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
async function onSubmit(data: ProductFormValues) {
|
||||||
|
try {
|
||||||
|
setLoading(true)
|
||||||
|
|
||||||
|
let result
|
||||||
|
if (initialData) {
|
||||||
|
result = await updateProduct(initialData.id, data)
|
||||||
|
} else {
|
||||||
|
result = await createProduct(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!result.success) {
|
||||||
|
toast.error(result.error || "Bir hata oluştu")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
toast.success(initialData ? "Ürün güncellendi" : "Ürün başarıyla oluşturuldu")
|
||||||
|
router.push("/dashboard/products")
|
||||||
|
router.refresh()
|
||||||
|
} catch (error) {
|
||||||
|
toast.error("Bir aksilik oldu")
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form {...form}>
|
||||||
|
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8 w-full max-w-2xl">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="name"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Ürün Adı</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Çelik Kasa Model X" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="category"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Kategori</FormLabel>
|
||||||
|
<Select onValueChange={field.onChange} defaultValue={field.value}>
|
||||||
|
<FormControl>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="Kategori seçin" />
|
||||||
|
</SelectTrigger>
|
||||||
|
</FormControl>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="ev">Ev Tipi</SelectItem>
|
||||||
|
<SelectItem value="ofis">Ofis Tipi</SelectItem>
|
||||||
|
<SelectItem value="otel">Otel Kasası</SelectItem>
|
||||||
|
<SelectItem value="ozel">Özel Üretim</SelectItem>
|
||||||
|
<SelectItem value="diger">Diğer</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="price"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Fiyat (₺)</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input type="number" placeholder="0.00" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="image_url"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Görsel URL (Opsiyonel)</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="https://..." {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormDescription>
|
||||||
|
Ürün görseli için şimdilik dış bağlantı kullanın.
|
||||||
|
</FormDescription>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="description"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Açıklama</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Textarea placeholder="Ürün özellikleri..." {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Button type="submit" disabled={loading}>
|
||||||
|
{loading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
||||||
|
{initialData ? "Güncelle" : "Oluştur"}
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
import { usePathname } from "next/navigation"
|
import { usePathname } from "next/navigation"
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
import { LayoutDashboard, Package, ShoppingCart, Users, Settings } from "lucide-react"
|
import { LayoutDashboard, Package, ShoppingCart, Users, Settings, Globe, Tags } from "lucide-react"
|
||||||
|
|
||||||
const sidebarItems = [
|
const sidebarItems = [
|
||||||
{
|
{
|
||||||
@@ -21,6 +21,11 @@ const sidebarItems = [
|
|||||||
href: "/dashboard/orders",
|
href: "/dashboard/orders",
|
||||||
icon: ShoppingCart,
|
icon: ShoppingCart,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: "Kategoriler",
|
||||||
|
href: "/dashboard/categories",
|
||||||
|
icon: Tags,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: "Kullanıcılar",
|
title: "Kullanıcılar",
|
||||||
href: "/dashboard/users",
|
href: "/dashboard/users",
|
||||||
@@ -31,6 +36,11 @@ const sidebarItems = [
|
|||||||
href: "/dashboard/settings",
|
href: "/dashboard/settings",
|
||||||
icon: Settings,
|
icon: Settings,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: "Siteye Dön",
|
||||||
|
href: "/",
|
||||||
|
icon: Globe,
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
interface SidebarProps extends React.HTMLAttributes<HTMLDivElement> { }
|
interface SidebarProps extends React.HTMLAttributes<HTMLDivElement> { }
|
||||||
|
|||||||
164
components/dashboard/site-settings-form.tsx
Normal file
164
components/dashboard/site-settings-form.tsx
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useState } from "react"
|
||||||
|
import { useRouter } from "next/navigation"
|
||||||
|
import { useForm } from "react-hook-form"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import * as z from "zod"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Textarea } from "@/components/ui/textarea"
|
||||||
|
import {
|
||||||
|
Form,
|
||||||
|
FormControl,
|
||||||
|
FormDescription,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormMessage,
|
||||||
|
} from "@/components/ui/form"
|
||||||
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
import { Loader2 } from "lucide-react"
|
||||||
|
import { updateSiteSettings } from "@/app/(dashboard)/dashboard/settings/actions"
|
||||||
|
|
||||||
|
const settingsSchema = z.object({
|
||||||
|
site_title: z.string().min(2, "Site başlığı en az 2 karakter olmalıdır."),
|
||||||
|
site_description: z.string().optional(),
|
||||||
|
contact_email: z.string().email("Geçerli bir e-posta adresi giriniz.").optional().or(z.literal("")),
|
||||||
|
contact_phone: z.string().optional(),
|
||||||
|
currency: z.string().default("TRY"),
|
||||||
|
})
|
||||||
|
|
||||||
|
type SettingsFormValues = z.infer<typeof settingsSchema>
|
||||||
|
|
||||||
|
interface SiteSettingsFormProps {
|
||||||
|
initialData: any
|
||||||
|
}
|
||||||
|
|
||||||
|
export function SiteSettingsForm({ initialData }: SiteSettingsFormProps) {
|
||||||
|
const router = useRouter()
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
|
||||||
|
const form = useForm<SettingsFormValues>({
|
||||||
|
resolver: zodResolver(settingsSchema),
|
||||||
|
defaultValues: {
|
||||||
|
site_title: initialData?.site_title || "ParaKasa",
|
||||||
|
site_description: initialData?.site_description || "",
|
||||||
|
contact_email: initialData?.contact_email || "",
|
||||||
|
contact_phone: initialData?.contact_phone || "",
|
||||||
|
currency: initialData?.currency || "TRY",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const onSubmit = async (data: SettingsFormValues) => {
|
||||||
|
setLoading(true)
|
||||||
|
try {
|
||||||
|
// @ts-ignore
|
||||||
|
const result = await updateSiteSettings(data)
|
||||||
|
|
||||||
|
if (result.error) {
|
||||||
|
toast.error(result.error)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
toast.success("Site ayarları güncellendi.")
|
||||||
|
router.refresh()
|
||||||
|
} catch (error) {
|
||||||
|
toast.error("Bir sorun oluştu.")
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Genel Ayarlar</CardTitle>
|
||||||
|
<CardDescription>Web sitesinin genel yapılandırma ayarları.</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<Form {...form}>
|
||||||
|
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="site_title"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Site Başlığı</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="ParaKasa" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormDescription>Tarayıcı sekmesinde görünen ad.</FormDescription>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="site_description"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Site Açıklaması</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Textarea placeholder="Premium çelik kasalar..." {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="contact_email"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>İletişim E-posta</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="info@parakasa.com" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="contact_phone"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>İletişim Telefon</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="+90 555 123 45 67" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="currency"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Para Birimi</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="TRY" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Button type="submit" disabled={loading}>
|
||||||
|
{loading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
||||||
|
Ayarları Kaydet
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
)
|
||||||
|
}
|
||||||
201
components/dashboard/user-form.tsx
Normal file
201
components/dashboard/user-form.tsx
Normal file
@@ -0,0 +1,201 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useState } from "react"
|
||||||
|
import { useRouter } from "next/navigation"
|
||||||
|
import { useForm } from "react-hook-form"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import * as z from "zod"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import {
|
||||||
|
Form,
|
||||||
|
FormControl,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormMessage,
|
||||||
|
} from "@/components/ui/form"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
|
import { Card, CardContent } from "@/components/ui/card"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
import { Loader2 } from "lucide-react"
|
||||||
|
import { createUser, updateUser } from "@/app/(dashboard)/dashboard/users/actions"
|
||||||
|
|
||||||
|
const userSchema = z.object({
|
||||||
|
firstName: z.string().min(2, "Ad en az 2 karakter olmalıdır."),
|
||||||
|
lastName: z.string().min(2, "Soyad en az 2 karakter olmalıdır."),
|
||||||
|
email: z.string().email("Geçerli bir e-posta adresi giriniz."),
|
||||||
|
password: z.string().optional(), // Password is optional on edit
|
||||||
|
role: z.enum(["admin", "user"]),
|
||||||
|
}).refine((data) => {
|
||||||
|
// If we are creating a NEW user (no ID passed in props effectively, but schema doesn't know props),
|
||||||
|
// we generally want password required. But here we'll handle it in the component logic or strictly separate schemas.
|
||||||
|
// For simplicity, we make password optional in Zod but check it in onSubmit if it's a create action.
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
type UserFormValues = z.infer<typeof userSchema>
|
||||||
|
|
||||||
|
interface UserFormProps {
|
||||||
|
initialData?: {
|
||||||
|
id: string
|
||||||
|
firstName: string
|
||||||
|
lastName: string
|
||||||
|
email: string
|
||||||
|
role: "admin" | "user"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function UserForm({ initialData }: UserFormProps) {
|
||||||
|
const router = useRouter()
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
|
||||||
|
const form = useForm<UserFormValues>({
|
||||||
|
resolver: zodResolver(userSchema),
|
||||||
|
defaultValues: initialData ? {
|
||||||
|
firstName: initialData.firstName,
|
||||||
|
lastName: initialData.lastName,
|
||||||
|
email: initialData.email,
|
||||||
|
password: "", // Empty password means no change
|
||||||
|
role: initialData.role,
|
||||||
|
} : {
|
||||||
|
firstName: "",
|
||||||
|
lastName: "",
|
||||||
|
email: "",
|
||||||
|
password: "",
|
||||||
|
role: "user",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const onSubmit = async (data: UserFormValues) => {
|
||||||
|
setLoading(true)
|
||||||
|
try {
|
||||||
|
let result;
|
||||||
|
if (initialData) {
|
||||||
|
// Update
|
||||||
|
result = await updateUser(initialData.id, data)
|
||||||
|
} else {
|
||||||
|
// Create
|
||||||
|
if (!data.password || data.password.length < 6) {
|
||||||
|
toast.error("Yeni kullanıcı için şifre gereklidir (min 6 karakter).")
|
||||||
|
setLoading(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
result = await createUser(data.firstName, data.lastName, data.email, data.password, data.role)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.error) {
|
||||||
|
toast.error(result.error)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
toast.success(initialData ? "Kullanıcı güncellendi." : "Kullanıcı oluşturuldu.")
|
||||||
|
router.push("/dashboard/users")
|
||||||
|
router.refresh()
|
||||||
|
} catch (error) {
|
||||||
|
toast.error("Bir sorun oluştu.")
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card className="max-w-xl">
|
||||||
|
<CardContent className="pt-6">
|
||||||
|
<Form {...form}>
|
||||||
|
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="firstName"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Ad</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Ahmet" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="lastName"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Soyad</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Yılmaz" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="email"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>E-posta</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="ahmet@parakasa.com" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="password"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Şifre</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input type="password" placeholder={initialData ? "Değiştirmek için yeni şifre girin" : "******"} {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="role"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Rol</FormLabel>
|
||||||
|
<Select onValueChange={field.onChange} defaultValue={field.value}>
|
||||||
|
<FormControl>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="Rol seçin" />
|
||||||
|
</SelectTrigger>
|
||||||
|
</FormControl>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="user">Kullanıcı</SelectItem>
|
||||||
|
<SelectItem value="admin">Yönetici</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Button type="submit" disabled={loading} className="w-full">
|
||||||
|
{loading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
||||||
|
Kullanıcı Oluştur
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
AvatarImage,
|
AvatarImage,
|
||||||
} from "@/components/ui/avatar"
|
} from "@/components/ui/avatar"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
|
import Link from "next/link"
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
@@ -49,12 +50,21 @@ export function UserNav() {
|
|||||||
</DropdownMenuLabel>
|
</DropdownMenuLabel>
|
||||||
<DropdownMenuSeparator />
|
<DropdownMenuSeparator />
|
||||||
<DropdownMenuGroup>
|
<DropdownMenuGroup>
|
||||||
<DropdownMenuItem>
|
<Link href="/dashboard/profile">
|
||||||
|
<DropdownMenuItem className="cursor-pointer">
|
||||||
Profil
|
Profil
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem>
|
</Link>
|
||||||
|
<Link href="/dashboard/users">
|
||||||
|
<DropdownMenuItem className="cursor-pointer">
|
||||||
|
Kullanıcılar
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</Link>
|
||||||
|
<Link href="/dashboard/settings">
|
||||||
|
<DropdownMenuItem className="cursor-pointer">
|
||||||
Ayarlar
|
Ayarlar
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
|
</Link>
|
||||||
</DropdownMenuGroup>
|
</DropdownMenuGroup>
|
||||||
<DropdownMenuSeparator />
|
<DropdownMenuSeparator />
|
||||||
<DropdownMenuItem onClick={handleSignOut}>
|
<DropdownMenuItem onClick={handleSignOut}>
|
||||||
|
|||||||
57
components/modals/alert-modal.tsx
Normal file
57
components/modals/alert-modal.tsx
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
|
|
||||||
|
interface AlertModalProps {
|
||||||
|
isOpen: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
onConfirm: () => void;
|
||||||
|
loading: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const AlertModal: React.FC<AlertModalProps> = ({
|
||||||
|
isOpen,
|
||||||
|
onClose,
|
||||||
|
onConfirm,
|
||||||
|
loading,
|
||||||
|
}) => {
|
||||||
|
const [isMounted, setIsMounted] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setIsMounted(true);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (!isMounted) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={isOpen} onOpenChange={onClose}>
|
||||||
|
<DialogContent>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Emin misiniz?</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Bu işlem geri alınamaz. Bu kategoriyi kalıcı olarak silmek istediğinizden emin misiniz?
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<DialogFooter className="pt-6 space-x-2 flex items-center justify-end w-full">
|
||||||
|
<Button disabled={loading} variant="outline" onClick={onClose}>
|
||||||
|
İptal
|
||||||
|
</Button>
|
||||||
|
<Button disabled={loading} variant="destructive" onClick={onConfirm}>
|
||||||
|
Devam Et
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
};
|
||||||
9
components/theme-provider.tsx
Normal file
9
components/theme-provider.tsx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import { ThemeProvider as NextThemesProvider } from "next-themes"
|
||||||
|
import { type ThemeProviderProps } from "next-themes/dist/types"
|
||||||
|
|
||||||
|
export function ThemeProvider({ children, ...props }: ThemeProviderProps) {
|
||||||
|
return <NextThemesProvider {...props}>{children}</NextThemesProvider>
|
||||||
|
}
|
||||||
46
components/ui/badge.tsx
Normal file
46
components/ui/badge.tsx
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import * as React from "react"
|
||||||
|
import { Slot } from "@radix-ui/react-slot"
|
||||||
|
import { cva, type VariantProps } from "class-variance-authority"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
const badgeVariants = cva(
|
||||||
|
"inline-flex items-center justify-center rounded-full border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
variant: {
|
||||||
|
default:
|
||||||
|
"border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
|
||||||
|
secondary:
|
||||||
|
"border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
|
||||||
|
destructive:
|
||||||
|
"border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
||||||
|
outline:
|
||||||
|
"text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: "default",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
function Badge({
|
||||||
|
className,
|
||||||
|
variant,
|
||||||
|
asChild = false,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"span"> &
|
||||||
|
VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
|
||||||
|
const Comp = asChild ? Slot : "span"
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Comp
|
||||||
|
data-slot="badge"
|
||||||
|
className={cn(badgeVariants({ variant }), className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Badge, badgeVariants }
|
||||||
143
components/ui/dialog.tsx
Normal file
143
components/ui/dialog.tsx
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import * as DialogPrimitive from "@radix-ui/react-dialog"
|
||||||
|
import { XIcon } from "lucide-react"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
function Dialog({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Root>) {
|
||||||
|
return <DialogPrimitive.Root data-slot="dialog" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogTrigger({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
|
||||||
|
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogPortal({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Portal>) {
|
||||||
|
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogClose({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Close>) {
|
||||||
|
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogOverlay({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Overlay>) {
|
||||||
|
return (
|
||||||
|
<DialogPrimitive.Overlay
|
||||||
|
data-slot="dialog-overlay"
|
||||||
|
className={cn(
|
||||||
|
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogContent({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
showCloseButton = true,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Content> & {
|
||||||
|
showCloseButton?: boolean
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<DialogPortal data-slot="dialog-portal">
|
||||||
|
<DialogOverlay />
|
||||||
|
<DialogPrimitive.Content
|
||||||
|
data-slot="dialog-content"
|
||||||
|
className={cn(
|
||||||
|
"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 outline-none sm:max-w-lg",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
{showCloseButton && (
|
||||||
|
<DialogPrimitive.Close
|
||||||
|
data-slot="dialog-close"
|
||||||
|
className="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"
|
||||||
|
>
|
||||||
|
<XIcon />
|
||||||
|
<span className="sr-only">Close</span>
|
||||||
|
</DialogPrimitive.Close>
|
||||||
|
)}
|
||||||
|
</DialogPrimitive.Content>
|
||||||
|
</DialogPortal>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="dialog-header"
|
||||||
|
className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="dialog-footer"
|
||||||
|
className={cn(
|
||||||
|
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogTitle({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Title>) {
|
||||||
|
return (
|
||||||
|
<DialogPrimitive.Title
|
||||||
|
data-slot="dialog-title"
|
||||||
|
className={cn("text-lg leading-none font-semibold", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogDescription({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Description>) {
|
||||||
|
return (
|
||||||
|
<DialogPrimitive.Description
|
||||||
|
data-slot="dialog-description"
|
||||||
|
className={cn("text-muted-foreground text-sm", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
Dialog,
|
||||||
|
DialogClose,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogOverlay,
|
||||||
|
DialogPortal,
|
||||||
|
DialogTitle,
|
||||||
|
DialogTrigger,
|
||||||
|
}
|
||||||
190
components/ui/select.tsx
Normal file
190
components/ui/select.tsx
Normal file
@@ -0,0 +1,190 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import * as SelectPrimitive from "@radix-ui/react-select"
|
||||||
|
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
function Select({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Root>) {
|
||||||
|
return <SelectPrimitive.Root data-slot="select" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectGroup({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Group>) {
|
||||||
|
return <SelectPrimitive.Group data-slot="select-group" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectValue({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Value>) {
|
||||||
|
return <SelectPrimitive.Value data-slot="select-value" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectTrigger({
|
||||||
|
className,
|
||||||
|
size = "default",
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Trigger> & {
|
||||||
|
size?: "sm" | "default"
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Trigger
|
||||||
|
data-slot="select-trigger"
|
||||||
|
data-size={size}
|
||||||
|
className={cn(
|
||||||
|
"border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
<SelectPrimitive.Icon asChild>
|
||||||
|
<ChevronDownIcon className="size-4 opacity-50" />
|
||||||
|
</SelectPrimitive.Icon>
|
||||||
|
</SelectPrimitive.Trigger>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectContent({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
position = "item-aligned",
|
||||||
|
align = "center",
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Content>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Portal>
|
||||||
|
<SelectPrimitive.Content
|
||||||
|
data-slot="select-content"
|
||||||
|
className={cn(
|
||||||
|
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md",
|
||||||
|
position === "popper" &&
|
||||||
|
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
position={position}
|
||||||
|
align={align}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<SelectScrollUpButton />
|
||||||
|
<SelectPrimitive.Viewport
|
||||||
|
className={cn(
|
||||||
|
"p-1",
|
||||||
|
position === "popper" &&
|
||||||
|
"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</SelectPrimitive.Viewport>
|
||||||
|
<SelectScrollDownButton />
|
||||||
|
</SelectPrimitive.Content>
|
||||||
|
</SelectPrimitive.Portal>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectLabel({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Label>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Label
|
||||||
|
data-slot="select-label"
|
||||||
|
className={cn("text-muted-foreground px-2 py-1.5 text-xs", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectItem({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Item>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Item
|
||||||
|
data-slot="select-item"
|
||||||
|
className={cn(
|
||||||
|
"focus:bg-accent focus:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
data-slot="select-item-indicator"
|
||||||
|
className="absolute right-2 flex size-3.5 items-center justify-center"
|
||||||
|
>
|
||||||
|
<SelectPrimitive.ItemIndicator>
|
||||||
|
<CheckIcon className="size-4" />
|
||||||
|
</SelectPrimitive.ItemIndicator>
|
||||||
|
</span>
|
||||||
|
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
|
||||||
|
</SelectPrimitive.Item>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectSeparator({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Separator>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Separator
|
||||||
|
data-slot="select-separator"
|
||||||
|
className={cn("bg-border pointer-events-none -mx-1 my-1 h-px", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectScrollUpButton({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.ScrollUpButton>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.ScrollUpButton
|
||||||
|
data-slot="select-scroll-up-button"
|
||||||
|
className={cn(
|
||||||
|
"flex cursor-default items-center justify-center py-1",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<ChevronUpIcon className="size-4" />
|
||||||
|
</SelectPrimitive.ScrollUpButton>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectScrollDownButton({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.ScrollDownButton>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.ScrollDownButton
|
||||||
|
data-slot="select-scroll-down-button"
|
||||||
|
className={cn(
|
||||||
|
"flex cursor-default items-center justify-center py-1",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<ChevronDownIcon className="size-4" />
|
||||||
|
</SelectPrimitive.ScrollDownButton>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectGroup,
|
||||||
|
SelectItem,
|
||||||
|
SelectLabel,
|
||||||
|
SelectScrollDownButton,
|
||||||
|
SelectScrollUpButton,
|
||||||
|
SelectSeparator,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
}
|
||||||
31
components/ui/switch.tsx
Normal file
31
components/ui/switch.tsx
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import * as SwitchPrimitive from "@radix-ui/react-switch"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
function Switch({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SwitchPrimitive.Root>) {
|
||||||
|
return (
|
||||||
|
<SwitchPrimitive.Root
|
||||||
|
data-slot="switch"
|
||||||
|
className={cn(
|
||||||
|
"peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-stone-300 dark:data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<SwitchPrimitive.Thumb
|
||||||
|
data-slot="switch-thumb"
|
||||||
|
className={cn(
|
||||||
|
"bg-background pointer-events-none block size-4 rounded-full ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0 shadow-sm"
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</SwitchPrimitive.Root>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Switch }
|
||||||
8
lib/site-settings.ts
Normal file
8
lib/site-settings.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { createClient } from "@/lib/supabase-server"
|
||||||
|
import { cache } from "react"
|
||||||
|
|
||||||
|
export const getSiteSettings = cache(async () => {
|
||||||
|
const supabase = createClient()
|
||||||
|
const { data } = await supabase.from('site_settings').select('*').single()
|
||||||
|
return data
|
||||||
|
})
|
||||||
8
lib/supabase-browser.ts
Normal file
8
lib/supabase-browser.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { createBrowserClient } from '@supabase/ssr'
|
||||||
|
|
||||||
|
export function createClient() {
|
||||||
|
return createBrowserClient(
|
||||||
|
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
||||||
|
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
|
||||||
|
)
|
||||||
|
}
|
||||||
8
make_admin.sql
Normal file
8
make_admin.sql
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
-- Insert profile for the existing user and make them admin
|
||||||
|
insert into public.profiles (id, role, full_name)
|
||||||
|
select id, 'admin', 'Sistem Yöneticisi'
|
||||||
|
from auth.users
|
||||||
|
where email = 'kenankaraerr@hotmail.com'
|
||||||
|
on conflict (id) do update
|
||||||
|
set role = 'admin';
|
||||||
120
package-lock.json
generated
120
package-lock.json
generated
@@ -14,15 +14,19 @@
|
|||||||
"@radix-ui/react-dropdown-menu": "^2.1.16",
|
"@radix-ui/react-dropdown-menu": "^2.1.16",
|
||||||
"@radix-ui/react-label": "^2.1.8",
|
"@radix-ui/react-label": "^2.1.8",
|
||||||
"@radix-ui/react-navigation-menu": "^1.2.14",
|
"@radix-ui/react-navigation-menu": "^1.2.14",
|
||||||
|
"@radix-ui/react-select": "^2.2.6",
|
||||||
"@radix-ui/react-separator": "^1.1.8",
|
"@radix-ui/react-separator": "^1.1.8",
|
||||||
"@radix-ui/react-slot": "^1.2.4",
|
"@radix-ui/react-slot": "^1.2.4",
|
||||||
|
"@radix-ui/react-switch": "^1.2.6",
|
||||||
"@supabase/ssr": "^0.8.0",
|
"@supabase/ssr": "^0.8.0",
|
||||||
"@supabase/supabase-js": "^2.89.0",
|
"@supabase/supabase-js": "^2.89.0",
|
||||||
"class-variance-authority": "^0.7.1",
|
"class-variance-authority": "^0.7.1",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
|
"date-fns": "^4.1.0",
|
||||||
"embla-carousel-react": "^8.6.0",
|
"embla-carousel-react": "^8.6.0",
|
||||||
"lucide-react": "^0.378.0",
|
"lucide-react": "^0.378.0",
|
||||||
"next": "14.2.16",
|
"next": "14.2.16",
|
||||||
|
"next-themes": "^0.4.6",
|
||||||
"react": "^18",
|
"react": "^18",
|
||||||
"react-dom": "^18",
|
"react-dom": "^18",
|
||||||
"react-hook-form": "^7.70.0",
|
"react-hook-form": "^7.70.0",
|
||||||
@@ -560,6 +564,12 @@
|
|||||||
"node": ">=14"
|
"node": ">=14"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@radix-ui/number": {
|
||||||
|
"version": "1.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@radix-ui/number/-/number-1.1.1.tgz",
|
||||||
|
"integrity": "sha512-MkKCwxlXTgz6CFoJx3pCwn07GKp36+aZyu/u2Ln2VrA5DcdyCZkASEDBTd8x5whTQQL5CiYf4prXKLcgQdv29g==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/@radix-ui/primitive": {
|
"node_modules/@radix-ui/primitive": {
|
||||||
"version": "1.1.3",
|
"version": "1.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/@radix-ui/primitive/-/primitive-1.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/@radix-ui/primitive/-/primitive-1.1.3.tgz",
|
||||||
@@ -1203,6 +1213,67 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@radix-ui/react-select": {
|
||||||
|
"version": "2.2.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/@radix-ui/react-select/-/react-select-2.2.6.tgz",
|
||||||
|
"integrity": "sha512-I30RydO+bnn2PQztvo25tswPH+wFBjehVGtmagkU78yMdwTwVf12wnAOF+AeP8S2N8xD+5UPbGhkUfPyvT+mwQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@radix-ui/number": "1.1.1",
|
||||||
|
"@radix-ui/primitive": "1.1.3",
|
||||||
|
"@radix-ui/react-collection": "1.1.7",
|
||||||
|
"@radix-ui/react-compose-refs": "1.1.2",
|
||||||
|
"@radix-ui/react-context": "1.1.2",
|
||||||
|
"@radix-ui/react-direction": "1.1.1",
|
||||||
|
"@radix-ui/react-dismissable-layer": "1.1.11",
|
||||||
|
"@radix-ui/react-focus-guards": "1.1.3",
|
||||||
|
"@radix-ui/react-focus-scope": "1.1.7",
|
||||||
|
"@radix-ui/react-id": "1.1.1",
|
||||||
|
"@radix-ui/react-popper": "1.2.8",
|
||||||
|
"@radix-ui/react-portal": "1.1.9",
|
||||||
|
"@radix-ui/react-primitive": "2.1.3",
|
||||||
|
"@radix-ui/react-slot": "1.2.3",
|
||||||
|
"@radix-ui/react-use-callback-ref": "1.1.1",
|
||||||
|
"@radix-ui/react-use-controllable-state": "1.2.2",
|
||||||
|
"@radix-ui/react-use-layout-effect": "1.1.1",
|
||||||
|
"@radix-ui/react-use-previous": "1.1.1",
|
||||||
|
"@radix-ui/react-visually-hidden": "1.2.3",
|
||||||
|
"aria-hidden": "^1.2.4",
|
||||||
|
"react-remove-scroll": "^2.6.3"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@types/react": "*",
|
||||||
|
"@types/react-dom": "*",
|
||||||
|
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
|
||||||
|
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"@types/react": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"@types/react-dom": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@radix-ui/react-select/node_modules/@radix-ui/react-slot": {
|
||||||
|
"version": "1.2.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@radix-ui/react-slot/-/react-slot-1.2.3.tgz",
|
||||||
|
"integrity": "sha512-aeNmHnBxbi2St0au6VBVC7JXFlhLlOnvIIlePNniyUNAClzmtAUEY8/pBiK3iHjufOlwA+c20/8jngo7xcrg8A==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@radix-ui/react-compose-refs": "1.1.2"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@types/react": "*",
|
||||||
|
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"@types/react": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@radix-ui/react-separator": {
|
"node_modules/@radix-ui/react-separator": {
|
||||||
"version": "1.1.8",
|
"version": "1.1.8",
|
||||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-separator/-/react-separator-1.1.8.tgz",
|
"resolved": "https://registry.npmjs.org/@radix-ui/react-separator/-/react-separator-1.1.8.tgz",
|
||||||
@@ -1267,6 +1338,35 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@radix-ui/react-switch": {
|
||||||
|
"version": "1.2.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/@radix-ui/react-switch/-/react-switch-1.2.6.tgz",
|
||||||
|
"integrity": "sha512-bByzr1+ep1zk4VubeEVViV592vu2lHE2BZY5OnzehZqOOgogN80+mNtCqPkhn2gklJqOpxWgPoYTSnhBCqpOXQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@radix-ui/primitive": "1.1.3",
|
||||||
|
"@radix-ui/react-compose-refs": "1.1.2",
|
||||||
|
"@radix-ui/react-context": "1.1.2",
|
||||||
|
"@radix-ui/react-primitive": "2.1.3",
|
||||||
|
"@radix-ui/react-use-controllable-state": "1.2.2",
|
||||||
|
"@radix-ui/react-use-previous": "1.1.1",
|
||||||
|
"@radix-ui/react-use-size": "1.1.1"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@types/react": "*",
|
||||||
|
"@types/react-dom": "*",
|
||||||
|
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
|
||||||
|
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"@types/react": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"@types/react-dom": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@radix-ui/react-use-callback-ref": {
|
"node_modules/@radix-ui/react-use-callback-ref": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-use-callback-ref/-/react-use-callback-ref-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/@radix-ui/react-use-callback-ref/-/react-use-callback-ref-1.1.1.tgz",
|
||||||
@@ -2983,6 +3083,16 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/date-fns": {
|
||||||
|
"version": "4.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-4.1.0.tgz",
|
||||||
|
"integrity": "sha512-Ukq0owbQXxa/U3EGtsdVBkR1w7KOQ5gIBqdH2hkvknzZPYvBxb/aa6E8L7tmjFtkwZBu3UXBbjIgPo/Ez4xaNg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"funding": {
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/kossnocorp"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/debug": {
|
"node_modules/debug": {
|
||||||
"version": "4.4.3",
|
"version": "4.4.3",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
|
||||||
@@ -5267,6 +5377,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/next-themes": {
|
||||||
|
"version": "0.4.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/next-themes/-/next-themes-0.4.6.tgz",
|
||||||
|
"integrity": "sha512-pZvgD5L0IEvX5/9GWyHMf3m8BKiVQwsCMHfoFosXtXBMnaS0ZnIJ9ST4b4NqLVKDEm8QBxoNNGNaBv2JNF6XNA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": "^16.8 || ^17 || ^18 || ^19 || ^19.0.0-rc",
|
||||||
|
"react-dom": "^16.8 || ^17 || ^18 || ^19 || ^19.0.0-rc"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/next/node_modules/postcss": {
|
"node_modules/next/node_modules/postcss": {
|
||||||
"version": "8.4.31",
|
"version": "8.4.31",
|
||||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz",
|
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz",
|
||||||
|
|||||||
@@ -15,15 +15,19 @@
|
|||||||
"@radix-ui/react-dropdown-menu": "^2.1.16",
|
"@radix-ui/react-dropdown-menu": "^2.1.16",
|
||||||
"@radix-ui/react-label": "^2.1.8",
|
"@radix-ui/react-label": "^2.1.8",
|
||||||
"@radix-ui/react-navigation-menu": "^1.2.14",
|
"@radix-ui/react-navigation-menu": "^1.2.14",
|
||||||
|
"@radix-ui/react-select": "^2.2.6",
|
||||||
"@radix-ui/react-separator": "^1.1.8",
|
"@radix-ui/react-separator": "^1.1.8",
|
||||||
"@radix-ui/react-slot": "^1.2.4",
|
"@radix-ui/react-slot": "^1.2.4",
|
||||||
|
"@radix-ui/react-switch": "^1.2.6",
|
||||||
"@supabase/ssr": "^0.8.0",
|
"@supabase/ssr": "^0.8.0",
|
||||||
"@supabase/supabase-js": "^2.89.0",
|
"@supabase/supabase-js": "^2.89.0",
|
||||||
"class-variance-authority": "^0.7.1",
|
"class-variance-authority": "^0.7.1",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
|
"date-fns": "^4.1.0",
|
||||||
"embla-carousel-react": "^8.6.0",
|
"embla-carousel-react": "^8.6.0",
|
||||||
"lucide-react": "^0.378.0",
|
"lucide-react": "^0.378.0",
|
||||||
"next": "14.2.16",
|
"next": "14.2.16",
|
||||||
|
"next-themes": "^0.4.6",
|
||||||
"react": "^18",
|
"react": "^18",
|
||||||
"react-dom": "^18",
|
"react-dom": "^18",
|
||||||
"react-hook-form": "^7.70.0",
|
"react-hook-form": "^7.70.0",
|
||||||
|
|||||||
58
supabase_schema_additions.sql
Normal file
58
supabase_schema_additions.sql
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
|
||||||
|
-- Create profiles table
|
||||||
|
create table if not exists profiles (
|
||||||
|
id uuid references auth.users on delete cascade primary key,
|
||||||
|
role text not null default 'user' check (role in ('admin', 'user')),
|
||||||
|
full_name text,
|
||||||
|
created_at timestamp with time zone default timezone('utc'::text, now()) not null
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Enable RLS for profiles
|
||||||
|
alter table profiles enable row level security;
|
||||||
|
|
||||||
|
-- Policies for profiles
|
||||||
|
create policy "Public profiles are viewable by everyone."
|
||||||
|
on profiles for select
|
||||||
|
using ( true );
|
||||||
|
|
||||||
|
create policy "Users can insert their own profile."
|
||||||
|
on profiles for insert
|
||||||
|
with check ( auth.uid() = id );
|
||||||
|
|
||||||
|
create policy "Users can update own profile."
|
||||||
|
on profiles for update
|
||||||
|
using ( auth.uid() = id );
|
||||||
|
|
||||||
|
-- Create site_settings table
|
||||||
|
create table if not exists site_settings (
|
||||||
|
id bigint primary key generated always as identity,
|
||||||
|
site_title text not null default 'ParaKasa',
|
||||||
|
site_description text,
|
||||||
|
contact_email text,
|
||||||
|
contact_phone text,
|
||||||
|
logo_url text,
|
||||||
|
currency text default 'TRY',
|
||||||
|
updated_at timestamp with time zone default timezone('utc'::text, now()) not null
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Enable RLS for site_settings
|
||||||
|
alter table site_settings enable row level security;
|
||||||
|
|
||||||
|
-- Policies for site_settings
|
||||||
|
create policy "Site settings are viewable by everyone."
|
||||||
|
on site_settings for select
|
||||||
|
using ( true );
|
||||||
|
|
||||||
|
create policy "Only admins can update site settings."
|
||||||
|
on site_settings for update
|
||||||
|
using (
|
||||||
|
exists (
|
||||||
|
select 1 from profiles
|
||||||
|
where profiles.id = auth.uid() and profiles.role = 'admin'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Initialize default site settings if empty
|
||||||
|
insert into site_settings (site_title, contact_email)
|
||||||
|
select 'ParaKasa', 'info@parakasa.com'
|
||||||
|
where not exists (select 1 from site_settings);
|
||||||
44
supabase_schema_categories.sql
Normal file
44
supabase_schema_categories.sql
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
-- Create categories table
|
||||||
|
create table if not exists categories (
|
||||||
|
id uuid default gen_random_uuid() primary key,
|
||||||
|
name text not null,
|
||||||
|
slug text not null unique,
|
||||||
|
description text,
|
||||||
|
image_url text,
|
||||||
|
created_at timestamp with time zone default timezone('utc'::text, now()) not null
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Enable RLS
|
||||||
|
alter table categories enable row level security;
|
||||||
|
|
||||||
|
-- Policies
|
||||||
|
create policy "Public categories are viewable by everyone."
|
||||||
|
on categories for select
|
||||||
|
using ( true );
|
||||||
|
|
||||||
|
create policy "Admins can insert categories."
|
||||||
|
on categories for insert
|
||||||
|
with check (
|
||||||
|
exists (
|
||||||
|
select 1 from profiles
|
||||||
|
where profiles.id = auth.uid() and profiles.role = 'admin'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
create policy "Admins can update categories."
|
||||||
|
on categories for update
|
||||||
|
using (
|
||||||
|
exists (
|
||||||
|
select 1 from profiles
|
||||||
|
where profiles.id = auth.uid() and profiles.role = 'admin'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
create policy "Admins can delete categories."
|
||||||
|
on categories for delete
|
||||||
|
using (
|
||||||
|
exists (
|
||||||
|
select 1 from profiles
|
||||||
|
where profiles.id = auth.uid() and profiles.role = 'admin'
|
||||||
|
)
|
||||||
|
);
|
||||||
6
supabase_schema_products_category_fk.sql
Normal file
6
supabase_schema_products_category_fk.sql
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
-- Add category_id to products table
|
||||||
|
alter table products
|
||||||
|
add column if not exists category_id uuid references categories(id) on delete set null;
|
||||||
|
|
||||||
|
-- Optional: Create an index for better performance
|
||||||
|
create index if not exists idx_products_category_id on products(category_id);
|
||||||
Reference in New Issue
Block a user