]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-library/my-ownership/my-accept-ownership/my-accept-ownership.component.ts
Fix accept ownership change accept
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-library / my-ownership / my-accept-ownership / my-accept-ownership.component.ts
CommitLineData
ff2cac9f 1import { switchMap } from 'rxjs/operators'
74d63469 2import { Component, ElementRef, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
f8b2c1b4 3import { AuthService, Notifier } from '@app/core'
7ed1edbb
C
4import { OWNERSHIP_CHANGE_CHANNEL_VALIDATOR } from '@app/shared/form-validators/video-ownership-change-validators'
5import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
67ed6552 6import { VideoChannelService, VideoOwnershipService } from '@app/shared/shared-main'
74d63469 7import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
67ed6552 8import { VideoChangeOwnership, VideoChannel } from '@shared/models'
74d63469
GR
9
10@Component({
17119e4a
C
11 selector: 'my-accept-ownership',
12 templateUrl: './my-accept-ownership.component.html',
13 styleUrls: [ './my-accept-ownership.component.scss' ]
74d63469 14})
17119e4a 15export class MyAcceptOwnershipComponent extends FormReactive implements OnInit {
74d63469
GR
16 @Output() accepted = new EventEmitter<void>()
17
f36da21e 18 @ViewChild('modal', { static: true }) modal: ElementRef
74d63469
GR
19
20 videoChangeOwnership: VideoChangeOwnership | undefined = undefined
21
22 videoChannels: VideoChannel[]
23
24 error: string = null
25
26 constructor (
27 protected formValidatorService: FormValidatorService,
74d63469 28 private videoOwnershipService: VideoOwnershipService,
f8b2c1b4 29 private notifier: Notifier,
74d63469
GR
30 private authService: AuthService,
31 private videoChannelService: VideoChannelService,
66357162
C
32 private modalService: NgbModal
33 ) {
74d63469
GR
34 super()
35 }
36
37 ngOnInit () {
38 this.videoChannels = []
39
ff2cac9f
C
40 this.authService.userInformationLoaded
41 .pipe(switchMap(() => this.videoChannelService.listAccountVideoChannels(this.authService.getUser().account)))
74d63469
GR
42 .subscribe(videoChannels => this.videoChannels = videoChannels.data)
43
44 this.buildForm({
7ed1edbb 45 channel: OWNERSHIP_CHANGE_CHANNEL_VALIDATOR
74d63469
GR
46 })
47 }
48
49 show (videoChangeOwnership: VideoChangeOwnership) {
50 this.videoChangeOwnership = videoChangeOwnership
51 this.modalService
24e7916c 52 .open(this.modal, { centered: true })
74d63469
GR
53 .result
54 .then(() => this.acceptOwnership())
55 .catch(() => this.videoChangeOwnership = undefined)
56 }
57
58 acceptOwnership () {
59 const channel = this.form.value['channel']
60
61 const videoChangeOwnership = this.videoChangeOwnership
62 this.videoOwnershipService
63 .acceptOwnership(videoChangeOwnership.id, { channelId: channel })
64 .subscribe(
65 () => {
66357162 66 this.notifier.success($localize`Ownership accepted`)
74d63469
GR
67 if (this.accepted) this.accepted.emit()
68 this.videoChangeOwnership = undefined
69 },
70
f8b2c1b4 71 err => this.notifier.error(err.message)
74d63469
GR
72 )
73 }
74}