- Add Settings button label i18n (de: Einstellungen) - Allow editing plan title, feeding per day, feeding interval, and litter interval - Update PlanSettings component with new form fields - Add German and English translations for new settings - Update Plan type to include title property
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
"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}`)
|
|
}
|