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 }) => {