Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1462 from navikt/hente-varsel-uten-proxy
Browse files Browse the repository at this point in the history
Hente varsler direkte fra tms-varsel-api
  • Loading branch information
Amirhlotfi authored Jul 5, 2023
2 parents 0eb2d08 + 4822578 commit 45d3aae
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 23 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ CASETYPE_ID=66D660EF-6F14-44B4-8ADE-A70A127202D0
NAV_GROUP_ID=A034081B-6B73-46B7-BE27-23B8E9CE3079
OPPORTUNITY_ID=615FF5E7-37B7-4697-A35F-72598B0DC53B
SOLUTION_ID=5EB316A1-11E2-460A-B4E3-F82DBD13E21D
VARSEL_API_URL=http://localhost:8095/tms-varsel-api
2 changes: 2 additions & 0 deletions .nais/vars/dev-beta-navno.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ env:
value: https://login.ekstern.dev.nav.no/oauth2/login
- name: LOGOUT_URL
value: https://login.ekstern.dev.nav.no/oauth2/logout
- name: VARSEL_API_URL
value: https://www.intern.dev.nav.no/tms-varsel-api
replicas:
min: 1
max: 1
Expand Down
2 changes: 2 additions & 0 deletions .nais/vars/dev-beta-tms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ env:
value: https://login.ekstern.dev.nav.no/oauth2/login
- name: LOGOUT_URL
value: https://login.ekstern.dev.nav.no/oauth2/logout
- name: VARSEL_API_URL
value: https://www.intern.dev.nav.no/tms-varsel-api
replicas:
min: 1
max: 1
Expand Down
2 changes: 2 additions & 0 deletions .nais/vars/dev-stable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ env:
value: https://login.ekstern.dev.nav.no/oauth2/login
- name: LOGOUT_URL
value: https://login.ekstern.dev.nav.no/oauth2/logout
- name: VARSEL_API_URL
value: https://www.intern.dev.nav.no/tms-varsel-api
replicas:
min: 1
max: 2
Expand Down
2 changes: 2 additions & 0 deletions .nais/vars/prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ env:
value: https://login.nav.no/oauth2/login
- name: LOGOUT_URL
value: https://login.nav.no/oauth2/logout
- name: VARSEL_API_URL
value: https://www.nav.no/tms-varsel-api
replicas:
min: 2
max: 8
Expand Down
8 changes: 4 additions & 4 deletions src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ export const hentInnloggingsstatusFetch = (API_DEKORATOREN_URL: string): Promise
credentials: 'include',
});

