7eb0c1acc2
Sorun: - node-appwrite v20-25 hepsi Node 26'da bozuk (node-fetch-native-with-agent polyfill) - appwrite browser SDK Server Action context'inde 'unexpected response' veriyor (büyük olasılıkla browser-only global'ları kontrol ederken) Çözüm: - Tüm Appwrite SDK'larını sil (appwrite + node-appwrite) - lib/appwrite-rest.ts: native fetch üzerinde ~250 satırlık ince REST wrapper - account: createEmailPasswordSession, get, deleteSession - tablesDB: listRows, getRow, createRow, updateRow, deleteRow - storage: listFiles, createFile, deleteFile, fileViewUrl - Q helpers: equal, orderAsc/Desc, limit, offset - AppwriteError class - Session secret cookie tabanlı auth korundu (isletmem-kovakcrm'deki desen) - Tüm CRUD action ve query'ler REST katmanına bağlandı End-to-end test edildi: ✓ Login (proper 401 hata mesajları, başarılı durumda redirect) ✓ Public read (services, blog, testimonials) ✓ Anonim create (contact form) ✓ Build (24 route) ✓ Sıfır SDK bağımlılığı — Node 26 sorunu yok
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
"use server";
|
||
|
||
import { DATABASE_ID, ID, TABLES, tablesDB } from "@/lib/appwrite-rest";
|
||
|
||
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 tablesDB.createRow(DATABASE_ID, TABLES.contactMessages, ID.unique(), {
|
||
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}` };
|
||
}
|
||
}
|