diff --git a/src/components/Modal.js b/src/components/Modal.js index b0ba77c..70af5b3 100644 --- a/src/components/Modal.js +++ b/src/components/Modal.js @@ -7,7 +7,6 @@ import CreateCafe from "../pages/CreateCafe" import CreateTenant from "../pages/CreateTenant" import TablesPage from "./TablesPage.js"; import PaymentOptions from "./PaymentOptions.js"; -import TableMaps from "../components/TableMaps"; import Transaction from "../pages/Transaction"; import Transaction_pending from "../pages/Transaction_pending"; import Transaction_confirmed from "../pages/Transaction_confirmed"; diff --git a/src/components/TablesPage.js b/src/components/TablesPage.js index f6cf73e..43ed86d 100644 --- a/src/components/TablesPage.js +++ b/src/components/TablesPage.js @@ -1,5 +1,5 @@ import React, { useState, useRef, useEffect } from "react"; -import jsQR from "jsqr"; +import API_BASE_URL from "../config.js"; import { getImageUrl } from "../helpers/itemHelper"; import { getTables, updateTable, createTable } from "../helpers/tableHelper"; import { @@ -9,6 +9,7 @@ import { } from "../helpers/cafeHelpers"; import { toPng } from 'html-to-image'; +import { ColorRing } from "react-loader-spinner"; const SetPaymentQr = ({ shop }) => { const [initialPos, setInitialPos] = useState({ @@ -29,7 +30,6 @@ 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; @@ -59,6 +59,8 @@ const SetPaymentQr = ({ shop }) => { const [selectedTable, setSelectedTable] = useState(null); const [tableNo, setTableNo] = useState(null); + const [isLoading, setIsLoading] = useState(false); + const [identifyNameResponse, setIdentifyNameResponse] = useState('-----------------'); useEffect(() => { 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 (
Klik untuk ganti alamat
{ setIsConfigCafeIdentityName(true); cafeIdentifyNameRef.current && cafeIdentifyNameRef.current.focus() }}>-----------------
+-----------------
{cafeIdentifyNameUpdate == shop.cafeIdentifyName ? + '-----------------' : + !isLoading && identifyNameResponse == 200 ? + 'Alamat tersedia' + : + !isLoading && identifyNameResponse != 200 ? + 'Alamat terpakai' + : + < ColorRing + height="16" + width="16" style={{ marginTop: '5px' }} /> - }} - style={{ - backgroundColor: '#303034', - width: '47%', - color: 'white', - borderRadius: '0 0 6px 0px', - fontFamily: 'Roboto', - fontSize: '13px', - padding: 3, - cursor: 'pointer', - }} - > - Simpan + } +
{cafeIdentifyNameUpdate != shop.cafeIdentifyName && identifyNameResponse == 200 && !isLoading ? +