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

Tsf 3739 send brev til tredjepart #5276

Merged
merged 11 commits into from
Nov 22, 2023
1 change: 1 addition & 0 deletions eslint/eslintrc.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const config = {
],

// note you must disable the base rule as it can report incorrect errors
'no-nested-ternary': OFF,
'no-use-before-define': OFF,
'@typescript-eslint/no-use-before-define': [ERROR],
'no-shadow': OFF,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ describe('<FrisinnFakta>', () => {
statsborgerskap: {
kode: '',
kodeverk: '',
navn: '',
},
diskresjonskode: {
kode: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ describe('<OmsorgspengerFakta>', () => {
statsborgerskap: {
kode: '',
kodeverk: '',
navn: '',
},
diskresjonskode: {
kode: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ describe('<OpplaeringspengerFakta>', () => {
statsborgerskap: {
kode: '',
kodeverk: '',
navn: '',
},
diskresjonskode: {
kode: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ describe('<PleiepengerSluttfaseFakta>', () => {
statsborgerskap: {
kode: '',
kodeverk: '',
navn: '',
},
diskresjonskode: {
kode: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ describe('<PleiepengerFakta>', () => {
statsborgerskap: {
kode: '',
kodeverk: '',
navn: ''
},
diskresjonskode: {
kode: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
statsborgerskap: {
kode: '',
kodeverk: '',
navn: '',
},
diskresjonskode: {
kode: '',
Expand Down Expand Up @@ -123,7 +124,7 @@
},
};

it.skip('skal rendre faktapaneler og sidemeny korrekt', () => {

Check warning on line 127 in packages/behandling-unntak/src/components/UnntakFakta.spec.tsx

View workflow job for this annotation

GitHub Actions / lint-tscheck-build / Lint, typescript-sjekk og bygg

Disabled test
const fetchedData: Partial<FetchedData> = {
aksjonspunkter,
vilkar,
Expand Down
1 change: 1 addition & 0 deletions packages/form/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export { default as PeriodpickerField } from './src/PeriodpickerField';
export { default as AutocompleteField } from './src/AutocompleteField';
export { default as CheckboxGroupFormik } from './src/CheckboxGroupFormik';
export { default as FormState } from './src/FormState';
export { default as Label } from './src/Label';

export {
behandlingForm,
Expand Down
18 changes: 13 additions & 5 deletions packages/form/src/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,31 @@ interface SelectFieldProps {
}

/* eslint-disable-next-line react/prop-types */
const renderReadOnly = () => ({ input, selectValues, ...otherProps }) => {
const renderReadOnly = () => ({ input, selectValues, disabled, hideValueOnDisable, ...otherProps }) => {
/* eslint-disable-next-line react/prop-types */
const option = selectValues.map(sv => sv.props).find(o => o.value === input.value);
const value = option ? option.children : undefined;
return <ReadOnlyField input={{ value }} {...otherProps} />;
let value = option ? option.children : undefined;
// For å få nokolunde samme oppførsel som "opprinneleg komponent" på readonly komponenten når disabled og hideValueOnDisable
// er satt, legger vi inn value som eit tomt mellomrom i dette tilfellet. Dette sidan viss vi setter value til null, undefined
// eller "", så returnerer ReadOnlyField null, så heile input feltet med label forsvinner.
const hideValue = hideValueOnDisable === true && disabled === true
if(hideValue) {
value = <>&nbsp;</>
}
return <ReadOnlyField input={{ value }} { ...otherProps} />;
};

const renderNavSelect = renderNavField(CustomNavSelect);

const SelectField = ({ name, label, selectValues, validate, readOnly, ...otherProps }: SelectFieldProps) => (
const SelectField = ({ name, label, selectValues, validate, readOnly, hideValueOnDisable, disabled, ...otherProps }: SelectFieldProps) => (
<Field
name={name}
validate={validate}
component={readOnly ? renderReadOnly() : renderNavSelect}
label={label}
selectValues={selectValues}
disabled={!!readOnly}
disabled={disabled === true}
hideValueOnDisable={hideValueOnDisable}
{...otherProps}
readOnly={readOnly}
// @ts-ignore TODO Fiks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import HistorikkIndex from './historikk/HistorikkIndex';
import MeldingIndex from './melding/MeldingIndex';
import NotaterIndex from './notater/NotaterIndex';
import TotrinnskontrollIndex from './totrinnskontroll/TotrinnskontrollIndex';
import MeldingBackendClient from "./melding/MeldingBackendClient";

export const hentSynligePaneler = (
behandlingRettigheter?: BehandlingRettigheter,
Expand Down Expand Up @@ -182,6 +183,7 @@ const BehandlingSupportIndex = ({
behandlingVersjon={behandlingVersjon}
personopplysninger={personopplysninger}
arbeidsgiverOpplysninger={arbeidsgiverOpplysninger}
backendApi={new MeldingBackendClient()}
/>
)}
{aktivtSupportPanel === SupportTabs.DOKUMENTER && (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { EregOrganizationLookupResponse } from "@k9-sak-web/types";
import { BackendApi } from "./MeldingIndex";

export default class MeldingBackendClient implements BackendApi {
// TODO Bytt ut denne implementasjonen med ein som går mot eigen backend, og bruker requestApi, eller ein lågare nivå
// http klient dependency injecta i konstruktør (axios)
async getTredjepartsmottakerInfo(orgnr: string): Promise<EregOrganizationLookupResponse> {
const resp = await fetch(`https://data.brreg.no/enhetsregisteret/api/enheter/${orgnr}`, {
headers: {
'Accept': 'application/vnd.brreg.enhetsregisteret.enhet.v2+json;charset=UTF-8'
}
})
if(resp.ok) {
const json = await resp.json()
return {name: json.navn}
}
if(resp.status === 400) {
return {invalidOrgnum: true}
}
if(resp.status === 404) {
return {notFound: true}
}
throw new Error(`Unexpected response from data.brreg.no: ${resp.status} - ${resp.statusText}`)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import { combineReducers, createStore } from 'redux';

import kodeverkTyper from '@fpsak-frontend/kodeverk/src/kodeverkTyper';
import BehandlingType from '@fpsak-frontend/kodeverk/src/behandlingType';
import { BehandlingAppKontekst, Fagsak } from '@k9-sak-web/types';
import type { BehandlingAppKontekst, Brevmaler, Fagsak, Mottaker } from '@k9-sak-web/types';
import dokumentMalType from '@fpsak-frontend/kodeverk/src/dokumentMalType';

import { requestApi, K9sakApiKeys } from '../../data/k9sakApi';
import MeldingIndex from './MeldingIndex';
import MeldingIndex, { type BackendApi } from './MeldingIndex';

const mockHistoryPush = jest.fn();

Expand All @@ -39,6 +39,12 @@ interface ExtendedWindow {
}

describe('<MeldingIndex>', () => {
const meldingBackend = {
async getTredjepartsmottakerInfo(orgnr: string) {
return {name: `Test Org navn (${orgnr})`}
}
} satisfies BackendApi
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

satisfies var ny for meg. Virker kult!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ja, kan hjelpe til å lage betre intellisense/typesikkerhet i nokre tilfeller, såvidt eg veit.


const meldingMal: SendMeldingPayload = {
behandlingId: 1,
overstyrtMottaker: undefined,
Expand Down Expand Up @@ -74,11 +80,12 @@ describe('<MeldingIndex>', () => {
mottakere: aktorer,
linker: [],
støtterFritekst: true,
støtterTredjepartsmottaker: true,
},
[dokumentMalType.REVURDERING_DOK]: { navn: 'Revurdering Dok', mottakere: aktorer, linker: [] },
[dokumentMalType.AVSLAG]: { navn: 'Avslag', mottakere: aktorer, linker: [] },
[dokumentMalType.FORLENGET_DOK]: { navn: 'Forlenget', mottakere: aktorer, linker: [] },
};
} satisfies Brevmaler;

const assignMock = jest.fn();
delete (window as Partial<ExtendedWindow>).location;
Expand All @@ -103,6 +110,7 @@ describe('<MeldingIndex>', () => {
alleBehandlinger={alleBehandlinger as BehandlingAppKontekst[]}
behandlingId={1}
behandlingVersjon={123}
backendApi={meldingBackend}
/>
</MemoryRouter>
</Provider>,
Expand All @@ -127,6 +135,7 @@ describe('<MeldingIndex>', () => {
alleBehandlinger={alleBehandlinger as BehandlingAppKontekst[]}
behandlingId={1}
behandlingVersjon={123}
backendApi={meldingBackend}
/>
</MemoryRouter>
</MockForm>
Expand Down Expand Up @@ -158,6 +167,7 @@ describe('<MeldingIndex>', () => {
alleBehandlinger={alleBehandlinger as BehandlingAppKontekst[]}
behandlingId={1}
behandlingVersjon={123}
backendApi={meldingBackend}
/>
</MemoryRouter>
</MockForm>
Expand All @@ -184,6 +194,61 @@ describe('<MeldingIndex>', () => {
expect(reqData[0].params).toEqual({ ...meldingMal, ...melding });
});

it('skal sende melding til tredjepartsmottaker hvis det er valgt og utfyllt', async () => {
requestApi.mock(K9sakApiKeys.KODEVERK, kodeverk);
requestApi.mock(K9sakApiKeys.HAR_APENT_KONTROLLER_REVURDERING_AP, true);
requestApi.mock(K9sakApiKeys.BREVMALER, templates);
requestApi.mock(K9sakApiKeys.SUBMIT_MESSAGE);
requestApi.mock(K9sakApiKeys.FEATURE_TOGGLE, [{ TYPE_MEDISINSKE_OPPLYSNINGER_BREV: true }]);

render(
<Provider store={createStore(combineReducers({ form: formReducer }))}>
<MockForm>
<MemoryRouter>
<MeldingIndex
fagsak={fagsak as Fagsak}
alleBehandlinger={alleBehandlinger as BehandlingAppKontekst[]}
behandlingId={1}
behandlingVersjon={123}
backendApi={meldingBackend}
/>
</MemoryRouter>
</MockForm>
</Provider>,
);

const melding = {
overstyrtMottaker: { id: '00000000', type: 'AKTØRID' },
brevmalkode: dokumentMalType.INNHENT_DOK,
fritekst: 'Dette er meldingen',
};

userEvent.selectOptions(await screen.getByLabelText('Mal'), melding.brevmalkode);
userEvent.selectOptions(await screen.getByLabelText('Mottaker'), JSON.stringify(melding.overstyrtMottaker));
userEvent.type(await screen.getByLabelText('Fritekst'), melding.fritekst);

userEvent.click(await screen.getByLabelText('Send til tredjepartsmottaker'))
const tredjepartsMottaker = {
type: "ORGNR",
id: "974652269",
} satisfies Mottaker;

await act(async () => {
const orgnrInput = await screen.getByLabelText("Org.nr")
expect(orgnrInput).toBeInTheDocument()
userEvent.type(orgnrInput, tredjepartsMottaker.id)
})

await act(async () => {
// Simuler klikk på Send brev knapp
userEvent.click(await screen.getByRole('button', { name: 'Send brev' }));
});

const reqData = requestApi.getRequestMockData(K9sakApiKeys.SUBMIT_MESSAGE);
expect(reqData).toHaveLength(1);
expect(reqData[0].params).toEqual({ ...meldingMal, ...melding, ...{overstyrtMottaker: tredjepartsMottaker} });
});

it('skal sende melding og ikke sette saken på vent hvis ikke Innhent eller forlenget', async () => {
requestApi.mock(K9sakApiKeys.KODEVERK, kodeverk);
requestApi.mock(K9sakApiKeys.HAR_APENT_KONTROLLER_REVURDERING_AP, true);
Expand All @@ -200,6 +265,7 @@ describe('<MeldingIndex>', () => {
alleBehandlinger={alleBehandlinger as BehandlingAppKontekst[]}
behandlingId={1}
behandlingVersjon={123}
backendApi={meldingBackend}
/>
</MemoryRouter>
</MockForm>
Expand Down Expand Up @@ -246,6 +312,7 @@ describe('<MeldingIndex>', () => {
alleBehandlinger={alleBehandlinger as BehandlingAppKontekst[]}
behandlingId={1}
behandlingVersjon={123}
backendApi={meldingBackend}
/>
</MemoryRouter>
</MockForm>
Expand Down Expand Up @@ -294,6 +361,7 @@ describe('<MeldingIndex>', () => {
alleBehandlinger={alleBehandlinger as BehandlingAppKontekst[]}
behandlingId={1}
behandlingVersjon={123}
backendApi={meldingBackend}
/>
</MemoryRouter>
</MockForm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import BehandlingType, { erTilbakekrevingType } from '@fpsak-frontend/kodeverk/s
import dokumentMalType from '@fpsak-frontend/kodeverk/src/dokumentMalType';
import venteArsakType from '@fpsak-frontend/kodeverk/src/venteArsakType';
import kodeverkTyper from '@fpsak-frontend/kodeverk/src/kodeverkTyper';
import MeldingerSakIndex, { FormValues, MessagesModalSakIndex } from '@k9-sak-web/sak-meldinger';
import MeldingerSakIndex, { FormValues, MessagesModalSakIndex, type MeldingerSakIndexBackendApi } from '@k9-sak-web/sak-meldinger';
import { LoadingPanel } from '@fpsak-frontend/shared-components';
import { RestApiState } from '@k9-sak-web/rest-api-hooks';
import {
Expand Down Expand Up @@ -91,13 +91,16 @@ const getPreviewCallback =
fetchPreview(false, data);
};

export interface BackendApi extends MeldingerSakIndexBackendApi {}

interface OwnProps {
fagsak: Fagsak;
alleBehandlinger: BehandlingAppKontekst[];
behandlingId: number;
behandlingVersjon?: number;
personopplysninger?: Personopplysninger;
arbeidsgiverOpplysninger?: ArbeidsgiverOpplysningerWrapper;
readonly backendApi: BackendApi;
}

const EMPTY_ARRAY = [];
Expand All @@ -114,6 +117,7 @@ const MeldingIndex = ({
behandlingVersjon,
personopplysninger,
arbeidsgiverOpplysninger,
backendApi,
}: OwnProps) => {
const [showSettPaVentModal, setShowSettPaVentModal] = useState(false);
const [showMessagesModal, setShowMessageModal] = useState(false);
Expand Down Expand Up @@ -228,6 +232,7 @@ const MeldingIndex = ({
behandling.type.kode === BehandlingType.TILBAKEKREVING ||
behandling.type.kode === BehandlingType.TILBAKEKREVING_REVURDERING
}
backendApi={backendApi}
/>

{submitFinished && showSettPaVentModal && (
Expand Down
1 change: 1 addition & 0 deletions packages/sak-app/src/data/k9sakApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export enum K9sakApiKeys {
BEHANDLING_PERIODER_ÅRSAK_MED_VILKÅR = 'BEHANDLING_PERIODER_ÅRSAK_MED_VILKÅR',
LOS_LAGRE_MERKNAD = 'LOS_LAGRE_MERKNAD',
LOS_HENTE_MERKNAD = 'LOS_HENTE_MERKNAD',
ORGNR_ENHETSINFO = 'ORGNR_ENHETSINFO',
}

const endpoints = new RestApiConfigBuilder()
Expand Down
5 changes: 5 additions & 0 deletions packages/sak-meldinger/i18n/nb_NO.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"Messages.TypeAvDokumentasjon": "Type dokumentasjon du vil etterspørre",
"Messages.VelgTypeAvDokumentasjon": "Velg type",
"Messages.ChooseRecipient": "Velg mottaker",
"Messages.SendToThirdparty": "Send til tredjepartsmottaker",
"Messages.OrgNum": "Org.nr",
"Messages.InvalidOrgNum": "Ugyldig org.nr",
"Messages.OrgNumNotFound": "Org.nr ikke funnet i registeret",
"Messages.Name": "Navn",
"Messages.Fritekst": "Fritekst",
"Messages.FritekstTittel": "Tittel",
"Messages.VelgÅrsak": "Velg årsak",
Expand Down
2 changes: 1 addition & 1 deletion packages/sak-meldinger/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { default } from './src/MeldingerSakIndex';
export { default, type BackendApi as MeldingerSakIndexBackendApi } from './src/MeldingerSakIndex';
export { default as MessagesModalSakIndex } from './src/MessagesModalSakIndex';
export type { FormValues } from './src/components/Messages';
Loading
Loading