Commit baaac0df authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

update show order in report

parent b65e1604
...@@ -9,15 +9,12 @@ import TableRow from "@mui/material/TableRow"; ...@@ -9,15 +9,12 @@ import TableRow from "@mui/material/TableRow";
import Title from "./Title"; import Title from "./Title";
import { UserContext } from "@/pages/_app"; import { UserContext } from "@/pages/_app";
import { AdminOrderContext } from "../layout/AdminLayout"; import { AdminOrderContext } from "../layout/AdminLayout";
import axios from "axios";
function preventDefault(event) {
event.preventDefault();
}
export default function Orders() { export default function Orders() {
const user = React.useContext(UserContext);
const adminOrder = React.useContext(AdminOrderContext); const adminOrder = React.useContext(AdminOrderContext);
const [orderRecent, setOrderRecent] = React.useState([]); const [orderRecent, setOrderRecent] = React.useState([]);
const [userAll, setUserAll] = React.useState([]);
React.useEffect(() => { React.useEffect(() => {
let order_r = []; let order_r = [];
...@@ -27,6 +24,15 @@ export default function Orders() { ...@@ -27,6 +24,15 @@ export default function Orders() {
setOrderRecent(order_r); setOrderRecent(order_r);
}, [adminOrder]); }, [adminOrder]);
React.useEffect(() => {
axios
.get("/api/user")
.then((res) => {
setUserAll(res.data);
})
.catch((err) => console.log(err));
}, []);
return ( return (
<React.Fragment> <React.Fragment>
<Title>ออเดอร์ล่าสุด</Title> <Title>ออเดอร์ล่าสุด</Title>
...@@ -38,7 +44,7 @@ export default function Orders() { ...@@ -38,7 +44,7 @@ export default function Orders() {
"id", "id",
"ราคาทั้งหมด", "ราคาทั้งหมด",
"วันที่", "วันที่",
"จำนวนสินค้า", "ผู้ซื้อ",
"ค่าส่ง", "ค่าส่ง",
"ชำระเงิน", "ชำระเงิน",
].map((label, idx) => ( ].map((label, idx) => (
...@@ -62,8 +68,13 @@ export default function Orders() { ...@@ -62,8 +68,13 @@ export default function Orders() {
{new Date(order.date).toLocaleString()} {new Date(order.date).toLocaleString()}
</Link> </Link>
</TableCell> </TableCell>
<TableCell>{order.product_count}</TableCell> <TableCell>
<TableCell>{order.shipping_price}</TableCell> {userAll.length
? userAll?.filter((usr) => usr.id === order.user_id)[0]
.name ?? "undifined"
: "undifined"}
</TableCell>
<TableCell>${order.shipping_price}</TableCell>
<TableCell> <TableCell>
<Box color={order.pay_status ? "green" : "red"}> <Box color={order.pay_status ? "green" : "red"}>
{order.pay_status ? "ชำระเงินแล้ว" : "ยังไม่ชำระเงิน"} {order.pay_status ? "ชำระเงินแล้ว" : "ยังไม่ชำระเงิน"}
...@@ -76,7 +87,9 @@ export default function Orders() { ...@@ -76,7 +87,9 @@ export default function Orders() {
</Table> </Table>
</div> </div>
<Box sx={{ pt: 2 }}> <Box sx={{ pt: 2 }}>
<Link className="text-blue-600" href="/admin/order">ดูออเดอร์ทั้งหมด</Link> <Link className="text-blue-600" href="/admin/order">
ดูออเดอร์ทั้งหมด
</Link>
</Box> </Box>
</React.Fragment> </React.Fragment>
); );
......
...@@ -110,7 +110,11 @@ export default function Order() { ...@@ -110,7 +110,11 @@ export default function Order() {
</Link> </Link>
</TableCell> </TableCell>
<TableCell> <TableCell>
{userAll.filter((usr) => usr.id === order.user_id)[0].name} {userAll.length
? userAll?.filter(
(usr) => usr.id === order.user_id
)[0].name ?? "undifined"
: "undifined"}
</TableCell> </TableCell>
<TableCell> <TableCell>
<Box color="black">${order.shipping_price}</Box> <Box color="black">${order.shipping_price}</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