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.ts68
1 files changed, 64 insertions, 4 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
index adbe7fe9a..32812d9e0 100644
--- a/client/src/app/+about/about-instance/contact-admin-modal.component.ts
+++ b/client/src/app/+about/about-instance/contact-admin-modal.component.ts
@@ -1,4 +1,7 @@
1import { Component, OnInit, ViewChild } from '@angular/core' 1import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core'
2import { ActivatedRoute, Router, NavigationEnd } from '@angular/router'
3import { Subject } from 'rxjs'
4import { takeUntil, filter } from 'rxjs/operators'
2import { Notifier, ServerService } from '@app/core' 5import { Notifier, ServerService } from '@app/core'
3import { 6import {
4 BODY_VALIDATOR, 7 BODY_VALIDATOR,
@@ -18,10 +21,13 @@ import { HTMLServerConfig } from '@shared/models'
18 templateUrl: './contact-admin-modal.component.html', 21 templateUrl: './contact-admin-modal.component.html',
19 styleUrls: [ './contact-admin-modal.component.scss' ] 22 styleUrls: [ './contact-admin-modal.component.scss' ]
20}) 23})
21export class ContactAdminModalComponent extends FormReactive implements OnInit { 24export class ContactAdminModalComponent extends FormReactive implements OnInit, OnDestroy {
22 @ViewChild('modal', { static: true }) modal: NgbModal 25 @ViewChild('modal', { static: true }) modal: NgbModal
23 26
24 error: string 27 error: string
28 destroy = new Subject<any>()
29
30 subject: string
25 31
26 private openedModal: NgbModalRef 32 private openedModal: NgbModalRef
27 private serverConfig: HTMLServerConfig 33 private serverConfig: HTMLServerConfig
@@ -31,7 +37,9 @@ export class ContactAdminModalComponent extends FormReactive implements OnInit {
31 private modalService: NgbModal, 37 private modalService: NgbModal,
32 private instanceService: InstanceService, 38 private instanceService: InstanceService,
33 private serverService: ServerService, 39 private serverService: ServerService,
34 private notifier: Notifier 40 private notifier: Notifier,
41 private route: ActivatedRoute,
42 private router: Router
35 ) { 43 ) {
36 super() 44 super()
37 } 45 }
@@ -40,6 +48,10 @@ export class ContactAdminModalComponent extends FormReactive implements OnInit {
40 return this.serverConfig.instance.name 48 return this.serverConfig.instance.name
41 } 49 }
42 50
51 get isContactFormEnabled () {
52 return this.serverConfig.email.enabled && this.serverConfig.contactForm.enabled
53 }
54
43 ngOnInit () { 55 ngOnInit () {
44 this.serverConfig = this.serverService.getHTMLConfig() 56 this.serverConfig = this.serverService.getHTMLConfig()
45 57
@@ -49,10 +61,46 @@ export class ContactAdminModalComponent extends FormReactive implements OnInit {
49 subject: SUBJECT_VALIDATOR, 61 subject: SUBJECT_VALIDATOR,
50 body: BODY_VALIDATOR 62 body: BODY_VALIDATOR
51 }) 63 })
64
65 // Direct access
66 if (/^\/about\/instance\/contact/.test(this.router.url)) {
67 this.show()
68 this.prefillForm()
69 }
70
71 // Router access
72 this.router.events
73 .pipe(
74 takeUntil(this.destroy),
75 filter(event => event instanceof NavigationEnd)
76 )
77 .subscribe((event: NavigationEnd) => {
78 if (/^\/about\/instance\/contact/.test(event.url)) {
79 this.show()
80 this.prefillForm()
81 }
82 })
83 }
84
85 ngOnDestroy () {
86 this.destroy.next()
52 } 87 }
53 88
54 show () { 89 show () {
90 // If contactForm not enabled redirect to 404
91 if (!this.isContactFormEnabled) {
92 return this.router.navigate([ '/404' ], { state: { type: 'other', obj: { status: 404 } }, skipLocationChange: true })
93 }
94
95 // Open modal
55 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false }) 96 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false })
97
98 // Go back to /about/instance after the modal is closed
99 this.openedModal.result.then(() => {
100 this.router.navigateByUrl('/about/instance')
101 }, () => {
102 this.router.navigateByUrl('/about/instance')
103 })
56 } 104 }
57 105
58 hide () { 106 hide () {
@@ -64,7 +112,7 @@ export class ContactAdminModalComponent extends FormReactive implements OnInit {
64 } 112 }
65 113
66 sendForm () { 114 sendForm () {
67 const fromName = this.form.value['fromName'] 115 const fromName = this.form.value[ 'fromName' ]
68 const fromEmail = this.form.value[ 'fromEmail' ] 116 const fromEmail = this.form.value[ 'fromEmail' ]
69 const subject = this.form.value[ 'subject' ] 117 const subject = this.form.value[ 'subject' ]
70 const body = this.form.value[ 'body' ] 118 const body = this.form.value[ 'body' ]
@@ -83,4 +131,16 @@ export class ContactAdminModalComponent extends FormReactive implements OnInit {
83 } 131 }
84 ) 132 )
85 } 133 }
134
135 private prefillForm () {
136 const { subject, body } = this.route.snapshot.queryParams
137
138 if (subject) {
139 this.form.get('subject').setValue(subject)
140 }
141
142 if (body) {
143 this.form.get('body').setValue(body)
144 }
145 }
86} 146}