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