Files
kovakyazilim/app/actions.ts
T
Ege Can Komur 3b3efafcc8 Kovak Yazılım kurumsal site — Next.js 16 + Appwrite
- Anasayfa, Hizmetler, Projeler, Hakkımızda, İletişim sayfaları
- Header/Footer, Hero, ServicesGrid, ProjectsGrid, ContactForm bileşenleri
- Appwrite TablesDB entegrasyonu (services, projects, contact_messages)
- Server Action ile iletişim formu (submitContact)
- Brand palette: navy #0F2C5C + sky #4DA3C7
- kovakyazilim.com'dan alınan logo public/logo.png
2026-05-20 01:52:27 +03:00

56 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use server";
import { ID } from "node-appwrite";
import { serverTablesDB, 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 serverTablesDB.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}` };
}
}