Skip to content

Commit

Permalink
👽 Tar i bruk nytt endepunkt for søknader i dev
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbjoern committed Jan 9, 2024
1 parent c2111e3 commit 0884101
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .nais/dev-gcp.env
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ NEXT_PUBLIC_NY_INNSENDING="enabled"
DOKUMENTER_URL="http://dokumenter"
DOKUMENTER_AUDIENCE="dev-gcp:aap:dokumenter"

OPPSLAG_URL="http://oppslag"
OPPSLAG_AUDIENCE="dev-gcp:aap:oppslag"

ASSET_PREFIX="https://cdn.nav.no/aap/aap-innsyn"
WONDERWALL_REDIRECT_DESTINATION="/oauth2/login?redirect=/aap/mine-aap"

Expand Down
1 change: 1 addition & 0 deletions .nais/nais.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ spec:
rules:
- application: soknad-api
- application: innsending
- application: oppslag
- application: dokumenter
- application: nav-dekoratoren
namespace: personbruker
Expand Down
21 changes: 5 additions & 16 deletions components/Soknad/Soknad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,31 @@ export const Soknad = ({ søknad }: { søknad: Søknad }) => {
<FormattedMessage id="minSisteSøknad.søknad.heading" />
</Heading>
<BodyShort size="small" style={{ color: 'var(--a-text-subtle)', marginBlockEnd: '16px' }}>
<FormattedMessage
id="minSisteSøknad.mottatt"
values={{ date: formatDate(søknad.innsendtDato) }}
/>
<FormattedMessage id="minSisteSøknad.mottatt" values={{ date: formatDate(søknad.innsendtDato) }} />
</BodyShort>
{søknad.manglendeVedlegg?.length && (
<>
<Alert variant="warning" size="small" className={styles.alert}>
<FormattedMessage id="minSisteSøknad.søknad.alert.message" />
</Alert>
<DocumentationHeading
heading={formatMessage({ id: 'minSisteSøknad.dokumentasjon.mangler' })}
/>
<DocumentationHeading heading={formatMessage({ id: 'minSisteSøknad.dokumentasjon.mangler' })} />

<ul className={styles.dokumentasjonManglerList}>
{søknad.manglendeVedlegg.map((vedlegg) => {
return (
<li key={vedlegg}>
{formatMessage({ id: `ettersendelse.vedleggstyper.${vedlegg}.heading` })}
</li>
);
return <li key={vedlegg}>{formatMessage({ id: `ettersendelse.vedleggstyper.${vedlegg}.heading` })}</li>;
})}
</ul>
</>
)}

<ButtonRow>
<Button variant="primary" onClick={() => router.push(`/${søknad.søknadId}/ettersendelse/`)}>
<Button variant="primary" onClick={() => router.push(`/${søknad?.søknadId}/ettersendelse/`)}>
<FormattedMessage id="minSisteSøknad.søknad.button.text" />
</Button>
</ButtonRow>
{søknad.innsendteVedlegg?.length && (
<>
<DocumentationHeading
heading={formatMessage({ id: 'minSisteSøknad.dokumentasjon.mottatt' })}
/>
<DocumentationHeading heading={formatMessage({ id: 'minSisteSøknad.dokumentasjon.mottatt' })} />
<DocumentationList
elements={søknad.innsendteVedlegg.map((vedlegg) => {
return {
Expand Down
1 change: 1 addition & 0 deletions next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
/// <reference types="next/navigation-types/compat/navigation" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
32 changes: 24 additions & 8 deletions pages/api/soknader/soknader.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
import { mockSøknader } from 'lib/mock/mockSoknad';
import {
logger,
isMock,
tokenXApiProxy,
beskyttetApi,
getAccessTokenFromRequest,
} from '@navikt/aap-felles-utils';
import { logger, isMock, tokenXApiProxy, beskyttetApi, getAccessTokenFromRequest } from '@navikt/aap-felles-utils';
import metrics from 'lib/metrics';

const handler = beskyttetApi(async (req, res) => {
const accessToken = getAccessTokenFromRequest(req);
const params = {};
const søknader = await getSøknader(params, accessToken);
let søknader;
if (process.env.NEXT_PUBLIC_NY_INNSENDING === 'enabled') {
logger.info('Henter søknader fra innsending');
søknader = await getSøknaderInnsending(accessToken);
} else {
søknader = await getSøknader(params, accessToken);
}

res.status(200).json(søknader);
});

export const getSøknaderInnsending = async (accessToken?: string) => {
if (isMock()) return [];
const søknader = await tokenXApiProxy({
url: `${process.env.INNSENDING_URL}/innsending/søknader`,
prometheusPath: '/innsending/soeknader',
method: 'GET',
audience: process.env.INNSENDING_AUDIENCE ?? '',
bearerToken: accessToken,
logger: logger,
metricsStatusCodeCounter: metrics.backendApiStatusCodeCounter,
metricsTimer: metrics.backendApiDurationHistogram,
});
return søknader;
};

export const getSøknader = async (params: Record<string, string>, accessToken?: string) => {
if (isMock()) return mockSøknader;
const urlParams = Object.entries(params)
Expand Down
9 changes: 7 additions & 2 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getSøknader } from './api/soknader/soknader';
import { getSøknader, getSøknaderInnsending } from './api/soknader/soknader';
import { beskyttetSide, getAccessToken } from '@navikt/aap-felles-utils';
import { BodyShort, Button, Heading } from '@navikt/ds-react';
import { Card } from 'components/Card/Card';
Expand Down Expand Up @@ -122,7 +122,12 @@ export const getServerSideProps = beskyttetSide(async (ctx: NextPageContext): Pr
const bearerToken = getAccessToken(ctx);
const params = { page: '0', size: '1', sort: 'created,desc' };

const [søknader] = await Promise.all([getSøknader(params, bearerToken)]);
let søknader;
if (process.env.NEXT_PUBLIC_NY_INNSENDING === 'enabled') {
søknader = await getSøknaderInnsending(bearerToken);
} else {
søknader = await getSøknader(params, bearerToken);
}

stopTimer();

Expand Down

0 comments on commit 0884101

Please sign in to comment.