1
1
import Image from "next/image" ;
2
2
import Header from "../components/Header" ;
3
3
import { useSelector } from "react-redux" ;
4
- import { selectItems } from "../slices/basketSlice" ;
4
+ import { selectItems , selectTotal } from "../slices/basketSlice" ;
5
5
import CheckoutProduct from "../components/CheckoutProduct" ;
6
6
import Head from "next/head" ;
7
+ import Currency from "react-currency-formatter" ;
8
+ import { useSession } from "next-auth/client" ;
7
9
8
10
function checkout ( ) {
9
11
const items = useSelector ( selectItems ) ;
10
- // console.log(items);
12
+ const total = useSelector ( selectTotal ) ;
13
+ const [ session ] = useSession ( ) ;
14
+
11
15
return (
12
16
< div className = "bg-gray-100" >
13
17
< Head >
14
18
< title > Checkout Page</ title >
15
19
</ Head >
16
20
< Header />
17
- < main className = "lg:flex max-w-screen-2xl mx-auto" >
21
+ < main className = "lg:flex max-w-screen-2xl mx-auto mt-28" >
18
22
{ /* Left */ }
19
- < div className = "flex-grow m-5 shadow-sm" >
23
+ < div className = "flex-grow m-5 shadow-sm " >
20
24
< Image
21
25
src = "https:links.papareact.com/ikj"
22
- width = { 1020 }
26
+ width = { 1050 }
23
27
height = { 250 }
24
- alt = "shopping banner"
28
+ alt = "shopping banner"
25
29
priority = { true }
26
- className = "w-auto h-auto object-contain"
30
+ className = "w-auto h-auto object-contain "
27
31
/>
28
32
29
33
< div className = "flex flex-col p-5 space-y-10 bg-white" >
@@ -48,6 +52,26 @@ function checkout() {
48
52
</ div >
49
53
</ div >
50
54
{ /* Right */ }
55
+ < div className = "flex flex-col bg-white p-10 shadow-md min-w-fit" >
56
+ { items . length > 0 && (
57
+ < >
58
+ < h2 >
59
+ Subtotal ({ items . length } items):
60
+ < span className = "font-bold" >
61
+ < Currency quantity = { total } />
62
+ </ span >
63
+ </ h2 >
64
+ < button
65
+ className = { `button mt-2 ${
66
+ ! session &&
67
+ "from-gray-300 to-gray-500 border-gray-200 text-gray-300 cursor-not-allowed"
68
+ } `}
69
+ >
70
+ { ! session ? "Sign in to checkout" : "Proceed to checkout" }
71
+ </ button >
72
+ </ >
73
+ ) }
74
+ </ div >
51
75
</ main >
52
76
</ div >
53
77
) ;
0 commit comments