]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+about/about-instance/contact-admin-modal.component.ts
provide specific engine boundaries for nodejs and yarn
[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'
ba430d75 9import { ServerConfig } from '@shared/models'
d3e56c0c
C
10
11@Component({
12 selector: 'my-contact-admin-modal',
13 templateUrl: './contact-admin-modal.component.html',
14 styleUrls: [ './contact-admin-modal.component.scss' ]
15})
16export class ContactAdminModalComponent extends FormReactive implements OnInit {
f36da21e 17 @ViewChild('modal', { static: true }) modal: NgbModal
d3e56c0c
C
18
19 error: string
20
21 private openedModal: NgbModalRef
ba430d75 22 private serverConfig: ServerConfig
d3e56c0c
C
23
24 constructor (
25 protected formValidatorService: FormValidatorService,
26 private modalService: NgbModal,
27 private instanceValidatorsService: InstanceValidatorsService,
28 private instanceService: InstanceService,
26a008fe 29 private serverService: ServerService,
d3e56c0c
C
30 private notifier: Notifier,
31 private i18n: I18n
32 ) {
33 super()
34 }
35
26a008fe 36 get instanceName () {
ba430d75 37 return this.serverConfig.instance.name
26a008fe
C
38 }
39
d3e56c0c 40 ngOnInit () {
ba430d75
C
41 this.serverConfig = this.serverService.getTmpConfig()
42 this.serverService.getConfig()
43 .subscribe(config => this.serverConfig = config)
44
d3e56c0c
C
45 this.buildForm({
46 fromName: this.instanceValidatorsService.FROM_NAME,
47 fromEmail: this.instanceValidatorsService.FROM_EMAIL,
4e9fa5b7 48 subject: this.instanceValidatorsService.SUBJECT,
d3e56c0c
C
49 body: this.instanceValidatorsService.BODY
50 })
51 }
52
53 show () {
24e7916c 54 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false })
d3e56c0c
C
55 }
56
57 hide () {
58 this.form.reset()
59 this.error = undefined
60
61 this.openedModal.close()
62 this.openedModal = null
63 }
64
65 sendForm () {
66 const fromName = this.form.value['fromName']
67 const fromEmail = this.form.value[ 'fromEmail' ]
4e9fa5b7 68 const subject = this.form.value[ 'subject' ]
d3e56c0c
C
69 const body = this.form.value[ 'body' ]
70
4e9fa5b7 71 this.instanceService.contactAdministrator(fromEmail, fromName, subject, body)
d3e56c0c
C
72 .subscribe(
73 () => {
74 this.notifier.success(this.i18n('Your message has been sent.'))
75 this.hide()
76 },
77
78 err => {
79 this.error = err.status === 403
80 ? this.i18n('You already sent this form recently')
81 : err.message
82 }
83 )
84 }
85}