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

Oppdaterer react-router-dom v6 til react-router v7 #3497

Merged
merged 15 commits into from
Jan 16, 2025
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
3 changes: 3 additions & 0 deletions jest-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { TextEncoder } from 'util';

global.TextEncoder = TextEncoder;
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@
"react": "^18.3.1",
"react-collapse": "^5.0.1",
"react-dom": "^18.3.1",
"react-router-dom": "^6.3.0",
"react-router-hash-link": "^2.4.3",
"react-router": "^7.1.1",
"rxjs": "^7.8.1",
"styled-components": "^6.1.1",
"ts-node": "^10.9.2",
Expand All @@ -95,8 +94,7 @@
"@types/react": "18.3.1",
"@types/react-collapse": "^5.0.1",
"@types/react-dom": "^18.3.0",
"@types/react-router-dom": "^5.3.3",
"@types/react-router-hash-link": "^2.4.5",
"@types/react-router": "^5.1.20",
"@types/styled-components": "^5.1.14",
"@types/uuid": "^10.0.0",
"@types/webpack-env": "^1.18.0",
Expand Down Expand Up @@ -141,6 +139,7 @@
"tsconfig": "<rootDir>/src/frontend/tsconfig.json"
}
},
"setupFiles": ["./jest-setup.js"],
"moduleNameMapper": {
"\\.(css|svg)$": "<rootDir>/src/mockFile.js"
},
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/context/InstitusjonContext.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from 'react';

import createUseContext from 'constate';
import { useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router';

import { useFelt, useSkjema } from '@navikt/familie-skjema';
import type { Ressurs } from '@navikt/familie-typer';
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/context/ManuellJournalførContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useEffect, useState } from 'react';
import type { AxiosError } from 'axios';
import createUseContext from 'constate';
import { differenceInMilliseconds } from 'date-fns';
import { useNavigate, useParams } from 'react-router-dom';
import { useNavigate, useParams } from 'react-router';

import { useHttp } from '@navikt/familie-http';
import type { Avhengigheter, FeltState } from '@navikt/familie-skjema';
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/context/OppgaverContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useEffect, useMemo, useState } from 'react';

