Commit 2fcb9a27 authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

search product

parent 85145f0b
...@@ -20,14 +20,20 @@ import { Delete } from "@mui/icons-material"; ...@@ -20,14 +20,20 @@ import { Delete } from "@mui/icons-material";
import { Edit } from "@mui/icons-material"; import { Edit } from "@mui/icons-material";
import UpdateProduct from "@/components/product/UpdateProduct"; import UpdateProduct from "@/components/product/UpdateProduct";
import DeleteProduct from "@/components/product/DeleteProduct"; import DeleteProduct from "@/components/product/DeleteProduct";
import { useRouter } from "next/router";
export default function Stock() { export default function Stock() {
const router = useRouter();
const [modal, setModal] = useState(false); const [modal, setModal] = useState(false);
const [products, setProducts] = useState([]); const [products, setProducts] = useState([]);
const [updateState, setUpdateState] = useState({ open: false, data: {} }); const [updateState, setUpdateState] = useState({ open: false, data: {} });
const [deleteState, setDeleteState] = useState({ open: false, id: -1 }); const [deleteState, setDeleteState] = useState({ open: false, id: -1 });
const [category, setCategory] = useState([]); const [category, setCategory] = useState([]);
const productsFilter = !!router.query?.q
? products.filter((prod) => String(prod.name).includes(router.query.q))
: products;
useEffect(() => { useEffect(() => {
axios.get("/api/product").then((res) => { axios.get("/api/product").then((res) => {
setProducts(res.data); setProducts(res.data);
...@@ -51,7 +57,7 @@ export default function Stock() { ...@@ -51,7 +57,7 @@ export default function Stock() {
เพิ่มสินค้า เพิ่มสินค้า
</Button> </Button>
</Box> </Box>
{products.map((product, idx) => ( {productsFilter.map((product, idx) => (
<Card <Card
key={idx} key={idx}
sx={{ sx={{
...@@ -101,7 +107,10 @@ export default function Stock() { ...@@ -101,7 +107,10 @@ export default function Stock() {
> >
<Edit /> แก้ไข <Edit /> แก้ไข
</Button> </Button>
<Button color="error" onClick={() => setDeleteState({open: true, id: product.id})}> <Button
color="error"
onClick={() => setDeleteState({ open: true, id: product.id })}
>
<Delete /> ลบ <Delete /> ลบ
</Button> </Button>
</CardActions> </CardActions>
......
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