1 import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
2 import { NotificationsService } from 'angular2-notifications'
3 import { I18n } from '@ngx-translate/i18n-polyfill'
4 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
5 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
6 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
7 import { FormReactive, UserValidatorsService } from '@app/shared/forms'
8 import { User, UserService } from '@app/shared/users'
11 selector: 'my-user-ban-modal',
12 templateUrl: './user-ban-modal.component.html',
13 styleUrls: [ './user-ban-modal.component.scss' ]
15 export class UserBanModalComponent extends FormReactive implements OnInit {
16 @ViewChild('modal') modal: NgbModal
17 @Output() userBanned = new EventEmitter<User>()
19 private userToBan: User
20 private openedModal: NgbModalRef
23 protected formValidatorService: FormValidatorService,
24 private modalService: NgbModal,
25 private notificationsService: NotificationsService,
26 private userService: UserService,
27 private userValidatorsService: UserValidatorsService,
35 reason: this.userValidatorsService.USER_BAN_REASON
39 openModal (user: User) {
41 this.openedModal = this.modalService.open(this.modal)
45 this.userToBan = undefined
46 this.openedModal.close()
50 const reason = this.form.value['reason'] || undefined
52 this.userService.banUser(this.userToBan, reason)
55 this.notificationsService.success(
57 this.i18n('User {{username}} banned.', { username: this.userToBan.username })
60 this.userBanned.emit(this.userToBan)
61 this.hideBanUserModal()
64 err => this.notificationsService.error(this.i18n('Error'), err.message)