add alerts

This commit is contained in:
Pritimay Sarkar
2023-09-19 22:43:46 +05:30
parent 4ce2178af5
commit 97b592ce72
5 changed files with 72 additions and 2 deletions

4
package-lock.json generated
View File

@@ -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
View 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
View 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;

View File

@@ -14,6 +14,18 @@ import { getAnalytics } from "firebase/analytics";
// measurementId: "G-6JHQ47S9DD"
// };
// /* 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 = {

View File

@@ -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 />,
},
]);