Commit 0bca33ff authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

create: show product for admin;

fix: prisma schema image size;
parent 249022e7
-- AlterTable
ALTER TABLE `product` MODIFY `image` LONGTEXT NOT NULL;
-- AlterTable
ALTER TABLE `product` MODIFY `detail` LONGTEXT NOT NULL;
-- AlterTable
ALTER TABLE `user` MODIFY `photo` LONGTEXT NOT NULL;
...@@ -15,7 +15,7 @@ model user { ...@@ -15,7 +15,7 @@ model user {
name String name String
email String email String
phone String phone String
photo String photo String @db.LongText
google_token String google_token String
username String @unique username String @unique
password String password String
...@@ -30,14 +30,14 @@ model user { ...@@ -30,14 +30,14 @@ model user {
model product { model product {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
name String name String
detail String detail String @db.LongText
price Int price Int
discount Int discount Int
cate category @relation(fields: [cateId], references: [id]) cate category @relation(fields: [cateId], references: [id])
cateId Int cateId Int
watch_count Int watch_count Int
buy_count Int buy_count Int
image String image String @db.LongText
stock Int stock Int
wishlist wishlist[] wishlist wishlist[]
cart cart[] cart cart[]
......
...@@ -62,6 +62,7 @@ export default function AddProduct({ open, handleClose }) { ...@@ -62,6 +62,7 @@ export default function AddProduct({ open, handleClose }) {
setImage(""); setImage("");
setCategory(0); setCategory(0);
setMessage({ message: "เพิ่มสินค้าสำเร็จ", error: false }); setMessage({ message: "เพิ่มสินค้าสำเร็จ", error: false });
handleClose()
setTimeout(() => { setTimeout(() => {
setMessage({ message: "", error: false }); setMessage({ message: "", error: false });
}, 3000); }, 3000);
......
...@@ -3,18 +3,41 @@ import AddProduct from "@/components/AddProduct"; ...@@ -3,18 +3,41 @@ import AddProduct from "@/components/AddProduct";
import { import {
Box, Box,
Button, Button,
Grid, Card,
CardActions,
CardContent,
CardHeader,
CardMedia,
Paper, Paper,
Table, Table,
TableBody, TableBody,
TableCell, TableCell,
TableHead, TableHead,
TableRow, TableRow,
Typography,
} from "@mui/material"; } from "@mui/material";
import {useState} from "react"; import { useState, useEffect } from "react";
import axios from "axios";
import { Delete } from "@mui/icons-material";
import { Edit } from "@mui/icons-material";
export default function Stock() { export default function Stock() {
const [modal, setModal] = useState(false) const [modal, setModal] = useState(false);
const [products, setProducts] = useState([]);
const [category, setCategory] = useState([]);
useEffect(() => {
axios.get("/api/product").then((res) => {
console.log(res.data);
setProducts(res.data);
});
}, [modal]);
useEffect(() => {
axios.get("/api/category").then((res) => {
setCategory(res.data);
});
}, []);
return ( return (
<Box> <Box>
<Box sx={{ mb: 2, textAlign: "right" }}> <Box sx={{ mb: 2, textAlign: "right" }}>
...@@ -23,30 +46,52 @@ export default function Stock() { ...@@ -23,30 +46,52 @@ export default function Stock() {
เพิ่มสินค้า เพิ่มสินค้า
</Button> </Button>
</Box> </Box>
<Paper {products.map((product, idx) => (
sx={{ <Card
p: 2, sx={{ m: 1, px: 1, width: 300, height: 500, display: "inline-block" }}
}}
> >
<Table> <Box sx={{ px: 1 }}>
<TableHead> <h5 className="h-[40px] overflow-y-hidden">{product.name}</h5>
<TableRow> </Box>
<TableCell>hello</TableCell> <CardMedia
<TableCell>hello</TableCell> className="rounded"
<TableCell>hello</TableCell> component={"img"}
<TableCell>hello</TableCell> height={150}
</TableRow> image={product.image.length ? product.image : "/empty.jpg"}
</TableHead> />
<CardContent sx={{ px: 1 }}>
<Typography
sx={{ height: 70, overflowY: "scroll" }}
variant="body2"
color={"text.secondary"}
>
{product.detail}
</Typography>
<Table sx={{ m: 0, p: 0 }}>
<TableBody> <TableBody>
<TableRow sx={{ m: 0, p: 0 }}>
<TableCell sx={{ m: 0, p: 0, textAlign: "center " }}>
{Number(product.price).toLocaleString() + " บาท"}
</TableCell>
<TableCell> {`ส่วนลด ${product.discount}%`}</TableCell>
</TableRow>
<TableRow> <TableRow>
<TableCell>hello</TableCell> <TableCell>เข้าชม {product.watch_count} ครั้ง</TableCell>
<TableCell>hello</TableCell> <TableCell>คงเหลือ {product.stock} ชิ้น</TableCell>
<TableCell>hello</TableCell>
<TableCell>hello</TableCell>
</TableRow> </TableRow>
</TableBody> </TableBody>
</Table> </Table>
</Paper> </CardContent>
<CardActions disableSpacing sx={{ justifyContent: "end" }}>
<Button color="warning">
<Edit /> แก้ไข
</Button>
<Button color="error">
<Delete /> ลบ
</Button>
</CardActions>
</Card>
))}
<AddProduct open={modal} handleClose={() => setModal(false)} /> <AddProduct open={modal} handleClose={() => setModal(false)} />
</Box> </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