ok
This commit is contained in:
@@ -19,7 +19,7 @@ const LinktreePage = ({ data, setModal }) => {
|
|||||||
const code = queryParams.get('couponCode');
|
const code = queryParams.get('couponCode');
|
||||||
console.log(code)
|
console.log(code)
|
||||||
if (code) {
|
if (code) {
|
||||||
setCouponStatus(200)
|
setCouponStatus(200);
|
||||||
setCouponCode(code);
|
setCouponCode(code);
|
||||||
setIsUsingCoupon(true); // Automatically switch to the coupon input state
|
setIsUsingCoupon(true); // Automatically switch to the coupon input state
|
||||||
handleCheckCoupon(code); // Automatically check the coupon code
|
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 (
|
return (
|
||||||
<div className={styles.linktreePage}>
|
<div className={styles.linktreePage}>
|
||||||
{!isUsingCoupon ? (
|
{!isUsingCoupon ? (
|
||||||
@@ -150,9 +168,9 @@ const LinktreePage = ({ data, setModal }) => {
|
|||||||
className={styles.footerLink}
|
className={styles.footerLink}
|
||||||
>
|
>
|
||||||
Pelajari lebih lanjut
|
Pelajari lebih lanjut
|
||||||
</a><a
|
</a>
|
||||||
|
<a
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
|
||||||
// Get the current URL query parameters
|
// Get the current URL query parameters
|
||||||
const url = new URL(window.location.href);
|
const url = new URL(window.location.href);
|
||||||
|
|
||||||
@@ -162,19 +180,16 @@ const LinktreePage = ({ data, setModal }) => {
|
|||||||
// Update the browser's URL, but keep 'modal=join' intact
|
// Update the browser's URL, but keep 'modal=join' intact
|
||||||
window.history.pushState({}, '', url.toString());
|
window.history.pushState({}, '', url.toString());
|
||||||
|
|
||||||
// Reset the states
|
// Reset the states and force the component to reset
|
||||||
setIsUsingCoupon(couponStatus === 0 ? false : true);
|
setIsUsingCoupon(couponStatus == 0 ? false : true);
|
||||||
setCouponCode('');
|
setCouponCode('');
|
||||||
setCouponDetails(null);
|
setCouponDetails(null);
|
||||||
setCouponStatus(0);
|
setCouponStatus(0);
|
||||||
|
|
||||||
|
|
||||||
}}
|
}}
|
||||||
className={styles.footerLink}
|
className={styles.footerLink}
|
||||||
>
|
>
|
||||||
Kembali
|
Kembali
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.footerImage}>
|
<div className={styles.footerImage}>
|
||||||
<img src="./laporan.png" alt="Linktree visual" />
|
<img src="./laporan.png" alt="Linktree visual" />
|
||||||
|
|||||||
Reference in New Issue
Block a user