mirror of
https://github.com/lukevella/rallly.git
synced 2025-07-16 16:05:33 +02:00
♻️ Use revalidatePath instead of client side refresh (#1802)
This commit is contained in:
parent
961a493a29
commit
6bd24e7e1f
7 changed files with 22 additions and 29 deletions
|
@ -1,6 +1,7 @@
|
|||
"use server";
|
||||
|
||||
import { ActionError, authActionClient } from "@/features/safe-action/server";
|
||||
import { signOut } from "@/next-auth";
|
||||
import { subject } from "@casl/ability";
|
||||
import { prisma } from "@rallly/database";
|
||||
|
||||
|
@ -33,6 +34,16 @@ export const deleteCurrentUserAction = authActionClient.action(
|
|||
},
|
||||
});
|
||||
|
||||
ctx.posthog?.capture({
|
||||
event: "delete_account",
|
||||
distinctId: ctx.user.id,
|
||||
properties: {
|
||||
email: ctx.user.email,
|
||||
},
|
||||
});
|
||||
|
||||
await signOut();
|
||||
|
||||
return {
|
||||
success: true,
|
||||
};
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"use client";
|
||||
import { usePostHog } from "@rallly/posthog/client";
|
||||
import { Button } from "@rallly/ui/button";
|
||||
import type { DialogProps } from "@rallly/ui/dialog";
|
||||
import {
|
||||
|
@ -13,7 +12,6 @@ import {
|
|||
} from "@rallly/ui/dialog";
|
||||
import { Form, FormField, FormItem, FormMessage } from "@rallly/ui/form";
|
||||
import { Input } from "@rallly/ui/input";
|
||||
import { signOut } from "next-auth/react";
|
||||
import { useForm } from "react-hook-form";
|
||||
|
||||
import { Trans } from "@/components/trans";
|
||||
|
@ -34,16 +32,7 @@ export function DeleteAccountDialog({
|
|||
},
|
||||
});
|
||||
|
||||
const posthog = usePostHog();
|
||||
|
||||
const deleteUser = useSafeAction(deleteCurrentUserAction, {
|
||||
onSuccess: () => {
|
||||
posthog?.capture("delete account");
|
||||
signOut({
|
||||
redirectTo: "/login",
|
||||
});
|
||||
},
|
||||
});
|
||||
const deleteUser = useSafeAction(deleteCurrentUserAction);
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
|
|
|
@ -3,6 +3,7 @@ import { authActionClient } from "@/features/safe-action/server";
|
|||
import { ActionError } from "@/features/safe-action/server";
|
||||
import { subject } from "@casl/ability";
|
||||
import { prisma } from "@rallly/database";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export const makeMeAdminAction = authActionClient.action(async ({ ctx }) => {
|
||||
if (ctx.ability.cannot("update", subject("User", ctx.user), "role")) {
|
||||
|
@ -20,4 +21,6 @@ export const makeMeAdminAction = authActionClient.action(async ({ ctx }) => {
|
|||
role: "admin",
|
||||
},
|
||||
});
|
||||
|
||||
redirect("/control-panel");
|
||||
});
|
||||
|
|
|
@ -3,16 +3,10 @@
|
|||
import { Trans } from "@/components/trans";
|
||||
import { useSafeAction } from "@/features/safe-action/client";
|
||||
import { Button } from "@rallly/ui/button";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { makeMeAdminAction } from "./actions";
|
||||
|
||||
export function MakeMeAdminButton() {
|
||||
const router = useRouter();
|
||||
const makeMeAdmin = useSafeAction(makeMeAdminAction, {
|
||||
onSuccess: () => {
|
||||
router.replace("/control-panel");
|
||||
},
|
||||
});
|
||||
const makeMeAdmin = useSafeAction(makeMeAdminAction);
|
||||
return (
|
||||
<Button
|
||||
onClick={async () => {
|
||||
|
|
|
@ -24,7 +24,6 @@ import {
|
|||
FormMessage,
|
||||
} from "@rallly/ui/form";
|
||||
import { Input } from "@rallly/ui/input";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
|
||||
|
@ -53,7 +52,6 @@ export function DeleteUserDialog({
|
|||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const schema = useSchema(email);
|
||||
const form = useForm({
|
||||
resolver: zodResolver(schema),
|
||||
|
@ -64,7 +62,6 @@ export function DeleteUserDialog({
|
|||
|
||||
const deleteUser = useSafeAction(deleteUserAction, {
|
||||
onSuccess: () => {
|
||||
router.refresh();
|
||||
onOpenChange(false);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -23,7 +23,6 @@ import {
|
|||
} from "@rallly/ui/dropdown-menu";
|
||||
import { Icon } from "@rallly/ui/icon";
|
||||
import { MoreHorizontal, TrashIcon, UserPenIcon } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useTransition } from "react";
|
||||
import { DeleteUserDialog } from "./dialogs/delete-user-dialog";
|
||||
|
||||
|
@ -40,12 +39,7 @@ export function UserRow({
|
|||
image?: string;
|
||||
role: "admin" | "user";
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const changeRole = useSafeAction(changeRoleAction, {
|
||||
onSuccess: () => {
|
||||
router.refresh();
|
||||
},
|
||||
});
|
||||
const changeRole = useSafeAction(changeRoleAction);
|
||||
|
||||
const [isPending, startTransition] = useTransition();
|
||||
const { user } = useUser();
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import { ActionError, authActionClient } from "@/features/safe-action/server";
|
||||
import { subject } from "@casl/ability";
|
||||
import { prisma } from "@rallly/database";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { z } from "zod";
|
||||
import { getUser } from "./queries";
|
||||
|
||||
|
@ -46,6 +47,8 @@ export const changeRoleAction = authActionClient
|
|||
role,
|
||||
},
|
||||
});
|
||||
|
||||
revalidatePath("/control-panel");
|
||||
});
|
||||
|
||||
export const deleteUserAction = authActionClient
|
||||
|
@ -83,6 +86,8 @@ export const deleteUserAction = authActionClient
|
|||
},
|
||||
});
|
||||
|
||||
revalidatePath("/control-panel");
|
||||
|
||||
return {
|
||||
success: true,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue