Skip to content

Commit

Permalink
Types og opprydning #deploy-test-frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
betsytraran committed Sep 25, 2024
1 parent ed234b5 commit 31e1b0b
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export type BeloepTypes = {
fomDato: Date
belop: string
}

export type MocksvarTypes = {
tpId: string
statusAfp: string
virkningsDato: Date
sistBenyttetG: number
belopsListe: Array<BeloepTypes>
}

export type AfpOffentligTypes = {
direktekall: Array<string>
mocksvar: Array<MocksvarTypes>
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import React from 'react'
import { FormTextInput } from '@/components/ui/form/inputs/textInput/TextInput'
import { FormDatepicker } from '@/components/ui/form/inputs/datepicker/Datepicker'

export const BelopForm = ({ path }) => {
export const BelopForm = ({ path }: { path: string }) => {
return (
<FormDollyFieldArray name={path} header="Beløp" newEntry={initialBeloep} nested>
{(belop, idx) => (
{(belop: string, idx: number) => (
<div key={idx} className="flexbox">
<FormDatepicker name={`${belop}.fomDato`} label="F.o.m. dato" />
<FormTextInput name={`${belop}.belop`} label="Beløp" type="number" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { FormDatepicker } from '@/components/ui/form/inputs/datepicker/Datepicke
import { getYearRangeOptions } from '@/utils/DataFormatter'
import { BelopForm } from '@/components/fagsystem/afpOffentlig/form/BeloepForm'
import { validation } from '@/components/fagsystem/afpOffentlig/form/validation'
import { MocksvarTypes } from '@/components/fagsystem/afpOffentlig/afpOffentligTypes'

export const afpOffentligPath = 'pensjonforvalter.afpOffentlig'

Expand All @@ -23,14 +24,14 @@ export const AfpOffentligForm = () => {

const valgteDirektekall = formMethods.watch(`${afpOffentligPath}.direktekall`)
const filterTpOrdningOptions = tpOrdningData?.filter(
(option) => !valgteDirektekall?.includes(option.value),
(option: any) => !valgteDirektekall?.includes(option.value),
)

const valgteTpOrdninger = formMethods
.watch(`${afpOffentligPath}.mocksvar`)
?.map((mocksvar) => mocksvar.tpId)
?.map((mocksvar: MocksvarTypes) => mocksvar.tpId)
const filterDirektekallOptions = direktekallData?.filter(
(option) => !valgteTpOrdninger?.includes(option.value),
(option: any) => !valgteTpOrdninger?.includes(option.value),
)

return (
Expand Down Expand Up @@ -58,22 +59,20 @@ export const AfpOffentligForm = () => {
newEntry={initialMocksvar}
canBeEmpty={false}
>
{(formPath, idx) => (
{(formPath: string, idx: number) => (
<React.Fragment key={idx}>
<div className={'flexbox--flex-wrap'}>
<FormSelect
name={`${formPath}.tpId`}
label="TP-ordning"
size={'xxlarge'}
options={filterTpOrdningOptions}
// isClearable={false}
/>
<FormSelect
name={`${formPath}.statusAfp`}
label="Status AFP"
size={'medium'}
options={Options('statusAfp')}
// isClearable={false}
/>
<FormDatepicker name={`${formPath}.virkningsDato`} label="Virkningsdato" />
<FormSelect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,25 @@ import { TitleValue } from '@/components/ui/titleValue/TitleValue'
import { DollyFieldArray } from '@/components/ui/form/fieldArray/DollyFieldArray'
import { formatDate, showLabel } from '@/utils/DataFormatter'
import { useTpOrdning } from '@/utils/hooks/usePensjon'
import {
AfpOffentligTypes,
BeloepTypes,
MocksvarTypes,
} from '@/components/fagsystem/afpOffentlig/afpOffentligTypes'

export const sjekkManglerAfpOffentligData = (afpOffentligData) => {
type MiljoDataTypes = {
miljo: string
data: AfpOffentligTypes
}

type VisningTypes = {
data: Array<MiljoDataTypes>
loading: boolean
bestillingIdListe: Array<string>
tilgjengeligMiljoe: string
}

export const sjekkManglerAfpOffentligData = (afpOffentligData: Array<MiljoDataTypes>) => {
return (
afpOffentligData?.length < 1 ||
afpOffentligData?.every(
Expand All @@ -19,16 +36,16 @@ export const sjekkManglerAfpOffentligData = (afpOffentligData) => {
)
}

export const showTpNavn = (tpId) => {
export const showTpNavn = (tpId: string) => {
const { tpOrdningData } = useTpOrdning()
const tpOrdning = tpOrdningData?.find((tpOrdning) => tpOrdning.value === tpId)
const tpOrdning = tpOrdningData?.find((tpOrdning: any) => tpOrdning.value === tpId)
if (tpOrdning) {
return tpOrdning.label
}
return tpId
}

const DataVisning = ({ data }) => {
const DataVisning = ({ data }: { data: AfpOffentligTypes }) => {
return (
<div className="person-visning_content">
<TitleValue
Expand All @@ -37,15 +54,15 @@ const DataVisning = ({ data }) => {
size="full-width"
/>
<DollyFieldArray data={data?.mocksvar} header="AFP offentlig">
{(mocksvar, idx) => (
{(mocksvar: MocksvarTypes, idx: number) => (
<React.Fragment key={idx}>
<TitleValue title="TP-ordning" value={showTpNavn(mocksvar?.tpId)} />
<TitleValue title="Status AFP" value={showLabel('statusAfp', mocksvar?.statusAfp)} />
<TitleValue title="Virkningsdato" value={formatDate(mocksvar?.virkningsDato)} />
<TitleValue title="Sist benyttet G" value={mocksvar?.sistBenyttetG} />
{mocksvar?.belopsListe?.length > 0 && (
<DollyFieldArray data={mocksvar?.belopsListe} header="Beløp" nested>
{(belop, idy) => (
{(belop: BeloepTypes, idy: number) => (
<React.Fragment key={idx + idy}>
<TitleValue title="F.o.m. dato" value={formatDate(belop?.fomDato)} />
<TitleValue title="Beløp" value={belop?.belop} />
Expand All @@ -60,7 +77,12 @@ const DataVisning = ({ data }) => {
)
}

export const AfpOffentligVisning = ({ data, loading, bestillingIdListe, tilgjengeligMiljoe }) => {
export const AfpOffentligVisning = ({
data,
loading,
bestillingIdListe,
tilgjengeligMiljoe,
}: VisningTypes) => {
const { bestilteMiljoer } = useBestilteMiljoer(bestillingIdListe, 'PEN_AFP_OFFENTLIG')

if (loading) {
Expand All @@ -75,7 +97,6 @@ export const AfpOffentligVisning = ({ data, loading, bestillingIdListe, tilgjeng

const miljoerMedData = data?.map((miljoData) => miljoData.data && miljoData.miljo)
const errorMiljoer = bestilteMiljoer?.filter((miljo) => !miljoerMedData?.includes(miljo))

const forsteMiljo = data.find((miljoData) => miljoData?.data)?.miljo

const filteredData =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const usePensjonFacadeGenerer = (body: any) => {
export const useTpOrdning = () => {
const { data, isLoading, error } = useSWR<any, Error>(tpOrdningUrl, fetcher)

const options = data?.map((tpOrdning) => ({
const options = data?.map((tpOrdning: any) => ({
value: tpOrdning.tpnr,
label: `${tpOrdning.tpnr} - ${tpOrdning.navn}`,
}))
Expand All @@ -95,7 +95,7 @@ export const useTpOrdning = () => {
export const useMuligeDirektekall = () => {
const { data, isLoading, error } = useSWR<any, Error>(muligedirektekallUrl, fetcher)

const options = data?.muligeDirekteKall?.map((direktekall) => ({
const options = data?.muligeDirekteKall?.map((direktekall: any) => ({
value: direktekall.tpId,
label: `${direktekall.tpId} - ${direktekall.navn}`,
}))
Expand All @@ -107,7 +107,7 @@ export const useMuligeDirektekall = () => {
}
}

export const useMockOppsett = (miljoer, ident, harBestilling) => {
export const useMockOppsett = (miljoer: Array<string>, ident: string, harBestilling: boolean) => {
const mockOppsettUrl = harBestilling ? getMockOppsettUrl(miljoer, ident) : null
const { data, isLoading, error } = useSWR<any, Error>(mockOppsettUrl, multiFetcherAfpOffentlig)

Expand Down

0 comments on commit 31e1b0b

Please sign in to comment.