diff options
author | Chocobozzz <me@florianbigard.com> | 2019-01-10 11:12:41 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-01-10 11:32:38 +0100 |
commit | d3e56c0c4b307c99e83fbafb7f2c5884cbc20055 (patch) | |
tree | 39976ee10a49fa2b9d7eb87437f59c872e7db0b8 /client/src/app/+about/about-instance/contact-admin-modal.component.ts | |
parent | 3866f1a02f73665541468fbadcc3cd2cc459aef2 (diff) | |
download | PeerTube-d3e56c0c4b307c99e83fbafb7f2c5884cbc20055.tar.gz PeerTube-d3e56c0c4b307c99e83fbafb7f2c5884cbc20055.tar.zst PeerTube-d3e56c0c4b307c99e83fbafb7f2c5884cbc20055.zip |
Implement contact form in the client
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.ts | 72 |
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 @@ | |||
1 | import { Component, OnInit, ViewChild } from '@angular/core' | ||
2 | import { Notifier } from '@app/core' | ||
3 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
4 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' | ||
5 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' | ||
6 | import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' | ||
7 | import { FormReactive, InstanceValidatorsService } from '@app/shared' | ||
8 | import { 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 | }) | ||
15 | export 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 | } | ||