import LockOutlinedIcon from "@mui/icons-material/LockOutlined"; import { Alert } from "@mui/material"; import Avatar from "@mui/material/Avatar"; import Box from "@mui/material/Box"; import Button from "@mui/material/Button"; import CssBaseline from "@mui/material/CssBaseline"; import Grid from "@mui/material/Grid"; import Link from "@mui/material/Link"; import Paper from "@mui/material/Paper"; import TextField from "@mui/material/TextField"; import Typography from "@mui/material/Typography"; import * as React from "react"; import { useAlert } from "../hooks/context_providers/AlertDialogProvider"; import { useLoadingMessage } from "../hooks/context_providers/LoadingMessageProvider"; import { AuthApi } from "../api/AuthApi"; function Copyright(props: any) { return ( {"Copyright © "} Pierre HUBERT {" "} {new Date().getFullYear()} {"."} ); } export function LoginRoute() { const loadingMessage = useLoadingMessage(); const [user, setUser] = React.useState(""); const [password, setPassword] = React.useState(""); const [error, setError] = React.useState(); const handleSubmit = async (event: React.FormEvent) => { event.preventDefault(); try { loadingMessage.show("Signing in..."); setError(undefined); await AuthApi.AuthWithPassword(user, password); location.href = "/"; } catch (e) { console.error("Failed to perform login!", e); setError(`Failed to authenticate! ${e}`); } finally { loadingMessage.hide(); } }; return ( t.palette.mode === "light" ? t.palette.grey[50] : t.palette.grey[900], backgroundSize: "cover", backgroundPosition: "left", }} /> SolarEnergy {error && {error}} setUser(v.target.value)} /> setPassword(v.target.value)} /> ); }