Skip to content

Commit

Permalink
Legg til funksjonalitet for å fjerne en person fra kontekst ved event
Browse files Browse the repository at this point in the history
fra navigasjonsmenyen
  • Loading branch information
Joakim Lindquister committed Mar 7, 2018
1 parent 766db86 commit 0dce895
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 20 deletions.
10 changes: 8 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Provider } from 'react-redux';
import { BrowserRouter } from 'react-router-dom';

import getStore from './store';
import Routing from './routing';
import Routing, { paths } from './routes/routing';
import UnderArbeid from './components/underarbeid/UnderArbeid';

type DecoratorPersonsokEvent = EventListenerOrEventListenerObject & {fodselsnummer: string};
Expand All @@ -23,15 +23,21 @@ class App extends React.Component<AppProps> {

componentDidMount() {
document.addEventListener('dekorator-hode-personsok', this.handlePersonsok);
document.addEventListener('dekorator-hode-fjernperson', this.handleFjernPerson);
}

componentWillUnmount() {
document.removeEventListener('dekorator-hode-personsok', this.handlePersonsok);
document.removeEventListener('dekorator-hode-fjernperson', this.handleFjernPerson);
}

handlePersonsok(event: object) {
const personsokEvent = event as DecoratorPersonsokEvent;
window.location.href = `/person/${personsokEvent.fodselsnummer}`;
window.location.href = `${paths.personUri}/${personsokEvent.fodselsnummer}`;
}

handleFjernPerson() {
window.location.href = `/`;
}

render() {
Expand Down
3 changes: 0 additions & 3 deletions src/components/constants/url.ts

This file was deleted.

4 changes: 3 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import * as ReactDOM from 'react-dom';
import App from './App';
import './index.css';
import renderDecoratorHead from './menyConfig';
import { parseUrlForPersonIKontekst } from './utils/urlUtils';

ReactDOM.render(
<App />,
document.getElementById('root') as HTMLElement
);

renderDecoratorHead();
const fodselsnummer = parseUrlForPersonIKontekst(window.location);
renderDecoratorHead(fodselsnummer);
7 changes: 0 additions & 7 deletions src/logo.svg

This file was deleted.

11 changes: 8 additions & 3 deletions src/menyConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ interface Toggles {
visEnhet: boolean;
visSokefelt: boolean;
visVeileder: boolean;
visSokeIkon: boolean;
}

interface MenyConfig {
config: {
toggles: Toggles;
applicationName: string;
fnr: string;
};
}

Expand All @@ -20,13 +22,16 @@ const config: MenyConfig = {
toggles: {
visEnhet: true,
visSokefelt: true,
visVeileder: true
visVeileder: true,
visSokeIkon: false
},
applicationName: 'Modia personoversikt'
applicationName: 'Modia personoversikt',
fnr: ''
}
};

export default function () {
export default function (fodselsnummer: string) {
config.config.fnr = fodselsnummer;
if (window.renderDecoratorHead) {
window.renderDecoratorHead(config);
}
Expand Down
10 changes: 7 additions & 3 deletions src/routing.tsx → src/routes/routing.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import * as React from 'react';
import { withRouter } from 'react-router-dom';
import { Route, RouteComponentProps, Switch } from 'react-router';
import Personside from './components/personside/Personside';
import Startbilde from './components/startbilde/Startbilde';
import Personside from '../components/personside/Personside';
import Startbilde from '../components/startbilde/Startbilde';

export const paths = {
personUri : '/person'
};

function Routing(props: RouteComponentProps<{}> ) {
return (
<Switch location={props.location}>
<Route path="/person/:fodselsnummer/" component={Personside}/>
<Route path={`${paths.personUri}/:fodselsnummer/`} component={Personside}/>
<Route component={Startbilde}/>
</Switch>
);
Expand Down
22 changes: 22 additions & 0 deletions src/utils/urlUtils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { parseUrlForPersonIKontekst } from './urlUtils';
import { paths } from '../routes/routing';

it('returnerer fødselsnummeret når en person er i kontekst i URL', () => {
const location = {
pathname: `${paths.personUri}/123`
};

const fodselsnummer = parseUrlForPersonIKontekst(location);

expect(fodselsnummer).toEqual('123');
});

it('returnerer tomt fødselsnummer når en person ikke er i kontekst', () => {
const location = {
pathname: '/'
};

const fodselsnummer = parseUrlForPersonIKontekst(location);

expect(fodselsnummer).toEqual('');
});
13 changes: 13 additions & 0 deletions src/utils/urlUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { paths } from '../routes/routing';

interface Location {
pathname: string;
}

export function parseUrlForPersonIKontekst(location: Location): string {
const splittetUrl = location.pathname.split(`${paths.personUri}/`);
if (splittetUrl.length >= 2 && splittetUrl[1]) {
return splittetUrl[1];
}
return '';
}
2 changes: 1 addition & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"no-arg": true,
"no-bitwise": true,
"no-console": [
true,
false,
"log",
"error",
"debug",
Expand Down

0 comments on commit 0dce895

Please sign in to comment.