Enable captcha and refactor popup

astro
Kamran Ahmed 2 years ago
parent 577613132b
commit d7b201c7f7
  1. 1
      package.json
  2. 2
      src/components/Captcha/captcha.js
  3. 2
      src/components/DownloadPopup.astro
  4. 8
      src/components/Popup/Popup.astro
  5. 50
      src/components/Popup/popup.js
  6. 4
      src/components/RoadmapHeader.astro
  7. 2
      src/components/SubscribePopup.astro
  8. 2
      src/pages/signup.astro

@ -5,6 +5,7 @@
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "astro dev", "dev": "astro dev",
"dev:verbose": "astro dev --verbose",
"start": "astro dev", "start": "astro dev",
"build": "astro build", "build": "astro build",
"preview": "astro preview", "preview": "astro preview",

@ -25,7 +25,7 @@ class Captcha {
target.querySelector('.recaptcha-response').value = captchaResponse; target.querySelector('.recaptcha-response').value = captchaResponse;
} }
target.closest('.modal').classList.add('hidden'); target.closest('.popup').classList.add('hidden');
return true; return true;
} }

@ -25,7 +25,7 @@ import Captcha from './Captcha/Captcha.astro';
placeholder='Enter your Email' placeholder='Enter your Email'
/> />
<!-- <Captcha /> --> <Captcha />
<input type='hidden' name='list' value='tTqz1w7nexY3cWDpLnI88Q' /> <input type='hidden' name='list' value='tTqz1w7nexY3cWDpLnI88Q' />
<input type='hidden' name='subform' value='yes' /> <input type='hidden' name='subform' value='yes' />

@ -15,17 +15,17 @@ const { id, title, subtitle } = Astro.props;
<div <div
id={id} id={id}
tabindex='-1' tabindex='-1'
class='hidden bg-black/50 overflow-y-auto overflow-x-hidden fixed top-0 right-0 left-0 z-50 h-full flex items-center justify-center modal' class='hidden bg-black/50 overflow-y-auto overflow-x-hidden fixed top-0 right-0 left-0 z-50 h-full items-center justify-center popup'
> >
<div class='relative p-4 w-full max-w-md h-full md:h-auto'> <div class='relative p-4 w-full max-w-md h-full md:h-auto'>
<div class='relative bg-white rounded-lg shadow modal-body'> <div class='relative bg-white rounded-lg shadow popup-body'>
<button <button
type='button' type='button'
class='absolute top-3 right-2.5 text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm p-1.5 ml-auto inline-flex items-center' class='absolute top-3 right-2.5 text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm p-1.5 ml-auto inline-flex items-center'
onclick='this.closest(".modal").classList.add("hidden")' onclick='this.closest(".popup").classList.add("hidden")'
> >
<Icon icon='close' /> <Icon icon='close' />
<span class='sr-only'>Close modal</span> <span class='sr-only'>Close popup</span>
</button> </button>
<div class='p-5'> <div class='p-5'>
<h3 class='text-2xl mb-0.5 font-medium'> <h3 class='text-2xl mb-0.5 font-medium'>

@ -1,41 +1,44 @@
export class Modal { export class Popup {
constructor() { constructor() {
this.triggerModal = this.triggerModal.bind(this); this.triggerPopup = this.triggerPopup.bind(this);
this.onDOMLoaded = this.onDOMLoaded.bind(this); this.onDOMLoaded = this.onDOMLoaded.bind(this);
this.handleCloseModal = this.handleCloseModal.bind(this); this.handleClosePopup = this.handleClosePopup.bind(this);
this.handleKeydown = this.handleKeydown.bind(this); this.handleKeydown = this.handleKeydown.bind(this);
} }
/** /**
* Triggers the modal on target elements * Triggers the popup on target elements
* @param {Event} e * @param {Event} e
*/ */
triggerModal(e) { triggerPopup(e) {
const modalToShow = e?.target?.closest('[data-modal]')?.dataset?.modal || 'unknown-modal'; const popupToShow =
const modalEl = document.querySelector(`#${modalToShow}`); e?.target?.closest('[data-popup]')?.dataset?.popup || 'unknown-popup';
const popupEl = document.querySelector(`#${popupToShow}`);
if (!modalEl) { if (!popupEl) {
return; return;
} }
modalEl.classList.remove('hidden'); popupEl.classList.remove('hidden');
const focusEl = modalEl.querySelector('[autofocus]'); popupEl.classList.add('flex');
const focusEl = popupEl.querySelector('[autofocus]');
if (focusEl) { if (focusEl) {
focusEl.focus(); focusEl.focus();
} }
} }
handleCloseModal(e) { handleClosePopup(e) {
const target = e.target; const target = e.target;
const modalBody = target.closest('.modal-body'); const popupBody = target.closest('.popup-body');
const closestModal = target.closest('.modal'); const closestPopup = target.closest('.popup');
if (modalBody) { if (popupBody) {
return; return;
} }
if (closestModal) { if (closestPopup) {
closestModal.classList.add('hidden'); closestPopup.classList.add('hidden');
closestPopup.classList.remove('flex');
} }
} }
@ -44,15 +47,16 @@ export class Modal {
return; return;
} }
const modal = document.querySelector('.modal:not(.hidden)'); const popup = document.querySelector('.popup:not(.hidden)');
if (modal) { if (popup) {
modal.classList.add('hidden'); popup.classList.add('hidden');
popup.classList.remove('flex');
} }
} }
onDOMLoaded() { onDOMLoaded() {
document.addEventListener('click', this.triggerModal); document.addEventListener('click', this.triggerPopup);
document.addEventListener('click', this.handleCloseModal); document.addEventListener('click', this.handleClosePopup);
document.addEventListener('keydown', this.handleKeydown); document.addEventListener('keydown', this.handleKeydown);
} }
@ -61,5 +65,5 @@ export class Modal {
} }
} }
const modalRef = new Modal(); const popupRef = new Popup();
modalRef.init(); popupRef.init();

@ -48,7 +48,7 @@ const isRoadmapReady = !isUpcoming;
{isRoadmapReady && ( {isRoadmapReady && (
<button <button
data-modal="download-popup" data-popup="download-popup"
class="inline-flex items-center justify-center bg-yellow-400 py-1.5 px-3 text-xs sm:text-sm font-medium rounded-md hover:bg-yellow-500" class="inline-flex items-center justify-center bg-yellow-400 py-1.5 px-3 text-xs sm:text-sm font-medium rounded-md hover:bg-yellow-500"
aria-label="Download Roadmap" aria-label="Download Roadmap"
> >
@ -58,7 +58,7 @@ const isRoadmapReady = !isUpcoming;
)} )}
<button <button
data-modal="subscribe-popup" data-popup="subscribe-popup"
class="inline-flex items-center justify-center bg-yellow-400 py-1.5 px-3 text-xs sm:text-sm font-medium rounded-md hover:bg-yellow-500" class="inline-flex items-center justify-center bg-yellow-400 py-1.5 px-3 text-xs sm:text-sm font-medium rounded-md hover:bg-yellow-500"
aria-label="Subscribe for Updates" aria-label="Subscribe for Updates"
> >

@ -24,7 +24,7 @@ import Captcha from './Captcha/Captcha.astro';
placeholder='Enter your Email' placeholder='Enter your Email'
/> />
<!-- <Captcha /> --> <Captcha />
<input type='hidden' name='list' value='tTqz1w7nexY3cWDpLnI88Q' /> <input type='hidden' name='list' value='tTqz1w7nexY3cWDpLnI88Q' />
<input type='hidden' name='subform' value='yes' /> <input type='hidden' name='subform' value='yes' />

@ -36,7 +36,7 @@ import BaseLayout from '../layouts/BaseLayout.astro';
placeholder='Enter your email' placeholder='Enter your email'
/> />
<!-- <Captcha /> --> <Captcha />
<input type='hidden' name='list' value='tTqz1w7nexY3cWDpLnI88Q' /> <input type='hidden' name='list' value='tTqz1w7nexY3cWDpLnI88Q' />
<input type='hidden' name='subform' value='yes' /> <input type='hidden' name='subform' value='yes' />

Loading…
Cancel
Save