This commit is contained in:
zadit
2025-02-05 07:50:33 +07:00
parent 66f73bc1ba
commit c7deaf2d35
4 changed files with 40 additions and 18 deletions

View File

@@ -4,6 +4,8 @@ import styles from './Join.module.css'; // Import the module.css file
import { checkCoupon, logCouponForUser } from '../helpers/couponHelpers'; // Import the new helper
import Coupon from '../components/Coupon';
import CryptoJS from 'crypto-js';
import {
getLocalStorage,
} from "../helpers/localStorageHelpers";
@@ -20,15 +22,15 @@ const LinktreePage = ({ data, setModal }) => {
useEffect(() => {
if (couponCode !== '') return;
const modal = queryParams.get('modal');
const code = queryParams.get('couponCode');
const code = queryParams.get('c');
console.log(code)
if (modal == 'claim-coupon') {
if (!getLocalStorage('auth')) {
// Preserve the couponCode query param while navigating to the claim-coupon modal
const newUrl = `?modal=join${code ? `&couponCode=${code}` : ''}`;
window.location.href = newUrl; // This will update the URL and reload the page
if(code) setModal('join', {c: code})
else setModal('join')
}
setIsOnlyClaimCoupon(true)
@@ -38,14 +40,21 @@ const LinktreePage = ({ data, setModal }) => {
if (getLocalStorage('auth')) {
// Preserve the couponCode query param while navigating to the claim-coupon modal
const newUrl = `?modal=claim-coupon${code ? `&couponCode=${code}` : ''}`;
window.location.href = newUrl; // This will update the URL and reload the page
if(code) setModal('claim-coupon', {c: code})
else setModal('claim-coupon')
}
}
if (code) {
setCouponCode(code);
// Your 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);
const decryptedCode = decryptedBytes.toString(CryptoJS.enc.Utf8);
console.log(decryptedCode)
setCouponCode(decryptedCode);
setIsUsingCoupon(true); // Automatically switch to the coupon input state
handleCheckCoupon(code); // Automatically check the coupon code
handleCheckCoupon(decryptedCode); // Automatically check the coupon code
}
}, [queryParams]);
@@ -162,8 +171,14 @@ const LinktreePage = ({ data, setModal }) => {
style={{ width: '266px' }}
onClick={() => {
if (!isOnlyClaimCoupon) {
const secretKey = 'xixixi666'; // Your AES-256 key (32 characters)
// Encrypt couponCode inline
const encryptedCouponCode = CryptoJS.AES.encrypt(couponCode, secretKey).toString();
// If it's only claiming a coupon, trigger claim logic
setModal('create_user', { codeStatus: 200, couponCode });
setModal('create_user', { codeStatus: 200, c: encryptedCouponCode });
} else {
// Otherwise, handle the coupon for user creation
handleLogCouponForUser();
@@ -180,15 +195,15 @@ const LinktreePage = ({ data, setModal }) => {
<div className={styles.footer}>
<div className={styles.footerLinks}>
{!getLocalStorage('auth') &&
<a
href="https://linktr.ee/discover/trending"
target="_blank"
rel="noreferrer"
className={styles.footerLink}
>
Sudah punya akun bisnis?
</a>
}
<a
href="https://linktr.ee/discover/trending"
target="_blank"
rel="noreferrer"
className={styles.footerLink}
>
Sudah punya akun bisnis?
</a>
}
<a
href="https://linktr.ee/discover/trending"
target="_blank"

View File

@@ -114,7 +114,7 @@ const App = ({ forCafe = true, cafeId = -1,
const [selectedCafeId, setSelectedCafeId] = useState(cafeId);
const [analytics, setAnalytics] = useState({});
const [loading, setLoading] = useState(true);
const [filter, setFilter] = useState("yesterday");
const [filter, setFilter] = useState("monthly");
const [circularFilter, setCircularFilter] = useState("item");
const [graphFilter, setGraphFilter] = useState("income");