Hooked up search to state
This commit is contained in:
1 parent
594509f3d9
commit
200c5fa523
2 files changed
+16
-16
No files matched your search
@@ -3,25 +3,21 @@ import { Box, ListItem, Autocomplete, TextField } from "@mui/material";
|
|||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import SearchIcon from "../../../assets/icons/search.svg?react";
|
import SearchIcon from "../../../assets/icons/search.svg?react";
|
||||||
|
|
||||||
const options = [
|
const Search = ({ id, options, value, handleChange, sx }) => {
|
||||||
"Google",
|
|
||||||
"Material UI",
|
|
||||||
"Alias",
|
|
||||||
"Twitter",
|
|
||||||
"Discord",
|
|
||||||
"YouTube",
|
|
||||||
];
|
|
||||||
|
|
||||||
const Search = ({ id, sx }) => {
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Autocomplete
|
<Autocomplete
|
||||||
id={id}
|
id={id}
|
||||||
|
inputValue={value}
|
||||||
|
onInputChange={(event, newValue) => {
|
||||||
|
handleChange(newValue);
|
||||||
|
}}
|
||||||
fullWidth
|
fullWidth
|
||||||
freeSolo
|
freeSolo
|
||||||
disableClearable
|
disableClearable
|
||||||
options={options}
|
options={options}
|
||||||
|
getOptionLabel={(option) => option.name}
|
||||||
renderInput={(params) => (
|
renderInput={(params) => (
|
||||||
<TextField
|
<TextField
|
||||||
{...params}
|
{...params}
|
||||||
@@ -61,11 +57,11 @@ const Search = ({ id, sx }) => {
|
|||||||
)}
|
)}
|
||||||
filterOptions={(options, { inputValue }) => {
|
filterOptions={(options, { inputValue }) => {
|
||||||
const filtered = options.filter((option) =>
|
const filtered = options.filter((option) =>
|
||||||
option.toLowerCase().includes(inputValue.toLowerCase())
|
option.name.toLowerCase().includes(inputValue.toLowerCase())
|
||||||
);
|
);
|
||||||
|
|
||||||
if (filtered.length === 0) {
|
if (filtered.length === 0) {
|
||||||
return [{ label: "No monitors found", noOptions: true }];
|
return [{ name: "No monitors found", noOptions: true }];
|
||||||
}
|
}
|
||||||
return filtered;
|
return filtered;
|
||||||
}}
|
}}
|
||||||
@@ -84,7 +80,7 @@ const Search = ({ id, sx }) => {
|
|||||||
: {}
|
: {}
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{option.noOptions ? option.label : option}
|
{option.name}
|
||||||
</ListItem>
|
</ListItem>
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import "./index.css";
|
import "./index.css";
|
||||||
import { useEffect } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
import { getUptimeMonitorsByTeamId } from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
import { getUptimeMonitorsByTeamId } from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
@@ -19,6 +19,7 @@ const Monitors = ({ isAdmin }) => {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const monitorState = useSelector((state) => state.uptimeMonitors);
|
const monitorState = useSelector((state) => state.uptimeMonitors);
|
||||||
const authState = useSelector((state) => state.auth);
|
const authState = useSelector((state) => state.auth);
|
||||||
|
const [search, setSearch] = useState("");
|
||||||
const dispatch = useDispatch({});
|
const dispatch = useDispatch({});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -28,7 +29,6 @@ const Monitors = ({ isAdmin }) => {
|
|||||||
monitorState?.isLoading &&
|
monitorState?.isLoading &&
|
||||||
monitorState?.monitorsSummary?.monitors?.length === 0;
|
monitorState?.monitorsSummary?.monitors?.length === 0;
|
||||||
|
|
||||||
console.log(monitorState.monitorsSummary.monitors);
|
|
||||||
return (
|
return (
|
||||||
<Stack className="monitors" gap={theme.spacing(8)}>
|
<Stack className="monitors" gap={theme.spacing(8)}>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
@@ -118,7 +118,11 @@ const Monitors = ({ isAdmin }) => {
|
|||||||
{monitorState?.monitorsSummary?.monitorCounts?.total || 0}
|
{monitorState?.monitorsSummary?.monitorCounts?.total || 0}
|
||||||
</Box>
|
</Box>
|
||||||
<Box width="25%" minWidth={150} ml="auto">
|
<Box width="25%" minWidth={150} ml="auto">
|
||||||
<Search />
|
<Search
|
||||||
|
options={monitorState?.monitorsSummary.monitors}
|
||||||
|
value={search}
|
||||||
|
handleChange={setSearch}
|
||||||
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
</Stack>
|
</Stack>
|
||||||
<MonitorTable isAdmin={isAdmin} />
|
<MonitorTable isAdmin={isAdmin} />
|
||||||
|
|||||||
Reference in new issue
Block a user