-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d589054
commit 6e70d8e
Showing
4 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
apps/dolly-frontend/src/main/js/src/components/fagsystem/uforetrygd/form/validation.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import * as Yup from 'yup' | ||
import { ifPresent, requiredNumber, requiredString } from '@/utils/YupValidations' | ||
import { isFuture, isPast } from 'date-fns' | ||
import { testDatoFom, testDatoTom } from '@/components/fagsystem/utils' | ||
|
||
const erIkkeLik = () => { | ||
return Yup.string().test( | ||
'er-ikke-lik', | ||
'Saksbehandler og attesterer kan ikke være samme person', | ||
function testIdenter() { | ||
const values = this.options.context | ||
const { saksbehandler, attesterer } = values?.pensjonforvalter?.uforetrygd | ||
if (!saksbehandler || !attesterer) { | ||
return true | ||
} | ||
return saksbehandler !== attesterer | ||
}, | ||
) | ||
} | ||
|
||
const datoErFremtidig = () => { | ||
return Yup.date().test('er-fremtidig', 'Dato må være frem i tid', function validDate(dato) { | ||
if (!dato) { | ||
return true | ||
} | ||
return isFuture(dato) | ||
}) | ||
} | ||
|
||
const forventetInntekt = Yup.object({ | ||
datoFom: testDatoFom(datoErFremtidig().nullable(), 'datoTom', 'Dato må være før dato t.o.m.'), // Før datoTom, frem i tid??? | ||
datoTom: testDatoTom(datoErFremtidig().nullable(), 'datoFom', 'Dato må være etter dato f.o.m.'), // Etter datoFom, frem i tid??? | ||
inntektType: Yup.string().nullable(), | ||
belop: Yup.number() | ||
.nullable() | ||
.transform((i, j) => (j === '' ? null : i)), | ||
}).nullable() | ||
|
||
export const validation = { | ||
uforetrygd: ifPresent( | ||
'$pensjonforvalter.uforetrygd', | ||
Yup.object({ | ||
kravFremsattDato: Yup.date().nullable(), | ||
onsketVirkningsDato: datoErFremtidig().nullable(), // Frem i tid | ||
uforetidspunkt: Yup.date() | ||
.test('er-historisk', 'Dato må være historisk', function validDate(dato) { | ||
if (!dato) { | ||
return true | ||
} | ||
return isPast(dato) | ||
}) | ||
.nullable(), // Historisk | ||
inntektForUforhet: requiredNumber.transform((i, j) => (j === '' ? null : i)), // Required | ||
uforegrad: requiredNumber.transform((i, j) => (j === '' ? null : i)), // Required | ||
minimumInntektForUforhetType: Yup.string().nullable(), // Not required | ||
saksbehandler: erIkkeLik().nullable(), // Kan ikke være lik attesterer | ||
attesterer: erIkkeLik().nullable(), // Kan ikke være lik saksbehandler | ||
navEnhetId: requiredString, // Required | ||
barnetilleggDetaljer: Yup.object({ | ||
barnetilleggType: requiredString, | ||
forventedeInntekterSoker: Yup.array().of(forventetInntekt), | ||
forventedeInntekterEP: Yup.array().of(forventetInntekt), | ||
}).nullable(), | ||
}), | ||
), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters