fix: Mailchimp signups

Also, inline age check
This commit is contained in:
Sol Irvine 2023-09-06 13:38:48 -07:00
parent 74e7600fc0
commit 8c194a6ca1
2 changed files with 247 additions and 242 deletions

View File

@ -49,8 +49,17 @@ export default function CartModal({
// Always update the quantity reference // Always update the quantity reference
quantityRef.current = cart?.totalQuantity; quantityRef.current = cart?.totalQuantity;
} }
return () => {
setIsConfirming(false);
};
}, [isOpen, cart?.totalQuantity, quantityRef]); }, [isOpen, cart?.totalQuantity, quantityRef]);
const checkoutWithAgeCheck = () => {
setIsOpen(true);
setIsConfirming(true);
};
return ( return (
<> <>
<button aria-label="Open cart" onClick={openCart}> <button aria-label="Open cart" onClick={openCart}>
@ -87,10 +96,19 @@ export default function CartModal({
</button> </button>
</div> </div>
{!!isConfirming && !!cart && cart?.checkoutUrl ? (
<AgeGateForm
didCancel={() => setIsConfirming(false)}
checkoutUrl={cart.checkoutUrl}
/>
) : (
<>
{!cart || cart.lines.length === 0 ? ( {!cart || cart.lines.length === 0 ? (
<div className="mt-20 flex w-full flex-col items-center justify-center overflow-hidden"> <div className="mt-20 flex w-full flex-col items-center justify-center overflow-hidden">
<ShoppingBagIcon className="h-16" strokeWidth={1} /> <ShoppingBagIcon className="h-16" strokeWidth={1} />
<p className="mt-6 text-center font-serif text-xl">Your shopping bag is empty.</p> <p className="mt-6 text-center font-serif text-xl">
Your shopping bag is empty.
</p>
</div> </div>
) : ( ) : (
<div className="flex h-full flex-col justify-between overflow-hidden p-1"> <div className="flex h-full flex-col justify-between overflow-hidden p-1">
@ -198,25 +216,21 @@ export default function CartModal({
<> <>
<button <button
type="button" type="button"
onClick={() => setIsConfirming(true)} onClick={() => checkoutWithAgeCheck()}
className="block w-full border border-white/20 bg-dark px-12 py-6 text-center font-sans font-medium uppercase tracking-wider text-white transition-colors duration-300 hover:bg-white hover:text-black" className="block w-full border border-white/20 bg-dark px-12 py-6 text-center font-sans font-medium uppercase tracking-wider text-white transition-colors duration-300 hover:bg-white hover:text-black"
> >
{t('cart.proceed')} {t('cart.proceed')}
</button> </button>
</> </>
)} )}
{/* <AgeConfirmBeforeCheckout checkoutUrl={cart.checkoutUrl}>
{t('cart.proceed')}
</AgeConfirmBeforeCheckout> */}
</div> </div>
)} )}
</>
)}
</Dialog.Panel> </Dialog.Panel>
</Transition.Child> </Transition.Child>
</Dialog> </Dialog>
</Transition> </Transition>
{!!isConfirming && !!cart && cart?.checkoutUrl && (
<AgeGateForm didCancel={() => setIsConfirming(false)} checkoutUrl={cart.checkoutUrl} />
)}
</> </>
); );
} }

View File

@ -3,7 +3,7 @@
/* This example requires Tailwind CSS v2.0+ */ /* This example requires Tailwind CSS v2.0+ */
import { FC, Fragment, useEffect, useRef, useState, useTransition } from 'react'; import { FC, Fragment, useEffect, useRef, useState, useTransition } from 'react';
import { Dialog, Transition } from '@headlessui/react'; import { Transition } from '@headlessui/react';
import { CheckIcon } from '@heroicons/react/24/outline'; import { CheckIcon } from '@heroicons/react/24/outline';
import { useAgeConfirmation } from 'app/hooks/use-age-confirmation'; import { useAgeConfirmation } from 'app/hooks/use-age-confirmation';
import clsx from 'clsx'; import clsx from 'clsx';
@ -27,7 +27,7 @@ const AgeGateForm: FC<AgeGateFormProps> = ({ checkoutUrl, didCancel }) => {
const { onAgeConfirmed } = useAgeConfirmation(); const { onAgeConfirmed } = useAgeConfirmation();
const yearFieldRef = useRef(null); const yearFieldRef = useRef<HTMLInputElement>(null);
const minAge = 20; const minAge = 20;
const maxAge = 130; const maxAge = 130;
@ -61,21 +61,16 @@ const AgeGateForm: FC<AgeGateFormProps> = ({ checkoutUrl, didCancel }) => {
} }
}, [month, day, year]); }, [month, day, year]);
useEffect(() => {
if (yearFieldRef) {
console.debug('yearFieldRef', yearFieldRef?.current);
yearFieldRef?.current?.focus();
}
}, []);
return ( return (
<> <>
<Transition show={true}> <Transition show={true}>
<Dialog className="relative z-50" initialFocus={yearFieldRef} onClose={() => {}}>
<Transition.Child
as={Fragment}
enter="transition-all ease-in-out duration-300"
enterFrom="opacity-0 backdrop-blur-none"
enterTo="opacity-100 backdrop-blur-[.5px]"
leave="transition-all ease-in-out duration-200"
leaveFrom="opacity-100 backdrop-blur-[.5px]"
leaveTo="opacity-0 backdrop-blur-none"
>
<div className="fixed inset-0 bg-black/70" aria-hidden="true" />
</Transition.Child>
<Transition.Child <Transition.Child
as={Fragment} as={Fragment}
enter="transition-all ease-in-out duration-300" enter="transition-all ease-in-out duration-300"
@ -85,26 +80,22 @@ const AgeGateForm: FC<AgeGateFormProps> = ({ checkoutUrl, didCancel }) => {
leaveFrom="translate-x-0" leaveFrom="translate-x-0"
leaveTo="translate-x-[-100%]" leaveTo="translate-x-[-100%]"
> >
<Dialog.Panel className="fixed inset-0 flex h-full w-full flex-col pb-6"> <div className="grid h-full w-full grid-cols-1 place-content-center">
<div className="grid h-full w-full grid-cols-1 place-content-center p-4"> <div className="mx-auto inline-block space-y-6 overflow-hidden rounded-lg py-12 text-left align-bottom text-white transition-all sm:my-8 sm:w-full sm:max-w-lg sm:p-6 sm:align-middle">
<div className="mx-auto inline-block space-y-6 overflow-hidden rounded-lg bg-white px-4 pb-4 pt-5 text-left align-bottom text-dark shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-lg sm:p-6 sm:align-middle">
<div> <div>
<div className="mx-auto flex h-12 w-12 items-center justify-center rounded-full bg-green-100 dark:bg-green-900"> <div className="mx-auto flex h-12 w-12 items-center justify-center rounded-full bg-green-900">
<CheckIcon <CheckIcon
className="h-6 w-6 text-green-600 dark:text-green-400" className="h-6 w-6 text-green-600 dark:text-green-400"
aria-hidden="true" aria-hidden="true"
/> />
</div> </div>
<div className="text-center sm:mt-5"> <div className="pt-5 text-center">
<Dialog.Title <h3 className="text-lg font-medium leading-6 text-white">
as="h3"
className="text-lg font-medium leading-6 text-dark dark:text-white"
>
{t('age-gate.title')} {t('age-gate.title')}
</Dialog.Title> </h3>
<div className="mt-2"> {/* <div className="mt-2">
<p className="text-sm text-white">{t('age-gate.description')}</p> <p className="text-sm text-white">{t('age-gate.description')}</p>
</div> </div> */}
</div> </div>
</div> </div>
<div> <div>
@ -115,9 +106,10 @@ const AgeGateForm: FC<AgeGateFormProps> = ({ checkoutUrl, didCancel }) => {
<div className="flex flex-col items-start space-y-1"> <div className="flex flex-col items-start space-y-1">
<input <input
type="text" type="text"
className="w-full border bg-white p-2 text-center selection:bg-emerald-200" className="w-full border bg-transparent p-2 text-center text-white selection:bg-emerald-200 focus:ring-offset-0"
ref={yearFieldRef} ref={yearFieldRef}
placeholder="YYYY" placeholder="YYYY"
autoFocus
maxLength={4} maxLength={4}
onChange={(e) => setYear(parseInt(e?.target?.value))} onChange={(e) => setYear(parseInt(e?.target?.value))}
/> />
@ -127,7 +119,7 @@ const AgeGateForm: FC<AgeGateFormProps> = ({ checkoutUrl, didCancel }) => {
<div className="flex flex-col items-start space-y-1"> <div className="flex flex-col items-start space-y-1">
<input <input
type="text" type="text"
className="w-full border bg-white p-2 text-center selection:bg-emerald-200" className="w-full border bg-transparent p-2 text-center text-white selection:bg-emerald-200 focus:ring-offset-0"
placeholder="MM" placeholder="MM"
maxLength={2} maxLength={2}
onChange={(e) => setMonth(parseInt(e?.target?.value))} onChange={(e) => setMonth(parseInt(e?.target?.value))}
@ -137,7 +129,7 @@ const AgeGateForm: FC<AgeGateFormProps> = ({ checkoutUrl, didCancel }) => {
<div className="flex flex-col items-start space-y-1"> <div className="flex flex-col items-start space-y-1">
<input <input
type="text" type="text"
className="w-full border bg-white p-2 text-center selection:bg-emerald-200" className="w-full border bg-transparent p-2 text-center text-white selection:bg-emerald-200 focus:ring-offset-0"
placeholder="DD" placeholder="DD"
maxLength={2} maxLength={2}
onChange={(e) => setDay(parseInt(e?.target?.value))} onChange={(e) => setDay(parseInt(e?.target?.value))}
@ -158,7 +150,7 @@ const AgeGateForm: FC<AgeGateFormProps> = ({ checkoutUrl, didCancel }) => {
'text-base font-medium text-black', 'text-base font-medium text-black',
'shadow-sm transition-colors duration-300', 'shadow-sm transition-colors duration-300',
'focus:outline-none focus:ring-2 focus:ring-white focus:ring-offset-2', 'focus:outline-none focus:ring-2 focus:ring-white focus:ring-offset-2',
'disabled:cursor-not-allowed disabled:opacity-50', 'disabled:cursor-not-allowed disabled:opacity-10',
'disabled:border-dark/50 disabled:hover:border-dark/50', 'disabled:border-dark/50 disabled:hover:border-dark/50',
'sm:col-start-2 sm:text-sm' 'sm:col-start-2 sm:text-sm'
)} )}
@ -171,13 +163,14 @@ const AgeGateForm: FC<AgeGateFormProps> = ({ checkoutUrl, didCancel }) => {
type="button" type="button"
className={clsx( className={clsx(
'mt-3 inline-flex w-full justify-center', 'mt-3 inline-flex w-full justify-center',
'border border-dark/50 hover:border-dark/20', 'border border-dark/10 hover:border-dark/30',
'bg-white px-4 py-2', 'bg-white/50 px-4 py-2',
'text-base font-medium', 'text-base font-medium',
'text-black shadow-sm transition-all duration-300 hover:bg-white hover:bg-opacity-20', 'text-black shadow-sm transition-all duration-300 hover:bg-white hover:bg-opacity-20',
'focus:outline-none focus:ring-2 focus:ring-green-500 focus:ring-offset-2', 'focus:outline-none focus:ring-2 focus:ring-green-500 focus:ring-offset-2',
'sm:col-start-1 sm:mt-0 sm:text-sm', 'sm:col-start-1 sm:mt-0 sm:text-sm',
'disabled:border-dark/50 disabled:hover:border-dark/50' 'disabled:border-dark/20 disabled:hover:border-dark/20',
'disabled:text-dark/30 disabled:hover:text-dark/30'
)} )}
onClick={() => cancel()} onClick={() => cancel()}
disabled={isPending} disabled={isPending}
@ -187,9 +180,7 @@ const AgeGateForm: FC<AgeGateFormProps> = ({ checkoutUrl, didCancel }) => {
</div> </div>
</div> </div>
</div> </div>
</Dialog.Panel>
</Transition.Child> </Transition.Child>
</Dialog>
</Transition> </Transition>
</> </>
); );