From 464277dd85a61d1c336c59a9eaf44f4f50dcd0cc Mon Sep 17 00:00:00 2001 From: insvrgent Date: Wed, 22 Jan 2025 13:30:09 +0700 Subject: [PATCH] ok --- src/pages/CreateUserWithCoupon.js | 2 +- src/pages/Join.js | 85 ++++++++++++++++++++----------- 2 files changed, 56 insertions(+), 31 deletions(-) diff --git a/src/pages/CreateUserWithCoupon.js b/src/pages/CreateUserWithCoupon.js index 16e7ab5..d06e73f 100644 --- a/src/pages/CreateUserWithCoupon.js +++ b/src/pages/CreateUserWithCoupon.js @@ -50,7 +50,7 @@ const LinktreePage = ({ setModal }) => { } try { - const response = await fetch(`${API_BASE_URL}/user/create-with-coupon`, { + const response = await fetch(`${API_BASE_URL}/coupon/create-user`, { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/src/pages/Join.js b/src/pages/Join.js index 52de2e8..7e29b98 100644 --- a/src/pages/Join.js +++ b/src/pages/Join.js @@ -1,7 +1,6 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import styles from './Join.module.css'; // Import the module.css file import API_BASE_URL from '../config.js'; - import Coupon from '../components/Coupon'; function getAuthToken() { @@ -9,15 +8,28 @@ function getAuthToken() { } const LinktreePage = ({ data, setModal }) => { + const queryParams = new URLSearchParams(window.location.search); const [isUsingCoupon, setIsUsingCoupon] = useState(false); const [couponCode, setCouponCode] = useState(''); const [couponStatus, setCouponStatus] = useState(0); const [couponDetails, setCouponDetails] = useState(null); - const handleCheckCoupon = async (e) => { - e.preventDefault(); + // Detect query params on component mount + useEffect(() => { + const code = queryParams.get('couponCode'); + console.log(code) + if (code) { + setCouponStatus(200) + setCouponCode(code); + setIsUsingCoupon(true); // Automatically switch to the coupon input state + handleCheckCoupon(code); // Automatically check the coupon code + } + }, [queryParams]); + + // Handle manual coupon code check + const handleCheckCoupon = async (code = couponCode) => { try { - const response = await fetch(`${API_BASE_URL}/coupon/check/${couponCode}`, { + const response = await fetch(`${API_BASE_URL}/coupon/check/${code}`, { method: 'GET', headers: { 'Content-Type': 'application/json', @@ -43,15 +55,10 @@ const LinktreePage = ({ data, setModal }) => {
{!isUsingCoupon ? (
- {/* Main Heading */}
Nikmati Kemudahan Mengelola Kafe
- - {/* Sub Heading */}
Daftarkan kedaimu sekarang dan mulai gunakan semua fitur unggulan kami.
- - {/* Form Section */}