@fleetbase/storefront-engine
Version:
Headless Commerce & Marketplace Extension for Fleetbase
85 lines (72 loc) • 2.4 kB
JavaScript
import Component from '@glimmer/component';
import applyContextComponentArguments from '@fleetbase/ember-core/utils/apply-context-component-arguments';
import contextComponentCallback from '@fleetbase/ember-core/utils/context-component-callback';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import { debug } from '@ember/debug';
import { task } from 'ember-concurrency';
export default class OrderPanelComponent extends Component {
storefront;
orderActions;
context = null;
store = null;
constructor() {
super(...arguments);
applyContextComponentArguments(this);
this.loadActiveStore.perform();
}
/**
* Sets the overlay context.
*
* @action
* @param {OverlayContextObject} overlayContext
*/
setOverlayContext(overlayContext) {
this.context = overlayContext;
contextComponentCallback(this, 'onLoad', ...arguments);
}
/**
* Handles the cancel action.
*
* @method
* @action
* @returns {Boolean} Indicates whether the cancel action was overridden.
*/
onPressCancel() {
return contextComponentCallback(this, 'onPressCancel', this.order);
}
acceptOrder(order) {
this.orderActions.acceptOrder(order);
}
markAsReady(order) {
this.orderActions.markAsReady(order);
}
markAsCompleted(order) {
this.orderActions.markAsCompleted(order);
}
assignDriver(order) {
this.orderActions.assignDriver(order);
}
cancelOrder(order) {
this.orderActions.cancelOrder(order);
}
*loadActiveStore() {
const storefrontId = this.order.meta.storefront_id;
if (!storefrontId) {
return null;
}
const currentStore = this.storefront.activeStore;
if (storefrontId === currentStore.public_id) {
this.store = currentStore;
return currentStore;
}
try {
const store = yield this.store.findRecord('store', storefrontId);
this.store = store;
return store;
} catch (err) {
debug(`Unable to load store for ${this.order.public_id}:`, err);
}
}
}