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
7749aa23
Commit
7749aa23
authored
Oct 01, 2023
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
create state at create product ui
parent
d29e972b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
12 deletions
+38
-12
AddProduct.js
src/components/AddProduct.js
+38
-12
No files found.
src/components/AddProduct.js
View file @
7749aa23
import
*
as
React
from
"react"
;
import
{
useState
}
from
"react"
;
import
Button
from
"@mui/material/Button"
;
import
Button
from
"@mui/material/Button"
;
import
TextField
from
"@mui/material/TextField"
;
import
TextField
from
"@mui/material/TextField"
;
import
Dialog
from
"@mui/material/Dialog"
;
import
Dialog
from
"@mui/material/Dialog"
;
import
DialogActions
from
"@mui/material/DialogActions"
;
import
DialogActions
from
"@mui/material/DialogActions"
;
import
DialogContent
from
"@mui/material/DialogContent"
;
import
DialogContent
from
"@mui/material/DialogContent"
;
import
DialogTitle
from
"@mui/material/DialogTitle"
;
import
DialogTitle
from
"@mui/material/DialogTitle"
;
import
{
import
{
FormControl
,
InputLabel
,
MenuItem
,
Select
}
from
"@mui/material"
;
FormControl
,
InputLabel
,
MenuItem
,
Select
,
}
from
"@mui/material"
;
export
default
function
AddProduct
({
open
,
handleClose
})
{
export
default
function
AddProduct
({
open
,
handleClose
})
{
const
[
name
,
setName
]
=
useState
(
""
);
const
[
price
,
setPrice
]
=
useState
();
const
[
detail
,
setDetail
]
=
useState
(
""
);
const
[
discount
,
setDiscount
]
=
useState
();
const
[
stock
,
setStock
]
=
useState
();
const
[
image
,
setImage
]
=
useState
(
""
);
const
[
category
,
setCategory
]
=
useState
();
const
CategoryList
=
[
const
CategoryList
=
[
{
{
id
:
0
,
id
:
0
,
...
@@ -31,12 +34,22 @@ export default function AddProduct({ open, handleClose }) {
...
@@ -31,12 +34,22 @@ export default function AddProduct({ open, handleClose }) {
<
Dialog
open
=
{
open
}
onClose
=
{
handleClose
}
>
<
Dialog
open
=
{
open
}
onClose
=
{
handleClose
}
>
<
DialogTitle
>
เพิ่มสินค้า
<
/DialogTitle
>
<
DialogTitle
>
เพิ่มสินค้า
<
/DialogTitle
>
<
DialogContent
className
=
"text-center"
>
<
DialogContent
className
=
"text-center"
>
<
TextField
className
=
"m-1"
label
=
"ชื่อสินค้า"
variant
=
"standard"
/>
<
TextField
className
=
"m-1"
label
=
"ชื่อสินค้า"
variant
=
"standard"
value
=
{
name
}
onChange
=
{(
e
)
=>
setName
(
e
.
target
.
value
)}
required
/>
<
TextField
<
TextField
className
=
"m-1"
className
=
"m-1"
label
=
"ราคา"
label
=
"ราคา"
variant
=
"standard"
variant
=
"standard"
type
=
"number"
type
=
"number"
value
=
{
price
}
onChange
=
{(
e
)
=>
setPrice
(
Number
(
e
.
target
.
value
))}
required
/>
/>
<
div
className
=
"text-left"
>
<
div
className
=
"text-left"
>
<
TextField
<
TextField
...
@@ -45,6 +58,9 @@ export default function AddProduct({ open, handleClose }) {
...
@@ -45,6 +58,9 @@ export default function AddProduct({ open, handleClose }) {
variant
=
"standard"
variant
=
"standard"
multiline
multiline
rows
=
{
3
}
rows
=
{
3
}
value
=
{
detail
}
onChange
=
{(
e
)
=>
setDetail
(
e
.
target
.
value
)}
required
/>
/>
<
/div
>
<
/div
>
<
div
className
=
"text-left"
>
<
div
className
=
"text-left"
>
...
@@ -53,12 +69,18 @@ export default function AddProduct({ open, handleClose }) {
...
@@ -53,12 +69,18 @@ export default function AddProduct({ open, handleClose }) {
label
=
"ส่วนลด (%)"
label
=
"ส่วนลด (%)"
variant
=
"standard"
variant
=
"standard"
type
=
"number"
type
=
"number"
value
=
{
discount
}
onChange
=
{(
e
)
=>
setDiscount
(
e
.
target
.
value
)}
required
/>
/>
<
TextField
<
TextField
className
=
"m-1"
className
=
"m-1"
label
=
"จำนวนสินค้า"
label
=
"จำนวนสินค้า"
variant
=
"standard"
variant
=
"standard"
type
=
"number"
type
=
"number"
value
=
{
stock
}
onChange
=
{(
e
)
=>
setStock
(
e
.
target
.
value
)}
required
/>
/>
<
/div
>
<
/div
>
<
TextField
<
TextField
...
@@ -66,18 +88,22 @@ export default function AddProduct({ open, handleClose }) {
...
@@ -66,18 +88,22 @@ export default function AddProduct({ open, handleClose }) {
variant
=
"standard"
variant
=
"standard"
fullWidth
fullWidth
helperText
=
"https://www.domain.com/image.png"
helperText
=
"https://www.domain.com/image.png"
value
=
{
image
}
onChange
=
{(
e
)
=>
setImage
(
e
.
target
.
value
)}
/
>
/
>
<
FormControl
className
=
"m-1"
variant
=
"standard"
sx
=
{{
minWidth
:
100
}}
>
<
FormControl
className
=
"m-1"
variant
=
"standard"
sx
=
{{
minWidth
:
100
}}
>
<
InputLabel
>
หมวดหมู่
<
/InputLabel
>
<
InputLabel
>
หมวดหมู่
<
/InputLabel
>
<
Select
>
<
Select
value
=
{
category
}
onChange
=
{(
e
)
=>
setCategory
(
Number
(
e
.
target
.
value
))}
>
{
CategoryList
.
map
((
cat
,
idx
)
=>
(
{
CategoryList
.
map
((
cat
,
idx
)
=>
(
<
MenuItem
value
=
{
cat
.
id
}
>
{
cat
.
name
}
<
/MenuItem
>
<
MenuItem
key
=
{
idx
}
value
=
{
cat
.
id
}
>
{
cat
.
name
}
<
/MenuItem
>
))}
))}
<
/Select
>
<
/Select
>
<
/FormControl
>
<
/FormControl
>
<
/DialogContent
>
<
/DialogContent
>
<
DialogActions
>
<
DialogActions
>
<
Button
color
=
"error"
onClick
=
{
handleClose
}
>
ยกเลิก
<
/Button
>
<
Button
color
=
"error"
onClick
=
{
handleClose
}
>
ยกเลิก
<
/Button
>
<
Button
onClick
=
{
handleClose
}
>
เพิ่ม
<
/Button
>
<
Button
onClick
=
{
handleClose
}
>
เพิ่ม
<
/Button
>
<
/DialogActions
>
<
/DialogActions
>
<
/Dialog
>
<
/Dialog
>
...
...
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