ok
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
"name": "groovebrew-mockup",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"homepage": "https://kedaimaster.com",
|
||||
"homepage": "https://dev.kedaimaster.com",
|
||||
"dependencies": {
|
||||
"@emotion/react": "^11.13.3",
|
||||
"@emotion/styled": "^11.13.0",
|
||||
|
||||
@@ -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!");
|
||||
|
||||
@@ -19,45 +19,47 @@ const LinktreePage = ({ data, setModal }) => {
|
||||
const [couponDetails, setCouponDetails] = useState(null);
|
||||
|
||||
// Detect query params on component mount
|
||||
|
||||
useEffect(() => {
|
||||
if (couponCode !== '') return;
|
||||
if (couponCode !== '') return; // Prevent repeated code
|
||||
|
||||
const modal = queryParams.get('modal');
|
||||
const code = queryParams.get('c');
|
||||
|
||||
console.log(code)
|
||||
if (modal == 'claim-coupon') {
|
||||
const encryptedCode = queryParams.get('c'); // Encrypted coupon code in query
|
||||
|
||||
console.log(encryptedCode);
|
||||
|
||||
if (modal === 'claim-coupon') {
|
||||
if (!getLocalStorage('auth')) {
|
||||
|
||||
// Preserve the couponCode query param while navigating to the claim-coupon modal
|
||||
if(code) setModal('join', {c: code})
|
||||
else setModal('join')
|
||||
if (encryptedCode) setModal('join', { c: encryptedCode });
|
||||
else setModal('join');
|
||||
}
|
||||
|
||||
setIsOnlyClaimCoupon(true)
|
||||
|
||||
setIsOnlyClaimCoupon(true);
|
||||
setIsUsingCoupon(true); // Automatically switch to the coupon input state
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (getLocalStorage('auth')) {
|
||||
|
||||
// Preserve the couponCode query param while navigating to the claim-coupon modal
|
||||
if(code) setModal('claim-coupon', {c: code})
|
||||
else setModal('claim-coupon')
|
||||
if (encryptedCode) setModal('claim-coupon', { c: encryptedCode });
|
||||
else setModal('claim-coupon');
|
||||
}
|
||||
}
|
||||
if (code) {
|
||||
// Your AES-256 key (ensure this is kept secret and secure!)
|
||||
|
||||
if (encryptedCode) {
|
||||
// AES-256 key (ensure this is kept secret and secure!)
|
||||
const secretKey = 'xixixi666'; // 32 characters for AES-256
|
||||
|
||||
// Decrypt the couponCode
|
||||
const decryptedBytes = CryptoJS.AES.decrypt(code, secretKey);
|
||||
|
||||
// Decode and decrypt the coupon code
|
||||
const decodedCouponCode = decodeURIComponent(encryptedCode); // Decode the encrypted code from the URL
|
||||
const decryptedBytes = CryptoJS.AES.decrypt(decodedCouponCode, secretKey);
|
||||
const decryptedCode = decryptedBytes.toString(CryptoJS.enc.Utf8);
|
||||
console.log(decryptedCode)
|
||||
|
||||
console.log(decryptedCode);
|
||||
setCouponCode(decryptedCode);
|
||||
setIsUsingCoupon(true); // Automatically switch to the coupon input state
|
||||
handleCheckCoupon(decryptedCode); // Automatically check the coupon code
|
||||
handleCheckCoupon(decryptedCode); // Automatically check the coupon code
|
||||
}
|
||||
}, [queryParams]);
|
||||
|
||||
}, [queryParams]);
|
||||
// Handle manual coupon code check
|
||||
const handleCheckCoupon = async (code = couponCode) => {
|
||||
const result = await checkCoupon(code); // Call the helper
|
||||
|
||||
Reference in New Issue
Block a user