Skip to content

Commit

Permalink
feat: update mutations to tanstack-query v5 syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
alvyynm committed Jun 22, 2024
1 parent 372c4f9 commit de2d2c9
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src/hooks/Mutations/shop/useMakeOrder.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const useMakeOrder = () => {
const { auth, logout } = useAuth();
const queryClient = useQueryClient();

return useMutation(
async (customerInfo) => {
return useMutation({
mutationFn: async (customerInfo) => {
const response = await privateAxios.post("/orders/", customerInfo, {
headers: {
"Content-Type": "application/json",
Expand All @@ -17,20 +17,19 @@ const useMakeOrder = () => {
});
return response.data;
},
{
onSuccess: (data) => {
console.log("Added to cart: ", data);
queryClient.invalidateQueries(["productsInCart"]);
},
onError: (error) => {
// eslint-disable-next-line no-console
console.error("Unable to add availability");
if (error.response.status === 401) {
logout();
}
},
}
);

onSuccess: (data) => {
console.log("Added to cart: ", data);
queryClient.invalidateQueries({ queryKey: ["productsInCart"] });
},
onError: (error) => {
// eslint-disable-next-line no-console
console.error("Unable to add availability");
if (error.response.status === 401) {
logout();
}
},
});
};

export default useMakeOrder;

0 comments on commit de2d2c9

Please sign in to comment.