-
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.
Returnerer data om nyoppstartet med begrunnelse fra aksjonspunkt (#7038)
* Returnerer data om nyoppstartet med begrunnelse fra aksjonspunkt * Endringer etter at dto fra backend er endret * Kjører prettier for å fikse identering osv * Endrer på story til å peke på ny index-fil Legger på typings på respons fra backend Skal bruke genererte typer etter backend er merget * Legger på enkel feilhåndtering Fikser path i story --------- Co-authored-by: Hallvard Andreas Stark <[email protected]>
- Loading branch information
1 parent
bf462c7
commit b0540e2
Showing
5 changed files
with
130 additions
and
56 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
37 changes: 0 additions & 37 deletions
37
packages/v2/gui/src/fakta/vurder-nyoppstartet/VurderNyoppstartet.stories.tsx
This file was deleted.
Oops, something went wrong.
31 changes: 14 additions & 17 deletions
31
packages/v2/gui/src/fakta/vurder-nyoppstartet/VurderNyoppstartet.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
51 changes: 51 additions & 0 deletions
51
packages/v2/gui/src/fakta/vurder-nyoppstartet/VurderNyoppstartetIndex.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,51 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { expect, fn, userEvent, waitFor } from '@storybook/test'; | ||
import { http, HttpResponse } from 'msw'; | ||
import { VurderNyoppstartetIndex } from './VurderNyoppstartetIndex'; | ||
|
||
const meta: Meta<typeof VurderNyoppstartetIndex> = { | ||
title: 'gui/fakta/vurder-nyoppstartet/VurderNyoppstartetIndex', | ||
component: VurderNyoppstartetIndex, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
submitCallback: fn(), | ||
harApneAksjonspunkter: true, | ||
aksjonspunkter: [], | ||
}, | ||
parameters: { | ||
msw: { | ||
handlers: [ | ||
http.get('/k9/sak/api/behandling/nyoppstartet', async () => { | ||
return HttpResponse.json({}, { status: 200 }); | ||
}), | ||
], | ||
}, | ||
}, | ||
play: async ({ canvas, args, step }) => { | ||
step('Skal sende inn nyoppstartet dato', async () => { | ||
await waitFor(() => expect(canvas.getByText('Ja')).toBeInTheDocument()); | ||
await userEvent.click(canvas.getByLabelText('Ja')); | ||
await userEvent.type(canvas.getByLabelText('Dato for nyoppstartet'), '2023-01-01'); | ||
await userEvent.type(canvas.getByLabelText('Begrunnelse'), 'Dette er en begrunnelse'); | ||
await userEvent.click(canvas.getByText('Bekreft')); | ||
await waitFor(() => expect(args.submitCallback).toHaveBeenCalledTimes(1)); | ||
expect(args.submitCallback).toHaveBeenCalledWith([ | ||
{ | ||
begrunnelse: 'Dette er en begrunnelse', | ||
kode: '9016', | ||
avklarNyoppstartet: { | ||
erNyoppstartet: true, | ||
fom: '2023-01-01', | ||
}, | ||
}, | ||
]); | ||
}); | ||
}, | ||
render: props => <VurderNyoppstartetIndex {...props} />, | ||
}; |
63 changes: 63 additions & 0 deletions
63
packages/v2/gui/src/fakta/vurder-nyoppstartet/VurderNyoppstartetIndex.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,63 @@ | ||
import AksjonspunktCodes from '@k9-sak-web/lib/kodeverk/types/AksjonspunktCodes.js'; | ||
import { Loader } from '@navikt/ds-react'; | ||
import type { AksjonspunktDto } from '@navikt/k9-sak-typescript-client'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import axios from 'axios'; | ||
import NetworkErrorPage from '../../sak/feilmeldinger/NetworkErrorPage.js'; | ||
import { type SubmitValues, VurderNyoppstartet } from './VurderNyoppstartet.js'; | ||
|
||
interface VurderNyoppstartetIndexProps { | ||
behandlingUUID: string; | ||
submitCallback: (data: SubmitValues[]) => void; | ||
harApneAksjonspunkter: boolean; | ||
readOnly: boolean; | ||
aksjonspunkter: AksjonspunktDto[]; | ||
} | ||
|
||
interface NyoppstartetData { | ||
erNyoppstartet: boolean | null; | ||
fom: string | null; | ||
} | ||
|
||
export const VurderNyoppstartetIndex = ({ | ||
behandlingUUID, | ||
submitCallback, | ||
harApneAksjonspunkter, | ||
readOnly, | ||
aksjonspunkter, | ||
}: VurderNyoppstartetIndexProps) => { | ||
const aksjonspunkt = aksjonspunkter.find(ap => ap.definisjon === AksjonspunktCodes.VURDER_NYOPPSTARTET); | ||
|
||
const { | ||
data: nyoppstartetData, | ||
isFetching, | ||
isError, | ||
} = useQuery<NyoppstartetData>({ | ||
queryKey: ['nyoppstartet', behandlingUUID], | ||
queryFn: () => | ||
axios | ||
.get('/k9/sak/api/behandling/nyoppstartet', { params: { behandlingUuid: behandlingUUID } }) | ||
.then(({ data }) => data), | ||
}); | ||
|
||
const formDefaultValues = { | ||
begrunnelse: aksjonspunkt?.begrunnelse ?? null, | ||
erNyoppstartet: nyoppstartetData?.erNyoppstartet ?? null, | ||
fom: nyoppstartetData?.fom ?? null, | ||
}; | ||
|
||
if (isFetching) { | ||
return <Loader />; | ||
} | ||
if (isError) { | ||
return <NetworkErrorPage />; | ||
} | ||
return ( | ||
<VurderNyoppstartet | ||
submitCallback={submitCallback} | ||
harApneAksjonspunkter={harApneAksjonspunkter} | ||
readOnly={readOnly} | ||
formDefaultValues={formDefaultValues} | ||
/> | ||
); | ||
}; |