fix: update user swap mutation to use async/await and improve navigation handling

This commit is contained in:
Marco Pedone 2025-09-09 10:21:19 +02:00
parent aa8fb57ab4
commit 0128f115ad
2 changed files with 18 additions and 8 deletions

View file

@ -41,11 +41,13 @@ type UserWChatInfo = Pick<
export const UsersTable = (props: { data: UserWChatInfo[] }) => { export const UsersTable = (props: { data: UserWChatInfo[] }) => {
const router = useRouter(); const router = useRouter();
const { mutate: swap } = api.auth.swapUser.useMutation({ const { mutateAsync: swap } = api.auth.swapUser.useMutation({
onMutate: async () => {
await router.push("/area-riservata/load-page");
},
onSuccess: async () => { onSuccess: async () => {
toast.success("Utente cambiato con successo"); toast.success("Utente cambiato con successo");
await router.push("/area-riservata/dashboard"); window.location.replace("/area-riservata/dashboard");
router.reload();
}, },
}); });
@ -264,11 +266,7 @@ export const UsersTable = (props: { data: UserWChatInfo[] }) => {
<button <button
aria-label="Login as User" aria-label="Login as User"
className="flex w-full items-center gap-2" className="flex w-full items-center gap-2"
onClick={() => onClick={async () => await swap({ id: user.id })}
swap({
id: user.id,
})
}
type="button" type="button"
> >
<User /> Login <User /> Login

View file

@ -0,0 +1,12 @@
import { AreaRiservataLayout } from "~/components/Layout";
import { LoadingPage } from "~/components/loading";
import type { NextPageWithLayout } from "../_app";
const LoadPage: NextPageWithLayout = () => {
return <LoadingPage />;
};
export default LoadPage;
LoadPage.getLayout = function getLayout(page) {
return <AreaRiservataLayout>{page}</AreaRiservataLayout>;
};