1 import { Component, OnInit, ViewChild } from '@angular/core'
2 import { Router } from '@angular/router'
3 import { Notifier, ServerService } from '@app/core'
9 } from '@app/shared/form-validators/instance-validators'
10 import { FormReactive, FormReactiveService } from '@app/shared/shared-forms'
11 import { InstanceService } from '@app/shared/shared-instance'
12 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
13 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
14 import { HTMLServerConfig, HttpStatusCode } from '@shared/models'
22 selector: 'my-contact-admin-modal',
23 templateUrl: './contact-admin-modal.component.html',
24 styleUrls: [ './contact-admin-modal.component.scss' ]
26 export class ContactAdminModalComponent extends FormReactive implements OnInit {
27 @ViewChild('modal', { static: true }) modal: NgbModal
31 private openedModal: NgbModalRef
32 private serverConfig: HTMLServerConfig
35 protected formReactiveService: FormReactiveService,
36 private router: Router,
37 private modalService: NgbModal,
38 private instanceService: InstanceService,
39 private serverService: ServerService,
40 private notifier: Notifier
46 return this.serverConfig.instance.name
50 this.serverConfig = this.serverService.getHTMLConfig()
53 fromName: FROM_NAME_VALIDATOR,
54 fromEmail: FROM_EMAIL_VALIDATOR,
55 subject: SUBJECT_VALIDATOR,
60 isContactFormEnabled () {
61 return this.serverConfig.email.enabled && this.serverConfig.contactForm.enabled
64 show (prefill: Prefill = {}) {
65 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false })
67 this.openedModal.shown.subscribe(() => this.prefillForm(prefill))
68 this.openedModal.result.finally(() => this.router.navigateByUrl('/about/instance'))
73 this.error = undefined
75 this.openedModal.close()
76 this.openedModal = null
80 const fromName = this.form.value['fromName']
81 const fromEmail = this.form.value['fromEmail']
82 const subject = this.form.value['subject']
83 const body = this.form.value['body']
85 this.instanceService.contactAdministrator(fromEmail, fromName, subject, body)
88 this.notifier.success($localize`Your message has been sent.`)
93 this.error = err.status === HttpStatusCode.FORBIDDEN_403
94 ? $localize`You already sent this form recently`
100 private prefillForm (prefill: Prefill) {
101 if (prefill.subject) {
102 this.form.get('subject').setValue(prefill.subject)
106 this.form.get('body').setValue(prefill.body)