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!

migrated to v6

Udai Gupta6e6eacd486c9
diff --git a/.env.example b/.env.example
index 4b9e403fb..27f06cdbc 100644
--- a/.env.example
+++ b/.env.example
@@ -1,3 +1,3 @@
-REACT_APP_API_URL=https://example.com/api/
+REACT_APP_API_URL=http://127.0.0.1:8080/
CHOKIDAR_USEPOLLING=true
GENERATE_SOURCEMAP=false
diff --git a/package.json b/package.json
index 3fe9ff6f2..8235e2471 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": "^5.3.0",
+ "react-router-dom": "^6.2.1",
"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 b4bdf3e87..aaa401396 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,5 +1,5 @@
import React, { useEffect, lazy, Suspense, useState } from 'react'
-import { Switch, Route, Redirect, useLocation } from 'react-router-dom'
+import { Routes, Route, useLocation } from 'react-router-dom'
import routes from 'routes'
import { useDispatch, useSelector } from 'react-redux'
import { useAlert } from 'react-alert'
@@ -8,11 +8,9 @@ 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'
@@ -108,37 +106,36 @@ const App = () => {
return (
(!accessToken || !loading) && (
- <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>
+ <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/>} />
+ </Routes>
+ </Suspense>
+ </Selfhosted>
+ </ScrollToTop>
+ <Footer minimal={isMinimalFooter} authenticated={authenticated} />
+ </Suspense>
)
)
}
diff --git a/src/components/Footer/index.jsx b/src/components/Footer/index.jsx
index cb3156704..65542eb7e 100644
--- a/src/components/Footer/index.jsx
+++ b/src/components/Footer/index.jsx
@@ -62,7 +62,7 @@ const Footer = ({ minimal, authenticated }) => {
const year = new Date().getFullYear()
if (minimal) {
- return (
+ return (
<footer className='bg-gray-800 dark:bg-gray-900'>
<div className='max-w-7xl mx-auto py-8 px-4 overflow-hidden sm:px-6 lg:px-8'>
<nav className='-mx-5 -my-2 flex flex-wrap justify-center' aria-label='Footer'>
diff --git a/src/hoc/ScrollToTop.jsx b/src/hoc/ScrollToTop.jsx
index 5bc7427bc..8da7e5eca 100644
--- a/src/hoc/ScrollToTop.jsx
+++ b/src/hoc/ScrollToTop.jsx
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react'
-import { useHistory } from 'react-router-dom'
+import { useLocation, useNavigate } from 'react-router-dom'
/**
* A HOC which listens to history changes and scrolls to top of the page when triggered.
@@ -8,21 +8,29 @@ import { useHistory } from 'react-router-dom'
* @param {HTMLElement} children The children covered by the listener.
*/
const ScrollToTop = ({ children }) => {
- const history = useHistory()
+ const location = useLocation()
useEffect(() => {
- const unlisten = history.listen(({ hash }) => {
- if (hash === '') {
- setTimeout(() => {
- window.scrollTo({
- top: 0,
- behavior: 'smooth',
- })
- }, 0)
- }
- })
- return unlisten
- }, [history])
+ if (location.hash === '') {
+ setTimeout(() => {
+ window.scrollTo({
+ top: 0,
+ behavior: 'smooth',
+ })
+ }, 0)
+ }
+ // const unlisten = location.listen(({ hash }) => {
+ // if (hash === '') {
+ // setTimeout(() => {
+ // window.scrollTo({
+ // top: 0,
+ // behavior: 'smooth',
+ // })
+ // }, 0)
+ // }
+ // })
+ // return unlisten
+ }, [location])
return <>{children}</>
}
diff --git a/src/hoc/Selfhosted.jsx b/src/hoc/Selfhosted.jsx
index 444080921..d9887e8d1 100644
--- a/src/hoc/Selfhosted.jsx
+++ b/src/hoc/Selfhosted.jsx
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react'
-import { useHistory } from 'react-router-dom'
+import { useNavigate, useLocation } from 'react-router-dom'
import _includes from 'lodash/includes'
import { isSelfhosted } from 'redux/constants'
@@ -12,24 +12,22 @@ const selfHostedBlacklist = [
const DEFAULT_PAGE = routes.signin
const Selfhosted = ({ children }) => {
- const history = useHistory()
-
+ const navigate = useNavigate()
+ const location = useLocation()
useEffect(() => {
if (isSelfhosted) {
if (_includes(selfHostedBlacklist, window.location.pathname)) {
- history.push(DEFAULT_PAGE)
+ navigate(DEFAULT_PAGE)
+ }
+
+ if (_includes(selfHostedBlacklist, location.pathname)) {
+ navigate(DEFAULT_PAGE)
}
-
- const unlisten = history.listen(({ pathname }) => {
- if (_includes(selfHostedBlacklist, pathname)) {
- history.push(DEFAULT_PAGE)
- }
- })
- return unlisten
}
- }, [history])
+ }, [location])
return <>{children}</>
+
}
export default Selfhosted
diff --git a/src/hoc/protected.js b/src/hoc/protected.js
index 10d5b43b8..adbe43053 100644
--- a/src/hoc/protected.js
+++ b/src/hoc/protected.js
@@ -1,5 +1,5 @@
import { useSelector } from 'react-redux'
-import { useHistory } from 'react-router-dom'
+import { useNavigate } 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 = useHistory()
+ const history = useNavigate()
if (!selector) {
- history.push(authParam.redirectPath)
+ history(authParam.redirectPath)
}
return <WrappedComponent {...params} />
diff --git a/src/index.js b/src/index.js
index 933802444..30f7f6766 100644
--- a/src/index.js
+++ b/src/index.js
@@ -53,7 +53,7 @@ ReactDOM.render(
<Provider store={store}>
<BrowserRouter>
<I18nextProvider i18n={i18next}>
- <App />
+ <App/>
</I18nextProvider>
</BrowserRouter>
</Provider>
diff --git a/src/pages/Auth/CreateNewPassword/CreateNewPassword.jsx b/src/pages/Auth/CreateNewPassword/CreateNewPassword.jsx
index 487786537..3f4e57ea8 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, useHistory, useParams } from 'react-router-dom'
+import { Link, useNavigate, 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 = useHistory()
+ const history = useNavigate()
const { id } = useParams()
const [form, setForm] = useState({
password: '',
@@ -37,7 +37,7 @@ const CreateNewPassword = ({
await createNewPassword(id, password)
newPassword(t('auth.recovery.updated'))
- history.push(routes.signin)
+ history(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 eb8d69990..9601c1ea6 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, useHistory } from 'react-router-dom'
+import { Link, useNavigate } 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 = useHistory()
+ const history = useNavigate()
const [form, setForm] = useState({
email: '',
})
@@ -35,7 +35,7 @@ const ForgotPassword = ({
await forgotPassword(data)
newPassword(t('auth.forgot.sent'))
- history.push(routes.main)
+ history(routes.main)
} catch (e) {
createNewPasswordFailed(e.toString())
} finally {
diff --git a/src/pages/Dashboard/Dashboard.jsx b/src/pages/Dashboard/Dashboard.jsx
index 332cda6ad..d245e935f 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, useHistory } from 'react-router-dom'
+import { Link, useNavigate } 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 = useHistory()
+ const history = useNavigate()
const onNewProject = () => {
if (user.isActive || isSelfhosted) {
- history.push(routes.new_project)
+ history(routes.new_project)
} else {
setShowActivateEmailModal(true)
}
diff --git a/src/pages/MainPage/index.jsx b/src/pages/MainPage/index.jsx
index d60bf5b94..6acc621fe 100644
--- a/src/pages/MainPage/index.jsx
+++ b/src/pages/MainPage/index.jsx
@@ -139,7 +139,7 @@ const Main = () => {
<Trans
t={t}
i18nKey='main.signupTerms'
- components={{
+ components={{
tos: <Link to={routes.terms} className='font-medium text-gray-900 dark:text-gray-300 hover:underline' />,
pp: <Link to={routes.privacy} className='font-medium text-gray-900 dark:text-gray-300 hover:underline' />,
}}
diff --git a/src/pages/Project/Settings/ProjectSettings.jsx b/src/pages/Project/Settings/ProjectSettings.jsx
index af4d6f27e..dbd98f417 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, useHistory, useParams } from 'react-router-dom'
+import { useLocation, useNavigate, useParams } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import _isEmpty from 'lodash/isEmpty'
import _size from 'lodash/size'
@@ -29,11 +29,12 @@ const ProjectSettings = ({
loadProjects, isLoading, projects, showError, removeProject, user,
}) => {
const { t } = useTranslation('common')
+ const location = useLocation()
const { pathname } = useLocation()
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 history = useHistory()
+ const history = useNavigate()
const [form, setForm] = useState({
name: '',
id: id || nanoid(),
@@ -50,13 +51,13 @@ const ProjectSettings = ({
useEffect(() => {
if (!user.isActive && !isSelfhosted) {
showError(t('project.settings.verify'))
- history.push(routes.dashboard)
+ history(routes.dashboard)
}
if (!isLoading && isSettings && !projectDeleting) {
if (_isEmpty(project) || project?.uiHidden) {
showError(t('project.noExist'))
- history.push(routes.dashboard)
+ history(routes.dashboard)
} else {
setForm({
...project,
@@ -64,7 +65,7 @@ const ProjectSettings = ({
})
}
}
- }, [user, project, isLoading, isSettings, history, showError, projectDeleting, t])
+ }, [user, project, isLoading, isSettings, location, showError, projectDeleting, t])
const onSubmit = async (data) => {
if (!projectSaving) {
@@ -84,7 +85,7 @@ const ProjectSettings = ({
}
loadProjects()
- history.push(routes.dashboard)
+ history(routes.dashboard)
} catch (e) {
if (isSettings) {
updateProjectFailed(e)
@@ -105,7 +106,7 @@ const ProjectSettings = ({
await deleteProject(id)
removeProject(id)
projectDeleted()
- history.push(routes.dashboard)
+ history(routes.dashboard)
} catch (e) {
deleteProjectFailed(e)
} finally {
@@ -160,7 +161,7 @@ const ProjectSettings = ({
}
const onCancel = () => {
- history.push(isSettings ? _replace(routes.project, ':id', id) : routes.dashboard)
+ history(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 5f61ac48a..b8f12623c 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 { useHistory, useParams, Link } from 'react-router-dom'
+import { useNavigate, 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 = useHistory()
+ const history = useNavigate()
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.push(routes.dashboard)
+ history(routes.dashboard)
}
const loadAnalytics = async () => {
@@ -307,7 +307,7 @@ const ViewProject = ({
}
const openSettingsHandler = () => {
- history.push(_replace(routes.project_settings, ':id', id))
+ history(_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 4aa65afdc..94b48b4e1 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 { useHistory } from 'react-router-dom'
+import { useNavigate } 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 = useHistory()
+ const history = useNavigate()
const onDelete = () => {
dispatch(
@@ -31,7 +31,7 @@ const UserSettingsContainer = () => {
(error) => dispatch(
errorsActions.deleteAccountFailed(error.description),
),
- () => history.push(routes.main),
+ () => history(routes.main),
)
)
}