From 001712ec0ae0de86ec7d2c36e2fff8bccc55bab5 Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 29 Jul 2023 22:58:51 +0800 Subject: ... --- FrontEnd/src/views/register/index.css | 5 -- FrontEnd/src/views/register/index.tsx | 137 ---------------------------------- 2 files changed, 142 deletions(-) delete mode 100644 FrontEnd/src/views/register/index.css delete mode 100644 FrontEnd/src/views/register/index.tsx (limited to 'FrontEnd/src/views') diff --git a/FrontEnd/src/views/register/index.css b/FrontEnd/src/views/register/index.css deleted file mode 100644 index c0078b28..00000000 --- a/FrontEnd/src/views/register/index.css +++ /dev/null @@ -1,5 +0,0 @@ -.register-page { - display: flex; - flex-direction: column; - align-items: center; -} diff --git a/FrontEnd/src/views/register/index.tsx b/FrontEnd/src/views/register/index.tsx deleted file mode 100644 index 3ecbca63..00000000 --- a/FrontEnd/src/views/register/index.tsx +++ /dev/null @@ -1,137 +0,0 @@ -import * as React from "react"; -import { useTranslation } from "react-i18next"; -import { useNavigate } from "react-router-dom"; - -import { HttpBadRequestError } from "@/http/common"; -import { getHttpTokenClient } from "@/http/token"; -import { userService, useUser } from "@/services/user"; - -import { LoadingButton } from "../common/button"; -import { hasError, InputPanelError } from "../common/input/InputGroup"; - -import "./index.css"; - -const validate = (values: string[], dirties: boolean[]): InputPanelError => { - const e: InputPanelError = {}; - if (dirties[0] && values[0].length === 0) { - e[0] = "register.error.usernameEmpty"; - } - if (dirties[1] && values[1].length === 0) { - e[1] = "register.error.passwordEmpty"; - } - if (dirties[2] && values[2] !== values[1]) { - e[2] = "register.error.confirmPasswordWrong"; - } - if (dirties[3] && values[3].length === 0) { - e[3] = "register.error.registerCodeEmpty"; - } - return e; -}; - -const RegisterPage: React.FC = () => { - const navigate = useNavigate(); - - const { t } = useTranslation(); - - const [username, setUsername] = React.useState(""); - const [password, setPassword] = React.useState(""); - const [confirmPassword, setConfirmPassword] = React.useState(""); - const [registerCode, setRegisterCode] = React.useState(""); - - const [dirty, setDirty] = React.useState(new Array(4).fill(false)); - - const [process, setProcess] = React.useState(false); - - const [inputError, setInputError] = React.useState(); - const [resultError, setResultError] = React.useState(null); - - const user = useUser(); - - React.useEffect(() => { - if (user != null) { - navigate("/"); - } - }); - - return ( -
- { - setUsername(values[0]); - setPassword(values[1]); - setConfirmPassword(values[2]); - setRegisterCode(values[3]); - const newDirty = dirty.slice(); - newDirty[index] = true; - setDirty(newDirty); - - setInputError(validate(values, newDirty)); - }} - error={inputError} - disable={process} - /> - {resultError &&
{t(resultError)}
} - { - const newDirty = dirty.slice().fill(true); - setDirty(newDirty); - const e = validate( - [username, password, confirmPassword, registerCode], - newDirty, - ); - if (hasError(e)) { - setInputError(e); - } else { - setProcess(true); - void getHttpTokenClient() - .register({ - username, - password, - registerCode, - }) - .then( - () => { - void userService - .login({ username, password }, true) - .then(() => { - navigate("/"); - }); - }, - (error) => { - if (error instanceof HttpBadRequestError) { - setResultError("register.error.registerCodeInvalid"); - } else { - setResultError("error.network"); - } - setProcess(false); - }, - ); - } - }} - /> -
- ); -}; - -export default RegisterPage; -- cgit v1.2.3