feat: implement pwa push notifications
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import prisma from "@/lib/prisma"
|
||||
import { revalidatePath } from "next/cache"
|
||||
import { headers } from "next/headers"
|
||||
import { sendNotification } from "@/lib/notifications"
|
||||
import { sendPlanNotification } 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") {
|
||||
@@ -34,7 +34,7 @@ export async function createBooking(planId: string, date: Date, name: string, ty
|
||||
}
|
||||
})
|
||||
|
||||
if (plan?.webhookUrl && plan.notifyAll) {
|
||||
if (plan?.notifyAll) {
|
||||
const host = (await headers()).get("host")
|
||||
const protocol = host?.includes("localhost") ? "http" : "https"
|
||||
const planUrl = `${protocol}://${host}/${lang}/dashboard/${planId}`
|
||||
@@ -44,7 +44,7 @@ export async function createBooking(planId: string, date: Date, name: string, ty
|
||||
? 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)
|
||||
await sendPlanNotification(planId, message, plan.webhookUrl)
|
||||
}
|
||||
|
||||
revalidatePath(`/${lang}/dashboard/${planId}`)
|
||||
@@ -64,7 +64,7 @@ export async function deleteBooking(bookingId: number, planId: string, lang: str
|
||||
where: { id: bookingId }
|
||||
})
|
||||
|
||||
if (booking.plan.webhookUrl) {
|
||||
if (booking.plan.notifyAll) {
|
||||
const host = (await headers()).get("host")
|
||||
const protocol = host?.includes("localhost") ? "http" : "https"
|
||||
const planUrl = `${protocol}://${host}/${lang}/dashboard/${planId}`
|
||||
@@ -77,7 +77,7 @@ export async function deleteBooking(bookingId: number, planId: string, lang: str
|
||||
.replace("{url}", planUrl)
|
||||
.replace("{message}", messageDisplay)
|
||||
|
||||
await sendNotification(booking.plan.webhookUrl, message)
|
||||
await sendPlanNotification(planId, message, booking.plan.webhookUrl)
|
||||
}
|
||||
|
||||
revalidatePath(`/${lang}/dashboard/${planId}`)
|
||||
@@ -98,7 +98,7 @@ export async function completeBooking(bookingId: number, planId: string, lang: s
|
||||
data: { completedAt: new Date() }
|
||||
})
|
||||
|
||||
if (booking.plan.webhookUrl) {
|
||||
if (booking.plan.notifyAll) {
|
||||
const host = (await headers()).get("host")
|
||||
const protocol = host?.includes("localhost") ? "http" : "https"
|
||||
const planUrl = `${protocol}://${host}/${lang}/dashboard/${planId}`
|
||||
@@ -109,7 +109,7 @@ export async function completeBooking(bookingId: number, planId: string, lang: s
|
||||
.replace("{date}", dateStr)
|
||||
.replace("{url}", planUrl)
|
||||
|
||||
await sendNotification(booking.plan.webhookUrl, message)
|
||||
await sendPlanNotification(planId, message, booking.plan.webhookUrl)
|
||||
}
|
||||
|
||||
revalidatePath(`/${lang}/dashboard/${planId}`)
|
||||
|
||||
Reference in New Issue
Block a user