]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+about/about-instance/contact-admin-modal.component.ts
Use HTML config when possible
[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'
2989628b 14import { HTMLServerConfig } 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
2989628b 27 private serverConfig: HTMLServerConfig
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 () {
2989628b 44 this.serverConfig = this.serverService.getHTMLConfig()
ba430d75 45
d3e56c0c 46 this.buildForm({
7ed1edbb
C
47 fromName: FROM_NAME_VALIDATOR,
48 fromEmail: FROM_EMAIL_VALIDATOR,
49 subject: SUBJECT_VALIDATOR,
50 body: BODY_VALIDATOR
d3e56c0c
C
51 })
52 }
53
54 show () {
24e7916c 55 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false })
d3e56c0c
C
56 }
57
58 hide () {
59 this.form.reset()
60 this.error = undefined
61
62 this.openedModal.close()
63 this.openedModal = null
64 }
65
66 sendForm () {
67 const fromName = this.form.value['fromName']
68 const fromEmail = this.form.value[ 'fromEmail' ]
4e9fa5b7 69 const subject = this.form.value[ 'subject' ]
d3e56c0c
C
70 const body = this.form.value[ 'body' ]
71
4e9fa5b7 72 this.instanceService.contactAdministrator(fromEmail, fromName, subject, body)
d3e56c0c
C
73 .subscribe(
74 () => {
66357162 75 this.notifier.success($localize`Your message has been sent.`)
d3e56c0c
C
76 this.hide()
77 },
78
79 err => {
f2eb23cd 80 this.error = err.status === HttpStatusCode.FORBIDDEN_403
66357162 81 ? $localize`You already sent this form recently`
d3e56c0c
C
82 : err.message
83 }
84 )
85 }
86}