Skip to content

Commit

Permalink
Uforetrygd validering og tilpasning av mal
Browse files Browse the repository at this point in the history
  • Loading branch information
betsytraran committed Oct 5, 2023
1 parent 1542526 commit 61d4f1f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ export const initialValuesBasedOnMal = (mal: any) => {
initialValuesMal.pensjonforvalter.alderspensjon,
)
}
if (initialValuesMal.pensjonforvalter?.uforetrygd) {
initialValuesMal.pensjonforvalter.uforetrygd = getUpdatedUforetrygdData(
initialValuesMal.pensjonforvalter.uforetrygd,
)
}

initialValuesMal.environments = filterMiljoe(dollyEnvironments, mal.bestilling.environments)
return initialValuesMal
Expand All @@ -76,6 +81,14 @@ const getUpdatedAlderspensjonData = (alderspensjonData) => {
return newAlderspensjonData
}

const getUpdatedUforetrygdData = (uforetrygdData) => {
const newUforetrygdData = Object.assign({}, uforetrygdData)
if (!isAfter(new Date(newUforetrygdData.onsketVirkningsDato), new Date())) {
newUforetrygdData.onsketVirkningsDato = setDate(addMonths(new Date(), 1), 1)
}
return newUforetrygdData
}

const getUpdatedArenaforvalterData = (arenaforvalterData) => {
let filtrertArenaforvalterData = Object.assign({}, arenaforvalterData)
if (_.isEmpty(filtrertArenaforvalterData.aap)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as _ from 'lodash-es'
import { useNavEnheter } from '@/utils/hooks/useNorg2'
import { BarnetilleggForm } from '@/components/fagsystem/uforetrygd/form/partials/BarnetilleggForm'
import { validation } from '@/components/fagsystem/uforetrygd/form/validation'
import { addDays } from 'date-fns'

const uforetrygdPath = 'pensjonforvalter.uforetrygd'

Expand Down Expand Up @@ -43,6 +44,7 @@ export const UforetrygdForm = ({ formikBag }) => {
<FormikDatepicker
name={`${uforetrygdPath}.onsketVirkningsDato`}
label="Ønsket virkningsdato"
minDate={addDays(new Date(), 1)}
/>
<FormikDatepicker name={`${uforetrygdPath}.uforetidspunkt`} label="Uføretidspunkt" />
<FormikTextInput
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Yup from 'yup'
import { ifPresent, requiredNumber, requiredString } from '@/utils/YupValidations'
import { isFuture, isPast } from 'date-fns'
import { isBefore, isFuture, isPast } from 'date-fns'
import { testDatoFom, testDatoTom } from '@/components/fagsystem/utils'

const erIkkeLik = () => {
Expand Down Expand Up @@ -40,7 +40,17 @@ export const validation = {
uforetrygd: ifPresent(
'$pensjonforvalter.uforetrygd',
Yup.object({
kravFremsattDato: Yup.date().nullable(),
kravFremsattDato: Yup.date()
.test(
'er-foer-virkningsdato',
'Dato må være før ønsket virkningsdato',
function validDate(kravFremsattDato) {
const virkningsdato =
this.options.context?.pensjonforvalter?.uforetrygd?.onsketVirkningsDato
return isBefore(new Date(kravFremsattDato), new Date(virkningsdato))
},
)
.nullable(),
onsketVirkningsDato: datoErFremtidig().nullable(),
uforetidspunkt: Yup.date()
.test('er-historisk', 'Dato må være historisk', function validDate(dato) {
Expand Down

0 comments on commit 61d4f1f

Please sign in to comment.