-
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.
- Loading branch information
Showing
6 changed files
with
126 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Order</title> | ||
<script src="/scripts/helpers.js"></script> | ||
<link href="/styles/order.css" rel="stylesheet" type="text/css" /> | ||
</head> | ||
<body> | ||
<div class="order-container"> | ||
<h1 class="order-id"></h1> | ||
<div class="order-items"></div> | ||
<div class="order-cost"></div> | ||
<div class="order-status"></div> | ||
</div> | ||
</body> | ||
<script src="/scripts/order.js"></script> | ||
</html> |
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,79 @@ | ||
async function getOrder() { | ||
const url = window.location.href | ||
const urlSplitted = url.split('/'); | ||
const id = urlSplitted[urlSplitted.length - 1]; | ||
const response = await fetch(`/api/order/${id}`); | ||
const data = await response.json(); | ||
const order = data['response'] || {}; | ||
return order | ||
} | ||
|
||
async function loadOrder() { | ||
const order = await getOrder(); | ||
console.log(order) | ||
if (order) { | ||
console.log('true') | ||
// set order id | ||
document.getElementsByClassName('order-id')[0].textContent = `Order ID: ${order['orderID']}` | ||
// display order items | ||
loadOrderItems(order['dishes']) | ||
// display order costs | ||
loadCosts(order['dishes'], order['deliveryMethod'] === 'delivery'); | ||
// display order status | ||
loadStatus(order['status']) | ||
} else { | ||
console.log('err') | ||
} | ||
} | ||
|
||
function loadOrderItems(items) { | ||
const orderItems = document.getElementsByClassName('order-items')[0]; | ||
let h2 = createElement('h2', { text: 'Items' }); | ||
orderItems.appendChild(h2); | ||
items.forEach(item => { | ||
orderItem = createOrderItem(item); | ||
orderItems.appendChild(orderItem); | ||
}) | ||
} | ||
|
||
function createOrderItem(item) { | ||
const orderItem = createElement('div', { class: 'order-item' }); | ||
const image = createElement('img', { src: item['imageURL'] }); | ||
const dishName = createElement('h3', { text: item['dishName'] }); | ||
const quantity = createElement('p', { text: `Quantity: ${item['quantity']}` }); | ||
appendChildren(orderItem, [image, dishName, quantity]) | ||
return orderItem | ||
} | ||
|
||
function loadCosts(items, isDelivery) { | ||
const prices = calculateCartPrice(items, isDelivery); | ||
const orderCosts = document.getElementsByClassName('order-cost')[0] | ||
const h2 = createElement('h2', { text: 'Costs' }); | ||
orderCosts.appendChild(h2); | ||
const priceElementArray = Object.keys(prices).map(priceType => { | ||
return createElement('p', { text: `${priceType}: ${prices[priceType].toFixed(2)}` }); | ||
}) | ||
appendChildren(orderCosts, priceElementArray); | ||
|
||
} | ||
// cur | ||
function calculateCartPrice(items, isDelivery) { | ||
let subtotal = 0; | ||
let taxes = 0; | ||
let deliveryFee = 0; | ||
let total = 0; | ||
items.forEach(item => { subtotal = item.price * item.quantity; }) | ||
taxes = subtotal * 0.08875; | ||
isDelivery && (deliveryFee = 7.99); | ||
total = subtotal + taxes + deliveryFee; | ||
return { subtotal, taxes, deliveryFee, total }; | ||
} | ||
|
||
function loadStatus(status) { | ||
const orderStatus = document.getElementsByClassName('order-status')[0]; | ||
const h2 = createElement('h2', { text: 'Status' }); | ||
const p = createElement('p', { text: status }); | ||
appendChildren(orderStatus, [h2, p]); | ||
} | ||
|
||
loadOrder() |
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,4 @@ | ||
.order-item img { | ||
width: 100px; | ||
height: 100px; | ||
} |
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