summaryrefslogtreecommitdiffhomepage
path: root/frontend/src/pages/Authentication.tsx
blob: 4b2ff721b8a180d8a74d6ef67bf23deffbc5387d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { useReduxStore } from "@redux/hooks/base";
import logo from "@static/logo128.png";
import { useSystem } from "apis/hooks";
import React, { FunctionComponent, useState } from "react";
import { Button, Card, Form, Image, Spinner } from "react-bootstrap";
import { Redirect } from "react-router-dom";
import "./Authentication.scss";

interface Props {}

const Authentication: FunctionComponent<Props> = () => {
  const [username, setUsername] = useState("");
  const [password, setPassword] = useState("");

  const { login, isWorking } = useSystem();

  const authenticated = useReduxStore((s) => s.status !== "unauthenticated");

  if (authenticated) {
    return <Redirect to="/"></Redirect>;
  }

  return (
    <div className="d-flex bg-light vh-100 justify-content-center align-items-center">
      <Card className="auth-card shadow">
        <Form
          onSubmit={(e) => {
            e.preventDefault();
            login({ username, password });
          }}
        >
          <Card.Body>
            <Form.Group className="mb-5 d-flex justify-content-center">
              <Image width="64" height="64" src={logo}></Image>
            </Form.Group>
            <Form.Group>
              <Form.Control
                disabled={isWorking}
                name="username"
                type="text"
                placeholder="Username"
                required
                onChange={(e) => setUsername(e.currentTarget.value)}
              ></Form.Control>
            </Form.Group>
            <Form.Group>
              <Form.Control
                disabled={isWorking}
                name="password"
                type="password"
                placeholder="Password"
                required
                onChange={(e) => setPassword(e.currentTarget.value)}
              ></Form.Control>
            </Form.Group>
            {/* <Collapse in={error.length !== 0}>
              <div>
                <Alert variant="danger" className="m-0">
                  {error}
                </Alert>
              </div>
            </Collapse> */}
          </Card.Body>
          <Card.Footer>
            <Button type="submit" disabled={isWorking} block>
              {isWorking ? (
                <Spinner size="sm" animation="border"></Spinner>
              ) : (
                "LOGIN"
              )}
            </Button>
          </Card.Footer>
        </Form>
      </Card>
    </div>
  );
};

export default Authentication;