1 import { Component, OnInit, ViewChild } from '@angular/core'
2 import { Notifier, ServerService } from '@app/core'
3 import { I18n } from '@ngx-translate/i18n-polyfill'
4 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
5 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
6 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
7 import { FormReactive, InstanceValidatorsService } from '@app/shared'
8 import { InstanceService } from '@app/shared/instance/instance.service'
11 selector: 'my-contact-admin-modal',
12 templateUrl: './contact-admin-modal.component.html',
13 styleUrls: [ './contact-admin-modal.component.scss' ]
15 export class ContactAdminModalComponent extends FormReactive implements OnInit {
16 @ViewChild('modal') modal: NgbModal
20 private openedModal: NgbModalRef
23 protected formValidatorService: FormValidatorService,
24 private modalService: NgbModal,
25 private instanceValidatorsService: InstanceValidatorsService,
26 private instanceService: InstanceService,
27 private serverService: ServerService,
28 private notifier: Notifier,
35 return this.serverService.getConfig().instance.name
40 fromName: this.instanceValidatorsService.FROM_NAME,
41 fromEmail: this.instanceValidatorsService.FROM_EMAIL,
42 body: this.instanceValidatorsService.BODY
47 this.openedModal = this.modalService.open(this.modal, { keyboard: false })
52 this.error = undefined
54 this.openedModal.close()
55 this.openedModal = null
59 const fromName = this.form.value['fromName']
60 const fromEmail = this.form.value[ 'fromEmail' ]
61 const body = this.form.value[ 'body' ]
63 this.instanceService.contactAdministrator(fromEmail, fromName, body)
66 this.notifier.success(this.i18n('Your message has been sent.'))
71 this.error = err.status === 403
72 ? this.i18n('You already sent this form recently')