"use server" import prisma from "@/lib/prisma" import { revalidatePath } from "next/cache" import { headers } from "next/headers" import { sendNotification } from "@/lib/notifications" import { getDictionary } from "@/get-dictionary" export async function updatePlan( planId: string, data: { instructions?: string; webhookUrl?: string; notifyAll?: boolean; title?: string; feedingPerDay?: number; feedingInterval?: number; litterInterval?: number; }, lang: string = "en" ) { const dict = await getDictionary(lang as any) const plan = await prisma.plan.update({ where: { id: planId }, data: { instructions: data.instructions, webhookUrl: data.webhookUrl, notifyAll: data.notifyAll, title: data.title, feedingPerDay: data.feedingPerDay, feedingInterval: data.feedingInterval, litterInterval: data.litterInterval, } }) if (data.instructions && plan.webhookUrl && plan.notifyAll) { const host = (await headers()).get("host") const protocol = host?.includes("localhost") ? "http" : "https" const planUrl = `${protocol}://${host}/${lang}/dashboard/${planId}` await sendNotification( plan.webhookUrl, dict.notifications.instructionsUpdated.replace("{url}", planUrl) ) } revalidatePath(`/${lang}/dashboard/${planId}`) }