Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
final-exam
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nawasan Wisitsingkhon
final-exam
Commits
0bca33ff
Commit
0bca33ff
authored
Oct 01, 2023
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
create: show product for admin;
fix: prisma schema image size;
parent
249022e7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
83 additions
and
31 deletions
+83
-31
migration.sql
prisma/migrations/20231001054534_/migration.sql
+2
-0
migration.sql
prisma/migrations/20231001054815_dev/migration.sql
+2
-0
migration.sql
prisma/migrations/20231001055031_dev/migration.sql
+2
-0
schema.prisma
prisma/schema.prisma
+3
-3
empty.jpg
public/empty.jpg
+0
-0
AddProduct.js
src/components/AddProduct.js
+1
-0
stock.js
src/pages/admin/stock.js
+73
-28
No files found.
prisma/migrations/20231001054534_/migration.sql
0 → 100644
View file @
0bca33ff
-- AlterTable
ALTER
TABLE
`product`
MODIFY
`image`
LONGTEXT
NOT
NULL
;
prisma/migrations/20231001054815_dev/migration.sql
0 → 100644
View file @
0bca33ff
-- AlterTable
ALTER
TABLE
`product`
MODIFY
`detail`
LONGTEXT
NOT
NULL
;
prisma/migrations/20231001055031_dev/migration.sql
0 → 100644
View file @
0bca33ff
-- AlterTable
ALTER
TABLE
`user`
MODIFY
`photo`
LONGTEXT
NOT
NULL
;
prisma/schema.prisma
View file @
0bca33ff
...
...
@@ -15,7 +15,7 @@ model user {
name
String
email
String
phone
String
photo
String
photo
String
@
db
.
LongText
google_token
String
username
String
@
unique
password
String
...
...
@@ -30,14 +30,14 @@ model user {
model
product
{
id
Int
@
id
@
default
(
autoincrement
())
name
String
detail
String
detail
String
@
db
.
LongText
price
Int
discount
Int
cate
category
@
relation
(
fields
:
[
cateId
],
references
:
[
id
])
cateId
Int
watch_count
Int
buy_count
Int
image
String
image
String
@
db
.
LongText
stock
Int
wishlist
wishlist
[]
cart
cart
[]
...
...
public/empty.jpg
0 → 100644
View file @
0bca33ff
7.17 KB
src/components/AddProduct.js
View file @
0bca33ff
...
...
@@ -62,6 +62,7 @@ export default function AddProduct({ open, handleClose }) {
setImage
(
""
);
setCategory
(
0
);
setMessage
({
message
:
"เพิ่มสินค้าสำเร็จ"
,
error
:
false
});
handleClose
()
setTimeout
(()
=>
{
setMessage
({
message
:
""
,
error
:
false
});
},
3000
);
...
...
src/pages/admin/stock.js
View file @
0bca33ff
...
...
@@ -3,18 +3,41 @@ import AddProduct from "@/components/AddProduct";
import
{
Box
,
Button
,
Grid
,
Card
,
CardActions
,
CardContent
,
CardHeader
,
CardMedia
,
Paper
,
Table
,
TableBody
,
TableCell
,
TableHead
,
TableRow
,
Typography
,
}
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
()
{
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
(
<
Box
>
<
Box
sx
=
{{
mb
:
2
,
textAlign
:
"right"
}}
>
...
...
@@ -23,31 +46,53 @@ export default function Stock() {
เพิ่มสินค้า
<
/Button
>
<
/Box
>
<
Paper
sx
=
{{
p
:
2
,
}}
>
<
Table
>
<
TableHead
>
<
TableRow
>
<
TableCell
>
hello
<
/TableCell
>
<
TableCell
>
hello
<
/TableCell
>
<
TableCell
>
hello
<
/TableCell
>
<
TableCell
>
hello
<
/TableCell
>
<
/TableRow
>
<
/TableHead
>
<
TableBody
>
<
TableRow
>
<
TableCell
>
hello
<
/TableCell
>
<
TableCell
>
hello
<
/TableCell
>
<
TableCell
>
hello
<
/TableCell
>
<
TableCell
>
hello
<
/TableCell
>
<
/TableRow
>
<
/TableBody
>
<
/Table
>
<
/Paper
>
<
AddProduct
open
=
{
modal
}
handleClose
=
{()
=>
setModal
(
false
)}
/
>
{
products
.
map
((
product
,
idx
)
=>
(
<
Card
sx
=
{{
m
:
1
,
px
:
1
,
width
:
300
,
height
:
500
,
display
:
"inline-block"
}}
>
<
Box
sx
=
{{
px
:
1
}}
>
<
h5
className
=
"h-[40px] overflow-y-hidden"
>
{
product
.
name
}
<
/h5
>
<
/Box
>
<
CardMedia
className
=
"rounded"
component
=
{
"img"
}
height
=
{
150
}
image
=
{
product
.
image
.
length
?
product
.
image
:
"/empty.jpg"
}
/
>
<
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
>
<
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
>
<
TableCell
>
เข้าชม
{
product
.
watch_count
}
ครั้ง
<
/TableCell
>
<
TableCell
>
คงเหลือ
{
product
.
stock
}
ชิ้น
<
/TableCell
>
<
/TableRow
>
<
/TableBody
>
<
/Table
>
<
/CardContent
>
<
CardActions
disableSpacing
sx
=
{{
justifyContent
:
"end"
}}
>
<
Button
color
=
"warning"
>
<
Edit
/>
แก้ไข
<
/Button
>
<
Button
color
=
"error"
>
<
Delete
/>
ลบ
<
/Button
>
<
/CardActions
>
<
/Card
>
))}
<
AddProduct
open
=
{
modal
}
handleClose
=
{()
=>
setModal
(
false
)}
/
>
<
/Box
>
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment