ok
This commit is contained in:
64
src/pages/CheckCoupon.js
Normal file
64
src/pages/CheckCoupon.js
Normal file
@@ -0,0 +1,64 @@
|
||||
import React, { useState } from "react";
|
||||
|
||||
import API_BASE_URL from "../config.js";
|
||||
|
||||
function getAuthToken() {
|
||||
return localStorage.getItem("auth");
|
||||
}
|
||||
|
||||
const CheckCouponPage = () => {
|
||||
const [couponCode, setCouponCode] = useState("");
|
||||
const [couponStatus, setCouponStatus] = useState("");
|
||||
const [couponDetails, setCouponDetails] = useState(null);
|
||||
|
||||
const handleCheckCoupon = async () => {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}/coupon/check/${couponCode}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${getAuthToken()}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
setCouponStatus("Coupon is valid");
|
||||
setCouponDetails(data.coupon);
|
||||
} else {
|
||||
setCouponStatus("Coupon not found or expired");
|
||||
setCouponDetails(null);
|
||||
}
|
||||
} catch (error) {
|
||||
setCouponStatus("Error checking coupon.");
|
||||
setCouponDetails(null);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>Check Coupon</h1>
|
||||
<div>
|
||||
<label>Coupon Code:</label>
|
||||
<input
|
||||
type="text"
|
||||
value={couponCode}
|
||||
onChange={(e) => setCouponCode(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<button onClick={handleCheckCoupon}>Check Coupon</button>
|
||||
{couponStatus && <p>{couponStatus}</p>}
|
||||
{couponDetails && (
|
||||
<div>
|
||||
<p>Coupon Code: {couponDetails.code}</p>
|
||||
<p>Discount Type: {couponDetails.discountType}</p>
|
||||
<p>Discount Value: {couponDetails.discountValue}</p>
|
||||
<p>Discount Periods: {couponDetails.discountPeriods} weeks</p>
|
||||
<p>Expiration Date: {couponDetails.expirationDate || "No expiration"}</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default CheckCouponPage;
|
||||
80
src/pages/CreateCoupon.js
Normal file
80
src/pages/CreateCoupon.js
Normal file
@@ -0,0 +1,80 @@
|
||||
import React, { useState } from "react";
|
||||
|
||||
import API_BASE_URL from "../config.js";
|
||||
|
||||
function getAuthToken() {
|
||||
return localStorage.getItem("auth");
|
||||
}
|
||||
const CreateCouponPage = () => {
|
||||
const [discountType, setDiscountType] = useState("percentage");
|
||||
const [discountValue, setDiscountValue] = useState("");
|
||||
const [discountPeriods, setDiscountPeriods] = useState("");
|
||||
const [message, setMessage] = useState("");
|
||||
|
||||
const handleSubmit = async (e) => {
|
||||
e.preventDefault();
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}/coupon/create`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${getAuthToken()}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
discountType,
|
||||
discountValue,
|
||||
discountPeriods,
|
||||
}),
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
setMessage(`Coupon created successfully: ${data.coupon.code}`);
|
||||
} else {
|
||||
setMessage("Failed to create coupon.");
|
||||
}
|
||||
} catch (error) {
|
||||
setMessage("Error creating coupon.");
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>Create Coupon</h1>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<div>
|
||||
<label>Discount Type:</label>
|
||||
<select
|
||||
value={discountType}
|
||||
onChange={(e) => setDiscountType(e.target.value)}
|
||||
>
|
||||
<option value="percentage">Percentage</option>
|
||||
<option value="fixed">Fixed</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label>Discount Value:</label>
|
||||
<input
|
||||
type="number"
|
||||
value={discountValue}
|
||||
onChange={(e) => setDiscountValue(e.target.value)}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label>Discount Periods (in weeks):</label>
|
||||
<input
|
||||
type="number"
|
||||
value={discountPeriods}
|
||||
onChange={(e) => setDiscountPeriods(e.target.value)}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<button type="submit">Create Coupon</button>
|
||||
</form>
|
||||
{message && <p>{message}</p>}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default CreateCouponPage;
|
||||
0
src/pages/CreateUserWithCoupon.js
Normal file
0
src/pages/CreateUserWithCoupon.js
Normal file
@@ -927,8 +927,8 @@ const sortedMaterials = allMaterials.sort((a, b) => new Date(a.date) - new Date(
|
||||
|
||||
<div className={styles.footer}>
|
||||
<div className={styles.footerLinks}>
|
||||
<a href="https://linktr.ee/discover/trending" target="_blank" rel="noreferrer" className={styles.footerLink}>Pelajari lebih lanjut</a>
|
||||
<a href="https://linktr.ee" target="_blank" rel="noreferrer" className={styles.footerLink}>Tentang kedaimaster.com</a>
|
||||
<a href="https://kediritechnopark.com/kedaimaster" target="_blank" rel="noreferrer" className={styles.footerLink}>Pelajari lebih lanjut</a>
|
||||
<a href="https://kediritechnopark.com/" target="_blank" rel="noreferrer" className={styles.footerLink}>Tentang kedaimaster.com</a>
|
||||
<a
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
@@ -946,6 +946,7 @@ const sortedMaterials = allMaterials.sort((a, b) => new Date(a.date) - new Date(
|
||||
onError={(e) => e.target.src = '/fallback-image.png'}
|
||||
/>
|
||||
</div>
|
||||
<a style={{left: 0, right: 0, bottom: 0, textAlign: 'center', color: '#254F1A', fontSize:'13px', position: 'fixed'}}>©2025 KEDIRITECHNOPARK</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -47,7 +47,7 @@ const LinktreePage = ({ data }) => {
|
||||
rel="noreferrer"
|
||||
className={styles.footerLink}
|
||||
>
|
||||
Tentang kedaimaster.com
|
||||
Gunakan kupon
|
||||
</a>
|
||||
</div>
|
||||
<div className={styles.footerImage}>
|
||||
|
||||
Reference in New Issue
Block a user