1 import { Component, OnInit, ViewChild } from '@angular/core'
2 import { Notifier, ServerService } from '@app/core'
8 } from '@app/shared/form-validators/instance-validators'
9 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
10 import { InstanceService } from '@app/shared/shared-instance'
11 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
12 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
13 import { ServerConfig } from '@shared/models'
16 selector: 'my-contact-admin-modal',
17 templateUrl: './contact-admin-modal.component.html',
18 styleUrls: [ './contact-admin-modal.component.scss' ]
20 export class ContactAdminModalComponent extends FormReactive implements OnInit {
21 @ViewChild('modal', { static: true }) modal: NgbModal
25 private openedModal: NgbModalRef
26 private serverConfig: ServerConfig
29 protected formValidatorService: FormValidatorService,
30 private modalService: NgbModal,
31 private instanceService: InstanceService,
32 private serverService: ServerService,
33 private notifier: Notifier
39 return this.serverConfig.instance.name
43 this.serverConfig = this.serverService.getTmpConfig()
44 this.serverService.getConfig()
45 .subscribe(config => this.serverConfig = config)
48 fromName: FROM_NAME_VALIDATOR,
49 fromEmail: FROM_EMAIL_VALIDATOR,
50 subject: SUBJECT_VALIDATOR,
56 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false })
61 this.error = undefined
63 this.openedModal.close()
64 this.openedModal = null
68 const fromName = this.form.value['fromName']
69 const fromEmail = this.form.value[ 'fromEmail' ]
70 const subject = this.form.value[ 'subject' ]
71 const body = this.form.value[ 'body' ]
73 this.instanceService.contactAdministrator(fromEmail, fromName, subject, body)
76 this.notifier.success($localize`Your message has been sent.`)
81 this.error = err.status === 403
82 ? $localize`You already sent this form recently`