Justin Rhee 3 лет назад
Родитель
Сommit
f9c63892e7
2 измененных файлов с 53 добавлено и 6 удалено
  1. 3 1
      dashboard/src/main/auth/Login.tsx
  2. 50 5
      dashboard/src/main/auth/Register.tsx

+ 3 - 1
dashboard/src/main/auth/Login.tsx

@@ -47,6 +47,8 @@ const Login: React.FC<Props> = ({
   const handleLogin = (): void => {
     if (!emailRegex.test(email)) {
       setEmailError(true);
+    } else if (password === "") {
+      setCredentialError(true);
     } else {
       api.logInUser(
         "",
@@ -205,7 +207,7 @@ const Login: React.FC<Props> = ({
               }}
               width="100%"
               height="40px"
-              error={credentialError && "Incorrect email or password"}
+              error={credentialError && ""}
             >
               {hasResetPassword && (
                 <ForgotPassword>

+ 50 - 5
dashboard/src/main/auth/Register.tsx

@@ -3,8 +3,12 @@ import styled from "styled-components";
 
 import github from "assets/github-icon.png";
 import logo from "assets/logo.png";
-
 import GoogleIcon from "assets/GoogleIcon";
+
+import api from "shared/api";
+import { emailRegex } from "shared/regex";
+import { Context } from "shared/Context";
+
 import Heading from "components/form-components/Heading";
 import Button from "components/porter/Button";
 import Container from "components/porter/Container";
@@ -29,15 +33,56 @@ const Register: React.FC<Props> = ({
   const [lastName, setLastName] = useState("");
   const [email, setEmail] = useState("");
   const [password, setPassword] = useState("");
+  const [emailError, setEmailError] = useState(false);
+  const [hasBasic, setHasBasic] = useState(true);
   const [hasGithub, setHasGithub] = useState(true);
-  const [hasGoogle, setHasGoogle] = useState(true);
+  const [hasGoogle, setHasGoogle] = useState(false);
   const [windowDimensions, setWindowDimensions] = useState(getWindowDimensions());
 
-  useEffect(() => {
-    const handleResize = () => {
-      setWindowDimensions(getWindowDimensions());
+  const handleRegister = (): void => {
+    if (!emailRegex.test(email)) {
+      this.setState({ emailError: true });
+    }
+
+    if (confirmPassword !== password) {
+      this.setState({ confirmPasswordError: true });
+    }
+
+    // Check for valid input
+    if (emailRegex.test(email) && confirmPassword === password) {
+      // Attempt user registration
+      api
+        .registerUser(
+          "",
+          {
+            email: email,
+            password: password,
+          },
+          {}
+        )
+        .then((res: any) => {
+          if (res?.data?.redirect) {
+            window.location.href = res.data.redirect;
+          } else {
+            setUser(res?.data?.id, res?.data?.email);
+            authenticate();
+          }
+        })
+        .catch((err) => setCurrentError(err.response.data.error));
+    }
+  };
+
+  const handleResize = () => {
+    setWindowDimensions(getWindowDimensions());
+  };
+
+  const handleKeyDown = (e: any) => {
+    if (e.key === "Enter") {
+      handleLogin();
     };
+  };
 
+  useEffect(() => {
     window.addEventListener('resize', handleResize);
     return () => window.removeEventListener('resize', handleResize);
   }, []);