export const hentVarslerFetch = (API_DEKORATOREN_URL: string): Promise<varselinnboksData> => {
return fetchToJson(`${API_DEKORATOREN_URL}/varsel/proxy/varsel`, { credentials: 'include' });
export const hentVarslerFetch = (VARSEL_API_URL: string): Promise<varselinnboksData> => {
return fetchToJson(`${VARSEL_API_URL}/varselbjelle/varsler`, { credentials: 'include' });
};

export const postDone = (API_DEKORATOREN_URL: string, eventId: DoneEvent) =>
fetch(`${API_DEKORATOREN_URL}/varsel/beskjed/done`, {
export const postInaktiver = (VARSEL_API_URL: string, eventId: DoneEvent) =>
fetch(`${VARSEL_API_URL}/beskjed/inaktiver`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(eventId),
Expand Down
4 changes: 2 additions & 2 deletions src/komponenter/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const Header = () => {
const { language } = useSelector(stateSelector);
const { innloggingsstatus, menypunkt } = useSelector(stateSelector);
const { authenticated } = innloggingsstatus.data;
const { PARAMS, APP_URL, API_DEKORATOREN_URL, ENV } = environment;
const { PARAMS, APP_URL, API_DEKORATOREN_URL, ENV, VARSEL_API_URL } = environment;
const currentFeatureToggles = useSelector(stateSelector).featureToggles;
const breadcrumbs = PARAMS.BREADCRUMBS || [];
const availableLanguages = PARAMS.AVAILABLE_LANGUAGES || [];
Expand Down Expand Up @@ -157,7 +157,7 @@ export const Header = () => {
// Fetch notifications
useEffect(() => {
if (authenticated) {
hentVarsler(API_DEKORATOREN_URL)(dispatch);
hentVarsler(VARSEL_API_URL)(dispatch);
}
}, [authenticated]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Next } from '@navikt/ds-icons';
import Tekst from 'tekster/finn-tekst';
import { fjernLestVarsel } from 'store/reducers/varselinnboks-duck';
import { useDispatch } from 'react-redux';
import { postDone } from 'api/api';
import { postInaktiver } from 'api/api';
import { logAmplitudeEvent } from 'utils/analytics/amplitude';
import ArkiverKnapp from './arkiver-knapp/ArkiverKnapp';
import beskjedIkon from '../../../../../../ikoner/varsler/beskjedIkon.svg';
Expand All @@ -26,7 +26,7 @@ const getEksternvarslingStatus = (kanaler: string[]) => {

type Props = {
eventId: string;
apiVarselinnboksUrl: string;
VARSEL_API_URL: string;
tekst: string;
dato: string;
href: string;
Expand All @@ -39,7 +39,7 @@ type Props = {

const Beskjed = ({
eventId,
apiVarselinnboksUrl,
VARSEL_API_URL,
tekst,
dato,
href,
Expand All @@ -53,16 +53,16 @@ const Beskjed = ({

const dispatch = useDispatch();

const isOppgave = type === 'OPPGAVE';
const isOppgave = type.toLowerCase() === 'oppgave';
const isArkiverbar = !href && !isOppgave;
const eksternVarslingStatus = getEksternvarslingStatus(eksternVarslingKanaler);

const handleOnClick = () => {
if (type === 'BESKJED' && !isMasked) {
postDone(apiVarselinnboksUrl, { eventId: eventId });
if (type.toLowerCase() === 'beskjed' && !isMasked) {
postInaktiver(VARSEL_API_URL, { eventId: eventId });
dispatch(fjernLestVarsel(eventId));
}
logAmplitudeEvent('navigere', { komponent: type == "BESKJED" ? "varsel-beskjed" : "varsel-oppgave", kategori: "varselbjelle", destinasjon: href });
logAmplitudeEvent('navigere', { komponent: type.toLowerCase() == "beskjed" ? "varsel-beskjed" : "varsel-oppgave", kategori: "varselbjelle", destinasjon: href });
};

return isArkiverbar ? (
Expand All @@ -81,7 +81,7 @@ const Beskjed = ({
</div>
<ArkiverKnapp
eventId={eventId}
apiVarselinnboksUrl={apiVarselinnboksUrl}
VARSEL_API_URL={VARSEL_API_URL}
setActivateScreenReaderText={setActivateScreenReaderText}
id={id}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { postDone } from 'api/api';
import { postInaktiver } from 'api/api';
import React from 'react';
import { useDispatch } from 'react-redux';
import { fjernLestVarsel } from 'store/reducers/varselinnboks-duck';
Expand All @@ -9,16 +9,16 @@ import Tekst from 'tekster/finn-tekst';

type Props = {
eventId: string;
apiVarselinnboksUrl: string;
VARSEL_API_URL: string;
setActivateScreenReaderText: (setActivateScreenReaderText: boolean) => void;
id?: string;
};

const ArkiverKnapp = ({ eventId, apiVarselinnboksUrl, setActivateScreenReaderText, id }: Props) => {
const ArkiverKnapp = ({ eventId, VARSEL_API_URL, setActivateScreenReaderText, id }: Props) => {
const dispatch = useDispatch();

const handleOnClick = () => {
postDone(apiVarselinnboksUrl, { eventId: eventId });
postInaktiver(VARSEL_API_URL, { eventId: eventId });
setActivateScreenReaderText(false);
setActivateScreenReaderText(true);
dispatch(fjernLestVarsel(eventId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const VarselListe = ({ varsler, rowIndex }: Props) => {
const [activateScreenReaderText, setActivateScreenReaderText] = useState(false);
const arbeidsflate = useSelector((state: AppState) => state.arbeidsflate.status);
const environment = useSelector((state: AppState) => state.environment);
const { API_DEKORATOREN_URL } = environment;
const { VARSEL_API_URL } = environment;

const hasNoOppgaver = varsler?.oppgaver.length === 0;
const hasNoBeskjeder = varsler?.beskjeder.length === 0;
Expand All @@ -53,7 +53,7 @@ export const VarselListe = ({ varsler, rowIndex }: Props) => {
<li key={o.eventId}>
<VarselBoks
eventId={o.eventId}
apiVarselinnboksUrl={API_DEKORATOREN_URL}
VARSEL_API_URL={VARSEL_API_URL}
tekst={o.tekst}
dato={formatDato(o.tidspunkt)}
href={o.isMasked ? getLoginUrl(environment, arbeidsflate, 'Level4') : o.link}
Expand Down Expand Up @@ -86,7 +86,7 @@ export const VarselListe = ({ varsler, rowIndex }: Props) => {
<li key={b.eventId}>
<VarselBoks
eventId={b.eventId}
apiVarselinnboksUrl={API_DEKORATOREN_URL}
VARSEL_API_URL={VARSEL_API_URL}
tekst={b.tekst}
dato={formatDato(b.tidspunkt)}
href={b.isMasked ? getLoginUrl(environment, arbeidsflate, 'Level4') : b.link}
Expand Down
1 change: 1 addition & 0 deletions src/server/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const clientEnv = ({ req }: Props): Environment => {
MIN_SIDE_URL: process.env.MIN_SIDE_URL as string,
LOGIN_URL: process.env.LOGIN_URL as string,
LOGOUT_URL: process.env.LOGOUT_URL as string,
VARSEL_API_URL: process.env.VARSEL_API_URL as string,
...(req.query && {
PARAMS: {
CONTEXT: chosenContext,
Expand Down
2 changes: 2 additions & 0 deletions src/store/reducers/environment-duck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface Environment {
CASETYPE_ID: string;
SOLUTION_ID: string;
NAV_GROUP_ID: string;
VARSEL_API_URL: string;

// Parameters
PARAMS: Params;
Expand Down Expand Up @@ -66,6 +67,7 @@ export const initialState: Environment = {
CASETYPE_ID: '',
SOLUTION_ID: '',
NAV_GROUP_ID: '',
VARSEL_API_URL:'',

// Parameters
PARAMS: {
Expand Down
4 changes: 2 additions & 2 deletions src/store/reducers/varselinnboks-duck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export default function reducer(state: VarselinnboksState = initialState, action
}
}

export function hentVarsler(APP_URL: string): (dispatch: Dispatch) => Promise<void> {
return fetchThenDispatch<VarslerData>(() => hentVarslerFetch(APP_URL), {
export function hentVarsler(VARSEL_API_URL: string): (dispatch: Dispatch) => Promise<void> {
return fetchThenDispatch<VarslerData>(() => hentVarslerFetch(VARSEL_API_URL), {
ok: hentVarslerOk,
feilet: hentVarslerFeilet,
pending: hentVarslerPending,
Expand Down

0 comments on commit 45d3aae

Please sign in to comment.