Skip to content

Commit

Permalink
kan forhåndsvise brev for vedtak tilbakekreving
Browse files Browse the repository at this point in the history
  • Loading branch information
ramnav990 committed Nov 2, 2023
1 parent d2942f7 commit d1dc5cc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/api/tilbakekrevingApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
BrevtekstTilbakekrevingsbehandlingRequest,
ForhåndsvarsleTilbakekrevingRequest,
ForhåndsvisBrevtekstTilbakekrevingsbehandlingRequest,
ForhåndsvisVedtaksbrevTilbakekrevingsbehandlingRequest,
IverksettTilbakekrevingRequest,
ManuellTilbakekrevingsbehandling,
OpprettNyTilbakekrevingsbehandlingRequest,
Expand Down Expand Up @@ -66,6 +67,16 @@ export async function sendForhåndsvarsel(
});
}

export async function forhåndsvisVedtaksbrevTilbakekrevingsbehandling(
arg: ForhåndsvisVedtaksbrevTilbakekrevingsbehandlingRequest,
): Promise<ApiClientResult<Blob>> {
return apiClient({
url: `/saker/${arg.sakId}/tilbakekreving/${arg.behandlingId}/vedtaksbrev/forhandsvis`,
method: 'GET',
bodyTransformer: (res) => res.blob(),
});
}

export async function brevtekstTilbakekrevingsbehandling(
arg: BrevtekstTilbakekrevingsbehandlingRequest,
): Promise<ApiClientResult<ManuellTilbakekrevingsbehandling>> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import * as RemoteData from '@devexperts/remote-data-ts';
import { yupResolver } from '@hookform/resolvers/yup';
import { Button, Loader, Textarea } from '@navikt/ds-react';
import React, { useEffect } from 'react';
import React, { useEffect, useState } from 'react';
import { Controller, UseFormTrigger, useForm } from 'react-hook-form';
import { useNavigate } from 'react-router-dom';

import { ApiError } from '~src/api/apiClient';
import { forhåndsvisVedtaksbrevTilbakekrevingsbehandling } from '~src/api/tilbakekrevingApi';
import { ErrorIcon, SuccessIcon } from '~src/assets/Icons';
import ApiErrorAlert from '~src/components/apiErrorAlert/ApiErrorAlert';
import Feiloppsummering from '~src/components/feiloppsummering/Feiloppsummering';
Expand Down Expand Up @@ -36,6 +38,7 @@ const BrevForTilbakekreving = (props: {
const saksversjonRef = React.useRef(props.saksversjon);
const [autosaveStatus, autosave] = useAsyncActionCreator(brevtekstTilbakekrevingsbehandling);
const [sendTilAttesteringStatus, sendTilAttestering] = useAsyncActionCreator(sendTilbakekrevingTilAttestering);
const [hentBrevStatus, setHentBrevStatus] = useState<RemoteData.RemoteData<ApiError, null>>(RemoteData.initial);

const form = useForm<BrevForTilbakekrevingFormData>({
resolver: yupResolver(brevForTilbakekrevingSchema),
Expand Down Expand Up @@ -90,8 +93,22 @@ const BrevForTilbakekreving = (props: {
});
};

const onSeBrevClick = () => {
console.log('onSeBrevClick');
const onSeBrevClick = async () => {
if (RemoteData.isPending(hentBrevStatus)) return;

setHentBrevStatus(RemoteData.pending);

const res = await forhåndsvisVedtaksbrevTilbakekrevingsbehandling({
sakId: props.sakId,
behandlingId: props.tilbakekreving.id,
});

if (res.status === 'ok') {
setHentBrevStatus(RemoteData.success(null));
window.open(URL.createObjectURL(res.data));
} else {
setHentBrevStatus(RemoteData.failure(res.error));
}
};

const { isSaving } = useAutosaveOnChange(form.watch('brevtekst'), () => {
Expand Down Expand Up @@ -135,10 +152,12 @@ const BrevForTilbakekreving = (props: {
className={styles.seBrevButton}
variant="secondary"
onClick={onSeBrevClick}
loading={RemoteData.isPending(hentBrevStatus)}
>
{formatMessage('knapp.seBrev')}
</Button>
</div>
{RemoteData.isFailure(hentBrevStatus) && <ApiErrorAlert error={hentBrevStatus.error} />}
<div>
<Feiloppsummering
tittel={formatMessage('vurderTilbakekreving.feiloppsummering')}
Expand Down
5 changes: 5 additions & 0 deletions src/types/ManuellTilbakekrevingsbehandling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export interface BrevtekstTilbakekrevingsbehandlingRequest {
brevtekst: string;
}

export interface ForhåndsvisVedtaksbrevTilbakekrevingsbehandlingRequest {
sakId: string;
behandlingId: string;
}

export interface ForhåndsvisBrevtekstTilbakekrevingsbehandlingRequest {
sakId: string;
saksversjon: number;
Expand Down

0 comments on commit d1dc5cc

Please sign in to comment.