import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
import { FormReactive, UserValidatorsService } from '@app/shared/forms'
-import { User, UserService } from '@app/shared/users'
+import { UserService } from '@app/shared/users'
+import { User } from '../../../../../shared'
@Component({
selector: 'my-user-ban-modal',
})
export class UserBanModalComponent extends FormReactive implements OnInit {
@ViewChild('modal') modal: NgbModal
- @Output() userBanned = new EventEmitter<User>()
+ @Output() userBanned = new EventEmitter<User | User[]>()
- private userToBan: User
+ private usersToBan: User | User[]
private openedModal: NgbModalRef
constructor (
})
}
- openModal (user: User) {
- this.userToBan = user
+ openModal (user: User | User[]) {
+ this.usersToBan = user
this.openedModal = this.modalService.open(this.modal)
}
hideBanUserModal () {
- this.userToBan = undefined
+ this.usersToBan = undefined
this.openedModal.close()
}
async banUser () {
const reason = this.form.value['reason'] || undefined
- this.userService.banUser(this.userToBan, reason)
+ this.userService.banUsers(this.usersToBan, reason)
.subscribe(
() => {
- this.notificationsService.success(
- this.i18n('Success'),
- this.i18n('User {{username}} banned.', { username: this.userToBan.username })
- )
+ const message = Array.isArray(this.usersToBan)
+ ? this.i18n('{{num}} users banned.', { num: this.usersToBan.length })
+ : this.i18n('User {{username}} banned.', { username: this.usersToBan.username })
- this.userBanned.emit(this.userToBan)
+ this.notificationsService.success(this.i18n('Success'), message)
+
+ this.userBanned.emit(this.usersToBan)
this.hideBanUserModal()
},