feat: implement public contact and reservation forms connected to DB
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
'use server';
|
||||
|
||||
import { prisma } from '@/lib/db';
|
||||
|
||||
export async function submitContactMessage(formData: FormData) {
|
||||
const name = formData.get('name') as string;
|
||||
const email = formData.get('email') as string;
|
||||
const subject = formData.get('subject') as string | null;
|
||||
const message = formData.get('message') as string;
|
||||
|
||||
if (!name || !email || !message) {
|
||||
return { error: 'Gerekli alanları doldurunuz.' };
|
||||
}
|
||||
|
||||
try {
|
||||
await prisma.contactMessage.create({
|
||||
data: {
|
||||
name,
|
||||
email,
|
||||
subject,
|
||||
message,
|
||||
isRead: false,
|
||||
}
|
||||
});
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
console.error('Mesaj gönderilirken hata:', error);
|
||||
return { error: 'Mesajınız gönderilirken bir hata oluştu. Lütfen tekrar deneyin.' };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user