49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
"use server";
|
||
|
||
import { revalidatePath } from "next/cache";
|
||
import prisma from "@/lib/prisma";
|
||
|
||
export type HeroActionState = {
|
||
success?: boolean;
|
||
message?: string;
|
||
} | null;
|
||
|
||
export async function updateHero(prevState: HeroActionState, formData: FormData): Promise<HeroActionState> {
|
||
const lang = formData.get("lang") as string;
|
||
const location = formData.get("location") as string;
|
||
const welcome = formData.get("welcome") as string;
|
||
const title = formData.get("title") as string;
|
||
const subtitle = formData.get("subtitle") as string;
|
||
const bookNow = formData.get("bookNow") as string;
|
||
const exploreActivities = formData.get("exploreActivities") as string;
|
||
const scroll = formData.get("scroll") as string;
|
||
|
||
if (!lang) {
|
||
return { success: false, message: "Dil seçimi eksik." };
|
||
}
|
||
|
||
await prisma.heroSection.upsert({
|
||
where: { lang },
|
||
update: { location, welcome, title, subtitle, bookNow, exploreActivities, scroll },
|
||
create: {
|
||
lang,
|
||
location,
|
||
welcome,
|
||
title,
|
||
subtitle,
|
||
bookNow,
|
||
exploreActivities,
|
||
scroll
|
||
}
|
||
});
|
||
|
||
revalidatePath('/admin/hero');
|
||
revalidatePath(`/${lang}`);
|
||
revalidatePath('/');
|
||
|
||
return {
|
||
success: true,
|
||
message: `${lang.toUpperCase()} Hero ayarları başarıyla kaydedildi!`
|
||
};
|
||
}
|