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 last commit

kruzhambus55a07e4f20b7
diff --git a/package.json b/package.json
index a26c32b9e..f340ac492 100644
--- a/package.json
+++ b/package.json
@@ -6,6 +6,7 @@
"@blaumaus/react-alert": "^7.0.5",
"@headlessui/react": "^1.7.13",
"@heroicons/react": "^2.0.16",
+ "@reduxjs/toolkit": "^1.9.3",
"@swetrix/sdk": "^1.0.0",
"@tailwindcss/forms": "^0.5.3",
"axios": "^1.3.4",
diff --git a/src/redux/models/IAlerts.ts b/src/redux/models/IAlerts.ts
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/redux/models/IAuth.ts b/src/redux/models/IAuth.ts
new file mode 100644
index 000000000..99ebe9b8d
--- /dev/null
+++ b/src/redux/models/IAuth.ts
@@ -0,0 +1,7 @@
+import { IUser } from './IUser'
+
+export interface IAuth {
+ refresh_token: string
+ access_token: string
+ user: IUser
+}
diff --git a/src/redux/models/IProject.ts b/src/redux/models/IProject.ts
new file mode 100644
index 000000000..7f77a7a88
--- /dev/null
+++ b/src/redux/models/IProject.ts
@@ -0,0 +1,37 @@
+export interface IOverall {
+ thisWeek: number
+ lastWeek: number
+ thisWeekUnique: number
+ lastWeekUnique: number
+}
+
+export interface IUserShareProject {
+ email: string
+}
+
+export interface IShareOwnerProject {
+ id: string
+ confirmed: boolean
+ role: string
+ created: string
+ updated: string
+ user: IUserShareProject
+}
+
+export interface IProject {
+ id: string
+ name: string
+ origins: string[]
+ ipBlacklist: string[] | null
+ active: boolean
+ public: boolean
+ isAnalyticsProject: boolean
+ isCaptchaProject: boolean
+ isCaptchaEnabled: boolean
+ captchaSecretKey: string | null
+ created: string
+ share: IShareOwnerProject[]
+ isOwner: boolean
+ overall: IOverall
+ live: number
+}
diff --git a/src/redux/models/ISharedProject.ts b/src/redux/models/ISharedProject.ts
new file mode 100644
index 000000000..46f4dfe29
--- /dev/null
+++ b/src/redux/models/ISharedProject.ts
@@ -0,0 +1,10 @@
+import { IProject } from './IProject'
+
+export interface ISharedProject {
+ id: string
+ confirmed: boolean
+ role: string
+ created: string
+ updated: string
+ project: IProject
+}
diff --git a/src/redux/models/IUser.ts b/src/redux/models/IUser.ts
new file mode 100644
index 000000000..8d0bf7624
--- /dev/null
+++ b/src/redux/models/IUser.ts
@@ -0,0 +1,32 @@
+import { ISharedProject } from './ISharedProject'
+
+export interface IUser {
+ id: string
+ roles: string[]
+ planCode: string
+ nickname: string
+ email: string
+ isActive: boolean
+ trialEndDate: string
+ reportFrequency: string
+ emailRequests: number
+ created: string
+ updated: string
+ evWarningSentOn: string | null
+ exportedAt: string
+ subID: string | null
+ subUpdateURL: string | null
+ subCancelURL: string | null
+ timezone: string
+ theme: string | null
+ isTwoFactorAuthenticationEnabled: boolean
+ trialReminderSent: boolean
+ billingFrequency: string | null
+ nextBillDate: string | null
+ cancellationEffectiveDate: string | null
+ apiKey: string | null
+ telegramChatId: string
+ isTelegramChatIdConfirmed: boolean
+ timeFormat: string
+ sharedProjects: ISharedProject[]
+}
diff --git a/src/redux/reducers/alerts.ts b/src/redux/reducers/alerts.ts
new file mode 100644
index 000000000..3408c2484
--- /dev/null
+++ b/src/redux/reducers/alerts.ts
@@ -0,0 +1,41 @@
+/* eslint-disable no-param-reassign */
+import { createSlice, PayloadAction } from '@reduxjs/toolkit'
+
+interface IInitialState {
+ message: null | string
+ type: string
+}
+
+const initialState: IInitialState = {
+ message: null,
+ type: 'info',
+}
+
+const alertsCreate = (state: IInitialState, { payload }: PayloadAction<{ message: string, type: string }>) => {
+ state.message = payload.message
+ state.type = payload.type
+}
+
+const alertsSlice = createSlice({
+ name: 'alerts',
+ initialState,
+ reducers: {
+ accountDeleted: alertsCreate,
+ accountUpdated: alertsCreate,
+ newPassword: alertsCreate,
+ deleteProjectSuccess: alertsCreate,
+ createNewProjectSuccess: alertsCreate,
+ roleUpdated: alertsCreate,
+ inviteUser: alertsCreate,
+ removeUser: alertsCreate,
+ userSharedUpdate: alertsCreate,
+ generateAlerts: alertsCreate,
+ clearAlerts: (state) => {
+ state.message = null
+ state.type = 'info'
+ },
+ },
+})
+
+export const alertsActions = alertsSlice.actions
+export default alertsSlice.reducer
diff --git a/src/redux/reducers/auth.ts b/src/redux/reducers/auth.ts
new file mode 100644
index 000000000..9662311ae
--- /dev/null
+++ b/src/redux/reducers/auth.ts
@@ -0,0 +1,96 @@
+/* eslint-disable @typescript-eslint/no-unused-expressions */
+/* eslint-disable no-unused-expressions */
+/* eslint-disable no-param-reassign */
+import { createSlice, PayloadAction } from '@reduxjs/toolkit'
+import _filter from 'lodash/filter'
+import _map from 'lodash/map'
+import { IUser } from '../models/IUser'
+import { FREE_TIER_KEY, isSelfhosted } from '../constants'
+import { ISharedProject } from '../models/ISharedProject'
+
+interface IAuthState {
+ user: IUser
+ redirectPath: string | null
+ authenticated: boolean
+ loading: boolean
+ dontRemember: boolean
+ isPaidTierUsed: boolean
+}
+
+const initialState: IAuthState = {
+ user: {} as IUser,
+ redirectPath: null,
+ authenticated: false,
+ loading: true,
+ dontRemember: false,
+ // if the app is selfhosted, we assume that the user is using a paid tier so there won't be any restrictions or advertising of it
+ isPaidTierUsed: isSelfhosted,
+}
+
+const authSlice = createSlice({
+ name: 'auth',
+ initialState,
+ reducers: {
+ finishLoading: (state) => {
+ state.loading = false
+ },
+ loginSuccessful: (state, { payload }: PayloadAction<IUser>) => {
+ state.user = payload
+ state.authenticated = true
+ state.isPaidTierUsed = isSelfhosted || (payload?.planCode && payload.planCode !== FREE_TIER_KEY) as boolean
+ },
+ emailVerifySuccessful: (state) => {
+ state.user = { ...state.user, isActive: true }
+ },
+ signupUpSuccessful: (state, { payload }: PayloadAction<IUser>) => {
+ state.user = payload
+ state.authenticated = true
+ state.isPaidTierUsed = isSelfhosted || (payload?.planCode && payload.planCode !== FREE_TIER_KEY) as boolean
+ },
+ updateUserProfileSuccess: (state, { payload }: PayloadAction<IUser>) => {
+ state.user = payload
+ },
+ logout: (state) => {
+ state.user = {} as IUser
+ state.authenticated = false
+ state.isPaidTierUsed = isSelfhosted
+ },
+ savePath: (state, { payload }: PayloadAction<string>) => {
+ state.redirectPath = payload
+ },
+ deleteAccountSuccess: (state) => {
+ state.user = {} as IUser
+ state.authenticated = false
+ state.isPaidTierUsed = isSelfhosted
+ },
+ deleteShareProject: (state, { payload }: PayloadAction<string>) => {
+ const projects = _filter(state.user?.sharedProjects, (item) => item.id !== payload)
+ state.user = { ...state.user, sharedProjects: projects }
+ },
+ setUserShareData: (state, { payload }: PayloadAction<{ data: ISharedProject, id: string }>) => {
+ const projects = _map(state.user?.sharedProjects, (item) => {
+ if (item.id === payload.id) {
+ return { ...item, ...payload.data }
+ }
+ return item
+ })
+ state.user = { ...state.user, sharedProjects: projects }
+ },
+ setDontRemember: (state, { payload }: PayloadAction<boolean>) => {
+ state.dontRemember = payload
+ },
+ updateUserData: (state, { payload }: PayloadAction<IUser>) => {
+ state.user = { ...state.user, ...payload }
+ },
+ setApiKey: (state, { payload }: PayloadAction<string>) => {
+ state.user = { ...state.user, apiKey: payload }
+ },
+ setUser: (state, { payload }: PayloadAction<IUser>) => {
+ state.user = { ...state.user, ...payload }
+ },
+ },
+})
+
+export const authActions = authSlice.actions
+
+export default authSlice.reducer
diff --git a/src/redux/reducers/errors.ts b/src/redux/reducers/errors.ts
new file mode 100644
index 000000000..6e0fe15a2
--- /dev/null
+++ b/src/redux/reducers/errors.ts
@@ -0,0 +1,38 @@
+/* eslint-disable no-param-reassign */
+import { createSlice, PayloadAction } from '@reduxjs/toolkit'
+
+interface IInitialState {
+ error: null | string
+}
+
+const initialState: IInitialState = {
+ error: null,
+}
+
+const errorsCreate = (state: IInitialState, { payload }: PayloadAction<{ message: string, type: string }>) => {
+ state.error = payload.message
+}
+
+const errorsSlice = createSlice({
+ name: 'alerts',
+ initialState,
+ reducers: {
+ genericError: errorsCreate,
+ loginFailed: errorsCreate,
+ signUpFailed: errorsCreate,
+ updateUserProfileFailed: errorsCreate,
+ createNewPasswordFailed: errorsCreate,
+ deleteAccountFailed: errorsCreate,
+ createNewProjectFailed: errorsCreate,
+ updateProjectFailed: errorsCreate,
+ deleteProjectFailed: errorsCreate,
+ gdprExportFailed: errorsCreate,
+ sharedProjectFailed: errorsCreate,
+ clearErrors: (state) => {
+ state.error = null
+ },
+ },
+})
+
+export const alertsActions = errorsSlice.actions
+export default errorsSlice.reducer
diff --git a/src/redux/reducers/ui/alerts.js b/src/redux/reducers/ui/alerts.js
deleted file mode 100644
index 7cf808b34..000000000
--- a/src/redux/reducers/ui/alerts.js
+++ /dev/null
@@ -1,48 +0,0 @@
-import { types } from 'redux/actions/ui/types'
-
-const getInitialState = () => {
- return {
- alerts: [],
- total: 0,
- pageTotal: 0,
- loading: false,
- }
-}
-
-// eslint-disable-next-line default-param-last
-const alertsReducer = (state = getInitialState(), { type, payload }) => {
- switch (type) {
- case types.SET_PROJECT_ALERTS: {
- const { alerts } = payload
-
- return {
- ...state,
- alerts,
- }
- }
-
- case types.SET_PROJECT_ALERTS_TOTAL: {
- const { total, pageTotal } = payload
-
- return {
- ...state,
- total,
- pageTotal,
- }
- }
-
- case types.SET_PROJECT_ALERTS_LOADING: {
- const { loading } = payload
-
- return {
- ...state,
- loading,
- }
- }
-
- default:
- return state
- }
-}
-
-export default alertsReducer
diff --git a/src/redux/reducers/ui/alerts.ts b/src/redux/reducers/ui/alerts.ts
new file mode 100644
index 000000000..9982251fb
--- /dev/null
+++ b/src/redux/reducers/ui/alerts.ts
@@ -0,0 +1,13 @@
+import { createSlice, PayloadAction } from '@reduxjs/toolkit'
+
+// alerts: [],
+// total: 0,
+// pageTotal: 0,
+// loading: false,
+
+interface IInitialState {
+ alerts: any[]
+ total: number
+ pageTotal: number
+ loading: boolean
+}
diff --git a/src/redux/reducers/ui/cache.js b/src/redux/reducers/ui/cache.js
deleted file mode 100644
index 9654378a6..000000000
--- a/src/redux/reducers/ui/cache.js
+++ /dev/null
@@ -1,226 +0,0 @@
-import { types } from 'redux/actions/ui/types'
-import _filter from 'lodash/filter'
-import _isEmpty from 'lodash/isEmpty'
-
-import {
- getProjectCacheKey, LS_VIEW_PREFS_SETTING, LS_CAPTCHA_VIEW_PREFS_SETTING, getProjectCaptchaCacheKey,
-} from 'redux/constants'
-
-export const getInitialViewPrefs = (LS_VIEW) => {
- if (typeof window !== 'undefined' && window.localStorage) {
- const storedPrefs = window.localStorage.getItem(LS_VIEW)
- if (typeof storedPrefs === 'string') {
- try {
- return JSON.parse(storedPrefs)
- } catch (e) {
- window.localStorage.removeItem(LS_VIEW)
- }
- }
- }
-
- return {}
-}
-
-const getInitialState = () => {
- return {
- // { pid: { 'period + timeBucket': { ... }, ... }, ... }
- // example: { 'FSMaC9V4HFLA': { '4wday': { }, '7dhour': { } } }
- analytics: {},
-
- analyticsPerf: {},
-
- captchaAnalytics: {},
-
- captchaProjectsViewPrefs: getInitialViewPrefs(LS_CAPTCHA_VIEW_PREFS_SETTING),
-
- // { pid: { period: '7d', timeBucket: 'day' }, ... }
- projectViewPrefs: getInitialViewPrefs(LS_VIEW_PREFS_SETTING),
- }
-}
-
-// eslint-disable-next-line default-param-last
-const cacheReducer = (state = getInitialState(), { type, payload }) => {
- switch (type) {
- case types.SET_PROJECT_CACHE: {
- const { pid, data, key } = payload
-
- return {
- ...state,
- analytics: {
- ...state.analytics,
- [pid]: {
- ...state.analytics[pid],
- [key]: data,
- },
- },
- }
- }
-
- case types.SET_CAPTCHA_PROJECT_CACHE: {
- const { pid, data, key } = payload
-
- return {
- ...state,
- captchaAnalytics: {
- ...state.captchaAnalytics,
- [pid]: {
- ...state.captchaAnalytics[pid],
- [key]: data,
- },
- },
- }
- }
-
- case types.DELETE_PROJECT_CACHE: {
- const { pid, period, timeBucket } = payload
- const key = getProjectCacheKey(period, timeBucket)
-
- if (_isEmpty(period) || _isEmpty(timeBucket)) {
- if (_isEmpty(pid)) {
- return {
- ...state,
- analytics: {},
- }
- }
-
- return {
- ...state,
- analytics: _filter(state.analytics, (project) => project !== pid),
- }
- }
-
- return {
- ...state,
- analytics: {
- ...state.analytics,
- [pid]: _filter(state.analytics[pid], (ckey) => ckey !== key),
- },
- }
- }
-
- case types.DELETE_CAPTCHA_PROJECT_CACHE: {
- const { pid, period, timeBucket } = payload
- const key = getProjectCaptchaCacheKey(period, timeBucket)
-
- if (_isEmpty(period) || _isEmpty(timeBucket)) {
- if (_isEmpty(pid)) {
- return {
- ...state,
- captchaAnalytics: {},
- }
- }
-
- return {
- ...state,
- captchaAnalytics: _filter(state.captchaAnalytics, (project) => project !== pid),
- }
- }
-
- return {
- ...state,
- captchaAnalytics: {
- ...state.captchaAnalytics,
- [pid]: _filter(state.captchaAnalytics[pid], (ckey) => ckey !== key),
- },
- }
- }
-
- case types.SET_PROJECT_VIEW_PREFS: {
- const {
- pid, period, timeBucket, rangeDate,
- } = payload
-
- return {
- ...state,
- projectViewPrefs: {
- ...state.projectViewPrefs,
- [pid]: rangeDate ? {
- period, timeBucket, rangeDate,
- } : {
- period, timeBucket,
- },
- },
- }
- }
-
- case types.SET_CAPTCHA_PROJECTS_VIEW_PREFS: {
- const {
- pid, period, timeBucket, rangeDate,
- } = payload
-
- return {
- ...state,
- captchaProjectsViewPrefs: {
- ...state.captchaProjectsViewPrefs,
- [pid]: rangeDate ? {
- period, timeBucket, rangeDate,
- } : {
- period, timeBucket,
- },
- },
- }
- }
-
- case types.SET_PROJECT_CACHE_PERF: {
- const { pid, data, key } = payload
-
- return {
- ...state,
- analyticsPerf: {
- ...state.analyticsPerf,
- [pid]: {
- ...state.analyticsPerf[pid],
- [key]: data,
- },
- },
- }
- }
-
- case types.DELETE_PROJECT_CACHE_PERF: {
- const { pid, period, timeBucket } = payload
- const key = getProjectCacheKey(period, timeBucket)
-
- if (_isEmpty(period) || _isEmpty(timeBucket)) {
- if (_isEmpty(pid)) {
- return {
- ...state,
- analyticsPerf: {},
- }
- }
-
- return {
- ...state,
- analyticsPerf: _filter(state.analyticsPerf, (project) => project !== pid),
- }
- }
-
- return {
- ...state,
- analyticsPerf: {
- ...state.analyticsPerf,
- [pid]: _filter(state.analyticsPerf[pid], (ckey) => ckey !== key),
- },
- }
- }
-
- case types.SET_PROJECT_FORECAST_CACHE: {
- const { pid, data, key } = payload
-
- return {
- ...state,
- analytics: {
- ...state.analytics,
- [pid]: {
- ...state.analytics[pid],
- [key]: data,
- },
- },
- }
- }
-
- default:
- return state
- }
-}
-
-export default cacheReducer
diff --git a/src/redux/reducers/ui/cache.ts b/src/redux/reducers/ui/cache.ts
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/redux/reducers/ui/index.js b/src/redux/reducers/ui/index.js
deleted file mode 100644
index 8a3d0ad92..000000000
--- a/src/redux/reducers/ui/index.js
+++ /dev/null
@@ -1,10 +0,0 @@
-import { combineReducers } from 'redux'
-import projects from './projects'
-import cache from './cache'
-import theme from './theme'
-import misc from './misc'
-import alerts from './alerts'
-
-export default combineReducers({
- projects, cache, theme, misc, alerts,
-})
diff --git a/src/redux/reducers/ui/misc.js b/src/redux/reducers/ui/misc.js
deleted file mode 100644
index 9bb1388f7..000000000
--- a/src/redux/reducers/ui/misc.js
+++ /dev/null
@@ -1,81 +0,0 @@
-import { types } from 'redux/actions/ui/types'
-import { LOW_EVENTS_WARNING } from 'redux/constants'
-import { setCookie } from 'utils/cookie'
-import { secondsTillNextMonth } from 'utils/generic'
-
-const initialState = {
- stats: {
- users: 0,
- projects: 0,
- pageviews: 0,
- },
- paddle: {
- lastEvent: null,
- },
- showNoEventsLeftBanner: false,
- lastBlogPost: {},
- extensions: [],
-}
-
-// eslint-disable-next-line default-param-last
-const miscReducer = (state = initialState, { type, payload }) => {
- switch (type) {
- case types.SET_GENERAL_STATS: {
- const { stats } = payload
-
- return {
- ...state,
- stats,
- }
- }
-
- case types.SET_PADDLE_LAST_EVENT: {
- const { event } = payload
-
- return {
- ...state,
- paddle: {
- ...state.paddle,
- lastEvent: event,
- },
- }
- }
-
- case types.SET_SHOW_NO_EVENTS_LEFT: {
- const { showNoEventsLeftBanner } = payload
-
- if (!showNoEventsLeftBanner) {
- const maxAge = secondsTillNextMonth() + 86400
- setCookie(LOW_EVENTS_WARNING, 1, maxAge)
- }
-
- return {
- ...state,
- showNoEventsLeftBanner,
- }
- }
-
- case types.SET_EXTENSIONS: {
- const { extensions } = payload
-
- return {
- ...state,
- extensions,
- }
- }
-
- case types.SET_LAST_BLOG_POST: {
- const { lastBlogPost } = payload
-
- return {
- ...state,
- lastBlogPost,
- }
- }
-
- default:
- return state
- }
-}
-
-export default miscReducer
diff --git a/src/redux/reducers/ui/misc.ts b/src/redux/reducers/ui/misc.ts
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/redux/reducers/ui/projects.js b/src/redux/reducers/ui/projects.js
deleted file mode 100644
index 532a74aff..000000000
--- a/src/redux/reducers/ui/projects.js
+++ /dev/null
@@ -1,322 +0,0 @@
-import { types } from 'redux/actions/ui/types'
-import _filter from 'lodash/filter'
-import _findIndex from 'lodash/findIndex'
-import _map from 'lodash/map'
-import { tabForOwnedProject, PROJECT_TABS } from 'redux/constants'
-import { setItem, getItem } from 'utils/localstorage'
-
-const getInitialState = () => {
- return {
- projects: [],
- sharedProjects: [],
- captchaProjects: [],
- isLoading: true,
- isLoadingShared: true,
- isLoadingCaptcha: true,
- error: null,
- totalMonthlyEvents: null,
- total: 0,
- sharedTotal: 0,
- captchaTotal: 0,
- dashboardPaginationPage: 1,
- dashboardPaginationPageShared: 1,
- dashboardPaginationPageCaptcha: 1,
- dashboardTabs: getItem('dashboardTabs') || tabForOwnedProject,
- projectTab: PROJECT_TABS.traffic,
- alerts: [],
- subscribers: [],
- }
-}
-
-// eslint-disable-next-line default-param-last
-const projectsReducer = (state = getInitialState(), { type, payload }) => {
- switch (type) {
- case types.SET_PROJECTS: {
- const { projects, shared = false } = payload
- if (shared) {
- return {
- ...state,
- isLoadingShared: false,
- sharedProjects: projects,
- }
- }
-
- return {
- ...state,
- projects,
- isLoading: false,
- }
- }
-
- case types.SET_CAPTCHA_PROJECTS: {
- const { captchaProjects } = payload
- return {
- ...state,
- captchaProjects,
- isLoadingCaptcha: false,
- }
- }
-
- case types.SET_DASHBOARD_PAGINATION_PAGE: {
- const { page } = payload
- return {
- ...state,
- dashboardPaginationPage: page,
- }
- }
-
- case types.SET_DASHBOARD_PAGINATION_PAGE_SHARED: {
- const { page } = payload
- return {
- ...state,
- dashboardPaginationPageShared: page,
- }
- }
-
- case types.SET_DASHBOARD_PAGINATION_PAGE_CAPTCHA: {
- const { page } = payload
- return {
- ...state,
- dashboardPaginationPageCaptcha: page,
- }
- }
-
- case types.SET_TOTAL_MONTHLY_EVENTS: {
- const { totalMonthlyEvents } = payload
- return {
- ...state,
- totalMonthlyEvents,
- }
- }
-
- case types.SET_TOTAL: {
- const { total, shared } = payload
-
- if (shared) {
- return {
- ...state,
- sharedTotal: total,
- }
- }
-
- return {
- ...state,
- total,
- }
- }
-
- case types.SET_CAPTCHA_PROJECTS_TOTAL: {
- const { total } = payload
- return {
- ...state,
- captchaTotal: total,
- }
- }
-
- case types.SET_CAPTCHA_PROJECTS_LOADING: {
- const { isLoading } = payload
- return {
- ...state,
- isLoadingCaptcha: isLoading,
- }
- }
-
- case types.REMOVE_CAPTCHA_PROJECT: {
- const { id } = payload
- return {
- ...state,
- captchaProjects: _filter(state.captchaProjects, (el) => el.id !== id),
- }
- }
-
- case types.SET_LIVE_STATS: {
- const { data, shared = false } = payload
-
- if (shared) {
- return {
- ...state,
- sharedProjects: _map(state.sharedProjects, res => ({
- ...res,
- project: {
- ...res.project,
- live: data[res.project.id],
- },
- })),
- }
- }
-
- return {
- ...state,
- projects: _map(state.projects, res => ({
- ...res,
- live: data[res.id],
- })),
- }
- }
-
- case types.SET_LIVE_STATS_PROJECT: {
- const { id, count, shared = false } = payload
-
- if (shared) {
- return {
- ...state,
- sharedProjects: _map(state.sharedProjects, res => {
- if (res.id === id) {
- return {
- ...res,
- live: count,
- }
- }
-
- return res
- }),
- }
- }
-
- return {
- ...state,
- projects: _map(state.projects, res => {
- if (res.id === id) {
- return {
- ...res,
- live: count,
- }
- }
-
- return res
- }),
- }
- }
-
- case types.SET_PUBLIC_PROJECT: {
- const { project, shared = false } = payload
-
- if (shared) {
- return {
- ...state,
- sharedProjects: _findIndex(state.sharedProjects, (el) => el.id === project.id) >= 0
- ? state.sharedProjects
- : [
- ...state.sharedProjects,
- {
- ...project,
- uiHidden: true,
- },
- ],
- }
- }
-
- return {
- ...state,
- projects: _findIndex(state.projects, (el) => el.id === project.id) >= 0
- ? state.projects
- : [
- ...state.projects,
- {
- ...project,
- uiHidden: true,
- },
- ],
- }
- }
-
- case types.SET_PROJECTS_SHARE_DATA: {
- const { data, id, shared = false } = payload
-
- if (shared) {
- return {
- ...state,
- sharedProjects: _map(state.sharedProjects, (item) => {
- if (item.project.id === id) {
- return {
- ...item,
- ...data,
- }
- }
-
- return item
- }),
- }
- }
-
- return {
- ...state,
- projects: _map(state.projects, (item) => {
- if (item.id === id) {
- return {
- ...item,
- ...data,
- }
- }
-
- return item
- }),
- }
- }
-
- case types.SET_PROJECTS_ERROR: {
- const { error } = payload
- return {
- ...state,
- error,
- }
- }
-
- case types.REMOVE_PROJECT: {
- const { pid, shared = false } = payload
-
- if (shared) {
- return {
- ...state,
- sharedProjects: _filter(state.sharedProjects, (item) => item.project.id !== pid),
- sharedTotal: state.sharedTotal - 1,
- }
- }
-
- return {
- ...state,
- projects: _filter(state.projects, (project) => project.id !== pid),
- total: state.total - 1,
- }
- }
-
- case types.SET_PROJECTS_LOADING: {
- const { isLoading, shared = false } = payload
- if (shared) {
- return {
- ...state,
- isLoadingShared: isLoading,
- }
- }
- return {
- ...state,
- isLoading,
- }
- }
-
- case types.SET_DASHBOARD_TABS: {
- const { tab } = payload
-
- setItem('dashboardTabs', tab)
-
- return {
- ...state,
- dashboardTabs: tab,
- }
- }
-
- case types.SET_PROJECT_TAB: {
- const { tab } = payload
-
- return {
- ...state,
- projectTab: tab,
- }
- }
-
- default:
- return state
- }
-}
-
-export default projectsReducer
diff --git a/src/redux/reducers/ui/projects.ts b/src/redux/reducers/ui/projects.ts
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/redux/reducers/ui/theme.js b/src/redux/reducers/ui/theme.js
deleted file mode 100644
index 738b2b119..000000000
--- a/src/redux/reducers/ui/theme.js
+++ /dev/null
@@ -1,72 +0,0 @@
-import _includes from 'lodash/includes'
-import { types } from 'redux/actions/ui/types'
-import { LS_THEME_SETTING, SUPPORTED_THEMES, THEME_TYPE } from 'redux/constants'
-
-const setThemeToDOM = (theme) => {
- const root = window.document.documentElement
- const isDark = theme === 'dark'
-
- root.classList.remove(isDark ? 'light' : 'dark')
- root.classList.add(theme)
-}
-
-const setTheme = (theme) => {
- setThemeToDOM(theme)
- localStorage.setItem(LS_THEME_SETTING, theme)
- return theme
-}
-
-const getInitialTheme = () => {
- if (typeof window !== 'undefined' && window.localStorage) {
- const lsTheme = window.localStorage.getItem(LS_THEME_SETTING)
- if (_includes(SUPPORTED_THEMES, lsTheme)) {
- setThemeToDOM(lsTheme)
- return lsTheme
- }
-
- const userMedia = window.matchMedia('(prefers-color-scheme: dark)')
- if (userMedia.matches) {
- setThemeToDOM('dark')
- return 'dark'
- }
- }
-
- setThemeToDOM('light')
- return 'light' // light theme as the default
-}
-
-const getInitialState = () => {
- return {
- theme: getInitialTheme(),
- type: THEME_TYPE.classic,
- }
-}
-
-// eslint-disable-next-line default-param-last
-const themeReducer = (state = getInitialState(), { type, payload }) => {
- switch (type) {
- case types.SET_THEME: {
- const { theme } = payload
-
- setTheme(theme)
- return {
- ...state,
- theme,
- }
- }
-
- case types.SET_THEME_TYPE: {
- const { theme } = payload
-
- return {
- ...state,
- type: theme,
- }
- }
-
- default:
- return state
- }
-}
-
-export default themeReducer
diff --git a/src/redux/reducers/ui/theme.ts b/src/redux/reducers/ui/theme.ts
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/redux/store/index.ts b/src/redux/store/index.ts
new file mode 100644
index 000000000..9ccd990e1
--- /dev/null
+++ b/src/redux/store/index.ts
@@ -0,0 +1,24 @@
+import { combineReducers, configureStore } from '@reduxjs/toolkit'
+import createSagaMiddleware from 'redux-saga'
+import rootSaga from '../sagas'
+import authSlice from '../reducers/auth'
+
+const rootReducer = combineReducers({
+ auth: authSlice,
+})
+
+const sagaMiddleware = createSagaMiddleware()
+
+export const setupStore = () => {
+ return configureStore({
+ reducer: rootReducer,
+ middleware: (getDefaultMiddleware: any) => getDefaultMiddleware()
+ .concat(sagaMiddleware),
+ })
+}
+
+export type RootState = ReturnType<typeof rootReducer>
+export type AppStore = ReturnType<typeof setupStore>
+export type AppDispatch = AppStore['dispatch']
+
+sagaMiddleware.run(rootSaga)
diff --git a/src/redux/actions/alerts/index.js b/src/redux3/actions/alerts/index.js
similarity index 100%
rename from src/redux/actions/alerts/index.js
rename to src/redux3/actions/alerts/index.js
diff --git a/src/redux/actions/alerts/types.js b/src/redux3/actions/alerts/types.js
similarity index 100%
rename from src/redux/actions/alerts/types.js
rename to src/redux3/actions/alerts/types.js
diff --git a/src/redux/actions/auth/index.js b/src/redux3/actions/auth/index.js
similarity index 100%
rename from src/redux/actions/auth/index.js
rename to src/redux3/actions/auth/index.js
diff --git a/src/redux/actions/auth/types.js b/src/redux3/actions/auth/types.js
similarity index 100%
rename from src/redux/actions/auth/types.js
rename to src/redux3/actions/auth/types.js
diff --git a/src/redux/actions/errors/index.js b/src/redux3/actions/errors/index.js
similarity index 100%
rename from src/redux/actions/errors/index.js
rename to src/redux3/actions/errors/index.js
diff --git a/src/redux/actions/errors/types.js b/src/redux3/actions/errors/types.js
similarity index 100%
rename from src/redux/actions/errors/types.js
rename to src/redux3/actions/errors/types.js
diff --git a/src/redux/actions/ui/index.js b/src/redux3/actions/ui/index.js
similarity index 100%
rename from src/redux/actions/ui/index.js
rename to src/redux3/actions/ui/index.js
diff --git a/src/redux/actions/ui/types.js b/src/redux3/actions/ui/types.js
similarity index 100%
rename from src/redux/actions/ui/types.js
rename to src/redux3/actions/ui/types.js
diff --git a/src/redux3/constants/index.ts b/src/redux3/constants/index.ts
new file mode 100644
index 000000000..2647efe70
--- /dev/null
+++ b/src/redux3/constants/index.ts
@@ -0,0 +1,349 @@
+const getCustomLabel = (dates: Date[], t: Function) => {
+ if (dates) {
+ const from = dates[0].toLocaleDateString()
+ const to = dates[1].toLocaleDateString()
+
+ if (from === to) {
+ return from
+ }
+
+ return `${from} - ${to}`
+ }
+
+ return t('project.custom')
+}
+
+export const FORECAST_MAX_MAPPING = {
+ hour: 72,
+ day: 21,
+ week: 21,
+ month: 12,
+}
+
+export const tbPeriodPairs = (t: Function, tbs: String[] | null, dates: Date[]) => [{
+ label: t('project.today'),
+ period: 'today',
+ tbs: ['hour'],
+ access: 'free',
+}, {
+ label: t('project.yesterday'),
+ period: 'yesterday',
+ tbs: ['hour'],
+ access: 'free',
+}, {
+ label: t('project.last24h'),
+ period: '1d',
+ tbs: ['hour'],
+ access: 'free',
+}, {
+ label: t('project.lastXDays', { amount: 7 }),
+ period: '7d',
+ tbs: ['hour', 'day'],
+ access: 'free',
+}, {
+ label: t('project.lastXWeeks', { amount: 4 }),
+ period: '4w',
+ tbs: ['day', 'week'],
+ access: 'free',
+}, {
+ label: t('project.lastXMonths', { amount: 3 }),
+ period: '3M',
+ tbs: ['week', 'month'],
+ access: 'free',
+}, {
+ label: t('project.lastXMonths', { amount: 12 }),
+ period: '12M',
+ tbs: ['week', 'month'],
+ access: 'paid',
+}, {
+ label: t('project.lastXMonths', { amount: 24 }),
+ period: '24M',
+ tbs: ['month'],
+ access: 'paid',
+}, {
+ label: getCustomLabel(dates, t),
+ dropdownLabel: t('project.custom'),
+ isCustomDate: true,
+ period: 'custom',
+ tbs: tbs || ['custom'],
+ access: 'free',
+}]
+
+// the order of panels in the project view
+export const TRAFFIC_PANELS_ORDER = ['cc', 'pg', 'lc', 'br', 'os', 'dv', 'ref', 'so', 'me', 'ca']
+export const PERFORMANCE_PANELS_ORDER = ['cc', 'pg', 'br', 'dv']
+
+// the maximum amount of months user can go back when picking a date in flat picker (project view)
+export const MAX_MONTHS_IN_PAST = 24
+export const MAX_MONTHS_IN_PAST_FREE = 3
+
+export const timeBucketToDays = [
+ { lt: 1, tb: ['hour'] }, // 1 days
+ { lt: 7, tb: ['hour', 'day'] }, // 7 days
+ { lt: 28, tb: ['day', 'week'] }, // 4 weeks
+ { lt: 366, tb: ['week', 'month'] }, // 12 months
+ { lt: 732, tb: ['month'] }, // 24 months
+]
+
+export const tbsFormatMapper = {
+ hour: '%d %b %H:%M',
+ day: '%d %b',
+ week: '%d %b',
+ month: '%d %b %Y',
+}
+
+export const tbsFormatMapper24h = {
+ hour: '%H:%M',
+ day: '%d %b',
+ week: '%d %b',
+ month: '%d %b %Y',
+}
+
+export const TimeFormat = {
+ '12-hour': '12-hour',
+ '24-hour': '24-hour',
+}
+
+export const FREE_TIER_KEY = 'free'
+
+// a dedicated variable is needed for paid tier checking
+export const WEEKLY_REPORT_FREQUENCY = 'weekly'
+export const reportFrequencies = [WEEKLY_REPORT_FREQUENCY, 'monthly', 'quarterly', 'never']
+
+export const reportFrequencyForEmailsOptions = [
+ { value: 'quarterly', label: 'Quarterly' },
+ { value: 'monthly', label: 'Monthly' },
+ { value: 'weekly', label: 'Weekly' },
+ { value: 'never', label: 'Never' },
+]
+
+export const GDPR_EXPORT_TIMEFRAME = 14 // days
+
+export const SHOW_BANNER_AT_PERC = 85 // show banner when 85% of events in tier are used
+
+export const TITLE_SUFFIX = '| Swetrix'
+
+export const LS_THEME_SETTING = 'colour-theme'
+export const LS_VIEW_PREFS_SETTING = 'proj-view-preferences'
+export const LS_CAPTCHA_VIEW_PREFS_SETTING = 'captcha-view-preferences'
+
+export const DEFAULT_TIMEZONE = 'Etc/GMT'
+
+export const DONATE_URL = 'https://ko-fi.com/andriir'
+export const FIREFOX_ADDON_URL = 'https://addons.mozilla.org/en-US/firefox/addon/swetrix/'
+export const CHROME_EXTENSION_URL = 'https://chrome.google.com/webstore/detail/swetrix/glbeclfdldjldjonfnpnembfkhphmeld'
+export const HAVE_I_BEEN_PWNED_URL = 'https://haveibeenpwned.com/passwords'
+export const LINKEDIN_URL = 'https://www.linkedin.com/company/swetrix/'
+export const GITHUB_URL = 'https://github.com/Swetrix'
+export const TWITTER_URL = 'https://twitter.com/intent/user?screen_name=swetrix'
+export const TWITTER_USERNAME = '@swetrix'
+export const DISCORD_URL = 'https://discord.gg/tVxGxU3s4B'
+export const STATUSPAGE_URL = 'https://stats.uptimerobot.com/33rvmiXXEz'
+export const BLOG_URL = 'https://blog.swetrix.com'
+export const UTM_GENERATOR_URL = 'https://url.swetrix.com'
+export const MARKETPLACE_URL = 'https://marketplace.swetrix.com'
+export const DOCS_URL = 'https://docs.swetrix.com'
+export const CAPTCHA_URL = 'https://captcha.swetrix.com'
+export const DOCS_CAPTCHA_URL = `${DOCS_URL}/captcha/introduction`
+export const CDN_URL = process.env.REACT_APP_CDN_URL
+
+// Swetrix vs ...
+export const SWETRIX_VS_GOOGLE = 'https://blog.swetrix.com/post/vs-google-analytics/'
+export const SWETRIX_VS_CLOUDFLARE = 'https://blog.swetrix.com/post/vs-cloudflare-analytics/'
+export const SWETRIX_VS_SIMPLE_ANALYTICS = 'https://blog.swetrix.com/post/vs-simple-analytics/'
+
+export const isDevelopment = !process.env.NODE_ENV || process.env.NODE_ENV === 'development'
+
+export const SUPPORTED_THEMES = ['light', 'dark']
+
+export const CONTACT_EMAIL = '[email protected]'
+export const SECURITY_EMAIL = '[email protected]'
+
+export const isSelfhosted = Boolean(process.env.REACT_APP_SELFHOSTED)
+
+export const LIVE_VISITORS_UPDATE_INTERVAL = 40000
+export const GENERAL_STATS_UPDATE_INTERVAL = 60000
+
+// Functions
+export const getProjectCacheKey = (period: string, timeBucket: string) => `${period}${timeBucket}`
+export const getProjectCaptchaCacheKey = (period: string, timeBucket: string) => `${period}${timeBucket}captcha`
+export const getProjectForcastCacheKey = (period: string, timeBucket: string, periodToForecast: string) => `${period}${timeBucket}${periodToForecast}forecast`
+export const getProjectCacheCustomKey = (from: string, to: string, timeBucket: string) => `${from}-${to}-${timeBucket}`
+
+// Cookies
+export const GDPR_REQUEST = 'gdpr_request'
+export const CONFIRMATION_TIMEOUT = 'confirmation_timeout'
+export const LOW_EVENTS_WARNING = 'low_events_warning'
+export const TOKEN = 'access_token'
+export const REFRESH_TOKEN = 'refresh_token'
+
+// List of languages with translations available
+export const whitelist = ['en', 'uk', 'pl', 'de', 'sv', 'el', 'ru', 'hi', 'zh']
+export const defaultLanguage = 'en'
+export const languages = {
+ en: 'English',
+ uk: 'Українська',
+ pl: 'Polski',
+ de: 'Deutsch',
+ sv: 'Svenska',
+ el: 'Ελληνικά',
+ ru: 'Русский',
+ hi: 'हिन्दी',
+ zh: '中文简体',
+}
+
+export const languageFlag = {
+ en: 'GB',
+ uk: 'UA',
+ pl: 'PL',
+ de: 'DE',
+ sv: 'SE',
+ el: 'GR',
+ ru: 'RU',
+ hi: 'IN',
+ zh: 'CN',
+}
+
+export const paddleLanguageMapping = {
+ zh: 'zh-Hans',
+ uk: 'ru',
+ el: 'en',
+}
+
+// dashboard && projects
+
+export const roles = ['admin', 'viewer']
+
+export const roleViewer = {
+ name: 'Viewer',
+ role: 'viewer',
+ description: 'Can view the project',
+}
+
+export const roleAdmin = {
+ name: 'Admin',
+ role: 'admin',
+ description: 'Can manage the project',
+}
+
+export const tabForOwnedProject = 'owned'
+export const tabForSharedProject = 'shared'
+export const tabForCaptchaProject = 'captcha'
+
+export const tabsForDashboard = [
+ {
+ name: tabForOwnedProject,
+ label: 'profileSettings.owned',
+ },
+ {
+ name: tabForSharedProject,
+ label: 'profileSettings.shared',
+ },
+ {
+ name: tabForCaptchaProject,
+ label: 'profileSettings.captcha',
+ },
+]
+
+export const PROJECT_TABS = {
+ traffic: 'traffic',
+ performance: 'performance',
+ alerts: 'alerts',
+}
+
+export const DASHBOARD_TABS = {
+ owned: 'owned',
+ shared: 'shared',
+ captcha: 'captcha',
+}
+
+export const QUERY_METRIC = {
+ PAGE_VIEWS: 'page_views',
+ UNIQUE_PAGE_VIEWS: 'unique_page_views',
+ ONLINE_USERS: 'online_users',
+}
+
+export const QUERY_CONDITION = {
+ GREATER_THAN: 'greater_than',
+ GREATER_EQUAL_THAN: 'greater_equal_than',
+ LESS_THAN: 'less_than',
+ LESS_EQUAL_THAN: 'less_equal_than',
+}
+
+export const QUERY_TIME = {
+ LAST_15_MINUTES: 'last_15_minutes',
+ LAST_30_MINUTES: 'last_30_minutes',
+ LAST_1_HOUR: 'last_1_hour',
+ LAST_4_HOURS: 'last_4_hours',
+ LAST_24_HOURS: 'last_24_hours',
+ LAST_48_HOURS: 'last_48_hours',
+}
+
+export const INVITATION_EXPIRES_IN = 48 // hours
+export const ENTRIES_PER_PAGE_DASHBOARD = 10
+
+export const THEME_TYPE = {
+ classic: 'classic',
+ christmas: 'christmas',
+}
+
+export const DEFAULT_ALERTS_TAKE = 100
+
+// TODO: Eventually this should be fetched from the API, e.g. GET /config route
+export const PLAN_LIMITS = {
+ free: {
+ priceMonthly: 0,
+ priceYearly: 0,
+ monthlyUsageLimit: 5000,
+ maxProjects: 10,
+ maxAlerts: 1,
+ legacy: true,
+ },
+ trial: {
+ monthlyUsageLimit: 100000,
+ maxProjects: 20,
+ maxAlerts: 20,
+ legacy: false,
+ priceMonthly: 0,
+ priceYearly: 0,
+ },
+ hobby: {
+ monthlyUsageLimit: 10000,
+ maxProjects: 20,
+ maxAlerts: 10,
+ legacy: false,
+ priceMonthly: 5,
+ priceYearly: 50,
+ },
+ freelancer: {
+ monthlyUsageLimit: 100000,
+ maxProjects: 20,
+ maxAlerts: 20,
+ legacy: false,
+ priceMonthly: 15,
+ priceYearly: 150,
+ },
+ startup: {
+ monthlyUsageLimit: 1000000,
+ maxProjects: 30,
+ maxAlerts: 50,
+ legacy: false,
+ priceMonthly: 59,
+ priceYearly: 590,
+ },
+ enterprise: {
+ monthlyUsageLimit: 5000000,
+ maxProjects: 50,
+ maxAlerts: 100,
+ legacy: false,
+ priceMonthly: 110,
+ priceYearly: 1100,
+ },
+}
+
+export const TRIAL_DAYS = 14
+
+export const chartTypes = {
+ line: 'line',
+ bar: 'bar',
+}
diff --git a/src/redux/reducers/alerts.js b/src/redux3/reducers/alerts.js
similarity index 100%
rename from src/redux/reducers/alerts.js
rename to src/redux3/reducers/alerts.js
diff --git a/src/redux/reducers/auth.js b/src/redux3/reducers/auth.js
similarity index 100%
rename from src/redux/reducers/auth.js
rename to src/redux3/reducers/auth.js
diff --git a/src/redux/reducers/errors.js b/src/redux3/reducers/errors.ts
similarity index 88%
rename from src/redux/reducers/errors.js
rename to src/redux3/reducers/errors.ts
index 0e6a2be27..c04635001 100644
--- a/src/redux/reducers/errors.js
+++ b/src/redux3/reducers/errors.ts
@@ -1,6 +1,10 @@
import { types } from 'redux/actions/errors/types'
-const initialState = {
+interface initialStateInterface {
+ error: string | null
+}
+
+const initialState: initialStateInterface = {
error: null,
}
diff --git a/src/redux/reducers/index.js b/src/redux3/reducers/index.ts
similarity index 100%
rename from src/redux/reducers/index.js
rename to src/redux3/reducers/index.ts
diff --git a/src/redux3/sagas/auth/watchers/index.js b/src/redux3/sagas/auth/watchers/index.js
new file mode 100644
index 000000000..0e3cb93b7
--- /dev/null
+++ b/src/redux3/sagas/auth/watchers/index.js
@@ -0,0 +1,40 @@
+import { takeLatest, all, call } from 'redux-saga/effects'
+import { types } from 'redux/actions/auth/types'
+import signIn from 'redux/sagas/auth/workers/signin'
+import signUp from 'redux/sagas/auth/workers/signup'
+import logout from 'redux/sagas/auth/workers/logout'
+import verifyEmail from 'redux/sagas/auth/workers/verifyEmail'
+import updateUserProfile from 'redux/sagas/auth/workers/updateUserProfile'
+import deleteUserAccount from 'redux/sagas/auth/workers/deleteUserAccount'
+
+function* watchLogin() {
+ yield takeLatest(types.LOGIN_ASYNC, signIn)
+}
+
+function* watchVerifyEmail() {
+ yield takeLatest(types.EMAIL_VERIFY_ASYNC, verifyEmail)
+}
+
+function* watchSignup() {
+ yield takeLatest(types.SIGNUP_ASYNC, signUp)
+}
+
+function* watchLogout() {
+ yield takeLatest(types.LOGOUT, logout)
+}
+
+function* watchUpdateUserProfile() {
+ yield takeLatest(types.UPDATE_USER_PROFILE_ASYNC, updateUserProfile)
+}
+
+function* watchDeleteUserProfile() {
+ yield takeLatest(types.DELETE_ACCOUNT_ASYNC, deleteUserAccount)
+}
+
+export default function* watchAuth() {
+ yield all([
+ call(watchLogin), call(watchSignup), call(watchVerifyEmail),
+ call(watchUpdateUserProfile), call(watchDeleteUserProfile),
+ call(watchLogout),
+ ])
+}
diff --git a/src/redux3/sagas/auth/workers/deleteUserAccount.js b/src/redux3/sagas/auth/workers/deleteUserAccount.js
new file mode 100644
index 000000000..1d1a09466
--- /dev/null
+++ b/src/redux3/sagas/auth/workers/deleteUserAccount.js
@@ -0,0 +1,26 @@
+import { call, put } from 'redux-saga/effects'
+
+import { authActions } from 'redux/actions/auth'
+import { alertsActions } from 'redux/actions/alerts'
+import { deleteUser } from 'api'
+
+export default function* deleteUserAccountWorker({ payload: { errorCallback, successCallback, t } }) {
+ try {
+ yield call(deleteUser)
+ yield call(successCallback)
+ yield put(authActions.deleteAccountSuccess())
+ yield put(alertsActions.accountDeleted(t('apiNotifications.accountDeleted')))
+ } catch (error) {
+ let message
+
+ try {
+ message = JSON.parse(error.message).message || 'somethingWentWrong'
+ } catch (e) {
+ message = 'somethingWentWrong'
+ }
+
+ errorCallback(t([`apiNotifications.${message}`, 'apiNotifications.somethingWentWrong']))
+ } finally {
+ yield put(authActions.finishLoading())
+ }
+}
diff --git a/src/redux3/sagas/auth/workers/logout.js b/src/redux3/sagas/auth/workers/logout.js
new file mode 100644
index 000000000..23b5adbad
--- /dev/null
+++ b/src/redux3/sagas/auth/workers/logout.js
@@ -0,0 +1,18 @@
+import { call, put } from 'redux-saga/effects'
+import Debug from 'debug'
+
+import UIActions from 'redux/actions/ui'
+import { getGeneralStats } from 'api'
+
+const debug = Debug('swetrix:rx:s:logout')
+
+export default function* logoutWorker({ payload: { basedOn401Error } = {} }) {
+ try {
+ if (!basedOn401Error) {
+ const stats = yield call(getGeneralStats)
+ yield put(UIActions.setGeneralStats(stats))
+ }
+ } catch (e) {
+ debug('Error while getting general stats data: %s', e)
+ }
+}
diff --git a/src/redux3/sagas/auth/workers/signin.js b/src/redux3/sagas/auth/workers/signin.js
new file mode 100644
index 000000000..c568a645d
--- /dev/null
+++ b/src/redux3/sagas/auth/workers/signin.js
@@ -0,0 +1,44 @@
+import { call, put } from 'redux-saga/effects'
+import { authActions } from 'redux/actions/auth'
+import { errorsActions } from 'redux/actions/errors'
+import _isObject from 'lodash/isPlainObject'
+import _omit from 'lodash/omit'
+
+import UIActions from 'redux/actions/ui'
+import { setAccessToken } from 'utils/accessToken'
+import { login } from 'api'
+import { setRefreshToken } from 'utils/refreshToken'
+
+export default function* singinWorker({ payload: { credentials, callback } }) {
+ try {
+ const { dontRemember } = credentials
+ const {
+ user, accessToken, refreshToken,
+ } = yield call(login, _omit(credentials, ['dontRemember']))
+
+ yield put(authActions.setDontRemember(dontRemember))
+
+ if (user.isTwoFactorAuthenticationEnabled) {
+ yield call(setAccessToken, accessToken, true)
+ yield call(setRefreshToken, refreshToken)
+ yield put(authActions.updateUserData(user))
+ callback(false, true)
+ return
+ }
+
+ yield put(authActions.loginSuccess(user))
+ yield call(setAccessToken, accessToken, dontRemember)
+ yield call(setRefreshToken, refreshToken)
+ yield put(UIActions.setThemeType(user.theme))
+ yield put(UIActions.loadProjects())
+ yield put(UIActions.loadSharedProjects())
+ yield put(UIActions.loadProjectAlerts())
+ callback(true, false)
+ } catch (error) {
+ const err = _isObject(error) ? error.message : error
+ yield put(errorsActions.loginFailed(err || 'apiNotifications.somethingWentWrong'))
+ callback(false, false)
+ } finally {
+ yield put(authActions.finishLoading())
+ }
+}
diff --git a/src/redux3/sagas/auth/workers/signup.js b/src/redux3/sagas/auth/workers/signup.js
new file mode 100644
index 000000000..58b100196
--- /dev/null
+++ b/src/redux3/sagas/auth/workers/signup.js
@@ -0,0 +1,35 @@
+import { call, put } from 'redux-saga/effects'
+import { authActions } from 'redux/actions/auth'
+import { errorsActions } from 'redux/actions/errors'
+import _omit from 'lodash/omit'
+
+import UIActions from 'redux/actions/ui'
+import { setAccessToken } from 'utils/accessToken'
+import { signup } from 'api'
+import { setRefreshToken } from 'utils/refreshToken'
+
+export default function* signupWorder({ payload: { data: rawData, callback } }) {
+ try {
+ const { repeat, ...data } = rawData
+ const { dontRemember } = data
+ const {
+ user, accessToken, refreshToken, // theme,
+ } = yield call(signup, _omit(data, ['dontRemember']))
+
+ yield put(authActions.signupSuccess(user))
+ yield call(setAccessToken, accessToken, dontRemember)
+ yield call(setRefreshToken, refreshToken)
+ yield put(authActions.setDontRemember(dontRemember))
+ // yield put(UIActions.setThemeType(response.theme))
+ yield put(UIActions.loadProjects())
+ yield put(UIActions.loadSharedProjects())
+ yield put(UIActions.loadProjectAlerts())
+ callback(true)
+ } catch (error) {
+ const message = error.message || (typeof error === 'string' ? error : error[0])
+ yield put(errorsActions.signupFailed(message || 'apiNotifications.somethingWentWrong'))
+ callback(false)
+ } finally {
+ yield put(authActions.finishLoading())
+ }
+}
diff --git a/src/redux3/sagas/auth/workers/updateUserProfile.js b/src/redux3/sagas/auth/workers/updateUserProfile.js
new file mode 100644
index 000000000..aada1db8d
--- /dev/null
+++ b/src/redux3/sagas/auth/workers/updateUserProfile.js
@@ -0,0 +1,20 @@
+import { call, put } from 'redux-saga/effects'
+
+import { authActions } from 'redux/actions/auth'
+import { errorsActions } from 'redux/actions/errors'
+import { changeUserDetails } from 'api'
+
+export default function* updateUserProfileWorker({ payload: { data, callback } }) {
+ let isSuccess = false
+ try {
+ const user = yield call(changeUserDetails, data)
+
+ yield put(authActions.updateProfileSuccess(user))
+ isSuccess = true
+ } catch (error) {
+ yield put(errorsActions.updateProfileFailed(error.message || (typeof error === 'string' ? error : error[0])))
+ } finally {
+ yield put(authActions.finishLoading())
+ callback(isSuccess)
+ }
+}
diff --git a/src/redux3/sagas/auth/workers/verifyEmail.js b/src/redux3/sagas/auth/workers/verifyEmail.js
new file mode 100644
index 000000000..5ca09fdb8
--- /dev/null
+++ b/src/redux3/sagas/auth/workers/verifyEmail.js
@@ -0,0 +1,16 @@
+import { call, put } from 'redux-saga/effects'
+
+import { authActions } from 'redux/actions/auth'
+import { verifyEmail } from 'api'
+
+export default function* verifyEmailWorker({ payload: { data, successfulCallback, errorCallback } }) {
+ try {
+ yield call(verifyEmail, data)
+ yield put(authActions.emailVerifySuccess())
+ successfulCallback()
+ } catch (error) {
+ errorCallback(error)
+ } finally {
+ yield put(authActions.finishLoading())
+ }
+}
diff --git a/src/redux3/sagas/index.js b/src/redux3/sagas/index.js
new file mode 100644
index 000000000..8287aea30
--- /dev/null
+++ b/src/redux3/sagas/index.js
@@ -0,0 +1,8 @@
+import { fork } from 'redux-saga/effects'
+import watchAuth from './auth/watchers'
+import uiSaga from './ui'
+
+export default function* rootSaga() {
+ yield fork(watchAuth)
+ yield fork(uiSaga)
+}
diff --git a/src/redux3/sagas/ui/index.js b/src/redux3/sagas/ui/index.js
new file mode 100644
index 000000000..c07f6281d
--- /dev/null
+++ b/src/redux3/sagas/ui/index.js
@@ -0,0 +1,31 @@
+import { takeEvery, fork, takeLatest } from 'redux-saga/effects'
+import { types } from '../../actions/ui/types'
+import { types as authTypes } from '../../actions/auth/types'
+
+import loadProjects from './load_projects'
+import initialise from './initialise'
+import liveVisitors from './worker_live_visitors'
+import generalStats from './worker_general_stats'
+import setProjectViewPrefs from './set_project_view_prefs'
+import isEventsAvailable from './worker_is_events_available'
+import shareVerify from './share_verify'
+import loadExtensions from './load_extensions'
+import logout from './logout'
+import loadSharedProjects from './load_shared_projects'
+import loadProjectAlerts from './load_alerts'
+
+function* mainUISaga() {
+ yield fork(initialise)
+ yield fork(liveVisitors)
+ yield fork(isEventsAvailable)
+ yield fork(generalStats)
+ yield takeEvery(types.SET_PROJECT_VIEW_PREFS, setProjectViewPrefs)
+ yield takeEvery(types.LOAD_PROJECTS, loadProjects)
+ yield takeEvery(types.LOAD_SHARED_PROJECTS, loadSharedProjects)
+ yield takeEvery(types.LOAD_EXTENSIONS, loadExtensions)
+ yield takeEvery(authTypes.LOGOUT, logout)
+ yield takeLatest(types.SHARE_VERIFY_ASYNC, shareVerify)
+ yield takeLatest(types.LOAD_PROJECT_ALERTS, loadProjectAlerts)
+}
+
+export default mainUISaga
diff --git a/src/redux3/sagas/ui/initialise.js b/src/redux3/sagas/ui/initialise.js
new file mode 100644
index 000000000..ce9ac621e
--- /dev/null
+++ b/src/redux3/sagas/ui/initialise.js
@@ -0,0 +1,29 @@
+import { put, call } from 'redux-saga/effects'
+import Debug from 'debug'
+
+import { getAccessToken } from 'utils/accessToken'
+import { getRefreshToken } from 'utils/refreshToken'
+import { getLastPost } from 'api/blog'
+import UIActions from 'redux/actions/ui'
+
+const debug = Debug('swetrix:rx:s:initialise')
+
+export default function* initialise() {
+ try {
+ const token = yield call(getAccessToken)
+ const refreshToken = yield call(getRefreshToken)
+
+ if (token && refreshToken) {
+ yield put(UIActions.loadProjects())
+ yield put(UIActions.loadSharedProjects())
+ yield put(UIActions.loadProjectsCaptcha())
+ yield put(UIActions.loadExtensions())
+ yield put(UIActions.loadProjectAlerts())
+ }
+
+ const lastBlogPost = yield call(getLastPost)
+ yield put(UIActions.setLastBlogPost(lastBlogPost))
+ } catch (e) {
+ debug('An error occured whilst initialising: %s', e)
+ }
+}
diff --git a/src/redux3/sagas/ui/load_alerts.js b/src/redux3/sagas/ui/load_alerts.js
new file mode 100644
index 000000000..fea0b9010
--- /dev/null
+++ b/src/redux3/sagas/ui/load_alerts.js
@@ -0,0 +1,26 @@
+import { put, call } from 'redux-saga/effects'
+import Debug from 'debug'
+import _isString from 'lodash/isString'
+import UIActions from 'redux/actions/ui'
+import { errorsActions } from 'redux/actions/errors'
+import { DEFAULT_ALERTS_TAKE } from 'redux/constants'
+import { getAlerts } from 'api'
+
+const debug = Debug('swetrix:rx:s:load-extensions')
+
+export default function* loadProjectAlerts({ payload: { take = DEFAULT_ALERTS_TAKE, skip = 0 } }) {
+ try {
+ yield put(UIActions.setProjectAlertsLoading(true))
+ const { results, total, page_total: pageTotal } = yield call(getAlerts, take, skip)
+
+ yield put(UIActions.setProjectAlerts(results))
+ yield put(UIActions.setProjectAlertsTotal(total, pageTotal))
+ } catch ({ message }) {
+ if (_isString(message)) {
+ yield put(errorsActions.setError(message))
+ }
+ debug('failed to load extensions: %s', message)
+ } finally {
+ yield put(UIActions.setProjectAlertsLoading(false))
+ }
+}
diff --git a/src/redux3/sagas/ui/load_extensions.js b/src/redux3/sagas/ui/load_extensions.js
new file mode 100644
index 000000000..1d49b5672
--- /dev/null
+++ b/src/redux3/sagas/ui/load_extensions.js
@@ -0,0 +1,23 @@
+import { put, call } from 'redux-saga/effects'
+import Debug from 'debug'
+
+import UIActions from 'redux/actions/ui'
+
+import {
+ getInstalledExtensions,
+} from '../../../api'
+
+const debug = Debug('swetrix:rx:s:load-extensions')
+
+export default function* loadExtensions() {
+ try {
+ const { extensions } = yield call(getInstalledExtensions)
+
+ yield put(UIActions.setExtensions(extensions))
+ } catch ({ message }) {
+ // if (_isString(message)) {
+ // yield put(UIActions.setProjectsError(message))
+ // }
+ debug('failed to load extensions: %s', message)
+ }
+}
diff --git a/src/redux3/sagas/ui/load_forecast.js b/src/redux3/sagas/ui/load_forecast.js
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/redux3/sagas/ui/load_projects.js b/src/redux3/sagas/ui/load_projects.js
new file mode 100644
index 000000000..74bac29a4
--- /dev/null
+++ b/src/redux3/sagas/ui/load_projects.js
@@ -0,0 +1,67 @@
+import { put, call } from 'redux-saga/effects'
+import _map from 'lodash/map'
+import _isString from 'lodash/isString'
+import Debug from 'debug'
+
+import UIActions from 'redux/actions/ui'
+
+import { ENTRIES_PER_PAGE_DASHBOARD } from 'redux/constants'
+import {
+ getProjects, getOverallStats, getLiveVisitors, getOverallStatsCaptcha,
+} from '../../../api'
+
+const debug = Debug('swetrix:rx:s:load-projects')
+
+export default function* loadProjects({ payload: { take = ENTRIES_PER_PAGE_DASHBOARD, skip = 0, isCaptcha = false } }) {
+ try {
+ if (isCaptcha) {
+ yield put(UIActions.setCaptchaLoading(true))
+ } else {
+ yield put(UIActions.setProjectsLoading(true))
+ }
+
+ let {
+ // eslint-disable-next-line prefer-const
+ results, totalMonthlyEvents, total,
+ } = yield call(getProjects, take, skip, isCaptcha)
+
+ const pids = _map(results, result => result.id)
+ let overall
+
+ if (isCaptcha) {
+ try {
+ overall = yield call(getOverallStatsCaptcha, pids)
+ } catch (e) {
+ debug('failed to overall stats: %s', e)
+ }
+ } else {
+ try {
+ overall = yield call(getOverallStats, pids)
+ } catch (e) {
+ debug('failed to overall stats: %s', e)
+ }
+ }
+
+ results = _map(results, res => ({
+ ...res,
+ overall: overall?.[res.id],
+ }))
+
+ if (isCaptcha) {
+ yield put(UIActions.setCaptchaProjects(results))
+ yield put(UIActions.setTotalCaptcha(total))
+ } else {
+ yield put(UIActions.setProjects(results))
+ yield put(UIActions.setTotalMonthlyEvents(totalMonthlyEvents))
+ yield put(UIActions.setTotal(total))
+ }
+
+ const liveStats = yield call(getLiveVisitors, pids)
+ yield put(UIActions.setLiveStats(liveStats))
+ } catch ({ message }) {
+ if (_isString(message)) {
+ yield put(UIActions.setProjectsError(message))
+ }
+ debug('failed to load projects: %s', message)
+ }
+}
diff --git a/src/redux3/sagas/ui/load_shared_projects.js b/src/redux3/sagas/ui/load_shared_projects.js
new file mode 100644
index 000000000..494c7a14a
--- /dev/null
+++ b/src/redux3/sagas/ui/load_shared_projects.js
@@ -0,0 +1,66 @@
+import { put, call } from 'redux-saga/effects'
+import _map from 'lodash/map'
+import _isString from 'lodash/isString'
+import Debug from 'debug'
+
+import UIActions from 'redux/actions/ui'
+
+import { ENTRIES_PER_PAGE_DASHBOARD } from 'redux/constants'
+import {
+ getSharedProjects, getOverallStats, getLiveVisitors,
+} from '../../../api'
+
+const debug = Debug('swetrix:rx:s:load-projects')
+
+export default function* loadSharedProjects({ payload: { take = ENTRIES_PER_PAGE_DASHBOARD, skip = 0 } }) {
+ try {
+ yield put(UIActions.setProjectsLoading(true, true))
+
+ let {
+ // eslint-disable-next-line prefer-const
+ results, total,
+ } = yield call(getSharedProjects, take, skip)
+
+ if (total === 0) {
+ return
+ }
+
+ const projectsWithShared = _map(results, (result) => {
+ return {
+ ...result,
+ project: {
+ ...result.project,
+ shared: true,
+ },
+ }
+ })
+ const pids = _map(projectsWithShared, ({ project }) => project.id)
+
+ let overall
+
+ try {
+ overall = yield call(getOverallStats, pids)
+ } catch (e) {
+ debug('failed to overall stats: %s', e)
+ }
+
+ results = _map(projectsWithShared, res => ({
+ ...res,
+ project: {
+ ...res.project,
+ overall: overall?.[res.project.id],
+ },
+ }))
+
+ yield put(UIActions.setProjects(results, true))
+ yield put(UIActions.setTotal(total, true))
+
+ const liveStats = yield call(getLiveVisitors, pids)
+ yield put(UIActions.setLiveStats(liveStats, true))
+ } catch ({ message }) {
+ if (_isString(message)) {
+ yield put(UIActions.setProjectsError(message))
+ }
+ debug('failed to load shared projects: %s', message)
+ }
+}
diff --git a/src/redux3/sagas/ui/logout.js b/src/redux3/sagas/ui/logout.js
new file mode 100644
index 000000000..cb661f35c
--- /dev/null
+++ b/src/redux3/sagas/ui/logout.js
@@ -0,0 +1,11 @@
+import { put } from 'redux-saga/effects'
+
+import UIActions from 'redux/actions/ui'
+
+export default function* logout() {
+ yield put(UIActions.setProjects([]))
+ yield put(UIActions.setProjects([], true))
+ yield put(UIActions.setTotal(0))
+ yield put(UIActions.setTotal(0, true))
+ yield put(UIActions.deleteProjectCache())
+}
diff --git a/src/redux3/sagas/ui/set_project_view_prefs.js b/src/redux3/sagas/ui/set_project_view_prefs.js
new file mode 100644
index 000000000..7bdc3cfa5
--- /dev/null
+++ b/src/redux3/sagas/ui/set_project_view_prefs.js
@@ -0,0 +1,21 @@
+import { LS_VIEW_PREFS_SETTING } from 'redux/constants'
+import { getInitialViewPrefs } from 'redux/reducers/ui/cache'
+
+export default function setProjectViewPrefs({
+ payload: {
+ pid, period, timeBucket, rangeDate,
+ },
+}) {
+ if (typeof window !== 'undefined' && window.localStorage) {
+ const viewPrefs = {
+ ...getInitialViewPrefs(),
+ [pid]: rangeDate ? {
+ period, timeBucket, rangeDate,
+ } : {
+ period, timeBucket,
+ },
+ }
+
+ window.localStorage.setItem(LS_VIEW_PREFS_SETTING, JSON.stringify(viewPrefs))
+ }
+}
diff --git a/src/redux3/sagas/ui/share_verify.js b/src/redux3/sagas/ui/share_verify.js
new file mode 100644
index 000000000..4bd036917
--- /dev/null
+++ b/src/redux3/sagas/ui/share_verify.js
@@ -0,0 +1,15 @@
+import { call, put } from 'redux-saga/effects'
+
+import UIActions from 'redux/actions/ui'
+import { verifyShare } from 'api'
+
+export default function* shareVerify({ payload: { data, successfulCallback, errorCallback } }) {
+ try {
+ yield call(verifyShare, data)
+ yield put(UIActions.loadProjects())
+ yield put(UIActions.loadSharedProjects())
+ successfulCallback()
+ } catch (error) {
+ errorCallback(error)
+ }
+}
diff --git a/src/redux3/sagas/ui/worker_general_stats.js b/src/redux3/sagas/ui/worker_general_stats.js
new file mode 100644
index 000000000..e3984f2bb
--- /dev/null
+++ b/src/redux3/sagas/ui/worker_general_stats.js
@@ -0,0 +1,32 @@
+import {
+ put, call, delay, select,
+} from 'redux-saga/effects'
+import Debug from 'debug'
+
+import { getGeneralStats } from 'api'
+import UIActions from 'redux/actions/ui'
+import { GENERAL_STATS_UPDATE_INTERVAL } from 'redux/constants'
+
+const debug = Debug('swetrix:rx:s:general-stats')
+
+const NOT_AUTHED_INTERVAL = 5000 // 5 seconds
+
+export default function* generalStats() {
+ while (true) {
+ const isAuthenticated = yield select(state => state.auth.authenticated)
+ if (isAuthenticated) {
+ yield delay(NOT_AUTHED_INTERVAL)
+ continue
+ }
+
+ try {
+ const stats = yield call(getGeneralStats)
+
+ yield put(UIActions.setGeneralStats(stats))
+ } catch (e) {
+ debug('Error while getting general stats data: %s', e)
+ }
+
+ yield delay(GENERAL_STATS_UPDATE_INTERVAL)
+ }
+}
diff --git a/src/redux3/sagas/ui/worker_is_events_available.js b/src/redux3/sagas/ui/worker_is_events_available.js
new file mode 100644
index 000000000..e88058dba
--- /dev/null
+++ b/src/redux3/sagas/ui/worker_is_events_available.js
@@ -0,0 +1,51 @@
+import { put, delay, select } from 'redux-saga/effects'
+import _isNull from 'lodash/isNull'
+
+import UIActions from 'redux/actions/ui'
+import { SHOW_BANNER_AT_PERC, LOW_EVENTS_WARNING } from 'redux/constants'
+import { getCookie } from 'utils/cookie'
+
+const NOT_AUTHED_INTERVAL = 1000 // 1 second
+const NO_DATA_YET = 1000 // 1 second
+const DATA_REQUEST_ATTEMPTS = 20
+
+export default function* checkEventsAvailable() {
+ const lowEvents = getCookie(LOW_EVENTS_WARNING)
+
+ if (lowEvents) {
+ return
+ }
+
+ let dataRequests = 0
+
+ while (true) {
+ if (dataRequests > DATA_REQUEST_ATTEMPTS) {
+ return
+ }
+
+ const isAuthenticated = yield select(state => state.auth.authenticated)
+
+ if (!isAuthenticated) {
+ yield delay(NOT_AUTHED_INTERVAL)
+ continue
+ }
+
+ const totalMonthlyEvents = yield select(state => state.ui.projects.totalMonthlyEvents)
+
+ if (_isNull(totalMonthlyEvents)) {
+ dataRequests++
+ yield delay(NO_DATA_YET)
+ continue
+ }
+
+ const maxEventsCount = yield select(state => state.auth.user.maxEventsCount)
+
+ const eventsUsedPercentage = (totalMonthlyEvents * 100) / maxEventsCount
+
+ if (eventsUsedPercentage >= SHOW_BANNER_AT_PERC) {
+ yield put(UIActions.setShowNoEventsLeftBanner(true))
+ }
+
+ return
+ }
+}
diff --git a/src/redux3/sagas/ui/worker_live_visitors.js b/src/redux3/sagas/ui/worker_live_visitors.js
new file mode 100644
index 000000000..ba999818d
--- /dev/null
+++ b/src/redux3/sagas/ui/worker_live_visitors.js
@@ -0,0 +1,50 @@
+import {
+ put, call, delay, select,
+} from 'redux-saga/effects'
+import _map from 'lodash/map'
+import _filter from 'lodash/filter'
+import _isEmpty from 'lodash/isEmpty'
+
+import { getLiveVisitors } from 'api'
+import UIActions from 'redux/actions/ui'
+import { LIVE_VISITORS_UPDATE_INTERVAL, tabForSharedProject } from 'redux/constants'
+
+export default function* liveVisitors() {
+ while (true) {
+ yield delay(LIVE_VISITORS_UPDATE_INTERVAL)
+ const tab = yield select(state => state.ui.projects.dashboardTabs)
+
+ if (tabForSharedProject === tab) {
+ const sharedProjects = yield select(state => state.ui.projects.sharedProjects)
+
+ if (_isEmpty(sharedProjects)) {
+ continue
+ }
+
+ const pids = _map(_filter(sharedProjects, ({ project }) => !project.uiHidden), item => item.project.id)
+
+ if (_isEmpty(pids)) {
+ continue
+ }
+
+ const liveStats = yield call(getLiveVisitors, pids)
+
+ yield put(UIActions.setLiveStats(liveStats, true))
+ } else {
+ const projects = yield select(state => state.ui.projects.projects)
+ if (_isEmpty(projects)) {
+ continue
+ }
+
+ const pids = _map(_filter(projects, ({ uiHidden }) => !uiHidden), project => project.id)
+
+ if (_isEmpty(pids)) {
+ continue
+ }
+
+ const liveStats = yield call(getLiveVisitors, pids)
+
+ yield put(UIActions.setLiveStats(liveStats))
+ }
+ }
+}
diff --git a/src/redux/store/index.js b/src/redux3/store/index.ts
similarity index 79%
rename from src/redux/store/index.js
rename to src/redux3/store/index.ts
index 032f4635e..857c5d1cc 100644
--- a/src/redux/store/index.js
+++ b/src/redux3/store/index.ts
@@ -3,7 +3,8 @@ import createSagaMiddleware from 'redux-saga'
import rootReducer from 'redux/reducers'
import rootSaga from 'redux/sagas'
-const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
+// @ts-ignore
+const composeEnhancers = window?.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
const sagaMiddleware = createSagaMiddleware()
export const store = createStore(
diff --git a/src/redux3/types/IAuth.ts b/src/redux3/types/IAuth.ts
new file mode 100644
index 000000000..99ebe9b8d
--- /dev/null
+++ b/src/redux3/types/IAuth.ts
@@ -0,0 +1,7 @@
+import { IUser } from './IUser'
+
+export interface IAuth {
+ refresh_token: string
+ access_token: string
+ user: IUser
+}
diff --git a/src/redux3/types/IProject.ts b/src/redux3/types/IProject.ts
new file mode 100644
index 000000000..7f77a7a88
--- /dev/null
+++ b/src/redux3/types/IProject.ts
@@ -0,0 +1,37 @@
+export interface IOverall {
+ thisWeek: number
+ lastWeek: number
+ thisWeekUnique: number
+ lastWeekUnique: number
+}
+
+export interface IUserShareProject {
+ email: string
+}
+
+export interface IShareOwnerProject {
+ id: string
+ confirmed: boolean
+ role: string
+ created: string
+ updated: string
+ user: IUserShareProject
+}
+
+export interface IProject {
+ id: string
+ name: string
+ origins: string[]
+ ipBlacklist: string[] | null
+ active: boolean
+ public: boolean
+ isAnalyticsProject: boolean
+ isCaptchaProject: boolean
+ isCaptchaEnabled: boolean
+ captchaSecretKey: string | null
+ created: string
+ share: IShareOwnerProject[]
+ isOwner: boolean
+ overall: IOverall
+ live: number
+}
diff --git a/src/redux3/types/ISharedProject.ts b/src/redux3/types/ISharedProject.ts
new file mode 100644
index 000000000..46f4dfe29
--- /dev/null
+++ b/src/redux3/types/ISharedProject.ts
@@ -0,0 +1,10 @@
+import { IProject } from './IProject'
+
+export interface ISharedProject {
+ id: string
+ confirmed: boolean
+ role: string
+ created: string
+ updated: string
+ project: IProject
+}
diff --git a/src/redux3/types/IUser.ts b/src/redux3/types/IUser.ts
new file mode 100644
index 000000000..8d0bf7624
--- /dev/null
+++ b/src/redux3/types/IUser.ts
@@ -0,0 +1,32 @@
+import { ISharedProject } from './ISharedProject'
+
+export interface IUser {
+ id: string
+ roles: string[]
+ planCode: string
+ nickname: string
+ email: string
+ isActive: boolean
+ trialEndDate: string
+ reportFrequency: string
+ emailRequests: number
+ created: string
+ updated: string
+ evWarningSentOn: string | null
+ exportedAt: string
+ subID: string | null
+ subUpdateURL: string | null
+ subCancelURL: string | null
+ timezone: string
+ theme: string | null
+ isTwoFactorAuthenticationEnabled: boolean
+ trialReminderSent: boolean
+ billingFrequency: string | null
+ nextBillDate: string | null
+ cancellationEffectiveDate: string | null
+ apiKey: string | null
+ telegramChatId: string
+ isTelegramChatIdConfirmed: boolean
+ timeFormat: string
+ sharedProjects: ISharedProject[]
+}