Commit d5d6f305 authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

search user in admin

parent 19c283bf
...@@ -73,8 +73,10 @@ function AdminNavbar(props) { ...@@ -73,8 +73,10 @@ function AdminNavbar(props) {
const [mobileOpen, setMobileOpen] = React.useState(false); const [mobileOpen, setMobileOpen] = React.useState(false);
React.useEffect(() => { React.useEffect(() => {
router.push({pathname: router.pathname, query: {q: search}}) if (search.length)
}, [search]) router.push({ pathname: router.pathname, query: { q: search } });
else router.push({ pathname: router.pathname });
}, [search]);
const handleDrawerToggle = () => { const handleDrawerToggle = () => {
setMobileOpen(!mobileOpen); setMobileOpen(!mobileOpen);
......
...@@ -4,8 +4,14 @@ import Head from "next/head"; ...@@ -4,8 +4,14 @@ import Head from "next/head";
import axios from "axios"; import axios from "axios";
import { import {
Alert, Alert,
Box,
Button, Button,
FormControl,
FormLabel,
InputLabel,
MenuItem,
Paper, Paper,
Select,
Snackbar, Snackbar,
Switch, Switch,
Table, Table,
...@@ -15,12 +21,27 @@ import { ...@@ -15,12 +21,27 @@ import {
TableRow, TableRow,
} from "@mui/material"; } from "@mui/material";
import DeleteMember from "@/components/member/DeleteMember"; import DeleteMember from "@/components/member/DeleteMember";
import { useRouter } from "next/router";
export default function Member() { export default function Member() {
const user = useContext(UserContext); const user = useContext(UserContext);
const router = useRouter();
const [userAll, setUserAll] = useState([]); const [userAll, setUserAll] = useState([]);
const [message, setMessage] = useState({ error: false, message: "" }); const [message, setMessage] = useState({ error: false, message: "" });
const [deleteState, setDeleteState] = useState({ open: false, id: -1 }); const [deleteState, setDeleteState] = useState({ open: false, id: -1 });
const [filterAdmin, setFilterAdmin] = useState(-1);
console.log(userAll);
const userAllFilter = !!router.query?.q
? userAll.filter(
(usr) =>
(filterAdmin === -1 || usr.rank === !filterAdmin) &&
(String(usr.name).includes(router.query.q) ||
String(usr.username).includes(router.query.q) ||
String(usr.phone).includes(router.query.q) ||
String(usr.id).includes(router.query.q))
)
: userAll.filter((usr) => filterAdmin === -1 || usr.rank === !filterAdmin);
async function changeRank(id, rank) { async function changeRank(id, rank) {
try { try {
...@@ -68,6 +89,19 @@ export default function Member() { ...@@ -68,6 +89,19 @@ export default function Member() {
{message.message} {message.message}
</Alert> </Alert>
</Snackbar> </Snackbar>
<Box sx={{ m: 1, textAlign: "right" }}>
<FormControl>
<Select
variant="standard"
value={filterAdmin}
onChange={(e) => setFilterAdmin(Number(e.target.value))}
>
<MenuItem value={-1}>ทั้งหมด</MenuItem>
<MenuItem value={0}>admin</MenuItem>
<MenuItem value={1}>ผู้ใช้</MenuItem>
</Select>
</FormControl>
</Box>
<Paper sx={{ p: 2 }}> <Paper sx={{ p: 2 }}>
<Table> <Table>
<TableHead> <TableHead>
...@@ -89,7 +123,7 @@ export default function Member() { ...@@ -89,7 +123,7 @@ export default function Member() {
</TableRow> </TableRow>
</TableHead> </TableHead>
<TableBody> <TableBody>
{userAll.map((user, idx) => ( {userAllFilter.map((user, idx) => (
<TableRow key={idx}> <TableRow key={idx}>
<TableCell>{user.id}</TableCell> <TableCell>{user.id}</TableCell>
<TableCell> <TableCell>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment