ok
This commit is contained in:
@@ -50,7 +50,7 @@ const LinktreePage = ({ setModal }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_BASE_URL}/user/create-with-coupon`, {
|
const response = await fetch(`${API_BASE_URL}/coupon/create-user`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|||||||
@@ -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 styles from './Join.module.css'; // Import the module.css file
|
||||||
import API_BASE_URL from '../config.js';
|
import API_BASE_URL from '../config.js';
|
||||||
|
|
||||||
import Coupon from '../components/Coupon';
|
import Coupon from '../components/Coupon';
|
||||||
|
|
||||||
function getAuthToken() {
|
function getAuthToken() {
|
||||||
@@ -9,15 +8,28 @@ function getAuthToken() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const LinktreePage = ({ data, setModal }) => {
|
const LinktreePage = ({ data, setModal }) => {
|
||||||
|
const queryParams = new URLSearchParams(window.location.search);
|
||||||
const [isUsingCoupon, setIsUsingCoupon] = useState(false);
|
const [isUsingCoupon, setIsUsingCoupon] = useState(false);
|
||||||
const [couponCode, setCouponCode] = useState('');
|
const [couponCode, setCouponCode] = useState('');
|
||||||
const [couponStatus, setCouponStatus] = useState(0);
|
const [couponStatus, setCouponStatus] = useState(0);
|
||||||
const [couponDetails, setCouponDetails] = useState(null);
|
const [couponDetails, setCouponDetails] = useState(null);
|
||||||
|
|
||||||
const handleCheckCoupon = async (e) => {
|
// Detect query params on component mount
|
||||||
e.preventDefault();
|
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 {
|
try {
|
||||||
const response = await fetch(`${API_BASE_URL}/coupon/check/${couponCode}`, {
|
const response = await fetch(`${API_BASE_URL}/coupon/check/${code}`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@@ -43,15 +55,10 @@ const LinktreePage = ({ data, setModal }) => {
|
|||||||
<div className={styles.linktreePage}>
|
<div className={styles.linktreePage}>
|
||||||
{!isUsingCoupon ? (
|
{!isUsingCoupon ? (
|
||||||
<div className={styles.dashboardContainer}>
|
<div className={styles.dashboardContainer}>
|
||||||
{/* Main Heading */}
|
|
||||||
<div className={styles.mainHeading}>Nikmati Kemudahan Mengelola Kafe</div>
|
<div className={styles.mainHeading}>Nikmati Kemudahan Mengelola Kafe</div>
|
||||||
|
|
||||||
{/* Sub Heading */}
|
|
||||||
<div className={styles.subHeading}>
|
<div className={styles.subHeading}>
|
||||||
Daftarkan kedaimu sekarang dan mulai gunakan semua fitur unggulan kami.
|
Daftarkan kedaimu sekarang dan mulai gunakan semua fitur unggulan kami.
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Form Section */}
|
|
||||||
<form className={styles.linktreeForm}>
|
<form className={styles.linktreeForm}>
|
||||||
<label htmlFor="username" className={styles.usernameLabel}>
|
<label htmlFor="username" className={styles.usernameLabel}>
|
||||||
--------------------------------------------
|
--------------------------------------------
|
||||||
@@ -66,8 +73,6 @@ const LinktreePage = ({ data, setModal }) => {
|
|||||||
<span>➜</span>
|
<span>➜</span>
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{/* Footer Links */}
|
|
||||||
<div className={styles.footer}>
|
<div className={styles.footer}>
|
||||||
<div className={styles.footerLinks}>
|
<div className={styles.footerLinks}>
|
||||||
<a
|
<a
|
||||||
@@ -92,17 +97,12 @@ const LinktreePage = ({ data, setModal }) => {
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className={styles.dashboardContainer}>
|
<div className={styles.dashboardContainer}>
|
||||||
{/* Main Heading */}
|
|
||||||
<div className={styles.mainHeading}>Daftar Menggunakan Kupon</div>
|
<div className={styles.mainHeading}>Daftar Menggunakan Kupon</div>
|
||||||
|
|
||||||
{/* Sub Heading */}
|
|
||||||
<div className={styles.subHeading}>
|
<div className={styles.subHeading}>
|
||||||
Kupon tidak hanya dapat digunakan untuk pembuatan akun penyewa, tetapi juga dapat digunakan untuk memperpanjang masa berlangganan.
|
Kupon tidak hanya dapat digunakan untuk pembuatan akun penyewa, tetapi juga dapat digunakan untuk memperpanjang masa berlangganan.
|
||||||
</div>
|
</div>
|
||||||
|
{couponStatus === 0 ? (
|
||||||
{/* Coupon Check Section */}
|
<form className={styles.linktreeForm} onSubmit={(e) => e.preventDefault()}>
|
||||||
{couponStatus == 0 ?
|
|
||||||
<form className={styles.linktreeForm} onSubmit={handleCheckCoupon}>
|
|
||||||
<label htmlFor="coupon" className={styles.usernameLabel}>
|
<label htmlFor="coupon" className={styles.usernameLabel}>
|
||||||
--------------------------------------------
|
--------------------------------------------
|
||||||
</label>
|
</label>
|
||||||
@@ -114,26 +114,33 @@ const LinktreePage = ({ data, setModal }) => {
|
|||||||
value={couponCode}
|
value={couponCode}
|
||||||
onChange={(e) => setCouponCode(e.target.value)}
|
onChange={(e) => setCouponCode(e.target.value)}
|
||||||
/>
|
/>
|
||||||
<button type="submit" className={styles.claimButton}>
|
<button onClick={() => handleCheckCoupon()} className={styles.claimButton}>
|
||||||
<span>Cek</span>
|
<span>Cek</span>
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
:
|
) : (
|
||||||
<>
|
<>
|
||||||
<Coupon code={couponDetails?.code || null} value={couponDetails?.discountValue} period={couponDetails?.discountPeriods} expiration={couponDetails?.expirationDate} />
|
<Coupon
|
||||||
|
code={couponDetails?.code || null}
|
||||||
|
value={couponDetails?.discountValue}
|
||||||
|
period={couponDetails?.discountPeriods}
|
||||||
|
expiration={couponDetails?.expirationDate}
|
||||||
|
/>
|
||||||
<form className={styles.linktreeForm}>
|
<form className={styles.linktreeForm}>
|
||||||
<label htmlFor="username" className={styles.usernameLabel}>
|
<label htmlFor="username" className={styles.usernameLabel}>
|
||||||
--------------------------------------------
|
--------------------------------------------
|
||||||
</label>
|
</label>
|
||||||
<button type="submit" className={styles.claimButton} style={{ width: '266px' }} onClick={() => setModal('create_user', { codeStatus: 200, couponCode })}>
|
<button
|
||||||
|
type="submit"
|
||||||
|
className={styles.claimButton}
|
||||||
|
style={{ width: '266px' }}
|
||||||
|
onClick={() => setModal('create_user', { codeStatus: 200, couponCode })}
|
||||||
|
>
|
||||||
<span>Buat akun dengan kupon ini</span>
|
<span>Buat akun dengan kupon ini</span>
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
</>
|
</>
|
||||||
}
|
)}
|
||||||
{/* Footer Links */}
|
|
||||||
<div className={styles.footer}>
|
<div className={styles.footer}>
|
||||||
<div className={styles.footerLinks}>
|
<div className={styles.footerLinks}>
|
||||||
<a
|
<a
|
||||||
@@ -143,13 +150,31 @@ const LinktreePage = ({ data, setModal }) => {
|
|||||||
className={styles.footerLink}
|
className={styles.footerLink}
|
||||||
>
|
>
|
||||||
Pelajari lebih lanjut
|
Pelajari lebih lanjut
|
||||||
</a>
|
</a><a
|
||||||
<a
|
onClick={() => {
|
||||||
onClick={() => { setIsUsingCoupon(couponStatus == 0 ? false : true); setCouponCode(null); setCouponDetails(null); setCouponStatus(0) }}
|
|
||||||
|
// Get the current URL query parameters
|
||||||
|
const url = new URL(window.location.href);
|
||||||
|
|
||||||
|
// Remove the couponCode query parameter
|
||||||
|
url.searchParams.delete('couponCode');
|
||||||
|
|
||||||
|
// Update the browser's URL, but keep 'modal=join' intact
|
||||||
|
window.history.pushState({}, '', url.toString());
|
||||||
|
|
||||||
|
// Reset the states
|
||||||
|
setIsUsingCoupon(couponStatus === 0 ? false : true);
|
||||||
|
setCouponCode('');
|
||||||
|
setCouponDetails(null);
|
||||||
|
setCouponStatus(0);
|
||||||
|
|
||||||
|
|
||||||
|
}}
|
||||||
className={styles.footerLink}
|
className={styles.footerLink}
|
||||||
>
|
>
|
||||||
Kembali
|
Kembali
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.footerImage}>
|
<div className={styles.footerImage}>
|
||||||
<img src="./laporan.png" alt="Linktree visual" />
|
<img src="./laporan.png" alt="Linktree visual" />
|
||||||
|
|||||||
Reference in New Issue
Block a user