Skip to content

Commit

Permalink
Validation ferdig + fix changehandling
Browse files Browse the repository at this point in the history
  • Loading branch information
betsytraran committed Oct 15, 2024
1 parent 24d3b4b commit ad2702b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ export const YrkesskaderForm = () => {
const formMethods = useFormContext()

const handleChangeTidstype = (value, path) => {
formMethods.setValue(`${path}.tidstype`, value?.value)
formMethods.setValue(`${path}.tidstype`, value?.value || null)
formMethods.setValue(`${path}.skadetidspunkt`, null)
formMethods.setValue(`${path}.perioder`, [initialYrkesskadePeriode])
if (value?.value === 'periode') {
formMethods.setValue(`${path}.perioder`, [initialYrkesskadePeriode])
} else {
formMethods.setValue(`${path}.perioder`, null)
}
formMethods.trigger(path)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,19 @@ export const validation = {
referanse: Yup.string().nullable(),
ferdigstillSak: Yup.string().nullable(),
tidstype: Yup.string().nullable(),
// skadetidspunkt: null,
// perioder: null,
skadetidspunkt: Yup.mixed().when('tidstype', {
is: (tidstype: string) => tidstype === 'tidspunkt',
then: () => requiredString,
otherwise: () => Yup.mixed().notRequired(),
}),
perioder: Yup.array()
.of(
Yup.object({
fra: ifPresent('$fra', requiredString),
til: ifPresent('$til', requiredString),
}),
)
.nullable(),
}),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ export const initialYrkesskadePeriode = {
}

export const initialYrkesskade = {
// skadelidtIdentifikator: '',
rolletype: 'arbeidstaker',
// innmelderIdentifikator: null,
innmelderrolle: 'virksomhetsrepresentant',
klassifisering: 'MANUELL',
// paaVegneAv: null,
tidstype: null,
skadetidspunkt: null,
perioder: null,
Expand Down

0 comments on commit ad2702b

Please sign in to comment.