From 2d42d316a04ebe2ddbb6e906f8479f69f48187ea Mon Sep 17 00:00:00 2001 From: gurusainath Date: Thu, 2 May 2024 13:14:02 +0530 Subject: [PATCH] chore: UI changes and revamp components for authentication --- space/components/views/auth.tsx | 2 +- space/pages/accounts/forgot-password.tsx | 5 +- space/pages/accounts/reset-password.tsx | 2 +- .../account/auth-forms/auth-banner.tsx | 2 +- web/components/account/auth-forms/email.tsx | 10 +- .../account/auth-forms/password.tsx | 2 +- .../account/auth-forms/sign-in-root.tsx | 78 ++++--- .../account/auth-forms/sign-up-root.tsx | 2 +- .../account/auth-forms/unique-code.tsx | 2 +- .../account/oauth/github-sign-in.tsx | 62 ------ .../account/oauth/google-sign-in.tsx | 60 ------ web/components/account/oauth/index.ts | 2 - .../account/oauth/oauth-options.tsx | 4 +- web/components/page-views/index.ts | 1 - web/components/page-views/signup.tsx | 61 ------ web/pages/accounts/forgot-password.tsx | 128 ++++++----- web/pages/accounts/reset-password.tsx | 194 +++++++++-------- web/pages/accounts/set-password.tsx | 201 +++++++++--------- web/pages/accounts/sign-in.tsx | 16 +- web/pages/index.tsx | 60 +++++- 20 files changed, 372 insertions(+), 522 deletions(-) delete mode 100644 web/components/account/oauth/github-sign-in.tsx delete mode 100644 web/components/account/oauth/google-sign-in.tsx delete mode 100644 web/components/page-views/signup.tsx diff --git a/space/components/views/auth.tsx b/space/components/views/auth.tsx index 28ae94419..c951bbf5e 100644 --- a/space/components/views/auth.tsx +++ b/space/components/views/auth.tsx @@ -50,7 +50,7 @@ export const AuthView = observer(() => {
Plane background pattern
diff --git a/space/pages/accounts/forgot-password.tsx b/space/pages/accounts/forgot-password.tsx index 1def106a6..0538df24a 100644 --- a/space/pages/accounts/forgot-password.tsx +++ b/space/pages/accounts/forgot-password.tsx @@ -79,9 +79,9 @@ const ForgotPasswordPage: NextPage = () => { return (
- Plane background pattern
@@ -159,5 +159,4 @@ const ForgotPasswordPage: NextPage = () => { ); }; - export default ForgotPasswordPage; diff --git a/space/pages/accounts/reset-password.tsx b/space/pages/accounts/reset-password.tsx index 7ea610e4f..a8d232d97 100644 --- a/space/pages/accounts/reset-password.tsx +++ b/space/pages/accounts/reset-password.tsx @@ -79,7 +79,7 @@ const ResetPasswordPage: NextPage = () => {
Plane background pattern
diff --git a/web/components/account/auth-forms/auth-banner.tsx b/web/components/account/auth-forms/auth-banner.tsx index 6d805e5bf..191d7a0a7 100644 --- a/web/components/account/auth-forms/auth-banner.tsx +++ b/web/components/account/auth-forms/auth-banner.tsx @@ -13,7 +13,7 @@ export const AuthBanner: FC = (props) => { if (!bannerData) return <>; return ( -
+
diff --git a/web/components/account/auth-forms/email.tsx b/web/components/account/auth-forms/email.tsx index f5225811c..573dc59e6 100644 --- a/web/components/account/auth-forms/email.tsx +++ b/web/components/account/auth-forms/email.tsx @@ -38,7 +38,7 @@ export const AuthEmailForm: FC = observer((props) => { const isButtonDisabled = email.length === 0 || Boolean(emailError?.email) || isSubmitting; return ( -
+
-
diff --git a/web/components/account/auth-forms/password.tsx b/web/components/account/auth-forms/password.tsx index 9c4d2150e..de3d813e1 100644 --- a/web/components/account/auth-forms/password.tsx +++ b/web/components/account/auth-forms/password.tsx @@ -98,7 +98,7 @@ export const AuthPasswordForm: React.FC = observer((props: Props) => { return (
setIsSubmitting(true)} diff --git a/web/components/account/auth-forms/sign-in-root.tsx b/web/components/account/auth-forms/sign-in-root.tsx index 883bf9674..87224471d 100644 --- a/web/components/account/auth-forms/sign-in-root.tsx +++ b/web/components/account/auth-forms/sign-in-root.tsx @@ -11,7 +11,7 @@ import { AuthPasswordForm, OAuthOptions, TermsAndConditions, - UniqueCodeForm, + AuthUniqueCodeForm, } from "@/components/account"; // helpers import { @@ -82,45 +82,43 @@ export const SignInAuthRoot = observer(() => { ); return ( - <> -
- + + {errorInfo && errorInfo?.type === EErrorAlertType.BANNER_ALERT && ( + setErrorInfo(value)} /> + )} + {authStep === EAuthSteps.EMAIL && } + {authStep === EAuthSteps.UNIQUE_CODE && ( + { + setEmail(""); + setAuthStep(EAuthSteps.EMAIL); + }} + submitButtonText="Continue" + mode={authMode} /> - {errorInfo && errorInfo?.type === EErrorAlertType.BANNER_ALERT && ( - setErrorInfo(value)} /> - )} - {authStep === EAuthSteps.EMAIL && } - {authStep === EAuthSteps.UNIQUE_CODE && ( - { - setEmail(""); - setAuthStep(EAuthSteps.EMAIL); - }} - submitButtonText="Continue" - mode={authMode} - /> - )} - {authStep === EAuthSteps.PASSWORD && ( - { - setEmail(""); - setAuthStep(EAuthSteps.EMAIL); - }} - handleStepChange={(step) => setAuthStep(step)} - mode={authMode} - /> - )} - {isOAuthEnabled && } - -
- + )} + {authStep === EAuthSteps.PASSWORD && ( + { + setEmail(""); + setAuthStep(EAuthSteps.EMAIL); + }} + handleStepChange={(step) => setAuthStep(step)} + mode={authMode} + /> + )} + {isOAuthEnabled && } + +
); }); diff --git a/web/components/account/auth-forms/sign-up-root.tsx b/web/components/account/auth-forms/sign-up-root.tsx index 25b996ae0..ec5fbd1d3 100644 --- a/web/components/account/auth-forms/sign-up-root.tsx +++ b/web/components/account/auth-forms/sign-up-root.tsx @@ -91,7 +91,7 @@ export const SignUpAuthRoot: FC = observer(() => { ); return ( -
+
= (props) => { return ( setIsSubmitting(true)} diff --git a/web/components/account/oauth/github-sign-in.tsx b/web/components/account/oauth/github-sign-in.tsx deleted file mode 100644 index 1f0f56225..000000000 --- a/web/components/account/oauth/github-sign-in.tsx +++ /dev/null @@ -1,62 +0,0 @@ -// react -import { useEffect, useState, FC } from "react"; -// next -import Link from "next/link"; -import Image from "next/image"; -import { useRouter } from "next/router"; -import { useTheme } from "next-themes"; -// images -import githubLightModeImage from "/public/logos/github-black.png"; -import githubDarkModeImage from "/public/logos/github-dark.svg"; - -type Props = { - handleSignIn: React.Dispatch; - clientId: string; - type: "sign_in" | "sign_up"; -}; - -export const GitHubSignInButton: FC = (props) => { - const { handleSignIn, clientId, type } = props; - // states - const [loginCallBackURL, setLoginCallBackURL] = useState(undefined); - const [gitCode, setGitCode] = useState(null); - // router - const { - query: { code }, - } = useRouter(); - // theme - const { resolvedTheme } = useTheme(); - - useEffect(() => { - if (code && !gitCode) { - setGitCode(code.toString()); - handleSignIn(code.toString()); - } - }, [code, gitCode, handleSignIn]); - - useEffect(() => { - const origin = typeof window !== "undefined" && window.location.origin ? window.location.origin : ""; - setLoginCallBackURL(`${origin}/` as any); - }, []); - return ( -
- - - -
- ); -}; diff --git a/web/components/account/oauth/google-sign-in.tsx b/web/components/account/oauth/google-sign-in.tsx deleted file mode 100644 index c1c57baa0..000000000 --- a/web/components/account/oauth/google-sign-in.tsx +++ /dev/null @@ -1,60 +0,0 @@ -import { FC, useEffect, useRef, useCallback, useState } from "react"; -import Script from "next/script"; - -type Props = { - handleSignIn: React.Dispatch; - clientId: string; - type: "sign_in" | "sign_up"; -}; - -export const GoogleSignInButton: FC = (props) => { - const { handleSignIn, clientId, type } = props; - // refs - const googleSignInButton = useRef(null); - // states - const [gsiScriptLoaded, setGsiScriptLoaded] = useState(false); - - const loadScript = useCallback(() => { - if (!googleSignInButton.current || gsiScriptLoaded) return; - - window?.google?.accounts.id.initialize({ - client_id: clientId, - callback: handleSignIn, - }); - - try { - window?.google?.accounts.id.renderButton( - googleSignInButton.current, - { - type: "standard", - theme: "outline", - size: "large", - logo_alignment: "center", - text: type === "sign_in" ? "signin_with" : "signup_with", - } as GsiButtonConfiguration // customization attributes - ); - } catch (err) { - console.log(err); - } - - window?.google?.accounts.id.prompt(); // also display the One Tap dialog - - setGsiScriptLoaded(true); - }, [handleSignIn, gsiScriptLoaded, clientId, type]); - - useEffect(() => { - if (window?.google?.accounts?.id) { - loadScript(); - } - return () => { - window?.google?.accounts.id.cancel(); - }; - }, [loadScript]); - - return ( - <> -