f833d429fc
Backend altyapısı: - 4 yeni Appwrite tablosu: blog_posts, testimonials, seo_pages, seo_settings - Appwrite Storage bucket: kovak-yazilim-media (görsel yüklemeleri) - Appwrite Auth ile session cookie tabanlı koruma Admin paneli (/admin): - Login akışı (email/password) + protected layout - Dashboard: sayım kartları + hızlı aksiyonlar - Blog CRUD: markdown content, kapak görseli, draft/published, SEO alanları - Services CRUD: lucide ikon seçici - Projects CRUD: teknoloji etiketleri, live URL - Testimonials CRUD: puanlama - SEO yöneticisi: global ayarlar + sayfa bazlı override - Mesaj inbox: status filtreleme + güncelleme - Medya kütüphanesi: Appwrite Storage upload/delete Public: - /blog ve /blog/[slug] sayfaları (markdown render) - Anasayfaya Testimonials bölümü - Tüm public sayfalarda generateMetadata + seo_pages override - Header'a Blog linki Route yapısı: - app/(site)/ — public site, Header/Footer ortak - app/admin/login — auth dışı - app/admin/(protected)/ — requireUser() korumalı 23 route üretiliyor, public static, admin dynamic.
56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
"use server";
|
||
|
||
import { ID } from "node-appwrite";
|
||
import { adminDB, DATABASE_ID, TABLES } from "@/lib/appwrite-server";
|
||
|
||
export type ContactFormState = {
|
||
ok: boolean;
|
||
message: string;
|
||
errors?: Record<string, string>;
|
||
};
|
||
|
||
const initial: ContactFormState = { ok: false, message: "" };
|
||
|
||
export async function submitContact(
|
||
_prev: ContactFormState = initial,
|
||
formData: FormData,
|
||
): Promise<ContactFormState> {
|
||
const name = String(formData.get("name") ?? "").trim();
|
||
const email = String(formData.get("email") ?? "").trim();
|
||
const phone = String(formData.get("phone") ?? "").trim();
|
||
const subject = String(formData.get("subject") ?? "").trim();
|
||
const message = String(formData.get("message") ?? "").trim();
|
||
|
||
const errors: Record<string, string> = {};
|
||
if (!name) errors.name = "Ad zorunlu";
|
||
if (!email) errors.email = "E-posta zorunlu";
|
||
else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email))
|
||
errors.email = "Geçerli bir e-posta girin";
|
||
if (!message || message.length < 10)
|
||
errors.message = "Mesaj en az 10 karakter olmalı";
|
||
|
||
if (Object.keys(errors).length > 0) {
|
||
return { ok: false, message: "Lütfen form alanlarını kontrol edin", errors };
|
||
}
|
||
|
||
try {
|
||
await adminDB.createRow({
|
||
databaseId: DATABASE_ID,
|
||
tableId: TABLES.contactMessages,
|
||
rowId: ID.unique(),
|
||
data: {
|
||
name,
|
||
email,
|
||
phone: phone || null,
|
||
subject: subject || null,
|
||
message,
|
||
status: "new",
|
||
},
|
||
});
|
||
return { ok: true, message: "Mesajınız iletildi. En kısa sürede dönüş yapacağız." };
|
||
} catch (err) {
|
||
const detail = err instanceof Error ? err.message : "Bilinmeyen hata";
|
||
return { ok: false, message: `Kayıt başarısız: ${detail}` };
|
||
}
|
||
}
|