Site içerik yönetimi

This commit is contained in:
2026-01-25 02:03:27 +03:00
parent 0fe49b5c96
commit 6992891ae3
9 changed files with 154 additions and 248 deletions

View File

@@ -1,42 +0,0 @@
"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 }
}

View File

@@ -1,28 +1,62 @@
import { createClient } from "@/lib/supabase-server"
import { SettingsTabs } from "@/components/dashboard/settings-tabs"
import { getSmsSettings } from "@/lib/sms/actions"
import { SiteContent } from "@/types/cms"
export default async function SettingsPage() {
const supabase = createClient()
// Fetch site settings
const { data: siteSettings } = await supabase
.from('site_settings')
.select('*')
.single()
// Fetch SMS settings (server-side call to our action/db)
// Note: getSmsSettings is an action that checks for admin, which is fine.
// However, since we are in a server component with a Supabase client, we could also fetch directly if we had admin client.
// But let's use the clean action or direct logic.
// Actually, calling server action from server component is fine, but we need to handle the return structure.
// Fetch SMS settings
const smsResponse = await getSmsSettings()
const smsSettings = smsResponse.data || null
// Fetch Users (Profiles)
const { data: profiles } = await supabase
.from("profiles")
.select("*")
.order("created_at", { ascending: false })
// Fetch Site Contents (CMS)
const { data: contents } = await supabase
.from('site_contents')
.select('*')
.order('key')
// Define default contents for CMS
const DEFAULT_CONTENTS: SiteContent[] = [
// General
{ key: 'site_title', value: 'ParaKasa', type: 'text', section: 'general' },
{ key: 'site_description', value: '', type: 'long_text', section: 'general' },
{ key: 'site_logo', value: '', type: 'image_url', section: 'general' },
// Contact
{ key: 'contact_phone', value: '', type: 'text', section: 'contact' },
{ key: 'contact_email', value: '', type: 'text', section: 'contact' },
{ key: 'contact_address', value: '', type: 'long_text', section: 'contact' },
{ key: 'social_instagram', value: '', type: 'text', section: 'contact' },
{ key: 'social_youtube', value: '', type: 'text', section: 'contact' },
{ key: 'social_tiktok', value: '', type: 'text', section: 'contact' },
{ key: 'contact_map_embed', value: '', type: 'html', section: 'contact' },
]
// Merge default contents with existing contents
const mergedContents = [...(contents as SiteContent[] || [])]
const existingKeys = new Set(mergedContents.map(c => c.key))
DEFAULT_CONTENTS.forEach(item => {
if (!existingKeys.has(item.key)) {
mergedContents.push(item)
}
})
return (
<div className="flex-1 space-y-4 p-8 pt-6">
<h2 className="text-3xl font-bold tracking-tight">Ayarlar</h2>
<SettingsTabs siteSettings={siteSettings} smsSettings={smsSettings} />
<SettingsTabs
smsSettings={smsSettings}
users={profiles || []}
contents={mergedContents}
/>
</div>
)
}

View File

@@ -6,14 +6,14 @@ import "./globals.css";
const inter = Inter({ subsets: ["latin"] });
const outfit = Outfit({ subsets: ["latin"], variable: "--font-outfit" });
import { getSiteSettings } from "@/lib/site-settings";
import { getSiteContents } from "@/lib/data";
export async function generateMetadata() {
const settings = await getSiteSettings();
const settings = await getSiteContents();
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.",
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.",
};
}