Skip to content

Commit

Permalink
Legger på visning av feilmelding på utsending av brev (#2002)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanneolsen authored Nov 22, 2024
1 parent fad4855 commit 5c0c2d4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';

import { BodyShort, Button, Heading, Select, Textarea } from '@navikt/ds-react';
import { BodyShort, Button, Fieldset, Heading, Select, Textarea } from '@navikt/ds-react';

import ForhåndsvisBrev from './ForhåndsvisBrev/ForhåndsvisBrev';
import { useSendMelding } from './SendMeldingContext';
Expand All @@ -24,7 +24,7 @@ interface IProps {
}

const SendMelding: React.FC<IProps> = ({ fagsak, behandling }) => {
const { maler, skjema, senderInn, sendBrev } = useSendMelding();
const { maler, skjema, senderInn, sendBrev, feilmelding } = useSendMelding();
const { behandlingILesemodus } = useBehandling();
const erLesevisning = !!behandlingILesemodus;

Expand All @@ -36,7 +36,7 @@ const SendMelding: React.FC<IProps> = ({ fagsak, behandling }) => {
const kanSende = skjema.felter.maltype.verdi !== '' && skjema.felter.fritekst.verdi !== '';

return (
<div>
<Fieldset error={feilmelding} legend={'Send brev'} hideLegend>
{behandling.manuelleBrevmottakere.length ? (
<>
<Heading size="xsmall" spacing>
Expand Down Expand Up @@ -109,7 +109,7 @@ const SendMelding: React.FC<IProps> = ({ fagsak, behandling }) => {
</Button>
{kanSende && <ForhåndsvisBrev />}
</Navigering>
</div>
</Fieldset>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ import { DokumentMal } from '../../../../kodeverk';
import { BrevPayload } from '../../../../typer/api';
import { IBehandling } from '../../../../typer/behandling';
import { IFagsak } from '../../../../typer/fagsak';
import { erFeltetEmpty, validerTekstFeltMaksLengde } from '../../../../utils';
import {
erFeltetEmpty,
hentFrontendFeilmelding,
validerTekstFeltMaksLengde,
} from '../../../../utils';
import { sider } from '../../../Felleskomponenter/Venstremeny/sider';

interface Mottaker {
Expand Down Expand Up @@ -50,6 +54,7 @@ interface IProps {

const [SendMeldingProvider, useSendMelding] = createUseContext(({ behandling, fagsak }: IProps) => {
const [senderInn, settSenderInn] = React.useState<boolean>(false);
const [feilmelding, settFeilmelding] = React.useState<string | undefined>();
const { hentBehandlingMedBehandlingId } = useBehandling();
const { bestillBrev } = useDokumentApi();
const navigate = useNavigate();
Expand Down Expand Up @@ -104,13 +109,16 @@ const [SendMeldingProvider, useSendMelding] = createUseContext(({ behandling, fa
settSenderInn(true);
bestillBrev(hentBrevdata()).then((respons: Ressurs<void>) => {
settSenderInn(false);
settFeilmelding(undefined);
if (respons.status === RessursStatus.SUKSESS) {
nullstillSkjema();
hentBehandlingMedBehandlingId(behandling.behandlingId).then(() => {
navigate(
`/fagsystem/${fagsak.fagsystem}/fagsak/${fagsak.eksternFagsakId}/behandling/${behandling.eksternBrukId}/${sider.VERGE.href}`
);
});
} else {
settFeilmelding(hentFrontendFeilmelding(respons));
}
});
} else {
Expand All @@ -126,6 +134,7 @@ const [SendMeldingProvider, useSendMelding] = createUseContext(({ behandling, fa
kanSendeSkjema,
senderInn,
sendBrev,
feilmelding,
};
});

Expand Down

0 comments on commit 5c0c2d4

Please sign in to comment.