add alerts commponents
This commit is contained in:
0
src/components/Alerts.css
Normal file
0
src/components/Alerts.css
Normal file
39
src/components/Alerts.js
Normal file
39
src/components/Alerts.js
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
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 (!allTests) {
|
||||||
|
const q = query(collection(db, "alerts"));
|
||||||
|
|
||||||
|
const unsub = onSnapshot(q, (querySnapshot) => {
|
||||||
|
const testDevices = new Set();
|
||||||
|
const hposTests = [];
|
||||||
|
querySnapshot.forEach((document) => {
|
||||||
|
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}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Alerts;
|
||||||
Reference in New Issue
Block a user