-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'creme332:main' into testfuzzy
- Loading branch information
Showing
51 changed files
with
1,418 additions
and
716 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Cart, CartItem } from "./cart"; | ||
import ModalManager from "./modal"; | ||
|
||
const modal = ModalManager("my-modal"); | ||
|
||
function handleAddToCart(e) { | ||
// capture form submission | ||
e.preventDefault(); | ||
|
||
// extract form data | ||
const formData = new FormData(e.target); | ||
const formProps = Object.fromEntries(formData); | ||
|
||
const item = CartItem( | ||
parseInt(formProps.product_id, 10), | ||
parseInt(formProps.quantity, 10), | ||
formProps.cupSize, | ||
formProps.milkType, | ||
); | ||
Cart().addItem(item); | ||
|
||
// open modal to display success | ||
modal.openModal(); | ||
} | ||
|
||
window.addEventListener("DOMContentLoaded", function () { | ||
document | ||
.getElementById("product-customization-form") | ||
.addEventListener("submit", handleAddToCart); | ||
}); | ||
|
||
modal.init(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Cart } from "./cart"; | ||
|
||
/** | ||
* This script is executed when user accesses /cart. It sends the cart | ||
* data from localStorage to the server and then reloads the page. | ||
* @returns {Promise<void>} | ||
*/ | ||
async function uploadCart() { | ||
// send cart data to server | ||
const items = Cart().getItems(); | ||
console.log(items); | ||
const request = await fetch(window.location.href, { | ||
method: "POST", | ||
// redirect: "follow", | ||
body: JSON.stringify(items), | ||
}); | ||
// console.log(request); | ||
|
||
// add loading delay of 1s | ||
await new Promise((r) => setTimeout(r, 1000)); | ||
|
||
// reload page so that server can display the order details | ||
location.reload(); | ||
} | ||
|
||
window.addEventListener("DOMContentLoaded", uploadCart); |
Oops, something went wrong.