This commit is contained in:
zadit
2025-01-20 07:58:25 +07:00
parent 9cd0508d4a
commit 308eafa6d4
8 changed files with 163 additions and 7 deletions

View File

@@ -10,7 +10,6 @@ import {
} from "react-router-dom";
import socket from "./services/socketService";
import API_BASE_URL from "./config.js";
import Dashboard from "./pages/Dashboard";
import ScanMeja from "./pages/ScanMeja";

View File

@@ -27,6 +27,10 @@ import Login from "../pages/Login";
import ResetPassword from "../pages/ResetPassword";
import { getImageUrl } from "../helpers/itemHelper.js";
import CreateCoupon from "../pages/CreateCoupon";
import CheckCoupon from "../pages/CheckCoupon";
const Modal = ({ user, shop, isOpen, onClose, modalContent, setModal, handleMoveToTransaction,welcomePageConfig }) => {
const [shopImg, setShopImg] = useState('');
@@ -95,6 +99,10 @@ const Modal = ({ user, shop, isOpen, onClose, modalContent, setModal, handleMove
)}
{modalContent === "welcome_config" && <WelcomePageEditor cafeId={shop.cafeId} welcomePageConfig={shop.welcomePageConfig} />}
{modalContent === "reports" && <Reports handleClose={handleOverlayClick} cafeId={shop.cafeId} />}
{modalContent === "create_coupon" && <CreateCoupon />}
{modalContent === "check_coupon" && <CheckCoupon />}
</div>
</div>
);

View File

@@ -29,6 +29,7 @@ const SetPaymentQr = ({ shop }) => {
const [bgImageUrl, setBgImageUrl] = useState(getImageUrl(shop.qrBackground));
const qrBackgroundInputRef = useRef(null);
const [cafeIdentifyNameDefault, setCafeIdentifyNameDefault] = useState(shop.cafeIdentifyName);
const [cafeIdentifyNameUpdate, setCafeIdentifyNameUpdate] = useState(shop.cafeIdentifyName);
const shopUrl = window.location.hostname + "/" + cafeIdentifyNameUpdate;
@@ -350,7 +351,7 @@ const SetPaymentQr = ({ shop }) => {
}}
onBlur={() => {
setIsConfigCafeIdentityName(false); // Set the state to false when input loses focus
setCafeIdentifyNameUpdate(shop.cafeIdentifyName)
setCafeIdentifyNameUpdate(cafeIdentifyNameDefault)
}} // Handle blur event to reset the state
/>
</div>
@@ -617,7 +618,8 @@ const SetPaymentQr = ({ shop }) => {
>
Ganti alamat kedai
</div> : (
<div style={{ display: 'flex', justifyContent: 'space-between', width: '100%' }}>
<div style={{ display: 'flex', justifyContent: 'space-between', width: '100%',
marginBottom: '10px' }}>
<div
onClick={() => setIsConfigCafeIdentityName(false)} // Close the config modal
style={{
@@ -636,8 +638,10 @@ const SetPaymentQr = ({ shop }) => {
<div
onClick={() => {
setCafeIdentifyNameDefault(cafeIdentifyNameUpdate)
// Handle save functionality here
setIsConfigCafeIdentityName(false); // Close after saving
}}
style={{
backgroundColor: '#303034',
@@ -951,7 +955,7 @@ const styles = {
},
qrCodeContainer: {
backgroundColor: '#999999',
borderRadius: '20px',
borderRadius: '8px',
position: "relative",
width: "100%",
height: "200px",

64
src/pages/CheckCoupon.js Normal file
View 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
View 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;

View File

View 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>

View File

@@ -47,7 +47,7 @@ const LinktreePage = ({ data }) => {
rel="noreferrer"
className={styles.footerLink}
>
Tentang kedaimaster.com
Gunakan kupon
</a>
</div>
<div className={styles.footerImage}>