ok
This commit is contained in:
@@ -104,7 +104,7 @@ const Modal = ({ user, shop, isOpen, onClose, modalContent, setModal, handleMove
|
|||||||
|
|
||||||
{modalContent === "create_coupon" && <CreateCoupon />}
|
{modalContent === "create_coupon" && <CreateCoupon />}
|
||||||
{modalContent === "check_coupon" && <CheckCoupon />}
|
{modalContent === "check_coupon" && <CheckCoupon />}
|
||||||
{modalContent === "create_user" && <CreateUserWithCoupon />}
|
{modalContent === "create_user" && <CreateUserWithCoupon setModal={setModal}/>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -12,6 +12,11 @@ const LinktreePage = ({ setModal }) => {
|
|||||||
const [couponCode, setCouponCode] = useState('');
|
const [couponCode, setCouponCode] = useState('');
|
||||||
const [couponStatus, setCouponStatus] = useState('');
|
const [couponStatus, setCouponStatus] = useState('');
|
||||||
const [couponDetails, setCouponDetails] = useState(null);
|
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 [username, setUsername] = useState('');
|
||||||
const [email, setEmail] = useState('');
|
const [email, setEmail] = useState('');
|
||||||
const [password, setPassword] = useState('');
|
const [password, setPassword] = useState('');
|
||||||
@@ -80,13 +85,25 @@ const LinktreePage = ({ setModal }) => {
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
setCouponStatus('User created successfully with coupon');
|
setCouponStatus('User created successfully with coupon');
|
||||||
setCouponDetails(null);
|
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 {
|
} else {
|
||||||
const errorData = await response.json();
|
const errorData = await response.json();
|
||||||
setCouponStatus(errorData.message || 'Error creating user');
|
setCouponStatus(errorData.message || 'Error creating user');
|
||||||
|
setModal('join', { couponCode })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setCouponStatus('Error creating user.');
|
setCouponStatus('Error creating user.');
|
||||||
|
setModal('join', { couponCode })
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -94,39 +111,62 @@ const LinktreePage = ({ setModal }) => {
|
|||||||
<div className={styles.linktreePage}>
|
<div className={styles.linktreePage}>
|
||||||
<div className={styles.dashboardContainer}>
|
<div className={styles.dashboardContainer}>
|
||||||
<div className={styles.mainHeading}>Gunakan Kupon</div>
|
<div className={styles.mainHeading}>Gunakan Kupon</div>
|
||||||
<form className={styles.linktreeForm} onSubmit={handleCreateUserWithCoupon}>
|
|
||||||
|
<div className={styles.LoginForm}>
|
||||||
|
<div className={`${styles.FormUsername} ${inputtingPassword ? styles.animateForm : wasInputtingPassword ? styles.reverseForm : ''}`}>
|
||||||
|
<label htmlFor="username" className={styles.usernameLabel}>---- masuk -------------------------------</label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Username"
|
placeholder="Username"
|
||||||
|
maxLength="30"
|
||||||
value={username}
|
value={username}
|
||||||
onChange={(e) => setUsername(e.target.value)}
|
onChange={(e) => setUsername(e.target.value)}
|
||||||
className={styles.usernameInput}
|
className={!error ? styles.usernameInput : styles.usernameInputError}
|
||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
type="email"
|
type="email"
|
||||||
placeholder="Email"
|
placeholder="Email"
|
||||||
value={email}
|
value={email}
|
||||||
onChange={(e) => setEmail(e.target.value)}
|
onChange={(e) => setEmail(e.target.value)}
|
||||||
className={styles.usernameInput}
|
className={!error ? styles.usernameInput : styles.usernameInputError}
|
||||||
/>
|
/>
|
||||||
|
<button onClick={() => { setInputtingPassword(true); setWasInputtingPassword(true) }} className={styles.claimButton}>
|
||||||
|
<span>➜</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={`${styles.FormPassword} ${inputtingPassword ? styles.animateForm : wasInputtingPassword ? styles.reverseForm : ''}`}>
|
||||||
|
<span>
|
||||||
|
<label onClick={() => setInputtingPassword(false)} htmlFor="password" className={styles.usernameLabel}> <--- <-- kembali </label>
|
||||||
|
<label htmlFor="password" className={styles.usernameLabel}> ----------------- </label>
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
<input
|
<input
|
||||||
type="password"
|
type="password"
|
||||||
placeholder="Password"
|
placeholder="Password"
|
||||||
value={password}
|
value={password}
|
||||||
onChange={(e) => setPassword(e.target.value)}
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
className={styles.usernameInput}
|
maxLength="30"
|
||||||
|
className={!error ? styles.usernameInput : styles.usernameInputError}
|
||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
type="password"
|
type="password"
|
||||||
placeholder="Re-type Password"
|
placeholder="Re-type Password"
|
||||||
value={retypePassword}
|
value={retypePassword}
|
||||||
onChange={(e) => setRetypePassword(e.target.value)}
|
onChange={(e) => setRetypePassword(e.target.value)}
|
||||||
className={styles.usernameInput}
|
maxLength="30"
|
||||||
|
className={!error ? styles.usernameInput : styles.usernameInputError}
|
||||||
/>
|
/>
|
||||||
<button type="submit" className={styles.claimButton}>
|
<button
|
||||||
<span>Buat Akun</span>
|
onClick={handleCreateUserWithCoupon}
|
||||||
|
className={`${styles.claimButton} ${loading ? styles.loading : ''}`}
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
|
<span>{loading ? 'Loading...' : 'Masuk'}</span>
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ const LinktreePage = ({ user, setModal }) => {
|
|||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const [lastModal, setLastModal] = useState(false);
|
const [lastModal, setLastModal] = useState(false);
|
||||||
|
|
||||||
|
const [wasInputtingPassword, setWasInputtingPassword] = useState(false);
|
||||||
const [inputtingPassword, setInputtingPassword] = useState(false);
|
const [inputtingPassword, setInputtingPassword] = useState(false);
|
||||||
const [username, setUsername] = useState('');
|
const [username, setUsername] = useState('');
|
||||||
const [password, setPassword] = useState('');
|
const [password, setPassword] = useState('');
|
||||||
@@ -882,7 +883,7 @@ const sortedMaterials = allMaterials.sort((a, b) => new Date(a.date) - new Date(
|
|||||||
|
|
||||||
{getLocalStorage('auth') == null && (
|
{getLocalStorage('auth') == null && (
|
||||||
<div className={styles.LoginForm}>
|
<div className={styles.LoginForm}>
|
||||||
<div className={`${styles.FormUsername} ${inputtingPassword ? styles.animateForm : styles.reverseForm}`}>
|
<div className={`${styles.FormUsername} ${inputtingPassword ? styles.animateForm : wasInputtingPassword? styles.reverseForm : ''}`}>
|
||||||
<label htmlFor="username" className={styles.usernameLabel}>---- masuk -------------------------------</label>
|
<label htmlFor="username" className={styles.usernameLabel}>---- masuk -------------------------------</label>
|
||||||
<input
|
<input
|
||||||
id="username"
|
id="username"
|
||||||
@@ -892,12 +893,12 @@ const sortedMaterials = allMaterials.sort((a, b) => new Date(a.date) - new Date(
|
|||||||
value={username}
|
value={username}
|
||||||
onChange={(e) => setUsername(e.target.value)}
|
onChange={(e) => setUsername(e.target.value)}
|
||||||
/>
|
/>
|
||||||
<button onClick={() => setInputtingPassword(true)} className={styles.claimButton}>
|
<button onClick={() => {setInputtingPassword(true); setWasInputtingPassword(true)}} className={styles.claimButton}>
|
||||||
<span>➜</span>
|
<span>➜</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={`${styles.FormPassword} ${inputtingPassword ? styles.animateForm : styles.reverseForm}`}>
|
<div className={`${styles.FormPassword} ${inputtingPassword ? styles.animateForm : wasInputtingPassword? styles.reverseForm : ''}`}>
|
||||||
<span>
|
<span>
|
||||||
<label onClick={() => setInputtingPassword(false)} htmlFor="password" className={styles.usernameLabel}> <--- <-- kembali </label>
|
<label onClick={() => setInputtingPassword(false)} htmlFor="password" className={styles.usernameLabel}> <--- <-- kembali </label>
|
||||||
<label htmlFor="password" className={styles.usernameLabel}> ----- </label>
|
<label htmlFor="password" className={styles.usernameLabel}> ----- </label>
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ const LinktreePage = ({ data, setModal }) => {
|
|||||||
|
|
||||||
// Detect query params on component mount
|
// Detect query params on component mount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if(couponCode != '') return;
|
||||||
const code = queryParams.get('couponCode');
|
const code = queryParams.get('couponCode');
|
||||||
console.log(code)
|
console.log(code)
|
||||||
if (code) {
|
if (code) {
|
||||||
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
|
||||||
@@ -144,6 +144,7 @@ const LinktreePage = ({ data, setModal }) => {
|
|||||||
period={couponDetails?.discountPeriods}
|
period={couponDetails?.discountPeriods}
|
||||||
expiration={couponDetails?.expirationDate}
|
expiration={couponDetails?.expirationDate}
|
||||||
/>
|
/>
|
||||||
|
{couponStatus == 200 &&
|
||||||
<form className={styles.linktreeForm}>
|
<form className={styles.linktreeForm}>
|
||||||
<label htmlFor="username" className={styles.usernameLabel}>
|
<label htmlFor="username" className={styles.usernameLabel}>
|
||||||
--------------------------------------------
|
--------------------------------------------
|
||||||
@@ -157,6 +158,7 @@ const LinktreePage = ({ data, setModal }) => {
|
|||||||
<span>Buat akun dengan kupon ini</span>
|
<span>Buat akun dengan kupon ini</span>
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
<div className={styles.footer}>
|
<div className={styles.footer}>
|
||||||
@@ -176,6 +178,7 @@ const LinktreePage = ({ data, setModal }) => {
|
|||||||
|
|
||||||
// Remove the couponCode query parameter
|
// Remove the couponCode query parameter
|
||||||
url.searchParams.delete('couponCode');
|
url.searchParams.delete('couponCode');
|
||||||
|
url.searchParams.delete('codeStatus');
|
||||||
|
|
||||||
// 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());
|
||||||
|
|||||||
@@ -233,8 +233,13 @@
|
|||||||
left: 0vw;
|
left: 0vw;
|
||||||
}
|
}
|
||||||
|
|
||||||
100% {
|
99.9% {
|
||||||
left: 100vw;
|
left: 100vw;
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
left: 0vw;
|
||||||
|
visibility: hidden;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user