1 import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
2 import { Notifier } from '@app/core'
3 import { FormReactive, FormReactiveService } from '@app/shared/shared-forms'
4 import { AbuseService } from '@app/shared/shared-moderation'
5 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
6 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
7 import { AdminAbuse } from '@shared/models'
8 import { ABUSE_MODERATION_COMMENT_VALIDATOR } from '../form-validators/abuse-validators'
11 selector: 'my-moderation-comment-modal',
12 templateUrl: './moderation-comment-modal.component.html',
13 styleUrls: [ './moderation-comment-modal.component.scss' ]
15 export class ModerationCommentModalComponent extends FormReactive implements OnInit {
16 @ViewChild('modal', { static: true }) modal: NgbModal
17 @Output() commentUpdated = new EventEmitter<string>()
19 private abuseToComment: AdminAbuse
20 private openedModal: NgbModalRef
23 protected formReactiveService: FormReactiveService,
24 private modalService: NgbModal,
25 private notifier: Notifier,
26 private abuseService: AbuseService
33 moderationComment: ABUSE_MODERATION_COMMENT_VALIDATOR
37 openModal (abuseToComment: AdminAbuse) {
38 this.abuseToComment = abuseToComment
39 this.openedModal = this.modalService.open(this.modal, { centered: true })
41 this.form.patchValue({
42 moderationComment: this.abuseToComment.moderationComment
47 this.abuseToComment = undefined
48 this.openedModal.close()
53 const moderationComment: string = this.form.value['moderationComment']
55 this.abuseService.updateAbuse(this.abuseToComment, { moderationComment })
58 this.notifier.success($localize`Comment updated.`)
60 this.commentUpdated.emit(moderationComment)
64 error: err => this.notifier.error(err.message)