]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/shared-moderation/report-modals/account-report.component.ts
Refactor form reactive
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-moderation / report-modals / account-report.component.ts
index 78ca934c732df58484db9169c482500e20128c06..d587a97091140c4410bc303492cf5d1fb683032b 100644 (file)
@@ -1,12 +1,13 @@
 import { mapValues, pickBy } from 'lodash-es'
-import { Component, Input, OnInit, ViewChild } from '@angular/core'
+import { Component, OnInit, ViewChild } from '@angular/core'
 import { Notifier } from '@app/core'
-import { AbuseValidatorsService, FormReactive, FormValidatorService } from '@app/shared/shared-forms'
+import { ABUSE_REASON_VALIDATOR } from '@app/shared/form-validators/abuse-validators'
+import { FormReactive, FormReactiveService } from '@app/shared/shared-forms'
 import { Account } from '@app/shared/shared-main'
 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
-import { I18n } from '@ngx-translate/i18n-polyfill'
-import { abusePredefinedReasonsMap, AbusePredefinedReasonsString } from '@shared/models'
+import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'
+import { AbusePredefinedReasonsString } from '@shared/models'
 import { AbuseService } from '../abuse.service'
 
 @Component({
@@ -15,23 +16,20 @@ import { AbuseService } from '../abuse.service'
   styleUrls: [ './report.component.scss' ]
 })
 export class AccountReportComponent extends FormReactive implements OnInit {
-  @Input() account: Account = null
-
   @ViewChild('modal', { static: true }) modal: NgbModal
 
   error: string = null
   predefinedReasons: { id: AbusePredefinedReasonsString, label: string, description?: string, help?: string }[] = []
   modalTitle: string
+  account: Account = null
 
   private openedModal: NgbModalRef
 
   constructor (
-    protected formValidatorService: FormValidatorService,
+    protected formReactiveService: FormReactiveService,
     private modalService: NgbModal,
-    private abuseValidatorsService: AbuseValidatorsService,
     private abuseService: AbuseService,
-    private notifier: Notifier,
-    private i18n: I18n
+    private notifier: Notifier
   ) {
     super()
   }
@@ -49,17 +47,19 @@ export class AccountReportComponent extends FormReactive implements OnInit {
   }
 
   ngOnInit () {
-    this.modalTitle = this.i18n('Report {{displayName}}', { displayName: this.account.displayName })
-
     this.buildForm({
-      reason: this.abuseValidatorsService.ABUSE_REASON,
+      reason: ABUSE_REASON_VALIDATOR,
       predefinedReasons: mapValues(abusePredefinedReasonsMap, r => null)
     })
 
     this.predefinedReasons = this.abuseService.getPrefefinedReasons('account')
   }
 
-  show () {
+  show (account: Account) {
+    this.account = account
+
+    this.modalTitle = $localize`Report ${this.account.displayName}`
+
     this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false, size: 'lg' })
   }
 
@@ -78,14 +78,14 @@ export class AccountReportComponent extends FormReactive implements OnInit {
       account: {
         id: this.account.id
       }
-    }).subscribe(
-      () => {
-        this.notifier.success(this.i18n('Account reported.'))
+    }).subscribe({
+      next: () => {
+        this.notifier.success($localize`Account reported.`)
         this.hide()
       },
 
-      err => this.notifier.error(err.message)
-    )
+      error: err => this.notifier.error(err.message)
+    })
   }
 
   isRemote () {