From 5c771c806da0da3f3e875135cc9811ba11e566e4 Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Wed, 14 Feb 2024 14:51:06 +0600 Subject: [PATCH] fix: disable login buttons --- .../AuthenticationFlow/AuthenticationForm.tsx | 26 +++++++++++++++++++ .../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 | 17 +++++------- src/pages/signup.astro | 11 ++------ 9 files changed, 101 insertions(+), 51 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..2667a141d --- /dev/null +++ b/src/components/AuthenticationFlow/AuthenticationForm.tsx @@ -0,0 +1,26 @@ +import { GitHubButton } from './GitHubButton'; +import { GoogleButton } from './GoogleButton'; +import { LinkedInButton } from './LinkedInButton'; +import { EmailLoginForm } from './EmailLoginForm'; +import { useState } from 'react'; + +export function AuthenticationForm() { + const [isDisabled, setIsDisabled] = useState(false); + return ( + <> +
+ + + +
+ +
+
+ OR +
+
+ + + + ); +} 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() {