From 33944e5baff9f9aa4cd5fb65d2a3ef82ef2ff3fc Mon Sep 17 00:00:00 2001 From: igorrCarvalho Date: Thu, 10 Aug 2023 03:22:18 -0300 Subject: [PATCH] refactor[loginPage]: Refactor login Page to use Form UI Radix Modal --- src/frontend/src/constants/constants.ts | 5 + src/frontend/src/pages/loginPage/index.tsx | 153 ++++++++++++++++---- src/frontend/src/pages/signUpPage/index.tsx | 12 +- src/frontend/src/types/components/index.ts | 7 +- 4 files changed, 138 insertions(+), 39 deletions(-) diff --git a/src/frontend/src/constants/constants.ts b/src/frontend/src/constants/constants.ts index 142684c3e..776e3d4f8 100644 --- a/src/frontend/src/constants/constants.ts +++ b/src/frontend/src/constants/constants.ts @@ -514,3 +514,8 @@ export const CONTROL_INPUT_STATE = { cnfPassword: "", username: "", }; + +export const CONTROL_LOGIN_STATE = { + username: "", + password: "", +}; diff --git a/src/frontend/src/pages/loginPage/index.tsx b/src/frontend/src/pages/loginPage/index.tsx index 6ba88455a..29ae6a4e1 100644 --- a/src/frontend/src/pages/loginPage/index.tsx +++ b/src/frontend/src/pages/loginPage/index.tsx @@ -1,39 +1,130 @@ -import { FaApple, FaGithub } from "react-icons/fa"; +import * as Form from "@radix-ui/react-form"; +import { useState } from "react"; +import InputComponent from "../../components/inputComponent"; import { Button } from "../../components/ui/button"; import { Input } from "../../components/ui/input"; -import { GoogleIcon } from "../../icons/Google"; +import { CONTROL_LOGIN_STATE } from "../../constants/constants"; +import { inputHandlerEventType, loginInputStateType, } from "../../types/components"; +import { Link } from "react-router-dom"; +import IconComponent from "../../components/genericIconComponent"; -export default function LoginPage() { +export default function LoginPage(): JSX.Element { + const [inputState, setInputState] = + useState(CONTROL_LOGIN_STATE); + + const { password, username } = inputState; + + function handleInput({ + target: { name, value }, + }: inputHandlerEventType): void { + setInputState((prev) => ({ ...prev, [name]: value })); + } return ( -
-
- ⛓️ - - Log in to LangFlow - -
- - - + { + if (password === "") { + event.preventDefault(); + return; + } + + const data = Object.fromEntries(new FormData(event.currentTarget)); + event.preventDefault(); + }} + className="w-full h-full" + > +
+
+ ⛓️ + + Sign in to LangFlow + +
+ + + +
+ or +
+ + + Username * + + + + { + handleInput({ target: { name: "username", value } }); + }} + value={username} + className="w-full" + required + placeholder="Username" + /> + + + + Please enter your username + + +
+
+ + + Password * + + + + { + handleInput({ target: { name: "password", value } }); + }} + value={password} + password={true} + placeholder="Password" + className="w-full" + /> + + + + Please enter your password + + + {password === "" && ( + + Please enter a valid password + + )} + +
+
+ + + +
+
+ + + +
- or - - - -
-
+ ); } diff --git a/src/frontend/src/pages/signUpPage/index.tsx b/src/frontend/src/pages/signUpPage/index.tsx index 797ef62b6..448fd5804 100644 --- a/src/frontend/src/pages/signUpPage/index.tsx +++ b/src/frontend/src/pages/signUpPage/index.tsx @@ -1,18 +1,16 @@ import * as Form from "@radix-ui/react-form"; -import { useState } from "react"; -import { FaApple, FaGithub } from "react-icons/fa"; +import { FormEvent, useState } from "react"; import InputComponent from "../../components/inputComponent"; import { Button } from "../../components/ui/button"; import { Input } from "../../components/ui/input"; import { CONTROL_INPUT_STATE } from "../../constants/constants"; -import { GoogleIcon } from "../../icons/Google"; -import { inputHandlerEventType, inputStateType } from "../../types/components"; +import { inputHandlerEventType, signUpInputStateType } from "../../types/components"; import { Link } from "react-router-dom"; import IconComponent from "../../components/genericIconComponent"; export default function SignUp(): JSX.Element { const [inputState, setInputState] = - useState(CONTROL_INPUT_STATE); + useState(CONTROL_INPUT_STATE); const { password, cnfPassword, username } = inputState; @@ -23,8 +21,8 @@ export default function SignUp(): JSX.Element { } return ( { - if (password !== cnfPassword) { + onSubmit={(event: FormEvent) => { + if (password === "") { event.preventDefault(); return; } diff --git a/src/frontend/src/types/components/index.ts b/src/frontend/src/types/components/index.ts index 70c19aa1a..ba6e0da87 100644 --- a/src/frontend/src/types/components/index.ts +++ b/src/frontend/src/types/components/index.ts @@ -174,7 +174,7 @@ export interface languageMap { [key: string]: string | undefined; } -export type inputStateType = { +export type signUpInputStateType = { password: string; cnfPassword: string; username: string; @@ -219,3 +219,8 @@ export type UserManagementType = { index?: number; onConfirm: (index, data) => void; }; + +export type loginInputStateType = { + username: string; + password: string; +}