]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+about/about-instance/contact-admin-modal.component.ts
Add categories and languages to about page
[github/Chocobozzz/PeerTube.git] / client / src / app / +about / about-instance / contact-admin-modal.component.ts
CommitLineData
d3e56c0c 1import { Component, OnInit, ViewChild } from '@angular/core'
26a008fe 2import { Notifier, ServerService } from '@app/core'
d3e56c0c
C
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 {
f36da21e 16 @ViewChild('modal', { static: true }) modal: NgbModal
d3e56c0c
C
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,
26a008fe 27 private serverService: ServerService,
d3e56c0c
C
28 private notifier: Notifier,
29 private i18n: I18n
30 ) {
31 super()
32 }
33
26a008fe
C
34 get instanceName () {
35 return this.serverService.getConfig().instance.name
36 }
37
d3e56c0c
C
38 ngOnInit () {
39 this.buildForm({
40 fromName: this.instanceValidatorsService.FROM_NAME,
41 fromEmail: this.instanceValidatorsService.FROM_EMAIL,
4e9fa5b7 42 subject: this.instanceValidatorsService.SUBJECT,
d3e56c0c
C
43 body: this.instanceValidatorsService.BODY
44 })
45 }
46
47 show () {
48 this.openedModal = this.modalService.open(this.modal, { keyboard: false })
49 }
50
51 hide () {
52 this.form.reset()
53 this.error = undefined
54
55 this.openedModal.close()
56 this.openedModal = null
57 }
58
59 sendForm () {
60 const fromName = this.form.value['fromName']
61 const fromEmail = this.form.value[ 'fromEmail' ]
4e9fa5b7 62 const subject = this.form.value[ 'subject' ]
d3e56c0c
C
63 const body = this.form.value[ 'body' ]
64
4e9fa5b7 65 this.instanceService.contactAdministrator(fromEmail, fromName, subject, body)
d3e56c0c
C
66 .subscribe(
67 () => {
68 this.notifier.success(this.i18n('Your message has been sent.'))
69 this.hide()
70 },
71
72 err => {
73 this.error = err.status === 403
74 ? this.i18n('You already sent this form recently')
75 : err.message
76 }
77 )
78 }
79}