aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/form-validators/video-ownership-change-validators.ts
blob: 3e7823c4912a1d27fed9c1b581e2c0db97d7ccc3 (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
import { AbstractControl, ValidationErrors, Validators } from '@angular/forms'
import { BuildFormValidator } from './form-validator.model'

export const OWNERSHIP_CHANGE_CHANNEL_VALIDATOR: BuildFormValidator = {
  VALIDATORS: [ Validators.required ],
  MESSAGES: {
    required: $localize`The channel is required.`
  }
}

export const OWNERSHIP_CHANGE_USERNAME_VALIDATOR: BuildFormValidator = {
  VALIDATORS: [ Validators.required, localAccountValidator ],
  MESSAGES: {
    required: $localize`The username is required.`,
    localAccountOnly: $localize`You can only transfer ownership to a local account`
  }
}

function localAccountValidator (control: AbstractControl): ValidationErrors {
  if (control.value.includes('@')) {
    return { localAccountOnly: true }
  }

  return null
}