Skip to content

Commit

Permalink
Validation
Browse files Browse the repository at this point in the history
  • Loading branch information
betsytraran committed Sep 25, 2024
1 parent 5e953fb commit 9f95315
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { SelectOptionsManager as Options } from '@/service/SelectOptions'
import { FormDatepicker } from '@/components/ui/form/inputs/datepicker/Datepicker'
import { getYearRangeOptions } from '@/utils/DataFormatter'
import { BelopForm } from '@/components/fagsystem/afpOffentlig/form/BeloepForm'
import { validation } from '@/components/fagsystem/afpOffentlig/form/validation'

export const afpOffentligPath = 'pensjonforvalter.afpOffentlig'

Expand Down Expand Up @@ -91,3 +92,5 @@ export const AfpOffentligForm = () => {
</Vis>
)
}

AfpOffentligForm.validation = validation
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ifPresent, requiredDate, requiredNumber } from '@/utils/YupValidations'
import * as Yup from 'yup'

export const validation = {
afpOffentlig: ifPresent(
'$pensjonforvalter.afpOffentlig',
Yup.object({
direktekall: Yup.array().of(Yup.string()).nullable(),
mocksvar: Yup.array().of(
Yup.object({
tpId: Yup.string().nullable(),
statusAfp: Yup.string().nullable(),
virkningsDato: Yup.date().nullable(),
sistBenyttetG: Yup.number()
.transform((i, j) => (j === '' ? null : i))
.nullable(),
belopsListe: Yup.array().of(
Yup.object({
fomDato: ifPresent('$fomDato', requiredDate),
belop: ifPresent(
'$belop',
requiredNumber.transform((i, j) => (j === '' ? null : i)),
),
}),
),
}),
),
}),
),
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export const initialBeloep = {
fomDato: '',
fomDato: null,
belop: 0,
}

export const initialMocksvar = {
tpId: '',
statusAfp: '',
virkningsDato: '',
tpId: null,
statusAfp: null,
virkningsDato: null,
sistBenyttetG: 2024,
belopsListe: [initialBeloep],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ const DataVisning = ({ data }) => {
<TitleValue title="Status AFP" value={showLabel('statusAfp', mocksvar?.statusAfp)} />
<TitleValue title="Virkningsdato" value={formatDate(mocksvar?.virkningsDato)} />
<TitleValue title="Sist benyttet G" value={mocksvar?.sistBenyttetG} />
<DollyFieldArray data={mocksvar?.belopsListe} header="Beløp" nested>
{(belop, idy) => (
<React.Fragment key={idx + idy}>
<TitleValue title="F.o.m. dato" value={formatDate(belop?.fomDato)} />
<TitleValue title="Beløp" value={belop?.belop} />
</React.Fragment>
)}
</DollyFieldArray>
{mocksvar?.belopsListe?.length > 0 && (
<DollyFieldArray data={mocksvar?.belopsListe} header="Beløp" nested>
{(belop, idy) => (
<React.Fragment key={idx + idy}>
<TitleValue title="F.o.m. dato" value={formatDate(belop?.fomDato)} />
<TitleValue title="Beløp" value={belop?.belop} />
</React.Fragment>
)}
</DollyFieldArray>
)}
</React.Fragment>
)}
</DollyFieldArray>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AlderspensjonForm } from '@/components/fagsystem/alderspensjon/form/For
import { UforetrygdForm } from '@/components/fagsystem/uforetrygd/form/Form'
import { PensjonsavtaleForm } from '@/components/fagsystem/pensjonsavtale/form/Form'
import { getYear } from 'date-fns'
import { AfpOffentligForm } from '@/components/fagsystem/afpOffentlig/form/Form'

function calculate_age(dob) {
const diff_ms = Date.now() - dob.getTime()
Expand Down Expand Up @@ -224,6 +225,7 @@ export const validation = {
...TjenestepensjonForm.validation,
...AlderspensjonForm.validation,
...UforetrygdForm.validation,
...AfpOffentligForm.validation,
}),
),
}

0 comments on commit 9f95315

Please sign in to comment.