Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

♻️ Do revalidation on the client (#1843)

Luke Vella4af6955e7dd7
diff --git a/apps/web/src/features/safe-action/client.ts b/apps/web/src/features/safe-action/client.ts
index ce85c31d6..57adfb6fd 100644
--- a/apps/web/src/features/safe-action/client.ts
+++ b/apps/web/src/features/safe-action/client.ts
@@ -1,12 +1,18 @@
"use client";
import { toast } from "@rallly/ui/sonner";
+import { useRouter } from "next/navigation";
import { useAction } from "next-safe-action/hooks";
import { useTranslation } from "@/i18n/client";
export const useSafeAction: typeof useAction = (action, options) => {
const { t } = useTranslation();
+ const router = useRouter();
return useAction(action, {
...options,
+ onSuccess: (args) => {
+ router.refresh();
+ options?.onSuccess?.(args);
+ },
onError: ({ error }) => {
if (error.serverError) {
let translatedDescription = "An unexpected error occurred";
diff --git a/apps/web/src/features/safe-action/server.ts b/apps/web/src/features/safe-action/server.ts
index da582282f..279582994 100644
--- a/apps/web/src/features/safe-action/server.ts
+++ b/apps/web/src/features/safe-action/server.ts
@@ -2,7 +2,6 @@ import "server-only";
import { posthog } from "@rallly/posthog/server";
import { waitUntil } from "@vercel/functions";
-import { revalidatePath } from "next/cache";
import { createMiddleware, createSafeActionClient } from "next-safe-action";
import z from "zod";
import { requireUserAbility } from "@/auth/queries";
@@ -34,12 +33,6 @@ export class ActionError extends Error {
}
}
-const autoRevalidateMiddleware = createMiddleware().define(async ({ next }) => {
- const result = await next();
- revalidatePath("/", "layout");
- return result;
-});
-
const posthogMiddleware = createMiddleware<{
ctx: { user: { id: string } };
metadata: { actionName: string };
@@ -103,7 +96,7 @@ export const actionClient = createSafeActionClient({
return "INTERNAL_SERVER_ERROR";
},
-}).use(autoRevalidateMiddleware);
+});
export const authActionClient = actionClient
.use(async ({ next }) => {