Skip to content

Fixes "unexpected application error" thrown in the shop/item/itemID and shop/checkout pages #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 28 additions & 32 deletions src/hooks/Mutations/shop/useCartSwagg.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const useAddSwagToCart = () => {
const { auth, logout } = useAuth();
const queryClient = useQueryClient();

return useMutation(
async (cartItems) => {
return useMutation({
mutationFn: async (cartItems) => {
const response = await publicAxios.post("/cart/swaggs/", cartItems, {
headers: {
"Content-Type": "application/json",
Expand All @@ -17,28 +17,26 @@ const useAddSwagToCart = () => {
});
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();
}
},
});
};

const useDeleteSwag = () => {
const { auth, logout } = useAuth();
const queryClient = useQueryClient();

return useMutation(
async (id) => {
return useMutation({
mutationFn: async (id) => {
const response = await publicAxios.delete(`/cart/swaggs/${id}/`, {
headers: {
"Content-Type": "application/json",
Expand All @@ -48,20 +46,18 @@ const useDeleteSwag = () => {
console.log("response ", response.data);
return response.data;
},
{
onSuccess: (data) => {
console.log("Successfully deleted ", data);
queryClient.invalidateQueries(["productsInCart"]);
},
onError: (error) => {
// eslint-disable-next-line no-console
console.error("Unable to delete swag");
if (error.response.status === 401) {
logout();
}
},
}
);
onSuccess: (data) => {
console.log("Successfully deleted ", data);
queryClient.invalidateQueries({ queryKey: ["productsInCart"] });
},
onError: (error) => {
// eslint-disable-next-line no-console
console.error("Unable to delete swag");
if (error.response.status === 401) {
logout();
}
},
});
};

export { useAddSwagToCart, useDeleteSwag };
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;
2 changes: 1 addition & 1 deletion src/hooks/Queries/shop/useOrdersList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const fetchSingleOrder = async (id) => {

const useSingleOrder = (id) =>
useQuery({
queryKey: ["singleOrder"],
queryKey: ["singleOrder", id],
queryFn: () => fetchSingleOrder(id),
refetchOnWindowFocus: true,
staleTime: 5 * 60 * 60,
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/Queries/shop/useSwagList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const fetchSingleSwag = async (id) => {

const useSingleSwag = (id) =>
useQuery({
queryKey: ["single swag"],
queryKey: ["singleSwag", id],
queryFn: () => fetchSingleSwag(id),
refetchOnWindowFocus: false,
});
Expand Down
Loading