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
49cb2cf8
Commit
49cb2cf8
authored
Oct 07, 2023
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
show sending price on confirm order
parent
741f2d08
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
3 deletions
+24
-3
ConfirmOrder.js
src/components/order/ConfirmOrder.js
+6
-2
cart.js
src/pages/cart.js
+18
-1
No files found.
src/components/order/ConfirmOrder.js
View file @
49cb2cf8
...
...
@@ -7,6 +7,7 @@ import DialogContent from "@mui/material/DialogContent";
import
DialogTitle
from
"@mui/material/DialogTitle"
;
import
{
Alert
,
Box
,
FormControl
,
InputLabel
,
MenuItem
,
...
...
@@ -19,7 +20,7 @@ import { CartContext, OrderContext, UserContext } from "@/pages/_app";
export
default
function
ConfirmOrder
({
open
,
handleClose
})
{
const
user
=
useContext
(
UserContext
);
const
cart
=
useContext
(
CartContext
);
const
order
=
useContext
(
OrderContext
)
const
order
=
useContext
(
OrderContext
)
;
const
[
message
,
setMessage
]
=
useState
({
message
:
""
,
error
:
false
});
const
[
address
,
setAddress
]
=
useState
(
user
.
value
?.
address
??
""
);
...
...
@@ -97,8 +98,11 @@ export default function ConfirmOrder({ open, handleClose }) {
[
"ธรรมดา"
,
40
],
[
"ช้า"
,
20
],
].
map
((
ls
,
idx
)
=>
(
<
MenuItem
key
=
{
idx
}
selected
=
{
ls
[
1
]
===
40
}
value
=
{
ls
[
1
]}
>
<
MenuItem
sx
=
{{
display
:
"flex"
,
justifyContent
:
"space-between"
}}
key
=
{
idx
}
selected
=
{
ls
[
1
]
===
40
}
value
=
{
ls
[
1
]}
>
{
ls
[
0
]}
<
Box
sx
=
{{
ml
:
3
}}
component
=
{
"span"
}
color
=
{
"orangered"
}
>
$
{
ls
[
1
]}
<
/Box
>
<
/MenuItem
>
))}
<
/Select
>
...
...
src/pages/cart.js
View file @
49cb2cf8
...
...
@@ -27,6 +27,7 @@ export default function Cart() {
const
[
orderState
,
setOrderState
]
=
useState
(
false
);
const
router
=
useRouter
();
const
[
CartProduct
,
setCartProduct
]
=
useState
([]);
const
[
totalProduct
,
setTotalProduct
]
=
useState
(
0
);
const
removeFromCart
=
async
(
id
)
=>
{
let
response
=
await
axios
.
delete
(
`/api/u/cart?id=
${
id
}
`
,
{
...
...
@@ -64,6 +65,15 @@ export default function Cart() {
);
},
[
cart
,
products
]);
useEffect
(()
=>
{
let
total
=
0
;
CartProduct
.
map
((
pdt
)
=>
{
if
(
!
pdt
)
return
;
total
+=
pdt
.
price
-
pdt
.
price
*
(
pdt
.
discount
/
100
);
});
setTotalProduct
(
Math
.
floor
(
total
));
},
[
CartProduct
]);
return
(
<>
<
Head
>
...
...
@@ -75,7 +85,7 @@ export default function Cart() {
isError
=
{
message
.
error
}
message
=
{
message
.
message
}
/
>
<
Paper
className
=
"shadow-none"
sx
=
{{
p
:
2
,
overflowX
:
"scroll"
}}
>
<
Paper
className
=
"shadow-none"
sx
=
{{
p
:
2
,
overflowX
:
"scroll"
,
maxWidth
:
1200
,
mx
:
"auto"
}}
>
{
cart
.
value
.
length
>
0
?
(
<
Box
>
<
Table
>
...
...
@@ -136,6 +146,13 @@ export default function Cart() {
<
/TableBody
>
<
/Table
>
<
Box
sx
=
{{
textAlign
:
"right"
,
p
:
1
}}
>
<
Box
sx
=
{{
p
:
1
}}
>
ทั้งหมด
<
Box
component
=
{
"span"
}
color
=
{
"orangered"
}
>
{
" "
}
$
{
totalProduct
.
toLocaleString
()}
<
/Box
>
<
/Box
>
<
Button
size
=
"large"
onClick
=
{()
=>
setOrderState
(
true
)}
>
<
ShoppingBag
/>
สั่งซื้อ
<
/Button
>
...
...
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