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