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!

Get rid of misc reducer

Blue Mouseff743ebe390f
diff --git a/web/app/App.tsx b/web/app/App.tsx
index c73ed0c44..5e4a78c66 100644
--- a/web/app/App.tsx
+++ b/web/app/App.tsx
@@ -13,14 +13,13 @@ import Footer from '~/components/Footer'
import Header from '~/components/Header'
import { isBrowser, isSelfhosted } from '~/lib/constants'
import { authActions } from '~/lib/reducers/auth'
-import UIActions from '~/lib/reducers/ui'
import { StateType, useAppDispatch } from '~/lib/store'
import { getAccessToken } from '~/utils/accessToken'
-import { logout, shouldShowLowEventsBanner } from '~/utils/auth'
+import { logout } from '~/utils/auth'
import routesPath from '~/utils/routes'
import { getPageMeta } from '~/utils/server'
-import { authMe, getGeneralStats, getInstalledExtensions, getLastPost, getPaymentMetainfo } from './api'
+import { authMe, getInstalledExtensions } from './api'
interface AppProps {
ssrTheme: 'dark' | 'light'
@@ -45,15 +44,11 @@ const App = ({ ssrTheme, ssrAuthenticated }: AppProps) => {
if (accessToken && !reduxAuthenticated) {
try {
const { user, totalMonthlyEvents } = await authMe()
- dispatch(authActions.authSuccessful(user))
-
- if (shouldShowLowEventsBanner(totalMonthlyEvents, user.maxEventsCount)) {
- dispatch(UIActions.setShowNoEventsLeftBanner(true))
- }
+ dispatch(authActions.authSuccessful({ ...user, totalMonthlyEvents }))
if (!isSelfhosted) {
const extensions = await getInstalledExtensions()
- dispatch(UIActions.setExtensions(extensions))
+ dispatch(authActions.setExtensions(extensions))
}
} catch (reason) {
dispatch(authActions.logout())
@@ -62,17 +57,6 @@ const App = ({ ssrTheme, ssrAuthenticated }: AppProps) => {
}
}
- if (!isSelfhosted) {
- const [metainfo, lastBlogPost, generalStats] = await Promise.all([
- getPaymentMetainfo(),
- getLastPost(),
- getGeneralStats(),
- ])
- dispatch(UIActions.setMetainfo(metainfo))
- dispatch(UIActions.setLastBlogPost(lastBlogPost))
- dispatch(UIActions.setGeneralStats(generalStats))
- }
-
dispatch(authActions.finishLoading())
})()
}, [reduxAuthenticated]) // eslint-disable-line
diff --git a/web/app/api/index.ts b/web/app/api/index.ts
index ffd3075bd..ecdf30603 100644
--- a/web/app/api/index.ts
+++ b/web/app/api/index.ts
@@ -1,4 +1,4 @@
-import axios, { AxiosResponse } from 'axios'
+import axios, { AxiosRequestConfig, AxiosResponse } from 'axios'
import createAuthRefreshInterceptor from 'axios-auth-refresh'
import _isArray from 'lodash/isArray'
import _isEmpty from 'lodash/isEmpty'
@@ -7,8 +7,10 @@ import _map from 'lodash/map'
import { DEFAULT_ALERTS_TAKE, API_URL } from '~/lib/constants'
import { Alerts } from '~/lib/models/Alerts'
import { Auth } from '~/lib/models/Auth'
+import { Metainfo } from '~/lib/models/Metainfo'
import { Role } from '~/lib/models/Organisation'
import { Project, Overall, LiveStats, Funnel } from '~/lib/models/Project'
+import { Stats } from '~/lib/models/Stats'
import { Subscriber } from '~/lib/models/Subscriber'
import { User, FeatureFlag } from '~/lib/models/User'
import { authActions } from '~/lib/reducers/auth'
@@ -888,7 +890,7 @@ export const getLiveVisitors = (pids: string[], password?: string): Promise<Live
export const getGeneralStats = () =>
api
.get('log/generalStats')
- .then((response) => response.data)
+ .then((response): Stats => response.data)
.catch((error) => {
throw _isEmpty(error.response.data?.message) ? error.response.data : error.response.data.message
})
@@ -1340,10 +1342,10 @@ export const checkPassword = (pid: string, password: string) =>
throw _isEmpty(error.response.data?.message) ? error.response.data : error.response.data.message
})
-export const getPaymentMetainfo = () =>
+export const getPaymentMetainfo = (config?: AxiosRequestConfig) =>
api
- .get('user/metainfo')
- .then((response) => response.data)
+ .get('user/metainfo', config)
+ .then((response): Metainfo => response.data)
.catch((error) => {
throw _isEmpty(error.response.data?.message) ? error.response.data : error.response.data.message
})
@@ -1452,9 +1454,9 @@ export const getBlogPostWithCategory = (category: string, slug: string) =>
throw error
})
-export const getLastPost = () =>
+export const getLastPost = (config?: AxiosRequestConfig) =>
api
- .get('v1/blog/last-post')
+ .get('v1/blog/last-post', config)
.then(
(
response,
diff --git a/web/app/components/EventsRunningOutBanner.tsx b/web/app/components/EventsRunningOutBanner.tsx
index e30a34756..6c6b6d8bf 100644
--- a/web/app/components/EventsRunningOutBanner.tsx
+++ b/web/app/components/EventsRunningOutBanner.tsx
@@ -1,25 +1,39 @@
import { ExclamationTriangleIcon, XMarkIcon } from '@heroicons/react/24/outline'
-import { memo, useState } from 'react'
+import { memo, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useSelector } from 'react-redux'
-import { SHOW_BANNER_AT_PERC } from '~/lib/constants'
-import UIActions from '~/lib/reducers/ui'
-import { useAppDispatch, StateType } from '~/lib/store'
+import { LOW_EVENTS_WARNING, SHOW_BANNER_AT_PERC } from '~/lib/constants'
+import { StateType } from '~/lib/store'
import Modal from '~/ui/Modal'
+import { shouldShowLowEventsBanner } from '~/utils/auth'
+import { setCookie } from '~/utils/cookie'
+import { secondsTillNextMonth } from '~/utils/generic'
const EventsRunningOutBanner = () => {
const { t } = useTranslation('common')
- const dispatch = useAppDispatch()
- const showNoEventsLeftBanner = useSelector((state: StateType) => state.ui.misc.showNoEventsLeftBanner)
- const dashboardBlockReason = useSelector((state: StateType) => state.auth.user.dashboardBlockReason)
+ const [shouldShowBanner, setShouldShowBanner] = useState(false)
+ const { dashboardBlockReason, totalMonthlyEvents, maxEventsCount } = useSelector(
+ (state: StateType) => state.auth.user,
+ )
const [showMoreInfoModal, setShowMoreInfoModal] = useState(false)
+ useEffect(() => {
+ if (!totalMonthlyEvents || !maxEventsCount) {
+ return
+ }
+
+ setShouldShowBanner(shouldShowLowEventsBanner(totalMonthlyEvents, maxEventsCount))
+ }, [totalMonthlyEvents, maxEventsCount])
+
const closeHandler = () => {
- dispatch(UIActions.setShowNoEventsLeftBanner(false))
+ setShouldShowBanner(false)
+
+ const maxAge = secondsTillNextMonth() + 86400
+ setCookie(LOW_EVENTS_WARNING, 1, maxAge)
}
- if (!showNoEventsLeftBanner || dashboardBlockReason) {
+ if (!shouldShowBanner || dashboardBlockReason) {
return null
}
diff --git a/web/app/components/marketing/Pricing.tsx b/web/app/components/marketing/Pricing.tsx
index b1e176c5e..34b1532cd 100644
--- a/web/app/components/marketing/Pricing.tsx
+++ b/web/app/components/marketing/Pricing.tsx
@@ -12,7 +12,7 @@ import { Link } from 'react-router'
import { ClientOnly } from 'remix-utils/client-only'
import { toast } from 'sonner'
-import { authMe, previewSubscriptionUpdate, changeSubscriptionPlan } from '~/api'
+import { authMe, previewSubscriptionUpdate, changeSubscriptionPlan, getPaymentMetainfo } from '~/api'
import {
CONTACT_EMAIL,
paddleLanguageMapping,
@@ -23,6 +23,7 @@ import {
STANDARD_PLANS,
TRIAL_DAYS,
} from '~/lib/constants'
+import { DEFAULT_METAINFO, Metainfo } from '~/lib/models/Metainfo'
import { authActions } from '~/lib/reducers/auth'
import { AppDispatch, StateType } from '~/lib/store'
import { Badge } from '~/ui/Badge'
@@ -49,9 +50,12 @@ const getPaidFeatures = (t: any, tier: any) => {
interface PricingProps {
authenticated: boolean
isBillingPage?: boolean
+ lastEvent?: {
+ event: string
+ } | null
}
-const Pricing = ({ authenticated, isBillingPage }: PricingProps) => {
+const Pricing = ({ authenticated, isBillingPage, lastEvent }: PricingProps) => {
const {
t,
i18n: { language },
@@ -59,8 +63,9 @@ const Pricing = ({ authenticated, isBillingPage }: PricingProps) => {
const dispatch = useDispatch<AppDispatch>()
const { user } = useSelector((state: StateType) => state.auth)
const { theme } = useSelector((state: StateType) => state.ui.theme)
- const { paddle, metainfo } = useSelector((state: StateType) => state.ui.misc)
- const { lastEvent } = paddle
+
+ const [metainfo, setMetainfo] = useState<Metainfo>(DEFAULT_METAINFO)
+
const currencyCode = user?.tierCurrency || metainfo.code
const [planCodeLoading, setPlanCodeLoading] = useState<string | null>(null)
@@ -96,6 +101,20 @@ const Pricing = ({ authenticated, isBillingPage }: PricingProps) => {
}
useEffect(() => {
+ const abortController = new AbortController()
+
+ getPaymentMetainfo({ signal: abortController.signal })
+ .then(setMetainfo)
+ .catch(() => {})
+
+ return () => abortController.abort()
+ }, [])
+
+ useEffect(() => {
+ if (!lastEvent) {
+ return
+ }
+
const lastEventHandler = async (data: { event: string }) => {
if (_isNil(data)) {
return
diff --git a/web/app/lib/models/Metainfo.ts b/web/app/lib/models/Metainfo.ts
index 8fe6f0087..d561db4ef 100644
--- a/web/app/lib/models/Metainfo.ts
+++ b/web/app/lib/models/Metainfo.ts
@@ -5,3 +5,11 @@ export interface Metainfo {
symbol: string
code: 'USD' | 'EUR' | 'GBP'
}
+
+export const DEFAULT_METAINFO: Metainfo = {
+ country: null,
+ region: null,
+ city: null,
+ symbol: '$',
+ code: 'USD',
+}
diff --git a/web/app/lib/models/User.ts b/web/app/lib/models/User.ts
index 99082be30..8664c5e99 100644
--- a/web/app/lib/models/User.ts
+++ b/web/app/lib/models/User.ts
@@ -75,4 +75,7 @@ export interface User {
dashboardBlockReason: DashboardBlockReason
isAccountBillingSuspended: boolean
organisationMemberships: OrganisationMembership[]
+
+ // Does not come from User directly; we need it for the EventsRunningOutBanner
+ totalMonthlyEvents: number
}
diff --git a/web/app/lib/reducers/auth.ts b/web/app/lib/reducers/auth.ts
index 4367d3761..afece4ff8 100644
--- a/web/app/lib/reducers/auth.ts
+++ b/web/app/lib/reducers/auth.ts
@@ -7,6 +7,7 @@ interface AuthState {
authenticated: boolean
loading: boolean
dontRemember: boolean
+ extensions: any[]
}
const initialState: AuthState = {
@@ -14,6 +15,9 @@ const initialState: AuthState = {
authenticated: false,
loading: true,
dontRemember: false,
+
+ // TODO: Only load extensions per project; migrate this to useCurrentProject
+ extensions: [],
}
const authSlice = createSlice({
@@ -40,6 +44,9 @@ const authSlice = createSlice({
setUser: (state, { payload }: PayloadAction<User>) => {
state.user = payload
},
+ setExtensions(state, { payload }: PayloadAction<any[]>) {
+ state.extensions = payload
+ },
},
})
diff --git a/web/app/lib/reducers/ui/index.ts b/web/app/lib/reducers/ui/index.ts
index 84cd1bcda..54549f6dd 100644
--- a/web/app/lib/reducers/ui/index.ts
+++ b/web/app/lib/reducers/ui/index.ts
@@ -1,8 +1,6 @@
-import { miscActions } from './misc'
import { themeActions } from './theme'
const UIActions = {
- ...miscActions,
...themeActions,
}
diff --git a/web/app/lib/reducers/ui/misc.ts b/web/app/lib/reducers/ui/misc.ts
deleted file mode 100644
index fc24b9807..000000000
--- a/web/app/lib/reducers/ui/misc.ts
+++ /dev/null
@@ -1,69 +0,0 @@
-import { createSlice, PayloadAction } from '@reduxjs/toolkit'
-
-import { LOW_EVENTS_WARNING } from '~/lib/constants'
-import { Metainfo } from '~/lib/models/Metainfo'
-import { Stats } from '~/lib/models/Stats'
-import { setCookie } from '~/utils/cookie'
-import { secondsTillNextMonth } from '~/utils/generic'
-
-interface InitialState {
- stats: Stats
- metainfo: Metainfo
- paddle: any
- showNoEventsLeftBanner: boolean
- lastBlogPost: any
- extensions: any[]
-}
-
-const initialState: InitialState = {
- stats: {
- users: 0,
- projects: 0,
- events: 0,
- },
- metainfo: {
- country: null,
- region: null,
- city: null,
- symbol: '$',
- code: 'USD',
- },
- paddle: {},
- showNoEventsLeftBanner: false,
- lastBlogPost: null,
- extensions: [],
-}
-
-const miscSlice = createSlice({
- name: 'misc',
- initialState,
- reducers: {
- setGeneralStats(state, { payload }: PayloadAction<Stats>) {
- state.stats = payload
- },
- setPaddleLastEvent(state, { payload }: PayloadAction<any>) {
- state.paddle = { ...state.paddle, lastEvent: payload }
- },
- setShowNoEventsLeftBanner(state, { payload }: PayloadAction<boolean>) {
- if (!payload) {
- const maxAge = secondsTillNextMonth() + 86400
- setCookie(LOW_EVENTS_WARNING, 1, maxAge)
- }
-
- state.showNoEventsLeftBanner = payload
- },
- setExtensions(state, { payload }: PayloadAction<any[]>) {
- state.extensions = payload
- },
- setMetainfo(state, { payload }: PayloadAction<Metainfo>) {
- state.metainfo = payload
- },
- setLastBlogPost(state, { payload }: PayloadAction<any>) {
- state.lastBlogPost = payload
- },
- },
-})
-
-export const miscActions = miscSlice.actions
-
-export default miscSlice.reducer
diff --git a/web/app/lib/store/index.ts b/web/app/lib/store/index.ts
index 1f5a7f918..2adc2eebe 100644
--- a/web/app/lib/store/index.ts
+++ b/web/app/lib/store/index.ts
@@ -4,13 +4,11 @@ import { useDispatch } from 'react-redux'
import { isDevelopment } from '~/lib/constants'
import authSlice from '../reducers/auth'
-import miscSlice from '../reducers/ui/misc'
import themeSlice from '../reducers/ui/theme'
const rootReducer = combineReducers({
auth: authSlice,
ui: combineReducers({
- misc: miscSlice,
theme: themeSlice,
}),
})
diff --git a/web/app/pages/Auth/Signin/Signin.tsx b/web/app/pages/Auth/Signin/Signin.tsx
index b2104a7cc..662e005aa 100644
--- a/web/app/pages/Auth/Signin/Signin.tsx
+++ b/web/app/pages/Auth/Signin/Signin.tsx
@@ -14,13 +14,11 @@ import { withAuthentication, auth } from '~/hoc/protected'
import { isSelfhosted, REFERRAL_COOKIE, TRIAL_DAYS } from '~/lib/constants'
import { SSOProvider } from '~/lib/models/Auth'
import { authActions } from '~/lib/reducers/auth'
-import UIActions from '~/lib/reducers/ui'
import { useAppDispatch } from '~/lib/store'
import Button from '~/ui/Button'
import Checkbox from '~/ui/Checkbox'
import Input from '~/ui/Input'
import { setAccessToken, removeAccessToken } from '~/utils/accessToken'
-import { shouldShowLowEventsBanner } from '~/utils/auth'
import { deleteCookie, getCookie } from '~/utils/cookie'
import { delay, openBrowserWindow } from '~/utils/generic'
import { setRefreshToken, removeRefreshToken } from '~/utils/refreshToken'
@@ -131,14 +129,10 @@ const Signin = ({ ssrTheme }: SigninProps) => {
return
}
- dispatch(authActions.authSuccessful(user))
+ dispatch(authActions.authSuccessful({ ...user, totalMonthlyEvents }))
setAccessToken(accessToken, false)
setRefreshToken(refreshToken)
- if (shouldShowLowEventsBanner(totalMonthlyEvents, user.maxEventsCount)) {
- dispatch(UIActions.setShowNoEventsLeftBanner(true))
- }
-
await loadExtensions()
dispatch(authActions.finishLoading())
@@ -168,7 +162,7 @@ const Signin = ({ ssrTheme }: SigninProps) => {
}
const extensions = await getInstalledExtensions()
- dispatch(UIActions.setExtensions(extensions))
+ dispatch(authActions.setExtensions(extensions))
}
const onSubmit = async (data: SigninForm) => {
@@ -194,14 +188,10 @@ const Signin = ({ ssrTheme }: SigninProps) => {
return
}
- dispatch(authActions.authSuccessful(user))
+ dispatch(authActions.authSuccessful({ ...user, totalMonthlyEvents }))
setAccessToken(accessToken, dontRemember)
setRefreshToken(refreshToken)
- if (shouldShowLowEventsBanner(totalMonthlyEvents, user.maxEventsCount)) {
- dispatch(UIActions.setShowNoEventsLeftBanner(true))
- }
-
await loadExtensions()
setIsLoading(false)
diff --git a/web/app/pages/Auth/Signup/Signup.tsx b/web/app/pages/Auth/Signup/Signup.tsx
index 1b932fff9..9f141d7aa 100644
--- a/web/app/pages/Auth/Signup/Signup.tsx
+++ b/web/app/pages/Auth/Signup/Signup.tsx
@@ -13,7 +13,6 @@ import GoogleAuth from '~/components/GoogleAuth'
import { HAVE_I_BEEN_PWNED_URL, REFERRAL_COOKIE, TRIAL_DAYS } from '~/lib/constants'
import { SSOProvider } from '~/lib/models/Auth'
import { authActions } from '~/lib/reducers/auth'
-import UIActions from '~/lib/reducers/ui'
import { StateType, useAppDispatch } from '~/lib/store'
import Button from '~/ui/Button'
import Checkbox from '~/ui/Checkbox'
@@ -21,7 +20,6 @@ import Input from '~/ui/Input'
import Tooltip from '~/ui/Tooltip'
import { getAccessToken, setAccessToken } from '~/utils/accessToken'
import { trackCustom } from '~/utils/analytics'
-import { shouldShowLowEventsBanner } from '~/utils/auth'
import { deleteCookie, getCookie } from '~/utils/cookie'
import { delay, openBrowserWindow } from '~/utils/generic'
import { setRefreshToken } from '~/utils/refreshToken'
@@ -193,14 +191,10 @@ const Signup = ({ ssrTheme }: SignupProps) => {
return
}
- dispatch(authActions.authSuccessful(user))
+ dispatch(authActions.authSuccessful({ ...user, totalMonthlyEvents }))
setAccessToken(accessToken, false)
setRefreshToken(refreshToken)
- if (shouldShowLowEventsBanner(totalMonthlyEvents, user.maxEventsCount)) {
- dispatch(UIActions.setShowNoEventsLeftBanner(true))
- }
-
dispatch(authActions.finishLoading())
navigate(routes.dashboard)
diff --git a/web/app/pages/Billing/index.tsx b/web/app/pages/Billing/index.tsx
index 3c42ca3d8..c9fd32f74 100644
--- a/web/app/pages/Billing/index.tsx
+++ b/web/app/pages/Billing/index.tsx
@@ -8,7 +8,7 @@ import { useTranslation, Trans } from 'react-i18next'
import { useSelector } from 'react-redux'
import { toast } from 'sonner'
-import { getUsageInfo } from '~/api'
+import { getPaymentMetainfo, getUsageInfo } from '~/api'
import DashboardLockedBanner from '~/components/DashboardLockedBanner'
import { withAuthentication, auth } from '~/hoc/protected'
import {
@@ -19,9 +19,9 @@ import {
paddleLanguageMapping,
isBrowser,
} from '~/lib/constants'
+import { DEFAULT_METAINFO, Metainfo } from '~/lib/models/Metainfo'
import { UsageInfo } from '~/lib/models/Usageinfo'
-import UIActions from '~/lib/reducers/ui'
-import { useAppDispatch, StateType } from '~/lib/store'
+import { StateType } from '~/lib/store'
import Button from '~/ui/Button'
import Loader from '~/ui/Loader'
import Modal from '~/ui/Modal'
@@ -41,7 +41,12 @@ interface BillingProps {
const Billing = ({ ssrAuthenticated, ssrTheme }: BillingProps) => {
const [isCancelSubModalOpened, setIsCancelSubModalOpened] = useState(false)
- const { metainfo } = useSelector((state: StateType) => state.ui.misc)
+
+ const [metainfo, setMetainfo] = useState<Metainfo>(DEFAULT_METAINFO)
+ const [lastEvent, setLastEvent] = useState<{
+ event: string
+ } | null>(null)
+
const { user, loading: authLoading } = useSelector((state: StateType) => state.auth)
const { theme: reduxTheme } = useSelector((state: StateType) => state.ui.theme)
const theme = isBrowser ? reduxTheme : ssrTheme
@@ -57,7 +62,6 @@ const Billing = ({ ssrAuthenticated, ssrTheme }: BillingProps) => {
customEventsPerc: 0,
captchaPerc: 0,
})
- const dispatch = useAppDispatch()
const {
t,
i18n: { language },
@@ -82,14 +86,20 @@ const Billing = ({ ssrAuthenticated, ssrTheme }: BillingProps) => {
const [isLoading, setIsLoading] = useState(true)
+ useEffect(() => {
+ const abortController = new AbortController()
+
+ getPaymentMetainfo({ signal: abortController.signal })
+ .then(setMetainfo)
+ .catch(() => {})
+
+ return () => abortController.abort()
+ }, [])
+
// Paddle (payment processor) set-up
useEffect(() => {
loadScript(PADDLE_JS_URL)
- const eventCallback = (data: any) => {
- dispatch(UIActions.setPaddleLastEvent(data))
- }
-
const interval = setInterval(paddleSetup, 200)
// prettier-ignore
@@ -99,12 +109,12 @@ const Billing = ({ ssrAuthenticated, ssrTheme }: BillingProps) => {
} else if ((window as any)?.Paddle) {
(window as any).Paddle.Setup({
vendor: PADDLE_VENDOR_ID,
- eventCallback,
+ eventCallback: setLastEvent,
})
clearInterval(interval)
}
}
- }, []) // eslint-disable-line
+ }, [])
const loadUsageInfo = async () => {
if (!isLoading) {
@@ -305,7 +315,7 @@ const Billing = ({ ssrAuthenticated, ssrTheme }: BillingProps) => {
<Loader />
) : (
<div className='mt-8 flex flex-col'>
- <Pricing authenticated={authenticated} isBillingPage />
+ <Pricing authenticated={authenticated} isBillingPage lastEvent={lastEvent} />
<div className='mt-2 space-y-2'>
{subUpdateURL && !cancellationEffectiveDate ? (
<Button className='mr-2' onClick={onUpdatePaymentDetails} type='button' primary large>
diff --git a/web/app/pages/ErrorTracking/index.tsx b/web/app/pages/ErrorTracking/index.tsx
index 990cbf623..10171bfe4 100644
--- a/web/app/pages/ErrorTracking/index.tsx
+++ b/web/app/pages/ErrorTracking/index.tsx
@@ -2,12 +2,13 @@ import { ArrowRightIcon } from '@heroicons/react/20/solid'
import { ChevronRightIcon } from '@heroicons/react/24/solid'
import _isEmpty from 'lodash/isEmpty'
import _map from 'lodash/map'
-import { memo } from 'react'
+import { memo, useEffect, useState } from 'react'
import { useTranslation, Trans } from 'react-i18next'
import { useSelector } from 'react-redux'
import { Link } from 'react-router'
import { ClientOnly } from 'remix-utils/client-only'
+import { getLastPost } from '~/api'
import Header from '~/components/Header'
import { DitchGoogle } from '~/components/marketing/DitchGoogle'
import { ERROR_TRACKING_LIVE_DEMO_URL, isBrowser } from '~/lib/constants'
@@ -35,11 +36,21 @@ const ErrorTracking = ({ ssrTheme, ssrAuthenticated }: ErrorTrackingProps) => {
const { t } = useTranslation('common')
const reduxTheme = useSelector((state: StateType) => state.ui.theme.theme)
const { authenticated: reduxAuthenticated, loading } = useSelector((state: StateType) => state.auth)
- const { lastBlogPost } = useSelector((state: StateType) => state.ui.misc)
+ const [lastBlogPost, setLastBlogPost] = useState<Awaited<ReturnType<typeof getLastPost>> | null>(null)
const theme = isBrowser ? reduxTheme : ssrTheme
const accessToken = getAccessToken()
const authenticated = isBrowser ? (loading ? !!accessToken : reduxAuthenticated) : ssrAuthenticated
+ useEffect(() => {
+ const abortController = new AbortController()
+
+ getLastPost({ signal: abortController.signal })
+ .then(setLastBlogPost)
+ .catch(() => {})
+
+ return () => abortController.abort()
+ }, [])
+
return (
<div className='overflow-hidden'>
<main className='bg-white dark:bg-slate-900'>
diff --git a/web/app/pages/OpenStartup/index.tsx b/web/app/pages/OpenStartup/index.tsx
index 57e779dee..e368a240f 100644
--- a/web/app/pages/OpenStartup/index.tsx
+++ b/web/app/pages/OpenStartup/index.tsx
@@ -1,12 +1,12 @@
/* eslint-disable no-useless-escape */
import billboard, { bar, line } from 'billboard.js'
-import { useEffect } from 'react'
+import { useEffect, useState } from 'react'
import { useTranslation, Trans } from 'react-i18next'
-import { useSelector } from 'react-redux'
import { Link } from 'react-router'
+import { getGeneralStats } from '~/api'
import { LIVE_DEMO_URL } from '~/lib/constants'
-import { StateType } from '~/lib/store/index'
+import { Stats } from '~/lib/models/Stats'
import { nFormatterSeparated } from '~/utils/generic'
// This should be generated on the API side, will be done later.
@@ -386,13 +386,17 @@ const getSettings = () => {
const OpenStartup = () => {
const { t }: any = useTranslation('common')
- const { stats } = useSelector((state: StateType) => state.ui.misc)
+ const [stats, setStats] = useState<Stats>({} as Stats)
const events = nFormatterSeparated(Number(stats.events), 1)
const users = nFormatterSeparated(Number(stats.users), 1)
const websites = nFormatterSeparated(Number(stats.projects), 1)
useEffect(() => {
+ getGeneralStats()
+ .then((stats) => setStats(stats))
+ .catch(console.error)
+
const bbSettings = getSettings()
// @ts-expect-error
diff --git a/web/app/pages/Performance/index.tsx b/web/app/pages/Performance/index.tsx
index 6a3adbbb7..97088a20d 100644
--- a/web/app/pages/Performance/index.tsx
+++ b/web/app/pages/Performance/index.tsx
@@ -2,15 +2,17 @@ import { ArrowRightIcon } from '@heroicons/react/20/solid'
import { ChevronRightIcon } from '@heroicons/react/24/solid'
import _isEmpty from 'lodash/isEmpty'
import _map from 'lodash/map'
-import { memo } from 'react'
+import { memo, useEffect, useState } from 'react'
import { useTranslation, Trans } from 'react-i18next'
import { useSelector } from 'react-redux'
import { Link } from 'react-router'
import { ClientOnly } from 'remix-utils/client-only'
+import { getGeneralStats, getLastPost } from '~/api'
import Header from '~/components/Header'
import { DitchGoogle } from '~/components/marketing/DitchGoogle'
import { PERFORMANCE_LIVE_DEMO_URL, isBrowser } from '~/lib/constants'
+import { Stats } from '~/lib/models/Stats'
import { StateType } from '~/lib/store/index'
import BackgroundSvg from '~/ui/icons/BackgroundSvg'
import { getAccessToken } from '~/utils/accessToken'
@@ -33,7 +35,13 @@ interface PerformanceProps {
export const PeopleLoveSwetrix = () => {
const { t } = useTranslation('common')
- const { stats } = useSelector((state: StateType) => state.ui.misc)
+ const [stats, setStats] = useState<Stats>({} as Stats)
+
+ useEffect(() => {
+ getGeneralStats()
+ .then((stats) => setStats(stats))
+ .catch(console.error)
+ }, [])
const events = nFormatterSeparated(Number(stats.events))
const users = nFormatterSeparated(Number(stats.users))
@@ -94,11 +102,21 @@ const Performance = ({ ssrTheme, ssrAuthenticated }: PerformanceProps) => {
const { t } = useTranslation('common')
const reduxTheme = useSelector((state: StateType) => state.ui.theme.theme)
const { authenticated: reduxAuthenticated, loading } = useSelector((state: StateType) => state.auth)
- const { lastBlogPost } = useSelector((state: StateType) => state.ui.misc)
+ const [lastBlogPost, setLastBlogPost] = useState<Awaited<ReturnType<typeof getLastPost>> | null>(null)
const theme = isBrowser ? reduxTheme : ssrTheme
const accessToken = getAccessToken()
const authenticated = isBrowser ? (loading ? !!accessToken : reduxAuthenticated) : ssrAuthenticated
+ useEffect(() => {
+ const abortController = new AbortController()
+
+ getLastPost({ signal: abortController.signal })
+ .then(setLastBlogPost)
+ .catch(() => {})
+
+ return () => abortController.abort()
+ }, [])
+
return (
<div className='overflow-hidden'>
<main className='bg-white dark:bg-slate-900'>
diff --git a/web/app/pages/Project/View/ViewProject.tsx b/web/app/pages/Project/View/ViewProject.tsx
index 33324856c..c0b4f6d31 100644
--- a/web/app/pages/Project/View/ViewProject.tsx
+++ b/web/app/pages/Project/View/ViewProject.tsx
@@ -268,7 +268,7 @@ const ViewProject = () => {
const { theme } = useSelector((state: StateType) => state.ui.theme)
- const { extensions } = useSelector((state: StateType) => state.ui.misc)
+ const { extensions } = useSelector((state: StateType) => state.auth)
const authenticated = isBrowser ? (authLoading ? ssrAuthenticated : csrAuthenticated) : ssrAuthenticated
const { timezone = DEFAULT_TIMEZONE } = user || {}
diff --git a/web/app/pages/Project/View/utils/cache.ts b/web/app/pages/Project/View/utils/cache.ts
index abe049294..47a7cfbce 100644
--- a/web/app/pages/Project/View/utils/cache.ts
+++ b/web/app/pages/Project/View/utils/cache.ts
@@ -6,7 +6,7 @@ import { ProjectPreferences } from '../providers/CurrentProjectProvider'
import { filterInvalidPreferences } from './filters'
-export const getAllProjectPreferences = (): Record<string, ProjectPreferences> => {
+const getAllProjectPreferences = (): Record<string, ProjectPreferences> => {
if (!isBrowser) {
return {}
}
@@ -37,7 +37,7 @@ export const setProjectPreferences = (id: Project['id'], preferences: ProjectPre
)
}
-export const getAllProjectPasswords = () => (getItem(LS_PROJECTS_PROTECTED_KEY) as Record<string, string>) || {}
+const getAllProjectPasswords = () => (getItem(LS_PROJECTS_PROTECTED_KEY) as Record<string, string>) || {}
export const setProjectPassword = (id: Project['id'], password: string) => {
setItem(
diff --git a/web/app/routes/_index.tsx b/web/app/routes/_index.tsx
index 95ca55e79..8fa9946c3 100644
--- a/web/app/routes/_index.tsx
+++ b/web/app/routes/_index.tsx
@@ -14,6 +14,7 @@ import type { SitemapFunction } from 'remix-sitemap'
import { ClientOnly } from 'remix-utils/client-only'
import { UAParser } from 'ua-parser-js'
+import { getGeneralStats, getPaymentMetainfo } from '~/api'
import Header from '~/components/Header'
import { ConveyorBelt } from '~/components/marketing/ConveyorBelt'
import { DitchGoogle } from '~/components/marketing/DitchGoogle'
@@ -31,6 +32,8 @@ import {
BROWSER_LOGO_MAP,
isDisableMarketingPages,
} from '~/lib/constants'
+import { DEFAULT_METAINFO, Metainfo } from '~/lib/models/Metainfo'
+import { Stats } from '~/lib/models/Stats'
import { StateType } from '~/lib/store/index'
import CCRow from '~/pages/Project/View/components/CCRow'
import { MetricCard, MetricCardSelect } from '~/pages/Project/View/components/MetricCards'
@@ -278,7 +281,13 @@ const REVIEWERS = [
const Testimonials = () => {
const { t } = useTranslation('common')
- const { stats } = useSelector((state: StateType) => state.ui.misc)
+ const [stats, setStats] = useState<Stats>({} as Stats)
+
+ useEffect(() => {
+ getGeneralStats()
+ .then((stats) => setStats(stats))
+ .catch(console.error)
+ }, [])
return (
<div className='mt-8 flex flex-col items-center justify-center gap-3 font-mono md:flex-row'>
@@ -402,7 +411,17 @@ const FeatureBlocks = ({ theme }: { theme: 'dark' | 'light' }) => {
t,
i18n: { language },
} = useTranslation('common')
- const { metainfo } = useSelector((state: StateType) => state.ui.misc)
+ const [metainfo, setMetainfo] = useState<Metainfo>(DEFAULT_METAINFO)
+
+ useEffect(() => {
+ const abortController = new AbortController()
+
+ getPaymentMetainfo({ signal: abortController.signal })
+ .then(setMetainfo)
+ .catch(() => {})
+
+ return () => abortController.abort()
+ }, [])
const { deviceInfo } = useLoaderData<typeof loader>()