From 02ab16d2660fa2520af0b6975d8f0a09e7773df1 Mon Sep 17 00:00:00 2001 From: Sol Irvine Date: Wed, 6 Sep 2023 12:27:16 -0700 Subject: [PATCH] fix: Age gate --- components/cart/modal.tsx | 35 +++- components/product/age-gate-form.tsx | 254 +++++++++++++-------------- 2 files changed, 152 insertions(+), 137 deletions(-) diff --git a/components/cart/modal.tsx b/components/cart/modal.tsx index d1b34ecfb..a8c8db8bd 100644 --- a/components/cart/modal.tsx +++ b/components/cart/modal.tsx @@ -2,7 +2,9 @@ import { Dialog, Transition } from '@headlessui/react'; import { ShoppingBagIcon } from '@heroicons/react/24/outline'; +import { useAgeConfirmation } from 'app/hooks/use-age-confirmation'; import Price from 'components/price'; +import AgeGateForm from 'components/product/age-gate-form'; import { DEFAULT_OPTION } from 'lib/constants'; import type { Cart, Product } from 'lib/shopify/types'; import { createUrl } from 'lib/utils'; @@ -10,7 +12,6 @@ import { useTranslations } from 'next-intl'; import Image from 'next/image'; import Link from 'next/link'; import { Fragment, useEffect, useRef, useState } from 'react'; -import AgeConfirmBeforeCheckout from './age-gate-confirm-before-checkout'; import CloseCart from './close-cart'; import DeleteItemButton from './delete-item-button'; import EditItemQuantityButton from './edit-item-quantity-button'; @@ -29,7 +30,10 @@ export default function CartModal({ promotedItem?: Product; }) { const t = useTranslations('Index'); - const [isOpen, setIsOpen] = useState(false); + const [isOpen, setIsOpen] = useState(false); + const [isConfirming, setIsConfirming] = useState(false); + const { ageConfirmed } = useAgeConfirmation(); + const quantityRef = useRef(cart?.totalQuantity); const openCart = () => setIsOpen(true); const closeCart = () => setIsOpen(false); @@ -181,15 +185,38 @@ export default function CartModal({ /> - + {ageConfirmed ? ( + <> + + {t('cart.proceed')} + + + ) : ( + <> + + + )} + {/* {t('cart.proceed')} - + */} )} + {!!isConfirming && !!cart && cart?.checkoutUrl && ( + setIsConfirming(false)} checkoutUrl={cart.checkoutUrl} /> + )} ); } diff --git a/components/product/age-gate-form.tsx b/components/product/age-gate-form.tsx index 321f6bc4e..3c75b60b2 100644 --- a/components/product/age-gate-form.tsx +++ b/components/product/age-gate-form.tsx @@ -63,146 +63,134 @@ const AgeGateForm: FC = ({ checkoutUrl, didCancel }) => { return ( <> - - {}} - > -
+ {}}> + - - - - - {/* This element is to trick the browser into centering the modal contents. */} - - -
-
-
-
- + ); };