aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+about/about-instance/contact-admin-modal.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/+about/about-instance/contact-admin-modal.component.ts')
-rw-r--r--client/src/app/+about/about-instance/contact-admin-modal.component.ts72
1 files changed, 72 insertions, 0 deletions
diff --git a/client/src/app/+about/about-instance/contact-admin-modal.component.ts b/client/src/app/+about/about-instance/contact-admin-modal.component.ts
new file mode 100644
index 000000000..2f707bd53
--- /dev/null
+++ b/client/src/app/+about/about-instance/contact-admin-modal.component.ts
@@ -0,0 +1,72 @@
1import { Component, OnInit, ViewChild } from '@angular/core'
2import { Notifier } from '@app/core'
3import { I18n } from '@ngx-translate/i18n-polyfill'
4import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
5import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
6import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
7import { FormReactive, InstanceValidatorsService } from '@app/shared'
8import { InstanceService } from '@app/shared/instance/instance.service'
9
10@Component({
11 selector: 'my-contact-admin-modal',
12 templateUrl: './contact-admin-modal.component.html',
13 styleUrls: [ './contact-admin-modal.component.scss' ]
14})
15export class ContactAdminModalComponent extends FormReactive implements OnInit {
16 @ViewChild('modal') modal: NgbModal
17
18 error: string
19
20 private openedModal: NgbModalRef
21
22 constructor (
23 protected formValidatorService: FormValidatorService,
24 private modalService: NgbModal,
25 private instanceValidatorsService: InstanceValidatorsService,
26 private instanceService: InstanceService,
27 private notifier: Notifier,
28 private i18n: I18n
29 ) {
30 super()
31 }
32
33 ngOnInit () {
34 this.buildForm({
35 fromName: this.instanceValidatorsService.FROM_NAME,
36 fromEmail: this.instanceValidatorsService.FROM_EMAIL,
37 body: this.instanceValidatorsService.BODY
38 })
39 }
40
41 show () {
42 this.openedModal = this.modalService.open(this.modal, { keyboard: false })
43 }
44
45 hide () {
46 this.form.reset()
47 this.error = undefined
48
49 this.openedModal.close()
50 this.openedModal = null
51 }
52
53 sendForm () {
54 const fromName = this.form.value['fromName']
55 const fromEmail = this.form.value[ 'fromEmail' ]
56 const body = this.form.value[ 'body' ]
57
58 this.instanceService.contactAdministrator(fromEmail, fromName, body)
59 .subscribe(
60 () => {
61 this.notifier.success(this.i18n('Your message has been sent.'))
62 this.hide()
63 },
64
65 err => {
66 this.error = err.status === 403
67 ? this.i18n('You already sent this form recently')
68 : err.message
69 }
70 )
71 }
72}