Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

reverted 'migrated to v6' and 'minor updates' commits

Blue Mouse1bb765220589
diff --git a/.env.example b/.env.example
index 27f06cdbc..4b9e403fb 100644
--- a/.env.example
+++ b/.env.example
@@ -1,3 +1,3 @@
-REACT_APP_API_URL=http://127.0.0.1:8080/
+REACT_APP_API_URL=https://example.com/api/
CHOKIDAR_USEPOLLING=true
GENERATE_SOURCEMAP=false
diff --git a/package.json b/package.json
index 8235e2471..3fe9ff6f2 100644
--- a/package.json
+++ b/package.json
@@ -31,7 +31,7 @@
"react-helmet": "^6.1.0",
"react-i18next": "^11.15.3",
"react-redux": "^7.2.6",
- "react-router-dom": "^6.2.1",
+ "react-router-dom": "^5.3.0",
"react-router-hash-link": "^2.4.3",
"react-scripts": "5.0.0",
"redux": "^4.1.2",
diff --git a/src/App.js b/src/App.js
index 7b84bd4e3..b4bdf3e87 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,5 +1,5 @@
import React, { useEffect, lazy, Suspense, useState } from 'react'
-import { Routes, Route, useLocation, Navigate } from 'react-router-dom'
+import { Switch, Route, Redirect, useLocation } from 'react-router-dom'
import routes from 'routes'
import { useDispatch, useSelector } from 'react-redux'
import { useAlert } from 'react-alert'
@@ -8,9 +8,11 @@ import _some from 'lodash/some'
import _includes from 'lodash/includes'
import 'dayjs/locale/ru'
import 'dayjs/locale/uk'
+
import Header from 'components/Header'
import Footer from 'components/Footer'
import Loader from 'ui/Loader'
+
import ScrollToTop from 'hoc/ScrollToTop'
import Selfhosted from 'hoc/Selfhosted'
import { getAccessToken } from 'utils/accessToken'
@@ -106,37 +108,37 @@ const App = () => {
return (
(!accessToken || !loading) && (
- <Suspense fallback={<></>}>
- <Header authenticated={authenticated} theme={theme} />
- <ScrollToTop>
- <Selfhosted>
- <Suspense fallback={<Fallback theme={theme} isMinimalFooter={isMinimalFooter} />}>
- <Routes>
- <Route path={routes.main} element={<MainPage/>} />
- <Route path={routes.signin} element={<SignIn/>} />
- <Route path={routes.signup} element={<SignUp/>} />
- <Route path={routes.dashboard} element={<Dashboard/>} />
- <Route path={routes.user_settings} element={<UserSettings/>} />
- <Route path={routes.verify} element={<VerifyEmail/>} />
- <Route path={routes.change_email} element={<VerifyEmail/>} />
- <Route path={routes.reset_password} element={<ForgotPassword/>} />
- <Route path={routes.new_password_form} element={<CreateNewPassword/>} />
- <Route path={routes.new_project} element={<ProjectSettings/>} />
- <Route path={routes.project_settings} element={<ProjectSettings/>} />
- <Route path={routes.project} element={<ViewProject/>} />
- <Route path={routes.billing} element={<Billing/>} />
- <Route path={routes.docs} element={<Docs/>} />
- <Route path={routes.contact} element={<Contact/>} />
- <Route path={routes.features} element={<Features/>} />
- <Route path={routes.privacy} element={<Privacy/>} />
- <Route path={routes.terms} element={<Terms/>} />
- <Route path='*' element={<Navigate to={routes.main} />} />
- </Routes>
- </Suspense>
- </Selfhosted>
- </ScrollToTop>
- <Footer minimal={isMinimalFooter} authenticated={authenticated} />
- </Suspense>
+ <Suspense fallback={<></>}>
+ <Header authenticated={authenticated} theme={theme} />
+ <ScrollToTop>
+ <Selfhosted>
+ <Suspense fallback={<Fallback theme={theme} isMinimalFooter={isMinimalFooter} />}>
+ <Switch>
+ <Route path={routes.main} component={MainPage} exact />
+ <Route path={routes.signin} component={SignIn} exact />
+ <Route path={routes.signup} component={SignUp} exact />
+ <Route path={routes.dashboard} component={Dashboard} exact />
+ <Route path={routes.user_settings} component={UserSettings} exact />
+ <Route path={routes.verify} component={VerifyEmail} exact />
+ <Route path={routes.change_email} component={VerifyEmail} exact />
+ <Route path={routes.reset_password} component={ForgotPassword} exact />
+ <Route path={routes.new_password_form} component={CreateNewPassword} exact />
+ <Route path={routes.new_project} component={ProjectSettings} exact />
+ <Route path={routes.project_settings} component={ProjectSettings} exact />
+ <Route path={routes.project} component={ViewProject} exact />
+ <Route path={routes.billing} component={Billing} exact />
+ <Route path={routes.docs} component={Docs} exact />
+ <Route path={routes.contact} component={Contact} exact />
+ <Route path={routes.features} component={Features} exact />
+ <Route path={routes.privacy} component={Privacy} exact />
+ <Route path={routes.terms} component={Terms} exact />
+ <Redirect to={routes.main} />
+ </Switch>
+ </Suspense>
+ </Selfhosted>
+ </ScrollToTop>
+ <Footer minimal={isMinimalFooter} authenticated={authenticated} />
+ </Suspense>
)
)
}
diff --git a/src/hoc/ScrollToTop.jsx b/src/hoc/ScrollToTop.jsx
index 6a42ae853..5bc7427bc 100644
--- a/src/hoc/ScrollToTop.jsx
+++ b/src/hoc/ScrollToTop.jsx
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react'
-import { useLocation } from 'react-router-dom'
+import { useHistory } from 'react-router-dom'
/**
* A HOC which listens to history changes and scrolls to top of the page when triggered.
@@ -8,18 +8,21 @@ import { useLocation } from 'react-router-dom'
* @param {HTMLElement} children The children covered by the listener.
*/
const ScrollToTop = ({ children }) => {
- const location = useLocation()
+ const history = useHistory()
useEffect(() => {
- if (location.hash === '') {
- setTimeout(() => {
- window.scrollTo({
- top: 0,
- behavior: 'smooth',
- })
- }, 0)
- }
- }, [location])
+ const unlisten = history.listen(({ hash }) => {
+ if (hash === '') {
+ setTimeout(() => {
+ window.scrollTo({
+ top: 0,
+ behavior: 'smooth',
+ })
+ }, 0)
+ }
+ })
+ return unlisten
+ }, [history])
return <>{children}</>
}
diff --git a/src/hoc/Selfhosted.jsx b/src/hoc/Selfhosted.jsx
index 219ad33ac..444080921 100644
--- a/src/hoc/Selfhosted.jsx
+++ b/src/hoc/Selfhosted.jsx
@@ -1,30 +1,35 @@
import React, { useEffect } from 'react'
-import { useNavigate, useLocation } from 'react-router-dom'
+import { useHistory } from 'react-router-dom'
import _includes from 'lodash/includes'
import { isSelfhosted } from 'redux/constants'
import routes from 'routes'
const selfHostedBlacklist = [
- routes.signup, routes.reset_password, routes.new_password_form, routes.main, routes.user_settings, routes.verify, routes.change_email, routes.billing,
+ routes.signup, routes.reset_password, routes.new_password_form, routes.main, routes.user_settings, routes.verify, routes.change_email,
]
const DEFAULT_PAGE = routes.signin
const Selfhosted = ({ children }) => {
- const navigate = useNavigate()
- const location = useLocation()
+ const history = useHistory()
useEffect(() => {
if (isSelfhosted) {
- if (_includes(selfHostedBlacklist, location.pathname)) {
- navigate(DEFAULT_PAGE)
+ if (_includes(selfHostedBlacklist, window.location.pathname)) {
+ history.push(DEFAULT_PAGE)
}
+
+ const unlisten = history.listen(({ pathname }) => {
+ if (_includes(selfHostedBlacklist, pathname)) {
+ history.push(DEFAULT_PAGE)
+ }
+ })
+ return unlisten
}
- }, [location, navigate])
+ }, [history])
return <>{children}</>
-
}
export default Selfhosted
diff --git a/src/hoc/protected.js b/src/hoc/protected.js
index adbe43053..10d5b43b8 100644
--- a/src/hoc/protected.js
+++ b/src/hoc/protected.js
@@ -1,5 +1,5 @@
import { useSelector } from 'react-redux'
-import { useNavigate } from 'react-router-dom'
+import { useHistory } from 'react-router-dom'
import routes from 'routes'
export const auth = {
@@ -16,10 +16,10 @@ export const auth = {
export const withAuthentication = (WrappedComponent, authParam) => {
const WithAuthentication = (params) => {
const selector = useSelector(authParam.selector)
- const history = useNavigate()
+ const history = useHistory()
if (!selector) {
- history(authParam.redirectPath)
+ history.push(authParam.redirectPath)
}
return <WrappedComponent {...params} />
diff --git a/src/pages/Auth/CreateNewPassword/CreateNewPassword.jsx b/src/pages/Auth/CreateNewPassword/CreateNewPassword.jsx
index 3f4e57ea8..487786537 100644
--- a/src/pages/Auth/CreateNewPassword/CreateNewPassword.jsx
+++ b/src/pages/Auth/CreateNewPassword/CreateNewPassword.jsx
@@ -1,5 +1,5 @@
import React, { useState, useEffect, memo } from 'react'
-import { Link, useNavigate, useParams } from 'react-router-dom'
+import { Link, useHistory, useParams } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { createNewPassword } from 'api'
@@ -14,7 +14,7 @@ const CreateNewPassword = ({
createNewPasswordFailed, newPassword,
}) => {
const { t } = useTranslation('common')
- const history = useNavigate()
+ const history = useHistory()
const { id } = useParams()
const [form, setForm] = useState({
password: '',
@@ -37,7 +37,7 @@ const CreateNewPassword = ({
await createNewPassword(id, password)
newPassword(t('auth.recovery.updated'))
- history(routes.signin)
+ history.push(routes.signin)
} catch (e) {
createNewPasswordFailed(e.toString())
} finally {
diff --git a/src/pages/Auth/ForgotPassword/ForgotPassword.jsx b/src/pages/Auth/ForgotPassword/ForgotPassword.jsx
index 9601c1ea6..eb8d69990 100644
--- a/src/pages/Auth/ForgotPassword/ForgotPassword.jsx
+++ b/src/pages/Auth/ForgotPassword/ForgotPassword.jsx
@@ -1,5 +1,5 @@
import React, { useState, useEffect, memo } from 'react'
-import { Link, useNavigate } from 'react-router-dom'
+import { Link, useHistory } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { forgotPassword } from 'api'
@@ -14,7 +14,7 @@ const ForgotPassword = ({
createNewPasswordFailed, newPassword,
}) => {
const { t } = useTranslation('common')
- const history = useNavigate()
+ const history = useHistory()
const [form, setForm] = useState({
email: '',
})
@@ -35,7 +35,7 @@ const ForgotPassword = ({
await forgotPassword(data)
newPassword(t('auth.forgot.sent'))
- history(routes.main)
+ history.push(routes.main)
} catch (e) {
createNewPasswordFailed(e.toString())
} finally {
diff --git a/src/pages/Dashboard/Dashboard.jsx b/src/pages/Dashboard/Dashboard.jsx
index d245e935f..332cda6ad 100644
--- a/src/pages/Dashboard/Dashboard.jsx
+++ b/src/pages/Dashboard/Dashboard.jsx
@@ -1,5 +1,5 @@
import React, { memo, useState } from 'react'
-import { Link, useNavigate } from 'react-router-dom'
+import { Link, useHistory } from 'react-router-dom'
import cx from 'clsx'
import dayjs from 'dayjs'
import PropTypes from 'prop-types'
@@ -121,11 +121,11 @@ const NoProjects = ({ t }) => (
const Dashboard = ({ projects, isLoading, error, user }) => {
const { t, i18n: { language } } = useTranslation('common')
const [showActivateEmailModal, setShowActivateEmailModal] = useState(false)
- const history = useNavigate()
+ const history = useHistory()
const onNewProject = () => {
if (user.isActive || isSelfhosted) {
- history(routes.new_project)
+ history.push(routes.new_project)
} else {
setShowActivateEmailModal(true)
}
diff --git a/src/pages/MainPage/index.jsx b/src/pages/MainPage/index.jsx
index bfa2bc33d..d60bf5b94 100644
--- a/src/pages/MainPage/index.jsx
+++ b/src/pages/MainPage/index.jsx
@@ -272,4 +272,4 @@ const Main = () => {
)
}
-export default withAuthentication(memo(Main), auth.notAuthenticated)
+export default memo(withAuthentication(Main, auth.notAuthenticated))
diff --git a/src/pages/Project/Settings/ProjectSettings.jsx b/src/pages/Project/Settings/ProjectSettings.jsx
index facd09609..af4d6f27e 100644
--- a/src/pages/Project/Settings/ProjectSettings.jsx
+++ b/src/pages/Project/Settings/ProjectSettings.jsx
@@ -1,5 +1,5 @@
import React, { useState, useEffect, useMemo, memo } from 'react'
-import { useLocation, useNavigate, useParams } from 'react-router-dom'
+import { useLocation, useHistory, useParams } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import _isEmpty from 'lodash/isEmpty'
import _size from 'lodash/size'
@@ -33,7 +33,7 @@ const ProjectSettings = ({
const { id } = useParams()
const project = useMemo(() => _find(projects, p => p.id === id) || {}, [projects, id])
const isSettings = !_isEmpty(id) && (_replace(routes.project_settings, ':id', id) === pathname)
- const navigate = useNavigate()
+ const history = useHistory()
const [form, setForm] = useState({
name: '',
id: id || nanoid(),
@@ -50,13 +50,13 @@ const ProjectSettings = ({
useEffect(() => {
if (!user.isActive && !isSelfhosted) {
showError(t('project.settings.verify'))
- navigate(routes.dashboard)
+ history.push(routes.dashboard)
}
if (!isLoading && isSettings && !projectDeleting) {
if (_isEmpty(project) || project?.uiHidden) {
showError(t('project.noExist'))
- navigate(routes.dashboard)
+ history.push(routes.dashboard)
} else {
setForm({
...project,
@@ -64,7 +64,7 @@ const ProjectSettings = ({
})
}
}
- }, [user, project, isLoading, isSettings, showError, projectDeleting, t, navigate])
+ }, [user, project, isLoading, isSettings, history, showError, projectDeleting, t])
const onSubmit = async (data) => {
if (!projectSaving) {
@@ -84,7 +84,7 @@ const ProjectSettings = ({
}
loadProjects()
- navigate(routes.dashboard)
+ history.push(routes.dashboard)
} catch (e) {
if (isSettings) {
updateProjectFailed(e)
@@ -105,7 +105,7 @@ const ProjectSettings = ({
await deleteProject(id)
removeProject(id)
projectDeleted()
- navigate(routes.dashboard)
+ history.push(routes.dashboard)
} catch (e) {
deleteProjectFailed(e)
} finally {
@@ -160,7 +160,7 @@ const ProjectSettings = ({
}
const onCancel = () => {
- navigate(isSettings ? _replace(routes.project, ':id', id) : routes.dashboard)
+ history.push(isSettings ? _replace(routes.project, ':id', id) : routes.dashboard)
}
const title = isSettings ? `${t('project.settings.settings')} ${form.name}` : t('project.settings.create')
diff --git a/src/pages/Project/View/ViewProject.jsx b/src/pages/Project/View/ViewProject.jsx
index b8f12623c..5f61ac48a 100644
--- a/src/pages/Project/View/ViewProject.jsx
+++ b/src/pages/Project/View/ViewProject.jsx
@@ -1,5 +1,5 @@
import React, { useState, useEffect, useMemo, memo, useRef } from 'react'
-import { useNavigate, useParams, Link } from 'react-router-dom'
+import { useHistory, useParams, Link } from 'react-router-dom'
import domToImage from 'dom-to-image'
import { saveAs } from 'file-saver'
import bb, { area, zoom } from 'billboard.js' // eslint-disable-line
@@ -160,7 +160,7 @@ const ViewProject = ({
const periodPairs = tbPeriodPairs(t)
const dashboardRef = useRef(null)
const { id } = useParams()
- const history = useNavigate()
+ const history = useHistory()
const project = useMemo(() => _find(projects, p => p.id === id) || {}, [projects, id])
const [isProjectPublic, setIsProjectPublic] = useState(false)
const [panelsData, setPanelsData] = useState({})
@@ -182,7 +182,7 @@ const ViewProject = ({
const onErrorLoading = () => {
showError(t('project.noExist'))
- history(routes.dashboard)
+ history.push(routes.dashboard)
}
const loadAnalytics = async () => {
@@ -307,7 +307,7 @@ const ViewProject = ({
}
const openSettingsHandler = () => {
- history(_replace(routes.project_settings, ':id', id))
+ history.push(_replace(routes.project_settings, ':id', id))
}
const exportAsImageHandler = async () => {
diff --git a/src/pages/UserSettings/UserSettings.container.jsx b/src/pages/UserSettings/UserSettings.container.jsx
index 94b48b4e1..4aa65afdc 100644
--- a/src/pages/UserSettings/UserSettings.container.jsx
+++ b/src/pages/UserSettings/UserSettings.container.jsx
@@ -1,5 +1,5 @@
import React, { memo } from 'react'
-import { useNavigate } from 'react-router-dom'
+import { useHistory } from 'react-router-dom'
import { useDispatch } from 'react-redux'
import { useTranslation } from 'react-i18next'
import dayjs from 'dayjs'
@@ -23,7 +23,7 @@ dayjs.extend(utc)
const UserSettingsContainer = () => {
const { t } = useTranslation('common')
const dispatch = useDispatch()
- const history = useNavigate()
+ const history = useHistory()
const onDelete = () => {
dispatch(
@@ -31,7 +31,7 @@ const UserSettingsContainer = () => {
(error) => dispatch(
errorsActions.deleteAccountFailed(error.description),
),
- () => history(routes.main),
+ () => history.push(routes.main),
)
)
}