Skip to content

Commit

Permalink
Merge pull request #62 from SilverCareOrg/stefan
Browse files Browse the repository at this point in the history
Filter done
  • Loading branch information
avramstefan authored Nov 14, 2023
2 parents 1730268 + 4e57e7b commit fb05f68
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/components/CartPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default function CartPanel({ onClose }) {
} else {
services = [];
}

console.log(services);
setProducts(services);
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/components/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ const Navbar = () => {
/>
</div>
<b className="relative tracking-[0.15em] leading-[120%] uppercase">
rezerva acum
rezervă acum
</b>
</div>
</Link>
Expand Down Expand Up @@ -397,7 +397,7 @@ const Navbar = () => {

<Link to="/category">
<b className="relative tracking-[0.15em] leading-[120%] uppercase flex items-center justify-center w-[6rem] h-[2rem] shrink-0">
EXPERIENTE
EXPERIENȚE
</b>
</Link>

Expand Down
77 changes: 44 additions & 33 deletions src/components/ProductDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,54 +53,65 @@ const ProductDetails = () => {
// add the product to cart using the localstorage
// store the name of the product, the number of participants, the id of the product
// the price and the option
var cart = localStorage.getItem("cart");
var cart = localStorage.getItem("services");

if (cart === null) {
cart = [{
name: product.name,
participants: numberOfParticipants,
service_image_path: img_path,
service_name: product.name,
number_of_participants: numberOfParticipants,
id: product.service_id,
option_name: main_option === null ? options.find(option => option.id === selectedOption).name : main_option.name,
option_id: main_option === null ? selectedOption : main_option.id,
price: main_option === null ? numberOfParticipants * main_option.price : numberOfParticipants * options.find(option => option.id === selectedOption).price,
option_details: {
id: main_option === null ? selectedOption : main_option.id,
},
price: main_option != null ? numberOfParticipants * main_option.price : numberOfParticipants * options.find(option => option.id === selectedOption).price,
}];
localStorage.setItem("cart", JSON.stringify(cart));
console.log(cart);
localStorage.setItem("services", JSON.stringify(cart));
} else {
cart = JSON.parse(cart);
cart.push({
name: product.name,
participants: numberOfParticipants,
service_image_path: img_path,
service_name: product.name,
number_of_participants: numberOfParticipants,
id: product.service_id,
price: main_option !== null ? numberOfParticipants * main_option.price : numberOfParticipants * options.find(option => option.id === selectedOption).price,
option_name: main_option === null ? options.find(option => option.id === selectedOption).name : main_option.name,
option_id: main_option === null ? selectedOption : main_option.id,
option_details: {
id: main_option === null ? selectedOption : main_option.id,
},
price: main_option != null ? numberOfParticipants * main_option.price : numberOfParticipants * options.find(option => option.id === selectedOption).price,
});
localStorage.setItem("cart", JSON.stringify(cart));
localStorage.setItem("services", JSON.stringify(cart));
}

return;
} else {
// otherwise, if the token is set, we send the request back to the api to keep track of the cart
axios_api.post("/add_to_cart", {
service_id: product.id,
number_of_participants: numberOfParticipants,
option_id: main_option === null ? selectedOption : main_option.id,
price: main_option !== null ? numberOfParticipants * main_option.price : numberOfParticipants * options.find(option => option.id === selectedOption).price,
}, {sameSite: 'none', withCredentials: true,
headers: {
// 'X-CSRFToken': csrfToken, // Set the CSRF token in the request headers
'Content-Type': 'application/json'
}})
.then((response) => {
// Handle the response
if (response.status == 200) {
} else {
console.log("Failed to send login data to the API");
}
})
.catch((error) => {
// Handle errors
console.log("Error:", error);
});
}

// otherwise, if the token is set, we send the request back to the api to keep track of the cart
axios_api.post("/add_to_cart", {
service_id: product.id,
number_of_participants: numberOfParticipants,
option_id: main_option === null ? selectedOption : main_option.id,
price: main_option !== null ? numberOfParticipants * main_option.price : numberOfParticipants * options.find(option => option.id === selectedOption).price,
}, {sameSite: 'none', withCredentials: true,
headers: {
// 'X-CSRFToken': csrfToken, // Set the CSRF token in the request headers
'Content-Type': 'application/json'
}})
.then((response) => {
// Handle the response
if (response.status == 200) {
} else {
console.log("Failed to send login data to the API");
}
})
.catch((error) => {
// Handle errors
console.log("Error:", error);
});

toggleCartPanel();
};

Expand Down

0 comments on commit fb05f68

Please sign in to comment.