Skip to content

Commit

Permalink
Revert "Revert til gamle arbeidssøkerregistret (#144)"
Browse files Browse the repository at this point in the history
This reverts commit c291876.
  • Loading branch information
nattaphongklinjan committed Apr 5, 2024
1 parent c291876 commit 4535f16
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SERVERSIDE_LOGIN=disabled

INNSYN_API=https://dp-innsyn.intern.dev.nav.no
IDPORTEN_REDIRECT_URI=http://localhost:3000/api/auth/callback
VEILARBPROXY_URL=http://veilarbregistrering.paw.svc.cluster.local/veilarbregistrering
ARBEIDSSOEKERREGISTERET_URL=https://oppslag-arbeidssoekerregisteret.intern.dev.nav.no
DEKORATOR_ENV=dev
SELF_URL=http://localhost:3000
AMPLITUDE_API_KEY=
Expand Down
6 changes: 3 additions & 3 deletions .nais/nais.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ spec:
value: {{dekorator.url}}
- name: DEKORATOR_ENV
value: {{dekorator.env}}
- name: VEILARBPROXY_URL
value: {{veilarbproxyUrl}}
- name: ARBEIDSSOEKERREGISTERET_URL
value: {{arbeidssoekerregisteretUrl}}
- name: KONTOREGISTER_URL
value: {{kontoregisterUrl}}
- name: AMPLITUDE_API_KEY
Expand Down Expand Up @@ -66,7 +66,7 @@ spec:
- application: safselvbetjening
namespace: teamdokumenthandtering
cluster: {{saf.cluster}}
- application: veilarbregistrering
- application: paw-arbeidssoekerregisteret-api-oppslag
namespace: paw
- application: sokos-kontoregister-person
namespace: okonomi
Expand Down
2 changes: 1 addition & 1 deletion .nais/vars-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dekorator:
env: dev
loginservice:
url: https://loginservice.dev.nav.no/login
veilarbproxyUrl: http://veilarbregistrering.paw.svc.cluster.local/veilarbregistrering
arbeidssoekerregisteretUrl: https://oppslag-arbeidssoekerregisteret.intern.dev.nav.no
kontoregisterUrl: http://sokos-kontoregister-person.okonomi/api/borger/v1
amplitude:
apiKey: 9845ded64c69cd068651cd0d968e0796
Expand Down
2 changes: 1 addition & 1 deletion .nais/vars-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dekorator:
env: prod
loginservice:
url: https://loginservice.nav.no/login
veilarbproxyUrl: http://veilarbregistrering.paw.svc.cluster.local/veilarbregistrering
arbeidssoekerregisteretUrl: https://oppslag-arbeidssoekerregisteret.intern.nav.no
kontoregisterUrl: http://sokos-kontoregister-person.okonomi/api/borger/v1
amplitude:
apiKey: 913768927b84cde5eac0d0d18c737561
Expand Down
3 changes: 2 additions & 1 deletion src/__mocks__/handlers/frontend/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { HttpResponse, http } from "msw";
import { syntheticUserFnr } from "./syntheticUserFnr";
import { dokumentListeResolver } from "./dokumenter";
import { arbeidssokerperioderResolver } from "../resolvers/arbeidssokerperioderResolver";
import kontoResolver from "./konto";
import soknaderResolver from "./soknader";
import api from "../../../lib/api";

