import React, { FunctionComponent, useCallback, useState } from "react"; import { Alert, Button, Card, Collapse, Form, Image, Spinner, } from "react-bootstrap"; import { Redirect } from "react-router-dom"; import { siteAuthSuccess } from "../@redux/actions"; import { useReduxAction, useReduxStore } from "../@redux/hooks/base"; import logo from "../@static/logo128.png"; import { SystemApi } from "../apis"; import "./style.scss"; interface Props {} const AuthPage: FunctionComponent = () => { const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [updating, setUpdate] = useState(false); const updateError = useCallback((msg: string) => { setError(msg); setTimeout(() => setError(""), 2000); }, []); const onSuccess = useReduxAction(siteAuthSuccess); const authState = useReduxStore((s) => s.site.auth); const onError = useCallback(() => { setUpdate(false); updateError("Login Failed"); }, [updateError]); if (authState) { return ; } return (
{ e.preventDefault(); if (!updating) { setUpdate(true); SystemApi.login(username, password) .then(onSuccess) .catch(onError); } }} > setUsername(e.currentTarget.value)} > setPassword(e.currentTarget.value)} >
{error}
); }; export default AuthPage;