@@ -38,16 +38,22 @@ const CartContents = () => {
38
38
} ,
39
39
} ) ;
40
40
41
- const [ updateCart , { loading : updateCartProcessing } ] = useMutation ( UPDATE_CART , {
42
- onCompleted : ( ) => {
43
- refetch ( ) ;
44
- setTimeout ( ( ) => {
41
+ const [ updateCart , { loading : updateCartProcessing } ] = useMutation (
42
+ UPDATE_CART ,
43
+ {
44
+ onCompleted : ( ) => {
45
45
refetch ( ) ;
46
- } , 3000 ) ;
46
+ setTimeout ( ( ) => {
47
+ refetch ( ) ;
48
+ } , 3000 ) ;
49
+ } ,
47
50
} ,
48
- } ) ;
51
+ ) ;
49
52
50
- const handleRemoveProductClick = ( cartKey : string , products : IProductRootObject [ ] ) => {
53
+ const handleRemoveProductClick = (
54
+ cartKey : string ,
55
+ products : IProductRootObject [ ] ,
56
+ ) => {
51
57
if ( products ?. length ) {
52
58
const updatedItems = getUpdatedItems ( products , 0 , cartKey ) ;
53
59
updateCart ( {
@@ -72,29 +78,37 @@ const CartContents = () => {
72
78
const cartTotal = data ?. cart ?. total || '0' ;
73
79
74
80
const getUnitPrice = ( subtotal : string , quantity : number ) => {
75
- const numericSubtotal = parseFloat ( subtotal . replace ( / [ ^ 0 - 9 . - ] + / g, "" ) ) ;
76
- return isNaN ( numericSubtotal ) ? 'N/A' : ( numericSubtotal / quantity ) . toFixed ( 2 ) ;
81
+ const numericSubtotal = parseFloat ( subtotal . replace ( / [ ^ 0 - 9 . - ] + / g, '' ) ) ;
82
+ return isNaN ( numericSubtotal )
83
+ ? 'N/A'
84
+ : ( numericSubtotal / quantity ) . toFixed ( 2 ) ;
77
85
} ;
78
86
79
87
return (
80
88
< div className = "container mx-auto px-4 py-8" >
81
- < h1 className = "text-3xl font-bold mb-8" > Handlekurv</ h1 >
82
89
{ data ?. cart ?. contents ?. nodes ?. length ? (
83
90
< >
84
91
< div className = "bg-white rounded-lg shadow-md p-6 mb-8" >
85
92
{ data . cart . contents . nodes . map ( ( item : IProductRootObject ) => (
86
- < div key = { item . key } className = "flex items-center border-b border-gray-200 py-4" >
93
+ < div
94
+ key = { item . key }
95
+ className = "flex items-center border-b border-gray-200 py-4"
96
+ >
87
97
< div className = "flex-shrink-0 w-24 h-24 relative" >
88
98
< Image
89
- src = { item . product . node . image ?. sourceUrl || '/placeholder.png' }
99
+ src = {
100
+ item . product . node . image ?. sourceUrl || '/placeholder.png'
101
+ }
90
102
alt = { item . product . node . name }
91
103
layout = "fill"
92
104
objectFit = "cover"
93
105
className = "rounded"
94
106
/>
95
107
</ div >
96
108
< div className = "flex-grow ml-4" >
97
- < h2 className = "text-lg font-semibold" > { item . product . node . name } </ h2 >
109
+ < h2 className = "text-lg font-semibold" >
110
+ { item . product . node . name }
111
+ </ h2 >
98
112
< p className = "text-gray-600" >
99
113
Enhetspris: kr { getUnitPrice ( item . subtotal , item . quantity ) }
100
114
</ p >
@@ -116,7 +130,12 @@ const CartContents = () => {
116
130
className = "w-16 px-2 py-1 text-center border border-gray-300 rounded mr-2"
117
131
/>
118
132
< Button
119
- handleButtonClick = { ( ) => handleRemoveProductClick ( item . key , data . cart . contents . nodes ) }
133
+ handleButtonClick = { ( ) =>
134
+ handleRemoveProductClick (
135
+ item . key ,
136
+ data . cart . contents . nodes ,
137
+ )
138
+ }
120
139
color = "red"
121
140
buttonDisabled = { updateCartProcessing }
122
141
>
@@ -136,20 +155,18 @@ const CartContents = () => {
136
155
</ div >
137
156
{ ! isCheckoutPage && (
138
157
< Link href = "/kasse" passHref >
139
- < Button fullWidth >
140
- GÅ TIL KASSE
141
- </ Button >
158
+ < Button fullWidth > GÅ TIL KASSE</ Button >
142
159
</ Link >
143
160
) }
144
161
</ div >
145
162
</ >
146
163
) : (
147
164
< div className = "text-center" >
148
- < h2 className = "text-2xl font-bold mb-4" > Ingen produkter i handlekurven</ h2 >
165
+ < h2 className = "text-2xl font-bold mb-4" >
166
+ Ingen produkter i handlekurven
167
+ </ h2 >
149
168
< Link href = "/produkter" passHref >
150
- < Button >
151
- Fortsett å handle
152
- </ Button >
169
+ < Button > Fortsett å handle</ Button >
153
170
</ Link >
154
171
</ div >
155
172
) }
0 commit comments