@@ -2,6 +2,7 @@ import { Link, router } from '@inertiajs/react'
22import { ArrowLeft , Minus , Plus , Trash2 } from 'lucide-react'
33import { useState } from 'react'
44import { EcomLayout } from '@/layouts/ecom-layout' ;
5+ import { toast } from 'react-toastify' ;
56
67interface CartItem {
78 id : string | number
@@ -33,7 +34,7 @@ const Cart = ({ cartItems, cartCount }: CartProps) => {
3334 const updateQuantity = ( item : CartItem , newQuantity : number ) => {
3435 if ( newQuantity < 1 ) return
3536
36- const itemKey = `${ item . product_id } _ ${ JSON . stringify ( item . option_ids ) } `
37+ const itemKey = `${ item . id } `
3738 setUpdatingItems ( ( prev ) => new Set ( prev ) . add ( itemKey ) )
3839
3940 router . put (
@@ -59,11 +60,14 @@ const Cart = ({ cartItems, cartCount }: CartProps) => {
5960 data : {
6061 option_ids : item . option_ids ,
6162 } ,
63+ onSuccess : ( ) => {
64+ toast . success ( 'The product has been deleted.' ) ;
65+ } ,
6266 } )
6367 }
6468
6569 const subtotal = cartItems . reduce ( ( sum , item ) => sum + item . price * item . quantity , 0 )
66- const shipping = 0 // Free shipping
70+ const shipping = 0
6771 const total = subtotal + shipping
6872
6973 const handleCheckout = ( ) => {
@@ -76,28 +80,14 @@ const Cart = ({ cartItems, cartCount }: CartProps) => {
7680 < div className = "container mx-auto px-4 py-8" >
7781 < div className = "text-center" >
7882 < div className = "mb-6" >
79- < svg
80- className = "mx-auto h-24 w-24 text-gray-300"
81- fill = "none"
82- viewBox = "0 0 24 24"
83- stroke = "currentColor"
84- >
85- < path
86- strokeLinecap = "round"
87- strokeLinejoin = "round"
88- strokeWidth = { 2 }
89- d = "M3 3h2l.4 2M7 13h10l4-8H5.4m0 0L7 13m0 0l-2.5 5M7 13l2.5 5m6-5v6a2 2 0 01-2 2H9a2 2 0 01-2-2v-6m6 0V9a2 2 0 00-2-2H9a2 2 0 00-2 2v4.01"
90- />
83+ < svg className = "mx-auto h-24 w-24 text-gray-300" fill = "none" viewBox = "0 0 24 24" stroke = "currentColor" >
84+ < path strokeLinecap = "round" strokeLinejoin = "round" strokeWidth = { 2 }
85+ d = "M3 3h2l.4 2M7 13h10l4-8H5.4m0 0L7 13m0 0l-2.5 5M7 13l2.5 5m6-5v6a2 2 0 01-2 2H9a2 2 0 01-2-2v-6m6 0V9a2 2 0 00-2-2H9a2 2 0 00-2 2v4.01" />
9186 </ svg >
9287 </ div >
9388 < h2 className = "mb-4 text-2xl font-bold text-gray-800" > Your cart is empty</ h2 >
94- < p className = "mb-8 text-gray-600" >
95- Looks like you haven't added any items to your cart yet.
96- </ p >
97- < Link
98- href = "/"
99- className = "inline-flex items-center rounded-md bg-indigo-600 px-6 py-3 text-white hover:bg-indigo-700"
100- >
89+ < p className = "mb-8 text-gray-600" > Looks like you haven't added any items to your cart yet.</ p >
90+ < Link href = "/" className = "inline-flex items-center rounded-md bg-indigo-600 px-6 py-3 text-white hover:bg-indigo-700" >
10191 < ArrowLeft className = "mr-2 h-5 w-5" />
10292 Continue Shopping
10393 </ Link >
@@ -110,23 +100,18 @@ const Cart = ({ cartItems, cartCount }: CartProps) => {
110100 return (
111101 < EcomLayout >
112102 < div className = "container mx-auto px-4 py-8" >
113- { /* Breadcrumb */ }
114103 < div className = "mb-6" >
115104 < nav className = "flex" aria-label = "Breadcrumb" >
116105 < ol className = "flex items-center space-x-4" >
117106 < li >
118- < Link href = "/" className = "text-gray-500 hover:text-gray-700" >
119- Home
120- </ Link >
107+ < Link href = "/" className = "text-gray-500 hover:text-gray-700" > Home</ Link >
121108 </ li >
122109 < li >
123110 < div className = "flex items-center" >
124111 < svg className = "h-5 w-5 text-gray-400" fill = "currentColor" viewBox = "0 0 20 20" >
125- < path
126- fillRule = "evenodd"
127- d = "M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"
128- clipRule = "evenodd"
129- />
112+ < path fillRule = "evenodd"
113+ d = "M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"
114+ clipRule = "evenodd" />
130115 </ svg >
131116 < span className = "ml-4 text-gray-500" > Shopping Cart</ span >
132117 </ div >
@@ -136,7 +121,6 @@ const Cart = ({ cartItems, cartCount }: CartProps) => {
136121 </ div >
137122
138123 < div className = "grid grid-cols-1 gap-8 lg:grid-cols-3" >
139- { /* Cart Items */ }
140124 < div className = "lg:col-span-2" >
141125 < div className = "rounded-lg bg-white shadow-sm" >
142126 < div className = "border-b px-6 py-4" >
@@ -146,7 +130,7 @@ const Cart = ({ cartItems, cartCount }: CartProps) => {
146130 </ div >
147131 < div className = "divide-y" >
148132 { cartItems . map ( ( item ) => {
149- const itemKey = `${ item . product_id } _ ${ JSON . stringify ( item . option_ids ) } `
133+ const itemKey = `${ item . id } `
150134 const isUpdating = updatingItems . has ( itemKey )
151135
152136 return (
@@ -159,19 +143,16 @@ const Cart = ({ cartItems, cartCount }: CartProps) => {
159143 />
160144 < div className = "ml-4 flex-1" >
161145 < h3 className = "text-lg font-medium text-gray-800" >
162- < Link
163- href = { route ( 'product.detail' , { slug : item . slug } ) }
164- className = "hover:text-indigo-600"
165- >
146+ < Link href = { route ( 'product.detail' , { slug : item . slug } ) } className = "hover:text-indigo-600" >
166147 { item . name }
167148 </ Link >
168149 </ h3 >
169150 { item . options . length > 0 && (
170151 < div className = "mt-1 text-sm text-gray-600" >
171152 { item . options . map ( ( option ) => (
172153 < span key = { option . id } className = "mr-2" >
173- { option . type . name } : { option . name }
174- </ span >
154+ { option . type . name } : { option . name }
155+ </ span >
175156 ) ) }
176157 </ div >
177158 ) }
@@ -215,12 +196,11 @@ const Cart = ({ cartItems, cartCount }: CartProps) => {
215196 </ div >
216197 </ div >
217198
218- { /* Order Summary */ }
219199 < div className = "lg:col-span-1" >
220200 < div className = "rounded-lg bg-white p-6 shadow-sm" >
221201 < h2 className = "mb-4 text-lg font-semibold text-gray-800" > Order Summary</ h2 >
222202 < div className = "space-y-3" >
223- < div className = "flex justify-between" >
203+ < div className = "text-black flex justify-between" >
224204 < span className = "text-gray-600" > Subtotal</ span >
225205 < span className = "font-medium" > ${ subtotal . toFixed ( 2 ) } </ span >
226206 </ div >
0 commit comments