-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Justeringer for UNG i tilkjent ytelse (#6713)
* Justeringner for UNG i tilkjent ytelse Tar bort uttak i ung beregning Justeringer i tabell * Bedre typesikring på henting av data Story * Fikser tester * Bruker generert type * Fiks story * Rydding
- Loading branch information
1 parent
398acc8
commit 967da23
Showing
15 changed files
with
208 additions
and
167 deletions.
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
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
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
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
14 changes: 14 additions & 0 deletions
14
packages/v2/gui/src/prosess/ung-beregning/UngBeregning.stories.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,14 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { FakeUngBeregningBackendApi } from '../../storybook/mocks/FakeUngBeregningBackendApi'; | ||
import UngBeregning from './UngBeregning'; | ||
|
||
const api = new FakeUngBeregningBackendApi(); | ||
const meta = { | ||
title: 'gui/prosess/ung-beregning/UngBeregning.tsx', | ||
component: UngBeregning, | ||
} satisfies Meta<typeof UngBeregning>; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const DefaultStory: Story = { args: { behandling: { uuid: '123' }, api } }; |
85 changes: 85 additions & 0 deletions
85
packages/v2/gui/src/prosess/ung-beregning/UngBeregning.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,85 @@ | ||
import type { UngdomsytelseSatsPeriodeDto } from '@k9-sak-web/backend/k9sak/generated'; | ||
import { formatPeriod } from '@k9-sak-web/lib/dateUtils/dateUtils.js'; | ||
import { Alert, Heading, Loader, Table } from '@navikt/ds-react'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import type { UngBeregningBackendApiType } from './UngBeregningBackendApiType'; | ||
|
||
const formatCurrencyWithKr = (value: number) => { | ||
const formattedValue = Number(value).toLocaleString('nb-NO').replace(/,|\s/g, ' '); | ||
return `${formattedValue} kr`; | ||
}; | ||
|
||
const formatCurrencyNoKr = (value: number) => { | ||
if (value === null || value === undefined) { | ||
return undefined; | ||
} | ||
// Fjerner mellomrom i tilfelle vi får inn tall med det | ||
const newVal = value.toString().replace(/\s/g, ''); | ||
if (Number.isNaN(newVal)) { | ||
return undefined; | ||
} | ||
return Number(Math.round(+newVal)).toLocaleString('nb-NO').replace(/,|\s/g, ' '); | ||
}; | ||
|
||
interface Props { | ||
behandling: { uuid: string }; | ||
api: UngBeregningBackendApiType; | ||
} | ||
|
||
const UngBeregning = ({ api, behandling }: Props) => { | ||
const { | ||
data: satser, | ||
isLoading: satserIsLoading, | ||
isSuccess: satserSuccess, | ||
isError: satserIsError, | ||
} = useQuery<UngdomsytelseSatsPeriodeDto[]>({ | ||
queryKey: ['satser'], | ||
queryFn: () => api.getSatser(behandling.uuid), | ||
}); | ||
|
||
if (satserIsLoading) { | ||
return <Loader size="large" />; | ||
} | ||
|
||
if (satserIsError) { | ||
return <Alert variant="error">Noe gikk galt, vennligst prøv igjen senere</Alert>; | ||
} | ||
|
||
return ( | ||
<div className="max-w-[768px]"> | ||
{satserSuccess && ( | ||
<div> | ||
<Heading size="small" level="2"> | ||
Satser | ||
</Heading> | ||
<Table> | ||
<Table.Header> | ||
<Table.Row> | ||
<Table.HeaderCell scope="col">Periode</Table.HeaderCell> | ||
<Table.HeaderCell scope="col">Sats</Table.HeaderCell> | ||
<Table.HeaderCell scope="col" align="right"> | ||
Grunnbeløp | ||
</Table.HeaderCell> | ||
<Table.HeaderCell scope="col" align="right"> | ||
Dagsats | ||
</Table.HeaderCell> | ||
</Table.Row> | ||
</Table.Header> | ||
<Table.Body> | ||
{satser.map(({ fom, tom, satsType, dagsats, grunnbeløp }) => ( | ||
<Table.Row key={`${fom}_${tom}`}> | ||
<Table.DataCell>{fom && tom && formatPeriod(fom, tom)}</Table.DataCell> | ||
<Table.DataCell>{satsType}</Table.DataCell> | ||
<Table.DataCell align="right">{grunnbeløp && formatCurrencyWithKr(grunnbeløp)}</Table.DataCell> | ||
<Table.DataCell align="right">{dagsats && formatCurrencyNoKr(dagsats)} kr</Table.DataCell> | ||
</Table.Row> | ||
))} | ||
</Table.Body> | ||
</Table> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default UngBeregning; |
5 changes: 5 additions & 0 deletions
5
packages/v2/gui/src/prosess/ung-beregning/UngBeregningBackendApiType.ts
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,5 @@ | ||
import type { UngdomsytelseSatsPeriodeDto } from '@k9-sak-web/backend/k9sak/generated'; | ||
|
||
export type UngBeregningBackendApiType = { | ||
getSatser(behandlingUuid: string): Promise<UngdomsytelseSatsPeriodeDto[]>; | ||
}; |
13 changes: 13 additions & 0 deletions
13
packages/v2/gui/src/prosess/ung-beregning/UngBeregningBackendClient.ts
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,13 @@ | ||
import type { K9SakClient, UngdomsytelseSatsPeriodeDto } from '@k9-sak-web/backend/k9sak/generated'; | ||
|
||
export default class UngBeregningBackendClient { | ||
#k9sak: K9SakClient; | ||
|
||
constructor(k9sakClient: K9SakClient) { | ||
this.#k9sak = k9sakClient; | ||
} | ||
|
||
async getSatser(behandlingUuid: string): Promise<UngdomsytelseSatsPeriodeDto[]> { | ||
return this.#k9sak.ung.getUngdomsytelseInnvilgetSats(behandlingUuid); | ||
} | ||
} |
Oops, something went wrong.