Skip to content

Commit

Permalink
fixed supplier and models
Browse files Browse the repository at this point in the history
  • Loading branch information
TemuulenBM committed Nov 22, 2023
1 parent 0219311 commit 9eae4ec
Show file tree
Hide file tree
Showing 25 changed files with 303 additions and 838 deletions.
2 changes: 0 additions & 2 deletions addon/components/stock-adjustment-form-panel.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@
</div>
</InputGroup>
<InputGroup @name="Quantity" @type="number" @value={{this.stockAdjustment.quantity}} />
<InputGroup @name="Before Quantity" @type="number" @value={{this.stockAdjustment.before_quantity}} />
<InputGroup @name="After Quantity" @type="number" @value={{this.stockAdjustment.after_quantity}} />
</div>
</Overlay::Body>
</Overlay>
129 changes: 55 additions & 74 deletions addon/components/supplier-form-panel.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,83 +6,64 @@
@isResizeble={{or this.isResizable @isResizable}}
@width={{or this.width @width "600px"}}
>
<Overlay::Header @hideLeftSection={{true}} @actionsWrapperClass="flex-1 flex-col py-3" class="h-auto-i">
<div class="flex flex-row items-center justify-between w-full mb-4">
<div class="flex flex-1 space-x-2">
{{#if this.supplier.id}}
<Button @type="default" @icon="warehouse" @helpText="View supplier details" @onClick={{this.onViewDetails}} />
{{/if}}
</div>
<div class="flex flex-1 justify-end">
<div class="mr-2">
<Button @icon={{if this.supplier.id "save" "check"}} @type="primary" @text={{if this.supplier.id "Save Supplier" "Create Supplier"}} @onClick={{this.save}} />
</div>
<Button @type="default" @icon="times" @helpText={{if this.supplier.id "Cancel edit supplier" "Cancel new supplier"}} @onClick={{this.onPressCancel}} />
</div>
</div>
<div class="flex flex-row justify-between w-full">
<div class="flex flex-col flex-1 w-3/4">
<div class="flex flex-row">
<div class="w-14">
<div class="upload-avatar-overlay w-12 h-12 flex items-center justify-start rounded-lg">
<img src={{this.supplier.logo_url}} alt={{this.supplier.name}} height="48" width="48" class="h-12 w-12 rounded-lg shadow-sm" />
<Attach::Tooltip @class="clean" @animation="scale" @placement="top">
<InputInfo @text="Upload new photo" />
</Attach::Tooltip>
<div class="upload-avatar-button-wrapper rounded-lg">
<UploadButton
@name="photos"
@accept="image/*"
@onFileAdded={{this.onUploadNewPhoto}}
@icon="upload"
@hideButtonText={{true}}
@labelClass="upload-avatar-label-overlay"
class="w-12 btn-reset"
/>
</div>
</div>
</div>
<div class="flex flex-col">
<h1 class="text-gray-900 dark:text-white text-2xl">
{{#if this.supplier.id}}
{{this.supplier.name}}
{{else}}
{{#if this.supplier.name}}
{{this.supplier.name}}
{{else}}
<span>New Supplier</span>
{{/if}}
{{/if}}
</h1>
<div class="-mt-1">
<div class="flex flex-row items-center">
<span class="text-sm dark:text-blue-400 text-blue-600">{{n-a (smart-humanize this.supplier.type)}}</span>
</div>
</div>
</div>
</div>
</div>
<div class="flex justify-end w-1/4">
<Badge @status={{this.supplier.status}} @type="info" @hideStatusDot={{true}} />
</div>
<Overlay::Header
@title={{if this.supplier.public_id this.supplier.name "Add Supplier"}}
@status={{this.supplier.public_id}}
@hideStatusDot={{true}}
@createdAt={{this.supplier.createdAt}}
@titleWrapperClass="leading-5"
>
<div class="flex flex-1 justify-end">
<Button @icon={{if this.supplier.id "save" "check"}} @type="primary" @text={{if this.supplier.id "Save Supplier" "Add Supplier"}} @onClick={{this.save}} @wrapperClass="mr-2" />
{{#if this.supplier.id}}
<Button @type="default" @icon="supplier" @helpText="View supplier details" @onClick={{this.onViewDetails}} @wrapperClass="mr-2" />
{{/if}}
<Button @type="default" @icon="times" @helpText={{if this.supplier.id "Cancel edit supplier" "Cancel add supplier"}} @onClick={{this.onPressCancel}} />
</div>
</Overlay::Header>

<Overlay::Body @wrapperClass="new-service-rate-overlay-body px-4 space-y-4 pt-4" @increaseInnerBodyHeightBy={{1000}}>
{{#if this.isEditing}}
<SupplierFormPanel::EditForm
@supplier={{this.supplier}}
@supplierTypes={{this.supplierTypeOptions}}
@supplierStatusOptions={{this.supplierStatusOptions}}
@onSupplierChanged={{this.onSupplierChanged}}
/>
{{else}}
<SupplierFormPanel::CreateForm
@supplier={{this.supplier}}
@supplierTypes={{this.supplierTypeOptions}}
@supplierStatusOptions={{this.supplierStatusOptions}}
@onSupplierChanged={{this.onSupplierChanged}}
/>
{{/if}}
<div class="grid grid-cols-1 text-xs dark:text-gray-100">
<InputGroup @name="Name" @value={{this.supplier.name}} @helpText="The supplier's name, typically the name of a business." />
<InputGroup @name="Email" @type="email" @value={{this.supplier.email}} @helpText="The supplier's email, this can be used to trigger emails to the supplier." />
<InputGroup @name="Phone" @type="tel" @value={{this.supplier.phone}} @helpText="The supplier's phone #, this can be used to trigger SMS or messages to the supplier." />
<InputGroup @name="Website" @value={{this.supplier.website_url}} @helpText="The supplier's website, optionally add the suppliers website for reference." />
<InputGroup @name="Country">
<CountrySelect class="w-full form-input form-select form-datalist" @value={{this.supplier.country}} @onChange={{fn (mut this.supplier.country)}} placeholder="Country" />
</InputGroup>
<InputGroup @name="Status">
<div class="fleetbase-model-select fleetbase-power-select ember-model-select">
<PowerSelect
@options={{@supplierStatusOptions}}
@selected={{this.supplier.status}}
@onChange={{fn (mut this.supplier.status)}}
@placeholder="Select supplier status"
@triggerClass="form-select form-input"
as |status|
>
{{smart-humanize status}}
</PowerSelect>
</div>
</InputGroup>
<InputGroup @name="Address">
<div class="fleetbase-model-select fleetbase-power-select ember-model-select">
<ModelSelect
@modelName="place"
@selectedModel={{this.supplier.place}}
@placeholder="Select Address"
@triggerClass="form-select form-input"
@infiniteScroll={{false}}
@renderInPlace={{true}}
@onChange={{this.selectSupplierAddress}}
as |model|
>
<div class="flex items-center flex-row justify-between">
<div class="truncate flex-1">{{n-a model.address}}</div>
<Badge @hideStatusDot={{true}} @status="info">{{model.public_id}}</Badge>
</div>
</ModelSelect>
</div>
</InputGroup>
</div>
</Overlay::Body>
</Overlay>
74 changes: 6 additions & 68 deletions addon/components/supplier-form-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,13 @@ import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import contextComponentCallback from '../utils/context-component-callback';
import applyContextComponentArguments from '../utils/apply-context-component-arguments';
import getSupplierTypeOptions from '../utils/get-supplier-type-options';
import getSupplierStatusOptions from '../utils/get-supplier-status-options';

export default class SupplierFormPanelComponent extends Component {
/**
* @service store
*/
@service store;

/**
* @service fetch
*/
@service fetch;

/**
* @service currentUser
*/
@service currentUser;

/**
* @service notifications
*/
Expand Down Expand Up @@ -56,32 +44,17 @@ export default class SupplierFormPanelComponent extends Component {
@tracked isLoading = false;

/**
* The users supplier instance.
* @type {SupplierModel|IntegratedSupplierModel}
* Fuel Report status
* @type {Array}
*/
@tracked supplier;

/**
* Specific types of suppliers which can be set as the type.
*
* @memberof SupplierFormPanelComponent
*/
@tracked supplierTypeOptions = getSupplierTypeOptions();

/**
* Applicable status options for supplier.
*
* @memberof SupplierFormPanelComponent
*/
@tracked supplierStatusOptions = getSupplierStatusOptions();
@tracked statusOptions = ['draft', 'pending-approval', 'approved', 'rejected', 'revised', 'submitted', 'in-review', 'confirmed', 'processed', 'archived', 'cancelled'];

/**
* Constructs the component and applies initial state.
*/
constructor() {
super(...arguments);
this.supplier = this.args.supplier;
this.isEditing = typeof this.supplier.id === 'string';
applyContextComponentArguments(this);
}

Expand All @@ -97,7 +70,7 @@ export default class SupplierFormPanelComponent extends Component {
}

/**
* Saves the supplier changes.
* Saves the fuel report changes.
*
* @action
* @returns {Promise<any>}
Expand All @@ -114,7 +87,7 @@ export default class SupplierFormPanelComponent extends Component {
return supplier
.save()
.then((supplier) => {
this.notifications.success(`Supplier (${supplier.displayName}) saved successfully.`);
this.notifications.success(`Supplier saved successfully.`);
contextComponentCallback(this, 'onAfterSave', supplier);
})
.catch((error) => {
Expand All @@ -131,42 +104,7 @@ export default class SupplierFormPanelComponent extends Component {
}

/**
* Uploads a new logo for the supplier.
*
* @param {File} file
* @memberof DriverFormPanelComponent
*/
@action onUploadNewPhoto(file) {
this.fetch.uploadFile.perform(
file,
{
path: `uploads/${this.currentUser.companyId}/suppliers/${this.supplier.id}`,
subject_uuid: this.supplier.id,
subject_type: 'supplier',
type: 'supplier_logo',
},
(uploadedFile) => {
this.supplier.setProperties({
logo_uuid: uploadedFile.id,
logo_url: uploadedFile.url,
logo: uploadedFile,
});
}
);
}

/**
* Handle when supplier changed.
*
* @param {SupplierModel} supplier
* @memberof SupplierFormPanelComponent
*/
@action onSupplierChanged(supplier) {
this.supplier = supplier;
}

/**
* View the details of the supplier.
* View the details of the fuel-report.
*
* @action
*/
Expand Down
Loading

0 comments on commit 9eae4ec

Please sign in to comment.