import { workers, devTools } from '../../../build/module'; import './style.css'; import { Order } from './types'; (window as any).devTools = devTools; interface WorkerState { order: Order; } const app = document.querySelector('#app')!; const formatPrice = (price: number) => { return price.toLocaleString('en-US', { style: 'currency', currency: 'USD' }); }; const renderOrder = (order: Order) => { let html = ``; for (const item of order.Items) { html += ``; for (const subItem of item.SubItems) { html += ``; } } html += '
${item.Quantity}.${ item.Name }${formatPrice(item.Price)}
${ subItem.Name }${formatPrice(subItem.Price)}
'; if (order.Items.length > 0) { // Totals html += `
`; html += `
`; html += `
Subtotal: ${formatPrice(order.SubTotal)}
`; html += `
Tax: ${formatPrice(order.Tax)}
`; let totalDiscount = order.Discounts.reduce( (acc, discount) => acc + discount.Amount, 0 ); totalDiscount += order.Promotions.reduce( (acc, promotion) => acc + promotion.Amount, 0 ); if (totalDiscount > 0) { html += `
Discount: -${formatPrice(totalDiscount)}
`; } html += `
`; html += `
Total: ${formatPrice(order.Total)}
`; html += '
'; } app.innerHTML = html; }; // devTools.sendMessage('worker-state', { // name: 'brink-order-confirmation', // state: { // order: { // OrderId: 6609237444618, // EncodedOrderId: 'AAAGAMLWACAL', // DestinationName: 'DINE IN', // Number: 10, // Register: 1, // Items: [ // { // Id: 654227146, // Quantity: 1, // ItemType: 'FOOD', // Name: 'BBQ Chicken Alert', // Price: 8.39, // SubItems: [ // { // Id: 654227785, // Quantity: 1, // ItemType: 'FOOD', // Name: ' Extra Grilled Breast', // Price: 5, // SubItems: [], // }, // { // Id: 654227093, // Quantity: 1, // ItemType: 'FOOD', // Name: ' Pickles', // Price: 0.5, // SubItems: [], // }, // { // Id: 654227140, // Quantity: 1, // ItemType: 'FOOD', // Name: ' Avocado', // Price: 0.99, // SubItems: [], // }, // ], // }, // { // Id: 654227199, // Quantity: 1, // ItemType: 'FOOD', // Name: 'Ultimate Sandwich', // Price: 9.99, // SubItems: [ // { // Id: 654227186, // Quantity: 1, // ItemType: 'FOOD', // Name: ' Lettuce', // Price: 0.5, // SubItems: [], // }, // { // Id: 654227305, // Quantity: 1, // ItemType: 'FOOD', // Name: ' Tomato', // Price: 0.5, // SubItems: [], // }, // ], // }, // { // Id: 654228808, // Quantity: 1, // ItemType: 'BEER', // Name: 'Corona', // Price: 4.99, // SubItems: [], // }, // { // Id: 654232466, // Quantity: 1, // ItemType: 'BEER', // Name: 'Budweiser', // Price: 5.25, // SubItems: [], // }, // { // Id: 654228822, // Quantity: 1, // ItemType: 'BEER', // Name: 'Bud Light', // Price: 4.99, // SubItems: [], // }, // ], // Discounts: [ // { // CreatedTime: '2024-11-20T19:16:58.3467001Z', // DiscountId: 654233187, // Amount: 7.62, // Percent: 0, // OrderItemIds: [], // Name: '50% Off Beer/Wine', // LoyaltyAwardId: 0, // Source: 'Other', // }, // ], // Promotions: [ // { // Amount: 10, // Code: null, // CreatedTime: '2024-11-20T19:12:27.2372711Z', // ExternalOfferId: null, // Name: '$10 Promo Comp', // PromotionId: 654236492, // }, // ], // Donations: [], // Surcharges: [], // Type: 'Unknown', // OrderState: 'Unknown', // SubTotal: 23.48, // Tax: 1.97, // Total: 25.45, // CloseTime: null, // OpenTime: '2024-11-20T18:51:02.9570141Z', // CreatedDate: '2024-11-20T18:51:02.9570141Z', // BusinessDate: '2024-11-20T19:17:04.2876809Z', // TotaledTime: null, // PaidTime: null, // CancelledTime: null, // }, // }, // }); workers.subscribe('brink-order-confirmation', ({ order }) => { renderOrder(order); });