From 308eafa6d40ac8b624d5746a64dd02a9b5950146 Mon Sep 17 00:00:00 2001 From: zadit <75159257+insvrgent@users.noreply.github.com> Date: Mon, 20 Jan 2025 07:58:25 +0700 Subject: [PATCH] ok --- src/App.js | 1 - src/components/Modal.js | 8 ++++ src/components/TablesPage.js | 10 ++-- src/pages/CheckCoupon.js | 64 +++++++++++++++++++++++++ src/pages/CreateCoupon.js | 80 +++++++++++++++++++++++++++++++ src/pages/CreateUserWithCoupon.js | 0 src/pages/Dashboard.js | 5 +- src/pages/Join.js | 2 +- 8 files changed, 163 insertions(+), 7 deletions(-) create mode 100644 src/pages/CheckCoupon.js create mode 100644 src/pages/CreateCoupon.js create mode 100644 src/pages/CreateUserWithCoupon.js diff --git a/src/App.js b/src/App.js index 1904384..0a37693 100644 --- a/src/App.js +++ b/src/App.js @@ -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"; diff --git a/src/components/Modal.js b/src/components/Modal.js index 4212ddd..a979504 100644 --- a/src/components/Modal.js +++ b/src/components/Modal.js @@ -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" && } {modalContent === "reports" && } + + + {modalContent === "create_coupon" && } + {modalContent === "check_coupon" && } ); diff --git a/src/components/TablesPage.js b/src/components/TablesPage.js index f077969..3b71f6b 100644 --- a/src/components/TablesPage.js +++ b/src/components/TablesPage.js @@ -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 /> @@ -617,7 +618,8 @@ const SetPaymentQr = ({ shop }) => { > Ganti alamat kedai : ( -
+
setIsConfigCafeIdentityName(false)} // Close the config modal style={{ @@ -636,8 +638,10 @@ const SetPaymentQr = ({ shop }) => {
{ + 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", diff --git a/src/pages/CheckCoupon.js b/src/pages/CheckCoupon.js new file mode 100644 index 0000000..ee1e265 --- /dev/null +++ b/src/pages/CheckCoupon.js @@ -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 ( +
+

Check Coupon

+
+ + setCouponCode(e.target.value)} + /> +
+ + {couponStatus &&

{couponStatus}

} + {couponDetails && ( +
+

Coupon Code: {couponDetails.code}

+

Discount Type: {couponDetails.discountType}

+

Discount Value: {couponDetails.discountValue}

+

Discount Periods: {couponDetails.discountPeriods} weeks

+

Expiration Date: {couponDetails.expirationDate || "No expiration"}

+
+ )} +
+ ); +}; + +export default CheckCouponPage; diff --git a/src/pages/CreateCoupon.js b/src/pages/CreateCoupon.js new file mode 100644 index 0000000..5be0cf7 --- /dev/null +++ b/src/pages/CreateCoupon.js @@ -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 ( +
+

Create Coupon

+
+
+ + +
+
+ + setDiscountValue(e.target.value)} + required + /> +
+
+ + setDiscountPeriods(e.target.value)} + required + /> +
+ +
+ {message &&

{message}

} +
+ ); +}; + +export default CreateCouponPage; diff --git a/src/pages/CreateUserWithCoupon.js b/src/pages/CreateUserWithCoupon.js new file mode 100644 index 0000000..e69de29 diff --git a/src/pages/Dashboard.js b/src/pages/Dashboard.js index 33a4f35..75cae57 100644 --- a/src/pages/Dashboard.js +++ b/src/pages/Dashboard.js @@ -927,8 +927,8 @@ const sortedMaterials = allMaterials.sort((a, b) => new Date(a.date) - new Date(
diff --git a/src/pages/Join.js b/src/pages/Join.js index 4a850b7..c4e6647 100644 --- a/src/pages/Join.js +++ b/src/pages/Join.js @@ -47,7 +47,7 @@ const LinktreePage = ({ data }) => { rel="noreferrer" className={styles.footerLink} > - Tentang kedaimaster.com + Gunakan kupon