From 3dfaad87045cbc77c12dc5ecc4184559a0a103b6 Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Sun, 9 Apr 2023 15:59:13 +0100 Subject: [PATCH] Resend verfication email functionality --- src/components/Login/EmailSignupForm.tsx | 2 +- .../VerificationEmailMessage.tsx | 84 +++++++++++++++++++ ...erify.astro => verification-pending.astro} | 51 ++++------- 3 files changed, 100 insertions(+), 37 deletions(-) create mode 100644 src/components/RegistrationFlow/VerificationEmailMessage.tsx rename src/pages/{verify.astro => verification-pending.astro} (63%) diff --git a/src/components/Login/EmailSignupForm.tsx b/src/components/Login/EmailSignupForm.tsx index 1cacffc02..7dbb51b4c 100644 --- a/src/components/Login/EmailSignupForm.tsx +++ b/src/components/Login/EmailSignupForm.tsx @@ -19,7 +19,7 @@ const EmailSignupForm: FunctionComponent = () => { return; } - window.location.href = `/verify?email=${email}`; + window.location.href = `/verification-pending?email=${encodeURIComponent(email)}`; }; const onSubmit = (e: Event) => { diff --git a/src/components/RegistrationFlow/VerificationEmailMessage.tsx b/src/components/RegistrationFlow/VerificationEmailMessage.tsx new file mode 100644 index 000000000..9a7c43d07 --- /dev/null +++ b/src/components/RegistrationFlow/VerificationEmailMessage.tsx @@ -0,0 +1,84 @@ +import VerifyLetterIcon from '../../icons/verify-letter.svg'; +import { useEffect, useState } from 'preact/hooks'; + +export function VerificationEmailMessage() { + const [email, setEmail] = useState('..'); + const [error, setError] = useState(''); + const [isLoading, setIsLoading] = useState(false); + const [isEmailResent, setIsEmailResent] = useState(false); + + useEffect(() => { + const urlParams = new URLSearchParams(window.location.search); + + setEmail(urlParams.get('email')!); + }, []); + + const resendVerificationEmail = () => { + fetch(`${import.meta.env.PUBLIC_API_URL}/v1-send-verification-email`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + email, + }), + }) + .then((res) => { + if (!res.ok) { + throw new Error('Something went wrong. Please try again later.'); + } + + setIsEmailResent(true); + }) + .catch(() => { + setIsEmailResent(false); + setIsLoading(false); + setError('Something went wrong. Please try again later.'); + }); + }; + + return ( +
+ Verify Email +

+ Verify your email address +

+
+

+ We have you an email at {email}. + Please click the link to verify your account. This link will expire + shortly, so please verify soon! +

+ +
+ + {!isEmailResent && ( + <> + {isLoading &&

Sending the email ..

} + {!isLoading && !error && ( +

+ Please make sure to check your spam folder. If you still don't + have the email click to{' '} + +

+ )} + + {error &&

{error}

} + + )} + + {isEmailResent &&

Email sent!

} +
+
+ ); +} diff --git a/src/pages/verify.astro b/src/pages/verification-pending.astro similarity index 63% rename from src/pages/verify.astro rename to src/pages/verification-pending.astro index ecdca3ec0..459a7bf09 100644 --- a/src/pages/verify.astro +++ b/src/pages/verification-pending.astro @@ -1,50 +1,26 @@ --- -import Icon from '../components/AstroIcon.astro'; +import AstroIcon from '../components/AstroIcon.astro'; import SettingLayout from '../layouts/SettingLayout.astro'; +import { VerificationEmailMessage } from '../components/RegistrationFlow/VerificationEmailMessage'; --- -
-
- -

- Great, now verify your email -

-
-

- Check your inbox at john@example.com and click the verification link inside to complete your registration. - This link will expire shortly, so verify soon! -

- -
- Don't see an email? Check your spam folder. -
-
- Link expired? - -
-
-
-
+
+