first commit
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
'use server';
|
||||
|
||||
import { db } from '@/lib/db';
|
||||
import { revalidatePath } from 'next/cache';
|
||||
|
||||
export async function submitContactMessage(data: {
|
||||
name: string;
|
||||
email: string;
|
||||
subject: string;
|
||||
message: string;
|
||||
}) {
|
||||
try {
|
||||
const newMessage = await db.contactMessage.create({
|
||||
data: {
|
||||
name: data.name,
|
||||
email: data.email,
|
||||
subject: data.subject,
|
||||
message: data.message,
|
||||
},
|
||||
});
|
||||
|
||||
revalidatePath('/[locale]/admin');
|
||||
return { success: true, message: newMessage };
|
||||
} catch (error: any) {
|
||||
console.error('Error saving contact message:', error);
|
||||
return { success: false, error: error.message || 'Failed to submit contact message' };
|
||||
}
|
||||
}
|
||||
|
||||
export async function getContactMessages() {
|
||||
try {
|
||||
const messages = await db.contactMessage.findMany({
|
||||
orderBy: { createdAt: 'desc' },
|
||||
});
|
||||
return messages;
|
||||
} catch (error) {
|
||||
console.error('Error fetching contact messages:', error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user