Skip to content

Commit

Permalink
chore: Migrate my-session, ticket and billing forms to ES6 (#3619)
Browse files Browse the repository at this point in the history
  • Loading branch information
kushthedude authored and iamareebjamal committed Nov 12, 2019
1 parent fa27eac commit 416260b
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 74 deletions.
18 changes: 9 additions & 9 deletions app/components/forms/admin/settings/billing.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Component from '@ember/component';
import FormMixin from 'open-event-frontend/mixins/form';
import { validPhoneNumber } from 'open-event-frontend/utils/validators';
import { action } from '@ember/object';

export default Component.extend(FormMixin, {
export default class extends Component.extend(FormMixin) {
getValidationRules() {
return {
inline : true,
Expand Down Expand Up @@ -99,13 +100,12 @@ export default Component.extend(FormMixin, {
}
}
};
},
}

actions: {
submit() {
this.onValid(() => {
this.save();
});
}
@action
submit() {
this.onValid(() => {
this.save();
});
}
});
}
54 changes: 27 additions & 27 deletions app/components/forms/user-payment-info-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import Component from '@ember/component';
import FormMixin from 'open-event-frontend/mixins/form';
import { validPhoneNumber } from 'open-event-frontend/utils/validators';
import { pick, orderBy } from 'lodash-es';
import { computed } from '@ember/object';
import { action, computed } from '@ember/object';
import { countries } from 'open-event-frontend/utils/dictionary/demography';

export default Component.extend(FormMixin, {
export default class extends Component.extend(FormMixin) {
didInsertElement() {
this._super(...arguments);
super.didInsertElement(...arguments);
this.set('userBillingInfo', pick(this.authManager.currentUser, ['billingContactName', 'billingCity', 'billingPhone', 'company', 'billingTaxInfo', 'billingCountry', 'billingState', 'billingAddress', 'billingZipCode', 'billingAdditionalInfo']));
},
}

getValidationRules() {
return {
Expand Down Expand Up @@ -88,30 +88,30 @@ export default Component.extend(FormMixin, {
}
}
};
},
}

countries: computed(function() {
@computed()
get countries() {
return orderBy(countries, 'name');
}),
}

actions: {
submit() {
this.onValid(async() => {
this.set('isLoading', true);
try {
this.authManager.currentUser.setProperties(this.userBillingInfo);
await this.authManager.currentUser.save();
this.notify.success(this.l10n.t('Your billing details has been updated'), {
id: 'bill_det_updated'
});
} catch (error) {
this.authManager.currentUser.rollbackAttributes();
this.notify.error(this.l10n.t('An unexpected error occurred'), {
id: 'bill_det_unexpect'
});
}
this.set('isLoading', false);
});
}
@action
submit() {
this.onValid(async() => {
this.set('isLoading', true);
try {
this.authManager.currentUser.setProperties(this.userBillingInfo);
await this.authManager.currentUser.save();
this.notify.success(this.l10n.t('Your billing details has been updated'), {
id: 'bill_det_updated'
});
} catch (error) {
this.authManager.currentUser.rollbackAttributes();
this.notify.error(this.l10n.t('An unexpected error occurred'), {
id: 'bill_det_unexpect'
});
}
this.set('isLoading', false);
});
}
});
}
51 changes: 27 additions & 24 deletions app/controllers/my-sessions/view.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
import Controller from '@ember/controller';
import { computed } from '@ember/object';
import { computed, action } from '@ember/object';
import moment from 'moment';

export default Controller.extend({
isUpcoming: computed('model.endsAt', function() {
export default class extends Controller {

@computed('model.endsAt')
get isUpcoming() {
let endAt = this.get('model.endsAt');
if (endAt < moment()) {
return false;
}
return true;
}),
}

actions: {
openProposalDeleteModal() {
this.set('isProposalDeleteModalOpen', true);
},
deleteProposal() {
this.set('isLoading', true);
this.model.destroyRecord()
.then(() => {
this.transitionToRoute('my-sessions.index');
this.notify.success(this.l10n.t('Proposal has been deleted successfully.'));
})
.catch(() => {
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
})
.finally(() => {
this.set('isLoading', false);
this.set('isProposalDeleteModalOpen', false);
});
}
@action
openProposalDeleteModal() {
this.set('isProposalDeleteModalOpen', true);
}

@action
deleteProposal() {
this.set('isLoading', true);
this.model.destroyRecord()
.then(() => {
this.transitionToRoute('my-sessions.index');
this.notify.success(this.l10n.t('Proposal has been deleted successfully.'));
})
.catch(() => {
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
})
.finally(() => {
this.set('isLoading', false);
this.set('isProposalDeleteModalOpen', false);
});
}
});
}
15 changes: 8 additions & 7 deletions app/controllers/my-tickets/past.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import Controller from '@ember/controller';
export default Controller.extend({
actions: {
shareEvent(event) {
this.set('eventToShare', event);
this.set('isShareModalOpen', true);
}
import { action } from '@ember/object';

export default class extends Controller {
@action
shareEvent(event) {
this.set('eventToShare', event);
this.set('isShareModalOpen', true);
}
});
}
15 changes: 8 additions & 7 deletions app/controllers/my-tickets/upcoming.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import Controller from '@ember/controller';
export default Controller.extend({
actions: {
shareEvent(event) {
this.set('eventToShare', event);
this.set('isShareModalOpen', true);
}
import { action } from '@ember/object';

export default class extends Controller {
@action
shareEvent(event) {
this.set('eventToShare', event);
this.set('isShareModalOpen', true);
}
});
}

0 comments on commit 416260b

Please sign in to comment.