Skip to content

Commit 1858b6a

Browse files
committed
Zustand
1 parent 9740708 commit 1858b6a

File tree

3 files changed

+6
-27
lines changed

3 files changed

+6
-27
lines changed

src/components/Cart/CartContents.component.tsx

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { v4 as uuidv4 } from 'uuid';
77

88
import useCartStore, { RootObject, Product } from '@/stores/cart';
99
import Button from '@/components/UI/Button.component';
10-
import LoadingSpinner from '../LoadingSpinner/LoadingSpinner.component';
1110

1211
import {
1312
getFormattedCart,
@@ -32,13 +31,10 @@ const CartContents = () => {
3231
},
3332
});
3433

35-
const [updateCart, { loading: updateCartProcessing }] = useMutation(
36-
UPDATE_CART,
37-
{
38-
refetchQueries: [{ query: GET_CART }],
39-
awaitRefetchQueries: true,
40-
},
41-
);
34+
const [updateCart] = useMutation(UPDATE_CART, {
35+
refetchQueries: [{ query: GET_CART }],
36+
awaitRefetchQueries: true,
37+
});
4238

4339
const handleRemoveProductClick = (
4440
cartKey: string,
@@ -66,7 +62,6 @@ const CartContents = () => {
6662
},
6763
},
6864
});
69-
7065
}
7166
};
7267

@@ -141,8 +136,7 @@ const CartContents = () => {
141136
event,
142137
item.key,
143138
data.cart.contents.nodes,
144-
updateCart,
145-
updateCartProcessing,
139+
updateCart
146140
);
147141
}}
148142
className="w-16 px-2 py-1 text-center border border-gray-300 rounded mr-2"
@@ -155,7 +149,6 @@ const CartContents = () => {
155149
)
156150
}
157151
variant="secondary"
158-
buttonDisabled={updateCartProcessing}
159152
>
160153
Fjern
161154
</Button>
@@ -190,14 +183,6 @@ const CartContents = () => {
190183
</Link>
191184
</div>
192185
)}
193-
{updateCartProcessing && (
194-
<div className="fixed inset-0 flex items-center justify-center bg-black bg-opacity-50">
195-
<div className="bg-white p-4 rounded-lg">
196-
<p className="text-lg mb-2">Oppdaterer handlekurv...</p>
197-
<LoadingSpinner />
198-
</div>
199-
</div>
200-
)}
201186
</div>
202187
);
203188
};

src/components/Checkout/CheckoutForm.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const CheckoutForm = () => {
5757
const [orderCompleted, setorderCompleted] = useState<boolean>(false);
5858

5959
// Get cart data query
60-
const { data } = useQuery(GET_CART, {
60+
useQuery(GET_CART, {
6161
notifyOnNetworkStatusChange: true,
6262
onCompleted: (data) => {
6363
const updatedCart = getFormattedCart(data) as RootObject | undefined;

src/utils/functions/functions.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,16 +290,10 @@ export const handleQuantityChange = (
290290
cartKey: string,
291291
cart: IProductRootObject[],
292292
updateCart: (variables: IUpdateCartRootObject) => void,
293-
updateCartProcessing: boolean,
294293
) => {
295294
if (process.browser) {
296295
event.stopPropagation();
297296

298-
// Return if the previous update cart mutation request is still processing
299-
if (updateCartProcessing || !cart) {
300-
return;
301-
}
302-
303297
// If the user tries to delete the count of product, set that to 1 by default ( This will not allow him to reduce it less than zero )
304298
const newQty = event.target.value ? parseInt(event.target.value, 10) : 1;
305299

0 commit comments

Comments
 (0)