diff --git a/app/(dashboard)/dashboard/cms/content/actions.ts b/app/(dashboard)/dashboard/cms/content/actions.ts new file mode 100644 index 0000000..f6873dd --- /dev/null +++ b/app/(dashboard)/dashboard/cms/content/actions.ts @@ -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" } + } +} diff --git a/app/(dashboard)/dashboard/cms/content/page.tsx b/app/(dashboard)/dashboard/cms/content/page.tsx new file mode 100644 index 0000000..dfbcd5e --- /dev/null +++ b/app/(dashboard)/dashboard/cms/content/page.tsx @@ -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 ( +
+ Site başlığı, sloganlar, iletişim bilgileri ve logoları buradan yönetebilirsiniz. +
+Merkez Ofis & Showroom
-
- Organize Sanayi Bölgesi, 12. Cadde No: 45
- Başakşehir, İstanbul
+
+ {siteSettings.contact_address || "Organize Sanayi Bölgesi, 12. Cadde No: 45\nBaşakşehir, İstanbul"}
Telefon
-+90 (212) 555 00 00
++ {siteSettings.contact_phone || "+90 (212) 555 00 00"} +
E-posta
-info@parakasa.com
++ {siteSettings.contact_email || "info@parakasa.com"} +
+- En kısa sürede size dönüş yapacağız. -
- -+ En kısa sürede size dönüş yapacağız. +
+ +Bu bölümde henüz ayar bulunmuyor.
+ )} + {filteredContent.map((item) => ( +