Skip to content

Commit ede1d58

Browse files
Merge branch 'Dev' into Dev
2 parents d515da3 + 73821c5 commit ede1d58

File tree

5 files changed

+1375
-53
lines changed

5 files changed

+1375
-53
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 };

src/hooks/Mutations/shop/useMakeOrder.jsx

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

10-
return useMutation(
11-
async (customerInfo) => {
10+
return useMutation({
11+
mutationFn: async (customerInfo) => {
1212
const response = await privateAxios.post("/orders/", customerInfo, {
1313
headers: {
1414
"Content-Type": "application/json",
@@ -17,20 +17,19 @@ const useMakeOrder = () => {
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+
21+
onSuccess: (data) => {
22+
console.log("Added to cart: ", data);
23+
queryClient.invalidateQueries({ queryKey: ["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+
});
3433
};
3534

3635
export default useMakeOrder;

src/hooks/Queries/shop/useOrdersList.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const fetchSingleOrder = async (id) => {
4444

4545
const useSingleOrder = (id) =>
4646
useQuery({
47-
queryKey: ["singleOrder"],
47+
queryKey: ["singleOrder", id],
4848
queryFn: () => fetchSingleOrder(id),
4949
refetchOnWindowFocus: true,
5050
staleTime: 5 * 60 * 60,

src/hooks/Queries/shop/useSwagList.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const fetchSingleSwag = async (id) => {
3333

3434
const useSingleSwag = (id) =>
3535
useQuery({
36-
queryKey: ["single swag"],
36+
queryKey: ["singleSwag", id],
3737
queryFn: () => fetchSingleSwag(id),
3838
refetchOnWindowFocus: false,
3939
});

0 commit comments

Comments
 (0)