fix: update user swap mutation to use async/await and improve navigation handling
This commit is contained in:
parent
aa8fb57ab4
commit
0128f115ad
2 changed files with 18 additions and 8 deletions
|
|
@ -41,11 +41,13 @@ type UserWChatInfo = Pick<
|
|||
|
||||
export const UsersTable = (props: { data: UserWChatInfo[] }) => {
|
||||
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 () => {
|
||||
toast.success("Utente cambiato con successo");
|
||||
await router.push("/area-riservata/dashboard");
|
||||
router.reload();
|
||||
window.location.replace("/area-riservata/dashboard");
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -264,11 +266,7 @@ export const UsersTable = (props: { data: UserWChatInfo[] }) => {
|
|||
<button
|
||||
aria-label="Login as User"
|
||||
className="flex w-full items-center gap-2"
|
||||
onClick={() =>
|
||||
swap({
|
||||
id: user.id,
|
||||
})
|
||||
}
|
||||
onClick={async () => await swap({ id: user.id })}
|
||||
type="button"
|
||||
>
|
||||
<User /> Login
|
||||
|
|
|
|||
12
apps/infoalloggi/src/pages/area-riservata/load-page.tsx
Normal file
12
apps/infoalloggi/src/pages/area-riservata/load-page.tsx
Normal 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>;
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue