diff --git a/src/pages/Join.js b/src/pages/Join.js index 7e29b98..1e20541 100644 --- a/src/pages/Join.js +++ b/src/pages/Join.js @@ -19,7 +19,7 @@ const LinktreePage = ({ data, setModal }) => { const code = queryParams.get('couponCode'); console.log(code) if (code) { - setCouponStatus(200) + setCouponStatus(200); setCouponCode(code); setIsUsingCoupon(true); // Automatically switch to the coupon input state handleCheckCoupon(code); // Automatically check the coupon code @@ -51,6 +51,24 @@ const LinktreePage = ({ data, setModal }) => { } }; + // Listen for query parameter changes (using the `location` object) + useEffect(() => { + const handlePopState = () => { + const newQueryParams = new URLSearchParams(window.location.search); + const newCouponCode = newQueryParams.get('couponCode'); + if (!newCouponCode) { + setIsUsingCoupon(false); + setCouponCode(''); + setCouponDetails(null); + setCouponStatus(0); + } + }; + window.addEventListener('popstate', handlePopState); + return () => { + window.removeEventListener('popstate', handlePopState); + }; + }, []); + return (