]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-moderation/user-ban-modal.component.ts
Migrate to $localize
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-moderation / user-ban-modal.component.ts
1 import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
2 import { Notifier, UserService } from '@app/core'
3 import { FormReactive, FormValidatorService, UserValidatorsService } from '@app/shared/shared-forms'
4 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
5 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
6 import { User } from '@shared/models'
7
8 @Component({
9 selector: 'my-user-ban-modal',
10 templateUrl: './user-ban-modal.component.html',
11 styleUrls: [ './user-ban-modal.component.scss' ]
12 })
13 export class UserBanModalComponent extends FormReactive implements OnInit {
14 @ViewChild('modal', { static: true }) modal: NgbModal
15 @Output() userBanned = new EventEmitter<User | User[]>()
16
17 private usersToBan: User | User[]
18 private openedModal: NgbModalRef
19
20 constructor (
21 protected formValidatorService: FormValidatorService,
22 private modalService: NgbModal,
23 private notifier: Notifier,
24 private userService: UserService,
25 private userValidatorsService: UserValidatorsService
26 ) {
27 super()
28 }
29
30 ngOnInit () {
31 this.buildForm({
32 reason: this.userValidatorsService.USER_BAN_REASON
33 })
34 }
35
36 openModal (user: User | User[]) {
37 this.usersToBan = user
38 this.openedModal = this.modalService.open(this.modal, { centered: true })
39 }
40
41 hide () {
42 this.usersToBan = undefined
43 this.openedModal.close()
44 }
45
46 async banUser () {
47 const reason = this.form.value['reason'] || undefined
48
49 this.userService.banUsers(this.usersToBan, reason)
50 .subscribe(
51 () => {
52 const message = Array.isArray(this.usersToBan)
53 ? $localize`${this.usersToBan.length} users banned.`
54 : $localize`User ${this.usersToBan.username} banned.`
55
56 this.notifier.success(message)
57
58 this.userBanned.emit(this.usersToBan)
59 this.hide()
60 },
61
62 err => this.notifier.error(err.message)
63 )
64 }
65
66 }