Skip to content

Commit 8f5f2a9

Browse files
committed
Update CartContents.component.tsx
1 parent 3dc1386 commit 8f5f2a9

File tree

1 file changed

+38
-21
lines changed

1 file changed

+38
-21
lines changed

src/components/Cart/CartContents.component.tsx

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,22 @@ const CartContents = () => {
3838
},
3939
});
4040

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: () => {
4545
refetch();
46-
}, 3000);
46+
setTimeout(() => {
47+
refetch();
48+
}, 3000);
49+
},
4750
},
48-
});
51+
);
4952

50-
const handleRemoveProductClick = (cartKey: string, products: IProductRootObject[]) => {
53+
const handleRemoveProductClick = (
54+
cartKey: string,
55+
products: IProductRootObject[],
56+
) => {
5157
if (products?.length) {
5258
const updatedItems = getUpdatedItems(products, 0, cartKey);
5359
updateCart({
@@ -72,29 +78,37 @@ const CartContents = () => {
7278
const cartTotal = data?.cart?.total || '0';
7379

7480
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);
7785
};
7886

7987
return (
8088
<div className="container mx-auto px-4 py-8">
81-
<h1 className="text-3xl font-bold mb-8">Handlekurv</h1>
8289
{data?.cart?.contents?.nodes?.length ? (
8390
<>
8491
<div className="bg-white rounded-lg shadow-md p-6 mb-8">
8592
{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+
>
8797
<div className="flex-shrink-0 w-24 h-24 relative">
8898
<Image
89-
src={item.product.node.image?.sourceUrl || '/placeholder.png'}
99+
src={
100+
item.product.node.image?.sourceUrl || '/placeholder.png'
101+
}
90102
alt={item.product.node.name}
91103
layout="fill"
92104
objectFit="cover"
93105
className="rounded"
94106
/>
95107
</div>
96108
<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>
98112
<p className="text-gray-600">
99113
Enhetspris: kr {getUnitPrice(item.subtotal, item.quantity)}
100114
</p>
@@ -116,7 +130,12 @@ const CartContents = () => {
116130
className="w-16 px-2 py-1 text-center border border-gray-300 rounded mr-2"
117131
/>
118132
<Button
119-
handleButtonClick={() => handleRemoveProductClick(item.key, data.cart.contents.nodes)}
133+
handleButtonClick={() =>
134+
handleRemoveProductClick(
135+
item.key,
136+
data.cart.contents.nodes,
137+
)
138+
}
120139
color="red"
121140
buttonDisabled={updateCartProcessing}
122141
>
@@ -136,20 +155,18 @@ const CartContents = () => {
136155
</div>
137156
{!isCheckoutPage && (
138157
<Link href="/kasse" passHref>
139-
<Button fullWidth>
140-
GÅ TIL KASSE
141-
</Button>
158+
<Button fullWidth>GÅ TIL KASSE</Button>
142159
</Link>
143160
)}
144161
</div>
145162
</>
146163
) : (
147164
<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>
149168
<Link href="/produkter" passHref>
150-
<Button>
151-
Fortsett å handle
152-
</Button>
169+
<Button>Fortsett å handle</Button>
153170
</Link>
154171
</div>
155172
)}

0 commit comments

Comments
 (0)