Revalidate booking pages on updateProfile (#7941)

This commit is contained in:
Efraín Rochín authored and GitHub committed 2023-03-25 22:06:43 +01:00
1 parent a571d40958
commit 0365157638
1 file changed
+20
+20
View File
@@ -2,6 +2,7 @@ import type { DestinationCalendar, Prisma } from "@prisma/client";
import { AppCategories, BookingStatus, IdentityProvider } from "@prisma/client";
import { cityMapping } from "city-timezones";
import { reverse } from "lodash";
import type { NextApiResponse } from "next";
import { authenticator } from "otplib";
import z from "zod";
@@ -709,6 +710,25 @@ const loggedInViewerRouter = router({
},
});
}
// Revalidate booking pages
const res = ctx.res as NextApiResponse;
if (typeof res?.revalidate !== "undefined") {
const eventTypes = await prisma.eventType.findMany({
where: {
userId: user.id,
team: null,
hidden: false,
},
select: {
id: true,
slug: true,
},
});
// waiting for this isn't needed
Promise.all(eventTypes.map((eventType) => res?.revalidate(`/${ctx.user.username}/${eventType.slug}`)))
.then(() => console.info("Booking pages revalidated"))
.catch((e) => console.error(e));
}
}),
eventTypeOrder: authedProcedure
.input(