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!

(fix) Authorised hydration errors (#330)

Andrii Romasiun4ec4e9f5a1af
diff --git a/app/App.tsx b/app/App.tsx
index 83edcaa8c..43be4efe7 100644
--- a/app/App.tsx
+++ b/app/App.tsx
@@ -84,22 +84,25 @@ const App: React.FC<IApp> = ({ ssrTheme, ssrAuthenticated }) => {
const { error } = useSelector((state: StateType) => state.errors)
const { message, type } = useSelector((state: StateType) => state.alerts)
const accessToken = getAccessToken()
- const authenticated = isBrowser ? reduxAuthenticated : ssrAuthenticated
+ const authenticated = isBrowser
+ ? (loading ? !!accessToken : reduxAuthenticated)
+ : ssrAuthenticated
useEffect(() => {
(async () => {
- if (accessToken && !authenticated) {
+ if (accessToken && !reduxAuthenticated) {
try {
const me = await authMe()
dispatch(authActions.loginSuccessful(me))
- dispatch(authActions.finishLoading())
} catch (e) {
dispatch(authActions.logout())
dispatch(sagaActions.logout(false, false))
}
}
+
+ dispatch(authActions.finishLoading())
})()
- }, [authenticated]) // eslint-disable-line
+ }, [reduxAuthenticated]) // eslint-disable-line
useEffect(() => {
if (error) {
@@ -133,27 +136,23 @@ const App: React.FC<IApp> = ({ ssrTheme, ssrAuthenticated }) => {
const isMinimalFooter = _some(minimalFooterPages, (page) => _includes(pathname, page))
- if (!accessToken || !loading) {
- return (
- // eslint-disable-next-line react/jsx-no-useless-fragment
- <Suspense fallback={<></>}>
- {pathname !== routesPath.main && (
- <Header ssrTheme={ssrTheme} ssrAuthenticated={ssrAuthenticated} />
- )}
- {/* @ts-ignore */}
- <ScrollToTop>
- <Selfhosted>
- <Suspense fallback={<Fallback isMinimalFooter={isMinimalFooter} />}>
- <Outlet />
- </Suspense>
- </Selfhosted>
- </ScrollToTop>
- <Footer minimal={isMinimalFooter} authenticated={authenticated} />
- </Suspense>
- )
- }
-
- return null
+ return (
+ // eslint-disable-next-line react/jsx-no-useless-fragment
+ <Suspense fallback={<></>}>
+ {pathname !== routesPath.main && (
+ <Header ssrTheme={ssrTheme} authenticated={authenticated} />
+ )}
+ {/* @ts-ignore */}
+ <ScrollToTop>
+ <Selfhosted>
+ <Suspense fallback={<Fallback isMinimalFooter={isMinimalFooter} />}>
+ <Outlet />
+ </Suspense>
+ </Selfhosted>
+ </ScrollToTop>
+ <Footer minimal={isMinimalFooter} authenticated={authenticated} />
+ </Suspense>
+ )
}
export default App
diff --git a/app/components/Header/index.tsx b/app/components/Header/index.tsx
index 41bd6e8a1..1f8e90875 100644
--- a/app/components/Header/index.tsx
+++ b/app/components/Header/index.tsx
@@ -573,10 +573,10 @@ const NotAuthedHeader = ({
interface IHeader {
ssrTheme: 'dark' | 'light'
- ssrAuthenticated: boolean
+ authenticated: boolean
}
-const Header: React.FC<IHeader> = ({ ssrTheme, ssrAuthenticated }): JSX.Element => {
+const Header: React.FC<IHeader> = ({ ssrTheme, authenticated }): JSX.Element => {
const { t, i18n: { language } }: {
t: (key: string, options?: {
[key: string]: string | number | null
@@ -585,13 +585,12 @@ const Header: React.FC<IHeader> = ({ ssrTheme, ssrAuthenticated }): JSX.Element
} = useTranslation('common')
const dispatch = useAppDispatch()
const _dispatch = useDispatch()
- const { authenticated: reduxAuthenticated, user } = useSelector((state: StateType) => state.auth)
+ const { user } = useSelector((state: StateType) => state.auth)
const reduxTheme = useSelector((state: StateType) => state.ui.theme.theme)
const { pathname } = useLocation()
// @ts-ignore
const buttonRef: MutableRefObject<HTMLButtonElement> = useRef<HTMLButtonElement>()
const theme = isBrowser ? reduxTheme : ssrTheme
- const authenticated = isBrowser ? reduxAuthenticated : ssrAuthenticated
const [rawStatus, status] = useMemo(() => {
const { trialEndDate } = (user || {})
diff --git a/app/hoc/protected.tsx b/app/hoc/protected.tsx
index 5d44cd940..b7621a3de 100644
--- a/app/hoc/protected.tsx
+++ b/app/hoc/protected.tsx
@@ -2,11 +2,12 @@ import React, { useEffect } from 'react'
import { useSelector } from 'react-redux'
import { useNavigate } from '@remix-run/react'
+import { getAccessToken } from 'utils/accessToken'
import { StateType } from 'redux/store'
import routes from 'routesPath'
type AuthParamType = {
- selector: (state: StateType) => boolean,
+ shouldBeAuthenticated: boolean
redirectPath: string
}
@@ -16,27 +17,36 @@ type PropsType = {
export const auth = {
authenticated: {
- selector: (state: StateType) => state.auth.authenticated,
+ shouldBeAuthenticated: true,
redirectPath: routes.signin,
},
notAuthenticated: {
- selector: (state: StateType) => !state.auth.authenticated,
+ shouldBeAuthenticated: false,
redirectPath: routes.dashboard,
},
}
export const withAuthentication = <P extends PropsType>(WrappedComponent: any, authParam: AuthParamType) => {
+ const accessToken = getAccessToken()
+
const WithAuthentication = (props: P) => {
- const selector = useSelector(authParam.selector)
+ const {
+ shouldBeAuthenticated, redirectPath,
+ } = authParam
+ const {
+ authenticated: reduxAuthenticated,
+ loading,
+ } = useSelector((state: StateType) => state.auth)
const navigate = useNavigate()
+ const authenticated = loading ? !!accessToken : reduxAuthenticated
useEffect(() => {
- if (!selector) {
- navigate(authParam.redirectPath)
+ if (shouldBeAuthenticated !== authenticated) {
+ navigate(redirectPath)
}
// TODO: Investigate this later. https://github.com/remix-run/react-router/discussions/8465
// eslint-disable-next-line react-hooks/exhaustive-deps
- }, [selector])
+ }, [authenticated, shouldBeAuthenticated])
// if (!selector) {
// return null
diff --git a/app/pages/Billing/index.tsx b/app/pages/Billing/index.tsx
index 9e3ec6d7d..2a12108ea 100644
--- a/app/pages/Billing/index.tsx
+++ b/app/pages/Billing/index.tsx
@@ -15,6 +15,7 @@ import {
isSelfhosted, PADDLE_JS_URL, PADDLE_VENDOR_ID, CONTACT_EMAIL, paddleLanguageMapping, isBrowser,
} from 'redux/constants'
import { loadScript } from 'utils/generic'
+import Loader from 'ui/Loader'
import { useAppDispatch, StateType } from 'redux/store'
import routes from 'routesPath'
import sagaActions from 'redux/sagas/actions'
@@ -34,8 +35,8 @@ interface IBilling {
const Billing: React.FC<IBilling> = ({ ssrAuthenticated }): JSX.Element => {
const [isCancelSubModalOpened, setIsCancelSubModalOpened] = useState<boolean>(false)
const { metainfo, usageinfo } = useSelector((state: StateType) => state.ui.misc)
- const { user }: {
- user: IUser
+ const { user, loading }: {
+ user: IUser, loading: boolean,
} = useSelector((state: StateType) => state.auth)
const { theme } = useSelector((state: StateType) => state.ui.theme)
const paddleLoaded = useSelector((state: StateType) => state.ui.misc.paddleLoaded)
@@ -179,7 +180,7 @@ const Billing: React.FC<IBilling> = ({ ssrAuthenticated }): JSX.Element => {
}
return (
- <div className='bg-gray-50 dark:bg-slate-900'>
+ <div className='bg-gray-50 dark:bg-slate-900 min-h-page'>
<div className='w-11/12 md:w-4/5 mx-auto pb-16 pt-12 px-4 sm:px-6 lg:px-8 whitespace-pre-line'>
<div className='flex justify-between flex-wrap gap-y-2 mb-4'>
<h1 className='text-4xl font-extrabold text-gray-900 dark:text-gray-50 tracking-tight mr-2'>
@@ -246,53 +247,59 @@ const Billing: React.FC<IBilling> = ({ ssrAuthenticated }): JSX.Element => {
</span>
</div>
)}
- <Pricing authenticated={authenticated} t={t} language={language} />
- <p className='text-lg text-gray-900 dark:text-gray-50 tracking-tight mt-10'>
- <Trans
- // @ts-ignore
- t={t}
- i18nKey='billing.contact'
- values={{ email: CONTACT_EMAIL }}
- // @ts-ignore
- components={{
- mail: <a title={`Email us at ${CONTACT_EMAIL}`} href={`mailto:${CONTACT_EMAIL}`} className='font-medium text-indigo-600 hover:text-indigo-500 dark:text-indigo-400' />,
- amount: 5,
- }}
- />
- </p>
- <h2 id='usage' className='mt-5 text-3xl font-bold text-gray-900 dark:text-gray-50 tracking-tight mr-2'>
- {t('billing.planUsage')}
- </h2>
- <p className='mt-1 text-lg text-gray-900 dark:text-gray-50 tracking-tight'>
- {t('billing.usageOverview', {
- tracked: usageinfo.total,
- trackedPerc: totalUsage,
- maxEvents: maxEventsCount,
- })}
- </p>
- <div className='mt-2 text-lg text-gray-900 dark:text-gray-50 tracking-tight'>
- {t('billing.breakdown')}
- <ul className='list-disc list-inside'>
- <li>
- {t('billing.pageviews', {
- quantity: usageinfo.traffic,
- percentage: usageinfo.trafficPerc,
- })}
- </li>
- <li>
- {t('billing.customEvents', {
- quantity: usageinfo.customEvents,
- percentage: usageinfo.customEventsPerc,
+ {loading ? (
+ <Loader />
+ ) : (
+ <>
+ <Pricing authenticated={authenticated} t={t} language={language} />
+ <p className='text-lg text-gray-900 dark:text-gray-50 tracking-tight mt-10'>
+ <Trans
+ // @ts-ignore
+ t={t}
+ i18nKey='billing.contact'
+ values={{ email: CONTACT_EMAIL }}
+ // @ts-ignore
+ components={{
+ mail: <a title={`Email us at ${CONTACT_EMAIL}`} href={`mailto:${CONTACT_EMAIL}`} className='font-medium text-indigo-600 hover:text-indigo-500 dark:text-indigo-400' />,
+ amount: 5,
+ }}
+ />
+ </p>
+ <h2 id='usage' className='mt-5 text-3xl font-bold text-gray-900 dark:text-gray-50 tracking-tight mr-2'>
+ {t('billing.planUsage')}
+ </h2>
+ <p className='mt-1 text-lg text-gray-900 dark:text-gray-50 tracking-tight'>
+ {t('billing.usageOverview', {
+ tracked: usageinfo.total,
+ trackedPerc: totalUsage,
+ maxEvents: maxEventsCount,
})}
- </li>
- <li>
- {t('billing.captcha', {
- quantity: usageinfo.captcha,
- percentage: usageinfo.captchaPerc,
- })}
- </li>
- </ul>
- </div>
+ </p>
+ <div className='mt-2 text-lg text-gray-900 dark:text-gray-50 tracking-tight'>
+ {t('billing.breakdown')}
+ <ul className='list-disc list-inside'>
+ <li>
+ {t('billing.pageviews', {
+ quantity: usageinfo.traffic,
+ percentage: usageinfo.trafficPerc,
+ })}
+ </li>
+ <li>
+ {t('billing.customEvents', {
+ quantity: usageinfo.customEvents,
+ percentage: usageinfo.customEventsPerc,
+ })}
+ </li>
+ <li>
+ {t('billing.captcha', {
+ quantity: usageinfo.captcha,
+ percentage: usageinfo.captchaPerc,
+ })}
+ </li>
+ </ul>
+ </div>
+ </>
+ )}
</div>
<Modal
onClose={() => {
diff --git a/app/pages/Captcha/Settings/CaptchaSettings.container.tsx b/app/pages/Captcha/Settings/CaptchaSettings.container.tsx
index ee292e355..59e52deea 100644
--- a/app/pages/Captcha/Settings/CaptchaSettings.container.tsx
+++ b/app/pages/Captcha/Settings/CaptchaSettings.container.tsx
@@ -10,6 +10,7 @@ const mapStateToProps = (state: StateType) => ({
projects: state.ui.projects.captchaProjects,
analyticsProjects: state.ui.projects.projects,
isLoading: state.ui.projects.isLoadingCaptcha,
+ loading: state.auth.loading,
user: state.auth.user,
})
diff --git a/app/pages/Captcha/Settings/CaptchaSettings.tsx b/app/pages/Captcha/Settings/CaptchaSettings.tsx
index 77c2f483b..4eaa0f80b 100644
--- a/app/pages/Captcha/Settings/CaptchaSettings.tsx
+++ b/app/pages/Captcha/Settings/CaptchaSettings.tsx
@@ -25,6 +25,7 @@ import {
createProject, updateProject, deleteCaptchaProject, resetCaptchaProject, reGenerateCaptchaSecretKey, getProjectsNames, createCaptchaInherited,
} from 'api'
import Input from 'ui/Input'
+import Loader from 'ui/Loader'
import Button from 'ui/Button'
import Checkbox from 'ui/Checkbox'
import Modal from 'ui/Modal'
@@ -58,11 +59,7 @@ interface IForm extends Partial<ICaptchaProject> {
ipBlacklist?: string | null | string[]
}
-const CaptchaSettings = ({
- updateProjectFailed, createNewProjectFailed, newProject, projectDeleted, deleteProjectFailed,
- loadProjects, isLoading, projects, showError, removeProject, user,
- deleteProjectCache, analyticsProjects,
-}: {
+interface ICaptchaSettings {
updateProjectFailed: (error: string) => void,
createNewProjectFailed: (error: string) => void,
newProject: (message: string) => void,
@@ -76,7 +73,14 @@ const CaptchaSettings = ({
user: IUser,
deleteProjectCache: (pid: string) => void,
analyticsProjects: IProject[],
-}): JSX.Element => {
+ loading: boolean,
+}
+
+const CaptchaSettings = ({
+ updateProjectFailed, createNewProjectFailed, newProject, projectDeleted, deleteProjectFailed,
+ loadProjects, isLoading, projects, showError, removeProject, user,
+ deleteProjectCache, analyticsProjects, loading,
+}: ICaptchaSettings): JSX.Element => {
const { t }: {
t: (key: string, options?: {
[key: string]: string | number | boolean | undefined
@@ -118,6 +122,10 @@ const CaptchaSettings = ({
const copyTimerRef = useRef<HTMLDivElement>(null)
useEffect(() => {
+ if (loading) {
+ return
+ }
+
if (!user.isActive && !isSelfhosted) {
showError(t('project.captcha.settings.verify'))
navigate(routes.dashboard)
@@ -135,7 +143,7 @@ const CaptchaSettings = ({
})
}
}
- }, [user, project, isLoading, isSettings, navigate, showError, projectDeleting, t])
+ }, [user, project, isLoading, isSettings, navigate, showError, projectDeleting, t, loading])
const onSubmit = async (data: IForm) => {
if (!projectSaving) {
@@ -335,6 +343,10 @@ const CaptchaSettings = ({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [tab])
+ if (loading) {
+ return <Loader />
+ }
+
return (
<div
className={cx('min-h-min-footer bg-gray-50 dark:bg-slate-900 flex flex-col py-6 px-4 sm:px-6 lg:px-8', {
diff --git a/app/pages/MainPage/index.tsx b/app/pages/MainPage/index.tsx
index f8dc0c3f0..c9e8215e7 100644
--- a/app/pages/MainPage/index.tsx
+++ b/app/pages/MainPage/index.tsx
@@ -16,6 +16,7 @@ import _reduce from 'lodash/reduce'
import _isEmpty from 'lodash/isEmpty'
import routesPath from 'routesPath'
+import { getAccessToken } from 'utils/accessToken'
import { nFormatterSeparated } from 'utils/generic'
import {
GITHUB_URL, MARKETPLACE_URL, LIVE_DEMO_URL, isBrowser, BLOG_URL,
@@ -153,10 +154,16 @@ const Main: React.FC<IMain> = ({ ssrTheme, ssrAuthenticated }): JSX.Element => {
},
} = useTranslation('common')
const reduxTheme = useSelector((state: StateType) => state.ui.theme.theme)
- const reduxAuthenticated = useSelector((state: StateType) => state.auth.authenticated)
+ const {
+ authenticated: reduxAuthenticated,
+ loading,
+ } = useSelector((state: StateType) => state.auth)
const { stats, lastBlogPost } = useSelector((state: StateType) => state.ui.misc)
const theme = isBrowser ? reduxTheme : ssrTheme
- const authenticated = isBrowser ? reduxAuthenticated : ssrAuthenticated
+ const accessToken = getAccessToken()
+ const authenticated = isBrowser
+ ? (loading ? !!accessToken : reduxAuthenticated)
+ : ssrAuthenticated
const events = nFormatterSeparated(Number(stats.events))
const users = nFormatterSeparated(Number(stats.users))
@@ -203,7 +210,7 @@ const Main: React.FC<IMain> = ({ ssrTheme, ssrAuthenticated }): JSX.Element => {
}}
/>
</div>
- <Header ssrTheme={ssrTheme} ssrAuthenticated={ssrAuthenticated} />
+ <Header ssrTheme={ssrTheme} authenticated={authenticated} />
<div className='flex justify-center items-center py-2 px-2'>
<a
href='https://bank.gov.ua/en/news/all/natsionalniy-bank-vidkriv-spetsrahunok-dlya-zboru-koshtiv-na-potrebi-armiyi'
diff --git a/app/pages/Project/Settings/ProjectSettings.container.tsx b/app/pages/Project/Settings/ProjectSettings.container.tsx
index fa06c8e6b..bbe028065 100644
--- a/app/pages/Project/Settings/ProjectSettings.container.tsx
+++ b/app/pages/Project/Settings/ProjectSettings.container.tsx
@@ -12,6 +12,7 @@ const mapStateToProps = (state: StateType) => ({
projects: state.ui.projects.projects,
sharedProjects: state.ui.projects.sharedProjects,
isLoading: state.ui.projects.isLoading,
+ loading: state.auth.loading,
dashboardPaginationPage: state.ui.projects.dashboardPaginationPage,
dashboardPaginationPageShared: state.ui.projects.dashboardPaginationPageShared,
user: state.auth.user,
diff --git a/app/pages/Project/Settings/ProjectSettings.tsx b/app/pages/Project/Settings/ProjectSettings.tsx
index 828b8fe27..7c5f2fbac 100644
--- a/app/pages/Project/Settings/ProjectSettings.tsx
+++ b/app/pages/Project/Settings/ProjectSettings.tsx
@@ -32,6 +32,7 @@ import {
} from 'api'
import Input from 'ui/Input'
import Button from 'ui/Button'
+import Loader from 'ui/Loader'
import Checkbox from 'ui/Checkbox'
import Modal from 'ui/Modal'
import FlatPicker from 'ui/Flatpicker'
@@ -224,11 +225,7 @@ interface IForm extends Partial<IProject> {
const DEFAULT_PROJECT_NAME = 'Untitled Project'
-const ProjectSettings = ({
- updateProjectFailed, createNewProjectFailed, generateAlerts, projectDeleted, deleteProjectFailed,
- loadProjects, isLoading, projects, showError, removeProject, user, isSharedProject, sharedProjects,
- deleteProjectCache, setProjectProtectedPassword, dashboardPaginationPage, dashboardPaginationPageShared,
-}: {
+interface IProjectSettings {
updateProjectFailed: (message: string) => void,
createNewProjectFailed: (message: string) => void,
generateAlerts: (message: string) => void,
@@ -246,7 +243,14 @@ const ProjectSettings = ({
setProjectProtectedPassword: (pid: string, password: string) => void,
dashboardPaginationPage: number,
dashboardPaginationPageShared: number,
-}) => {
+ loading: boolean,
+}
+
+const ProjectSettings = ({
+ updateProjectFailed, createNewProjectFailed, generateAlerts, projectDeleted, deleteProjectFailed,
+ loadProjects, isLoading, projects, showError, removeProject, user, isSharedProject, sharedProjects,
+ deleteProjectCache, setProjectProtectedPassword, dashboardPaginationPage, dashboardPaginationPageShared, loading,
+}: IProjectSettings) => {
const { t, i18n: { language } }: {
t: (key: string, options?: {
[key: string]: string | number | null
@@ -297,6 +301,10 @@ const ProjectSettings = ({
const paginationSkip: number = isSharedProject ? dashboardPaginationPageShared * ENTRIES_PER_PAGE_DASHBOARD : dashboardPaginationPage * ENTRIES_PER_PAGE_DASHBOARD
useEffect(() => {
+ if (loading) {
+ return
+ }
+
if (!user.isActive && !isSelfhosted) {
showError(t('project.settings.verify'))
navigate(routes.dashboard)
@@ -314,7 +322,7 @@ const ProjectSettings = ({
})
}
}
- }, [user, project, isLoading, isSettings, navigate, showError, projectDeleting, t])
+ }, [user, project, isLoading, isSettings, navigate, showError, projectDeleting, t, loading])
const onSubmit = async (data: IForm) => {
if (!projectSaving) {
@@ -512,6 +520,10 @@ const ProjectSettings = ({
document.title = pageTitle
}, [form, t, isSettings])
+ if (loading) {
+ return <Loader />
+ }
+
return (
<div
className={cx('min-h-min-footer bg-gray-50 dark:bg-slate-900 flex flex-col py-6 px-4 sm:px-6 lg:px-8', {
diff --git a/app/pages/Project/View/Panels.tsx b/app/pages/Project/View/Panels.tsx
index f9f4398d9..1c7c04b99 100644
--- a/app/pages/Project/View/Panels.tsx
+++ b/app/pages/Project/View/Panels.tsx
@@ -228,7 +228,7 @@ const PanelContainer = ({
)
PanelContainer.propTypes = {
- name: PropTypes.oneOf([
+ name: PropTypes.oneOfType([
PropTypes.string, PropTypes.node,
]).isRequired,
children: PropTypes.node.isRequired,
@@ -1195,10 +1195,13 @@ const Panel = ({
}
Panel.propTypes = {
- name: PropTypes.oneOf([
+ name: PropTypes.oneOfType([
PropTypes.string.isRequired, PropTypes.node,
]).isRequired,
- data: PropTypes.objectOf(PropTypes.number).isRequired,
+ data: PropTypes.arrayOf(PropTypes.shape({
+ name: PropTypes.string,
+ count: PropTypes.number,
+ })).isRequired,
id: PropTypes.string,
rowMapper: PropTypes.func,
valueMapper: PropTypes.func,
diff --git a/app/pages/UserSettings/UserSettings.container.tsx b/app/pages/UserSettings/UserSettings.container.tsx
index 3a8d2e179..06759f618 100644
--- a/app/pages/UserSettings/UserSettings.container.tsx
+++ b/app/pages/UserSettings/UserSettings.container.tsx
@@ -17,6 +17,7 @@ const mapStateToProps = (state: StateType) => {
dontRemember: state.auth.dontRemember,
isPaidTierUsed: state.auth.isPaidTierUsed,
theme: state.ui.theme.theme,
+ loading: state.auth.loading,
}
}
diff --git a/app/pages/UserSettings/UserSettings.tsx b/app/pages/UserSettings/UserSettings.tsx
index 98b2a80c7..f2ff1c1b4 100644
--- a/app/pages/UserSettings/UserSettings.tsx
+++ b/app/pages/UserSettings/UserSettings.tsx
@@ -3,6 +3,7 @@ import React, {
useState, useEffect, memo, useRef,
} from 'react'
import { useNavigate } from '@remix-run/react'
+import { ClientOnly } from 'remix-utils'
import { useTranslation } from 'react-i18next'
import _size from 'lodash/size'
import _isEmpty from 'lodash/isEmpty'
@@ -44,6 +45,7 @@ import Select from 'ui/Select'
import Checkbox from 'ui/Checkbox'
import PaidFeature from 'modals/PaidFeature'
import TimezonePicker from 'ui/TimezonePicker'
+import Loader from 'ui/Loader'
import {
isValidEmail,
isValidPassword,
@@ -93,6 +95,7 @@ interface IProps {
theme: string,
updateShowLiveVisitorsInTitle: (show: boolean, callback: (isSuccess: boolean) => void) => void,
logoutAll: () => void,
+ loading: boolean,
}
interface IForm extends Partial<IUser> {
@@ -106,7 +109,7 @@ const UserSettings = ({
setProjectsShareData, userSharedUpdate, sharedProjectError, updateUserData,
genericError, onGDPRExportFailed, updateProfileFailed, updateUserProfileAsync,
accountUpdated, setAPIKey, user, dontRemember, isPaidTierUsed, // setThemeType, themeType,
- linkSSO, unlinkSSO, theme, updateShowLiveVisitorsInTitle, logoutAll,
+ linkSSO, unlinkSSO, theme, updateShowLiveVisitorsInTitle, logoutAll, loading,
}: IProps): JSX.Element => {
const navigate = useNavigate()
const {
@@ -135,6 +138,7 @@ const UserSettings = ({
const [reportFrequency, setReportFrequency] = useState<string>(
user.reportFrequency,
)
+ const [formPresetted, setFormPresetted] = useState<boolean>(false)
const [validated, setValidated] = useState<boolean>(false)
const [errors, setErrors] = useState<{
[key: string]: string;
@@ -199,6 +203,19 @@ const UserSettings = ({
}
}, [])
+ useEffect(() => {
+ if (!loading && !formPresetted) {
+ setForm(prev => ({
+ ...prev,
+ email: user.email || '',
+ timeFormat: user.timeFormat || TimeFormat['12-hour'],
+ }))
+ setTimezone(user.timezone || DEFAULT_TIMEZONE)
+ setReportFrequency(user.reportFrequency)
+ setFormPresetted(true)
+ }
+ }, [loading, user, formPresetted])
+
const _setTimezone = (value: string) => {
setTimezoneChanged(true)
setTimezone(value)
@@ -448,379 +465,395 @@ const UserSettings = ({
<h3 className='mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>
{t('profileSettings.general')}
</h3>
- <Input
- name='email'
- id='email'
- type='email'
- label={t('auth.common.email')}
- value={form.email}
- placeholder='[email protected]'
- className='mt-4'
- onChange={handleInput}
- error={beenSubmitted ? errors.email : null}
- disabled={isSelfhosted}
- />
- {!isSelfhosted && (
- <>
- <span
- onClick={toggleShowPasswordFields}
- className='flex items-center cursor-pointer max-w-max text-gray-900 dark:text-gray-50 hover:underline'
- >
- {t('auth.common.changePassword')}
- <ChevronDownIcon
- className={cx('w-4 h-4 ml-2', {
- 'rotate-180': showPasswordFields,
- })}
- />
- </span>
- {showPasswordFields && (
- <div className='grid grid-cols-1 gap-y-6 gap-x-4 sm:grid-cols-6 mt-4'>
- <Input
- name='password'
- id='password'
- type='password'
- label={t('auth.common.password')}
- hint={t('auth.common.hint', { amount: MIN_PASSWORD_CHARS })}
- value={form.password}
- placeholder={t('auth.common.password')}
- className='sm:col-span-3'
- onChange={handleInput}
- error={beenSubmitted ? errors.password : null}
- />
+ <ClientOnly
+ fallback={(
+ <Loader />
+ )}
+ >
+ {() => {
+ if (loading) {
+ return <Loader />
+ }
+
+ return (
+ <>
<Input
- name='repeat'
- id='repeat'
- type='password'
- label={t('auth.common.repeat')}
- value={form.repeat}
- placeholder={t('auth.common.repeat')}
- className='sm:col-span-3'
+ name='email'
+ id='email'
+ type='email'
+ label={t('auth.common.email')}
+ value={form.email}
+ placeholder='[email protected]'
+ className='mt-4'
onChange={handleInput}
- error={beenSubmitted ? errors.repeat : null}
+ error={beenSubmitted ? errors.email : null}
+ disabled={isSelfhosted}
/>
- </div>
- )}
- <Button className='mt-4' type='submit' primary large>
- {t('profileSettings.update')}
- </Button>
- </>
- )}
- {/* Theme type switch */}
- {/* <hr className='mt-5 border-gray-200 dark:border-gray-600' />
- <h3 className='flex items-center mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>
- {t('profileSettings.theme')}
- </h3>
- <div className='grid grid-cols-1 gap-y-6 gap-x-4 lg:grid-cols-2 mt-2 mb-4'>
- <div>
- <Select
- title={themeType}
- label={t('profileSettings.selectTheme')}
- className='w-full'
- items={[THEME_TYPE.classic, THEME_TYPE.christmas]}
- onSelect={(f) => setAsyncThemeType(f)}
- />
- </div>
- </div> */}
- {/* Timezone selector */}
- <hr className='mt-5 border-gray-200 dark:border-gray-600' />
- <h3 className='mt-2 text-lg font-bold text-gray-900 dark:text-gray-50 flex items-center'>
- {t('profileSettings.timezone')}
- <div className='ml-5'>
- <Beta />
- </div>
- </h3>
- <div className='grid grid-cols-1 gap-y-6 gap-x-4 lg:grid-cols-2 mt-4'>
- <div>
- <TimezonePicker value={timezone} onChange={_setTimezone} />
- </div>
- </div>
- <Button className='mt-4' onClick={handleTimezoneSave} primary large>
- {t('common.save')}
- </Button>
- {/* Timeformat selector (12 / 24 hour format) */}
- <hr className='mt-5 border-gray-200 dark:border-gray-600' />
- <h3 className='mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>
- {t('profileSettings.timeFormat')}
- </h3>
- <div className='grid grid-cols-1 gap-y-6 gap-x-4 lg:grid-cols-2 mt-4'>
- <div>
- <Select
- title={t(`profileSettings.${form.timeFormat}`)}
- label={t('profileSettings.selectTimeFormat')}
- className='w-full'
- items={translatedTimeFormat}
- onSelect={(f) => setForm((prev) => ({
- ...prev,
- timeFormat:
- timeFormatArray[
- _findIndex(translatedTimeFormat, (freq) => freq === f)
- ],
- }))}
- />
- </div>
- </div>
- <Button className='mt-4' onClick={setAsyncTimeFormat} primary large>
- {t('common.save')}
- </Button>
-
- {!isSelfhosted && (
- <>
- {/* Email reports frequency selector (e.g. monthly, weekly, etc.) */}
- <hr className='mt-5 border-gray-200 dark:border-gray-600' />
- <h3 className='mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>
- {t('profileSettings.email')}
- </h3>
- <div className='grid grid-cols-1 gap-y-6 gap-x-4 lg:grid-cols-2 mt-4'>
- <div>
- <Select
- title={t(`profileSettings.${reportFrequency}`)}
- label={t('profileSettings.frequency')}
- className='w-full'
- items={translatedFrequencies}
- iconExtractor={reportIconExtractor}
- onSelect={(f) => _setReportFrequency(
- reportFrequencies[_findIndex(translatedFrequencies, (freq) => freq === f)],
- )}
- />
- </div>
- </div>
- <Button className='mt-4' onClick={handleReportSave} primary large>
- {t('common.save')}
- </Button>
- </>
- )}
-
- {/* UI Settings */}
- <hr className='mt-5 border-gray-200 dark:border-gray-600' />
- <h3 className='mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>
- {t('profileSettings.uiSettings')}
- </h3>
- <Checkbox
- checked={user.showLiveVisitorsInTitle}
- onChange={handleShowLiveVisitorsSave}
- disabled={settingUpdating}
- name='active'
- id='active'
- className='mt-4'
- label={t('profileSettings.showVisitorsInTitle')}
- />
-
- {!isSelfhosted && (
- <>
- <hr className='mt-5 border-gray-200 dark:border-gray-600' />
- {/* Integrations setup */}
- <h3 id='integrations' className='flex items-center mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>
- {t('profileSettings.integrations')}
- </h3>
- <Integrations
- user={user}
- updateUserData={updateUserData}
- handleIntegrationSave={handleIntegrationSave}
- genericError={genericError}
- />
- <Checkbox
- checked={user.receiveLoginNotifications}
- onChange={handleReceiveLoginNotifications}
- disabled={settingUpdating}
- name='active'
- id='active'
- className='mt-4'
- label={t('profileSettings.receiveLoginNotifications')}
- />
- <hr className='mt-5 border-gray-200 dark:border-gray-600' />
-
- {/* API access setup */}
- <h3 className='flex items-center mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>
- {t('profileSettings.apiKey')}
- <div className='ml-5'>
- <Beta />
- </div>
- </h3>
- {user.apiKey ? (
- <>
- <p className='max-w-prose text-base text-gray-900 dark:text-gray-50'>
- {t('profileSettings.apiKeyWarning')}
- </p>
- <p className='mt-4 max-w-prose text-base text-gray-900 dark:text-gray-50'>
- {t('profileSettings.apiKey')}
- </p>
- <div className='grid grid-cols-1 gap-y-6 gap-x-4 lg:grid-cols-2'>
- <div className='relative group'>
- <Input
- name='apiKey'
- id='apiKey'
- type='text'
- className='pr-9'
- value={user.apiKey}
- onChange={handleInput}
- disabled
- />
- <div className='absolute right-2 top-3'>
- <div className='group relative'>
- <Button
- type='button'
- onClick={() => setToClipboard(user.apiKey || '')}
- className='opacity-70 hover:opacity-100'
- noBorder
- >
- <>
- <ClipboardDocumentIcon className='w-6 h-6' />
- {copied && (
- <div className='animate-appear bg-white dark:bg-slate-800 cursor-auto rounded p-1 absolute sm:top-0 top-0.5 right-8 text-xs text-green-600'>
- {t('common.copied')}
- </div>
- )}
- </>
- </Button>
+ {!isSelfhosted && (
+ <>
+ <span
+ onClick={toggleShowPasswordFields}
+ className='flex items-center cursor-pointer max-w-max text-gray-900 dark:text-gray-50 hover:underline'
+ >
+ {t('auth.common.changePassword')}
+ <ChevronDownIcon
+ className={cx('w-4 h-4 ml-2', {
+ 'rotate-180': showPasswordFields,
+ })}
+ />
+ </span>
+ {showPasswordFields && (
+ <div className='grid grid-cols-1 gap-y-6 gap-x-4 sm:grid-cols-6 mt-4'>
+ <Input
+ name='password'
+ id='password'
+ type='password'
+ label={t('auth.common.password')}
+ hint={t('auth.common.hint', { amount: MIN_PASSWORD_CHARS })}
+ value={form.password}
+ placeholder={t('auth.common.password')}
+ className='sm:col-span-3'
+ onChange={handleInput}
+ error={beenSubmitted ? errors.password : null}
+ />
+ <Input
+ name='repeat'
+ id='repeat'
+ type='password'
+ label={t('auth.common.repeat')}
+ value={form.repeat}
+ placeholder={t('auth.common.repeat')}
+ className='sm:col-span-3'
+ onChange={handleInput}
+ error={beenSubmitted ? errors.repeat : null}
+ />
</div>
- </div>
+ )}
+ <Button className='mt-4' type='submit' primary large>
+ {t('profileSettings.update')}
+ </Button>
+ </>
+ )}
+ {/* Theme type switch */}
+ {/* <hr className='mt-5 border-gray-200 dark:border-gray-600' />
+ <h3 className='flex items-center mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>
+ {t('profileSettings.theme')}
+ </h3>
+ <div className='grid grid-cols-1 gap-y-6 gap-x-4 lg:grid-cols-2 mt-2 mb-4'>
+ <div>
+ <Select
+ title={themeType}
+ label={t('profileSettings.selectTheme')}
+ className='w-full'
+ items={[THEME_TYPE.classic, THEME_TYPE.christmas]}
+ onSelect={(f) => setAsyncThemeType(f)}
+ />
+ </div>
+ </div> */}
+ {/* Timezone selector */}
+ <hr className='mt-5 border-gray-200 dark:border-gray-600' />
+ <h3 className='mt-2 text-lg font-bold text-gray-900 dark:text-gray-50 flex items-center'>
+ {t('profileSettings.timezone')}
+ <div className='ml-5'>
+ <Beta />
+ </div>
+ </h3>
+ <div className='grid grid-cols-1 gap-y-6 gap-x-4 lg:grid-cols-2 mt-4'>
+ <div>
+ <TimezonePicker value={timezone} onChange={_setTimezone} />
</div>
</div>
- </>
- ) : (
- <p className='max-w-prose text-base text-gray-900 dark:text-gray-50'>
- {t('profileSettings.noApiKey')}
- </p>
- )}
- {user.apiKey ? (
- <Button className='mt-4' onClick={() => setShowAPIDeleteModal(true)} danger large>
- {t('profileSettings.deleteApiKeyBtn')}
- </Button>
- ) : (
- <Button className='mt-4' onClick={onApiKeyGenerate} primary large>
- {t('profileSettings.addApiKeyBtn')}
- </Button>
- )}
-
- {/* 2FA setting */}
- <hr className='mt-5 border-gray-200 dark:border-gray-600' />
- <h3 className='flex items-center mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>
- {t('profileSettings.2fa')}
- </h3>
- <TwoFA
- user={user}
- dontRemember={dontRemember}
- updateUserData={updateUserData}
- genericError={genericError}
- />
-
- {/* Socialisations setup */}
- <hr className='mt-5 border-gray-200 dark:border-gray-600' />
- <h3 id='socialisations' className='flex items-center mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>
- {t('profileSettings.socialisations')}
- </h3>
- <Socialisations
- user={user}
- genericError={genericError}
- linkSSO={linkSSO}
- unlinkSSO={unlinkSSO}
- theme={theme}
- />
-
- {/* Shared projects setting */}
- <hr className='mt-5 border-gray-200 dark:border-gray-600' />
- <h3 className='flex items-center mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>
- {t('profileSettings.shared')}
- </h3>
- <div>
- {!_isEmpty(user.sharedProjects) ? (
- <div className='mt-3 flex flex-col'>
- <div className='-my-2 -mx-4 overflow-x-auto sm:-mx-6 lg:-mx-8'>
- <div className='inline-block min-w-full py-2 align-middle md:px-6 lg:px-8'>
- <div className='overflow-hidden shadow ring-1 ring-black ring-opacity-5 md:rounded-lg'>
- <table className='min-w-full divide-y divide-gray-300 dark:divide-gray-600'>
- <thead>
- <tr className='dark:bg-slate-800'>
- <th
- scope='col'
- className='py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 sm:pl-6 dark:text-white'
- >
- {t('profileSettings.sharedTable.project')}
- </th>
- <th
- scope='col'
- className='px-3 py-3.5 text-left text-sm font-semibold text-gray-900 dark:text-white'
- >
- {t('profileSettings.sharedTable.role')}
- </th>
- <th
- scope='col'
- className='px-3 py-3.5 text-left text-sm font-semibold text-gray-900 dark:text-white'
- >
- {t('profileSettings.sharedTable.joinedOn')}
- </th>
- <th scope='col' className='relative py-3.5 pl-3 pr-4 sm:pr-6' />
- </tr>
- </thead>
- <tbody className='divide-y divide-gray-300 dark:divide-gray-600'>
- {_map(user.sharedProjects, (item) => (
- <ProjectList
- key={item.id}
- item={item}
- removeProject={removeProject}
- removeShareProject={removeShareProject}
- setUserShareData={setUserShareData}
- setProjectsShareData={setProjectsShareData}
- userSharedUpdate={userSharedUpdate}
- sharedProjectError={sharedProjectError}
- />
- ))}
- </tbody>
- </table>
- </div>
- </div>
+ <Button className='mt-4' onClick={handleTimezoneSave} primary large>
+ {t('common.save')}
+ </Button>
+ {/* Timeformat selector (12 / 24 hour format) */}
+ <hr className='mt-5 border-gray-200 dark:border-gray-600' />
+ <h3 className='mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>
+ {t('profileSettings.timeFormat')}
+ </h3>
+ <div className='grid grid-cols-1 gap-y-6 gap-x-4 lg:grid-cols-2 mt-4'>
+ <div>
+ <Select
+ title={t(`profileSettings.${form.timeFormat}`)}
+ label={t('profileSettings.selectTimeFormat')}
+ className='w-full'
+ items={translatedTimeFormat}
+ onSelect={(f) => setForm((prev) => ({
+ ...prev,
+ timeFormat:
+ timeFormatArray[
+ _findIndex(translatedTimeFormat, (freq) => freq === f)
+ ],
+ }))}
+ />
</div>
</div>
- ) : (
- <NoSharedProjects t={t} />
- )}
- </div>
- <hr className='mt-5 border-gray-200 dark:border-gray-600' />
- {!user.isActive && (
- <div
- className='flex cursor-pointer mt-4 pl-0 underline text-blue-600 hover:text-indigo-800 dark:hover:text-indigo-600'
- onClick={() => onEmailConfirm(setError)}
- >
- <EnvelopeIcon className='mt-0.5 mr-2 w-6 h-6 text-blue-500' />
- {t('profileSettings.noLink')}
- </div>
- )}
- <div className='flex flex-wrap justify-center sm:justify-between gap-2 mt-4'>
- <Button onClick={() => setShowExportModal(true)} semiSmall primary>
- <>
- <ArrowDownTrayIcon className='w-5 h-5 mr-1' />
- {t('profileSettings.requestExport')}
- </>
- </Button>
- <Button
- className='ml-3'
- onClick={() => setShowModal(true)}
- semiSmall
- danger
- >
- <>
- <ExclamationTriangleIcon className='w-5 h-5 mr-1' />
- {t('profileSettings.delete')}
- </>
- </Button>
- <div className='flex justify-center flex-wrap gap-2'>
- <Button onClick={logoutAll} semiSmall semiDanger>
+ <Button className='mt-4' onClick={setAsyncTimeFormat} primary large>
+ {t('common.save')}
+ </Button>
+
+ {!isSelfhosted && (
<>
- {/* We need this div for the button to match the height of the button after it */}
- <div className='h-5' />
- {t('profileSettings.logoutAll')}
+ {/* Email reports frequency selector (e.g. monthly, weekly, etc.) */}
+ <hr className='mt-5 border-gray-200 dark:border-gray-600' />
+ <h3 className='mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>
+ {t('profileSettings.email')}
+ </h3>
+ <div className='grid grid-cols-1 gap-y-6 gap-x-4 lg:grid-cols-2 mt-4'>
+ <div>
+ <Select
+ title={t(`profileSettings.${reportFrequency}`)}
+ label={t('profileSettings.frequency')}
+ className='w-full'
+ items={translatedFrequencies}
+ iconExtractor={reportIconExtractor}
+ onSelect={(f) => _setReportFrequency(
+ reportFrequencies[_findIndex(translatedFrequencies, (freq) => freq === f)],
+ )}
+ />
+ </div>
+ </div>
+ <Button className='mt-4' onClick={handleReportSave} primary large>
+ {t('common.save')}
+ </Button>
</>
- </Button>
- <Button onClick={() => setShowModal(true)} semiSmall danger>
+ )}
+
+ {/* UI Settings */}
+ <hr className='mt-5 border-gray-200 dark:border-gray-600' />
+ <h3 className='mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>
+ {t('profileSettings.uiSettings')}
+ </h3>
+ <Checkbox
+ checked={user.showLiveVisitorsInTitle}
+ onChange={handleShowLiveVisitorsSave}
+ disabled={settingUpdating}
+ name='active'
+ id='active'
+ className='mt-4'
+ label={t('profileSettings.showVisitorsInTitle')}
+ />
+
+ {!isSelfhosted && (
<>
- <ExclamationTriangleIcon className='w-5 h-5 mr-1' />
- {t('profileSettings.delete')}
+ <hr className='mt-5 border-gray-200 dark:border-gray-600' />
+ {/* Integrations setup */}
+ <h3 id='integrations' className='flex items-center mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>
+ {t('profileSettings.integrations')}
+ </h3>
+ <Integrations
+ user={user}
+ updateUserData={updateUserData}
+ handleIntegrationSave={handleIntegrationSave}
+ genericError={genericError}
+ />
+ <Checkbox
+ checked={user.receiveLoginNotifications}
+ onChange={handleReceiveLoginNotifications}
+ disabled={settingUpdating}
+ name='active'
+ id='active'
+ className='mt-4'
+ label={t('profileSettings.receiveLoginNotifications')}
+ />
+ <hr className='mt-5 border-gray-200 dark:border-gray-600' />
+
+ {/* API access setup */}
+ <h3 className='flex items-center mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>
+ {t('profileSettings.apiKey')}
+ <div className='ml-5'>
+ <Beta />
+ </div>
+ </h3>
+ {user.apiKey ? (
+ <>
+ <p className='max-w-prose text-base text-gray-900 dark:text-gray-50'>
+ {t('profileSettings.apiKeyWarning')}
+ </p>
+ <p className='mt-4 max-w-prose text-base text-gray-900 dark:text-gray-50'>
+ {t('profileSettings.apiKey')}
+ </p>
+ <div className='grid grid-cols-1 gap-y-6 gap-x-4 lg:grid-cols-2'>
+ <div className='relative group'>
+ <Input
+ name='apiKey'
+ id='apiKey'
+ type='text'
+ className='pr-9'
+ value={user.apiKey}
+ onChange={handleInput}
+ disabled
+ />
+ <div className='absolute right-2 top-3'>
+ <div className='group relative'>
+ <Button
+ type='button'
+ onClick={() => setToClipboard(user.apiKey || '')}
+ className='opacity-70 hover:opacity-100'
+ noBorder
+ >
+ <>
+ <ClipboardDocumentIcon className='w-6 h-6' />
+ {copied && (
+ <div className='animate-appear bg-white dark:bg-slate-800 cursor-auto rounded p-1 absolute sm:top-0 top-0.5 right-8 text-xs text-green-600'>
+ {t('common.copied')}
+ </div>
+ )}
+ </>
+ </Button>
+ </div>
+ </div>
+ </div>
+ </div>
+ </>
+ ) : (
+ <p className='max-w-prose text-base text-gray-900 dark:text-gray-50'>
+ {t('profileSettings.noApiKey')}
+ </p>
+ )}
+ {user.apiKey ? (
+ <Button className='mt-4' onClick={() => setShowAPIDeleteModal(true)} danger large>
+ {t('profileSettings.deleteApiKeyBtn')}
+ </Button>
+ ) : (
+ <Button className='mt-4' onClick={onApiKeyGenerate} primary large>
+ {t('profileSettings.addApiKeyBtn')}
+ </Button>
+ )}
+
+ {/* 2FA setting */}
+ <hr className='mt-5 border-gray-200 dark:border-gray-600' />
+ <h3 className='flex items-center mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>
+ {t('profileSettings.2fa')}
+ </h3>
+ <TwoFA
+ user={user}
+ dontRemember={dontRemember}
+ updateUserData={updateUserData}
+ genericError={genericError}
+ />
+
+ {/* Socialisations setup */}
+ <hr className='mt-5 border-gray-200 dark:border-gray-600' />
+ <h3 id='socialisations' className='flex items-center mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>
+ {t('profileSettings.socialisations')}
+ </h3>
+ <Socialisations
+ user={user}
+ genericError={genericError}
+ linkSSO={linkSSO}
+ unlinkSSO={unlinkSSO}
+ theme={theme}
+ />
+
+ {/* Shared projects setting */}
+ <hr className='mt-5 border-gray-200 dark:border-gray-600' />
+ <h3 className='flex items-center mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>
+ {t('profileSettings.shared')}
+ </h3>
+ <div>
+ {!_isEmpty(user.sharedProjects) ? (
+ <div className='mt-3 flex flex-col'>
+ <div className='-my-2 -mx-4 overflow-x-auto sm:-mx-6 lg:-mx-8'>
+ <div className='inline-block min-w-full py-2 align-middle md:px-6 lg:px-8'>
+ <div className='overflow-hidden shadow ring-1 ring-black ring-opacity-5 md:rounded-lg'>
+ <table className='min-w-full divide-y divide-gray-300 dark:divide-gray-600'>
+ <thead>
+ <tr className='dark:bg-slate-800'>
+ <th
+ scope='col'
+ className='py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 sm:pl-6 dark:text-white'
+ >
+ {t('profileSettings.sharedTable.project')}
+ </th>
+ <th
+ scope='col'
+ className='px-3 py-3.5 text-left text-sm font-semibold text-gray-900 dark:text-white'
+ >
+ {t('profileSettings.sharedTable.role')}
+ </th>
+ <th
+ scope='col'
+ className='px-3 py-3.5 text-left text-sm font-semibold text-gray-900 dark:text-white'
+ >
+ {t('profileSettings.sharedTable.joinedOn')}
+ </th>
+ <th scope='col' className='relative py-3.5 pl-3 pr-4 sm:pr-6' />
+ </tr>
+ </thead>
+ <tbody className='divide-y divide-gray-300 dark:divide-gray-600'>
+ {_map(user.sharedProjects, (item) => (
+ <ProjectList
+ key={item.id}
+ item={item}
+ removeProject={removeProject}
+ removeShareProject={removeShareProject}
+ setUserShareData={setUserShareData}
+ setProjectsShareData={setProjectsShareData}
+ userSharedUpdate={userSharedUpdate}
+ sharedProjectError={sharedProjectError}
+ />
+ ))}
+ </tbody>
+ </table>
+ </div>
+ </div>
+ </div>
+ </div>
+ ) : (
+ <NoSharedProjects t={t} />
+ )}
+ </div>
+ <hr className='mt-5 border-gray-200 dark:border-gray-600' />
+ {!user.isActive && (
+ <div
+ className='flex cursor-pointer mt-4 pl-0 underline text-blue-600 hover:text-indigo-800 dark:hover:text-indigo-600'
+ onClick={() => onEmailConfirm(setError)}
+ >
+ <EnvelopeIcon className='mt-0.5 mr-2 w-6 h-6 text-blue-500' />
+ {t('profileSettings.noLink')}
+ </div>
+ )}
+ <div className='flex flex-wrap justify-center sm:justify-between gap-2 mt-4'>
+ <Button onClick={() => setShowExportModal(true)} semiSmall primary>
+ <>
+ <ArrowDownTrayIcon className='w-5 h-5 mr-1' />
+ {t('profileSettings.requestExport')}
+ </>
+ </Button>
+ <Button
+ className='ml-3'
+ onClick={() => setShowModal(true)}
+ semiSmall
+ danger
+ >
+ <>
+ <ExclamationTriangleIcon className='w-5 h-5 mr-1' />
+ {t('profileSettings.delete')}
+ </>
+ </Button>
+ <div className='flex justify-center flex-wrap gap-2'>
+ <Button onClick={logoutAll} semiSmall semiDanger>
+ <>
+ {/* We need this div for the button to match the height of the button after it */}
+ <div className='h-5' />
+ {t('profileSettings.logoutAll')}
+ </>
+ </Button>
+ <Button onClick={() => setShowModal(true)} semiSmall danger>
+ <>
+ <ExclamationTriangleIcon className='w-5 h-5 mr-1' />
+ {t('profileSettings.delete')}
+ </>
+ </Button>
+ </div>
+ </div>
</>
- </Button>
- </div>
- </div>
- </>
- )}
+ )}
+ </>
+ )
+ }}
+ </ClientOnly>
</form>
<PaidFeature
diff --git a/app/root.tsx b/app/root.tsx
index ff8f4a716..6cefe73e0 100644
--- a/app/root.tsx
+++ b/app/root.tsx
@@ -35,7 +35,9 @@ import { useChangeLanguage } from 'remix-i18next'
import { useTranslation } from 'react-i18next'
import AppWrapper from 'App'
import { detectLanguage } from 'i18n'
-import { detectTheme, getPageMeta, isAuthenticated } from 'utils/server'
+import {
+ detectTheme, getPageMeta, isAuthenticated,
+} from 'utils/server'
import mainCss from 'styles/index.css'
import tailwindCss from 'styles/tailwind.css'
@@ -92,17 +94,6 @@ export const headers: HeadersFunction = () => ({
'X-XSS-Protection': '1; mode=block',
})
-// const removeObsoleteAuthTokens = () => {
-// const accessToken = getAccessToken()
-// const refreshToken = getRefreshToken()
-
-// if (accessToken && !refreshToken) {
-// removeAccessToken()
-// }
-// }
-
-// removeObsoleteAuthTokens()
-
export function ErrorBoundary() {
const error = useRouteError()
const [crashStackShown, setCrashStackShown] = useState(false)
diff --git a/app/ui/Loader.tsx b/app/ui/Loader.tsx
index c2b47b4b5..1b725bc3d 100644
--- a/app/ui/Loader.tsx
+++ b/app/ui/Loader.tsx
@@ -3,7 +3,7 @@ import Spin from './icons/Spin'
const Loader = () => (
<div className='flex justify-center pt-10'>
- <Spin className='h-20 w-20 text-indigo-700' />
+ <Spin />
<span className='sr-only'>Loading...</span>
</div>
)
diff --git a/app/ui/icons/Spin.tsx b/app/ui/icons/Spin.tsx
index e6bb892cd..1bcd172ef 100644
--- a/app/ui/icons/Spin.tsx
+++ b/app/ui/icons/Spin.tsx
@@ -5,7 +5,7 @@ import PropTypes from 'prop-types'
const Spin = ({ className }: {
className?: string,
}): JSX.Element => (
- <svg className={cx('animate-spin -ml-1 mr-2 h-4 w-4 text-white', className)} xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24'>
+ <svg className={cx('animate-spin -ml-1 mr-2 h-4 w-4 text-slate-900 dark:text-white', className)} xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24'>
<circle className='opacity-25' cx='12' cy='12' r='10' stroke='currentColor' strokeWidth='4' />
<path className='opacity-75' fill='currentColor' d='M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z' />
</svg>
diff --git a/app/utils/server.ts b/app/utils/server.ts
index 217a8d6bc..9a07f5c5f 100644
--- a/app/utils/server.ts
+++ b/app/utils/server.ts
@@ -20,11 +20,15 @@ export function detectTheme(request: Request): 'dark' | 'light' {
return 'light'
}
-export function isAuthenticated(request: Request): boolean {
+export function getAccessToken(request: Request): string | null {
const cookie = request.headers.get('Cookie')
const accessToken = cookie?.match(/(?<=access_token=)[^;]*/)?.[0]
- return !!accessToken
+ return accessToken || null
+}
+
+export function isAuthenticated(request: Request): boolean {
+ return !!getAccessToken(request)
}
interface IPageMeta {