From 6f0b2b85df74199575eabee3abfd7734bd36df76 Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 13 Jul 2020 20:59:52 +0800 Subject: Move front end to a submodule. --- Timeline/ClientApp/src/app/user/Login.tsx | 147 ------------------------------ 1 file changed, 147 deletions(-) delete mode 100644 Timeline/ClientApp/src/app/user/Login.tsx (limited to 'Timeline/ClientApp/src/app/user/Login.tsx') diff --git a/Timeline/ClientApp/src/app/user/Login.tsx b/Timeline/ClientApp/src/app/user/Login.tsx deleted file mode 100644 index f8b3f0e7..00000000 --- a/Timeline/ClientApp/src/app/user/Login.tsx +++ /dev/null @@ -1,147 +0,0 @@ -import React, { Fragment, useState, useEffect } from 'react'; -import { useHistory } from 'react-router'; -import { useTranslation } from 'react-i18next'; -import { AxiosError } from 'axios'; - -import AppBar from '../common/AppBar'; - -import { userLogin, useUser } from '../data/user'; -import { - Label, - FormGroup, - Input, - Form, - FormFeedback, - Spinner, - Button, -} from 'reactstrap'; - -const Login: React.FC = (_) => { - const { t } = useTranslation(); - const history = useHistory(); - const [username, setUsername] = useState(''); - const [usernameDirty, setUsernameDirty] = useState(false); - const [password, setPassword] = useState(''); - const [passwordDirty, setPasswordDirty] = useState(false); - const [rememberMe, setRememberMe] = useState(true); - const [process, setProcess] = useState(false); - const [error, setError] = useState(null); - - const user = useUser(); - - useEffect(() => { - if (user != null) { - const id = setTimeout(() => history.push('/'), 3000); - return () => { - clearTimeout(id); - }; - } - }, [history, user]); - - if (user != null) { - return ( - <> - -

{t('login.alreadyLogin')}

- - ); - } - - function onSubmit(event: React.SyntheticEvent): void { - if (username === '' || password === '') { - setUsernameDirty(true); - setPasswordDirty(true); - return; - } - - setProcess(true); - userLogin( - { - username: username, - password: password, - }, - rememberMe - ).then( - (_) => { - if (history.length === 0) { - history.push('/'); - } else { - history.goBack(); - } - }, - (e: AxiosError | Error) => { - setProcess(false); - setError(e.message); - } - ); - event.preventDefault(); - } - - return ( - - -
-

{t('welcome')}

-
- - - { - setUsername(e.target.value); - setUsernameDirty(true); - }} - value={username} - invalid={usernameDirty && username === ''} - /> - {usernameDirty && username === '' && ( - {t('login.emptyUsername')} - )} - - - - { - setPassword(e.target.value); - setPasswordDirty(true); - }} - value={password} - invalid={passwordDirty && password === ''} - /> - {passwordDirty && password === '' && ( - {t('login.emptyPassword')} - )} - - - { - const v = (e.target as HTMLInputElement).checked; - setRememberMe(v); - }} - /> - - - {error ?

{t(error)}

: null} -
- {process ? ( - - ) : ( - - )} -
-
-
-
- ); -}; - -export default Login; -- cgit v1.2.3