ok
This commit is contained in:
@@ -7,7 +7,6 @@ import CreateCafe from "../pages/CreateCafe"
|
|||||||
import CreateTenant from "../pages/CreateTenant"
|
import CreateTenant from "../pages/CreateTenant"
|
||||||
import TablesPage from "./TablesPage.js";
|
import TablesPage from "./TablesPage.js";
|
||||||
import PaymentOptions from "./PaymentOptions.js";
|
import PaymentOptions from "./PaymentOptions.js";
|
||||||
import TableMaps from "../components/TableMaps";
|
|
||||||
import Transaction from "../pages/Transaction";
|
import Transaction from "../pages/Transaction";
|
||||||
import Transaction_pending from "../pages/Transaction_pending";
|
import Transaction_pending from "../pages/Transaction_pending";
|
||||||
import Transaction_confirmed from "../pages/Transaction_confirmed";
|
import Transaction_confirmed from "../pages/Transaction_confirmed";
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useState, useRef, useEffect } from "react";
|
import React, { useState, useRef, useEffect } from "react";
|
||||||
import jsQR from "jsqr";
|
import API_BASE_URL from "../config.js";
|
||||||
import { getImageUrl } from "../helpers/itemHelper";
|
import { getImageUrl } from "../helpers/itemHelper";
|
||||||
import { getTables, updateTable, createTable } from "../helpers/tableHelper";
|
import { getTables, updateTable, createTable } from "../helpers/tableHelper";
|
||||||
import {
|
import {
|
||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
} from "../helpers/cafeHelpers";
|
} from "../helpers/cafeHelpers";
|
||||||
|
|
||||||
import { toPng } from 'html-to-image';
|
import { toPng } from 'html-to-image';
|
||||||
|
import { ColorRing } from "react-loader-spinner";
|
||||||
|
|
||||||
const SetPaymentQr = ({ shop }) => {
|
const SetPaymentQr = ({ shop }) => {
|
||||||
const [initialPos, setInitialPos] = useState({
|
const [initialPos, setInitialPos] = useState({
|
||||||
@@ -29,7 +30,6 @@ const SetPaymentQr = ({ shop }) => {
|
|||||||
const [bgImageUrl, setBgImageUrl] = useState(getImageUrl(shop.qrBackground));
|
const [bgImageUrl, setBgImageUrl] = useState(getImageUrl(shop.qrBackground));
|
||||||
const qrBackgroundInputRef = useRef(null);
|
const qrBackgroundInputRef = useRef(null);
|
||||||
|
|
||||||
const [cafeIdentifyNameDefault, setCafeIdentifyNameDefault] = useState(shop.cafeIdentifyName);
|
|
||||||
const [cafeIdentifyNameUpdate, setCafeIdentifyNameUpdate] = useState(shop.cafeIdentifyName);
|
const [cafeIdentifyNameUpdate, setCafeIdentifyNameUpdate] = useState(shop.cafeIdentifyName);
|
||||||
const shopUrl = window.location.hostname + "/" + cafeIdentifyNameUpdate;
|
const shopUrl = window.location.hostname + "/" + cafeIdentifyNameUpdate;
|
||||||
|
|
||||||
@@ -59,6 +59,8 @@ const SetPaymentQr = ({ shop }) => {
|
|||||||
const [selectedTable, setSelectedTable] = useState(null);
|
const [selectedTable, setSelectedTable] = useState(null);
|
||||||
|
|
||||||
const [tableNo, setTableNo] = useState(null);
|
const [tableNo, setTableNo] = useState(null);
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [identifyNameResponse, setIdentifyNameResponse] = useState('-----------------');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
@@ -178,7 +180,46 @@ const SetPaymentQr = ({ shop }) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This will hold the timeout ID so we can clear it when needed
|
||||||
|
const typingTimeoutRef = useRef(null);
|
||||||
|
|
||||||
|
const handleInputChange = (e) => {
|
||||||
|
setIsLoading(true)
|
||||||
|
const updatedValue = e.target.value
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/ /g, '_')
|
||||||
|
.replace(/[^a-z0-9_]/g, '');
|
||||||
|
setCafeIdentifyNameUpdate(updatedValue);
|
||||||
|
|
||||||
|
// Clear the existing timeout
|
||||||
|
if (typingTimeoutRef.current) {
|
||||||
|
clearTimeout(typingTimeoutRef.current);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set a new timeout
|
||||||
|
typingTimeoutRef.current = setTimeout(() => {
|
||||||
|
// Call the function to check if the name is already used
|
||||||
|
checkIfNameIsUsed(updatedValue);
|
||||||
|
}, 1000); // 1 second delay
|
||||||
|
};
|
||||||
|
|
||||||
|
const checkIfNameIsUsed = async (newIdentifyName) => {
|
||||||
|
// Replace this with your actual API call
|
||||||
|
try {
|
||||||
|
const response = await fetch(API_BASE_URL+`/cafe/check-identifyName/${newIdentifyName}`);
|
||||||
|
console.log(response)
|
||||||
|
if (response.ok) {
|
||||||
|
setIsLoading(false);
|
||||||
|
setIdentifyNameResponse(200)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setIsLoading(false);
|
||||||
|
setIdentifyNameResponse(409)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={styles.container}>
|
<div style={styles.container}>
|
||||||
@@ -343,22 +384,13 @@ const SetPaymentQr = ({ shop }) => {
|
|||||||
paddingLeft: isconfigcafeidentityname ? '10px' : '0', // Adjust padding when focused
|
paddingLeft: isconfigcafeidentityname ? '10px' : '0', // Adjust padding when focused
|
||||||
borderLeft: isconfigcafeidentityname ? '1px solid #ccc' : '0', // Adjust border when focused
|
borderLeft: isconfigcafeidentityname ? '1px solid #ccc' : '0', // Adjust border when focused
|
||||||
}}
|
}}
|
||||||
onChange={(e) => {
|
onChange={
|
||||||
// Convert to lowercase, replace spaces with underscores, and remove invalid characters
|
handleInputChange
|
||||||
const updatedValue = e.target.value
|
}
|
||||||
.toLowerCase() // Convert input to lowercase
|
|
||||||
.replace(/ /g, '_') // Replace spaces with underscores
|
|
||||||
.replace(/[^a-z0-9_]/g, ''); // Remove characters that are not lowercase letters, numbers, or underscores
|
|
||||||
setCafeIdentifyNameUpdate(updatedValue);
|
|
||||||
}}
|
|
||||||
value={cafeIdentifyNameUpdate}
|
value={cafeIdentifyNameUpdate}
|
||||||
onFocus={() => {
|
onFocus={() => {
|
||||||
setIsConfigCafeIdentityName(true); // Set the state to true when input is focused
|
setIsConfigCafeIdentityName(true); // Set the state to true when input is focused
|
||||||
}}
|
}}
|
||||||
onBlur={() => {
|
|
||||||
setIsConfigCafeIdentityName(false); // Set the state to false when input loses focus
|
|
||||||
setCafeIdentifyNameUpdate(cafeIdentifyNameDefault); // Reset to default value on blur
|
|
||||||
}} // Handle blur event to reset the state
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@@ -615,52 +647,56 @@ const SetPaymentQr = ({ shop }) => {
|
|||||||
<p>Klik untuk ganti alamat</p>
|
<p>Klik untuk ganti alamat</p>
|
||||||
</div>
|
</div>
|
||||||
<div style={styles.resultMessage}>
|
<div style={styles.resultMessage}>
|
||||||
<p onClick={() => { setIsConfigCafeIdentityName(true); cafeIdentifyNameRef.current && cafeIdentifyNameRef.current.focus() }}>-----------------</p>
|
<p>-----------------</p>
|
||||||
<div
|
<div
|
||||||
onClick={() => {setIsConfigCafeIdentityName(true); cafeIdentifyNameRef.current && cafeIdentifyNameRef.current.focus()}} style={styles.changeButton}>Ganti</div>
|
onClick={() => { setIsConfigCafeIdentityName(true); cafeIdentifyNameRef.current && cafeIdentifyNameRef.current.focus(); }} style={styles.changeButton}>Ganti
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</> : (
|
</> : (
|
||||||
<div style={{
|
<>
|
||||||
display: 'flex', justifyContent: 'space-between', width: '100%',
|
|
||||||
marginBottom: '10px'
|
|
||||||
}}>
|
|
||||||
<div
|
|
||||||
onClick={() => setIsConfigCafeIdentityName(false)} // Close the config modal
|
|
||||||
style={{
|
|
||||||
backgroundColor: '#303034',
|
|
||||||
width: '47%',
|
|
||||||
color: 'white',
|
|
||||||
borderRadius: '0 0 0px 6px',
|
|
||||||
fontFamily: 'Roboto',
|
|
||||||
fontSize: '13px',
|
|
||||||
padding: 3,
|
|
||||||
cursor: 'pointer',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Batalkan
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
<div style={styles.uploadMessage}>
|
||||||
onClick={() => {
|
<p>{cafeIdentifyNameUpdate == shop.cafeIdentifyName ?
|
||||||
setCafeIdentifyNameDefault(cafeIdentifyNameUpdate)
|
'-----------------' :
|
||||||
// Handle save functionality here
|
!isLoading && identifyNameResponse == 200 ?
|
||||||
setIsConfigCafeIdentityName(false); // Close after saving
|
'Alamat tersedia'
|
||||||
|
:
|
||||||
|
!isLoading && identifyNameResponse != 200 ?
|
||||||
|
'Alamat terpakai'
|
||||||
|
:
|
||||||
|
< ColorRing
|
||||||
|
height="16"
|
||||||
|
width="16" style={{ marginTop: '5px' }} />
|
||||||
|
|
||||||
}}
|
}
|
||||||
style={{
|
</p>
|
||||||
backgroundColor: '#303034',
|
|
||||||
width: '47%',
|
|
||||||
color: 'white',
|
|
||||||
borderRadius: '0 0 6px 0px',
|
|
||||||
fontFamily: 'Roboto',
|
|
||||||
fontSize: '13px',
|
|
||||||
padding: 3,
|
|
||||||
cursor: 'pointer',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Simpan
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div style={styles.resultMessage}>
|
||||||
|
<p>{cafeIdentifyNameUpdate != shop.cafeIdentifyName && identifyNameResponse == 200 && !isLoading ?
|
||||||
|
<div
|
||||||
|
onClick={() => setIsConfigCafeIdentityName(false)} style={styles.changeButton2}>Terapkan
|
||||||
|
</div>
|
||||||
|
:
|
||||||
|
'----------'}</p>
|
||||||
|
{isconfigcafeidentityname ?
|
||||||
|
<div
|
||||||
|
onClick={() => { setIdentifyNameResponse(0); setCafeIdentifyNameUpdate(shop.cafeIdentifyName); setIsConfigCafeIdentityName(false); }} style={styles.changeButton}>Batal
|
||||||
|
</div>
|
||||||
|
:
|
||||||
|
<div
|
||||||
|
onClick={() => { setIsConfigCafeIdentityName(true); cafeIdentifyNameRef.current && cafeIdentifyNameRef.current.focus(); }} style={styles.changeButton}>Ganti
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
{/* <div
|
||||||
|
onClick={() => { }} style={styles.changeButton}>Simpan
|
||||||
|
{isLoading &&
|
||||||
|
<ColorRing
|
||||||
|
height="20"
|
||||||
|
width="20" style={{ marginTop: '5px' }} />
|
||||||
|
}
|
||||||
|
</div> */}
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
<div
|
<div
|
||||||
id="qr-code-container"
|
id="qr-code-container"
|
||||||
@@ -982,6 +1018,14 @@ const styles = {
|
|||||||
lineHeight: '32px',
|
lineHeight: '32px',
|
||||||
paddingLeft: '10px',
|
paddingLeft: '10px',
|
||||||
paddingHeight: '10px',
|
paddingHeight: '10px',
|
||||||
|
marginBottom: '22px',
|
||||||
|
width: '80px',
|
||||||
|
textAlign: 'center'
|
||||||
|
},
|
||||||
|
changeButton2: {
|
||||||
|
color: 'black',
|
||||||
|
fontWeight: 700,
|
||||||
|
textAlign: 'left'
|
||||||
},
|
},
|
||||||
uploadButton: {
|
uploadButton: {
|
||||||
paddingRight: '10px',
|
paddingRight: '10px',
|
||||||
@@ -1003,6 +1047,13 @@ const styles = {
|
|||||||
display: 'flex',
|
display: 'flex',
|
||||||
justifyContent: 'space-between'
|
justifyContent: 'space-between'
|
||||||
},
|
},
|
||||||
|
resultMessage2: {
|
||||||
|
marginTop: "-24px",
|
||||||
|
marginBottom: "10px",
|
||||||
|
textAlign: "left",
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'space-evenly'
|
||||||
|
},
|
||||||
buttonContainer: {
|
buttonContainer: {
|
||||||
marginTop: "20px",
|
marginTop: "20px",
|
||||||
textAlign: "left",
|
textAlign: "left",
|
||||||
|
|||||||
@@ -122,7 +122,6 @@ const App = ({ forCafe = true, cafeId = -1,
|
|||||||
const [graphFilter, setGraphFilter] = useState("income");
|
const [graphFilter, setGraphFilter] = useState("income");
|
||||||
|
|
||||||
const [itemName, setItemName] = useState('');
|
const [itemName, setItemName] = useState('');
|
||||||
|
|
||||||
const fetchData = async (filter) => {
|
const fetchData = async (filter) => {
|
||||||
if (selectedCafeId == '-1') return;
|
if (selectedCafeId == '-1') return;
|
||||||
console.log(selectedCafeId, filter)
|
console.log(selectedCafeId, filter)
|
||||||
@@ -573,12 +572,12 @@ const App = ({ forCafe = true, cafeId = -1,
|
|||||||
loading={loading}
|
loading={loading}
|
||||||
value={'Rp'+analytics?.currentTotals?.totalPromoSpend}
|
value={'Rp'+analytics?.currentTotals?.totalPromoSpend}
|
||||||
width= {`calc(${!forCafe && selectedCafeId !== 0 ? '50%' : '100%'} - 10px)`}
|
width= {`calc(${!forCafe && selectedCafeId !== 0 ? '50%' : '100%'} - 10px)`}
|
||||||
onClick={() => window.location.href = window.location.origin + '/' + otherCafes.find(item => item.cafeId === selectedCafeId).cafeIdentifyName}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{!forCafe && selectedCafeId != -1 && selectedCafeId != 0 && (
|
{!forCafe && selectedCafeId != -1 && selectedCafeId != 0 && (
|
||||||
<RoundedRectangle
|
<RoundedRectangle
|
||||||
title={"Kunjungi bisnis"}
|
title={"Kunjungi"}
|
||||||
|
value={"bisnis"}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
width= {`calc(${selectedCafeId !== 0 ? '50%' : '100%'} - 10px)`}
|
width= {`calc(${selectedCafeId !== 0 ? '50%' : '100%'} - 10px)`}
|
||||||
onClick={() => window.location.href = window.location.origin + '/' + otherCafes.find(item => item.cafeId === selectedCafeId).cafeIdentifyName}
|
onClick={() => window.location.href = window.location.origin + '/' + otherCafes.find(item => item.cafeId === selectedCafeId).cafeIdentifyName}
|
||||||
|
|||||||
Reference in New Issue
Block a user