Implement i18n with German and English support (default DE)
This commit is contained in:
@@ -4,8 +4,11 @@ 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 createBooking(planId: string, date: Date, name: string, type: "SITTER" | "OWNER_HOME" = "SITTER", lang: string = "en") {
|
||||
const dict = await getDictionary(lang as any)
|
||||
|
||||
export async function createBooking(planId: string, date: Date, name: string, type: "SITTER" | "OWNER_HOME" = "SITTER") {
|
||||
// Simple check to ensure no double booking on server side
|
||||
const existing = await prisma.booking.findFirst({
|
||||
where: {
|
||||
@@ -34,19 +37,22 @@ export async function createBooking(planId: string, date: Date, name: string, ty
|
||||
if (plan?.webhookUrl && plan.notifyAll) {
|
||||
const host = (await headers()).get("host")
|
||||
const protocol = host?.includes("localhost") ? "http" : "https"
|
||||
const planUrl = `${protocol}://${host}/dashboard/${planId}`
|
||||
const planUrl = `${protocol}://${host}/${lang}/dashboard/${planId}`
|
||||
|
||||
const dateStr = date.toLocaleDateString()
|
||||
const dateStr = date.toLocaleDateString(lang)
|
||||
const message = type === "OWNER_HOME"
|
||||
? `🏠 OWNER HOME: Marked for ${dateStr}.\nPlan: ${planUrl}`
|
||||
: `✅ NEW BOOKING: ${name} is sitting on ${dateStr}.\nPlan: ${planUrl}`
|
||||
? dict.notifications.ownerHome.replace("{date}", dateStr).replace("{url}", planUrl)
|
||||
: dict.notifications.newBooking.replace("{name}", name).replace("{date}", dateStr).replace("{url}", planUrl)
|
||||
|
||||
await sendNotification(plan.webhookUrl, message)
|
||||
}
|
||||
|
||||
revalidatePath(`/dashboard/${planId}`)
|
||||
revalidatePath(`/${lang}/dashboard/${planId}`)
|
||||
}
|
||||
|
||||
export async function deleteBooking(bookingId: number, planId: string) {
|
||||
export async function deleteBooking(bookingId: number, planId: string, lang: string = "en") {
|
||||
const dict = await getDictionary(lang as any)
|
||||
|
||||
const booking = await prisma.booking.findUnique({
|
||||
where: { id: bookingId },
|
||||
include: { plan: true }
|
||||
@@ -61,11 +67,16 @@ export async function deleteBooking(bookingId: number, planId: string) {
|
||||
if (booking.plan.webhookUrl) {
|
||||
const host = (await headers()).get("host")
|
||||
const protocol = host?.includes("localhost") ? "http" : "https"
|
||||
const planUrl = `${protocol}://${host}/dashboard/${planId}`
|
||||
const planUrl = `${protocol}://${host}/${lang}/dashboard/${planId}`
|
||||
|
||||
const dateStr = booking.date.toLocaleDateString()
|
||||
await sendNotification(booking.plan.webhookUrl, `🚨 CANCELLATION: ${booking.sitterName} removed their booking for ${dateStr}.\nPlan: ${planUrl}`)
|
||||
const dateStr = booking.date.toLocaleDateString(lang)
|
||||
const message = dict.notifications.cancellation
|
||||
.replace("{name}", booking.sitterName || "Someone")
|
||||
.replace("{date}", dateStr)
|
||||
.replace("{url}", planUrl)
|
||||
|
||||
await sendNotification(booking.plan.webhookUrl, message)
|
||||
}
|
||||
|
||||
revalidatePath(`/dashboard/${planId}`)
|
||||
revalidatePath(`/${lang}/dashboard/${planId}`)
|
||||
}
|
||||
|
||||
@@ -4,8 +4,15 @@ 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 },
|
||||
lang: string = "en"
|
||||
) {
|
||||
const dict = await getDictionary(lang as any)
|
||||
|
||||
export async function updatePlan(planId: string, data: { instructions?: string; webhookUrl?: string; notifyAll?: boolean }) {
|
||||
const plan = await prisma.plan.update({
|
||||
where: { id: planId },
|
||||
data: {
|
||||
@@ -18,9 +25,13 @@ export async function updatePlan(planId: string, data: { instructions?: string;
|
||||
if (data.instructions && plan.webhookUrl && plan.notifyAll) {
|
||||
const host = (await headers()).get("host")
|
||||
const protocol = host?.includes("localhost") ? "http" : "https"
|
||||
const planUrl = `${protocol}://${host}/dashboard/${planId}`
|
||||
await sendNotification(plan.webhookUrl, `📝 UPDATED: Cat instructions have been modified.\nPlan: ${planUrl}`)
|
||||
const planUrl = `${protocol}://${host}/${lang}/dashboard/${planId}`
|
||||
|
||||
await sendNotification(
|
||||
plan.webhookUrl,
|
||||
dict.notifications.instructionsUpdated.replace("{url}", planUrl)
|
||||
)
|
||||
}
|
||||
|
||||
revalidatePath(`/dashboard/${planId}`)
|
||||
revalidatePath(`/${lang}/dashboard/${planId}`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user