fix: deactivate account post loading (#3022)

This commit is contained in:
Lakhan Baheti 2023-12-07 17:31:58 +05:30 committed by Aaryan Khandelwal
parent 7b32ccbad0
commit 4f32831b8e
3 changed files with 13 additions and 3 deletions

View File

@ -1,7 +1,9 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { useTheme } from "next-themes";
import { Dialog, Transition } from "@headlessui/react"; import { Dialog, Transition } from "@headlessui/react";
import { Trash2 } from "lucide-react"; import { Trash2 } from "lucide-react";
import { mutate } from "swr";
// mobx store // mobx store
import { useMobxStore } from "lib/mobx/store-provider"; import { useMobxStore } from "lib/mobx/store-provider";
// ui // ui
@ -27,6 +29,7 @@ export const DeactivateAccountModal: React.FC<Props> = (props) => {
const router = useRouter(); const router = useRouter();
const { setToastAlert } = useToast(); const { setToastAlert } = useToast();
const { setTheme } = useTheme();
const handleClose = () => { const handleClose = () => {
setIsDeactivating(false); setIsDeactivating(false);
@ -43,8 +46,10 @@ export const DeactivateAccountModal: React.FC<Props> = (props) => {
title: "Success!", title: "Success!",
message: "Account deactivated successfully.", message: "Account deactivated successfully.",
}); });
handleClose(); mutate("CURRENT_USER_DETAILS", null);
setTheme("system");
router.push("/"); router.push("/");
handleClose();
}) })
.catch((err) => .catch((err) =>
setToastAlert({ setToastAlert({

View File

@ -1,4 +1,4 @@
import React, {useState } from "react"; import React, { useState } from "react";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { mutate } from "swr"; import { mutate } from "swr";
import { useTheme } from "next-themes"; import { useTheme } from "next-themes";
@ -67,8 +67,10 @@ export const SwitchOrDeleteAccountModal: React.FC<Props> = (props) => {
title: "Success!", title: "Success!",
message: "Account deleted successfully.", message: "Account deleted successfully.",
}); });
handleClose(); mutate("CURRENT_USER_DETAILS", null);
setTheme("system");
router.push("/"); router.push("/");
handleClose();
}) })
.catch((err) => .catch((err) =>
setToastAlert({ setToastAlert({

View File

@ -374,6 +374,9 @@ class UserStore implements IUserStore {
deactivateAccount = async () => { deactivateAccount = async () => {
try { try {
await this.userService.deactivateAccount(); await this.userService.deactivateAccount();
this.currentUserError = null;
this.currentUser = null;
this.isUserLoggedIn = false;
} catch (error) { } catch (error) {
throw error; throw error;
} }