1 import { Component, OnInit, ViewChild } from '@angular/core'
2 import { Notifier, ServerService } from '@app/core'
3 import { FormReactive, FormValidatorService, InstanceValidatorsService } from '@app/shared/shared-forms'
4 import { InstanceService } from '@app/shared/shared-instance'
5 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
6 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
7 import { I18n } from '@ngx-translate/i18n-polyfill'
8 import { ServerConfig } from '@shared/models'
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', { static: true }) modal: NgbModal
20 private openedModal: NgbModalRef
21 private serverConfig: ServerConfig
24 protected formValidatorService: FormValidatorService,
25 private modalService: NgbModal,
26 private instanceValidatorsService: InstanceValidatorsService,
27 private instanceService: InstanceService,
28 private serverService: ServerService,
29 private notifier: Notifier,
36 return this.serverConfig.instance.name
40 this.serverConfig = this.serverService.getTmpConfig()
41 this.serverService.getConfig()
42 .subscribe(config => this.serverConfig = config)
45 fromName: this.instanceValidatorsService.FROM_NAME,
46 fromEmail: this.instanceValidatorsService.FROM_EMAIL,
47 subject: this.instanceValidatorsService.SUBJECT,
48 body: this.instanceValidatorsService.BODY
53 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false })
58 this.error = undefined
60 this.openedModal.close()
61 this.openedModal = null
65 const fromName = this.form.value['fromName']
66 const fromEmail = this.form.value[ 'fromEmail' ]
67 const subject = this.form.value[ 'subject' ]
68 const body = this.form.value[ 'body' ]
70 this.instanceService.contactAdministrator(fromEmail, fromName, subject, body)
73 this.notifier.success(this.i18n('Your message has been sent.'))
78 this.error = err.status === 403
79 ? this.i18n('You already sent this form recently')