import type { AxiosError } from 'axios';
import createUseContext from 'constate';
import { useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router';

import type { SortState } from '@navikt/ds-react';
import { useHttp } from '@navikt/familie-http';
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/context/SøknadContext.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';

import createUseContext from 'constate';
import { useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router';

import type { Avhengigheter } from '@navikt/familie-skjema';
import { feil, ok, useFelt, useSkjema } from '@navikt/familie-skjema';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from 'react';

import createUseContext from 'constate';
import { useLocation, useNavigate } from 'react-router-dom';
import { useLocation, useNavigate } from 'react-router';

import { RessursStatus } from '@navikt/familie-typer';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useState } from 'react';

import type { AxiosError } from 'axios';
import createUseContext from 'constate';
import { useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router';

import { useHttp } from '@navikt/familie-http';
import { byggFeiletRessurs, byggTomRessurs, type Ressurs } from '@navikt/familie-typer';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from 'react';

import type { AxiosError } from 'axios';
import { useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router';

import { useHttp } from '@navikt/familie-http';
import type { Ressurs } from '@navikt/familie-typer';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react';

import { useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router';

import { useHttp } from '@navikt/familie-http';
import type { Ressurs } from '@navikt/familie-typer';
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/hooks/useSakOgBehandlingParams.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { PropsWithChildren } from 'react';
import React from 'react';

import { renderHook } from '@testing-library/react';
import { MemoryRouter as Router } from 'react-router-dom';
import { MemoryRouter as Router } from 'react-router';

import useSakOgBehandlingParams from './useSakOgBehandlingParams';

Expand Down
2 changes: 1 addition & 1 deletion src/frontend/hooks/useSakOgBehandlingParams.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMatch } from 'react-router-dom';
import { useMatch } from 'react-router';

const useSakOgBehandlingParams = (): { fagsakId?: string; behandlingId?: string } => {
const matchFagsakIdOgBehandlingId = useMatch('/fagsak/:fagsakId/:behandlingId/*');
Expand Down
45 changes: 45 additions & 0 deletions src/frontend/hooks/useScrollTilAnker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { useEffect, useRef } from 'react';

import { useLocation } from 'react-router';

export function useScrollTilAnker() {
const location = useLocation();
const lastHash = useRef('');

function scrollTilHash() {
if (location.hash) {
lastHash.current = location.hash.slice(1); // Alt utenom #
}

if (lastHash.current && document.getElementById(lastHash.current)) {
return setTimeout(() => {
document
.getElementById(lastHash.current)
?.scrollIntoView({ behavior: 'smooth', block: 'start' });
lastHash.current = '';
}, 100);
}
}

// Når location endrer seg uten en hard refresh
useEffect(() => {
const timeout = scrollTilHash();

// Clear timeout om komponenten denne effekten brukes i unmountes før timeouten kjøres
return () => clearTimeout(timeout);
}, [location]);

// Når vi kjører en hard refresh
useEffect(() => {
let timeout = setTimeout(() => {
const scrollTimeout = scrollTilHash();

if (scrollTimeout) {
timeout = scrollTimeout;
}
}, 500); // For å gi UIet tid til å rendres før vi finner og scroller til elementet

// Clear timeout om komponenten denne effekten brukes i unmountes før timeouten kjøres
return () => clearTimeout(timeout);
}, []);
}
2 changes: 1 addition & 1 deletion src/frontend/komponenter/Container.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { BrowserRouter as Router, Navigate, Route, Routes } from 'react-router-dom';
import { BrowserRouter as Router, Navigate, Route, Routes } from 'react-router';
import styled from 'styled-components';

import FagsakContainer from './Fagsak/FagsakContainer';
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/komponenter/Fagsak/BehandlingRouter.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect } from 'react';

import { Route, Routes, useLocation } from 'react-router-dom';
import { Route, Routes, useLocation } from 'react-router';

import Behandlingsresultat from './Behandlingsresultat/Behandlingsresultat';
import Filtreringsregler from './Filtreringsregler/Filtreringsregler';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { useEffect, useState } from 'react';

import { useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router';
import styled from 'styled-components';

import { PencilIcon } from '@navikt/aksel-icons';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router';
import styled from 'styled-components';

import { Button, Modal } from '@navikt/ds-react';
Expand Down
4 changes: 3 additions & 1 deletion src/frontend/komponenter/Fagsak/FagsakContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect } from 'react';

import { Navigate, Route, Routes } from 'react-router-dom';
import { Navigate, Route, Routes } from 'react-router';
import styled from 'styled-components';

import { Alert } from '@navikt/ds-react';
Expand All @@ -15,6 +15,7 @@ import { HentOgSettBehandlingProvider } from '../../context/behandlingContext/He
import { DokumentutsendingProvider } from '../../context/DokumentutsendingContext';
import { useFagsakContext } from '../../context/Fagsak/FagsakContext';
import useSakOgBehandlingParams from '../../hooks/useSakOgBehandlingParams';
import { useScrollTilAnker } from '../../hooks/useScrollTilAnker';

const HovedInnhold = styled.div`
height: calc(100vh - 3rem);
Expand All @@ -23,6 +24,7 @@ const HovedInnhold = styled.div`

const FagsakContainer: React.FunctionComponent = () => {
const { fagsakId } = useSakOgBehandlingParams();
useScrollTilAnker();

const { bruker: brukerRessurs, minimalFagsak, hentMinimalFagsak } = useFagsakContext();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router';
import styled from 'styled-components';

import { BodyShort } from '@navikt/ds-react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';

import { useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router';
import styled from 'styled-components';

import { BodyShort, Button, Fieldset, Link, Modal, Select, Textarea } from '@navikt/ds-react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { useLocation } from 'react-router-dom';
import { useLocation } from 'react-router';
import styled from 'styled-components';

import { Alert, Button, Fieldset, Select, TextField } from '@navikt/ds-react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';

import { useLocation } from 'react-router-dom';
import { useLocation } from 'react-router';
import styled from 'styled-components';

import { PlusCircleIcon } from '@navikt/aksel-icons';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { useLocation, useNavigate } from 'react-router-dom';
import { useLocation, useNavigate } from 'react-router';

import { Dropdown } from '@navikt/ds-react';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect } from 'react';

import { useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router';

import type { Avhengigheter, FeltState } from '@navikt/familie-skjema';
import { feil, ok, useFelt, useSkjema } from '@navikt/familie-skjema';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';

import { useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router';
import styled from 'styled-components';

import { Alert } from '@navikt/ds-react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';

import { useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router';

import { BodyShort, Button, Modal } from '@navikt/ds-react';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';

import { useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router';
import styled from 'styled-components';

import { Alert } from '@navikt/ds-react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';

import classNames from 'classnames';
import { useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router';
import styled from 'styled-components';

import { ArrowsSquarepathIcon } from '@navikt/aksel-icons';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { useState } from 'react';

import { useLocation } from 'react-router-dom';
import { useLocation } from 'react-router';
import styled from 'styled-components';

import { MagnifyingGlassIcon } from '@navikt/aksel-icons';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';

import { useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router';

import Endringslogg from '@navikt/familie-endringslogg';
import type { ISøkeresultat } from '@navikt/familie-header';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react';

import { useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router';

import { useHttp } from '@navikt/familie-http';
import { RessursStatus } from '@navikt/familie-typer';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';

import { useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router';
import styled from 'styled-components';

import { Button, Modal } from '@navikt/ds-react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';

import type { AxiosError } from 'axios';
import { useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router';
import styled from 'styled-components';

import { Button, Modal } from '@navikt/ds-react';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { PropsWithChildren } from 'react';
import * as React from 'react';
import { useEffect } from 'react';

import { useLocation } from 'react-router-dom';
import { useLocation } from 'react-router';
import styled from 'styled-components';

import { Alert, Button, ErrorMessage, Heading } from '@navikt/ds-react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useEffect } from 'react';

import { endOfMonth } from 'date-fns';
import { useMatch } from 'react-router-dom';
import { useMatch } from 'react-router';
import styled from 'styled-components';

import { GlobeIcon as Eu, HouseIcon as NorwegianFlag } from '@navikt/aksel-icons';
Expand Down
Loading
Loading