From f1e0b84e60c61d89007d9a5f0bda35f8b226817a Mon Sep 17 00:00:00 2001 From: Aditya Gannavarapu Date: Sat, 20 Jan 2024 03:10:50 +0530 Subject: [PATCH 1/3] Add loader to Button component and clean login page --- apps/client/pages/login.tsx | 25 +++++++------ apps/client/pages/register.tsx | 4 ++ libs/design-system/src/lib/Button/Button.tsx | 39 ++++++++++++++++++++ 3 files changed, 57 insertions(+), 11 deletions(-) diff --git a/apps/client/pages/login.tsx b/apps/client/pages/login.tsx index aabcc715..57cbfa70 100644 --- a/apps/client/pages/login.tsx +++ b/apps/client/pages/login.tsx @@ -1,6 +1,6 @@ import { useState, type ReactElement } from 'react' import { FullPageLayout } from '@maybe-finance/client/features' -import { Input, InputPassword, Button } from '@maybe-finance/design-system' +import { Input, InputPassword, Button, LoadingSpinner } from '@maybe-finance/design-system' import { signIn, useSession } from 'next-auth/react' import { useRouter } from 'next/router' import { useEffect } from 'react' @@ -10,8 +10,9 @@ import Link from 'next/link' export default function LoginPage() { const [email, setEmail] = useState('') const [password, setPassword] = useState('') - const [isValid, setIsValid] = useState(false) + const [isValid, setIsValid] = useState(true) const [errorMessage, setErrorMessage] = useState(null) + const [isLoading, setIsLoading] = useState(false) const { data: session } = useSession() const router = useRouter() @@ -26,6 +27,7 @@ export default function LoginPage() { e.preventDefault() setErrorMessage(null) setPassword('') + setIsLoading(true) const response = await signIn('credentials', { email, @@ -35,9 +37,16 @@ export default function LoginPage() { if (response && response.error) { setErrorMessage(response.error) + setIsLoading(false) } } + const onPasswordChange = (e: React.ChangeEvent) => { + setErrorMessage(null) + setPassword(e.target.value) + setIsValid(e.target.value.length > 0) + } + return ( <>