export const frontendHandlers = [
http.get(api("/arbeidssoker/perioder"), () => {
return HttpResponse.json({ arbeidssokerperioder: [] });
return HttpResponse.json(arbeidssokerperioderResolver);
}),
http.get(api("/auth/session"), () => {
return HttpResponse.json({
Expand Down
39 changes: 25 additions & 14 deletions src/components/arbeidssoker-status/ArbeidssokerStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
import useSWR from "swr";
import { useSanity } from "../../context/sanity-context";
import { Alert } from "@navikt/ds-react";
import { Alert, Skeleton } from "@navikt/ds-react";
import { PortableText } from "@portabletext/react";
import styles from "./ArbeidssokerStatus.module.css";

export function ArbeidssokerStatus() {
const { data: registrering, error } = useSWR(
const { data, error, isLoading } = useSWR(
`${process.env.NEXT_PUBLIC_BASE_PATH}/api/arbeidssoker/perioder`,
);

const registered = data?.findIndex((periode) => periode.avsluttet === null) !== -1;
const { getRichText } = useSanity();

if (registrering === undefined && !error) {
return null;
if (isLoading) {
return (
<div style={{ fontSize: "7rem" }}>
<Skeleton variant="text" width="100%" />
</div>
);
}

if (error || typeof registrering.arbeidssokerperioder === "undefined") {
return <PortableText value={getRichText("arbeidssokers-status.fant-ikke-svaret")} />;
if (!isLoading && error) {
return (
<Alert variant="warning" className={styles.arbeidssokerStatusNotRegisteredAlertBox}>
<PortableText value={getRichText("arbeidssokers-status.teknisk-feil")} />
</Alert>
);
}

const isRegistered = registrering.arbeidssokerperioder.length;

if (!isRegistered) {
if (!isLoading && !error && !registered) {
return (
<div className={styles.arbeidssokerStatusContainer}>
<Alert variant="warning" className={styles.arbeidssokerStatusNotRegisteredAlertBox}>
<PortableText value={getRichText("arbeidssokers-status.er-ikke-registrert")} />
</Alert>
</div>
<Alert variant="warning" className={styles.arbeidssokerStatusNotRegisteredAlertBox}>
<PortableText value={getRichText("arbeidssokers-status.er-ikke-registrert")} />
</Alert>
);
}

return (
<div className={styles.arbeidssokerStatusContainer}>
<PortableText value={getRichText("arbeidssokers-status.er-registrert")} />
</div>
);
}
2 changes: 1 addition & 1 deletion src/lib/audience.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const innsynAudience = `${process.env.NAIS_CLUSTER_NAME}:teamdagpenger:dp-innsyn`;
export const safAudience = `${process.env.SAF_SELVBETJENING_CLUSTER}:teamdokumenthandtering:${process.env.SAF_SELVBETJENING_SCOPE}`;
export const veilarbAudience = `${process.env.NAIS_CLUSTER_NAME}:paw:veilarbregistrering`;
export const audienceArbeidsoekkerregisteret = `${process.env.NAIS_CLUSTER_NAME}:paw:paw-arbeidssoekerregisteret-api-oppslag`;
export const kontoregisterAudience = `${process.env.NAIS_CLUSTER_NAME}:okonomi:sokos-kontoregister-person`;
40 changes: 25 additions & 15 deletions src/pages/api/arbeidssoker/perioder.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import { NextApiHandler, NextApiRequest, NextApiResponse } from "next";
import { getSession } from "../../../lib/auth.utils";
import { v4 as uuid } from "uuid";
import { formatISO } from "date-fns";
import { veilarbAudience } from "../../../lib/audience";
import { audienceArbeidsoekkerregisteret } from "../../../lib/audience";
import { logger } from "@navikt/next-logger";

export type Arbeidssøkerperiode = {
fraOgMedDato: string;
tilOgMedDato: string;
};
type brukerTypeResponse = "UKJENT_VERDI" | "UDEFINERT" | "VEILEDER" | "SYSTEM" | "SLUTTBRUKER";

export interface IArbeidssokerperiode {
periodeId: string;
startet: IArbeidssoekkerMetaResponse;
avsluttet: IArbeidssoekkerMetaResponse | null;
}

interface IArbeidssoekkerMetaResponse {
tidspunkt: string;
utfoertAv: { type: brukerTypeResponse };
kilde: string;
aarsak: string;
}

const perioderHandler: NextApiHandler<Arbeidssøkerperiode[]> = async (
const perioderHandler: NextApiHandler<IArbeidssokerperiode[]> = async (
req: NextApiRequest,
res: NextApiResponse,
) => {
Expand All @@ -21,19 +30,16 @@ const perioderHandler: NextApiHandler<Arbeidssøkerperiode[]> = async (

if (!session) return res.status(401).end();

const onBehalfOfToken = await session.apiToken(veilarbAudience);
const onBehalfOfToken = await session.apiToken(audienceArbeidsoekkerregisteret);

const today = formatISO(new Date(), { representation: "date" });
const url = `${process.env.VEILARBPROXY_URL}/api/arbeidssoker/perioder/niva3?fraOgMed=${today}`;
const url = `${process.env.ARBEIDSSOEKERREGISTERET_URL}/api/v1/arbeidssoekerperioder`;

logger.info(`Henter arbeidssøkerperioder fra veilarbregistrering (callId: ${callId})`);
logger.info(`Henter arbeidssøkerperioder fra arbeidssoekerregisteret (callId: ${callId})`);

const response = await fetch(url, {
method: "GET",
headers: {
Authorization: `Bearer ${onBehalfOfToken}`,
"Downstream-Authorization": `Bearer ${onBehalfOfToken}`,
"Nav-Consumer-Id": "dp-dagpenger",
"Nav-Call-Id": callId,
},
});

Expand All @@ -42,11 +48,15 @@ const perioderHandler: NextApiHandler<Arbeidssøkerperiode[]> = async (
}

const perioder = await response.json();

return res.status(response.status).json(perioder);
} catch (error) {
logger.error(`Kall mot veilarbregistrering (callId: ${callId}) feilet. Feilmelding: ${error}`);
logger.error(
`Kall mot arbeidssoekerregisteret (callId: ${callId}) feilet. Feilmelding: ${error}`,
);

return res.status(500).end(`Noe gikk galt (callId: ${callId})`);
}
};

export default perioderHandler;

0 comments on commit 4535f16

Please sign in to comment.