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
b732c9d0
Commit
b732c9d0
authored
Oct 06, 2023
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add category filter on admin stock
parent
e381489b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
30 deletions
+81
-30
stock.js
src/pages/admin/stock.js
+81
-10
index.js
src/pages/index.js
+0
-20
No files found.
src/pages/admin/stock.js
View file @
b732c9d0
...
...
@@ -28,10 +28,15 @@ export default function Stock() {
const
[
products
,
setProducts
]
=
useState
([]);
const
[
updateState
,
setUpdateState
]
=
useState
({
open
:
false
,
data
:
{}
});
const
[
deleteState
,
setDeleteState
]
=
useState
({
open
:
false
,
id
:
-
1
});
const
[
category
,
setCategory
]
=
useState
([]);
const
[
category
,
setCategory
]
=
useState
(
-
1
);
const
[
categoryList
,
setCategoryList
]
=
useState
([]);
const
productsFilter
=
!!
router
.
query
?.
q
?
products
.
filter
((
prod
)
=>
String
(
prod
.
name
).
includes
(
router
.
query
.
q
))
?
products
.
filter
((
prod
)
=>
String
(
prod
.
name
)
.
toLocaleLowerCase
()
.
includes
(
String
(
router
.
query
.
q
).
toLocaleLowerCase
())
)
:
products
;
useEffect
(()
=>
{
...
...
@@ -41,10 +46,18 @@ export default function Stock() {
},
[
modal
,
updateState
,
deleteState
]);
useEffect
(()
=>
{
axios
.
get
(
"/api/category"
).
then
((
res
)
=>
{
setCategory
(
res
.
data
);
setCategory
List
(
res
.
data
);
});
},
[]);
useEffect
(()
=>
{
if
(
router
.
query
?.
cat
)
{
setCategory
(
Number
(
router
.
query
.
cat
));
}
else
{
setCategory
(
-
1
);
}
},
[
router
]);
return
(
<>
<
Head
>
...
...
@@ -57,8 +70,54 @@ export default function Stock() {
เพิ่มสินค้า
<
/Button
>
<
/Box
>
<
Box
className
=
"flex justify-start mb-3 px-10 max-w-[1520px] mx-auto"
>
<
Box
sx
=
{{
display
:
"flex"
,
overflowX
:
"scroll"
,
maxWidth
:
"100vw"
}}
>
<
Button
variant
=
{
category
===
-
1
?
"contained"
:
"text"
}
className
=
{
`
${
category
===
-
1
?
""
:
"bg-white"
}
mx-1`
}
onClick
=
{()
=>
{
let
que
=
router
.
query
;
delete
que
.
cat
;
router
.
push
({
pathname
:
location
.
pathname
,
query
:
{
...
que
},
});
}}
>
ทั้งหมด
<
/Button
>
{
categoryList
.
map
((
cat
,
idx
)
=>
(
<
Button
className
=
{
`
${
cat
.
id
===
category
?
""
:
"bg-white"
}
mx-1`
}
variant
=
{
cat
.
id
===
category
?
"contained"
:
"text"
}
key
=
{
idx
}
onClick
=
{()
=>
{
if
(
cat
.
id
===
category
)
{
let
que
=
router
.
query
;
delete
que
.
cat
;
router
.
push
({
pathname
:
location
.
pathname
,
query
:
{
...
que
},
});
}
else
{
router
.
push
({
pathname
:
location
.
pathname
,
query
:
{
...
router
.
query
,
cat
:
cat
.
id
},
});
}
}}
>
{
cat
.
name
}
<
/Button
>
))}
<
/Box
>
<
/Box
>
<
div
className
=
"mx-auto text-left grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-3 2xl:grid-cols-4 max-w-[1520px]"
>
{
productsFilter
.
map
((
product
,
idx
)
=>
(
{
productsFilter
.
map
(
(
product
,
idx
)
=>
(
category
===
-
1
||
category
===
product
.
cateId
)
&&
(
<
Card
key
=
{
idx
}
sx
=
{{
...
...
@@ -71,7 +130,9 @@ export default function Stock() {
}}
>
<
Box
sx
=
{{
px
:
1
}}
>
<
h5
className
=
"h-[40px] overflow-y-hidden"
>
{
product
.
name
}
<
/h5
>
<
h5
className
=
"h-[40px] overflow-y-hidden"
>
{
product
.
name
}
<
/h5
>
<
/Box
>
<
CardMedia
className
=
"rounded object-contain"
...
...
@@ -93,10 +154,15 @@ export default function Stock() {
<
TableCell
sx
=
{{
m
:
0
,
p
:
0
,
textAlign
:
"center "
}}
>
{
Number
(
product
.
price
).
toLocaleString
()
+
" บาท"
}
<
/TableCell
>
<
TableCell
>
{
`ส่วนลด
${
product
.
discount
}
%`
}
<
/TableCell
>
<
TableCell
>
{
" "
}
{
`ส่วนลด
${
product
.
discount
}
%`
}
<
/TableCell
>
<
/TableRow
>
<
TableRow
>
<
TableCell
>
เข้าชม
{
product
.
watch_count
}
ครั้ง
<
/TableCell
>
<
TableCell
>
เข้าชม
{
product
.
watch_count
}
ครั้ง
<
/TableCell
>
<
TableCell
>
คงเหลือ
{
product
.
stock
}
ชิ้น
<
/TableCell
>
<
/TableRow
>
<
/TableBody
>
...
...
@@ -105,19 +171,24 @@ export default function Stock() {
<
CardActions
disableSpacing
sx
=
{{
justifyContent
:
"end"
}}
>
<
Button
color
=
"warning"
onClick
=
{()
=>
setUpdateState
({
open
:
true
,
data
:
product
})}
onClick
=
{()
=>
setUpdateState
({
open
:
true
,
data
:
product
})
}
>
<
Edit
/>
แก้ไข
<
/Button
>
<
Button
color
=
"error"
onClick
=
{()
=>
setDeleteState
({
open
:
true
,
id
:
product
.
id
})}
onClick
=
{()
=>
setDeleteState
({
open
:
true
,
id
:
product
.
id
})
}
>
<
Delete
/>
ลบ
<
/Button
>
<
/CardActions
>
<
/Card
>
))}
)
)}
<
/div
>
<
AddProduct
open
=
{
modal
}
handleClose
=
{()
=>
setModal
(
false
)}
/
>
<
/Box
>
...
...
src/pages/index.js
View file @
b732c9d0
...
...
@@ -133,26 +133,6 @@ export default function Home() {
/
>
<
div
>
<
Box
className
=
"flex justify-start mb-3 px-10 max-w-[1520px] mx-auto"
>
{
/* <Box className="flex items-center mx-3">หมวดหมู่</Box> */
}
{
/* <FormControl>
<Select
variant="standard"
value={category}
onChange={(e) => {
router.push({
pathname: location.pathname,
query: { ...router.query, cat: e.target.value },
});
}}
>
<MenuItem value="-1">ทั้งหมด</MenuItem>
{categoryList.map((cat, idx) => (
<MenuItem key={idx} value={cat.id}>
{cat.name}
</MenuItem>
))}
</Select>
</FormControl> */
}
<
Box
sx
=
{{
display
:
"flex"
,
overflowX
:
"scroll"
,
maxWidth
:
"100vw"
}}
>
<
Button
variant
=
{
category
===
-
1
?
"contained"
:
"text"
}
...
...
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