From e1f6ac68f9b5abe9ad7d958aacb0f75e22e3a1d7 Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Fri, 31 Mar 2023 23:09:10 +0600 Subject: [PATCH] chore: github astro component --- src/components/Login/Divider.astro | 5 + src/components/Login/GithubLogin.astro | 69 +++++++++++ src/components/Login/GoogleLogin.astro | 70 ++++++++++++ src/components/Login/LoginComponent.tsx | 69 ----------- src/components/Login/LoginCopmponent.astro | 31 +++++ src/components/Login/LoginPopup.astro | 5 +- src/components/Login/google-login.tsx | 127 --------------------- src/icons/github.svg | 1 + src/icons/google.svg | 2 +- src/pages/signup.astro | 11 +- 10 files changed, 186 insertions(+), 204 deletions(-) create mode 100644 src/components/Login/Divider.astro create mode 100644 src/components/Login/GithubLogin.astro create mode 100644 src/components/Login/GoogleLogin.astro delete mode 100644 src/components/Login/LoginComponent.tsx create mode 100644 src/components/Login/LoginCopmponent.astro delete mode 100644 src/components/Login/google-login.tsx create mode 100644 src/icons/github.svg diff --git a/src/components/Login/Divider.astro b/src/components/Login/Divider.astro new file mode 100644 index 000000000..49d9955ed --- /dev/null +++ b/src/components/Login/Divider.astro @@ -0,0 +1,5 @@ +
+
+ OR +
+
diff --git a/src/components/Login/GithubLogin.astro b/src/components/Login/GithubLogin.astro new file mode 100644 index 000000000..8d204ac89 --- /dev/null +++ b/src/components/Login/GithubLogin.astro @@ -0,0 +1,69 @@ +--- +import Icon from '../Icon.astro'; +import Spinner from '../Spinner.astro'; +--- + + + + diff --git a/src/components/Login/GoogleLogin.astro b/src/components/Login/GoogleLogin.astro new file mode 100644 index 000000000..6563c2ac6 --- /dev/null +++ b/src/components/Login/GoogleLogin.astro @@ -0,0 +1,70 @@ +--- +import Icon from '../Icon.astro'; +import Spinner from '../Spinner.astro'; +--- + + + + diff --git a/src/components/Login/LoginComponent.tsx b/src/components/Login/LoginComponent.tsx deleted file mode 100644 index 8445e1af4..000000000 --- a/src/components/Login/LoginComponent.tsx +++ /dev/null @@ -1,69 +0,0 @@ -import type { FunctionComponent } from 'preact'; -import EmailLoginForm from './email-login-form'; -import GoogleLoginButton from './google-login'; - -export default function LoginComponent() { - return ( -
-
-

- Welcome back -

-

- Please enter your details. -

-
- -
- - -
- - - - - -
- Don't have an account?{' '} - - Sign up - -
-
- ); -} - -export const Divider: FunctionComponent<{ className?: string }> = ({ - className, -}) => { - return ( -
-
- OR -
-
- ); -}; - -export const GithubLoginButton: FunctionComponent<{ className?: string }> = ({ - className, -}) => { - return ( - - ); -}; diff --git a/src/components/Login/LoginCopmponent.astro b/src/components/Login/LoginCopmponent.astro new file mode 100644 index 000000000..3e9b71014 --- /dev/null +++ b/src/components/Login/LoginCopmponent.astro @@ -0,0 +1,31 @@ +--- +import Divider from './Divider.astro'; +import GithubLogin from './GithubLogin.astro'; +import GoogleLogin from './GoogleLogin.astro'; +import EmailLoginForm from './email-login-form'; +--- + +
+
+

+ Welcome back +

+

+ Please enter your details. +

+
+ +
+ + +
+ + + + + +
+ Don't have an account?{' '} + Sign up +
+
diff --git a/src/components/Login/LoginPopup.astro b/src/components/Login/LoginPopup.astro index 2f5948035..be8cc5bd0 100644 --- a/src/components/Login/LoginPopup.astro +++ b/src/components/Login/LoginPopup.astro @@ -1,9 +1,8 @@ --- import Popup from '../Popup/Popup.astro'; -import LoginComponent from './LoginComponent' +import LoginComponent from './LoginCopmponent.astro'; --- - + - diff --git a/src/components/Login/google-login.tsx b/src/components/Login/google-login.tsx deleted file mode 100644 index 35885fffd..000000000 --- a/src/components/Login/google-login.tsx +++ /dev/null @@ -1,127 +0,0 @@ -import Cookies from 'js-cookie'; -import { useEffect, useState } from 'preact/hooks'; -import { TOKEN_COOKIE_NAME } from '../../lib/utils'; - -export default function GoogleLoginButton() { - const [isLoading, setIsLoading] = useState(false); - - const handleRedirect = () => { - setIsLoading(true); - fetch('http://localhost:8080/v1-google-login', { - credentials: 'include', - }) - .then((res) => res.json()) - .then((data) => { - setIsLoading(false); - window.location.href = data.loginUrl; - }); - }; - - useEffect(() => { - // Get all query params and send them to v1-google-callback - const urlParams = new URLSearchParams(window.location.search); - const code = urlParams.get('code'); - const state = urlParams.get('state'); - const prompt = urlParams.get('prompt'); - - if (code && state && prompt) { - setIsLoading(true); - fetch( - `http://localhost:8080/v1-google-callback${window.location.search}`, - { - method: 'GET', - credentials: 'include', - } - ) - .then((res) => res.json()) - .then((data) => { - if (data.token) { - Cookies.set(TOKEN_COOKIE_NAME, data.token); - setIsLoading(false); - window.location.href = '/'; - } - }) - .catch((err) => { - console.log(err); - }); - } - }, []); - - return ( - - ); -} - -function Spinner({ className }: { className?: string }) { - return ( - - - - - ); -} - -function GoogleLogo() { - return ( - - - - - - - - - ); -} diff --git a/src/icons/github.svg b/src/icons/github.svg new file mode 100644 index 000000000..1e00675e1 --- /dev/null +++ b/src/icons/github.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/google.svg b/src/icons/google.svg index a2491e75b..719c527b1 100644 --- a/src/icons/google.svg +++ b/src/icons/google.svg @@ -1,4 +1,4 @@ - + diff --git a/src/pages/signup.astro b/src/pages/signup.astro index 676906ee2..eb809863f 100644 --- a/src/pages/signup.astro +++ b/src/pages/signup.astro @@ -1,9 +1,10 @@ --- import CaptchaFields from '../components/Captcha/CaptchaFields.astro'; import CaptchaScripts from '../components/Captcha/CaptchaScripts.astro'; -import { Divider, GithubLoginButton } from '../components/Login/LoginComponent'; +import Divider from '../components/Login/Divider.astro'; +import GithubLogin from '../components/Login/GithubLogin.astro'; +import GoogleLogin from '../components/Login/GoogleLogin.astro'; import EmailLoginForm from '../components/Login/email-login-form'; -import GoogleLoginButton from '../components/Login/google-login'; import BaseLayout from '../layouts/BaseLayout.astro'; --- @@ -29,8 +30,10 @@ import BaseLayout from '../layouts/BaseLayout.astro';

- - +
+ + +