@ducna01120/fleetops-engine
Version:
Fleet & Transport Management Extension for Fleetbase
50 lines (42 loc) • 1.61 kB
JavaScript
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
export default class ModalsResetCustomerCredentialsComponent extends Component {
fetch;
notifications;
options = {};
password;
confirmPassword;
sendCredentials = true;
customer;
constructor(owner, { options }) {
super(...arguments);
this.customer = options.customer;
this.options = options;
this.setupOptions();
}
setupOptions() {
this.options.title = 'Reset Customer Credentials';
this.options.acceptButtonText = 'Reset Credentials';
this.options.declineButtonHidden = true;
this.options.confirm = async (modal) => {
modal.startLoading();
try {
await this.fetch.post('customers/reset-credentials', {
customer: this.customer.id,
password: this.password,
password_confirmation: this.confirmPassword,
send_credentials: this.sendCredentials,
});
this.notifications.success('Customer password reset.');
if (typeof this.options.onPasswordResetComplete === 'function') {
this.options.onPasswordResetComplete();
}
modal.done();
} catch (error) {
this.notifications.serverError(error);
modal.stopLoading();
}
};
}
}