Skip to content

Commit

Permalink
Fikset mer av opplegget for gjennomsnitt G generering
Browse files Browse the repository at this point in the history
#deploy-test-frontend
  • Loading branch information
stigus committed Jul 5, 2024
1 parent 8485b65 commit aad97d5
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { FormDollyFieldArray } from '@/components/ui/form/fieldArray/DollyFieldA
import { pensjonGenererPath } from '@/components/fagsystem/pensjon/form/Form'
import styled from 'styled-components'
import NavButton from '@/components/ui/button/NavButton/NavButton'
import { usePensjonFacadeGjennomsnitt } from '@/utils/hooks/usePensjonFacade'
import { ErrorMessage } from '@hookform/error-message'
import { usePensjonFacadeGenerer } from '@/utils/hooks/usePensjon'

const getTittel = (data) => {
const inntektsaar = data?.map((inntekt) => inntekt.ar)
Expand All @@ -28,7 +28,7 @@ const StyledPanel = styled.div`
`

export const GenerertInntektForm = ({ syttenFraOgMedAar, formMethods }) => {
const { pensjon, mutate } = usePensjonFacadeGjennomsnitt(
const { pensjon, mutate } = usePensjonFacadeGenerer(
formMethods.watch(`${pensjonGenererPath}.generer`),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const EditParameter = ({ name, initialValue, getOptions }: any) => {

//TODO: Implementer lagring av verdi paa parameter
const onSubmit = (data: any) => {
console.log('Lagrer... ', data) //TODO - SLETT MEG
closeModal()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const harTpBestilling = (bestillingerFagsystemer) => {
export const harPoppBestilling = (bestillingerFagsystemer) => {
let popp = false
bestillingerFagsystemer?.forEach((i) => {
if (i?.pensjonforvalter?.inntekt) {
if (i?.pensjonforvalter?.inntekt || i?.pensjonforvalter?.generertInntekt) {
popp = true
}
})
Expand Down
59 changes: 56 additions & 3 deletions apps/dolly-frontend/src/main/js/src/utils/hooks/usePensjon.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import useSWR from 'swr'
import { fetcher } from '@/api'
import api, { fetcher } from '@/api'
import { v4 as _uuid } from 'uuid'
import useSWRImmutable from 'swr/immutable'

const getPensjonVedtakUrl = '/testnav-pensjon-testdata-facade-proxy/api/vedtak'
const pensjonVedtakUrl = '/testnav-pensjon-testdata-facade-proxy/api/vedtak'
const pensjonFacadeGenererUrl =
'/testnav-pensjon-testdata-facade-proxy/api/v1/generate-inntekt-med-gjennomsnitt-g'

export const usePensjonVedtak = (ident, miljo) => {
const { data, isLoading, error } = useSWR<string[], Error>(
[`${getPensjonVedtakUrl}?miljo=${miljo}`, { fnr: ident }],
[`${pensjonVedtakUrl}?miljo=${miljo}`, { fnr: ident }],
([url, headers]) => fetcher(url, headers),
)

Expand All @@ -15,3 +19,52 @@ export const usePensjonVedtak = (ident, miljo) => {
error: error,
}
}

type GjennomsnittG = {
ar: string
inntekt: number
generatedG: number
grunnbelop: number
}
type PensjonResponse = {
data: {
arInntektGList: GjennomsnittG[]
averageG: number
}
}

const validateBody = (body) => {
if (!body) return false
const { fomAar, tomAar, averageG } = body
return fomAar && tomAar && averageG
}

export const usePensjonFacadeGenerer = (body: any) => {
const { data, isLoading, error, mutate } = useSWRImmutable<PensjonResponse, Error>(
validateBody(body) && pensjonFacadeGenererUrl,
(url) => {
return api
.fetchJson(
url,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Nav-Consumer-Id': 'dolly',
'Nav-Call-Id': 'dolly ' + _uuid(),
},
},
body,
)
.then((response: PensjonResponse) => ({ data: response }))
},
{ dedupingInterval: 1000 },
)

return {
pensjon: data?.data,
loading: isLoading,
error: error,
mutate: mutate,
}
}

This file was deleted.

0 comments on commit aad97d5

Please sign in to comment.