Skip to content

Commit 6aad532

Browse files
committed
feat: update mutations to tanstack-query v5 syntax
1 parent 373e105 commit 6aad532

File tree

1 file changed

+28
-32
lines changed

1 file changed

+28
-32
lines changed

src/hooks/Mutations/shop/useCartSwagg.jsx

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const useAddSwagToCart = () => {
77
const { auth, logout } = useAuth();
88
const queryClient = useQueryClient();
99

10-
return useMutation(
11-
async (cartItems) => {
10+
return useMutation({
11+
mutationFn: async (cartItems) => {
1212
const response = await publicAxios.post("/cart/swaggs/", cartItems, {
1313
headers: {
1414
"Content-Type": "application/json",
@@ -17,28 +17,26 @@ const useAddSwagToCart = () => {
1717
});
1818
return response.data;
1919
},
20-
{
21-
onSuccess: (data) => {
22-
console.log("Added to cart: ", data);
23-
queryClient.invalidateQueries(["productsInCart"]);
24-
},
25-
onError: (error) => {
26-
// eslint-disable-next-line no-console
27-
console.error("Unable to add availability");
28-
if (error.response.status === 401) {
29-
logout();
30-
}
31-
},
32-
}
33-
);
20+
onSuccess: (data) => {
21+
console.log("Added to cart: ", data);
22+
queryClient.invalidateQueries({ queryKey: ["productsInCart"] });
23+
},
24+
onError: (error) => {
25+
// eslint-disable-next-line no-console
26+
console.error("Unable to add availability");
27+
if (error.response.status === 401) {
28+
logout();
29+
}
30+
},
31+
});
3432
};
3533

3634
const useDeleteSwag = () => {
3735
const { auth, logout } = useAuth();
3836
const queryClient = useQueryClient();
3937

40-
return useMutation(
41-
async (id) => {
38+
return useMutation({
39+
mutationFn: async (id) => {
4240
const response = await publicAxios.delete(`/cart/swaggs/${id}/`, {
4341
headers: {
4442
"Content-Type": "application/json",
@@ -48,20 +46,18 @@ const useDeleteSwag = () => {
4846
console.log("response ", response.data);
4947
return response.data;
5048
},
51-
{
52-
onSuccess: (data) => {
53-
console.log("Successfully deleted ", data);
54-
queryClient.invalidateQueries(["productsInCart"]);
55-
},
56-
onError: (error) => {
57-
// eslint-disable-next-line no-console
58-
console.error("Unable to delete swag");
59-
if (error.response.status === 401) {
60-
logout();
61-
}
62-
},
63-
}
64-
);
49+
onSuccess: (data) => {
50+
console.log("Successfully deleted ", data);
51+
queryClient.invalidateQueries({ queryKey: ["productsInCart"] });
52+
},
53+
onError: (error) => {
54+
// eslint-disable-next-line no-console
55+
console.error("Unable to delete swag");
56+
if (error.response.status === 401) {
57+
logout();
58+
}
59+
},
60+
});
6561
};
6662

6763
export { useAddSwagToCart, useDeleteSwag };

0 commit comments

Comments
 (0)