ok
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
"name": "groovebrew-mockup",
|
"name": "groovebrew-mockup",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"homepage": "https://dev.kedaimaster.com",
|
"homepage": "https://kedaimaster.com",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@emotion/react": "^11.13.3",
|
"@emotion/react": "^11.13.3",
|
||||||
"@emotion/styled": "^11.13.0",
|
"@emotion/styled": "^11.13.0",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// src/config.js
|
// src/config.js
|
||||||
|
|
||||||
const API_BASE_URL = 'https://dev.api.kedaimaster.com';
|
const API_BASE_URL = 'https://api.kedaimaster.com';
|
||||||
|
|
||||||
export default API_BASE_URL;
|
export default API_BASE_URL;
|
||||||
|
|||||||
@@ -5,6 +5,11 @@ import App from './App';
|
|||||||
import reportWebVitals from './reportWebVitals';
|
import reportWebVitals from './reportWebVitals';
|
||||||
|
|
||||||
const root = ReactDOM.createRoot(document.getElementById('root'));
|
const root = ReactDOM.createRoot(document.getElementById('root'));
|
||||||
|
// Disable console methods
|
||||||
|
console.log = () => {};
|
||||||
|
console.warn = () => {};
|
||||||
|
console.error = () => {};
|
||||||
|
|
||||||
root.render(
|
root.render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<App />
|
<App />
|
||||||
|
|||||||
@@ -26,31 +26,32 @@ const CreateCouponPage = () => {
|
|||||||
const [codeExpectation, setCodeExpectation] = useState('');
|
const [codeExpectation, setCodeExpectation] = useState('');
|
||||||
const [couponUrl, setCouponUrl] = useState('');
|
const [couponUrl, setCouponUrl] = useState('');
|
||||||
|
|
||||||
|
|
||||||
const handleSubmit = async (e) => {
|
const handleSubmit = async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
// Call the helper function to create the coupon
|
// Call the helper function to create the coupon
|
||||||
const result = await createCoupon(discountType, discountValue, discountPeriods, codeExpectation);
|
const result = await createCoupon(discountType, discountValue, discountPeriods, codeExpectation);
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
setCouponDetails(result.coupon);
|
setCouponDetails(result.coupon);
|
||||||
|
|
||||||
const secretKey = 'xixixi666'; // AES-256 key (32 characters)
|
const secretKey = 'xixixi666'; // AES-256 key (32 characters)
|
||||||
|
|
||||||
// Encrypt the coupon code inline
|
// Encrypt the coupon code inline using CryptoJS
|
||||||
const encryptedCouponCode = CryptoJS.AES.encrypt(result.coupon.code, secretKey).toString();
|
let encryptedCouponCode = CryptoJS.AES.encrypt(result.coupon.code, secretKey).toString().replace('+','LDNWAlASJDNdaw').replace('/','XCLZBKlaWDJ').replace('=','LDSsadANJlas');
|
||||||
|
// Encode the encrypted coupon code for URL usage:
|
||||||
// Convert the encrypted code to Base64 URL-safe encoding
|
// 1. First, encodeURIComponent to handle URL-specific characters.
|
||||||
const base64UrlSafe = encryptedCouponCode.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
// 2. Then, replace special characters like '+' and '/' that might cause issues.
|
||||||
|
let encodedCouponCode = encodeURIComponent(encryptedCouponCode);
|
||||||
// Store the Base64 URL-safe encrypted coupon code in the query parameter
|
|
||||||
const encodedCouponCode = encodeURIComponent(base64UrlSafe); // Ensure it's safely encoded for URL use
|
// Construct the URL with the encoded coupon code as a query parameter
|
||||||
const urlWithCoupon = `https://dev.coupon.kedaimaster.com/coupon?c=${encodedCouponCode}`;
|
const urlWithCoupon = `https://coupon.kedaimaster.com/coupon?c=${encodedCouponCode}`;
|
||||||
|
|
||||||
// Optionally, set the URL to use with the coupon
|
// Optionally, set the URL to use with the coupon
|
||||||
setCouponUrl(urlWithCoupon);
|
setCouponUrl(urlWithCoupon);
|
||||||
console.log(urlWithCoupon);
|
|
||||||
|
console.log("Generated URL with Encrypted Coupon Code:", urlWithCoupon);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
} else {
|
} else {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@@ -58,6 +59,8 @@ const CreateCouponPage = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.linktreePage}>
|
<div className={styles.linktreePage}>
|
||||||
|
|||||||
@@ -18,20 +18,18 @@ const LinktreePage = ({ data, setModal }) => {
|
|||||||
const [couponStatus, setCouponStatus] = useState(0);
|
const [couponStatus, setCouponStatus] = useState(0);
|
||||||
const [couponDetails, setCouponDetails] = useState(null);
|
const [couponDetails, setCouponDetails] = useState(null);
|
||||||
|
|
||||||
// Detect query params on component mount
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (couponCode !== '') return; // Prevent repeated code
|
if (couponCode !== '') return;
|
||||||
|
|
||||||
const modal = queryParams.get('modal');
|
const modal = queryParams.get('modal');
|
||||||
const encryptedCode = queryParams.get('c'); // Encrypted coupon code in query
|
const code = queryParams.get('c');
|
||||||
|
|
||||||
console.log(encryptedCode);
|
console.log("Received coupon code:", code);
|
||||||
|
|
||||||
if (modal === 'claim-coupon') {
|
if (modal === 'claim-coupon') {
|
||||||
if (!getLocalStorage('auth')) {
|
if (!getLocalStorage('auth')) {
|
||||||
// Preserve the couponCode query param while navigating to the claim-coupon modal
|
// Preserve the couponCode query param while navigating to the claim-coupon modal
|
||||||
if (encryptedCode) setModal('join', { c: encryptedCode });
|
if (code) setModal('join', { c: code });
|
||||||
else setModal('join');
|
else setModal('join');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,26 +38,36 @@ const LinktreePage = ({ data, setModal }) => {
|
|||||||
} else {
|
} else {
|
||||||
if (getLocalStorage('auth')) {
|
if (getLocalStorage('auth')) {
|
||||||
// Preserve the couponCode query param while navigating to the claim-coupon modal
|
// Preserve the couponCode query param while navigating to the claim-coupon modal
|
||||||
if (encryptedCode) setModal('claim-coupon', { c: encryptedCode });
|
if (code) setModal('claim-coupon', { c: code });
|
||||||
else setModal('claim-coupon');
|
else setModal('claim-coupon');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (encryptedCode) {
|
if (code) {
|
||||||
// AES-256 key (ensure this is kept secret and secure!)
|
// URL decode the coupon code (it might be URL-encoded)
|
||||||
|
let decodedCode = code.replace('LDNWAlASJDNdaw','+').replace('XCLZBKlaWDJ','/').replace('LDSsadANJlas','=');
|
||||||
|
|
||||||
|
// Your AES-256 key (ensure this is kept secret and secure!)
|
||||||
const secretKey = 'xixixi666'; // 32 characters for AES-256
|
const secretKey = 'xixixi666'; // 32 characters for AES-256
|
||||||
|
|
||||||
// Decode and decrypt the coupon code
|
// Decrypt the coupon code
|
||||||
const decodedCouponCode = decodeURIComponent(encryptedCode); // Decode the encrypted code from the URL
|
const decryptedBytes = CryptoJS.AES.decrypt(decodedCode, secretKey);
|
||||||
const decryptedBytes = CryptoJS.AES.decrypt(decodedCouponCode, secretKey);
|
|
||||||
const decryptedCode = decryptedBytes.toString(CryptoJS.enc.Utf8);
|
const decryptedCode = decryptedBytes.toString(CryptoJS.enc.Utf8);
|
||||||
|
|
||||||
console.log(decryptedCode);
|
console.log("Decrypted Code:", decryptedCode);
|
||||||
setCouponCode(decryptedCode);
|
|
||||||
setIsUsingCoupon(true); // Automatically switch to the coupon input state
|
if (decryptedCode) {
|
||||||
handleCheckCoupon(decryptedCode); // Automatically check the coupon code
|
setCouponCode(decryptedCode);
|
||||||
|
setIsUsingCoupon(true); // Automatically switch to the coupon input state
|
||||||
|
handleCheckCoupon(decryptedCode); // Automatically check the coupon code
|
||||||
|
} else {
|
||||||
|
console.log("Failed to decrypt the coupon code");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [queryParams]);
|
}, [queryParams]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Handle manual coupon code check
|
// Handle manual coupon code check
|
||||||
const handleCheckCoupon = async (code = couponCode) => {
|
const handleCheckCoupon = async (code = couponCode) => {
|
||||||
const result = await checkCoupon(code); // Call the helper
|
const result = await checkCoupon(code); // Call the helper
|
||||||
|
|||||||
Reference in New Issue
Block a user