This commit is contained in:
insvrgent
2025-02-20 12:02:35 +07:00
parent 076522a6c7
commit f1247dd11c
3 changed files with 46 additions and 33 deletions

View File

@@ -30,23 +30,34 @@ const CreateCouponPage = () => {
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)
// Encrypt couponCode inline
const secretKey = 'xixixi666'; // AES-256 key (32 characters)
// Encrypt the coupon code inline
const encryptedCouponCode = CryptoJS.AES.encrypt(result.coupon.code, secretKey).toString();
setCouponUrl(encryptedCouponCode)
console.log(encryptedCouponCode)
// Convert the encrypted code to Base64 URL-safe encoding
const base64UrlSafe = encryptedCouponCode.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
// Store the Base64 URL-safe encrypted coupon code in the query parameter
const encodedCouponCode = encodeURIComponent(base64UrlSafe); // Ensure it's safely encoded for URL use
const urlWithCoupon = `https://dev.coupon.kedaimaster.com/coupon?c=${encodedCouponCode}`;
// Optionally, set the URL to use with the coupon
setCouponUrl(urlWithCoupon);
console.log(urlWithCoupon);
setLoading(false);
} else {
setLoading(false);
}
};
return (
<div className={styles.linktreePage}>
@@ -67,7 +78,7 @@ const CreateCouponPage = () => {
/>
<button
onClick={() => {
navigator.clipboard.writeText('https://dev.coupon.kedaimaster.com/coupon?c=' + couponUrl)
navigator.clipboard.writeText(couponUrl)
.then(() => {
// Optional: Show a message that the text has been copied
alert("Coupon URL copied to clipboard!");