Skip to content
Open
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
22 changes: 11 additions & 11 deletions src/redux/slices/cartSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,27 @@ export const updateCart = createAsyncThunk(
try {
const response = await axios.patch(
`${CARTS_URL}/${data.id}` + ".json",
data.body
data.body,
);
return response.data;
} catch (error) {
console.log(error);
}
}
},
);

export const deleteCart = createAsyncThunk(
"carts/deleteCart",
async (data: { body: string }) => {
try {
const response = await axios.delete(
`${CARTS_URL}/${data.body}` + ".json"
`${CARTS_URL}/${data.body}` + ".json",
);
return response.data;
} catch (error) {
console.log(error);
}
}
},
);

export const addCart = createAsyncThunk(
Expand All @@ -81,7 +81,7 @@ export const addCart = createAsyncThunk(
} catch (error) {
console.log(error);
}
}
},
);

export const addProductToCart = createAsyncThunk(
Expand Down Expand Up @@ -138,15 +138,15 @@ export const addProductToCart = createAsyncThunk(
} catch (error) {
console.log(error);
}
}
},
);

export const removeProductFromCart = createAsyncThunk(
"carts/removeProductFromCart",
async (data: { body: CartItem; cart: Cart }) => {
try {
const newItems = data.cart.items.filter(
(item) => item.id !== data.body.id
(item) => item.id !== data.body.id,
);
const newCart = {
id: data.cart.id,
Expand All @@ -157,13 +157,13 @@ export const removeProductFromCart = createAsyncThunk(
// console.log(newCart);
const response = await axios.patch(
`${CARTS_URL}/${data.cart.id}` + ".json",
newCart
newCart,
);
return response.data;
} catch (error) {
console.log(error);
}
}
},
);

export const updateProductFromCart = createAsyncThunk(
Expand All @@ -186,13 +186,13 @@ export const updateProductFromCart = createAsyncThunk(
// console.log(data, newItems, newCart);
const response = await axios.patch(
`${CARTS_URL}/${data.cart.id}` + ".json",
newCart
newCart,
);
return response.data;
} catch (error) {
console.log(error);
}
}
},
);

export const cartSlice = createSlice({
Expand Down
4 changes: 2 additions & 2 deletions src/views/home/Checkout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ const Checkout: React.VFC = () => {
dispatch(
deleteCart({
body: carts[carts.length - 1].id,
})
}),
),
{
loading: `Deleting Cart ${carts.length - 1} ...`,
success: "Deleted Cart successfully",
error: "There was an error",
}
},
)
.then(() => {
setActiveCart(carts[0]?.id || "");
Expand Down