aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/user-subscription/remote-subscribe.component.ts
blob: 7a81108cde0e36e2b22ebcb3980180e7ec06a6a0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { Component, Input, OnInit } from '@angular/core'
import { FormReactive } from '@app/shared/forms/form-reactive'
import {
  FormValidatorService,
  UserValidatorsService
} from '@app/shared/forms/form-validators'

@Component({
  selector: 'my-remote-subscribe',
  templateUrl: './remote-subscribe.component.html',
  styleUrls: ['./remote-subscribe.component.scss']
})
export class RemoteSubscribeComponent extends FormReactive implements OnInit {
  @Input() account: string
  @Input() interact = false
  @Input() showHelp = false

  constructor (
    protected formValidatorService: FormValidatorService,
    private userValidatorsService: UserValidatorsService
  ) {
    super()
  }

  ngOnInit () {
    this.buildForm({
      text: this.userValidatorsService.USER_EMAIL
    })
  }

  onValidKey () {
    this.onValueChanged()
    if (!this.form.valid) return

    this.formValidated()
  }

  formValidated () {
    const address = this.form.value['text']
    const [ , hostname ] = address.split('@')
    window.open(`https://${hostname}/authorize_interaction?acct=${this.account}`)
  }
}