Commit 5f1c16ca authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

filter at order admin

parent 7b33dfbd
...@@ -16,13 +16,17 @@ import { ...@@ -16,13 +16,17 @@ import {
FormControl, FormControl,
Select, Select,
MenuItem, MenuItem,
Button,
} from "@mui/material"; } from "@mui/material";
import { useRouter } from "next/router";
export default function Order() { export default function Order() {
const user = useContext(UserContext); const user = useContext(UserContext);
const router = useRouter();
const adminOrder = useContext(AdminOrderContext); const adminOrder = useContext(AdminOrderContext);
const [message, setMessage] = useState({ message: "", error: false }); const [message, setMessage] = useState({ message: "", error: false });
const [userAll, setUserAll] = useState([]); const [userAll, setUserAll] = useState([]);
const [payStatusFilter, setPayStatusFilter] = useState(0);
useEffect(() => { useEffect(() => {
axios axios
...@@ -70,6 +74,15 @@ export default function Order() { ...@@ -70,6 +74,15 @@ export default function Order() {
isError={message.error} isError={message.error}
message={message.message} message={message.message}
/> />
<Box sx={{ maxWidth: 1200, mx: "auto" }}>
<Box sx={{ textAlign: "right", mb: 2 }}>
<Button
onClick={() => setPayStatusFilter(!payStatusFilter)}
variant={payStatusFilter ? "contained" : "text"}
>
ยังไม่ชำระเงิน
</Button>
</Box>
<Paper sx={{ p: 1, overflowX: "scroll" }}> <Paper sx={{ p: 1, overflowX: "scroll" }}>
{adminOrder.value?.length > 0 ? ( {adminOrder.value?.length > 0 ? (
<Box> <Box>
...@@ -93,6 +106,9 @@ export default function Order() { ...@@ -93,6 +106,9 @@ export default function Order() {
<TableBody> <TableBody>
{adminOrder.value.map( {adminOrder.value.map(
(order, idx) => (order, idx) =>
(!payStatusFilter || order.pay_status === 0) &&
(!router.query?.q ||
order.id === Number(router.query.q)) &&
order && ( order && (
<TableRow key={idx}> <TableRow key={idx}>
<TableCell>{order.id}</TableCell> <TableCell>{order.id}</TableCell>
...@@ -159,10 +175,13 @@ export default function Order() { ...@@ -159,10 +175,13 @@ export default function Order() {
</Box> </Box>
) : ( ) : (
<div className="text-center"> <div className="text-center">
{user.value?.token ? "รายการว่างเปล่า" : "คุณยังไม่ได้เข้าสู่ระบบ"} {user.value?.token
? "รายการว่างเปล่า"
: "คุณยังไม่ได้เข้าสู่ระบบ"}
</div> </div>
)} )}
</Paper> </Paper>
</Box>
</> </>
); );
} }
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