-
Notifications
You must be signed in to change notification settings - Fork 909
Expand file tree
/
Copy pathtracking.js
More file actions
65 lines (52 loc) · 1.59 KB
/
tracking.js
File metadata and controls
65 lines (52 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import {getOrder} from '../data/orders.js';
import {getProduct, loadProductsFetch} from '../data/products.js';
import dayjs from 'https://unpkg.com/dayjs@1.11.10/esm/index.js';
async function loadPage() {
await loadProductsFetch();
const url = new URL(window.location.href);
const orderId = url.searchParams.get('orderId');
const productId = url.searchParams.get('productId');
const order = getOrder(orderId);
const product = getProduct(productId);
// Get additional details about the product like
// the estimated delivery time.
let productDetails;
order.products.forEach((details) => {
if (details.productId === product.id) {
productDetails = details;
}
});
const trackingHTML = `
<a class="back-to-orders-link link-primary" href="orders.html">
View all orders
</a>
<div class="delivery-date">
Arriving on ${
dayjs(productDetails.estimatedDeliveryTime).format('dddd, MMMM D')
}
</div>
<div class="product-info">
${product.name}
</div>
<div class="product-info">
Quantity: ${productDetails.quantity}
</div>
<img class="product-image" src="${product.image}">
<div class="progress-labels-container">
<div class="progress-label">
Preparing
</div>
<div class="progress-label current-status">
Shipped
</div>
<div class="progress-label">
Delivered
</div>
</div>
<div class="progress-bar-container">
<div class="progress-bar"></div>
</div>
`;
document.querySelector('.js-order-tracking').innerHTML = trackingHTML;
}
loadPage();