diff --git a/src/components/Modal.js b/src/components/Modal.js index bd0161e..0563f18 100644 --- a/src/components/Modal.js +++ b/src/components/Modal.js @@ -104,7 +104,7 @@ const Modal = ({ user, shop, isOpen, onClose, modalContent, setModal, handleMove {modalContent === "create_coupon" && } {modalContent === "check_coupon" && } - {modalContent === "create_user" && } + {modalContent === "create_user" && } ); diff --git a/src/pages/CreateUserWithCoupon.js b/src/pages/CreateUserWithCoupon.js index ddc2f77..c61fd4e 100644 --- a/src/pages/CreateUserWithCoupon.js +++ b/src/pages/CreateUserWithCoupon.js @@ -12,6 +12,11 @@ const LinktreePage = ({ setModal }) => { const [couponCode, setCouponCode] = useState(''); const [couponStatus, setCouponStatus] = useState(''); const [couponDetails, setCouponDetails] = useState(null); + + const [loading, setLoading] = useState(false); + const [error, setError] = useState(false); + const [wasInputtingPassword, setWasInputtingPassword] = useState(false); + const [inputtingPassword, setInputtingPassword] = useState(false); const [username, setUsername] = useState(''); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); @@ -80,54 +85,89 @@ const LinktreePage = ({ setModal }) => { const data = await response.json(); setCouponStatus('User created successfully with coupon'); setCouponDetails(null); - console.log(data); + + localStorage.setItem('auth', data.token); + + // Clean the URL by removing query parameters and hash + const cleanUrl = window.location.origin + window.location.pathname; + + // Replace the current URL with the cleaned one + window.history.replaceState(null, '', cleanUrl); + + // Reload the page with the cleaned URL (no query params or hash) + window.location.reload(); } else { const errorData = await response.json(); setCouponStatus(errorData.message || 'Error creating user'); + setModal('join', { couponCode }) } } catch (error) { setCouponStatus('Error creating user.'); + setModal('join', { couponCode }) } }; return (
-
-
Gunakan Kupon
-
- setUsername(e.target.value)} - className={styles.usernameInput} - /> - setEmail(e.target.value)} - className={styles.usernameInput} - /> - setPassword(e.target.value)} - className={styles.usernameInput} - /> - setRetypePassword(e.target.value)} - className={styles.usernameInput} - /> - -
+
+
Gunakan Kupon
+ +
+
+ + setUsername(e.target.value)} + className={!error ? styles.usernameInput : styles.usernameInputError} + /> + setEmail(e.target.value)} + className={!error ? styles.usernameInput : styles.usernameInputError} + /> + +
+ +
+ + + + + + + setPassword(e.target.value)} + maxLength="30" + className={!error ? styles.usernameInput : styles.usernameInputError} + /> + setRetypePassword(e.target.value)} + maxLength="30" + className={!error ? styles.usernameInput : styles.usernameInputError} + /> + +
+
); }; diff --git a/src/pages/Dashboard.js b/src/pages/Dashboard.js index 5d32462..4c470d8 100644 --- a/src/pages/Dashboard.js +++ b/src/pages/Dashboard.js @@ -17,6 +17,7 @@ const LinktreePage = ({ user, setModal }) => { const location = useLocation(); const [lastModal, setLastModal] = useState(false); + const [wasInputtingPassword, setWasInputtingPassword] = useState(false); const [inputtingPassword, setInputtingPassword] = useState(false); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); @@ -882,7 +883,7 @@ const sortedMaterials = allMaterials.sort((a, b) => new Date(a.date) - new Date( {getLocalStorage('auth') == null && (
-
+
new Date(a.date) - new Date( value={username} onChange={(e) => setUsername(e.target.value)} /> -
-
+
diff --git a/src/pages/Join.js b/src/pages/Join.js index 1e20541..e219a3a 100644 --- a/src/pages/Join.js +++ b/src/pages/Join.js @@ -16,10 +16,10 @@ const LinktreePage = ({ data, setModal }) => { // Detect query params on component mount useEffect(() => { + if(couponCode != '') return; const code = queryParams.get('couponCode'); console.log(code) if (code) { - setCouponStatus(200); setCouponCode(code); setIsUsingCoupon(true); // Automatically switch to the coupon input state handleCheckCoupon(code); // Automatically check the coupon code @@ -144,6 +144,7 @@ const LinktreePage = ({ data, setModal }) => { period={couponDetails?.discountPeriods} expiration={couponDetails?.expirationDate} /> + {couponStatus == 200 &&