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 { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
14 import { HTMLServerConfig } from '@shared/models'
17 selector: 'my-contact-admin-modal',
18 templateUrl: './contact-admin-modal.component.html',
19 styleUrls: [ './contact-admin-modal.component.scss' ]
21 export class ContactAdminModalComponent extends FormReactive implements OnInit {
22 @ViewChild('modal', { static: true }) modal: NgbModal
26 private openedModal: NgbModalRef
27 private serverConfig: HTMLServerConfig
30 protected formValidatorService: FormValidatorService,
31 private modalService: NgbModal,
32 private instanceService: InstanceService,
33 private serverService: ServerService,
34 private notifier: Notifier
40 return this.serverConfig.instance.name
44 this.serverConfig = this.serverService.getHTMLConfig()
47 fromName: FROM_NAME_VALIDATOR,
48 fromEmail: FROM_EMAIL_VALIDATOR,
49 subject: SUBJECT_VALIDATOR,
55 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false })
60 this.error = undefined
62 this.openedModal.close()
63 this.openedModal = null
67 const fromName = this.form.value['fromName']
68 const fromEmail = this.form.value[ 'fromEmail' ]
69 const subject = this.form.value[ 'subject' ]
70 const body = this.form.value[ 'body' ]
72 this.instanceService.contactAdministrator(fromEmail, fromName, subject, body)
75 this.notifier.success($localize`Your message has been sent.`)
80 this.error = err.status === HttpStatusCode.FORBIDDEN_403
81 ? $localize`You already sent this form recently`