diff --git a/addon/components/sales-order-form-panel.hbs b/addon/components/sales-order-form-panel.hbs index fb5c4b15..8b6ada56 100644 --- a/addon/components/sales-order-form-panel.hbs +++ b/addon/components/sales-order-form-panel.hbs @@ -1 +1,41 @@ -{{yield}} \ No newline at end of file + + +
+
+ {{#if this.salesOrder.id}} +
+
+
+
+
+
+
+
+ +
+
+
+ + +
+ +
+ + + + {{else}} + + {{/if}} + {{/each}} + + + + + + + {{#if this.showAdvancedOptions}} +
+ + + +
+ {{/if}} +
+ {{else}} +
+

Select an integrated supplier provider.

+
+ {{/if}} + {{else}} + + + + + + +
+ + {{smart-humanize type}} + +
+
+ +
+ + {{smart-humanize status}} + +
+
+ +
+ +
+
+
+ +
+
{{n-a model.address}}
+ {{model.public_id}} +
+
+
+ + + +
+ {{/if}} + {{/if}} +
\ No newline at end of file diff --git a/addon/components/supplier-form-panel/create-form.js b/addon/components/supplier-form-panel/create-form.js new file mode 100644 index 00000000..357e1cce --- /dev/null +++ b/addon/components/supplier-form-panel/create-form.js @@ -0,0 +1,158 @@ +import Component from '@glimmer/component'; +import { tracked } from '@glimmer/tracking'; +import { inject as service } from '@ember/service'; +import { action } from '@ember/object'; +import { isArray } from '@ember/array'; +import apiUrl from '@fleetbase/ember-core/utils/api-url'; +import contextComponentCallback from '../../utils/context-component-callback'; + +export default class SupplierFormPanelCreateFormComponent extends Component { + /** + * @service store + */ + @service store; + + /** + * @service fetch + */ + @service fetch; + + /** + * @service contextPanel + */ + @service contextPanel; + /** + * State of whether editing credentials is enabled. + * @type {Boolean} + */ + @tracked isEditingCredentials = false; + + /** + * State of whether to show advanced options for integrated supplier. + * @type {Boolean} + */ + @tracked showAdvancedOptions = false; + + /** + * The selectable types of suppliers. + * @type {Array} + */ + @tracked supplierTypes = [ + { label: 'Choose a integrated supplier', value: 'integrated-supplier' }, + { label: 'Create a custom supplier', value: 'supplier' }, + ]; + + /** + * The selected type of supplier being created or edited. + * @type {String} + */ + @tracked selectedSupplierType = this.supplierTypes[1]; + + /** + * The supported integrated suppliers. + * @type {Array} + */ + @tracked supportedIntegratedSuppliers = []; + + /** + * The selected integrated supplier provider. + * @type {Object} + */ + @tracked selectedIntegratedSupplier; + + constructor() { + super(...arguments); + this.supplier = this.args.supplier; + this.fetchSupportedIntegratedSuppliers(); + } + + @action toggleCredentialsReset() { + if (this.isEditingCredentials) { + this.isEditingCredentials = false; + } else { + this.isEditingCredentials = true; + } + } + + @action toggleAdvancedOptions() { + if (this.showAdvancedOptions) { + this.showAdvancedOptions = false; + } else { + this.showAdvancedOptions = true; + } + } + + @action onSelectSupplierType(selectedSupplierType) { + this.selectedSupplierType = selectedSupplierType; + } + + @action onSelectIntegratedSupplier(integratedSupplier) { + this.selectedIntegratedSupplier = integratedSupplier; + const { credential_params, option_params } = integratedSupplier; + + // create credentials object + const credentials = {}; + if (isArray(integratedSupplier.credential_params)) { + for (let i = 0; i < integratedSupplier.credential_params.length; i++) { + const param = integratedSupplier.credential_params.objectAt(i); + credentials[param] = null; + } + } + + // create options object + const options = {}; + if (isArray(integratedSupplier.option_params)) { + for (let i = 0; i < integratedSupplier.option_params.length; i++) { + const param = integratedSupplier.option_params.objectAt(i); + options[param.key] = null; + } + } + + const supplier = this.store.createRecord('integrated-supplier', { + provider: integratedSupplier.code, + webhook_url: apiUrl(`listeners/${integratedSupplier.code}`), + credentials: {}, + options: {}, + credential_params, + option_params, + }); + + this.supplier = supplier; + + // trigger callback + contextComponentCallback(this, 'onSupplierChanged', supplier); + } + + @action selectSupplierAddress(warehouse) { + this.supplier.warehouse = warehouse; + this.supplier.warehouse_uuid = warehouse.id; + } + + @action async editAddress() { + let warehouse; + + if (this.supplier.has_warehouse) { + warehouse = await this.supplier.warehouse; + } else { + warehouse = this.store.createRecord('warehouse'); + } + + return this.contextPanel.focus(warehouse, 'editing', { + onAfterSave: (warehouse) => { + this.supplier.warehouse = warehouse; + this.contextPanel.clear(); + }, + }); + } + + /** + * Fetches the supported integrated suppliers. + * + * @returns {Promise} + */ + fetchSupportedIntegratedSuppliers() { + return this.fetch.get('integrated-suppliers/supported').then((supportedIntegratedSuppliers) => { + this.supportedIntegratedSuppliers = supportedIntegratedSuppliers; + }); + } +} diff --git a/addon/components/supplier-form-panel/edit-form.hbs b/addon/components/supplier-form-panel/edit-form.hbs new file mode 100644 index 00000000..593101a7 --- /dev/null +++ b/addon/components/supplier-form-panel/edit-form.hbs @@ -0,0 +1,98 @@ +
+ {{#if this.isIntegratedSupplier}} + +
+ {{this.supplier.provider_settings.code}} +

{{this.supplier.provider_settings.name}}

+
+
+ + {{#if this.isEditingCredentials}} + {{#each this.supplier.provider_settings.credential_params as |param|}} + + {{/each}} + + {{else}} +
+

Sensitive credentials can only be reset, to update credentials you must re-enter the credentials.

+ Click here to reset credentials +
+
+ {{#each this.supplier.provider_settings.credential_params as |param|}} + + {{/each}} +
+ {{/if}} +
+ + {{#each this.supplier.provider_settings.option_params as |param|}} + {{#if param.options}} + +