ok
This commit is contained in:
@@ -3,37 +3,37 @@ import styles from './Join.module.css';
|
||||
import Coupon from '../components/Coupon';
|
||||
|
||||
import CryptoJS from 'crypto-js';
|
||||
import {createCoupon} from "../helpers/couponHelpers.js"
|
||||
import { createCoupon } from "../helpers/couponHelpers.js"
|
||||
|
||||
function getAuthToken() {
|
||||
return localStorage.getItem("auth");
|
||||
}
|
||||
return localStorage.getItem("auth");
|
||||
}
|
||||
const CreateCouponPage = () => {
|
||||
const [discountType, setDiscountType] = useState("percentage");
|
||||
const [discountValue, setDiscountValue] = useState("");
|
||||
const [discountPeriods, setDiscountPeriods] = 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('');
|
||||
const [retypePassword, setRetypePassword] = useState('');
|
||||
const [codeExpectation, setCodeExpectation] = useState('');
|
||||
const [couponUrl, setCouponUrl] = useState('');
|
||||
|
||||
|
||||
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('');
|
||||
const [retypePassword, setRetypePassword] = useState('');
|
||||
const [codeExpectation, setCodeExpectation] = useState('');
|
||||
const [couponUrl, setCouponUrl] = useState('');
|
||||
|
||||
|
||||
const handleSubmit = async (e) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
|
||||
|
||||
// Call the helper function to create the coupon
|
||||
const result = await createCoupon(discountType, discountValue, discountPeriods, codeExpectation);
|
||||
|
||||
|
||||
if (result.success) {
|
||||
setCouponDetails(result.coupon);
|
||||
const secretKey = 'xixixi666'; // Your AES-256 key (32 characters)
|
||||
@@ -57,87 +57,88 @@ const CreateCouponPage = () => {
|
||||
</div>
|
||||
|
||||
{couponDetails != null ?
|
||||
<>
|
||||
<Coupon
|
||||
code={couponDetails?.code || null}
|
||||
value={couponDetails?.discountValue}
|
||||
period={couponDetails?.discountPeriods}
|
||||
type={couponDetails?.type}
|
||||
expiration={couponDetails?.expirationDate}
|
||||
/>
|
||||
<button
|
||||
onClick={() => {
|
||||
navigator.clipboard.writeText('https://dev.coupon.kedaimaster.com/coupon?c=' + couponUrl)
|
||||
.then(() => {
|
||||
// Optional: Show a message that the text has been copied
|
||||
alert("Coupon URL copied to clipboard!");
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("Failed to copy text: ", err);
|
||||
});
|
||||
}}
|
||||
className={styles.claimButton}
|
||||
style={{marginBottom: '10px'}}
|
||||
>
|
||||
<span>Salin URL VOUCHER</span>
|
||||
</button></>
|
||||
<>
|
||||
<Coupon
|
||||
code={couponDetails?.code || null}
|
||||
value={couponDetails?.discountValue}
|
||||
period={couponDetails?.discountPeriods}
|
||||
type={couponDetails?.type}
|
||||
expiration={couponDetails?.expirationDate}
|
||||
/>
|
||||
<button
|
||||
onClick={() => {
|
||||
navigator.clipboard.writeText('https://dev.coupon.kedaimaster.com/coupon?c=' + couponUrl)
|
||||
.then(() => {
|
||||
// Optional: Show a message that the text has been copied
|
||||
alert("Coupon URL copied to clipboard!");
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("Failed to copy text: ", err);
|
||||
});
|
||||
}}
|
||||
className={styles.claimButton}
|
||||
style={{ marginBottom: '10px' }}
|
||||
>
|
||||
<span>Salin URL VOUCHER</span>
|
||||
</button></>
|
||||
|
||||
:
|
||||
<div className={styles.LoginForm}>
|
||||
<div className={`${styles.FormUsername} ${inputtingPassword ? styles.animateForm : wasInputtingPassword ? styles.reverseForm : ''}`}>
|
||||
<label htmlFor="username" className={styles.usernameLabel}>---- Daftar -------------------------------</label>
|
||||
<select
|
||||
className={!error ? styles.usernameInput : styles.usernameInputError}
|
||||
value={discountType}
|
||||
onChange={(e) => setDiscountType(e.target.value)}
|
||||
>
|
||||
<option value="percentage">Percentage</option>
|
||||
<option value="fixed">Fixed</option>
|
||||
</select>
|
||||
|
||||
<input
|
||||
type="number"
|
||||
placeholder="Nilai voucher"
|
||||
value={discountValue}
|
||||
onChange={(e) => setDiscountValue(e.target.value)}
|
||||
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
|
||||
type="number"
|
||||
placeholder="Periode diskon (minggu)"
|
||||
value={discountPeriods}
|
||||
onChange={(e) => setDiscountPeriods(e.target.value)}
|
||||
maxLength="30"
|
||||
className={!error ? styles.usernameInput : styles.usernameInputError}
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Ekspektasi kode"
|
||||
value={codeExpectation}
|
||||
onChange={(e) => setCodeExpectation(e.target.value)}
|
||||
maxLength="30"
|
||||
className={!error ? styles.usernameInput : styles.usernameInputError}
|
||||
/>
|
||||
<button
|
||||
onClick={handleSubmit}
|
||||
className={`${styles.claimButton} ${loading ? styles.loading : ''}`}
|
||||
disabled={loading}
|
||||
>
|
||||
<span>{loading ? 'Loading...' : 'Buat'}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
:
|
||||
<div className={styles.LoginForm}>
|
||||
<div className={`${styles.FormUsername} ${inputtingPassword ? styles.animateForm : wasInputtingPassword ? styles.reverseForm : ''}`}>
|
||||
<label htmlFor="username" className={styles.usernameLabel}>----------------------------------------------</label>
|
||||
<select
|
||||
className={!error ? styles.usernameInput : styles.usernameInputError}
|
||||
value={discountType}
|
||||
onChange={(e) => setDiscountType(e.target.value)}
|
||||
style={{width: '100%'}}
|
||||
>
|
||||
<option value="percentage">Percentage</option>
|
||||
<option value="fixed">Fixed</option>
|
||||
</select>
|
||||
|
||||
<input
|
||||
type="number"
|
||||
placeholder="Nilai voucher"
|
||||
value={discountValue}
|
||||
onChange={(e) => setDiscountValue(e.target.value)}
|
||||
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
|
||||
type="number"
|
||||
placeholder="Periode diskon (minggu)"
|
||||
value={discountPeriods}
|
||||
onChange={(e) => setDiscountPeriods(e.target.value)}
|
||||
maxLength="30"
|
||||
className={!error ? styles.usernameInput : styles.usernameInputError}
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Ekspektasi kode"
|
||||
value={codeExpectation}
|
||||
onChange={(e) => setCodeExpectation(e.target.value)}
|
||||
maxLength="30"
|
||||
className={!error ? styles.usernameInput : styles.usernameInputError}
|
||||
/>
|
||||
<button
|
||||
onClick={handleSubmit}
|
||||
className={`${styles.claimButton} ${loading ? styles.loading : ''}`}
|
||||
disabled={loading}
|
||||
>
|
||||
<span>{loading ? 'Loading...' : 'Buat'}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -387,7 +387,7 @@ const App = ({ forCafe = true, cafeId = -1,
|
||||
if (selectedItem) {
|
||||
setSelectedCafeId(selectedItem[1]); // Get the cafeId (second part of the pair)
|
||||
}
|
||||
if(selectedItem[1] == -1 && user.roleId == 0) setModal('create_coupon',{},setSelectedCafeId(0));
|
||||
if(selectedItem[1] == -1 && user.roleId == 0) setModal('create_coupon', {}, () => {setSelectedSwitch(0);setSelectedCafeId(0)});
|
||||
|
||||
setResetKey((prevKey) => prevKey + 1); // Increase the key to force re-render
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user