From 4863f08a4c0b37f82e1006a9a8169a321b9550c6 Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Wed, 14 Feb 2024 17:10:09 +0600 Subject: [PATCH] fix: disable login buttons (#5179) * fix: disable login buttons * refactor: remove dead code * fix: add signup form --- .../AuthenticationFlow/AuthenticationForm.tsx | 41 +++++++++++++++++++ .../AuthenticationFlow/EmailLoginForm.tsx | 13 +++++- .../AuthenticationFlow/EmailSignupForm.tsx | 19 ++++++--- .../AuthenticationFlow/GitHubButton.tsx | 14 ++++++- .../AuthenticationFlow/GoogleButton.tsx | 15 ++++++- .../AuthenticationFlow/LinkedInButton.tsx | 15 ++++++- .../AuthenticationFlow/LoginPopup.astro | 22 ++-------- src/pages/login.astro | 22 +++------- src/pages/signup.astro | 16 +------- 9 files changed, 116 insertions(+), 61 deletions(-) create mode 100644 src/components/AuthenticationFlow/AuthenticationForm.tsx diff --git a/src/components/AuthenticationFlow/AuthenticationForm.tsx b/src/components/AuthenticationFlow/AuthenticationForm.tsx new file mode 100644 index 000000000..70f07c5f4 --- /dev/null +++ b/src/components/AuthenticationFlow/AuthenticationForm.tsx @@ -0,0 +1,41 @@ +import { useState } from 'react'; +import { GitHubButton } from './GitHubButton'; +import { GoogleButton } from './GoogleButton'; +import { LinkedInButton } from './LinkedInButton'; +import { EmailLoginForm } from './EmailLoginForm'; +import { EmailSignupForm } from './EmailSignupForm'; + +type AuthenticationFormProps = { + type?: 'login' | 'signup'; +}; + +export function AuthenticationForm(props: AuthenticationFormProps) { + const { type = 'login' } = props; + + const [isDisabled, setIsDisabled] = useState(false); + + return ( + <> +
+ + + +
+ +
+
+ OR +
+
+ + {type === 'login' ? ( + + ) : ( + + )} + + ); +} diff --git a/src/components/AuthenticationFlow/EmailLoginForm.tsx b/src/components/AuthenticationFlow/EmailLoginForm.tsx index 3ba9c7c13..07304f00e 100644 --- a/src/components/AuthenticationFlow/EmailLoginForm.tsx +++ b/src/components/AuthenticationFlow/EmailLoginForm.tsx @@ -4,7 +4,14 @@ import { useState } from 'react'; import { httpPost } from '../../lib/http'; import { TOKEN_COOKIE_NAME } from '../../lib/jwt'; -export function EmailLoginForm() { +type EmailLoginFormProps = { + isDisabled?: boolean; + setIsDisabled?: (isDisabled: boolean) => void; +}; + +export function EmailLoginForm(props: EmailLoginFormProps) { + const { isDisabled, setIsDisabled } = props; + const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); @@ -14,6 +21,7 @@ export function EmailLoginForm() { const handleFormSubmit = async (e: FormEvent) => { e.preventDefault(); setIsLoading(true); + setIsDisabled?.(true); setError(''); const { response, error } = await httpPost<{ token: string }>( @@ -45,6 +53,7 @@ export function EmailLoginForm() { } setIsLoading(false); + setIsDisabled?.(false); setError(error?.message || 'Something went wrong. Please try again later.'); }; @@ -92,7 +101,7 @@ export function EmailLoginForm() {