1- "use client" ;
21
32import {
4- CustomButton ,
5- QuantityInput ,
6- QuantityInputCart ,
7- SectionTitle ,
3+ SectionTitle
84} from "@/components" ;
9- import Image from "next/image" ;
10- import React from "react" ;
11- import { FaCheck , FaClock , FaCircleQuestion , FaXmark } from "react-icons/fa6" ;
12- import { useProductStore } from "../_zustand/store" ;
13- import Link from "next/link" ;
14- import toast from "react-hot-toast" ;
5+ import { Loader } from "@/components/Loader" ;
6+ import { CartModule } from "@/components/modules/cart" ;
7+ import { Suspense } from "react" ;
158
169const CartPage = ( ) => {
17- const { products, removeFromCart, calculateTotals, total } =
18- useProductStore ( ) ;
19-
20- const handleRemoveItem = ( id : string ) => {
21- removeFromCart ( id ) ;
22- calculateTotals ( ) ;
23- toast . success ( "Product removed from the cart" ) ;
24- } ;
25-
2610 return (
2711 < div className = "bg-white" >
2812 < SectionTitle title = "Cart Page" path = "Home | Cart" />
@@ -31,166 +15,9 @@ const CartPage = () => {
3115 < h1 className = "text-3xl font-bold tracking-tight text-gray-900 sm:text-4xl" >
3216 Shopping Cart
3317 </ h1 >
34- < form className = "mt-12 lg:grid lg:grid-cols-12 lg:items-start lg:gap-x-12 xl:gap-x-16" >
35- < section aria-labelledby = "cart-heading" className = "lg:col-span-7" >
36- < h2 id = "cart-heading" className = "sr-only" >
37- Items in your shopping cart
38- </ h2 >
39-
40- < ul
41- role = "list"
42- className = "divide-y divide-gray-200 border-b border-t border-gray-200"
43- >
44- { products . map ( ( product ) => (
45- < li key = { product . id } className = "flex py-6 sm:py-10" >
46- < div className = "flex-shrink-0" >
47- < Image
48- width = { 192 }
49- height = { 192 }
50- src = { product ?. image ? `/${ product . image } ` : "/product_placeholder.jpg" }
51- alt = "laptop image"
52- className = "h-24 w-24 rounded-md object-cover object-center sm:h-48 sm:w-48"
53- />
54- </ div >
55-
56- < div className = "ml-4 flex flex-1 flex-col justify-between sm:ml-6" >
57- < div className = "relative pr-9 sm:grid sm:grid-cols-2 sm:gap-x-6 sm:pr-0" >
58- < div >
59- < div className = "flex justify-between" >
60- < h3 className = "text-sm" >
61- < Link
62- href = { `#` }
63- className = "font-medium text-gray-700 hover:text-gray-800"
64- >
65- { product . title }
66- </ Link >
67- </ h3 >
68- </ div >
69- { /* <div className="mt-1 flex text-sm">
70- <p className="text-gray-500">{product.color}</p>
71- {product.size ? (
72- <p className="ml-4 border-l border-gray-200 pl-4 text-gray-500">{product.size}</p>
73- ) : null}
74- </div> */ }
75- < p className = "mt-1 text-sm font-medium text-gray-900" >
76- ${ product . price }
77- </ p >
78- </ div >
79-
80- < div className = "mt-4 sm:mt-0 sm:pr-9" >
81- < QuantityInputCart product = { product } />
82- < div className = "absolute right-0 top-0" >
83- < button
84- onClick = { ( ) => handleRemoveItem ( product . id ) }
85- type = "button"
86- className = "-m-2 inline-flex p-2 text-gray-400 hover:text-gray-500"
87- >
88- < span className = "sr-only" > Remove</ span >
89- < FaXmark className = "h-5 w-5" aria-hidden = "true" />
90- </ button >
91- </ div >
92- </ div >
93- </ div >
94-
95- < p className = "mt-4 flex space-x-2 text-sm text-gray-700" >
96- { 1 ? (
97- < FaCheck
98- className = "h-5 w-5 flex-shrink-0 text-green-500"
99- aria-hidden = "true"
100- />
101- ) : (
102- < FaClock
103- className = "h-5 w-5 flex-shrink-0 text-gray-300"
104- aria-hidden = "true"
105- />
106- ) }
107-
108- < span > { 1 ? "In stock" : `Ships in 3 days` } </ span >
109- </ p >
110- </ div >
111- </ li >
112- ) ) }
113- </ ul >
114- </ section >
115-
116- { /* Order summary */ }
117- < section
118- aria-labelledby = "summary-heading"
119- className = "mt-16 rounded-lg bg-gray-50 px-4 py-6 sm:p-6 lg:col-span-5 lg:mt-0 lg:p-8"
120- >
121- < h2
122- id = "summary-heading"
123- className = "text-lg font-medium text-gray-900"
124- >
125- Order summary
126- </ h2 >
127-
128- < dl className = "mt-6 space-y-4" >
129- < div className = "flex items-center justify-between" >
130- < dt className = "text-sm text-gray-600" > Subtotal</ dt >
131- < dd className = "text-sm font-medium text-gray-900" >
132- ${ total }
133- </ dd >
134- </ div >
135- < div className = "flex items-center justify-between border-t border-gray-200 pt-4" >
136- < dt className = "flex items-center text-sm text-gray-600" >
137- < span > Shipping estimate</ span >
138- < a
139- href = "#"
140- className = "ml-2 flex-shrink-0 text-gray-400 hover:text-gray-500"
141- >
142- < span className = "sr-only" >
143- Learn more about how shipping is calculated
144- </ span >
145- < FaCircleQuestion
146- className = "h-5 w-5"
147- aria-hidden = "true"
148- />
149- </ a >
150- </ dt >
151- < dd className = "text-sm font-medium text-gray-900" > $5.00</ dd >
152- </ div >
153- < div className = "flex items-center justify-between border-t border-gray-200 pt-4" >
154- < dt className = "flex text-sm text-gray-600" >
155- < span > Tax estimate</ span >
156- < a
157- href = "#"
158- className = "ml-2 flex-shrink-0 text-gray-400 hover:text-gray-500"
159- >
160- < span className = "sr-only" >
161- Learn more about how tax is calculated
162- </ span >
163- < FaCircleQuestion
164- className = "h-5 w-5"
165- aria-hidden = "true"
166- />
167- </ a >
168- </ dt >
169- < dd className = "text-sm font-medium text-gray-900" >
170- ${ total / 5 }
171- </ dd >
172- </ div >
173- < div className = "flex items-center justify-between border-t border-gray-200 pt-4" >
174- < dt className = "text-base font-medium text-gray-900" >
175- Order total
176- </ dt >
177- < dd className = "text-base font-medium text-gray-900" >
178- ${ total === 0 ? 0 : Math . round ( total + total / 5 + 5 ) }
179- </ dd >
180- </ div >
181- </ dl >
182- { products . length > 0 && (
183- < div className = "mt-6" >
184- < Link
185- href = "/checkout"
186- className = "block flex justify-center items-center w-full uppercase bg-white px-4 py-3 text-base border border-black border-gray-300 font-bold text-blue-600 shadow-sm hover:bg-black hover:bg-gray-100 focus:outline-none focus:ring-2"
187- >
188- < span > Checkout</ span >
189- </ Link >
190- </ div >
191- ) }
192- </ section >
193- </ form >
18+ < Suspense fallback = { < Loader /> } >
19+ < CartModule />
20+ </ Suspense >
19421 </ div >
19522 </ div >
19623 </ div >
0 commit comments