-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcart.js
50 lines (44 loc) · 1.19 KB
/
cart.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { useEffect, useContext } from 'react'
import styled from 'styled-components'
import CartContext from '../context/cartContext'
import dynamic from 'next/dynamic'
import Head from 'next/head'
const CartList = dynamic(() => import('../components/cart/CartList'))
export default function Cart() {
const { itemsAmountInCart, assignProductAmountInCart } = useContext(CartContext)
useEffect(() => {
assignProductAmountInCart()
}, [])
return (
<>
<Head>
<title>Your cart - Alimazon</title>
</Head>
<DivCart>
{
itemsAmountInCart === null
? (
<div className="loader"></div>
)
: itemsAmountInCart < 1
? (
<h2 className="empty-cart-message">
<div>Your shopping cart is empty</div>
</h2>
)
: <CartList assignProductAmountInCart={assignProductAmountInCart} />
}
</DivCart>
</>
)
}
const DivCart = styled.div`
grid-area: 2 / 2 / 3 / 3;
width: 100%;
padding-left: 1em;
padding-right: 1em;
> .empty-cart-message {
display: flex;
justify-content: center;
}
`