Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
// tslint:disable:max-classes-per-file
import { InputState } from '../../inputs/InputState'
// @todo this needs fixing, validators took technical debt because of forms
import { isValidMonth } from '../../../validators/isValidExpiryDate'
import { observable, computed } from 'xmobx/mobx'

// month > 0 && month <= 12
// && >= current month
const isValidYear = (value: number | string) => +value <= 12

export class ExpiryDateState {
  @observable.ref monthState: InputState = new InputState()
  @observable.ref yearState: InputState = new InputState()
  @computed
  get isValid() {
    // && isValidYear(this.monthState.value, this.yearState.value)
    return this.monthState.isValid && this.yearState.isValid
  }
  toJSON() {
    return {
      month: this.monthState.value,
      year: this.monthState.value,
    }
  }
  static init() {
    const state = new ExpiryDateState()
    state.monthState.setValidator(isValidMonth)
    state.monthState.setType('number')
    state.yearState.setValidator(isValidYear)
    state.yearState.setType('number')
    return state
  }
}