From 2ddfb9646e556625d10df474569d2ad160afc81a Mon Sep 17 00:00:00 2001 From: trinity-y Date: Thu, 28 Nov 2024 22:34:57 -0500 Subject: [PATCH] add loading + error modals --- frontend/src/components/auth/Login.tsx | 127 ++++++++++++++++++------- 1 file changed, 95 insertions(+), 32 deletions(-) diff --git a/frontend/src/components/auth/Login.tsx b/frontend/src/components/auth/Login.tsx index 2ad1e14..b5a6716 100644 --- a/frontend/src/components/auth/Login.tsx +++ b/frontend/src/components/auth/Login.tsx @@ -1,4 +1,5 @@ import React, { useContext, useState, useEffect } from "react"; +import { Text, Flex } from "@chakra-ui/react"; import { Redirect } from "react-router-dom"; import { isSignInWithEmailLink } from "firebase/auth"; import auth from "../../firebase/firebase"; @@ -6,14 +7,19 @@ import authAPIClient from "../../APIClients/AuthAPIClient"; import { CREATE_PASSWORD_PAGE, HOME_PAGE } from "../../constants/Routes"; import AuthContext from "../../contexts/AuthContext"; import { AuthenticatedUser } from "../../types/AuthTypes"; +import ResponsiveModalWindow from "../common/responsive/ResponsiveModalWindow"; const Login = (): React.ReactElement => { const { authenticatedUser, setAuthenticatedUser } = useContext(AuthContext); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [redirectTo, setRedirectTo] = useState(null); + const [status, setStatus] = useState<"loading" | "error" | "default">( + "default", + ); useEffect(() => { + setStatus("loading"); const checkIfSignInLink = async () => { const url = window.location.href; const urlSearchParams = new URLSearchParams(window.location.search); @@ -25,8 +31,14 @@ const Login = (): React.ReactElement => { url, signInEmail, ); - setAuthenticatedUser(user); - setRedirectTo(CREATE_PASSWORD_PAGE); + if (user) { + setAuthenticatedUser(user); + setRedirectTo(CREATE_PASSWORD_PAGE); + } else { + setStatus("error"); + } + } else { + setStatus("default"); } }; @@ -48,36 +60,87 @@ const Login = (): React.ReactElement => { return ( <> -
-

Login

-
-
- setEmail(event.target.value)} - placeholder="username@domain.com" - /> -
-
- setPassword(event.target.value)} - placeholder="password" - /> -
-
- -
-
-
+ {status === "loading" && ( + + + + Loading, please wait... + + + + )} + + {status === "error" && ( + + + + An error occurred. If your link is expired, ask an adminstrator + for assistance. + + + + )} + + {status === "default" && !redirectTo && ( +
+

Login

+
+
+ setEmail(event.target.value)} + placeholder="username@domain.com" + /> +
+
+ setPassword(event.target.value)} + placeholder="password" + /> +
+
+ +
+
+
+ )} ); };