From 924e48c1f0c57db487806a95aee4e5b7be76630b Mon Sep 17 00:00:00 2001 From: Pritimay Sarkar Date: Tue, 19 Sep 2023 15:39:43 +0530 Subject: [PATCH] add alerts commponents --- src/components/Alerts.css | 0 src/components/Alerts.js | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/components/Alerts.css create mode 100644 src/components/Alerts.js diff --git a/src/components/Alerts.css b/src/components/Alerts.css new file mode 100644 index 0000000..e69de29 diff --git a/src/components/Alerts.js b/src/components/Alerts.js new file mode 100644 index 0000000..e6c412c --- /dev/null +++ b/src/components/Alerts.js @@ -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 ( +
+ {alerts.length} +
+ ) +} + +export default Alerts; \ No newline at end of file