Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legger på visning av feilmelding på utsending av brev #2002

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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