-
Notifications
You must be signed in to change notification settings - Fork 0
/
CartTotals.js
98 lines (94 loc) · 2.24 KB
/
CartTotals.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import styled from "styled-components";
import { useCartContext } from "../context/cart_context";
import { formatPrice } from "../utils/helpers";
import Link from "next/link";
import { useCurrentUser } from "../utils/useSWR";
import { useRouter } from "next/router";
const CartTotals = ({ data }) => {
const { loggedInUser } = useCurrentUser();
const router = useRouter();
console.log("carttotals data received ?", data);
const {
total_amount: total_amount_context,
shipping_fee: shipping_fee_context,
} = useCartContext();
return (
<Wrapper>
<div>
<article>
<h5>
subtotal :{" "}
<span>
{formatPrice(data ? data.subtotal : total_amount_context)}
</span>
</h5>
<p>
shipping fee :{" "}
<span>
{formatPrice(data ? data.shippingFee : shipping_fee_context)}
</span>
</p>
<p>
tax : <span>{formatPrice(data ? data.tax : 1)}</span>
</p>
<hr />
<h4>
order total :
<span>
{data
? formatPrice(data.total)
: formatPrice(total_amount_context + shipping_fee_context + 1)}
</span>
</h4>
</article>
{data ? (
""
) : loggedInUser ? (
<Link href="/checkout">
<a className="btn">proceed to checkout</a>
</Link>
) : (
<button
type="button"
className="btn"
onClick={() => router.push("/login?next=checkout")}
>
login to pay
</button>
)}
</div>
</Wrapper>
);
};
const Wrapper = styled.section`
margin-top: 3rem;
display: flex;
justify-content: center;
article {
border: 1px solid var(--clr-grey-8);
border-radius: var(--radius);
padding: 1.5rem 3rem;
}
h4,
h5,
p {
display: grid;
grid-template-columns: 200px 1fr;
}
p {
text-transform: capitalize;
}
h4 {
margin-top: 2rem;
}
@media (min-width: 776px) {
justify-content: flex-end;
}
.btn {
width: 100%;
margin-top: 1rem;
text-align: center;
font-weight: 700;
}
`;
export default CartTotals;