feat: add LogoutPage and adjust LoginPage

This commit is contained in:
Paul Pan 2023-12-21 16:36:39 +08:00
parent 2474012a1a
commit d69f6a5b86
4 changed files with 40 additions and 2 deletions

View File

@ -1,10 +1,11 @@
import { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";
import { message } from "antd";
import { LoginForm, ProFormText } from "@ant-design/pro-components";
import { LockOutlined, UserOutlined } from "@ant-design/icons";
import { useAuth } from "../components/hook.ts";
import { useEffect, useState } from "react";
export function LoginPage() {
const navigate = useNavigate();
@ -13,7 +14,11 @@ export function LoginPage() {
const [errMsg, setErrMsg] = useState("");
const onSuccess = async () => {
await msg.success("登录成功");
await msg.open({
type: "success",
content: "登录成功",
duration: 1,
});
if (window.history?.length) navigate(-1);
else navigate("/");
};

27
src/pages/logout.tsx Normal file
View File

@ -0,0 +1,27 @@
import { useEffect } from "react";
import { useNavigate } from "react-router-dom";
import { Result } from "antd";
import { SmileOutlined } from "@ant-design/icons";
import { useAuth } from "../components/hook.ts";
export function LogoutPage() {
const navigate = useNavigate();
const auth = useAuth();
const goHome = () => setTimeout(() => navigate("/"), 1500);
useEffect(
() => {
auth.logout(goHome, goHome);
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[],
);
return (
<>
<Result icon={<SmileOutlined />} title={"See you next time!"} />
</>
);
}

View File

@ -7,3 +7,4 @@ export { SearchPage } from "./search";
export { SubmitPage } from "./submit";
export { LoginPage } from "./login.tsx";
export { LogoutPage } from "./logout.tsx";

View File

@ -1,6 +1,7 @@
import {
HomePage,
LoginPage,
LogoutPage,
ProblemPage,
SearchPage,
SubmitPage,
@ -18,6 +19,10 @@ const RouteConfigs = [
path: "login",
element: <LoginPage />,
},
{
path: "logout",
element: <LogoutPage />,
},
{
path: "search",
element: <SearchPage />,