1 import { Component, ElementRef, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
2 import { AuthService, Notifier } from '@app/core'
3 import { OWNERSHIP_CHANGE_CHANNEL_VALIDATOR } from '@app/shared/form-validators/video-ownership-change-validators'
4 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
5 import { VideoChannelService, VideoOwnershipService } from '@app/shared/shared-main'
6 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
7 import { VideoChangeOwnership, VideoChannel } from '@shared/models'
10 selector: 'my-account-accept-ownership',
11 templateUrl: './my-account-accept-ownership.component.html',
12 styleUrls: [ './my-account-accept-ownership.component.scss' ]
14 export class MyAccountAcceptOwnershipComponent extends FormReactive implements OnInit {
15 @Output() accepted = new EventEmitter<void>()
17 @ViewChild('modal', { static: true }) modal: ElementRef
19 videoChangeOwnership: VideoChangeOwnership | undefined = undefined
21 videoChannels: VideoChannel[]
26 protected formValidatorService: FormValidatorService,
27 private videoOwnershipService: VideoOwnershipService,
28 private notifier: Notifier,
29 private authService: AuthService,
30 private videoChannelService: VideoChannelService,
31 private modalService: NgbModal
37 this.videoChannels = []
39 this.videoChannelService.listAccountVideoChannels(this.authService.getUser().account)
40 .subscribe(videoChannels => this.videoChannels = videoChannels.data)
43 channel: OWNERSHIP_CHANGE_CHANNEL_VALIDATOR
47 show (videoChangeOwnership: VideoChangeOwnership) {
48 this.videoChangeOwnership = videoChangeOwnership
50 .open(this.modal, { centered: true })
52 .then(() => this.acceptOwnership())
53 .catch(() => this.videoChangeOwnership = undefined)
57 const channel = this.form.value['channel']
59 const videoChangeOwnership = this.videoChangeOwnership
60 this.videoOwnershipService
61 .acceptOwnership(videoChangeOwnership.id, { channelId: channel })
64 this.notifier.success($localize`Ownership accepted`)
65 if (this.accepted) this.accepted.emit()
66 this.videoChangeOwnership = undefined
69 err => this.notifier.error(err.message)