Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sikre at personnummer er lastet inn før bruk #2195

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/app/personside/Personoversikt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import NyIdentModal from './NyIdentModal';
import { useGjeldendeBrukerLastet } from '../../redux/gjeldendeBruker/types';
import { CenteredLazySpinner } from '../../components/LazySpinner';
import useTimeout from '../../utils/hooks/use-timeout';
import VentPaaPersonLastet from '../../components/VentPaaPersonLastet';

function Personoversikt({ fnr }: { fnr: string }) {
const [loadTimeout, setLoadTimeout] = useState(false);
Expand Down Expand Up @@ -48,4 +49,10 @@ function Personoversikt({ fnr }: { fnr: string }) {
});
}

export default Personoversikt;
const PersonoversiktWrapper = ({ fnr }: { fnr: string }) => (
<VentPaaPersonLastet fnr={fnr}>
<Personoversikt fnr={fnr} />
</VentPaaPersonLastet>
);

export default PersonoversiktWrapper;
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import DokumentVisning from './dokumentvisning/SaksDokumentVisning';
import { useQueryParams } from '../../../../utils/url-utils';
import { AlertStripeFeil } from 'nav-frontend-alertstriper';
import styled from 'styled-components';
import SetFnrIRedux from '../../../PersonOppslagHandler/SetFnrIRedux';
import { getSaksdokumentUrl } from './dokumentvisning/getSaksdokumentUrl';
import VentPaaPersonLastet from '../../../../components/VentPaaPersonLastet';

interface Props {
fnr: string;
Expand Down Expand Up @@ -37,11 +37,12 @@ function SaksDokumentEgetVindu(props: Props) {
}
return (
<>
<SetFnrIRedux fnr={props.fnr} />
<DokumentVisning
fnr={props.fnr}
url={getSaksdokumentUrl(props.fnr, queryParams.journalpost ?? null, queryParams.dokument)}
/>
<VentPaaPersonLastet fnr={props.fnr}>
<DokumentVisning
fnr={props.fnr}
url={getSaksdokumentUrl(props.fnr, queryParams.journalpost ?? null, queryParams.dokument)}
/>
</VentPaaPersonLastet>
</>
);
}
Expand Down
37 changes: 37 additions & 0 deletions src/components/VentPaaPersonLastet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React, { PropsWithChildren, useEffect, useState } from 'react';
import { useHistory } from 'react-router';
import { useGjeldendeBrukerLastet } from '../redux/gjeldendeBruker/types';
import useTimeout from '../utils/hooks/use-timeout';
import { erGyldigishFnr } from '../utils/fnr-utils';
import { loggInfo } from '../utils/logger/frontendLogger';
import { paths } from '../app/routes/routing';
import { CenteredLazySpinner } from './LazySpinner';

type Props = {
fnr: string;
};

// Timeout 1 sekund for å laste fra context
const TIMEOUT_MILLIS = 1000;

const VentPaaPersonLastet = ({ fnr, children }: PropsWithChildren<Props>) => {
const [loadTimeout, setLoadTimeout] = useState(false);
const history = useHistory();
const gjeldendeBrukerHasLoaded = useGjeldendeBrukerLastet();
useTimeout(() => setLoadTimeout(true), TIMEOUT_MILLIS);

useEffect(() => {
if (!erGyldigishFnr(fnr) && (gjeldendeBrukerHasLoaded || loadTimeout)) {
loggInfo('Ugyldig fnr, redirecter til startside');
history.push(`${paths.basePath}`);
}
}, [fnr, gjeldendeBrukerHasLoaded, loadTimeout]);

if (!gjeldendeBrukerHasLoaded) {
return <CenteredLazySpinner />;
}

return <>{children}</>;
};

export default VentPaaPersonLastet;
Loading