add alerts
This commit is contained in:
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "hpos-dashboard",
|
||||
"name": "hpos-web",
|
||||
"version": "0.1.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "hpos-dashboard",
|
||||
"name": "hpos-web",
|
||||
"version": "0.1.0",
|
||||
"dependencies": {
|
||||
"@testing-library/jest-dom": "^5.16.5",
|
||||
|
||||
10
src/components/Alerts.css
Normal file
10
src/components/Alerts.css
Normal file
@@ -0,0 +1,10 @@
|
||||
.alert-card {
|
||||
width: 40vw;
|
||||
height: 20vh;
|
||||
background-color: white;
|
||||
margin: 10px;
|
||||
border-style: solid;
|
||||
border-color: rgb(219, 219, 219);
|
||||
border-radius: 6px;
|
||||
border-width: max(1px, 0.0625rem);
|
||||
}
|
||||
43
src/components/Alerts.js
Normal file
43
src/components/Alerts.js
Normal file
@@ -0,0 +1,43 @@
|
||||
import React, { useEffect, useState, useRef } from 'react';
|
||||
import { query, collection, onSnapshot } from 'firebase/firestore';
|
||||
|
||||
import './Alerts.css';
|
||||
import db from '../firebase';
|
||||
|
||||
const Alerts = () => {
|
||||
const [alerts, setAlerts] = useState([]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!alerts.length) {
|
||||
const q = query(collection(db, "alerts"));
|
||||
|
||||
const unsub = onSnapshot(q, (querySnapshot) => {
|
||||
const testDevices = new Set();
|
||||
const hposTests = [];
|
||||
querySnapshot.forEach((document) => {
|
||||
console.log(document.data());
|
||||
const hposTestData = document.data();
|
||||
hposTests.push(hposTestData);
|
||||
const { deviceSerialNumber } = hposTestData;
|
||||
testDevices.add(deviceSerialNumber);
|
||||
});
|
||||
const groups = [...testDevices];
|
||||
// setDevices(groups);
|
||||
setAlerts(hposTests);
|
||||
});
|
||||
|
||||
return () => unsub;
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{alerts.length &&
|
||||
alerts.map((alert) => <div key={alert.id} className='alert-card'>
|
||||
{alert.message}
|
||||
</div>)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default Alerts;
|
||||
@@ -15,6 +15,18 @@ import { getAnalytics } from "firebase/analytics";
|
||||
// };
|
||||
|
||||
|
||||
// /* preprod */
|
||||
// const firebaseConfig = {
|
||||
// apiKey: "AIzaSyB2-suWmKh2PgQbRmx7rzPjYhgoovQIsQ8",
|
||||
// authDomain: "hpos-preprod.firebaseapp.com",
|
||||
// projectId: "hpos-preprod",
|
||||
// storageBucket: "hpos-preprod.appspot.com",
|
||||
// messagingSenderId: "121176529204",
|
||||
// appId: "1:121176529204:web:6c0db8e642992192bbed61",
|
||||
// measurementId: "G-GYM6LRQ8KR"
|
||||
// };
|
||||
|
||||
|
||||
/* prod */
|
||||
const firebaseConfig = {
|
||||
apiKey: "AIzaSyBF4pLZReAedU4dWX1eRJNFNIaOIz2xk4s",
|
||||
|
||||
@@ -13,6 +13,7 @@ import TestAnalytics from './components/TestAnalytics';
|
||||
import WorldMap from './components/WorldMap';
|
||||
import RegistraionChart from './RegistraionChart';
|
||||
import Calibrations from './components/Calibrations';
|
||||
import Alerts from './components/Alerts';
|
||||
|
||||
const router = createBrowserRouter([
|
||||
{
|
||||
@@ -43,6 +44,10 @@ const router = createBrowserRouter([
|
||||
path: "/op",
|
||||
element: <AppOp />,
|
||||
},
|
||||
{
|
||||
path: "/alerts",
|
||||
element: <Alerts />,
|
||||
},
|
||||
]);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user