diff --git a/package-lock.json b/package-lock.json index c4f339a46..026f9e119 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,8 +34,8 @@ "react-dom": "^17.0.2", "react-i18next": "^11.13.0", "react-redux": "^7.2.6", - "react-router": "^5.2.1", - "react-router-dom": "^5.3.0", + "react-router": "^6.0.1", + "react-router-dom": "^6.0.1", "react-share": "^4.4.0", "styled-components": "^5.3.3", "uuid": "^8.3.2", @@ -44,7 +44,6 @@ "devDependencies": { "@cypress/code-coverage": "^3.9.11", "@cypress/instrument-cra": "^1.4.0", - "@types/history": "^4.7.9", "@types/node": "^16.11.6", "@types/react": "^17.0.34", "@types/react-dom": "^17.0.11", @@ -7295,9 +7294,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001230", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001230.tgz", - "integrity": "sha512-5yBd5nWCBS+jWKTcHOzXwo5xzcj4ePE/yjtkZyUV1BTUmrBaA9MRGC+e7mxnqXSA90CmCA8L3eKLaSUkt099IQ==", + "version": "1.0.30001278", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001278.tgz", + "integrity": "sha512-mpF9KeH8u5cMoEmIic/cr7PNS+F5LWBk0t2ekGT60lFf0Wq+n9LspAj0g3P+o7DQhD3sUdlMln4YFAWhFYn9jg==", "dev": true, "funding": { "type": "opencollective", @@ -12704,17 +12703,11 @@ "license": "MIT" }, "node_modules/history": { - "version": "4.10.1", - "resolved": "https://registry.npmjs.org/history/-/history-4.10.1.tgz", - "integrity": "sha512-36nwAD620w12kuzPAsyINPWJqlNbij+hpK1k9XRloDtym8mxzGYl2c17LnV6IAGB2Dmg4tEa7G7DlawS0+qjew==", - "license": "MIT", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/history/-/history-5.1.0.tgz", + "integrity": "sha512-zPuQgPacm2vH2xdORvGGz1wQMuHSIB56yNAy5FnLuwOwgSYyPKptJtcMm6Ev+hRGeS+GzhbmRacHzvlESbFwDg==", "dependencies": { - "@babel/runtime": "^7.1.2", - "loose-envify": "^1.2.0", - "resolve-pathname": "^3.0.0", - "tiny-invariant": "^1.0.2", - "tiny-warning": "^1.0.0", - "value-equal": "^1.0.1" + "@babel/runtime": "^7.7.6" } }, "node_modules/hmac-drbg": { @@ -14159,12 +14152,6 @@ "node": ">=8" } }, - "node_modules/isarray": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", - "license": "MIT" - }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -16421,20 +16408,6 @@ "node": ">=6" } }, - "node_modules/mini-create-react-context": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/mini-create-react-context/-/mini-create-react-context-0.4.1.tgz", - "integrity": "sha512-YWCYEmd5CQeHGSAKrYvXgmzzkrvssZcuuQDDeqkT+PziKGMgE+0MCCtcKbROzocGBG1meBLl2FotlRwf4gAzbQ==", - "license": "MIT", - "dependencies": { - "@babel/runtime": "^7.12.1", - "tiny-warning": "^1.0.3" - }, - "peerDependencies": { - "prop-types": "^15.0.0", - "react": "^0.14.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" - } - }, "node_modules/mini-css-extract-plugin": { "version": "0.11.3", "resolved": "https://registry.npmjs.org/mini-css-extract-plugin/-/mini-css-extract-plugin-0.11.3.tgz", @@ -17901,15 +17874,6 @@ "node": ">= 0.8.0" } }, - "node_modules/path-to-regexp": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz", - "integrity": "sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==", - "license": "MIT", - "dependencies": { - "isarray": "0.0.1" - } - }, "node_modules/path-type": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", @@ -20362,48 +20326,29 @@ } }, "node_modules/react-router": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/react-router/-/react-router-5.2.1.tgz", - "integrity": "sha512-lIboRiOtDLFdg1VTemMwud9vRVuOCZmUIT/7lUoZiSpPODiiH1UQlfXy+vPLC/7IWdFYnhRwAyNqA/+I7wnvKQ==", - "dependencies": { - "@babel/runtime": "^7.12.13", - "history": "^4.9.0", - "hoist-non-react-statics": "^3.1.0", - "loose-envify": "^1.3.1", - "mini-create-react-context": "^0.4.0", - "path-to-regexp": "^1.7.0", - "prop-types": "^15.6.2", - "react-is": "^16.6.0", - "tiny-invariant": "^1.0.2", - "tiny-warning": "^1.0.0" + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.0.1.tgz", + "integrity": "sha512-O3iab52icFnQaHWONZr50CcjRlf3gx8CCjPQ0YxN8xEuEklRJNgoZSeoYFYz0fLvA4cpnhc306Nd8BYgL4QZrQ==", + "dependencies": { + "history": "^5.1.0" }, "peerDependencies": { - "react": ">=15" + "react": ">=16.8" } }, "node_modules/react-router-dom": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-5.3.0.tgz", - "integrity": "sha512-ObVBLjUZsphUUMVycibxgMdh5jJ1e3o+KpAZBVeHcNQZ4W+uUGGWsokurzlF4YOldQYRQL4y6yFRWM4m3svmuQ==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.0.1.tgz", + "integrity": "sha512-fiE+PzFTrof5q8Z/+RHzuiin9/U/q5KY2adlHClwYexbY0DqJnHcC/0U9yv3Amz9em2/bcK7X8mk7+zxB+qhvg==", "dependencies": { - "@babel/runtime": "^7.12.13", - "history": "^4.9.0", - "loose-envify": "^1.3.1", - "prop-types": "^15.6.2", - "react-router": "5.2.1", - "tiny-invariant": "^1.0.2", - "tiny-warning": "^1.0.0" + "history": "^5.1.0", + "react-router": "6.0.1" }, "peerDependencies": { - "react": ">=15" + "react": ">=16.8", + "react-dom": ">=16.8" } }, - "node_modules/react-router/node_modules/react-is": { - "version": "16.13.1", - "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", - "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==", - "license": "MIT" - }, "node_modules/react-scripts": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/react-scripts/-/react-scripts-4.0.3.tgz", @@ -21188,12 +21133,6 @@ "node": ">=4" } }, - "node_modules/resolve-pathname": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/resolve-pathname/-/resolve-pathname-3.0.0.tgz", - "integrity": "sha512-C7rARubxI8bXFNB/hqcp/4iUeIXJhJZvFPFPiSPRnhU5UPxzMFIl+2E6yY6c4k9giDJAhtV+enfA+G89N6Csng==", - "license": "MIT" - }, "node_modules/resolve-url": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/resolve-url/-/resolve-url-0.2.1.tgz", @@ -24117,12 +24056,6 @@ "dev": true, "license": "MIT" }, - "node_modules/tiny-invariant": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/tiny-invariant/-/tiny-invariant-1.1.0.tgz", - "integrity": "sha512-ytxQvrb1cPc9WBEI/HSeYYoGD0kWnGEOR8RY6KomWLBVhqz0RgTwVO9dLrGz7dC+nN9llyI7OKAgRq8Vq4ZBSw==", - "license": "MIT" - }, "node_modules/tiny-warning": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/tiny-warning/-/tiny-warning-1.0.3.tgz", @@ -24930,12 +24863,6 @@ "spdx-expression-parse": "^3.0.0" } }, - "node_modules/value-equal": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/value-equal/-/value-equal-1.0.1.tgz", - "integrity": "sha512-NOJ6JZCAWr0zlxZt+xqCHNTEKOsrks2HQd4MqhP1qy4z1SkbEP467eNx6TgDKXMvUOb+OENfJCZwM+16n7fRfw==", - "license": "MIT" - }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", @@ -32844,9 +32771,9 @@ } }, "caniuse-lite": { - "version": "1.0.30001230", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001230.tgz", - "integrity": "sha512-5yBd5nWCBS+jWKTcHOzXwo5xzcj4ePE/yjtkZyUV1BTUmrBaA9MRGC+e7mxnqXSA90CmCA8L3eKLaSUkt099IQ==", + "version": "1.0.30001278", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001278.tgz", + "integrity": "sha512-mpF9KeH8u5cMoEmIic/cr7PNS+F5LWBk0t2ekGT60lFf0Wq+n9LspAj0g3P+o7DQhD3sUdlMln4YFAWhFYn9jg==", "dev": true }, "capture-exit": { @@ -36882,16 +36809,11 @@ "dev": true }, "history": { - "version": "4.10.1", - "resolved": "https://registry.npmjs.org/history/-/history-4.10.1.tgz", - "integrity": "sha512-36nwAD620w12kuzPAsyINPWJqlNbij+hpK1k9XRloDtym8mxzGYl2c17LnV6IAGB2Dmg4tEa7G7DlawS0+qjew==", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/history/-/history-5.1.0.tgz", + "integrity": "sha512-zPuQgPacm2vH2xdORvGGz1wQMuHSIB56yNAy5FnLuwOwgSYyPKptJtcMm6Ev+hRGeS+GzhbmRacHzvlESbFwDg==", "requires": { - "@babel/runtime": "^7.1.2", - "loose-envify": "^1.2.0", - "resolve-pathname": "^3.0.0", - "tiny-invariant": "^1.0.2", - "tiny-warning": "^1.0.0", - "value-equal": "^1.0.1" + "@babel/runtime": "^7.7.6" } }, "hmac-drbg": { @@ -37928,11 +37850,6 @@ "is-docker": "^2.0.0" } }, - "isarray": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=" - }, "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -39659,15 +39576,6 @@ "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", "dev": true }, - "mini-create-react-context": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/mini-create-react-context/-/mini-create-react-context-0.4.1.tgz", - "integrity": "sha512-YWCYEmd5CQeHGSAKrYvXgmzzkrvssZcuuQDDeqkT+PziKGMgE+0MCCtcKbROzocGBG1meBLl2FotlRwf4gAzbQ==", - "requires": { - "@babel/runtime": "^7.12.1", - "tiny-warning": "^1.0.3" - } - }, "mini-css-extract-plugin": { "version": "0.11.3", "resolved": "https://registry.npmjs.org/mini-css-extract-plugin/-/mini-css-extract-plugin-0.11.3.tgz", @@ -40772,14 +40680,6 @@ "integrity": "sha1-6GQhf3TDaFDwhSt43Hv31KVyG/I=", "dev": true }, - "path-to-regexp": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz", - "integrity": "sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==", - "requires": { - "isarray": "0.0.1" - } - }, "path-type": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", @@ -42654,41 +42554,20 @@ "dev": true }, "react-router": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/react-router/-/react-router-5.2.1.tgz", - "integrity": "sha512-lIboRiOtDLFdg1VTemMwud9vRVuOCZmUIT/7lUoZiSpPODiiH1UQlfXy+vPLC/7IWdFYnhRwAyNqA/+I7wnvKQ==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.0.1.tgz", + "integrity": "sha512-O3iab52icFnQaHWONZr50CcjRlf3gx8CCjPQ0YxN8xEuEklRJNgoZSeoYFYz0fLvA4cpnhc306Nd8BYgL4QZrQ==", "requires": { - "@babel/runtime": "^7.12.13", - "history": "^4.9.0", - "hoist-non-react-statics": "^3.1.0", - "loose-envify": "^1.3.1", - "mini-create-react-context": "^0.4.0", - "path-to-regexp": "^1.7.0", - "prop-types": "^15.6.2", - "react-is": "^16.6.0", - "tiny-invariant": "^1.0.2", - "tiny-warning": "^1.0.0" - }, - "dependencies": { - "react-is": { - "version": "16.13.1", - "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", - "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" - } + "history": "^5.1.0" } }, "react-router-dom": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-5.3.0.tgz", - "integrity": "sha512-ObVBLjUZsphUUMVycibxgMdh5jJ1e3o+KpAZBVeHcNQZ4W+uUGGWsokurzlF4YOldQYRQL4y6yFRWM4m3svmuQ==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.0.1.tgz", + "integrity": "sha512-fiE+PzFTrof5q8Z/+RHzuiin9/U/q5KY2adlHClwYexbY0DqJnHcC/0U9yv3Amz9em2/bcK7X8mk7+zxB+qhvg==", "requires": { - "@babel/runtime": "^7.12.13", - "history": "^4.9.0", - "loose-envify": "^1.3.1", - "prop-types": "^15.6.2", - "react-router": "5.2.1", - "tiny-invariant": "^1.0.2", - "tiny-warning": "^1.0.0" + "history": "^5.1.0", + "react-router": "6.0.1" } }, "react-scripts": { @@ -43277,11 +43156,6 @@ "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==" }, - "resolve-pathname": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/resolve-pathname/-/resolve-pathname-3.0.0.tgz", - "integrity": "sha512-C7rARubxI8bXFNB/hqcp/4iUeIXJhJZvFPFPiSPRnhU5UPxzMFIl+2E6yY6c4k9giDJAhtV+enfA+G89N6Csng==" - }, "resolve-url": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/resolve-url/-/resolve-url-0.2.1.tgz", @@ -45478,11 +45352,6 @@ "integrity": "sha1-QFQRqOfmM5/mTbmiNN4R3DHgK9Q=", "dev": true }, - "tiny-invariant": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/tiny-invariant/-/tiny-invariant-1.1.0.tgz", - "integrity": "sha512-ytxQvrb1cPc9WBEI/HSeYYoGD0kWnGEOR8RY6KomWLBVhqz0RgTwVO9dLrGz7dC+nN9llyI7OKAgRq8Vq4ZBSw==" - }, "tiny-warning": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/tiny-warning/-/tiny-warning-1.0.3.tgz", @@ -46075,11 +45944,6 @@ "spdx-expression-parse": "^3.0.0" } }, - "value-equal": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/value-equal/-/value-equal-1.0.1.tgz", - "integrity": "sha512-NOJ6JZCAWr0zlxZt+xqCHNTEKOsrks2HQd4MqhP1qy4z1SkbEP467eNx6TgDKXMvUOb+OENfJCZwM+16n7fRfw==" - }, "vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", diff --git a/package.json b/package.json index 4f7160d61..7e8d1f41d 100644 --- a/package.json +++ b/package.json @@ -56,8 +56,8 @@ "react-dom": "^17.0.2", "react-i18next": "^11.13.0", "react-redux": "^7.2.6", - "react-router": "^5.2.1", - "react-router-dom": "^5.3.0", + "react-router": "^6.0.2", + "react-router-dom": "^6.0.2", "react-share": "^4.4.0", "styled-components": "^5.3.3", "uuid": "^8.3.2", @@ -66,7 +66,6 @@ "devDependencies": { "@cypress/code-coverage": "^3.9.11", "@cypress/instrument-cra": "^1.4.0", - "@types/history": "^4.7.9", "@types/node": "^16.11.6", "@types/react": "^17.0.34", "@types/react-dom": "^17.0.11", @@ -89,4 +88,4 @@ "start-server-and-test": "^1.14.0", "typescript": "^4.4.4" } -} \ No newline at end of file +} diff --git a/src/App.tsx b/src/App.tsx index 3c554ef26..e9324d53e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,5 @@ import React, { useCallback, useEffect, useRef, useState } from 'react'; -import { BrowserRouter, Route, Switch } from 'react-router-dom'; +import { BrowserRouter } from 'react-router-dom'; import { useDispatch, useSelector } from 'react-redux'; import { setUser } from './state/userSlice'; import { @@ -13,7 +13,6 @@ import { CircularProgress } from '@mui/material'; import { USE_MOCK_DATA } from './utils/constants'; import i18next from 'i18next'; import ErrorBanner from './components/ErrorBanner'; -import LoginRedirectPage from './pages/LoginRedirectPage'; import AppContent from './AppContent'; import { StyledFullPageProgressWrapper } from './components/styled/Wrappers'; import useInterval from './utils/useInterval'; @@ -125,19 +124,14 @@ const App = () => { return ( - - - - {tokenError && } - {!isLoadingUser && hasValidToken ? ( - - ) : ( - - - - )} - - + {tokenError && } + {!isLoadingUser && hasValidToken ? ( + + ) : ( + + + + )} ); }; diff --git a/src/AppRoutes.tsx b/src/AppRoutes.tsx index d5d486dd0..ffd62804e 100644 --- a/src/AppRoutes.tsx +++ b/src/AppRoutes.tsx @@ -1,5 +1,5 @@ import React, { lazy, Suspense } from 'react'; -import { Redirect, Route, Switch } from 'react-router-dom'; +import { Navigate, Route, Routes } from 'react-router-dom'; import PrivacyPolicy from './pages/infopages/PrivacyPolicy'; import { useSelector } from 'react-redux'; import ResourcePage from './pages/resource/ResourcePage'; @@ -17,64 +17,102 @@ import ProfilePage from './pages/profile/ProfilePage'; import { resourcePath } from './utils/constants'; import HandleNotFound from './pages/errorpages/HandleNotFound'; import ResourceNotFound from './pages/errorpages/ResourceNotFound'; +import LoginRedirectPage from './pages/LoginRedirectPage'; const Explore = lazy(() => import('./pages/dashboard/Explore')); const EditResourcePage = lazy(() => import('./pages/edit_resource/EditResourcePage')); const NotFound = lazy(() => import('./pages/errorpages/NotFound')); -const AppRoutes = () => { +function RequireAuth({ children }: any) { + const user = useSelector((state: RootState) => state.user); + return user.id ? children : ; +} + +function RequireAdmin({ children }: any) { const user = useSelector((state: RootState) => state.user); + return user.institutionAuthorities?.isAdministrator ? children : ; +} +function RequireCuratorOrEditor({ children }: any) { + const user = useSelector((state: RootState) => state.user); + return user.institutionAuthorities?.isEditor || user.institutionAuthorities?.isCurator ? ( + children + ) : ( + + ); +} + +const AppRoutes = () => { return ( }> - - - - - - + } /> + } /> + } /> + } /> + } /> + } /> + } /> - - + } /> + } /> } + element={ + + + + } + /> + + + + } /> } + element={ + + + + } + /> + + + + + } /> - } /> - - {/* CreatorRoutes */} - } /> - {/*hack: uuidv4-key is forcing page refresh*/} + {/*TODO/!*hack: uuidv4-key is forcing page refresh*!/*/} } + element={ + + + + } /> ( - - )} + element={ + + + + } /> - - - - - + } /> + } /> + } /> + } /> + ); }; diff --git a/src/components/ResultListItem.tsx b/src/components/ResultListItem.tsx index b75df22b6..5084e4ff8 100644 --- a/src/components/ResultListItem.tsx +++ b/src/components/ResultListItem.tsx @@ -18,7 +18,6 @@ import institutions from '../resources/assets/institutions.json'; const StyledListItem: any = styled.li` width: 100%; - max-width: ${StyleWidths.width4}; background-color: ${Colors.Background}; margin-bottom: 0.5rem; padding: 1rem; diff --git a/src/pages/LoginRedirectPage.tsx b/src/pages/LoginRedirectPage.tsx index 952e80b96..08c609463 100644 --- a/src/pages/LoginRedirectPage.tsx +++ b/src/pages/LoginRedirectPage.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useState } from 'react'; -import { Redirect, useLocation } from 'react-router-dom'; +import { useLocation } from 'react-router-dom'; import { getTokenExpiry, getUserAppFeaturesApplication, @@ -10,12 +10,12 @@ import { setUser } from '../state/userSlice'; import { useDispatch, useSelector } from 'react-redux'; import ErrorBanner from '../components/ErrorBanner'; import { RootState } from '../state/rootReducer'; -import { unpackFeideLogin } from '../utils/rewriteSearchParams'; +//import { unpackFeideLogin } from '../utils/rewriteSearchParams'; import { AxiosError } from 'axios'; import { handlePotentialAxiosError } from '../utils/AxiosErrorHandling'; const LoginRedirectPage = () => { - const user = useSelector((state: RootState) => state.user); + //const user = useSelector((state: RootState) => state.user); const location = useLocation(); const dispatch = useDispatch(); const [error, setError] = useState(); @@ -58,7 +58,7 @@ const LoginRedirectPage = () => { return ( <> - {user.id && !error && doneLoading && } + {/*{user.id && !error && doneLoading && }*/}
{error && }
); diff --git a/src/pages/admin/AdminPage.tsx b/src/pages/admin/AdminPage.tsx index 02a1589ca..830098dcf 100644 --- a/src/pages/admin/AdminPage.tsx +++ b/src/pages/admin/AdminPage.tsx @@ -8,7 +8,6 @@ import { getInstitutionAuthorizations } from '../../api/institutionAuthorization import { InstitutionProfilesNames } from '../../types/user.types'; import styled from 'styled-components'; import { Colors } from '../../themes/mainTheme'; -import AdminRoute from '../../utils/routes/AdminRoute'; import RoleSetter from './RoleSetter'; import { handlePotentialAxiosError } from '../../utils/AxiosErrorHandling'; import { AxiosError } from 'axios'; @@ -96,4 +95,4 @@ const AdminPage = () => { ); }; -export default AdminRoute(AdminPage); +export default AdminPage; diff --git a/src/pages/content_view/MainContentView.tsx b/src/pages/content_view/MainContentView.tsx index 858070eaa..6af9b045d 100644 --- a/src/pages/content_view/MainContentView.tsx +++ b/src/pages/content_view/MainContentView.tsx @@ -18,12 +18,8 @@ const ContentWrapper = styled.div<{ height: string }>` justify-content: center; `; -interface ContentViewParams { - resourceIdentifier: string; -} - const MainContentView = () => { - const { resourceIdentifier } = useParams(); + const { resourceIdentifier } = useParams(); const [resource, setResource] = useState(emptyResource); const searchParams = new URLSearchParams(window.location.search); const height = searchParams.get('height') ?? '27rem'; @@ -46,7 +42,7 @@ const MainContentView = () => { }; if (resourceIdentifier) { - fetchData(resourceIdentifier); + fetchData(resourceIdentifier).then(); } }, [resourceIdentifier]); return isLoadingResource ? ( diff --git a/src/pages/dashboard/AccessFiltering.tsx b/src/pages/dashboard/AccessFiltering.tsx index 6738a6240..fc629dcaa 100644 --- a/src/pages/dashboard/AccessFiltering.tsx +++ b/src/pages/dashboard/AccessFiltering.tsx @@ -1,7 +1,7 @@ import React, { Dispatch, FC, SetStateAction } from 'react'; import { Checkbox, FormControlLabel } from '@mui/material'; import { QueryObject, SearchParameters } from '../../types/search.types'; -import { useHistory, useLocation } from 'react-router-dom'; +import { useNavigate, useLocation } from 'react-router-dom'; import { rewriteSearchParams } from '../../utils/rewriteSearchParams'; import HelperTextPopover from '../../components/HelperTextPopover'; import Typography from '@mui/material/Typography'; @@ -14,7 +14,7 @@ interface AccessFilteringProps { const AccessFiltering: FC = ({ queryObject, setQueryObject }) => { const location = useLocation(); - const history = useHistory(); + const navigate = useNavigate(); const { t } = useTranslation(); const changeSelected = (event: any) => { @@ -26,7 +26,7 @@ const AccessFiltering: FC = ({ queryObject, setQueryObject rewriteSearchParams( SearchParameters.showInaccessible, [event.target.checked ? 'true' : 'false'], - history, + navigate, location, true ); diff --git a/src/pages/dashboard/Explore.tsx b/src/pages/dashboard/Explore.tsx index 28e687ebc..1e1c65c9f 100644 --- a/src/pages/dashboard/Explore.tsx +++ b/src/pages/dashboard/Explore.tsx @@ -17,7 +17,7 @@ import ErrorBanner from '../../components/ErrorBanner'; import { PageHeader } from '../../components/PageHeader'; import { StyledContentWrapperLarge, StyledPaginationWrapper } from '../../components/styled/Wrappers'; import SearchInput from './SearchInput'; -import { useHistory, useLocation } from 'react-router-dom'; +import { useNavigate, useLocation } from 'react-router-dom'; import { Pagination } from '@mui/material'; import ResultListItem from '../../components/ResultListItem'; import FilterSearchOptions from './FilterSearchOptions'; @@ -120,7 +120,7 @@ const Explore = () => { const [resources, setResources] = useState([]); const { t } = useTranslation(); const [searchError, setSearchError] = useState(); - const history = useHistory(); + const navigate = useNavigate(); const [hasPopStateListener, setHasPopStateListener] = useState(false); const resultListRef = useRef(null); @@ -131,13 +131,13 @@ const Explore = () => { ...prevState, offset: (Number(value) - 1) * NumberOfResultsPrPage, })); - rewriteSearchParams(SearchParameters.page, ['' + value], history, location); + rewriteSearchParams(SearchParameters.page, ['' + value], navigate, location); if (startOfList && startOfList.current) { startOfList.current.scrollIntoView(); } }, - [history, location, startOfList] + [navigate, location, startOfList] ); const triggerSearch = async (queryObject: QueryObject) => { diff --git a/src/pages/dashboard/InstitutionFiltering.tsx b/src/pages/dashboard/InstitutionFiltering.tsx index e6f4249b6..df0624a3f 100644 --- a/src/pages/dashboard/InstitutionFiltering.tsx +++ b/src/pages/dashboard/InstitutionFiltering.tsx @@ -8,7 +8,7 @@ import styled from 'styled-components'; import { getAllFacets } from '../../api/resourceApi'; import ErrorBanner from '../../components/ErrorBanner'; import institutions from '../../resources/assets/institutions.json'; -import { useHistory, useLocation } from 'react-router-dom'; +import { useNavigate, useLocation } from 'react-router-dom'; import { rewriteSearchParams } from '../../utils/rewriteSearchParams'; import { handlePotentialAxiosError } from '../../utils/AxiosErrorHandling'; import { AxiosError } from 'axios'; @@ -45,7 +45,7 @@ const InstitutionFiltering: FC = ({ queryObject, setQ const [error, setError] = useState(); const mountedRef = useRef(true); const location = useLocation(); - const history = useHistory(); + const navigate = useNavigate(); useEffect(() => { return () => { @@ -105,7 +105,7 @@ const InstitutionFiltering: FC = ({ queryObject, setQ ); } setQueryObject(newQueryObject); - rewriteSearchParams(SearchParameters.institution, newQueryObject.institutions, history, location, true); + rewriteSearchParams(SearchParameters.institution, newQueryObject.institutions, navigate, location, true); }; const generateInstitutionName = (institutionCode: string): string => { diff --git a/src/pages/dashboard/LicenseFiltering.tsx b/src/pages/dashboard/LicenseFiltering.tsx index f3e1a8dcd..87652f80a 100644 --- a/src/pages/dashboard/LicenseFiltering.tsx +++ b/src/pages/dashboard/LicenseFiltering.tsx @@ -11,7 +11,7 @@ import styled from 'styled-components'; import { useSelector } from 'react-redux'; import { RootState } from '../../state/rootReducer'; import { User, UserInstitution } from '../../types/user.types'; -import { useHistory, useLocation } from 'react-router-dom'; +import { useNavigate, useLocation } from 'react-router-dom'; import { rewriteSearchParams } from '../../utils/rewriteSearchParams'; const StyledCheckboxLabelWrapper = styled.div` @@ -65,7 +65,7 @@ const LicenseFiltering: FC = ({ queryObject, setQueryObje const [licensesCheckList, setLicensesCheckList] = useState(initLicenseList(user)); const { t } = useTranslation(); const location = useLocation(); - const history = useHistory(); + const navigate = useNavigate(); useEffect(() => { if (queryObject.licenses.length > 0) { @@ -87,7 +87,7 @@ const LicenseFiltering: FC = ({ queryObject, setQueryObje (licenseCode) => licenseCode !== licensesCheckList[index].licenseCode )); setQueryObject(newQueryObject); - rewriteSearchParams(SearchParameters.license, newQueryObject.licenses, history, location, true); + rewriteSearchParams(SearchParameters.license, newQueryObject.licenses, navigate, location, true); }; return ( diff --git a/src/pages/dashboard/ResourceTypeFiltering.tsx b/src/pages/dashboard/ResourceTypeFiltering.tsx index f671e4235..c19fd717d 100644 --- a/src/pages/dashboard/ResourceTypeFiltering.tsx +++ b/src/pages/dashboard/ResourceTypeFiltering.tsx @@ -6,7 +6,7 @@ import { Checkbox, FormControl, FormControlLabel, FormGroup } from '@mui/materia import FormLabel from '@mui/material/FormLabel'; import Typography from '@mui/material/Typography'; import styled from 'styled-components'; -import { useHistory, useLocation } from 'react-router-dom'; +import { useNavigate, useLocation } from 'react-router-dom'; import { rewriteSearchParams } from '../../utils/rewriteSearchParams'; const StyledFormControl: any = styled(FormControl)` @@ -33,7 +33,7 @@ interface ResourceTypeFilteringProps { const ResourceTypeFiltering: FC = ({ queryObject, setQueryObject }) => { const { t } = useTranslation(); const location = useLocation(); - const history = useHistory(); + const navigate = useNavigate(); const [resourceTypeCheckList, setResourceCheckList] = useState(initialResourceTypeCheckList(t)); @@ -57,7 +57,7 @@ const ResourceTypeFiltering: FC = ({ queryObject, se (resourceType) => resourceType !== resourceTypeCheckList[index].name )); setQueryObject(newQueryObject); - rewriteSearchParams(SearchParameters.resourceType, newQueryObject.resourceTypes, history, location, true); + rewriteSearchParams(SearchParameters.resourceType, newQueryObject.resourceTypes, navigate, location, true); }; return ( diff --git a/src/pages/dashboard/SearchInput.tsx b/src/pages/dashboard/SearchInput.tsx index 5a406a7b0..de2730215 100644 --- a/src/pages/dashboard/SearchInput.tsx +++ b/src/pages/dashboard/SearchInput.tsx @@ -5,7 +5,7 @@ import styled from 'styled-components'; import SearchIcon from '@mui/icons-material/Search'; import { StyleWidths } from '../../themes/mainTheme'; import { NumberOfResultsPrPage, QueryObject, SearchParameters } from '../../types/search.types'; -import { useHistory, useLocation } from 'react-router-dom'; +import { useNavigate, useLocation } from 'react-router-dom'; import { rewriteSearchParams } from '../../utils/rewriteSearchParams'; import HelperTextPopover from '../../components/HelperTextPopover'; import Typography from '@mui/material/Typography'; @@ -65,7 +65,7 @@ interface SearchInputProps { const SearchInput: FC = ({ setQueryObject, queryObject }) => { const [searchTerm, setSearchTerm] = useState(queryObject.query); const location = useLocation(); - const history = useHistory(); + const navigate = useNavigate(); const { t } = useTranslation(); const handleSubmit = (event: FormEvent) => { @@ -77,7 +77,7 @@ const SearchInput: FC = ({ setQueryObject, queryObject }) => { offset: 0, queryFromURL: false, })); - rewriteSearchParams(SearchParameters.query, [searchTerm], history, location, true); + rewriteSearchParams(SearchParameters.query, [searchTerm], navigate, location, true); }; useEffect(() => { diff --git a/src/pages/dashboard/TagFiltering.tsx b/src/pages/dashboard/TagFiltering.tsx index 0ce4e9c43..e287ffc18 100644 --- a/src/pages/dashboard/TagFiltering.tsx +++ b/src/pages/dashboard/TagFiltering.tsx @@ -11,7 +11,7 @@ import HelperTextPopover from '../../components/HelperTextPopover'; import { searchTags } from '../../api/resourceApi'; import useDebounce from '../../utils/useDebounce'; import ErrorBanner from '../../components/ErrorBanner'; -import { useHistory, useLocation } from 'react-router-dom'; +import { useNavigate, useLocation } from 'react-router-dom'; import { rewriteSearchParams } from '../../utils/rewriteSearchParams'; import { StyleWidths } from '../../themes/mainTheme'; import { handlePotentialAxiosError } from '../../utils/AxiosErrorHandling'; @@ -59,7 +59,7 @@ const TagsFiltering: FC = ({ queryObject, setQueryObject }) const [cancelSearch, setCancelSearch] = useState(false); const [tagSearchError, setTagSearchError] = useState(); const location = useLocation(); - const history = useHistory(); + const navigate = useNavigate(); useEffect(() => { const searchForTags = async () => { @@ -94,7 +94,7 @@ const TagsFiltering: FC = ({ queryObject, setQueryObject }) tags: newTags, offset: 0, })); - rewriteSearchParams(SearchParameters.tag, newTags, history, location, true); + rewriteSearchParams(SearchParameters.tag, newTags, navigate, location, true); } setTagInputFieldValue(''); setCancelSearch(false); @@ -114,7 +114,7 @@ const TagsFiltering: FC = ({ queryObject, setQueryObject }) offset: 0, })); setTagValue(''); - rewriteSearchParams(SearchParameters.tag, newTags, history, location, true); + rewriteSearchParams(SearchParameters.tag, newTags, navigate, location, true); }; const handleChangeInBooleanSearchQueryCheckBox = (event: React.ChangeEvent) => { @@ -126,7 +126,7 @@ const TagsFiltering: FC = ({ queryObject, setQueryObject }) tagFilterOperator: searchQueryTabBooleanOperator, offset: 0, })); - rewriteSearchParams(SearchParameters.tagFilterOperator, [searchQueryTabBooleanOperator], history, location, true); + rewriteSearchParams(SearchParameters.tagFilterOperator, [searchQueryTabBooleanOperator], navigate, location, true); }; return ( diff --git a/src/pages/edit_resource/EditResourcePage.tsx b/src/pages/edit_resource/EditResourcePage.tsx index 61071f7fd..dcd812778 100644 --- a/src/pages/edit_resource/EditResourcePage.tsx +++ b/src/pages/edit_resource/EditResourcePage.tsx @@ -1,13 +1,12 @@ import React, { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { Prompt, useParams } from 'react-router-dom'; +import { useParams } from 'react-router-dom'; import styled from 'styled-components'; import { PageHeader } from '../../components/PageHeader'; import ResourceForm from './ResourceForm'; import LinkRegistration from './LinkRegistration'; import FileRegistration from './FileRegistration'; import { CircularProgress, Typography } from '@mui/material'; -import PrivateRoute from '../../utils/routes/PrivateRoute'; import { Contributor, ContributorFeatureNames, @@ -70,17 +69,14 @@ const StyledTypography = styled(Typography)` margin-bottom: 1.5rem; `; -interface EditResourcePageParamTypes { - identifier: string; -} - // StartingContributorType must match one of the elements in resources/assets/contributorTypeList.json. // This to prevent error: "Material-UI: You have provided an out-of-range value..." const StartingContributorType = 'HostingInstitution'; const EditResourcePage = () => { const { t } = useTranslation(); - const { identifier } = useParams(); + let { identifier } = useParams(); + identifier = identifier || ''; const [formikInitResource, setFormikInitResource] = useState(); const [expanded, setExpanded] = useState(''); const [isLoadingResource, setIsLoadingResource] = useState(false); @@ -366,53 +362,58 @@ const EditResourcePage = () => { useEffect(() => { const loadResource = async () => { - setIsLoadingResource(true); - const resource = deepmerge(emptyResource, (await getResource(identifier)).data); - setResourceType( - resource.features.dlr_content_type === ResourceCreationType.LINK - ? ResourceCreationType.LINK - : ResourceCreationType.FILE - ); - /*creating all promises first, and afterwards waiting - for their results reduces loading time from 2.4 seconds to 0.9 seconds. - */ - const contributorPromise = getResourceContributors(identifier); - const creatorPromise = getResourceCreators(identifier); - const licensesPromise = getResourceLicenses(identifier); - const contentsPromise = getResourceContents(identifier); - const tagsPromise = getResourceTags(identifier); + if (identifier) { + setIsLoadingResource(true); + const resource = deepmerge(emptyResource, (await getResource(identifier)).data); + setResourceType( + resource.features.dlr_content_type === ResourceCreationType.LINK + ? ResourceCreationType.LINK + : ResourceCreationType.FILE + ); + /*creating all promises first, and afterwards waiting + for their results reduces loading time from 2.4 seconds to 0.9 seconds. + */ + const contributorPromise = getResourceContributors(identifier); + const creatorPromise = getResourceCreators(identifier); + const licensesPromise = getResourceLicenses(identifier); + const contentsPromise = getResourceContents(identifier); + const tagsPromise = getResourceTags(identifier); - resource.contributors = (await contributorPromise).data; - resource.creators = (await creatorPromise).data; + resource.contributors = (await contributorPromise).data; + resource.creators = (await creatorPromise).data; - const contributorWithAuthoritiesPromise = fetchAuthoritiesForCreatorOrContributor( - resource.identifier, - resource.contributors - ); - const creatorWithAuthoritiesPromise = fetchAuthoritiesForCreatorOrContributor( - resource.identifier, - resource.creators - ); - resource.creators = (await creatorWithAuthoritiesPromise) as Creator[]; - resource.contributors = (await contributorWithAuthoritiesPromise) as Contributor[]; + const contributorWithAuthoritiesPromise = fetchAuthoritiesForCreatorOrContributor( + resource.identifier, + resource.contributors + ); + const creatorWithAuthoritiesPromise = fetchAuthoritiesForCreatorOrContributor( + resource.identifier, + resource.creators + ); + resource.creators = (await creatorWithAuthoritiesPromise) as Creator[]; + resource.contributors = (await contributorWithAuthoritiesPromise) as Contributor[]; - resource.tags = (await tagsPromise).data.filter((tag) => tag.length <= TAGS_MAX_LENGTH); - resource.contents = await contentsPromise; - resource.licenses = (await licensesPromise).data; - if (!resource.features.dlr_type) resource.features.dlr_type = ''; - if (!resource.licenses[0]) resource.licenses = [emptyLicense]; - setFormikInitResource(resource); - setIsLoadingResource(false); + resource.tags = (await tagsPromise).data.filter((tag) => tag.length <= TAGS_MAX_LENGTH); + resource.contents = await contentsPromise; + resource.licenses = (await licensesPromise).data; + if (!resource.features.dlr_type) resource.features.dlr_type = ''; + if (!resource.licenses[0]) resource.licenses = [emptyLicense]; + setFormikInitResource(resource); + setIsLoadingResource(false); + } }; if (identifier) { setShowForm(true); - loadResource(); + loadResource().then(); } }, [identifier, user.institutionAuthorities?.isCurator]); + //TODO ? + // usePrompt(t('resource.files_and_license.warning_leaving_form_premature'), mainFileBeingUploaded); + return ( <> - + {/*TODO*/} {!showForm ? ( {t('resource.new_registration')} @@ -471,4 +472,4 @@ const EditResourcePage = () => { ); }; -export default PrivateRoute(EditResourcePage); +export default EditResourcePage; diff --git a/src/pages/edit_resource/ResourceFormActions.tsx b/src/pages/edit_resource/ResourceFormActions.tsx index e0c093cae..31ace1c40 100644 --- a/src/pages/edit_resource/ResourceFormActions.tsx +++ b/src/pages/edit_resource/ResourceFormActions.tsx @@ -6,7 +6,7 @@ import { publishResource, updateSearchIndex } from '../../api/resourceApi'; import { getStepLabel, Resource, ResourceFormStep } from '../../types/resource.types'; import { StyledContentWrapperMedium, StyledSchemaPart } from '../../components/styled/Wrappers'; import ErrorBanner from '../../components/ErrorBanner'; -import { useHistory } from 'react-router-dom'; +import { useNavigate } from 'react-router-dom'; import { useFormikContext } from 'formik'; import ArrowForwardIcon from '@mui/icons-material/ArrowForward'; import ArrowBackIcon from '@mui/icons-material/ArrowBack'; @@ -84,7 +84,7 @@ const ResourceFormAction: FC = ({ uppy, }) => { const { t } = useTranslation(); - const history = useHistory(); + const navigate = useNavigate(); const [publishResourceError, setPublishResourceError] = useState(); const { values, isValid } = useFormikContext(); @@ -102,7 +102,7 @@ const ResourceFormAction: FC = ({ setPublishResourceError(undefined); try { await publishResource(values.identifier); - history.push(`${resourcePath}/${values.identifier}`); + navigate(`${resourcePath}/${values.identifier}`); } catch (error) { setPublishResourceError(handlePotentialAxiosError(error)); } @@ -110,7 +110,7 @@ const ResourceFormAction: FC = ({ const handleLeaveForm = async () => { values.features.dlr_status_published && updateSearchIndex(values.identifier); - history.push(`${resourcePath}/user/current`); + navigate(`${resourcePath}/user/current`); }; return ( diff --git a/src/pages/edit_resource/access_and_licence_step/LicenseWizardFields.tsx b/src/pages/edit_resource/access_and_licence_step/LicenseWizardFields.tsx index c13bd9761..0ece0008e 100644 --- a/src/pages/edit_resource/access_and_licence_step/LicenseWizardFields.tsx +++ b/src/pages/edit_resource/access_and_licence_step/LicenseWizardFields.tsx @@ -33,7 +33,7 @@ const StyledFormControlLabelDetail = styled.div` const StyledSchemaPartNoBottomPadding = styled.div` background-color: ${Colors.LicenseAccessPageGradientColor3}; - padding: 2rem 1rem 0rem 1rem; + padding: 2rem 1rem 0 1rem; display: flex; flex-direction: column; align-items: center; diff --git a/src/pages/my_resources/MyResources.tsx b/src/pages/my_resources/MyResources.tsx index fe930171d..2e1bbd9e8 100644 --- a/src/pages/my_resources/MyResources.tsx +++ b/src/pages/my_resources/MyResources.tsx @@ -12,7 +12,6 @@ import ErrorBanner from '../../components/ErrorBanner'; import { PageHeader } from '../../components/PageHeader'; import ResourceListItem from '../../components/ResourceListItem'; import { Colors } from '../../themes/mainTheme'; -import PrivateRoute from '../../utils/routes/PrivateRoute'; import { AxiosError } from 'axios'; import { handlePotentialAxiosError } from '../../utils/AxiosErrorHandling'; import { tabPanelClasses } from '@mui/lab'; @@ -51,7 +50,7 @@ const MyResources = () => { setIsLoadingMyResources(false); } }; - fetchData(); + fetchData().then(); }, []); const handleDeleteResource = (resourceIdentifier: string, isPublished: boolean) => { @@ -137,4 +136,4 @@ const MyResources = () => { ); }; -export default PrivateRoute(MyResources); +export default MyResources; diff --git a/src/pages/profile/ProfilePage.tsx b/src/pages/profile/ProfilePage.tsx index 96ae01e84..03a376535 100644 --- a/src/pages/profile/ProfilePage.tsx +++ b/src/pages/profile/ProfilePage.tsx @@ -1,5 +1,4 @@ import React from 'react'; -import PrivateRoute from '../../utils/routes/PrivateRoute'; import { StyledContentWrapperLarge } from '../../components/styled/Wrappers'; import { PageHeader } from '../../components/PageHeader'; import { useTranslation } from 'react-i18next'; @@ -40,4 +39,4 @@ const ProfilePage = () => { ); }; -export default PrivateRoute(ProfilePage); +export default ProfilePage; diff --git a/src/pages/resource/ResourcePage.tsx b/src/pages/resource/ResourcePage.tsx index 1379fabdd..145d7df98 100644 --- a/src/pages/resource/ResourcePage.tsx +++ b/src/pages/resource/ResourcePage.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useState } from 'react'; import styled from 'styled-components'; -import { useHistory, useParams } from 'react-router-dom'; +import { useNavigate, useParams } from 'react-router-dom'; import { emptyResource } from '../../types/resource.types'; import { getResource, @@ -25,28 +25,23 @@ const StyledResourceActionBar = styled.div` width: 100%; flex-direction: row; justify-content: flex-end; - align-items: flex; `; const StyledContentWrapperLargeWithBottomMargin = styled(StyledContentWrapperLarge)` margin-bottom: 2rem; `; -interface resourcePageParamTypes { - identifier: string; -} - const ResourcePage = () => { - const { identifier } = useParams(); + const { identifier } = useParams(); const [resource, setResource] = useState(emptyResource); const [isLoadingResource, setIsLoadingResource] = useState(true); const [resourceLoadingError, setResourceLoadingError] = useState(); const { t } = useTranslation(); - const history = useHistory(); + const navigate = useNavigate(); const [canEditResource, setCanEditResource] = useState(false); const handleClickEditButton = () => { - history.push(`/editresource/${resource?.identifier}`); + navigate(`/editresource/${resource?.identifier}`); }; useEffect(() => { @@ -66,7 +61,7 @@ const ResourcePage = () => { if ((potentialAxiosError as AxiosError).response) { const axiosError = potentialAxiosError as AxiosError; if (axiosError.response && (axiosError.response.status === 404 || axiosError.response.status === 503)) { - history.push(`/resourcenotfound/${identifier}`); + navigate(`/resourcenotfound/${identifier}`); } } else { setResourceLoadingError(potentialAxiosError); @@ -77,9 +72,9 @@ const ResourcePage = () => { }; if (identifier) { - fetchData(identifier); + fetchData(identifier).then(); } - }, [history, identifier]); + }, [navigate, identifier]); return isLoadingResource ? ( diff --git a/src/pages/worklist/WorkListPage.tsx b/src/pages/worklist/WorkListPage.tsx index 53dc8179b..f1f5fce92 100644 --- a/src/pages/worklist/WorkListPage.tsx +++ b/src/pages/worklist/WorkListPage.tsx @@ -1,5 +1,4 @@ import React, { useEffect, useRef, useState } from 'react'; -import CuratorOrEditorPrivateRoute from '../../utils/routes/CuratorOrEditorPrivateRoute'; import { StyledContentWrapperLarge } from '../../components/styled/Wrappers'; import { PageHeader } from '../../components/PageHeader'; import { useTranslation } from 'react-i18next'; @@ -206,4 +205,4 @@ const WorkListPage = () => { ); }; -export default CuratorOrEditorPrivateRoute(WorkListPage); +export default WorkListPage; diff --git a/src/utils/rewriteSearchParams.ts b/src/utils/rewriteSearchParams.ts index 73a5bcba6..0e82a2331 100644 --- a/src/utils/rewriteSearchParams.ts +++ b/src/utils/rewriteSearchParams.ts @@ -4,7 +4,7 @@ import { API_PATHS, API_URL } from './constants'; export const rewriteSearchParams = ( parameterName: SearchParameters, listOfNewParams: string[], - history: any, + navigate: any, location: any, removePage = false ) => { @@ -14,7 +14,7 @@ export const rewriteSearchParams = ( listOfNewParams.forEach((parameter) => { urlSearchTerms.append(parameterName, parameter); }); - history.push('?' + urlSearchTerms.toString()); + navigate('?' + urlSearchTerms.toString()); }; const ParamsSplitter = 'ZZZZ'; diff --git a/src/utils/routes/AdminRoute.tsx b/src/utils/routes/AdminRoute.tsx deleted file mode 100644 index b28d479ba..000000000 --- a/src/utils/routes/AdminRoute.tsx +++ /dev/null @@ -1,8 +0,0 @@ -import React, { ComponentType } from 'react'; -import { Redirect } from 'react-router-dom'; - -const AdminRoute = (Component: ComponentType) => (props: any) => { - return props.isAdmin ? : ; -}; - -export default AdminRoute; diff --git a/src/utils/routes/CuratorOrEditorPrivateRoute.tsx b/src/utils/routes/CuratorOrEditorPrivateRoute.tsx deleted file mode 100644 index f6beadbaf..000000000 --- a/src/utils/routes/CuratorOrEditorPrivateRoute.tsx +++ /dev/null @@ -1,8 +0,0 @@ -import React, { ComponentType } from 'react'; -import { Redirect } from 'react-router-dom'; - -const CuratorOrEditorPrivateRoute = (Component: ComponentType) => (props: any) => { - return props.isEditor || props.isCurator ? : ; -}; - -export default CuratorOrEditorPrivateRoute; diff --git a/src/utils/routes/PrivateRoute.tsx b/src/utils/routes/PrivateRoute.tsx deleted file mode 100644 index 6e2dba459..000000000 --- a/src/utils/routes/PrivateRoute.tsx +++ /dev/null @@ -1,8 +0,0 @@ -import React, { ComponentType } from 'react'; -import { Redirect } from 'react-router-dom'; - -const PrivateRoute = (Component: ComponentType) => (props: any) => { - return props.id ? : ; -}; - -export default PrivateRoute;