11export default function decorate ( block ) {
2- let orderStatus = [ ] ;
3- const orderStatusApiData = `{
4- "orders": [
5- {
6- "orderId": "ORD-1001",
7- "productName": "Foresight® Carrier Screen",
8- "orderDate": "2025-08-05",
9- "status": "Completed – View Results",
10- "trackingNumber": "TRACK12345",
11- "sampleReceivedDate": "2025-08-10",
12- "resultsAvailableDate": "2025-08-25",
13- "notes": "Returns complete, report available in patient portal"
14- },
15- {
16- "orderId": "ORD-1002",
17- "productName": "Prequel® Prenatal Screen",
18- "orderDate": "2025-08-15",
19- "status": "Processing",
20- "trackingNumber": "TRACK67890",
21- "expectedSampleArrival": "2025-08-20",
22- "expectedResultsDate": "2025-08-29",
23- "notes": "Blood draw scheduled via mobile phlebotomy"
24- },
25- {
26- "orderId": "ORD-1003",
27- "productName": "MyRisk® Hereditary Cancer Test",
28- "orderDate": "2025-08-20",
29- "status": "Pending",
30- "trackingNumber": null,
31- "expectedShipmentDate": "2025-08-22",
32- "notes": "Doctor needs to sign off order"
33- }
34- ]
35- }` ;
2+ const orderStatusAPI =
3+ "https://apim.workato.com/venuv0/eds-forms-endpoints-v1/getOrders" ;
4+
365 const orderTemplate = `<div id="order-{{orderId}}" class="order">
376 <h2>{{productName}}</h2>
387 <p><span class="order-key">Order Date:</span> <span name="order-date">{{orderDate}}</span></p>
@@ -56,13 +25,27 @@ export default function decorate(block) {
5625 return orderHTML ;
5726 }
5827
59- const orderStatusJSON = JSON . parse ( orderStatusApiData ) ;
60-
6128 // Function to iterate over orders and create markup for each
6229 function renderAllOrders ( orders ) {
6330 return orders . map ( renderOrderStatus ) . join ( "" ) ;
6431 }
6532
33+ fetch ( orderStatusAPI , {
34+ method : "GET" ,
35+ headers : {
36+ "Content-Type" : "application/json" ,
37+ "api-token" :
38+ "72e9157ec3edb8b64bbe109917633d5c32348386bc443900cc4a7dcf074069d1" ,
39+ } ,
40+ } )
41+ . then ( ( response ) => response . json ( ) )
42+ . then ( ( data ) => {
43+ ordersContainer . innerHTML = renderAllOrders ( data . orders ) ;
44+ } )
45+ . catch ( ( error ) => {
46+ console . error ( "Error fetching order status:" , error ) ;
47+ } ) ;
48+
6649 const orderStatusMarkup = document . createElement ( "h1" ) ;
6750 orderStatusMarkup . textContent = "Order Status" ;
6851 block . innerHTML = "" ;
@@ -71,6 +54,6 @@ export default function decorate(block) {
7154 // Create a container for all orders with the correct class for styling
7255 const ordersContainer = document . createElement ( "div" ) ;
7356 ordersContainer . className = "order-status-container" ;
74- ordersContainer . innerHTML = renderAllOrders ( orderStatusJSON . orders ) ;
57+
7558 block . append ( ordersContainer ) ;
7659}
0 commit comments