import { Component, OnInit, ViewChild } from '@angular/core'
+import { Router } from '@angular/router'
import { Notifier, ServerService } from '@app/core'
import {
BODY_VALIDATOR,
import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
import { HTMLServerConfig } from '@shared/models'
+type Prefill = {
+ subject?: string
+ body?: string
+}
+
@Component({
selector: 'my-contact-admin-modal',
templateUrl: './contact-admin-modal.component.html',
constructor (
protected formValidatorService: FormValidatorService,
+ private router: Router,
private modalService: NgbModal,
private instanceService: InstanceService,
private serverService: ServerService,
})
}
- show () {
+ isContactFormEnabled () {
+ return this.serverConfig.email.enabled && this.serverConfig.contactForm.enabled
+ }
+
+ show (prefill: Prefill = {}) {
this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false })
+
+ this.openedModal.shown.subscribe(() => this.prefillForm(prefill))
+ this.openedModal.result.finally(() => this.router.navigateByUrl('/about/instance'))
}
hide () {
}
sendForm () {
- const fromName = this.form.value['fromName']
+ const fromName = this.form.value[ 'fromName' ]
const fromEmail = this.form.value[ 'fromEmail' ]
const subject = this.form.value[ 'subject' ]
const body = this.form.value[ 'body' ]
}
)
}
+
+ private prefillForm (prefill: Prefill) {
+ if (prefill.subject) {
+ this.form.get('subject').setValue(prefill.subject)
+ }
+
+ if (prefill.body) {
+ this.form.get('body').setValue(prefill.body)
+ }
+ }
}