ok
This commit is contained in:
@@ -29,7 +29,7 @@
|
||||
width: 140px;
|
||||
border-radius: 30px;
|
||||
position: absolute;
|
||||
background-color: rgb(146, 146, 146); /* Semi-transparent blue */
|
||||
background-color: rgba(146, 146, 146, 0); /* Semi-transparent blue */
|
||||
border: none;
|
||||
transition: all 0.5s ease-in-out;
|
||||
top: 50%;
|
||||
|
||||
@@ -134,20 +134,22 @@ const ButtonWithReplica = ({
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
<div className={`replica ${isActive ? "active" : ""}`}></div>
|
||||
<QRCodeSVG
|
||||
className={`bussinessQR ${isActive ? "active" : ""}`}
|
||||
bgColor={"transparent"}
|
||||
fgColor={fgColor}
|
||||
value={QRValue}
|
||||
/>
|
||||
<div className={`bussinessName ${isActive ? "active" : ""}`}>
|
||||
<h2>{qrisComponent.merchantName}</h2>
|
||||
{qrisComponent.nmid != "" && <h4>NMID : {qrisComponent.nmid}</h4>}
|
||||
</div>
|
||||
<div className={`price ${isActive ? "active" : ""}`}>
|
||||
<h1>{price}</h1>
|
||||
</div>
|
||||
<>
|
||||
<div className={`replica ${isActive ? "active" : ""}`}></div>
|
||||
<QRCodeSVG
|
||||
className={`bussinessQR ${isActive ? "active" : ""}`}
|
||||
bgColor={"transparent"}
|
||||
fgColor={fgColor}
|
||||
value={QRValue}
|
||||
/>
|
||||
<div className={`bussinessName ${isActive ? "active" : ""}`}>
|
||||
<h2>{qrisComponent.merchantName}</h2>
|
||||
{qrisComponent.nmid != "" && <h4>NMID : {qrisComponent.nmid}</h4>}
|
||||
</div>
|
||||
<div className={`price ${isActive ? "active" : ""}`}>
|
||||
<h1>{price}</h1>
|
||||
</div>
|
||||
</>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -55,7 +55,9 @@ export default function ItemType({
|
||||
<div
|
||||
onClick={onClick}
|
||||
className={styles["item-type-rect"]}
|
||||
style={{ top: selected ? "-10px" : "initial" }}
|
||||
style={{
|
||||
top: selected ? "-10px" : "initial",
|
||||
}}
|
||||
>
|
||||
<img
|
||||
src={previewUrl}
|
||||
@@ -89,7 +91,10 @@ export default function ItemType({
|
||||
value={name}
|
||||
onChange={handleNameChange}
|
||||
disabled={!blank}
|
||||
style={{ top: selected ? "-5px" : "initial" }}
|
||||
style={{
|
||||
top: selected ? "-5px" : "initial",
|
||||
borderBottom: selected ? "1px solid #000" : "none",
|
||||
}}
|
||||
/>
|
||||
{blank && (
|
||||
<button className={styles["item-type-create"]} onClick={handleCreate}>
|
||||
|
||||
@@ -14,7 +14,7 @@ import MaterialList from "../pages/MaterialList.js";
|
||||
import MaterialMutationsPage from "../pages/MaterialMutationsPage.js";
|
||||
import Reports from "../pages/Reports.js";
|
||||
import NotificationBlocked from "../pages/NotificationBlocked.js";
|
||||
|
||||
import WelcomePageEditor from "../pages/WelcomePageEditor.js";
|
||||
const Modal = ({ shop, isOpen, onClose, modalContent }) => {
|
||||
if (!isOpen) return null;
|
||||
|
||||
@@ -63,6 +63,7 @@ const Modal = ({ shop, isOpen, onClose, modalContent }) => {
|
||||
{modalContent === "update_stock" && (
|
||||
<MaterialMutationsPage cafeId={shop.cafeId} />
|
||||
)}
|
||||
{modalContent === "welcome_config" && <WelcomePageEditor />}
|
||||
{modalContent === "reports" && <Reports cafeId={shop.cafeId} />}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
.modalContent {
|
||||
width: 90%;
|
||||
height: 80%;
|
||||
/* height: 80%; */
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||
position: relative;
|
||||
overflow: visible; /* Add this line to enable scrolling */
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
import React, { useState, useRef, useEffect } from "react";
|
||||
import jsQR from "jsqr"; // Import jsQR library
|
||||
import jsQR from "jsqr";
|
||||
import { getImageUrl } from "../helpers/itemHelper";
|
||||
import {
|
||||
getCafe,
|
||||
saveCafeDetails,
|
||||
setConfirmationStatus,
|
||||
} from "../helpers/cafeHelpers"; // Import the helper function
|
||||
} from "../helpers/cafeHelpers";
|
||||
import Switch from "react-switch";
|
||||
|
||||
// Main Component
|
||||
const SetPaymentQr = ({ shopId }) => {
|
||||
const [qrPosition, setQrPosition] = useState([50, 50]);
|
||||
const [qrSize, setQrSize] = useState(50);
|
||||
const [qrPayment, setQrPayment] = useState();
|
||||
const [qrCodeDetected, setQrCodeDetected] = useState(false);
|
||||
const qrPaymentInputRef = useRef(null);
|
||||
const overlayTextRef = useRef(null);
|
||||
const qrCodeContainerRef = useRef(null);
|
||||
const [isNeedConfirmation, setIsNeedConfirmation] = useState(false);
|
||||
const [cafe, setCafe] = useState([]);
|
||||
const [cafe, setCafe] = useState({});
|
||||
|
||||
// Use useEffect to detect QR code after qrPayment updates
|
||||
// Fetch cafe details on mount or shopId change
|
||||
useEffect(() => {
|
||||
const fetchCafe = async () => {
|
||||
try {
|
||||
@@ -29,119 +29,100 @@ const SetPaymentQr = ({ shopId }) => {
|
||||
setIsNeedConfirmation(response.needsConfirmation);
|
||||
setQrPosition([response.xposition, response.yposition]);
|
||||
setQrSize(response.scale);
|
||||
console.log(response);
|
||||
} catch (error) {
|
||||
console.error("Error fetching cafe:", error);
|
||||
}
|
||||
};
|
||||
|
||||
fetchCafe();
|
||||
}, [shopId]);
|
||||
|
||||
// Detect QR code when qrPayment updates
|
||||
useEffect(() => {
|
||||
if (qrPayment) {
|
||||
detectQRCodeFromContainer();
|
||||
}
|
||||
}, [qrPayment]);
|
||||
|
||||
// Handle file input change
|
||||
const handleFileChange = (e) => {
|
||||
const file = e.target.files[0];
|
||||
if (file) {
|
||||
const newqrPayment = URL.createObjectURL(file); // Create a temporary URL for display
|
||||
const newqrPayment = URL.createObjectURL(file);
|
||||
setQrPayment(newqrPayment);
|
||||
}
|
||||
};
|
||||
|
||||
// Detect QR code from the container
|
||||
const detectQRCodeFromContainer = () => {
|
||||
const container = qrCodeContainerRef.current;
|
||||
const canvas = document.createElement("canvas");
|
||||
const context = canvas.getContext("2d");
|
||||
|
||||
// Create an image element to load the background image
|
||||
const img = new Image();
|
||||
img.crossOrigin = "Anonymous"; // Handle CORS if needed
|
||||
img.crossOrigin = "Anonymous";
|
||||
img.onload = () => {
|
||||
// Set canvas size
|
||||
canvas.width = container.offsetWidth;
|
||||
canvas.height = container.offsetHeight;
|
||||
|
||||
// Draw image on canvas
|
||||
context.drawImage(img, 0, 0, canvas.width, canvas.height);
|
||||
|
||||
const imageData = context.getImageData(0, 0, canvas.width, canvas.height);
|
||||
const qrCode = jsQR(imageData.data, canvas.width, canvas.height);
|
||||
|
||||
setQrCodeDetected(!!qrCode);
|
||||
if (qrCode) {
|
||||
setQrCodeDetected(true);
|
||||
console.log("QR Code detected:", qrCode.data);
|
||||
} else {
|
||||
setQrCodeDetected(false);
|
||||
console.log("No QR Code detected");
|
||||
}
|
||||
};
|
||||
img.src = qrPayment; // Load the image URL
|
||||
img.src = qrPayment;
|
||||
};
|
||||
|
||||
const handleSave = () => {
|
||||
const qrPaymentFile = qrPaymentInputRef.current.files[0]; // Get the selected file for qrPayment
|
||||
|
||||
// Prepare the details object
|
||||
// Save cafe details
|
||||
const handleSave = async () => {
|
||||
const qrPaymentFile = qrPaymentInputRef.current.files[0];
|
||||
const details = {
|
||||
qrPosition,
|
||||
qrSize,
|
||||
qrPaymentFile, // Include qrPayment file
|
||||
qrPaymentFile,
|
||||
};
|
||||
|
||||
// Call saveCafeDetails function with the updated details object
|
||||
saveCafeDetails(cafe.cafeId, details)
|
||||
.then((response) => {
|
||||
console.log("Cafe details saved:", response);
|
||||
// handleQrSave(qrPosition, qrSize, qrPayment);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error saving cafe details:", error);
|
||||
});
|
||||
try {
|
||||
const response = await saveCafeDetails(cafe.cafeId, details);
|
||||
console.log("Cafe details saved:", response);
|
||||
} catch (error) {
|
||||
console.error("Error saving cafe details:", error);
|
||||
}
|
||||
};
|
||||
|
||||
// Toggle confirmation status
|
||||
const handleChange = async () => {
|
||||
console.log(isNeedConfirmation);
|
||||
setIsNeedConfirmation(!isNeedConfirmation);
|
||||
console.log(!isNeedConfirmation);
|
||||
try {
|
||||
// Wait for the updateItemAvailability response
|
||||
const response = await setConfirmationStatus(
|
||||
cafe.cafeId,
|
||||
!isNeedConfirmation
|
||||
);
|
||||
|
||||
setIsNeedConfirmation(response.needsConfirmation);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
setIsNeedConfirmation(cafe.needsConfirmation);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div style={styles.container}>
|
||||
<h2 style={styles.title}>Payment QRIS</h2>
|
||||
<div
|
||||
id="qr-code-container"
|
||||
ref={qrCodeContainerRef}
|
||||
style={{
|
||||
position: "relative",
|
||||
width: "300px",
|
||||
height: "300px",
|
||||
background: `center center / contain no-repeat url(${qrPayment})`,
|
||||
...styles.qrCodeContainer,
|
||||
backgroundImage: `url(${qrPayment})`,
|
||||
backgroundPosition: "center",
|
||||
backgroundRepeat: "no-repeat",
|
||||
backgroundSize: "contain",
|
||||
overflow: "hidden",
|
||||
border: "1px solid #ddd",
|
||||
}}
|
||||
>
|
||||
<div
|
||||
ref={overlayTextRef}
|
||||
style={styles.overlayText}
|
||||
onClick={() => qrPaymentInputRef.current.click()}
|
||||
>
|
||||
Click To Change Image
|
||||
Click To Change
|
||||
</div>
|
||||
<input
|
||||
type="file"
|
||||
@@ -151,51 +132,90 @@ const SetPaymentQr = ({ shopId }) => {
|
||||
onChange={handleFileChange}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ marginTop: "20px" }}>
|
||||
<div style={styles.resultMessage}>
|
||||
{qrCodeDetected ? <p>QR Code Detected</p> : <p>No QR Code Detected</p>}
|
||||
<div style={{ marginTop: "20px" }}>
|
||||
<button
|
||||
onClick={handleSave}
|
||||
style={{
|
||||
padding: "10px 20px",
|
||||
fontSize: "16px",
|
||||
backgroundColor: "#28a745",
|
||||
color: "#fff",
|
||||
border: "none",
|
||||
borderRadius: "4px",
|
||||
cursor: "pointer",
|
||||
transition: "background-color 0.3s",
|
||||
}}
|
||||
onMouseOver={(e) =>
|
||||
(e.currentTarget.style.backgroundColor = "#218838")
|
||||
}
|
||||
onMouseOut={(e) =>
|
||||
(e.currentTarget.style.backgroundColor = "#28a745")
|
||||
}
|
||||
>
|
||||
Save
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Switch onChange={() => handleChange()} checked={isNeedConfirmation} />
|
||||
<div style={styles.buttonContainer}>
|
||||
<button onClick={handleSave} style={styles.saveButton}>
|
||||
Save
|
||||
</button>
|
||||
</div>
|
||||
<div style={styles.switchContainer}>
|
||||
<h1>Double Check tem Availability</h1>
|
||||
<p style={styles.description}>
|
||||
Turn on the switch for the clerk to double check before customer pay.
|
||||
</p>
|
||||
<Switch onChange={handleChange} checked={isNeedConfirmation} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// Styles
|
||||
const styles = {
|
||||
container: {
|
||||
backgroundColor: "white",
|
||||
padding: "20px",
|
||||
borderRadius: "8px",
|
||||
boxShadow: "0 2px 10px rgba(0, 0, 0, 0.1)",
|
||||
textAlign: "center", // Center text and children
|
||||
},
|
||||
title: {
|
||||
marginBottom: "20px",
|
||||
fontSize: "24px",
|
||||
fontWeight: "bold",
|
||||
},
|
||||
qrCodeContainer: {
|
||||
position: "relative",
|
||||
width: "300px",
|
||||
height: "300px",
|
||||
backgroundSize: "contain",
|
||||
border: "1px solid #ddd",
|
||||
overflow: "hidden",
|
||||
margin: "0 auto", // Center the QR code container
|
||||
},
|
||||
overlayText: {
|
||||
position: "absolute",
|
||||
width: "100%",
|
||||
height: "100%",
|
||||
fontSize: "550%",
|
||||
textAlign: "left",
|
||||
top: "50%",
|
||||
left: "50%",
|
||||
transform: "translate(-50%, -50%)",
|
||||
backgroundColor: "rgba(0, 0, 0, 0.5)",
|
||||
color: "#fff",
|
||||
color: "rgba(256, 256, 256, 0.5)",
|
||||
padding: "10px",
|
||||
borderRadius: "5px",
|
||||
cursor: "pointer",
|
||||
},
|
||||
// Other styles omitted for brevity
|
||||
resultMessage: {
|
||||
marginTop: "20px",
|
||||
textAlign: "center",
|
||||
},
|
||||
buttonContainer: {
|
||||
marginTop: "20px",
|
||||
textAlign: "center",
|
||||
},
|
||||
saveButton: {
|
||||
padding: "10px 20px",
|
||||
fontSize: "16px",
|
||||
backgroundColor: "#28a745",
|
||||
color: "#fff",
|
||||
border: "none",
|
||||
borderRadius: "4px",
|
||||
cursor: "pointer",
|
||||
transition: "background-color 0.3s",
|
||||
},
|
||||
switchContainer: {
|
||||
marginTop: "20px",
|
||||
textAlign: "center",
|
||||
},
|
||||
description: {
|
||||
margin: "10px 0",
|
||||
fontSize: "14px",
|
||||
color: "#666",
|
||||
},
|
||||
};
|
||||
|
||||
export default SetPaymentQr;
|
||||
|
||||
Reference in New Issue
Block a user