Skip to content

Commit

Permalink
Merge branch 'master' of github.com:navikt/helse-speil
Browse files Browse the repository at this point in the history
  • Loading branch information
jksolbakken committed Aug 5, 2019
2 parents adfc596 + f8ddae4 commit 180cddc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
19 changes: 4 additions & 15 deletions src/components/App/App.jsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
import React, { useContext, useEffect } from 'react';
import React from 'react';
import { BrowserRouter as Router } from 'react-router-dom';
import HeaderBar from '../HeaderBar/HeaderBar';
import MainContentWrapper from '../MainContentWrapper/MainContentWrapper';
import { BehandlingerProvider } from '../../context/BehandlingerContext';
import { InnrapporteringProvider } from '../../context/InnrapporteringContext';
import { AuthProvider, AuthContext } from '../../context/AuthContext';
import { AuthProvider } from '../../context/AuthContext';
import { withContextProviders } from '../../context/withContextProviders';
import { useLogUserOut } from '../../hooks/useLogUserOut';
import './App.css';
import 'reset-css';
import fetchIntercept from 'fetch-intercept';

const App = withContextProviders(() => {
const { setUserLoggedOut } = useContext(AuthContext);

useEffect(() => {
fetchIntercept.register({
response: res => {
if (res.status === 401) {
setUserLoggedOut();
}
return res;
}
});
}, []);
useLogUserOut();

return (
<Router>
Expand Down
18 changes: 18 additions & 0 deletions src/hooks/useLogUserOut.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useContext, useEffect } from 'react';
import { AuthContext } from '../context/AuthContext';
import fetchIntercept from 'fetch-intercept';

export const useLogUserOut = () => {
const { setUserLoggedOut } = useContext(AuthContext);

useEffect(() => {
fetchIntercept.register({
response: res => {
if (res.status === 401) {
setUserLoggedOut();
}
return res;
}
});
}, []);
};
8 changes: 4 additions & 4 deletions src/io/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ export const behandlingerFor = async aktorId => {
return {
status: response.status,
data: await getData(response)
}
};
};

const getData = async response => {
try {
return await response.json()
return await response.json();
} catch (e) {
return undefined
return undefined;
}
}
};

export const putFeedback = async feedback => {
const response = await fetch(baseUrl + '/feedback', {
Expand Down

0 comments on commit 180cddc

Please sign in to comment.