Revised initial state for monitors
This commit is contained in:
1 parent
ccb61004bb
commit
fbe357091a
2 files changed
+25
-35
No files matched your search
@@ -1,34 +1,20 @@
|
|||||||
import { createSlice } from "@reduxjs/toolkit";
|
import { createSlice } from "@reduxjs/toolkit";
|
||||||
|
|
||||||
const initialState = [
|
const initialState = {
|
||||||
{
|
isLoading: false,
|
||||||
_id: 1,
|
monitors: [],
|
||||||
userId: 1,
|
success: null,
|
||||||
name: "Google",
|
msg: null,
|
||||||
description: "Search engine",
|
};
|
||||||
url: "https://www.google.com",
|
|
||||||
isActive: true,
|
|
||||||
interval: 1000,
|
|
||||||
createdAt: "2021-01",
|
|
||||||
updatedAt: "2021-01",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
_id: 2,
|
|
||||||
userId: 1,
|
|
||||||
name: "Yahoo",
|
|
||||||
description: "Search engine",
|
|
||||||
url: "https://www.yahoo.com",
|
|
||||||
isActive: true,
|
|
||||||
interval: 1000,
|
|
||||||
createdAt: "2021-01",
|
|
||||||
updatedAt: "2021-01",
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const monitorsSlice = createSlice({
|
const monitorsSlice = createSlice({
|
||||||
name: "monitors",
|
name: "monitors",
|
||||||
initialState,
|
initialState,
|
||||||
reducers: { setMonitors: (state, action) => action.payload },
|
reducers: {
|
||||||
|
setMonitors: (state, action) => {
|
||||||
|
state.monitors = action.payload;
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const { setMonitors } = monitorsSlice.actions;
|
export const { setMonitors } = monitorsSlice.actions;
|
||||||
|
|||||||
@@ -180,8 +180,8 @@ const Demo = () => {
|
|||||||
// *********************************
|
// *********************************
|
||||||
// Redux Demo
|
// Redux Demo
|
||||||
// *********************************
|
// *********************************
|
||||||
const monitors = useSelector((state) => state.monitors);
|
const monitorState = useSelector((state) => state.monitors);
|
||||||
|
const { monitors } = monitorState;
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div style={{ padding: "4rem", border: "1px solid black" }}>
|
<div style={{ padding: "4rem", border: "1px solid black" }}>
|
||||||
@@ -195,14 +195,17 @@ const Demo = () => {
|
|||||||
<th style={{ border: "1px solid black" }}>Name</th>
|
<th style={{ border: "1px solid black" }}>Name</th>
|
||||||
<th style={{ border: "1px solid black" }}>URL</th>
|
<th style={{ border: "1px solid black" }}>URL</th>
|
||||||
</tr>
|
</tr>
|
||||||
{monitors.map((monitor) => {
|
{monitors &&
|
||||||
return (
|
monitors.map((monitor) => {
|
||||||
<tr key={monitor._id}>
|
return (
|
||||||
<td style={{ border: "1px solid black" }}>{monitor.name}</td>
|
<tr key={monitor._id}>
|
||||||
<td style={{ border: "1px solid black" }}>{monitor.url}</td>
|
<td style={{ border: "1px solid black" }}>
|
||||||
</tr>
|
{monitor.name}
|
||||||
);
|
</td>
|
||||||
})}
|
<td style={{ border: "1px solid black" }}>{monitor.url}</td>
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<Button
|
<Button
|
||||||
@@ -215,6 +218,7 @@ const Demo = () => {
|
|||||||
);
|
);
|
||||||
const monitorsResponse = response.data;
|
const monitorsResponse = response.data;
|
||||||
const monitors = monitorsResponse.data;
|
const monitors = monitorsResponse.data;
|
||||||
|
console.log(monitors);
|
||||||
dispatch(setMonitors(monitors));
|
dispatch(setMonitors(monitors));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|||||||
Reference in new issue
Block a user