{"size": 2021, "ext": "js", "max_stars_repo_path": "app/components/modals/contact-organizer.js", "max_stars_repo_name": "kirtisingh3008/open-event-frontend", "max_stars_repo_stars_event_min_datetime": "2017-04-15T18:09:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T14:40:21.000Z", "max_issues_repo_path": "app/components/modals/contact-organizer.js", "max_issues_repo_name": "kirtisingh3008/open-event-frontend", "max_issues_repo_issues_event_min_datetime": "2017-04-21T17:02:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:16:36.000Z", "max_forks_repo_path": "app/components/modals/contact-organizer.js", "max_forks_repo_name": "kirtisingh3008/open-event-frontend", "max_forks_repo_forks_event_min_datetime": "2017-04-07T03:10:32.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-26T03:08:52.000Z"}
{"max_stars_count": 2913, "max_issues_count": 7946, "max_forks_count": 2401, "avg_line_length": 30.1641791045, "max_line_length": 107, "alphanum_fraction": 0.5423057892}
import ModalBase from 'open-event-frontend/components/modals/modal-base';
import { computed } from '@ember/object';
import FormMixin from 'open-event-frontend/mixins/form';

export default ModalBase.extend(FormMixin, {
  message  : '',
  mailSent : false,

  from: computed('authManager.currentUser', function() {
    return this.authManager.currentUser.fullName + ' <' + this.authManager.currentUser.email + '>';
  }),

  getValidationRules() {
    return {
      inline : true,
      delay  : false,
      on     : 'blur',
      fields : {
        identification: {
          identifier : 'message',
          rules      : [
            {
              type   : 'empty',
              prompt : this.l10n.t('Please enter a message.')
            }
          ]
        }
      }
    };
  },

  actions: {
    contactOrganizer() {
      this.onValid(async() => {
        const payload = {};
        payload.email = this.message;
        try {
          if (this.group) {
            const response = await this.loader.post(`/groups/${this.event.id}/contact-organizer`, payload);
            if (!response?.success) {throw response}
            this.notify.success(this.l10n.t('Organizer contacted successfully.'), {
              id: 'contact_organizer_succ'
            });
          } else {
            const response = await this.loader.post(`/events/${this.event.id}/contact-organizer`, payload);
            if (!response?.success) {throw response}
            this.notify.success(this.l10n.t('Organizer contacted successfully.'), {
              id: 'contact_organizer_succ'
            });
          }
          this.set('mailSent', true);
        } catch (e) {
          console.error('Error while contacting organizer', e);
          this.notify.error(this.l10n.t('An unexpected error has occurred.'), {
            id: 'contact_organizer_err'
          });
        }
      });
    },
    close() {
      this.set('isOpen', false);
      this.set('message', '');
      this.set('mailSent', false);
    }
  }
});
