diff --git a/frontend/src/App.css b/frontend/src/App.css index 4b14ecf..467c548 100644 --- a/frontend/src/App.css +++ b/frontend/src/App.css @@ -4,11 +4,3 @@ min-height: 100vh; width: 100%; } - -.card { - padding: 2em; -} - -.read-the-docs { - color: #888; -} diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 0f6f5f6..2f4a741 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -1,99 +1,78 @@ import { useState } from 'react'; import BarcodeScannerComponent from 'react-qr-barcode-scanner'; -import toast, { Toaster } from 'react-hot-toast'; import { Container, Row, Col } from 'react-bootstrap'; +import Table from 'react-bootstrap/Table'; +import Alert from 'react-bootstrap/Alert'; -// Styles import './App.css'; import 'bootstrap/dist/css/bootstrap.min.css'; function App() { - // State to store the latest scanned data - const [currentData, setCurrentData] = useState('No result'); - - // State to store an array of scanned results for history tracking - const [scanHistory, setScanHistory] = useState([]); - - /** - * Handles the scanning result. - * @param {Error} err - Error, if any, from the scanner. - * @param {Object} result - The scanning result object. - */ - const handleScan = (err, result) => { - if (result) { - // Update current data and add it to the scan history - setCurrentData(result.text); - setScanHistory(prevHistory => [...prevHistory, result.text]); - - // Show a success notification using toast - toast.success(`Product scanned: ${result.text}`); - } else { - setCurrentData('No result'); // Set message if no result - } - }; + const [reqAccount, setReqAccount] = useState(''); + const [actAccount, setActAccount] = useState(''); + const [balance, setBalance] = useState(-1); + const [statusMsg, setStatusMsg] = useState(''); + const [msgType, setMsgType] = useState('info'); + + const handleScan = async (err, result) => { + if (result) { + const ra = result.text; + setReqAccount(ra); + setStatusMsg('Loading'); + setMsgType('primary'); + try { + const resp = await fetch('/api/barcode/' + ra); + if (resp.ok) { + const json = await resp.json(); + setActAccount(ra); + setBalance(json.amount); + setStatusMsg('OK'); + setMsgType('success'); + } + } catch(ex) { + setMsgType('danger'); + setStatusMsg(ex.message); + } + } + }; return ( - {/* Notification toaster for displaying scan success messages */} - + - - {/* Scanner title */} -
BrmInv
- -
- - - - - {/* Barcode scanner component */} -
- -
- -
- - - - {/* Display the current scanned data */} -

Scanned Data: {currentData}

- -
- - - - {/* Table to display scan history */} -

Scan History

- - - - - - - - - {scanHistory.map((result, index) => ( - - - +
#Scanned Result
{index + 1}{result}
+ + + - ))} - -
Requested:{reqAccount}
+ + Loaded: + {actAccount} + + + Balance: + {balance} + +
-
- ); - } + + + {statusMsg} + + + + ); +} - export default App; +export default App;