UNPKG

@fleetbase/storefront-engine

Version:

Headless Commerce & Marketplace Extension for Fleetbase

62 lines (53 loc) 1.81 kB
import Component from '@glimmer/component'; import { tracked } from '@glimmer/tracking'; import { inject as service } from '@ember/service'; import { task } from 'ember-concurrency'; export default class WidgetOrdersByStatusComponent extends Component { static widgetId = 'storefront-orders-by-status-widget'; @service fetch; @service storefront; @service storefrontDashboard; @tracked data = null; @tracked error = null; constructor() { super(...arguments); this.load.perform(); this.storefront.on('order.broadcasted', () => { this.load.perform(); }); this.storefront.on('storefront.changed', () => { this.load.perform(); }); this.storefrontDashboard.on('periodChanged', () => { this.load.perform(); }); } get storeId() { return this.storefront.activeStore?.public_id ?? this.storefront.activeStore?.id; } get hasData() { return (this.data?.total ?? 0) > 0; } get chartOptions() { return { responsive: true, maintainAspectRatio: false, plugins: { legend: { display: false }, tooltip: { mode: 'index', intersect: false }, }, scales: { x: { grid: { display: false } }, y: { beginAtZero: true, ticks: { precision: 0 } }, }, }; } @task *load() { try { this.data = yield this.fetch.get('analytics/orders-by-status', this.storefrontDashboard.withStore(this.storeId), { namespace: 'storefront/int/v1' }); this.error = null; } catch (error) { this.error = error?.message ?? 'Unable to load order status mix'; } } }