Fetch data from endpoint instead of redux store
This commit is contained in:
1 parent
407edb6344
commit
5c1bb7ca6a
2 files changed
+18
-7
No files matched your search
@@ -1,20 +1,29 @@
|
|||||||
import React from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import CustomizedTables from "../../Components/CustomizedTables";
|
import CustomizedTables from "../../Components/CustomizedTables";
|
||||||
import { Box, Typography, useTheme } from "@mui/material";
|
import { Box, Typography, useTheme } from "@mui/material";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
|
import axiosInstance from "../../Utils/axiosConfig";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Details page component displaying monitor details and related information.
|
* Details page component displaying monitor details and related information.
|
||||||
* @component
|
* @component
|
||||||
*/
|
*/
|
||||||
const DetailsPage = () => {
|
const DetailsPage = () => {
|
||||||
const monitorState = useSelector((state) => state.monitors);
|
const [monitor, setMonitor] = useState({});
|
||||||
const { monitorId } = useParams();
|
const { monitorId } = useParams();
|
||||||
|
const { authToken } = useSelector((state) => state.auth);
|
||||||
const monitor = monitorState.monitors.find(
|
useEffect(() => {
|
||||||
(monitor) => monitor._id === monitorId
|
const fetchMonitor = async () => {
|
||||||
);
|
const res = await axiosInstance.get(`/monitors/${monitorId}`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${authToken}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
setMonitor(res.data.data);
|
||||||
|
};
|
||||||
|
fetchMonitor();
|
||||||
|
}, [monitorId, authToken]);
|
||||||
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
|
|||||||
@@ -272,7 +272,9 @@ const getAllMonitors = async (req, res) => {
|
|||||||
const getMonitorById = async (req, res) => {
|
const getMonitorById = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const monitor = await Monitor.findById(req.params.monitorId);
|
const monitor = await Monitor.findById(req.params.monitorId);
|
||||||
const checks = await Check.find({ monitorId: monitor._id });
|
const checks = await Check.find({ monitorId: monitor._id }).sort({
|
||||||
|
createdAt: -1,
|
||||||
|
});
|
||||||
const monitorWithChecks = { ...monitor.toObject(), checks };
|
const monitorWithChecks = { ...monitor.toObject(), checks };
|
||||||
return monitorWithChecks;
|
return monitorWithChecks;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in new issue
Block a user