58 lines
2.0 KiB
TypeScript
58 lines
2.0 KiB
TypeScript
"use server";
|
||
|
||
import { prisma } from "@/lib/prisma";
|
||
import { revalidatePath } from "next/cache";
|
||
|
||
export async function getContactSettings() {
|
||
try {
|
||
let settings = await prisma.contactSettings.findUnique({
|
||
where: { id: "default" }
|
||
});
|
||
|
||
if (!settings) {
|
||
settings = await prisma.contactSettings.create({
|
||
data: {
|
||
id: "default",
|
||
address: "Akyaka, Gökova Körfezi, Muğla",
|
||
phone: "905000000000",
|
||
instagram: "https://www.instagram.com/kozmosbeach/",
|
||
mapUrl: "https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d539.7850236154288!2d28.2165012!3d37.0413013527448!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x14bfa1006d98f019%3A0x85a41319cb3b8be!2sKozmos%20Beach%20%26%20More!5e1!3m2!1sen!2str!4v1781027409075!5m2!1sen!2str"
|
||
}
|
||
});
|
||
}
|
||
|
||
return { success: true, data: settings };
|
||
} catch (error) {
|
||
console.error("Error fetching contact settings:", error);
|
||
return { success: false, error: "İletişim ayarları alınırken bir hata oluştu." };
|
||
}
|
||
}
|
||
|
||
export async function updateContactSettings(formData: FormData) {
|
||
try {
|
||
const address = formData.get("address") as string;
|
||
const phone = formData.get("phone") as string;
|
||
const instagram = formData.get("instagram") as string;
|
||
const mapUrl = formData.get("mapUrl") as string;
|
||
|
||
if (!address || !phone || !instagram || !mapUrl) {
|
||
return { success: false, error: "Tüm alanların doldurulması zorunludur." };
|
||
}
|
||
|
||
await prisma.contactSettings.upsert({
|
||
where: { id: "default" },
|
||
update: { address, phone, instagram, mapUrl },
|
||
create: { id: "default", address, phone, instagram, mapUrl }
|
||
});
|
||
|
||
revalidatePath("/admin/contact");
|
||
revalidatePath("/");
|
||
revalidatePath("/tr");
|
||
revalidatePath("/en");
|
||
return { success: true };
|
||
} catch (error) {
|
||
console.error("Error updating contact settings:", error);
|
||
return { success: false, error: "İletişim ayarları güncellenirken bir hata oluştu." };
|
||
}
|
||
}
|