Remove logic for validating PoP date range out of clin-fields vue component
This commit is contained in:
parent
53cef32af5
commit
eef15f311f
@ -1,7 +1,3 @@
|
|||||||
import * as R from 'ramda'
|
|
||||||
import { format } from 'date-fns'
|
|
||||||
|
|
||||||
import DateSelector from './date_selector'
|
|
||||||
import { emitEvent } from '../lib/emitters'
|
import { emitEvent } from '../lib/emitters'
|
||||||
import Modal from '../mixins/modal'
|
import Modal from '../mixins/modal'
|
||||||
import optionsinput from './options_input'
|
import optionsinput from './options_input'
|
||||||
@ -11,16 +7,12 @@ import PopDateRange from './pop_date_range'
|
|||||||
|
|
||||||
const TOTAL_AMOUNT = 'total_amount'
|
const TOTAL_AMOUNT = 'total_amount'
|
||||||
const OBLIGATED_AMOUNT = 'obligated_amount'
|
const OBLIGATED_AMOUNT = 'obligated_amount'
|
||||||
const START_DATE = 'start_date'
|
|
||||||
const END_DATE = 'end_date'
|
|
||||||
const POP = 'period_of_performance'
|
|
||||||
const NUMBER = 'number'
|
const NUMBER = 'number'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'clin-fields',
|
name: 'clin-fields',
|
||||||
|
|
||||||
components: {
|
components: {
|
||||||
DateSelector,
|
|
||||||
optionsinput,
|
optionsinput,
|
||||||
textinput,
|
textinput,
|
||||||
clindollaramount,
|
clindollaramount,
|
||||||
@ -39,79 +31,26 @@ export default {
|
|||||||
type: Number,
|
type: Number,
|
||||||
default: 0,
|
default: 0,
|
||||||
},
|
},
|
||||||
initialStartDate: {
|
|
||||||
type: String,
|
|
||||||
default: null,
|
|
||||||
},
|
|
||||||
initialEndDate: {
|
|
||||||
type: String,
|
|
||||||
default: null,
|
|
||||||
},
|
|
||||||
initialClinNumber: {
|
initialClinNumber: {
|
||||||
type: String,
|
type: String,
|
||||||
default: null,
|
default: null,
|
||||||
},
|
},
|
||||||
contractStart: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
contractEnd: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
data: function() {
|
data: function() {
|
||||||
const start = !!this.initialStartDate
|
|
||||||
? new Date(this.initialStartDate)
|
|
||||||
: undefined
|
|
||||||
const end = !!this.initialEndDate
|
|
||||||
? new Date(this.initialEndDate)
|
|
||||||
: undefined
|
|
||||||
const fundingValidation =
|
const fundingValidation =
|
||||||
this.initialObligated && this.initialTotal
|
this.initialObligated && this.initialTotal
|
||||||
? this.initialObligated <= this.initialTotal
|
? this.initialObligated <= this.initialTotal
|
||||||
: true
|
: true
|
||||||
const popValidation = !this.initialStartDate ? false : start < end
|
|
||||||
const clinNumber = !!this.initialClinNumber
|
const clinNumber = !!this.initialClinNumber
|
||||||
? this.initialClinNumber
|
? this.initialClinNumber
|
||||||
: undefined
|
: undefined
|
||||||
const contractStartDate = new Date(this.contractStart)
|
|
||||||
const contractEndDate = new Date(this.contractEnd)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
clinIndex: this.initialClinIndex,
|
clinIndex: this.initialClinIndex,
|
||||||
clinNumber: clinNumber,
|
clinNumber: clinNumber,
|
||||||
startDate: start,
|
|
||||||
endDate: end,
|
|
||||||
popValid: popValidation,
|
|
||||||
startDateValid: false,
|
|
||||||
endDateValid: false,
|
|
||||||
contractStartDate: contractStartDate,
|
|
||||||
contractEndDate: contractEndDate,
|
|
||||||
clinNumber: clinNumber,
|
clinNumber: clinNumber,
|
||||||
showClin: true,
|
showClin: true,
|
||||||
popErrors: [],
|
|
||||||
validations: [
|
|
||||||
{
|
|
||||||
func: this.popDateOrder,
|
|
||||||
message: 'PoP start date must be before end date.',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
func: this.popStartsAfterContract,
|
|
||||||
message: `PoP start date must be on or after ${format(
|
|
||||||
contractStartDate,
|
|
||||||
'MMM D, YYYY'
|
|
||||||
)}.`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
func: this.popEndsBeforeContract,
|
|
||||||
message: `PoP end date must be before or on ${format(
|
|
||||||
contractEndDate,
|
|
||||||
'MMM D, YYYY'
|
|
||||||
)}.`,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
totalAmount: this.initialTotal || 0,
|
totalAmount: this.initialTotal || 0,
|
||||||
obligatedAmount: this.initialObligated || 0,
|
obligatedAmount: this.initialObligated || 0,
|
||||||
fundingValid: fundingValidation,
|
fundingValid: fundingValidation,
|
||||||
@ -129,11 +68,6 @@ export default {
|
|||||||
obligatedAmount: this.initialObligated,
|
obligatedAmount: this.initialObligated,
|
||||||
totalAmount: this.initialTotal,
|
totalAmount: this.initialTotal,
|
||||||
})
|
})
|
||||||
emitEvent('field-mount', this, {
|
|
||||||
optional: false,
|
|
||||||
name: 'clins-' + this.clinIndex + '-' + POP,
|
|
||||||
valid: this.checkPopValid(),
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
@ -145,50 +79,6 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
checkPopValid: function() {
|
|
||||||
return (
|
|
||||||
this.popDateOrder() &&
|
|
||||||
this.popStartsAfterContract() &&
|
|
||||||
this.popEndsBeforeContract()
|
|
||||||
)
|
|
||||||
},
|
|
||||||
|
|
||||||
validatePop: function() {
|
|
||||||
this.popValid = this.checkPopValid()
|
|
||||||
emitEvent('field-change', this, {
|
|
||||||
name: 'clins-' + this.clinIndex + '-' + POP,
|
|
||||||
valid: this.popValid,
|
|
||||||
})
|
|
||||||
|
|
||||||
this.popErrors = R.pipe(
|
|
||||||
R.map(validation =>
|
|
||||||
!validation.func() ? validation.message : undefined
|
|
||||||
),
|
|
||||||
R.filter(Boolean)
|
|
||||||
)(this.validations)
|
|
||||||
},
|
|
||||||
|
|
||||||
popStartsAfterContract: function() {
|
|
||||||
if (this.startDateValid) {
|
|
||||||
return this.startDate >= this.contractStartDate
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
},
|
|
||||||
|
|
||||||
popEndsBeforeContract: function() {
|
|
||||||
if (this.endDateValid) {
|
|
||||||
return this.endDate <= this.contractEndDate
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
},
|
|
||||||
|
|
||||||
popDateOrder: function() {
|
|
||||||
if (!!this.startDate && !!this.endDate) {
|
|
||||||
return this.startDate < this.endDate
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
},
|
|
||||||
|
|
||||||
checkFundingValid: function() {
|
checkFundingValid: function() {
|
||||||
return this.obligatedAmount <= this.totalAmount
|
return this.obligatedAmount <= this.totalAmount
|
||||||
},
|
},
|
||||||
@ -207,14 +97,6 @@ export default {
|
|||||||
} else if (event.name.includes(OBLIGATED_AMOUNT)) {
|
} else if (event.name.includes(OBLIGATED_AMOUNT)) {
|
||||||
this.obligatedAmount = parseFloat(event.value)
|
this.obligatedAmount = parseFloat(event.value)
|
||||||
this.validateFunding()
|
this.validateFunding()
|
||||||
} else if (event.name.includes(START_DATE)) {
|
|
||||||
if (!!event.value) this.startDate = new Date(event.value)
|
|
||||||
if (!!event.valid) this.startDateValid = event.valid
|
|
||||||
this.validatePop()
|
|
||||||
} else if (event.name.includes(END_DATE)) {
|
|
||||||
if (!!event.value) this.endDate = new Date(event.value)
|
|
||||||
if (!!event.valid) this.endDateValid = event.valid
|
|
||||||
this.validatePop()
|
|
||||||
} else if (event.name.includes(NUMBER)) {
|
} else if (event.name.includes(NUMBER)) {
|
||||||
this.clinNumber = event.value
|
this.clinNumber = event.value
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user