|
@@ -1,12 +1,7 @@
|
|
|
"use client";
|
|
|
-import { getLogoutApi } from "@/api/user";
|
|
|
+import { useLogout } from "@/hooks/useLogout";
|
|
|
import { useRouter } from "@/i18n/routing";
|
|
|
-import { useSearchStore } from "@/stores/useSearchStore";
|
|
|
-import { useUserInfoStore } from "@/stores/useUserInfoStore";
|
|
|
-import { useWalletStore } from "@/stores/useWalletStore";
|
|
|
import { CenterPopup } from "antd-mobile";
|
|
|
-import dayjs from "dayjs";
|
|
|
-import Cookies from "js-cookie";
|
|
|
import { useTranslations } from "next-intl";
|
|
|
import { FC, PropsWithChildren, useEffect, useRef, useState } from "react";
|
|
|
import "./style.scss";
|
|
@@ -21,29 +16,9 @@ export interface ItemComProps {
|
|
|
|
|
|
const ModalCom: FC<PropsWithChildren<ItemComProps>> = () => {
|
|
|
const t = useTranslations("ProfilePage");
|
|
|
- const restGlobal = useUserInfoStore((state) => state.reset);
|
|
|
- const resetSearch = useSearchStore((state) => state.reset);
|
|
|
- const restWalletStore = useWalletStore((state) => state.reset);
|
|
|
-
|
|
|
- // const { isOpen, onOpen, onClose, onOpenChange } = useDisclosure();
|
|
|
+ const { logout } = useLogout();
|
|
|
const [visible, setVisible] = useState(false);
|
|
|
const element = useRef<HTMLElement | null>(null);
|
|
|
- const logoutRequest = async () => {
|
|
|
- let res = await getLogoutApi();
|
|
|
- const isClearPromotion = dayjs().isSame(sessionStorage.getItem("isClosePromotion"), "days");
|
|
|
- if (res.code == 200) {
|
|
|
- restGlobal();
|
|
|
- resetSearch();
|
|
|
- restWalletStore();
|
|
|
- localStorage.clear();
|
|
|
- Cookies.remove("Token");
|
|
|
- router.replace("/login");
|
|
|
- }
|
|
|
- if (!isClearPromotion) {
|
|
|
- sessionStorage.clear();
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
const router = useRouter();
|
|
|
const goPage = (path = "/") => {
|
|
|
router.push(path);
|
|
@@ -80,7 +55,7 @@ const ModalCom: FC<PropsWithChildren<ItemComProps>> = () => {
|
|
|
<span className="modal-span-box" onClick={() => setVisible(false)}>
|
|
|
{t("Cancelar")}
|
|
|
</span>
|
|
|
- <span className="modal-span-box active" onClick={logoutRequest}>
|
|
|
+ <span className="modal-span-box active" onClick={logout}>
|
|
|
{t("Continuar")}
|
|
|
</span>
|
|
|
</div>
|