web sitesi yönetimi

This commit is contained in:
2026-01-25 01:46:12 +03:00
parent 6e56b1e75f
commit 0fe49b5c96
15 changed files with 575 additions and 155 deletions

View File

@@ -0,0 +1,45 @@
'use server'
import { createClient } from "@/lib/supabase-server"
import { SiteContent } from "@/types/cms"
import { revalidatePath } from "next/cache"
export async function updateSiteContent(contents: SiteContent[]) {
const supabase = await createClient()
try {
const { data: { user } } = await supabase.auth.getUser()
if (!user) {
return { success: false, error: "Oturum açmanız gerekiyor" }
}
// Upsert each content item
// Since we might have many items, we can do this in parallel or a single upsert if the structure allows
// Supabase upsert accepts an array
const { error } = await supabase
.from('site_contents')
.upsert(
contents.map(item => ({
key: item.key,
value: item.value,
type: item.type,
section: item.section,
updated_at: new Date().toISOString()
}))
)
if (error) {
console.error('CMS Update Error:', error)
return { success: false, error: "Güncelleme sırasında bir hata oluştu: " + error.message }
}
revalidatePath('/dashboard/cms/content')
revalidatePath('/') // Revalidate home page as it likely uses these settings
return { success: true }
} catch (error) {
console.error('CMS Update Error:', error)
return { success: false, error: "Bir hata oluştu" }
}
}

View File

@@ -0,0 +1,61 @@
import { createClient } from "@/lib/supabase-server"
import { ContentForm } from "@/components/dashboard/content-form"
import { SiteContent } from "@/types/cms"
export default async function ContentPage() {
const supabase = await createClient()
const { data: contents } = await supabase
.from('site_contents')
.select('*')
.order('key')
// Define default contents that should exist
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">
<div className="flex items-center justify-between space-y-2">
<h2 className="text-3xl font-bold tracking-tight">İçerik Yönetimi</h2>
</div>
<div className="hidden h-full flex-1 flex-col space-y-8 md:flex">
<div className="grid gap-4 md:grid-cols-1 lg:grid-cols-1">
<div className="col-span-1">
<div className="space-y-6">
<div>
<p className="text-sm text-muted-foreground">
Site başlığı, sloganlar, iletişim bilgileri ve logoları buradan yönetebilirsiniz.
</p>
</div>
<ContentForm initialContent={mergedContents} />
</div>
</div>
</div>
</div>
</div>
)
}