"use server";
import { revalidatePath } from "next/cache";
export async function revalidateUserPage() {
revalidatePath("/user/[id]", "page");
}
export async function revalidateThingsToDoPage() {
revalidatePath("/things-to-do/[...slug]", "page");
}
useEffect(() => {
if (itineraryDeleted && deleteCount === 0) {
setDeleteCount(1);
const userId = user?.id ?? "";
const lookingAtSingleItinerary = pathname.includes("itinerary");
if (lookingAtSingleItinerary) {
toast.success("Itinerary deleted. You will be redirected.");
setTimeout(() => {
void ctx.itinerary.getByUserId.invalidate();
void router.push(`/user/${userId}`);
}, 3000);
} else {
toast.success("Itinerary deleted.");
void revalidateThingsToDoPage();
}
setOpenModal(false);
}
}, [
ctx.itinerary.getByUserId,
deleteCount,
itineraryDeleted,
pathname,
router,
setOpenModal,
user?.id,
]);
I want to revalidateThingsToDoPage after router.push happens because if it is done before, the current page will break