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!

Migrate from react-alert to sonner

Blue Mouse0d9bf42744db
diff --git a/app/App.tsx b/app/App.tsx
index 8bca47b2c..e6f639e85 100644
--- a/app/App.tsx
+++ b/app/App.tsx
@@ -2,8 +2,6 @@ import React, { useEffect } from 'react'
import { useLocation, Outlet } from '@remix-run/react'
import { useSelector } from 'react-redux'
import { useTranslation } from 'react-i18next'
-// @ts-ignore
-import { useAlert } from '@blaumaus/react-alert'
import _some from 'lodash/some'
import _includes from 'lodash/includes'
import _startsWith from 'lodash/startsWith'
@@ -13,11 +11,10 @@ import 'dayjs/locale/uk'
import Header from 'components/Header'
import Footer from 'components/Footer'
+import { Toaster } from 'sonner'
import { getAccessToken } from 'utils/accessToken'
import { authActions } from 'redux/reducers/auth'
import sagaActions from 'redux/sagas/actions'
-import { errorsActions } from 'redux/reducers/errors'
-import { alertsActions } from 'redux/reducers/alerts'
import { StateType, useAppDispatch } from 'redux/store'
import { isBrowser } from 'redux/constants'
import routesPath from 'utils/routes'
@@ -37,13 +34,12 @@ const App: React.FC<IApp> = ({ ssrTheme, ssrAuthenticated }) => {
const dispatch = useAppDispatch()
const { pathname } = useLocation()
const { t } = useTranslation('common')
- const alert = useAlert()
const { loading } = useSelector((state: StateType) => state.auth)
const reduxAuthenticated = useSelector((state: StateType) => state.auth.authenticated)
- const { error } = useSelector((state: StateType) => state.errors)
- const { message, type } = useSelector((state: StateType) => state.alerts)
+ const reduxTheme = useSelector((state: StateType) => state.ui.theme.theme)
const accessToken = getAccessToken()
const authenticated = isBrowser ? (loading ? !!accessToken : reduxAuthenticated) : ssrAuthenticated
+ const theme = isBrowser ? reduxTheme : ssrTheme
// prettier-ignore
useEffect(() => {
@@ -62,27 +58,6 @@ const App: React.FC<IApp> = ({ ssrTheme, ssrAuthenticated }) => {
})()
}, [reduxAuthenticated]) // eslint-disable-line
- useEffect(() => {
- if (error) {
- alert.error(error.toString(), {
- onClose: () => {
- dispatch(errorsActions.clearErrors())
- },
- })
- }
- }, [error]) // eslint-disable-line
-
- useEffect(() => {
- if (message && type) {
- alert.show(message.toString(), {
- type,
- onClose: () => {
- dispatch(alertsActions.clearAlerts())
- },
- })
- }
- }, [message, type]) // eslint-disable-line
-
useEffect(() => {
if (_some(TITLE_BLACKLIST, (page) => _startsWith(pathname, page))) {
return
@@ -114,12 +89,17 @@ const App: React.FC<IApp> = ({ ssrTheme, ssrAuthenticated }) => {
]
return (
- // eslint-disable-next-line react/jsx-no-useless-fragment
<>
{!_includes(routesWithOutHeader, pathname) && !isReferralPage && !isProjectViewPage && (
<Header ssrTheme={ssrTheme} authenticated={authenticated} />
)}
<Outlet />
+ <Toaster
+ theme={theme}
+ toastOptions={{
+ duration: 5000,
+ }}
+ />
{!isReferralPage && !isProjectViewPage && <Footer minimal={isMinimalFooter} authenticated={authenticated} />}
</>
)
diff --git a/app/components/marketing/Pricing.tsx b/app/components/marketing/Pricing.tsx
index 43a88ee0c..f7899e439 100644
--- a/app/components/marketing/Pricing.tsx
+++ b/app/components/marketing/Pricing.tsx
@@ -12,6 +12,7 @@ import _includes from 'lodash/includes'
import { Trans } from 'react-i18next'
import { RadioGroup } from '@headlessui/react'
import cx from 'clsx'
+import { toast } from 'sonner'
import Modal from 'ui/Modal'
import Button from 'ui/Button'
@@ -25,8 +26,6 @@ import {
STANDARD_PLANS,
TRIAL_DAYS,
} from 'redux/constants'
-import { errorsActions } from 'redux/reducers/errors'
-import { alertsActions } from 'redux/reducers/alerts'
import { authActions } from 'redux/reducers/auth'
import sagaActions from 'redux/sagas/actions'
import { authMe, previewSubscriptionUpdate, changeSubscriptionPlan } from 'api'
@@ -116,11 +115,7 @@ const Pricing = ({ t, language, authenticated, isBillingPage }: IPricing) => {
dispatch(sagaActions.logout(false, false))
}
- dispatch(
- alertsActions.accountUpdated({
- message: t('apiNotifications.subscriptionUpdated'),
- }),
- )
+ toast.success(t('apiNotifications.subscriptionUpdated'))
}, 3000)
setPlanCodeLoading(null)
setDowngradeTo(null)
@@ -140,11 +135,7 @@ const Pricing = ({ t, language, authenticated, isBillingPage }: IPricing) => {
setSubUpdatePreview(preview)
} catch (reason) {
console.error('[ERROR] An error occured while loading subscription update pricing preview:', reason)
- dispatch(
- errorsActions.genericError({
- message: 'An error occured while loading subscription update pricing preview',
- }),
- )
+ toast.error('An error occured while loading subscription update pricing preview')
setSubUpdatePreview(false)
}
}
@@ -166,11 +157,7 @@ const Pricing = ({ t, language, authenticated, isBillingPage }: IPricing) => {
// @ts-ignore
if (!window.Paddle) {
- dispatch(
- errorsActions.genericError({
- message: 'Payment script has not yet loaded! Please, try again.',
- }),
- )
+ toast.error('Payment script has not yet loaded! Please, try again.')
setPlanCodeLoading(null)
return
}
@@ -222,19 +209,11 @@ const Pricing = ({ t, language, authenticated, isBillingPage }: IPricing) => {
dispatch(sagaActions.logout(false, false))
}
- dispatch(
- alertsActions.accountUpdated({
- message: t('apiNotifications.subscriptionUpdated'),
- }),
- )
+ toast.success(t('apiNotifications.subscriptionUpdated'))
closeUpdateModal(true)
} catch (reason) {
console.error('[ERROR] An error occured while updating subscription:', reason)
- dispatch(
- errorsActions.genericError({
- message: 'An error occured while updating subscription',
- }),
- )
+ toast.error('An error occured while updating subscription')
closeUpdateModal(true)
}
}
diff --git a/app/pages/Auth/CreateNewPassword/CreateNewPassword.container.tsx b/app/pages/Auth/CreateNewPassword/CreateNewPassword.container.tsx
deleted file mode 100644
index f52ada633..000000000
--- a/app/pages/Auth/CreateNewPassword/CreateNewPassword.container.tsx
+++ /dev/null
@@ -1,24 +0,0 @@
-import { connect } from 'react-redux'
-import { errorsActions } from 'redux/reducers/errors'
-import { alertsActions } from 'redux/reducers/alerts'
-import { AppDispatch } from 'redux/store'
-import CreateNewPassword from './CreateNewPassword'
-
-const mapDispatchToProps = (dispatch: AppDispatch) => ({
- createNewPasswordFailed: (e: string) => {
- dispatch(
- errorsActions.createNewPasswordFailed({
- message: e,
- }),
- )
- },
- newPassword: (message: string) => {
- dispatch(
- alertsActions.newPassword({
- message,
- }),
- )
- },
-})
-
-export default connect(null, mapDispatchToProps)(CreateNewPassword)
diff --git a/app/pages/Auth/CreateNewPassword/CreateNewPassword.tsx b/app/pages/Auth/CreateNewPassword/CreateNewPassword.tsx
index 4533070b5..f31e37554 100644
--- a/app/pages/Auth/CreateNewPassword/CreateNewPassword.tsx
+++ b/app/pages/Auth/CreateNewPassword/CreateNewPassword.tsx
@@ -4,6 +4,7 @@ import { useTranslation, Trans } from 'react-i18next'
import _size from 'lodash/size'
import _keys from 'lodash/keys'
import _isEmpty from 'lodash/isEmpty'
+import { toast } from 'sonner'
import { createNewPassword } from 'api'
import { withAuthentication, auth } from 'hoc/protected'
@@ -17,13 +18,7 @@ interface FormSubmitData {
repeat: string
}
-const CreateNewPassword = ({
- createNewPasswordFailed,
- newPassword,
-}: {
- createNewPasswordFailed: (e: string) => void
- newPassword: (message: string) => void
-}): JSX.Element => {
+const CreateNewPassword = () => {
const { t } = useTranslation('common')
const navigate = useNavigate()
const { id } = useParams()
@@ -74,10 +69,10 @@ const CreateNewPassword = ({
const { password } = data
await createNewPassword(id as string, password)
- newPassword(t('auth.recovery.updated'))
+ toast.success(t('auth.recovery.updated'))
navigate(routes.signin)
} catch (e: any) {
- createNewPasswordFailed(e.toString())
+ toast.error(e.toString())
} finally {
setIsLoading(false)
}
diff --git a/app/pages/Auth/CreateNewPassword/index.tsx b/app/pages/Auth/CreateNewPassword/index.tsx
index 2d019ca50..cf99f3f19 100644
--- a/app/pages/Auth/CreateNewPassword/index.tsx
+++ b/app/pages/Auth/CreateNewPassword/index.tsx
@@ -1,3 +1,3 @@
-import CreateNewPassword from './CreateNewPassword.container'
+import CreateNewPassword from './CreateNewPassword'
export default CreateNewPassword
diff --git a/app/pages/Auth/ForgotPassword/ForgotPassword.container.tsx b/app/pages/Auth/ForgotPassword/ForgotPassword.container.tsx
deleted file mode 100644
index 895a0b1df..000000000
--- a/app/pages/Auth/ForgotPassword/ForgotPassword.container.tsx
+++ /dev/null
@@ -1,24 +0,0 @@
-import { connect } from 'react-redux'
-import { errorsActions } from 'redux/reducers/errors'
-import { alertsActions } from 'redux/reducers/alerts'
-import { AppDispatch } from 'redux/store'
-import ForgotPassword from './ForgotPassword'
-
-const mapDispatchToProps = (dispatch: AppDispatch) => ({
- createNewPasswordFailed: (e: string) => {
- dispatch(
- errorsActions.createNewPasswordFailed({
- message: e,
- }),
- )
- },
- newPassword: (message: string) => {
- dispatch(
- alertsActions.newPassword({
- message,
- }),
- )
- },
-})
-
-export default connect(null, mapDispatchToProps)(ForgotPassword)
diff --git a/app/pages/Auth/ForgotPassword/ForgotPassword.tsx b/app/pages/Auth/ForgotPassword/ForgotPassword.tsx
index c6a43e5e9..dd6f39b0c 100644
--- a/app/pages/Auth/ForgotPassword/ForgotPassword.tsx
+++ b/app/pages/Auth/ForgotPassword/ForgotPassword.tsx
@@ -3,6 +3,7 @@ import { Link, useNavigate } from '@remix-run/react'
import { useTranslation, Trans } from 'react-i18next'
import _keys from 'lodash/keys'
import _isEmpty from 'lodash/isEmpty'
+import { toast } from 'sonner'
import { forgotPassword } from 'api'
import { withAuthentication, auth } from 'hoc/protected'
@@ -12,13 +13,7 @@ import Button from 'ui/Button'
import { TRIAL_DAYS } from 'redux/constants'
import { isValidEmail } from 'utils/validator'
-const ForgotPassword = ({
- createNewPasswordFailed,
- newPassword,
-}: {
- createNewPasswordFailed: (e: string) => void
- newPassword: (message: string) => void
-}): JSX.Element => {
+const ForgotPassword = () => {
const { t } = useTranslation('common')
const navigate = useNavigate()
const [form, setForm] = useState<{
@@ -59,10 +54,10 @@ const ForgotPassword = ({
try {
await forgotPassword(data)
- newPassword(t('auth.forgot.sent'))
+ toast.success(t('auth.forgot.sent'))
navigate(routes.main)
} catch (e: any) {
- createNewPasswordFailed(e.toString())
+ toast.error(e.toString())
} finally {
setIsLoading(false)
}
diff --git a/app/pages/Auth/ForgotPassword/index.tsx b/app/pages/Auth/ForgotPassword/index.tsx
index 657a2f2a9..1a8de9c9b 100644
--- a/app/pages/Auth/ForgotPassword/index.tsx
+++ b/app/pages/Auth/ForgotPassword/index.tsx
@@ -1,3 +1,3 @@
-import ForgotPassword from './ForgotPassword.container'
+import ForgotPassword from './ForgotPassword'
export default ForgotPassword
diff --git a/app/pages/Auth/Signin/Signin.container.tsx b/app/pages/Auth/Signin/Signin.container.tsx
index 1a8dd70df..7c98cbade 100644
--- a/app/pages/Auth/Signin/Signin.container.tsx
+++ b/app/pages/Auth/Signin/Signin.container.tsx
@@ -2,7 +2,6 @@ import { connect } from 'react-redux'
import type i18next from 'i18next'
import sagaActions from 'redux/sagas/actions'
import { authActions } from 'redux/reducers/auth'
-import { errorsActions } from 'redux/reducers/errors'
import { AppDispatch } from 'redux/store'
import { IUser } from 'redux/models/IUser'
import Signin from './Signin'
@@ -23,13 +22,6 @@ const mapDispatchToProps = (dispatch: AppDispatch) => ({
dispatch(sagaActions.loadProjects())
dispatch(sagaActions.loadSharedProjects())
},
- loginFailed: (error: string) => {
- dispatch(
- errorsActions.loginFailed({
- message: error,
- }),
- )
- },
authSSO: (provider: string, dontRemember: boolean, t: typeof i18next.t, callback: (res: any) => void) => {
dispatch(sagaActions.authSSO(provider, dontRemember, t, callback))
},
diff --git a/app/pages/Auth/Signin/Signin.tsx b/app/pages/Auth/Signin/Signin.tsx
index 3dd39c8b2..753e70ff8 100644
--- a/app/pages/Auth/Signin/Signin.tsx
+++ b/app/pages/Auth/Signin/Signin.tsx
@@ -5,6 +5,7 @@ import { useTranslation, Trans } from 'react-i18next'
import _keys from 'lodash/keys'
import _isEmpty from 'lodash/isEmpty'
import _isString from 'lodash/isString'
+import { toast } from 'sonner'
import GoogleAuth from 'components/GoogleAuth'
import GithubAuth from 'components/GithubAuth'
@@ -36,12 +37,11 @@ interface ISignin {
callback: (result: boolean, twoFARequired: boolean) => void,
) => void
loginSuccess: (user: IUser) => void
- loginFailed: (error: string) => void
authSSO: (provider: string, dontRemember: boolean, t: typeof i18next.t, callback: (res: any) => void) => void
ssrTheme: string
}
-const Signin = ({ login, loginSuccess, loginFailed, authSSO, ssrTheme }: ISignin): JSX.Element => {
+const Signin = ({ login, loginSuccess, authSSO, ssrTheme }: ISignin): JSX.Element => {
const { t } = useTranslation('common')
const [form, setForm] = useState<ISigninForm>({
email: '',
@@ -121,7 +121,7 @@ const Signin = ({ login, loginSuccess, loginFailed, authSSO, ssrTheme }: ISignin
loginSuccess(user)
} catch (err) {
if (_isString(err)) {
- loginFailed(err)
+ toast.error(err)
}
console.error(`[ERROR] Failed to authenticate with 2FA: ${err}`)
setTwoFACodeError(t('profileSettings.invalid2fa'))
diff --git a/app/pages/Captcha/Settings/CaptchaSettings.container.tsx b/app/pages/Captcha/Settings/CaptchaSettings.container.tsx
index b31ed34e7..898860d22 100644
--- a/app/pages/Captcha/Settings/CaptchaSettings.container.tsx
+++ b/app/pages/Captcha/Settings/CaptchaSettings.container.tsx
@@ -1,8 +1,6 @@
import { connect } from 'react-redux'
import UIActions from 'redux/reducers/ui'
import sagaActions from 'redux/sagas/actions'
-import { alertsActions } from 'redux/reducers/alerts'
-import { errorsActions } from 'redux/reducers/errors'
import { StateType, AppDispatch } from 'redux/store'
import CaptchaSettings from './CaptchaSettings'
@@ -15,43 +13,6 @@ const mapStateToProps = (state: StateType) => ({
})
const mapDispatchToProps = (dispatch: AppDispatch) => ({
- updateProjectFailed: (message: string) => {
- dispatch(
- errorsActions.updateProjectFailed({
- message,
- }),
- )
- },
- createNewProjectFailed: (message: string) => {
- dispatch(
- errorsActions.createNewProjectFailed({
- message,
- }),
- )
- },
- newProject: (message: string) => {
- dispatch(
- alertsActions.generateAlerts({
- message,
- type: 'success',
- }),
- )
- },
- projectDeleted: (message: string) => {
- dispatch(
- alertsActions.generateAlerts({
- message,
- type: 'success',
- }),
- )
- },
- deleteProjectFailed: (message: string) => {
- dispatch(
- errorsActions.deleteProjectFailed({
- message,
- }),
- )
- },
loadProjects: () => {
sagaActions.loadProjectsCaptcha()
},
@@ -65,13 +26,6 @@ const mapDispatchToProps = (dispatch: AppDispatch) => ({
}),
)
},
- showError: (message: string) => {
- dispatch(
- errorsActions.genericError({
- message,
- }),
- )
- },
})
export default connect(mapStateToProps, mapDispatchToProps)(CaptchaSettings)
diff --git a/app/pages/Captcha/Settings/CaptchaSettings.tsx b/app/pages/Captcha/Settings/CaptchaSettings.tsx
index 96a4b65ae..b2c604834 100644
--- a/app/pages/Captcha/Settings/CaptchaSettings.tsx
+++ b/app/pages/Captcha/Settings/CaptchaSettings.tsx
@@ -1,6 +1,7 @@
import React, { useState, useEffect, useMemo, memo, useRef } from 'react'
import { useNavigate, useParams } from '@remix-run/react'
import { useTranslation } from 'react-i18next'
+import { toast } from 'sonner'
import cx from 'clsx'
import _isEmpty from 'lodash/isEmpty'
import _size from 'lodash/size'
@@ -65,15 +66,9 @@ interface IForm extends Partial<ICaptchaProject> {
}
interface ICaptchaSettings {
- updateProjectFailed: (error: string) => void
- createNewProjectFailed: (error: string) => void
- newProject: (message: string) => void
- projectDeleted: (message: string) => void
- deleteProjectFailed: (error: string) => void
loadProjects: () => void
isLoading: boolean
projects: ICaptchaProject[]
- showError: (error: string) => void
removeProject: (pid: string) => void
user: IUser
deleteProjectCache: (pid: string) => void
@@ -83,15 +78,9 @@ interface ICaptchaSettings {
}
const CaptchaSettings = ({
- updateProjectFailed,
- createNewProjectFailed,
- newProject,
- projectDeleted,
- deleteProjectFailed,
loadProjects,
isLoading,
projects,
- showError,
removeProject,
user,
deleteProjectCache,
@@ -144,13 +133,13 @@ const CaptchaSettings = ({
}
if (!user.isActive && !isSelfhosted) {
- showError(t('project.captcha.settings.verify'))
+ toast.error(t('project.captcha.settings.verify'))
navigate(routes.dashboard)
}
if (!isLoading && isSettings && !projectDeleting) {
if (_isEmpty(project) || project?.uiHidden) {
- showError(t('project.captcha.noExist'))
+ toast.error(t('project.captcha.noExist'))
navigate(routes.dashboard)
} else {
setForm({
@@ -160,7 +149,7 @@ const CaptchaSettings = ({
})
}
}
- }, [user, project, isLoading, isSettings, navigate, showError, projectDeleting, t, loading])
+ }, [user, project, isLoading, isSettings, navigate, projectDeleting, t, loading])
const onSubmit = async (data: IForm) => {
if (!projectSaving) {
@@ -184,11 +173,11 @@ const CaptchaSettings = ({
}
if (isSettings) {
await updateProject(id, formalisedData as ICaptchaProject)
- newProject(t('project.settings.updated'))
+ toast.success(t('project.settings.updated'))
} else {
if (tab === tabForInheritance) {
if (_isEmpty(reuseProjectId)) {
- showError('Select projects')
+ toast.error('Select projects')
return
}
await createCaptchaInherited(formalisedData.id)
@@ -199,17 +188,13 @@ const CaptchaSettings = ({
})
}
trackCustom('CAPTCHA_CREATED')
- newProject(t('project.settings.created'))
+ toast.success(t('project.settings.created'))
}
loadProjects()
navigate(routes.dashboard)
- } catch (e) {
- if (isSettings) {
- updateProjectFailed(e as string)
- } else {
- createNewProjectFailed(e as string)
- }
+ } catch (reason: any) {
+ toast.error(reason)
} finally {
setProjectSaving(false)
}
@@ -223,10 +208,10 @@ const CaptchaSettings = ({
try {
await deleteCaptchaProject(id)
removeProject(id)
- projectDeleted(t('project.settings.deleted'))
+ toast.success(t('project.settings.deleted'))
navigate(routes.dashboard)
- } catch (e) {
- deleteProjectFailed(e as string)
+ } catch (reason: any) {
+ toast.error(reason)
} finally {
setProjectDeleting(false)
}
@@ -240,10 +225,10 @@ const CaptchaSettings = ({
try {
await resetCaptchaProject(id)
deleteProjectCache(id)
- projectDeleted(t('project.settings.resetted'))
+ toast.success(t('project.settings.resetted'))
navigate(routes.dashboard)
- } catch (e) {
- deleteProjectFailed(e as string)
+ } catch (reason: any) {
+ toast.error(reason)
} finally {
setProjectResetting(false)
}
@@ -303,7 +288,7 @@ const CaptchaSettings = ({
)
if (_isEmpty(data)) {
- showError('Select project or select corect project')
+ toast.error('Please select a project')
}
onSubmit({ ...(data as IForm), isCaptcha: true })
@@ -332,8 +317,8 @@ const CaptchaSettings = ({
try {
const res = await reGenerateCaptchaSecretKey(id)
setCaptchaSecretKey(res)
- } catch (e) {
- showError(e as string)
+ } catch (reason: any) {
+ toast.error(reason)
}
}
diff --git a/app/pages/Captcha/View/ViewCaptcha.container.tsx b/app/pages/Captcha/View/ViewCaptcha.container.tsx
index 1b7395cb2..104cf3403 100644
--- a/app/pages/Captcha/View/ViewCaptcha.container.tsx
+++ b/app/pages/Captcha/View/ViewCaptcha.container.tsx
@@ -1,5 +1,4 @@
import { connect } from 'react-redux'
-import { errorsActions } from 'redux/reducers/errors'
import UIActions from 'redux/reducers/ui'
import { StateType, AppDispatch } from 'redux/store'
@@ -18,13 +17,6 @@ const mapStateToProps = (state: StateType) => ({
})
const mapDispatchToProps = (dispatch: AppDispatch) => ({
- showError: (message: string) => {
- dispatch(
- errorsActions.genericError({
- message,
- }),
- )
- },
setProjectCache: (pid: string, data: any, key: string) => {
dispatch(
UIActions.setCaptchaProjectCache({
diff --git a/app/pages/Captcha/View/ViewCaptcha.tsx b/app/pages/Captcha/View/ViewCaptcha.tsx
index a4e2aa3ca..15d09f305 100644
--- a/app/pages/Captcha/View/ViewCaptcha.tsx
+++ b/app/pages/Captcha/View/ViewCaptcha.tsx
@@ -1,5 +1,6 @@
/* eslint-disable react/no-unstable-nested-components, react/display-name */
import React, { useState, useEffect, useMemo, memo, useRef } from 'react'
+import { toast } from 'sonner'
import useSize from 'hooks/useSize'
import { useNavigate, useParams } from '@remix-run/react'
import { ClientOnly } from 'remix-utils/client-only'
@@ -77,7 +78,6 @@ const PageLoader = () => (
interface IViewCaptcha {
projects: ICaptchaProject[]
isLoading: boolean
- showError: (message: string) => void
cache: any
setProjectCache: (pid: string, data: any, key: string) => void
projectViewPrefs: any
@@ -93,7 +93,6 @@ interface IViewCaptcha {
const ViewCaptcha = ({
projects,
isLoading: _isLoading,
- showError,
cache,
setProjectCache,
projectViewPrefs,
@@ -210,7 +209,7 @@ const ViewCaptcha = ({
})
const onErrorLoading = () => {
- showError(t('project.noExist'))
+ toast.error(t('project.noExist'))
navigate(routes.dashboard)
}
diff --git a/app/pages/Dashboard/Dashboard.container.tsx b/app/pages/Dashboard/Dashboard.container.tsx
index 458e3c673..062fdc75b 100644
--- a/app/pages/Dashboard/Dashboard.container.tsx
+++ b/app/pages/Dashboard/Dashboard.container.tsx
@@ -1,9 +1,7 @@
import { connect } from 'react-redux'
-import { errorsActions } from 'redux/reducers/errors'
import UIActions from 'redux/reducers/ui'
import sagaActions from 'redux/sagas/actions'
import { authActions } from 'redux/reducers/auth'
-import { alertsActions } from 'redux/reducers/alerts'
import { StateType, AppDispatch } from 'redux/store'
import { IProject } from 'redux/models/IProject'
import { ISharedProject } from 'redux/models/ISharedProject'
@@ -28,13 +26,6 @@ const mapStateToProps = (state: StateType) => ({
})
const mapDispatchToProps = (dispatch: AppDispatch) => ({
- deleteProjectFailed: (message: string) => {
- dispatch(
- errorsActions.deleteProjectFailed({
- message,
- }),
- )
- },
setProjectsShareData: (data: IProject | ISharedProject, id: string, shared?: boolean) => {
dispatch(
UIActions.setProjectsShareData({
@@ -52,20 +43,6 @@ const mapDispatchToProps = (dispatch: AppDispatch) => ({
}),
)
},
- userSharedUpdate: (message: string) => {
- dispatch(
- alertsActions.userSharedUpdate({
- message,
- }),
- )
- },
- sharedProjectError: (message: string) => {
- dispatch(
- errorsActions.sharedProjectFailed({
- message,
- }),
- )
- },
loadProjects: (take: number, skip: number, search: string) => {
dispatch(sagaActions.loadProjects(take, skip, search))
},
diff --git a/app/pages/Dashboard/Dashboard.tsx b/app/pages/Dashboard/Dashboard.tsx
index 6dd201acf..048916070 100644
--- a/app/pages/Dashboard/Dashboard.tsx
+++ b/app/pages/Dashboard/Dashboard.tsx
@@ -1,5 +1,6 @@
import React, { memo, useState, useEffect, useMemo } from 'react'
import { Link, useNavigate } from '@remix-run/react'
+import { toast } from 'sonner'
import type i18next from 'i18next'
import { ClientOnly } from 'remix-utils/client-only'
import cx from 'clsx'
@@ -60,13 +61,10 @@ interface IProjectCard {
isPublic?: boolean
confirmed?: boolean
id: string
- deleteProjectFailed: (message: string) => void
sharedProjects: ISharedProject[]
setProjectsShareData: (data: Partial<ISharedProject>, id: string, shared?: boolean) => void
setUserShareData: (data: Partial<ISharedProject>, id: string) => void
shared?: boolean
- userSharedUpdate: (message: string) => void
- sharedProjectError: (message: string) => void
captcha?: boolean
isTransferring?: boolean
getRole?: (id: string) => string | null
@@ -124,19 +122,16 @@ const ProjectCard = ({
isPublic,
confirmed,
id,
- deleteProjectFailed,
sharedProjects,
setProjectsShareData,
setUserShareData,
shared,
- userSharedUpdate,
- sharedProjectError,
captcha,
isTransferring,
type,
getRole,
members,
-}: IProjectCard): JSX.Element => {
+}: IProjectCard) => {
const [showInviteModal, setShowInviteModal] = useState(false)
const role = useMemo(() => getRole && getRole(id), [getRole, id])
const navigate = useNavigate()
@@ -152,11 +147,9 @@ const ProjectCard = ({
await acceptShareProject(pid)
setProjectsShareData({ confirmed: true }, id, true)
setUserShareData({ confirmed: true }, pid)
- userSharedUpdate(t('apiNotifications.acceptInvitation'))
- } catch (e) {
- sharedProjectError(t('apiNotifications.acceptInvitationError'))
- // @ts-ignore
- deleteProjectFailed(e)
+ toast.success(t('apiNotifications.acceptInvitation'))
+ } catch (reason: any) {
+ toast.error(t('apiNotifications.acceptInvitationError'))
}
}
@@ -312,11 +305,8 @@ interface DashboardProps {
isLoading: boolean
error: string
user: IUser
- deleteProjectFailed: (error: string) => void
setProjectsShareData: (data: Partial<ISharedProject>) => void
setUserShareData: (data: Partial<ISharedProject>) => void
- userSharedUpdate: (message: string) => void
- sharedProjectError: (error: string) => void
loadProjects: (take: number, skip: number, search: string) => void
loadSharedProjects: (take: number, skip: number, search: string) => void
total: number
@@ -342,11 +332,8 @@ const Dashboard = ({
isLoading,
error,
user,
- deleteProjectFailed,
setProjectsShareData,
setUserShareData,
- userSharedUpdate,
- sharedProjectError,
loadProjects,
loadSharedProjects,
total,
@@ -669,11 +656,8 @@ const Dashboard = ({
birdseye={birdseye}
live={_isNumber(liveStats[id]) ? liveStats[id] : 'N/A'}
setUserShareData={() => {}}
- deleteProjectFailed={() => {}}
- userSharedUpdate={() => {}}
sharedProjects={[]}
setProjectsShareData={() => {}}
- sharedProjectError={() => {}}
isTransferring={isTransferring}
confirmed
/>
@@ -709,12 +693,9 @@ const Dashboard = ({
isPublic={isPublic}
birdseye={birdseye}
live={_isNumber(liveStats[id]) ? liveStats[id] : 'N/A'}
- deleteProjectFailed={() => {}}
sharedProjects={[]}
setProjectsShareData={() => {}}
setUserShareData={() => {}}
- userSharedUpdate={() => {}}
- sharedProjectError={() => {}}
confirmed
/>
),
@@ -754,11 +735,8 @@ const Dashboard = ({
birdseye={birdseye}
live={_isNumber(liveStats[project.id]) ? liveStats[project.id] : 'N/A'}
setUserShareData={() => {}}
- deleteProjectFailed={() => {}}
sharedProjects={[]}
setProjectsShareData={() => {}}
- userSharedUpdate={() => {}}
- sharedProjectError={() => {}}
/>
)
}
@@ -780,9 +758,6 @@ const Dashboard = ({
setProjectsShareData={setProjectsShareData}
setUserShareData={setUserShareData}
live={_isNumber(liveStats[project.id]) ? liveStats[project.id] : 'N/A'}
- userSharedUpdate={userSharedUpdate}
- sharedProjectError={sharedProjectError}
- deleteProjectFailed={deleteProjectFailed}
/>
)
},
diff --git a/app/pages/Project/Alerts/Settings/ProjectAlertsSettings.container.tsx b/app/pages/Project/Alerts/Settings/ProjectAlertsSettings.container.tsx
index f0c9d689e..50abd3976 100644
--- a/app/pages/Project/Alerts/Settings/ProjectAlertsSettings.container.tsx
+++ b/app/pages/Project/Alerts/Settings/ProjectAlertsSettings.container.tsx
@@ -1,9 +1,7 @@
import { connect } from 'react-redux'
-import { errorsActions } from 'redux/reducers/errors'
import UIActions from 'redux/reducers/ui'
import { StateType, AppDispatch } from 'redux/store'
import { IAlerts } from 'redux/models/IAlerts'
-import { alertsActions } from 'redux/reducers/alerts'
import ProjectAlerts from './ProjectAlertsSettings'
const mapStateToProps = (state: StateType) => ({
@@ -14,21 +12,6 @@ const mapStateToProps = (state: StateType) => ({
})
const mapDispatchToProps = (dispatch: AppDispatch) => ({
- showError: (message: string) => {
- dispatch(
- errorsActions.genericError({
- message,
- }),
- )
- },
- generateAlerts: (message: string) => {
- dispatch(
- alertsActions.generateAlerts({
- message,
- type: 'success',
- }),
- )
- },
setProjectAlerts: (alerts: IAlerts[]) => {
dispatch(UIActions.setProjectAlerts(alerts))
},
diff --git a/app/pages/Project/Alerts/Settings/ProjectAlertsSettings.tsx b/app/pages/Project/Alerts/Settings/ProjectAlertsSettings.tsx
index d430eaad3..ef5a91f3e 100644
--- a/app/pages/Project/Alerts/Settings/ProjectAlertsSettings.tsx
+++ b/app/pages/Project/Alerts/Settings/ProjectAlertsSettings.tsx
@@ -1,6 +1,7 @@
import React, { useEffect, useMemo, useState } from 'react'
import { useNavigate, useParams, useLocation, Link } from '@remix-run/react'
import { useTranslation, Trans } from 'react-i18next'
+import { toast } from 'sonner'
import { ExclamationTriangleIcon } from '@heroicons/react/24/outline'
import _isEmpty from 'lodash/isEmpty'
@@ -32,22 +33,18 @@ const INTEGRATIONS_LINK = `${routes.user_settings}#integrations`
interface IProjectAlertsSettings {
alerts: IAlerts[]
setProjectAlerts: (item: IAlerts[]) => void
- showError: (message: string) => void
user: IUser
setProjectAlertsTotal: (num: number) => void
total: number
- generateAlerts: (message: string) => void
loading: boolean
}
const ProjectAlertsSettings = ({
alerts,
setProjectAlerts,
- showError,
user,
setProjectAlertsTotal,
total,
- generateAlerts,
loading,
}: IProjectAlertsSettings): JSX.Element => {
const navigate = useNavigate()
@@ -180,10 +177,10 @@ const ProjectAlertsSettings = ({
.then((res) => {
navigate(`/projects/${pid}?tab=${PROJECT_TABS.alerts}`)
setProjectAlerts([..._filter(alerts, (a) => a.id !== id), res])
- generateAlerts(t('alertsSettings.alertUpdated'))
+ toast.success(t('alertsSettings.alertUpdated'))
})
- .catch((err) => {
- showError(err.message || err || 'Something went wrong')
+ .catch((reason) => {
+ toast.error(reason.message || reason || 'Something went wrong')
})
} else {
createAlert(data as ICreateAlert)
@@ -191,17 +188,17 @@ const ProjectAlertsSettings = ({
navigate(`/projects/${pid}?tab=${PROJECT_TABS.alerts}`)
setProjectAlerts([...alerts, res])
setProjectAlertsTotal(total + 1)
- generateAlerts(t('alertsSettings.alertCreated'))
+ toast.success(t('alertsSettings.alertCreated'))
})
- .catch((err) => {
- showError(err.message || err || 'Something went wrong')
+ .catch((reason) => {
+ toast.error(reason.message || reason || 'Something went wrong')
})
}
}
const onDelete = () => {
if (!id) {
- showError('Something went wrong')
+ toast.error('Something went wrong')
return
}
@@ -210,10 +207,10 @@ const ProjectAlertsSettings = ({
setProjectAlerts(_filter(alerts, (a) => a.id !== id))
setProjectAlertsTotal(total - 1)
navigate(`/projects/${pid}?tab=${PROJECT_TABS.alerts}`)
- generateAlerts(t('alertsSettings.alertDeleted'))
+ toast.success(t('alertsSettings.alertDeleted'))
})
- .catch((err) => {
- showError(err.message || err || 'Something went wrong')
+ .catch((reason) => {
+ toast.error(reason.message || reason || 'Something went wrong')
})
}
diff --git a/app/pages/Project/Alerts/View/ProjectAlertsView.tsx b/app/pages/Project/Alerts/View/ProjectAlertsView.tsx
index 9facec9e1..b54fbe4b7 100644
--- a/app/pages/Project/Alerts/View/ProjectAlertsView.tsx
+++ b/app/pages/Project/Alerts/View/ProjectAlertsView.tsx
@@ -9,6 +9,7 @@ import _filter from 'lodash/filter'
import { useNavigate, Link } from '@remix-run/react'
import { useTranslation } from 'react-i18next'
import { useDispatch, useSelector } from 'react-redux'
+import { toast } from 'sonner'
import {
BellIcon,
CurrencyDollarIcon,
@@ -24,8 +25,6 @@ import Modal from 'ui/Modal'
import PaidFeature from 'modals/PaidFeature'
import { QUERY_METRIC, PLAN_LIMITS } from 'redux/constants'
import UIActions from 'redux/reducers/ui'
-import { alertsActions } from 'redux/reducers/alerts'
-import { errorsActions } from 'redux/reducers/errors'
import { deleteAlert as deleteAlertApi } from 'api'
import { StateType } from 'redux/store'
@@ -240,18 +239,9 @@ const ProjectAlerts = ({ projectId }: IProjectAlerts): JSX.Element => {
total: total - 1,
}),
)
- dispatch(
- alertsActions.generateAlerts({
- message: t('alertsSettings.alertDeleted'),
- type: 'success',
- }),
- )
+ toast.success(t('alertsSettings.alertDeleted'))
} catch (reason: any) {
- dispatch(
- errorsActions.genericError({
- message: reason?.response?.data?.message || reason?.message || 'Something went wrong',
- }),
- )
+ toast.error(reason?.response?.data?.message || reason?.message || 'Something went wrong')
}
}
diff --git a/app/pages/Project/New/index.tsx b/app/pages/Project/New/index.tsx
index fd81e08d0..28f3ae894 100644
--- a/app/pages/Project/New/index.tsx
+++ b/app/pages/Project/New/index.tsx
@@ -2,6 +2,7 @@ import React, { useState, useEffect, memo } from 'react'
import { useNavigate } from '@remix-run/react'
import { useTranslation } from 'react-i18next'
import { useSelector, useDispatch } from 'react-redux'
+import { toast } from 'sonner'
import _isEmpty from 'lodash/isEmpty'
import _size from 'lodash/size'
import _keys from 'lodash/keys'
@@ -17,8 +18,6 @@ import { trackCustom } from 'utils/analytics'
import routes from 'utils/routes'
import { useAppDispatch, StateType } from 'redux/store'
import sagaActions from 'redux/sagas/actions'
-import { alertsActions } from 'redux/reducers/alerts'
-import { errorsActions } from 'redux/reducers/errors'
const MAX_NAME_LENGTH = 50
@@ -48,11 +47,7 @@ const NewProject = () => {
}
if (!user.isActive && !isSelfhosted) {
- dispatch(
- errorsActions.genericError({
- message: t('project.settings.verify'),
- }),
- )
+ toast.error(t('project.settings.verify'))
navigate(routes.dashboard)
}
}, [user, navigate, dispatch, t, loading])
@@ -66,20 +61,11 @@ const NewProject = () => {
})
trackCustom('PROJECT_CREATED')
navigate(routes.dashboard)
- dispatch(
- alertsActions.generateAlerts({
- message: t('project.settings.created'),
- type: 'success',
- }),
- )
+ toast.success(t('project.settings.created'))
_dispatch(sagaActions.loadProjects(dashboardPaginationPage * ENTRIES_PER_PAGE_DASHBOARD))
- } catch (reason) {
- dispatch(
- errorsActions.createNewProjectFailed({
- message: reason as string,
- }),
- )
+ } catch (reason: any) {
+ toast.error(reason)
} finally {
setProjectSaving(false)
}
diff --git a/app/pages/Project/Settings/Emails/Emails.container.tsx b/app/pages/Project/Settings/Emails/Emails.container.tsx
deleted file mode 100644
index 435a05add..000000000
--- a/app/pages/Project/Settings/Emails/Emails.container.tsx
+++ /dev/null
@@ -1,45 +0,0 @@
-import { connect } from 'react-redux'
-import { errorsActions } from 'redux/reducers/errors'
-import { alertsActions } from 'redux/reducers/alerts'
-import { StateType, AppDispatch } from 'redux/store'
-import Emails from './Emails'
-
-const mapStateToProps = (state: StateType) => ({
- user: state.auth.user,
-})
-
-const mapDispatchToProps = (dispatch: AppDispatch) => ({
- emailFailed: (message: string) => {
- dispatch(
- errorsActions.genericError({
- message,
- }),
- )
- },
- addEmail: (message: string, type = 'success') => {
- dispatch(
- alertsActions.generateAlerts({
- message,
- type,
- }),
- )
- },
- removeEmail: (message: string, type = 'success') => {
- dispatch(
- alertsActions.generateAlerts({
- message,
- type,
- }),
- )
- },
- reportTypeNotifiction: (message: string, type = 'success') => {
- dispatch(
- alertsActions.generateAlerts({
- message,
- type,
- }),
- )
- },
-})
-
-export default connect(mapStateToProps, mapDispatchToProps)(Emails)
diff --git a/app/pages/Project/Settings/Emails/Emails.tsx b/app/pages/Project/Settings/Emails/Emails.tsx
index 13892dfe7..3531d4639 100644
--- a/app/pages/Project/Settings/Emails/Emails.tsx
+++ b/app/pages/Project/Settings/Emails/Emails.tsx
@@ -1,5 +1,6 @@
-import React, { useState, useEffect, useRef } from 'react'
import type i18next from 'i18next'
+import React, { useState, useEffect, useRef } from 'react'
+import { toast } from 'sonner'
import { TrashIcon, InboxStackIcon, ChevronDownIcon, CheckIcon } from '@heroicons/react/24/outline'
import { useTranslation } from 'react-i18next'
import dayjs from 'dayjs'
@@ -120,9 +121,7 @@ const EmailList = ({
onRemove,
t,
setEmails,
- emailFailed,
language,
- reportTypeNotifiction,
}: {
data: {
id: string
@@ -135,9 +134,7 @@ const EmailList = ({
onRemove: (id: string) => void
t: typeof i18next.t
setEmails: (value: ISubscribers[] | ((prevVar: ISubscribers[]) => ISubscribers[])) => void
- emailFailed: (message: string) => void
language: string
- reportTypeNotifiction: (message: string) => void
}) => {
const [open, setOpen] = useState<boolean>(false)
const [showDeleteModal, setShowDeleteModal] = useState<boolean>(false)
@@ -157,10 +154,10 @@ const EmailList = ({
})
return newEmails
})
- reportTypeNotifiction(t('apiNotifications.updatedPeriodEmailReports'))
- } catch (e) {
- console.error(`[ERROR] Error while updating user's role: ${e}`)
- emailFailed(t('apiNotifications.updatedPeriodEmailReportsError'))
+ toast.success(t('apiNotifications.updatedPeriodEmailReports'))
+ } catch (reason: any) {
+ console.error(`[ERROR] Error while updating user's role: ${reason}`)
+ toast.error(t('apiNotifications.updatedPeriodEmailReportsError'))
}
setOpen(false)
@@ -264,21 +261,7 @@ const NoSubscribers = ({ t }: { t: typeof i18next.t }): JSX.Element => (
</div>
)
-const Emails = ({
- emailFailed,
- addEmail,
- removeEmail,
- projectId,
- projectName,
- reportTypeNotifiction,
-}: {
- emailFailed: (message: string, type?: string) => void
- addEmail: (message: string, type?: string) => void
- removeEmail: (message: string) => void
- projectId: string
- projectName: string
- reportTypeNotifiction: (message: string, type?: string) => void
-}): JSX.Element => {
+const Emails = ({ projectId, projectName }: { projectId: string; projectName: string }): JSX.Element => {
const [showModal, setShowModal] = useState<boolean>(false)
const {
t,
@@ -363,10 +346,10 @@ const Emails = ({
try {
const results = await addSubscriber(projectId, { reportFrequency: form.reportFrequency, email: form.email })
setEmails([...emails, results])
- addEmail(t('apiNotifications.userInvited'))
+ toast.success(t('apiNotifications.userInvited'))
} catch (e) {
console.error(`[ERROR] Error while inviting a user: ${e}`)
- addEmail(t('apiNotifications.userInviteError'), 'error')
+ toast.error(t('apiNotifications.userInviteError'))
}
// a timeout is needed to prevent the flicker of data fields in the modal when closing
@@ -397,10 +380,10 @@ const Emails = ({
await removeSubscriber(projectId, email)
const results = _filter(emails, (s) => s.id !== email)
setEmails(results)
- removeEmail(t('apiNotifications.emailDelete'))
- } catch (e) {
- console.error(`[ERROR] Error while deleting a email: ${e}`)
- emailFailed(t('apiNotifications.emailDeleteError'))
+ toast.success(t('apiNotifications.emailDelete'))
+ } catch (reason: any) {
+ console.error(`[ERROR] Error while deleting a email: ${reason}`)
+ toast.error(t('apiNotifications.emailDeleteError'))
}
}
@@ -457,8 +440,6 @@ const Emails = ({
t={t}
language={language}
setEmails={setEmails}
- emailFailed={emailFailed}
- reportTypeNotifiction={reportTypeNotifiction}
/>
))}
</tbody>
diff --git a/app/pages/Project/Settings/Emails/index.tsx b/app/pages/Project/Settings/Emails/index.tsx
index df0c540c1..8536a320a 100644
--- a/app/pages/Project/Settings/Emails/index.tsx
+++ b/app/pages/Project/Settings/Emails/index.tsx
@@ -1,3 +1,3 @@
-import Emails from './Emails.container'
+import Emails from './Emails'
export default Emails
diff --git a/app/pages/Project/Settings/People/People.container.tsx b/app/pages/Project/Settings/People/People.container.tsx
index 9813f35b3..12b2e721a 100644
--- a/app/pages/Project/Settings/People/People.container.tsx
+++ b/app/pages/Project/Settings/People/People.container.tsx
@@ -1,7 +1,5 @@
import { connect } from 'react-redux'
import UIActions from 'redux/reducers/ui'
-import { errorsActions } from 'redux/reducers/errors'
-import { alertsActions } from 'redux/reducers/alerts'
import { StateType, AppDispatch } from 'redux/store'
import { IProject } from 'redux/models/IProject'
@@ -13,13 +11,6 @@ const mapStateToProps = (state: StateType) => ({
})
const mapDispatchToProps = (dispatch: AppDispatch) => ({
- updateProjectFailed: (message: string) => {
- dispatch(
- errorsActions.updateProjectFailed({
- message,
- }),
- )
- },
setProjectShareData: (data: Partial<IProject>, projectId: string, shared = false) => {
dispatch(
UIActions.setProjectsShareData({
@@ -29,30 +20,6 @@ const mapDispatchToProps = (dispatch: AppDispatch) => ({
}),
)
},
- roleUpdatedNotification: (message: string, type = 'success') => {
- dispatch(
- alertsActions.roleUpdated({
- message,
- type,
- }),
- )
- },
- inviteUserNotification: (message: string, type = 'success') => {
- dispatch(
- alertsActions.inviteUser({
- message,
- type,
- }),
- )
- },
- removeUserNotification: (message: string, type = 'success') => {
- dispatch(
- alertsActions.removeUser({
- message,
- type,
- }),
- )
- },
})
export default connect(mapStateToProps, mapDispatchToProps)(People)
diff --git a/app/pages/Project/Settings/People/People.tsx b/app/pages/Project/Settings/People/People.tsx
index 63c4a8858..b0bc6347d 100644
--- a/app/pages/Project/Settings/People/People.tsx
+++ b/app/pages/Project/Settings/People/People.tsx
@@ -1,5 +1,6 @@
-import React, { useState, useEffect, useRef } from 'react'
import type i18next from 'i18next'
+import React, { useState, useEffect, useRef } from 'react'
+import { toast } from 'sonner'
import { ChevronDownIcon, CheckIcon } from '@heroicons/react/24/solid'
import { TrashIcon, UserPlusIcon, CurrencyDollarIcon } from '@heroicons/react/24/outline'
import { useTranslation } from 'react-i18next'
@@ -37,9 +38,7 @@ interface IUsersList {
share?: IShareOwnerProject[]
setProjectShareData: (item: Partial<IProject>, id: string, shared: boolean) => void
pid: string
- updateProjectFailed: (message: string) => void
language: string
- roleUpdatedNotification: (email: string, role?: string) => void
authedUserEmail: string | undefined
isSharedProject: boolean
}
@@ -51,9 +50,7 @@ const UsersList = ({
share,
setProjectShareData,
pid,
- updateProjectFailed,
language,
- roleUpdatedNotification,
authedUserEmail,
isSharedProject,
}: IUsersList) => {
@@ -73,10 +70,10 @@ const UsersList = ({
return itShare
})
setProjectShareData({ share: newShared }, pid, isSharedProject)
- roleUpdatedNotification(t('apiNotifications.roleUpdated'))
- } catch (e) {
- console.error(`[ERROR] Error while updating user's role: ${e}`)
- updateProjectFailed(t('apiNotifications.roleUpdateError'))
+ toast.success(t('apiNotifications.roleUpdated'))
+ } catch (reason) {
+ console.error(`[ERROR] Error while updating user's role: ${reason}`)
+ toast.error(t('apiNotifications.roleUpdateError'))
}
setOpen(false)
@@ -178,11 +175,7 @@ const UsersList = ({
interface IPeopleProps {
project: IProject
- updateProjectFailed: (error: string) => void
setProjectShareData: (data: Partial<IProject>, projectId: string, share?: boolean) => void
- roleUpdatedNotification: (email: string, role?: string) => void
- inviteUserNotification: (email: string, type?: string) => void
- removeUserNotification: (email: string) => void
isPaidTierUsed: boolean
user: IUser
isSharedProject: boolean
@@ -190,11 +183,7 @@ interface IPeopleProps {
const People: React.FunctionComponent<IPeopleProps> = ({
project,
- updateProjectFailed,
setProjectShareData,
- roleUpdatedNotification,
- inviteUserNotification,
- removeUserNotification,
isPaidTierUsed,
user: currentUser,
isSharedProject,
@@ -260,10 +249,10 @@ const People: React.FunctionComponent<IPeopleProps> = ({
try {
const results = await shareProject(id, { email: form.email, role: form.role })
setProjectShareData({ share: results.share }, id)
- inviteUserNotification(t('apiNotifications.userInvited'))
+ toast.success(t('apiNotifications.userInvited'))
} catch (e) {
console.error(`[ERROR] Error while inviting a user: ${e}`)
- inviteUserNotification(t('apiNotifications.userInviteError'), 'error')
+ toast.error(t('apiNotifications.userInviteError'))
}
// a timeout is needed to prevent the flicker of data fields in the modal when closing
@@ -302,10 +291,10 @@ const People: React.FunctionComponent<IPeopleProps> = ({
(s) => s,
)
setProjectShareData({ share: newShared }, id)
- removeUserNotification(t('apiNotifications.userRemoved'))
- } catch (e) {
- console.error(`[ERROR] Error while deleting a user: ${e}`)
- updateProjectFailed(t('apiNotifications.userRemoveError'))
+ toast.success(t('apiNotifications.userRemoved'))
+ } catch (reason) {
+ console.error(`[ERROR] Error while deleting a user: ${reason}`)
+ toast.error(t('apiNotifications.userRemoveError'))
}
}
@@ -362,8 +351,6 @@ const People: React.FunctionComponent<IPeopleProps> = ({
language={language}
share={project.share}
setProjectShareData={setProjectShareData}
- updateProjectFailed={updateProjectFailed}
- roleUpdatedNotification={roleUpdatedNotification}
pid={id}
authedUserEmail={currentUser?.email}
isSharedProject={isSharedProject}
diff --git a/app/pages/Project/Settings/ProjectSettings.container.tsx b/app/pages/Project/Settings/ProjectSettings.container.tsx
index d099d2164..d5d50dfed 100644
--- a/app/pages/Project/Settings/ProjectSettings.container.tsx
+++ b/app/pages/Project/Settings/ProjectSettings.container.tsx
@@ -1,8 +1,6 @@
import { connect } from 'react-redux'
import UIActions from 'redux/reducers/ui'
import sagaActions from 'redux/sagas/actions'
-import { alertsActions } from 'redux/reducers/alerts'
-import { errorsActions } from 'redux/reducers/errors'
import { StateType, AppDispatch } from 'redux/store'
import { tabForSharedProject } from 'redux/constants'
@@ -21,36 +19,6 @@ const mapStateToProps = (state: StateType) => ({
})
const mapDispatchToProps = (dispatch: AppDispatch) => ({
- updateProjectFailed: (message: string) => {
- dispatch(
- errorsActions.updateProjectFailed({
- message,
- }),
- )
- },
- generateAlerts: (message: string) => {
- dispatch(
- alertsActions.generateAlerts({
- message,
- type: 'success',
- }),
- )
- },
- projectDeleted: (message: string) => {
- dispatch(
- alertsActions.generateAlerts({
- message,
- type: 'success',
- }),
- )
- },
- deleteProjectFailed: (message: string) => {
- dispatch(
- errorsActions.deleteProjectFailed({
- message,
- }),
- )
- },
loadProjects: (shared: boolean, skip: number) => {
if (shared) {
dispatch(sagaActions.loadSharedProjects(skip))
@@ -73,13 +41,6 @@ const mapDispatchToProps = (dispatch: AppDispatch) => ({
}),
)
},
- showError: (message: string) => {
- dispatch(
- errorsActions.genericError({
- message,
- }),
- )
- },
setProjectProtectedPassword(id: string, password: string) {
dispatch(
UIActions.setProjectProtectedPassword({
diff --git a/app/pages/Project/Settings/ProjectSettings.tsx b/app/pages/Project/Settings/ProjectSettings.tsx
index affd3e8b4..7fc4c77d6 100644
--- a/app/pages/Project/Settings/ProjectSettings.tsx
+++ b/app/pages/Project/Settings/ProjectSettings.tsx
@@ -1,5 +1,6 @@
import React, { useState, useEffect, useMemo, memo } from 'react'
import type i18next from 'i18next'
+import { toast } from 'sonner'
import { useNavigate, useParams } from '@remix-run/react'
import { useTranslation } from 'react-i18next'
import cx from 'clsx'
@@ -249,15 +250,10 @@ interface IForm extends Partial<IProject> {
const DEFAULT_PROJECT_NAME = 'Untitled Project'
interface IProjectSettings {
- updateProjectFailed: (message: string) => void
- generateAlerts: (message: string) => void
- projectDeleted: (message: string) => void
- deleteProjectFailed: (message: string) => void
loadProjects: (shared: boolean, skip: number) => void
isLoading: boolean
isLoadingShared: boolean
projects: IProject[]
- showError: (message: string) => void
removeProject: (pid: string, shared: boolean) => void
user: IUser
isSharedProject: boolean
@@ -270,15 +266,10 @@ interface IProjectSettings {
}
const ProjectSettings = ({
- updateProjectFailed,
- generateAlerts,
- projectDeleted,
- deleteProjectFailed,
loadProjects,
isLoading,
isLoadingShared,
projects,
- showError,
removeProject,
user,
isSharedProject,
@@ -349,13 +340,13 @@ const ProjectSettings = ({
}
if (!user.isActive && !isSelfhosted) {
- showError(t('project.settings.verify'))
+ toast.error(t('project.settings.verify'))
navigate(routes.dashboard)
}
if (!isLoading && !isLoadingShared && !projectDeleting) {
if (_isEmpty(project) || project?.uiHidden) {
- showError(t('project.noExist'))
+ toast.error(t('project.noExist'))
navigate(routes.dashboard)
} else {
setForm({
@@ -366,7 +357,7 @@ const ProjectSettings = ({
setInitialised(true)
}
}
- }, [user, project, initialised, isLoading, navigate, showError, projectDeleting, t, authLoading, isLoadingShared])
+ }, [user, project, initialised, isLoading, navigate, projectDeleting, t, authLoading, isLoadingShared])
const onSubmit = async (data: IForm) => {
if (!projectSaving) {
@@ -389,11 +380,11 @@ const ProjectSettings = ({
ipBlacklist: _isEmpty(data.ipBlacklist) ? null : _split(data.ipBlacklist, ','),
}
await updateProject(id, formalisedData as Partial<IProject>)
- generateAlerts(t('project.settings.updated'))
+ toast.success(t('project.settings.updated'))
loadProjects(isSharedProject, paginationSkip)
- } catch (reason) {
- updateProjectFailed(reason as string)
+ } catch (reason: any) {
+ toast.error(reason)
} finally {
setProjectSaving(false)
}
@@ -407,10 +398,10 @@ const ProjectSettings = ({
try {
await deleteProject(id)
removeProject(id, isSharedProject)
- projectDeleted(t('project.settings.deleted'))
+ toast.success(t('project.settings.deleted'))
navigate(routes.dashboard)
- } catch (e) {
- deleteProjectFailed(e as string)
+ } catch (reason: any) {
+ toast.error(reason)
} finally {
setProjectDeleting(false)
}
@@ -424,7 +415,7 @@ const ProjectSettings = ({
try {
if (tab === tabDeleteDataModal[1].name) {
if (_isEmpty(dateRange)) {
- deleteProjectFailed(t('project.settings.noDateRange'))
+ toast.error(t('project.settings.noDateRange'))
setProjectResetting(false)
return
}
@@ -434,7 +425,7 @@ const ProjectSettings = ({
})
} else if (tab === tabDeleteDataModal[2].name) {
if (_isEmpty(activeFilter)) {
- deleteProjectFailed(t('project.settings.noFilters'))
+ toast.error(t('project.settings.noFilters'))
setProjectResetting(false)
return
}
@@ -444,10 +435,10 @@ const ProjectSettings = ({
await resetProject(id)
}
deleteProjectCache(id)
- projectDeleted(t('project.settings.resetted'))
+ toast.success(t('project.settings.resetted'))
navigate(routes.dashboard)
- } catch (e) {
- deleteProjectFailed(e as string)
+ } catch (reason: any) {
+ toast.error(reason)
} finally {
setProjectResetting(false)
}
@@ -515,11 +506,11 @@ const ProjectSettings = ({
const onTransfer = async () => {
await transferProject(id, transferEmail)
.then(() => {
- generateAlerts(t('apiNotifications.transferRequestSent'))
+ toast.success(t('apiNotifications.transferRequestSent'))
navigate(routes.dashboard)
})
- .catch((e) => {
- showError(e as string)
+ .catch((reason) => {
+ toast.error(reason)
})
.finally(() => {
setShowTransfer(false)
diff --git a/app/pages/Project/View/ViewProject.container.tsx b/app/pages/Project/View/ViewProject.container.tsx
index 7d4b2fb96..26305cec5 100644
--- a/app/pages/Project/View/ViewProject.container.tsx
+++ b/app/pages/Project/View/ViewProject.container.tsx
@@ -1,8 +1,6 @@
import { connect } from 'react-redux'
-import { errorsActions } from 'redux/reducers/errors'
import UIActions from 'redux/reducers/ui'
import { tabForSharedProject } from 'redux/constants'
-import { alertsActions } from 'redux/reducers/alerts'
import { StateType, AppDispatch } from 'redux/store'
import { IProject } from 'redux/models/IProject'
import { ISharedProject } from 'redux/models/ISharedProject'
@@ -54,13 +52,6 @@ const mapStateToProps = (state: StateType) => {
}
const mapDispatchToProps = (dispatch: AppDispatch) => ({
- showError: (message: string) => {
- dispatch(
- errorsActions.genericError({
- message,
- }),
- )
- },
setProjectCache: (pid: string, data: any, key: string) => {
dispatch(
UIActions.setProjectCache({
@@ -129,14 +120,6 @@ const mapDispatchToProps = (dispatch: AppDispatch) => ({
}),
)
},
- generateAlert: (message: string, type: string) => {
- dispatch(
- alertsActions.generateAlerts({
- message,
- type,
- }),
- )
- },
setProjectTab: (tabs: string) => {
dispatch(UIActions.setProjectTab(tabs))
},
diff --git a/app/pages/Project/View/ViewProject.tsx b/app/pages/Project/View/ViewProject.tsx
index ad1715a53..b8c9c1d3d 100644
--- a/app/pages/Project/View/ViewProject.tsx
+++ b/app/pages/Project/View/ViewProject.tsx
@@ -60,6 +60,7 @@ import _every from 'lodash/every'
import _size from 'lodash/size'
import _truncate from 'lodash/truncate'
import _isString from 'lodash/isString'
+import { toast } from 'sonner'
import { withProjectProtected } from 'hoc/projectProtected'
@@ -275,7 +276,6 @@ interface IViewProject {
projects: IProject[]
extensions: any
isLoading: boolean
- showError: (message: string) => void
cache: any
cachePerf: any
setProjectCache: (pid: string, data: any, key: string) => void
@@ -289,7 +289,6 @@ interface IViewProject {
setProjectViewPrefs: (pid: string, period: string, timeBucket: string, rangeDate?: Date[]) => void
setPublicProject: (project: Partial<IProject | ISharedProject>) => void
setLiveStatsForProject: (id: string, count: number) => void
- generateAlert: (message: string, type: string) => void
setProjectCachePerf: (pid: string, data: any, key: string) => void
setProjectForcastCache: (pid: string, data: any, key: string) => void
authenticated: boolean
@@ -321,7 +320,6 @@ interface IViewProject {
const ViewProject = ({
projects,
isLoading: _isLoading,
- showError,
cache,
cachePerf,
setProjectCache,
@@ -334,7 +332,6 @@ const ViewProject = ({
user,
sharedProjects,
extensions,
- generateAlert,
setProjectCachePerf,
projectTab,
setProjectTab,
@@ -586,7 +583,7 @@ const ViewProject = ({
setProjectViews(views)
} catch (reason: any) {
console.error('[ERROR] (loadProjectViews)', reason)
- showError(reason)
+ toast.error(reason)
}
setProjectViewsLoading(false)
@@ -603,12 +600,12 @@ const ViewProject = ({
await deleteProjectView(id, viewId)
} catch (reason: any) {
console.error('[ERROR] (deleteProjectView)', reason)
- showError(reason)
+ toast.error(reason)
setProjectViewDeleting(false)
return
}
- generateAlert(t('apiNotifications.viewDeleted'), 'success')
+ toast.success(t('apiNotifications.viewDeleted'))
await loadProjectViews(true)
setProjectViewDeleting(false)
}
@@ -624,7 +621,7 @@ const ViewProject = ({
await addFunnel(id, name, steps)
} catch (reason: any) {
console.error('[ERROR] (onFunnelCreate)(addFunnel)', reason)
- showError(reason)
+ toast.error(reason)
}
try {
@@ -637,7 +634,7 @@ const ViewProject = ({
console.error('[ERROR] (onFunnelCreate)(getFunnels)', reason)
}
- generateAlert(t('apiNotifications.funnelCreated'), 'success')
+ toast.success(t('apiNotifications.funnelCreated'))
setFunnelActionLoading(false)
}
@@ -652,7 +649,7 @@ const ViewProject = ({
await updateFunnel(funnelId, id, name, steps)
} catch (reason: any) {
console.error('[ERROR] (onFunnelEdit)(updateFunnel)', reason)
- showError(reason)
+ toast.error(reason)
}
try {
@@ -665,7 +662,7 @@ const ViewProject = ({
console.error('[ERROR] (onFunnelCreate)(getFunnels)', reason)
}
- generateAlert(t('apiNotifications.funnelUpdated'), 'success')
+ toast.success(t('apiNotifications.funnelUpdated'))
setFunnelActionLoading(false)
}
@@ -680,7 +677,7 @@ const ViewProject = ({
await deleteFunnel(funnelId, id)
} catch (reason: any) {
console.error('[ERROR] (onFunnelDelete)(deleteFunnel)', reason)
- showError(reason)
+ toast.error(reason)
}
try {
@@ -693,7 +690,7 @@ const ViewProject = ({
console.error('[ERROR] (onFunnelCreate)(getFunnels)', reason)
}
- generateAlert(t('apiNotifications.funnelDeleted'), 'success')
+ toast.success(t('apiNotifications.funnelDeleted'))
setFunnelActionLoading(false)
}
// pgActiveFragment is a active fragment for pagination
@@ -1091,7 +1088,7 @@ const ViewProject = ({
const switchTrafficChartMetric = (pairID: string, conflicts?: string[]) => {
if (isConflicted(conflicts)) {
- generateAlert(t('project.conflictMetric'), 'error')
+ toast.error(t('project.conflictMetric'))
return
}
@@ -1154,12 +1151,12 @@ const ViewProject = ({
updateStatusInErrors('resolved')
} catch (reason) {
console.error('[markErrorAsResolved]', reason)
- generateAlert(t('apiNotifications.updateErrorStatusFailed'), 'error')
+ toast.error(t('apiNotifications.updateErrorStatusFailed'))
setErrorStatusUpdating(false)
return
}
- generateAlert(t('apiNotifications.errorStatusUpdated'), 'success')
+ toast.success(t('apiNotifications.errorStatusUpdated'))
setErrorStatusUpdating(false)
}
@@ -1176,12 +1173,12 @@ const ViewProject = ({
updateStatusInErrors('active')
} catch (reason) {
console.error('[markErrorAsResolved]', reason)
- generateAlert(t('apiNotifications.updateErrorStatusFailed'), 'error')
+ toast.error(t('apiNotifications.updateErrorStatusFailed'))
setErrorStatusUpdating(false)
return
}
- generateAlert(t('apiNotifications.errorStatusUpdated'), 'success')
+ toast.success(t('apiNotifications.errorStatusUpdated'))
setErrorStatusUpdating(false)
}
@@ -1197,7 +1194,7 @@ const ViewProject = ({
return
}
- showError(t('apiNotifications.incorrectPassword'))
+ toast.error(t('apiNotifications.incorrectPassword'))
navigate({
pathname: _replace(routes.project_protected_password, ':id', id),
search: `?theme=${ssrTheme}&embedded=${embedded}`,
@@ -1207,7 +1204,7 @@ const ViewProject = ({
return
}
- showError(t('project.noExist'))
+ toast.error(t('project.noExist'))
navigate(routes.dashboard)
}
@@ -1367,7 +1364,7 @@ const ViewProject = ({
toCompare = getFormatDate(dateRangeCompare[1])
keyCompare = getProjectCacheCustomKey(fromCompare, toCompare, timeBucket, mode, newFilters || filters)
} else {
- showError(t('project.compareDateRangeError'))
+ toast.error(t('project.compareDateRangeError'))
compareDisable()
}
} else {
@@ -1675,11 +1672,11 @@ const ViewProject = ({
const message = _isEmpty(reason.data?.message) ? reason.data : reason.data.message
console.error('[ERROR] (loadError)(getError)', message)
- showError(message)
+ toast.error(message)
}
setErrorLoading(false)
},
- [dateRange, id, period, projectPassword, showError, timezone],
+ [dateRange, id, period, projectPassword, timezone],
)
const loadSession = async (psid: string) => {
@@ -1695,7 +1692,7 @@ const ViewProject = ({
setActiveSession(session)
} catch (reason: any) {
console.error('[ERROR] (loadSession)(getSession)', reason)
- showError(reason) // todo: error message i18n
+ toast.error(reason)
}
setSessionLoading(false)
@@ -1951,7 +1948,7 @@ const ViewProject = ({
measure,
)
} else {
- showError(t('project.compareDateRangeError'))
+ toast.error(t('project.compareDateRangeError'))
compareDisable()
}
} else {
@@ -2700,7 +2697,7 @@ const ViewProject = ({
setIsInAIDetailsMode(true)
} catch (reason) {
console.error(`[forecastDetails] Error: ${reason}`)
- showError(t('apiNotifications.noAIForecastAvailable'))
+ toast.error(t('apiNotifications.noAIForecastAvailable'))
}
}
@@ -5476,7 +5473,6 @@ const ViewProject = ({
setProjectViewToUpdate(undefined)
}}
defaultView={projectViewToUpdate}
- showError={showError}
pid={id}
tnMapping={tnMapping}
/>
diff --git a/app/pages/Project/View/components/AddAViewModal.tsx b/app/pages/Project/View/components/AddAViewModal.tsx
index 11056bbde..b5866c91d 100644
--- a/app/pages/Project/View/components/AddAViewModal.tsx
+++ b/app/pages/Project/View/components/AddAViewModal.tsx
@@ -6,6 +6,7 @@ import _filter from 'lodash/filter'
import _map from 'lodash/map'
import _find from 'lodash/find'
import _size from 'lodash/size'
+import { toast } from 'sonner'
import Modal from 'ui/Modal'
import Select from 'ui/Select'
@@ -30,7 +31,6 @@ interface IAddAViewModal {
showModal: boolean
setShowModal: (show: boolean) => void
tnMapping: Record<string, string>
- showError: (message: string) => void
defaultView?: IProjectView
}
@@ -203,7 +203,6 @@ const AddAViewModal = ({
setShowModal,
tnMapping,
projectPassword,
- showError,
defaultView,
}: IAddAViewModal) => {
const {
@@ -344,7 +343,7 @@ const AddAViewModal = ({
}
} catch (reason) {
console.error('[ERROR] onViewCreate:', reason)
- showError(t('apiNotifications.somethingWentWrong'))
+ toast.error(t('apiNotifications.somethingWentWrong'))
}
setIsViewSubmitting(false)
diff --git a/app/pages/Project/View/components/UserFlow.tsx b/app/pages/Project/View/components/UserFlow.tsx
index da4cab40a..b9dc2f53d 100644
--- a/app/pages/Project/View/components/UserFlow.tsx
+++ b/app/pages/Project/View/components/UserFlow.tsx
@@ -1,10 +1,10 @@
-import { useEffect, useState } from 'react'
import type i18next from 'i18next'
+import { useEffect, useState } from 'react'
+import { toast } from 'sonner'
import { ResponsiveSankey } from '@nivo/sankey'
import { connect } from 'react-redux'
import { StateType, AppDispatch } from 'redux/store'
import UIActions from 'redux/reducers/ui'
-import { errorsActions } from 'redux/reducers/errors'
import { IUserFlow } from 'redux/models/IUserFlow'
import _isEmpty from 'lodash/isEmpty'
import { getUserFlowCacheKey } from 'redux/constants'
@@ -39,13 +39,6 @@ const mapDispatchToProps = (dispatch: AppDispatch) => ({
}),
)
},
- generateError: (message: string) => {
- dispatch(
- errorsActions.genericError({
- message,
- }),
- )
- },
})
interface IJSXUserFlow {
@@ -64,7 +57,6 @@ interface IJSXUserFlow {
isReversed?: boolean
setUserFlowAscending: (data: IUserFlow, id: string, pd: string, fltr: any) => void
setUserFlowDescending: (data: IUserFlow, id: string, pd: string, fltr: any) => void
- generateError: (message: string) => void
t: typeof i18next.t
filters: IFilter[]
setReversed: () => void
@@ -85,7 +77,6 @@ const UserFlow = ({
isReversed,
setUserFlowAscending,
setUserFlowDescending,
- generateError,
t,
projectPassword,
}: IJSXUserFlow) => {
@@ -104,7 +95,7 @@ const UserFlow = ({
setUserFlowDescending(descending, pid, period, filters)
})
.catch((err: Error) => {
- generateError(err.message)
+ toast.error(err.message)
})
.finally(() => {
setIsLoading(false)
diff --git a/app/pages/Project/uptime/Settings.tsx b/app/pages/Project/uptime/Settings.tsx
index 6e24a937d..98515d990 100644
--- a/app/pages/Project/uptime/Settings.tsx
+++ b/app/pages/Project/uptime/Settings.tsx
@@ -24,9 +24,8 @@ import { withAuthentication, auth } from 'hoc/protected'
import routes from 'utils/routes'
import { Monitor } from 'redux/models/Uptime'
import { useDispatch, useSelector } from 'react-redux'
+import { toast } from 'sonner'
import { StateType } from 'redux/store'
-import { errorsActions } from 'redux/reducers/errors'
-import { alertsActions } from 'redux/reducers/alerts'
import UIActions from 'redux/reducers/ui'
import { useRequiredParams } from 'hooks/useRequiredParams'
import Select from 'ui/Select'
@@ -183,8 +182,6 @@ const UptimeSettings = (): JSX.Element => {
const [beenSubmitted, setBeenSubmitted] = useState<boolean>(false)
const [showModal, setShowModal] = useState<boolean>(false)
- const showError = (message: string) => dispatch(errorsActions.genericError({ message }))
- const generateAlerts = (message: string) => dispatch(alertsActions.generateAlerts({ message, type: 'success' }))
const setMonitors = (monitors: Monitor[]) => dispatch(UIActions.setMonitors(monitors))
const setMonitorsTotal = (total: number) => dispatch(UIActions.setMonitorsTotal({ total }))
@@ -257,10 +254,10 @@ const UptimeSettings = (): JSX.Element => {
.then((res) => {
navigate(`/projects/${pid}?tab=${PROJECT_TABS.uptime}`)
setMonitors([..._filter(monitors, (a) => a.id !== id), res])
- generateAlerts(t('monitor.monitorUpdated'))
+ toast.success(t('monitor.monitorUpdated'))
})
.catch((err) => {
- showError(err.message || err || 'Something went wrong')
+ toast.error(err.message || err || 'Something went wrong')
})
} else {
createMonitor(pid, data as ICreateMonitor)
@@ -268,17 +265,17 @@ const UptimeSettings = (): JSX.Element => {
navigate(`/projects/${pid}?tab=${PROJECT_TABS.uptime}`)
setMonitors([...monitors, res])
setMonitorsTotal(total + 1)
- generateAlerts(t('monitor.monitorCreated'))
+ toast.success(t('monitor.monitorCreated'))
})
.catch((err) => {
- showError(err.message || err || 'Something went wrong')
+ toast.error(err.message || err || 'Something went wrong')
})
}
}
const onDelete = () => {
if (!id) {
- showError('Something went wrong')
+ toast.error('Something went wrong')
return
}
@@ -287,10 +284,10 @@ const UptimeSettings = (): JSX.Element => {
setMonitors(_filter(monitors, (a) => a.id !== id))
setMonitorsTotal(total - 1)
navigate(`/projects/${pid}?tab=${PROJECT_TABS.uptime}`)
- generateAlerts(t('monitor.monitorDeleted'))
+ toast.success(t('monitor.monitorDeleted'))
})
.catch((err) => {
- showError(err.message || err || 'Something went wrong')
+ toast.error(err.message || err || 'Something went wrong')
})
}
diff --git a/app/pages/Project/uptime/View.tsx b/app/pages/Project/uptime/View.tsx
index 9ae809bbb..0cc4b125e 100644
--- a/app/pages/Project/uptime/View.tsx
+++ b/app/pages/Project/uptime/View.tsx
@@ -18,6 +18,7 @@ import {
ArrowPathIcon,
ChevronLeftIcon,
} from '@heroicons/react/24/outline'
+import { toast } from 'sonner'
import routes from 'utils/routes'
import Button from 'ui/Button'
@@ -25,8 +26,6 @@ import Modal from 'ui/Modal'
import PaidFeature from 'modals/PaidFeature'
import { PLAN_LIMITS, tbPeriodPairs, UPTIME_PERIOD_PAIRS } from 'redux/constants'
import UIActions from 'redux/reducers/ui'
-import { alertsActions } from 'redux/reducers/alerts'
-import { errorsActions } from 'redux/reducers/errors'
import { deleteMonitor as deleteMonitorApi, getMonitorOverallStats, getMonitorStats, getProjectMonitors } from 'api'
import { StateType } from 'redux/store'
import { Monitor, MonitorOverallObject } from 'redux/models/Uptime'
@@ -223,18 +222,9 @@ const Uptime = (): JSX.Element => {
total: total - 1,
}),
)
- dispatch(
- alertsActions.generateAlerts({
- message: t('monitor.monitorDeleted'),
- type: 'success',
- }),
- )
+ toast.success(t('monitor.monitorDeleted'))
} catch (reason: any) {
- dispatch(
- errorsActions.genericError({
- message: reason?.response?.data?.message || reason?.message || 'Something went wrong',
- }),
- )
+ toast.error(reason?.response?.data?.message || reason?.message || 'Something went wrong')
}
}
diff --git a/app/pages/UserSettings/UserSettings.container.tsx b/app/pages/UserSettings/UserSettings.container.tsx
index 9c95e6b77..959a2dae5 100644
--- a/app/pages/UserSettings/UserSettings.container.tsx
+++ b/app/pages/UserSettings/UserSettings.container.tsx
@@ -1,9 +1,8 @@
import { connect } from 'react-redux'
+import { toast } from 'sonner'
import type i18next from 'i18next'
import UIActions from 'redux/reducers/ui'
-import { errorsActions } from 'redux/reducers/errors'
import { authActions } from 'redux/reducers/auth'
-import { alertsActions } from 'redux/reducers/alerts'
import { trackCustom } from 'utils/analytics'
import { StateType, AppDispatch } from 'redux/store'
import sagaActions from 'redux/sagas/actions'
@@ -26,13 +25,6 @@ const mapStateToProps = (state: StateType) => {
}
const mapDispatchToProps = (dispatch: AppDispatch) => ({
- onGDPRExportFailed: (message: string) => {
- dispatch(
- errorsActions.genericError({
- message,
- }),
- )
- },
onDelete: (
t: typeof i18next.t,
deletionFeedback: string,
@@ -42,12 +34,7 @@ const mapDispatchToProps = (dispatch: AppDispatch) => ({
) => {
dispatch(
sagaActions.deleteAccountAsync(
- (error: string) =>
- dispatch(
- errorsActions.deleteAccountFailed({
- message: error,
- }),
- ),
+ (error: string) => toast.error(error),
() => {
trackCustom('ACCOUNT_DELETED', {
reason_stated: deletionFeedback ? 'true' : 'false',
@@ -65,14 +52,6 @@ const mapDispatchToProps = (dispatch: AppDispatch) => ({
onDeleteProjectCache: () => {
dispatch(UIActions.deleteProjectCache({}))
},
- userSharedUpdate: (message: string) => {
- dispatch(
- alertsActions.userSharedUpdate({
- message,
- type: 'success',
- }),
- )
- },
setCache: (key: string, value: any) => {
dispatch(
UIActions.setCache({
@@ -81,20 +60,6 @@ const mapDispatchToProps = (dispatch: AppDispatch) => ({
}),
)
},
- sharedProjectError: (message: string) => {
- dispatch(
- errorsActions.sharedProjectFailed({
- message,
- }),
- )
- },
- genericError: (message: string) => {
- dispatch(
- errorsActions.genericError({
- message,
- }),
- )
- },
removeProject: (projectId: string) => {
dispatch(
UIActions.removeProject({
@@ -123,21 +88,6 @@ const mapDispatchToProps = (dispatch: AppDispatch) => ({
}),
)
},
- updateProfileFailed: (message: string) => {
- dispatch(
- errorsActions.updateUserProfileFailed({
- message,
- }),
- )
- },
- accountUpdated: (message: string) => {
- dispatch(
- alertsActions.accountUpdated({
- message,
- type: 'success',
- }),
- )
- },
updateUserProfileAsync: (
data: Partial<IUser>,
successMessage: string,
@@ -146,12 +96,7 @@ const mapDispatchToProps = (dispatch: AppDispatch) => ({
dispatch(
sagaActions.updateUserProfileAsync(data, (res: any) => {
if (res) {
- dispatch(
- alertsActions.accountUpdated({
- message: successMessage,
- type: 'success',
- }),
- )
+ toast.success(successMessage)
}
callback(res)
}),
diff --git a/app/pages/UserSettings/UserSettings.tsx b/app/pages/UserSettings/UserSettings.tsx
index 93f07f2e2..515de9b02 100644
--- a/app/pages/UserSettings/UserSettings.tsx
+++ b/app/pages/UserSettings/UserSettings.tsx
@@ -4,6 +4,7 @@ import type i18next from 'i18next'
import { useNavigate } from '@remix-run/react'
import { ClientOnly } from 'remix-utils/client-only'
import { useTranslation } from 'react-i18next'
+import { toast } from 'sonner'
import _size from 'lodash/size'
import _isEmpty from 'lodash/isEmpty'
import _isNull from 'lodash/isNull'
@@ -125,14 +126,8 @@ interface IProps {
removeShareProject: (id: string) => void
setUserShareData: (data: Partial<ISharedProject>, id: string) => void
setProjectsShareData: (data: Partial<ISharedProject>, id: string) => void
- userSharedUpdate: (message: string) => void
- sharedProjectError: (message: string) => void
updateUserData: (data: Partial<IUser>) => void
- genericError: (message: string) => void
- onGDPRExportFailed: (message: string) => void
- updateProfileFailed: (message: string) => void
updateUserProfileAsync: (data: IUser, successMessage: string, callback?: (isSuccess: boolean) => void) => void
- accountUpdated: (t: string) => void
setAPIKey: (key: string | null) => void
user: IUser
dontRemember: boolean
@@ -162,14 +157,8 @@ const UserSettings = ({
removeShareProject,
setUserShareData,
setProjectsShareData,
- userSharedUpdate,
- sharedProjectError,
updateUserData,
- genericError,
- onGDPRExportFailed,
- updateProfileFailed,
updateUserProfileAsync,
- accountUpdated,
setAPIKey,
user,
dontRemember,
@@ -346,11 +335,11 @@ const UserSettings = ({
setSettingUpdating(false)
if (isSuccess) {
- accountUpdated(t('profileSettings.updated'))
+ toast.success(t('profileSettings.updated'))
return
}
- genericError(t('apiNotifications.somethingWentWrong'))
+ toast.error(t('apiNotifications.somethingWentWrong'))
})
}
@@ -366,9 +355,9 @@ const UserSettings = ({
updateUserData({
receiveLoginNotifications: checked,
})
- accountUpdated(t('profileSettings.updated'))
+ toast.success(t('profileSettings.updated'))
} catch {
- genericError(t('apiNotifications.somethingWentWrong'))
+ toast.error(t('apiNotifications.somethingWentWrong'))
} finally {
setSettingUpdating(false)
}
@@ -439,7 +428,7 @@ const UserSettings = ({
getCookie(GDPR_REQUEST) ||
(!_isNull(exportedAt) && !dayjs().isAfter(dayjs.utc(exportedAt).add(GDPR_EXPORT_TIMEFRAME, 'day'), 'day'))
) {
- onGDPRExportFailed(
+ toast.error(
t('profileSettings.tryAgainInXDays', {
amount: GDPR_EXPORT_TIMEFRAME,
}),
@@ -449,16 +438,16 @@ const UserSettings = ({
await exportUserData()
trackCustom('GDPR_EXPORT')
- accountUpdated(t('profileSettings.reportSent'))
+ toast.success(t('profileSettings.reportSent'))
setCookie(GDPR_REQUEST, true, 1209600) // setting cookie for 14 days
- } catch (e) {
- updateProfileFailed(e as string)
+ } catch (reason: any) {
+ toast.error(reason)
}
}
const onEmailConfirm = async (errorCallback: any) => {
if (getCookie(CONFIRMATION_TIMEOUT)) {
- updateProfileFailed(t('profileSettings.confTimeout'))
+ toast.error(t('profileSettings.confTimeout'))
return
}
@@ -467,12 +456,12 @@ const UserSettings = ({
if (res) {
setCookie(CONFIRMATION_TIMEOUT, true, 600)
- accountUpdated(t('profileSettings.confSent'))
+ toast.success(t('profileSettings.confSent'))
} else {
errorCallback(t('profileSettings.noConfLeft'))
}
- } catch (e) {
- updateProfileFailed(e as string)
+ } catch (reason: any) {
+ toast.error(reason)
}
}
@@ -480,8 +469,8 @@ const UserSettings = ({
try {
const res = await generateApiKey()
setAPIKey(res.apiKey)
- } catch (e) {
- updateProfileFailed(e as string)
+ } catch (reason: any) {
+ toast.error(reason)
}
}
@@ -489,20 +478,11 @@ const UserSettings = ({
try {
await deleteApiKey()
setAPIKey(null)
- } catch (e) {
- updateProfileFailed(e as string)
+ } catch (reason: any) {
+ toast.error(reason)
}
}
- // const setAsyncThemeType = async (theme) => {
- // try {
- // await setTheme(theme)
- // setThemeType(theme)
- // } catch (e) {
- // updateProfileFailed(e)
- // }
- // }
-
const setAsyncTimeFormat = async () => {
setBeenSubmitted(true)
@@ -717,12 +697,7 @@ const UserSettings = ({
<h3 className='mt-2 flex items-center text-lg font-bold text-gray-900 dark:text-gray-50'>
{t('profileSettings.2fa')}
</h3>
- <TwoFA
- user={user}
- dontRemember={dontRemember}
- updateUserData={updateUserData}
- genericError={genericError}
- />
+ <TwoFA user={user} dontRemember={dontRemember} updateUserData={updateUserData} />
{/* Socialisations setup */}
<hr className='mt-5 border-gray-200 dark:border-gray-600' />
@@ -732,13 +707,7 @@ const UserSettings = ({
>
{t('profileSettings.socialisations')}
</h3>
- <Socialisations
- user={user}
- genericError={genericError}
- linkSSO={linkSSO}
- unlinkSSO={unlinkSSO}
- theme={theme}
- />
+ <Socialisations user={user} linkSSO={linkSSO} unlinkSSO={unlinkSSO} theme={theme} />
{/* Shared projects setting */}
<hr className='mt-5 border-gray-200 dark:border-gray-600' />
@@ -784,8 +753,6 @@ const UserSettings = ({
removeShareProject={removeShareProject}
setUserShareData={setUserShareData}
setProjectsShareData={setProjectsShareData}
- userSharedUpdate={userSharedUpdate}
- sharedProjectError={sharedProjectError}
/>
))}
</tbody>
@@ -937,7 +904,6 @@ const UserSettings = ({
user={user}
updateUserData={updateUserData}
handleIntegrationSave={handleIntegrationSave}
- genericError={genericError}
/>
{user.isTelegramChatIdConfirmed && (
<Checkbox
@@ -966,12 +932,10 @@ const UserSettings = ({
</h3>
<Referral
user={user}
- genericError={genericError}
updateUserData={updateUserData}
referralStatistics={referralStatistics}
activeReferrals={activeReferrals}
setCache={setCache}
- accountUpdated={accountUpdated}
/>
</>
)
diff --git a/app/pages/UserSettings/components/Integrations.tsx b/app/pages/UserSettings/components/Integrations.tsx
index 387e144a6..81a2f9a06 100644
--- a/app/pages/UserSettings/components/Integrations.tsx
+++ b/app/pages/UserSettings/components/Integrations.tsx
@@ -4,6 +4,7 @@ import { useTranslation, Trans } from 'react-i18next'
import _map from 'lodash/map'
import _isString from 'lodash/isString'
import { CheckCircleIcon, XCircleIcon, ClockIcon } from '@heroicons/react/24/solid'
+import { toast } from 'sonner'
import Input from 'ui/Input'
import Button from 'ui/Button'
@@ -51,12 +52,10 @@ const Integrations = ({
user,
updateUserData,
handleIntegrationSave,
- genericError,
}: {
user: IUser
updateUserData: (data: Partial<IUser>) => void
handleIntegrationSave: (data: Partial<IUser>, cb: (isSuccess: boolean) => void) => void
- genericError: (message: string) => void
}) => {
const { t } = useTranslation('common')
const available = getAvailableIntegrations(t)
@@ -96,7 +95,7 @@ const Integrations = ({
},
(isSuccess: boolean) => {
if (!isSuccess) {
- genericError(t('apiNotifications.integrationSaveError'))
+ toast.error(t('apiNotifications.integrationSaveError'))
}
setIsIntegrationLoading(false)
@@ -113,7 +112,7 @@ const Integrations = ({
},
(isSuccess: boolean) => {
if (!isSuccess) {
- genericError(t('apiNotifications.integrationSaveError'))
+ toast.error(t('apiNotifications.integrationSaveError'))
}
setIsIntegrationLoading(false)
@@ -172,9 +171,9 @@ const Integrations = ({
})
} catch (reason) {
if (_isString(reason)) {
- genericError(reason)
+ toast.error(reason)
} else {
- genericError(t('apiNotifications.integrationRemovalError'))
+ toast.error(t('apiNotifications.integrationRemovalError'))
}
console.error(`[ERROR] Failed to remove TG integration: ${reason}`)
}
@@ -189,7 +188,7 @@ const Integrations = ({
},
(isSuccess: boolean) => {
if (!isSuccess) {
- genericError(t('apiNotifications.integrationRemovalError'))
+ toast.error(t('apiNotifications.integrationRemovalError'))
}
updateUserData({
@@ -207,7 +206,7 @@ const Integrations = ({
},
(isSuccess: boolean) => {
if (!isSuccess) {
- genericError(t('apiNotifications.integrationRemovalError'))
+ toast.error(t('apiNotifications.integrationRemovalError'))
}
updateUserData({
diff --git a/app/pages/UserSettings/components/ProjectList.tsx b/app/pages/UserSettings/components/ProjectList.tsx
index 1bc818792..d462512e3 100644
--- a/app/pages/UserSettings/components/ProjectList.tsx
+++ b/app/pages/UserSettings/components/ProjectList.tsx
@@ -1,5 +1,6 @@
import React, { memo, useState } from 'react'
import dayjs from 'dayjs'
+import { toast } from 'sonner'
import { useTranslation } from 'react-i18next'
import Button from 'ui/Button'
@@ -13,16 +14,12 @@ const ProjectList = ({
removeProject,
setProjectsShareData,
setUserShareData,
- userSharedUpdate,
- sharedProjectError,
}: {
item: ISharedProject
removeShareProject: (id: string) => void
removeProject: (id: string) => void
setProjectsShareData: (data: Partial<ISharedProject>, id: string, shared?: boolean) => void
setUserShareData: (data: Partial<ISharedProject>, id: string) => void
- userSharedUpdate: (message: string) => void
- sharedProjectError: (message: string) => void
}): JSX.Element => {
const {
t,
@@ -37,10 +34,10 @@ const ProjectList = ({
await deleteShareProject(pid)
removeShareProject(pid)
removeProject(project.id)
- userSharedUpdate(t('apiNotifications.quitProject'))
- } catch (e) {
- console.error(`[ERROR] Error while quitting project: ${e}`)
- sharedProjectError(t('apiNotifications.quitProjectError'))
+ toast.success(t('apiNotifications.quitProject'))
+ } catch (reason) {
+ console.error(`[ERROR] Error while quitting project: ${reason}`)
+ toast.error(t('apiNotifications.quitProjectError'))
}
}
@@ -49,10 +46,10 @@ const ProjectList = ({
await acceptShareProject(id)
setProjectsShareData({ confirmed: true }, project.id)
setUserShareData({ confirmed: true }, id)
- userSharedUpdate(t('apiNotifications.acceptInvitation'))
+ toast.success(t('apiNotifications.acceptInvitation'))
} catch (e) {
console.error(`[ERROR] Error while accepting project invitation: ${e}`)
- sharedProjectError(t('apiNotifications.acceptInvitationError'))
+ toast.error(t('apiNotifications.acceptInvitationError'))
}
}
diff --git a/app/pages/UserSettings/components/Referral.tsx b/app/pages/UserSettings/components/Referral.tsx
index 98ea9d8c1..0ee68c63a 100644
--- a/app/pages/UserSettings/components/Referral.tsx
+++ b/app/pages/UserSettings/components/Referral.tsx
@@ -4,6 +4,7 @@ import { ClipboardDocumentIcon } from '@heroicons/react/24/outline'
import dayjs from 'dayjs'
import _isEmpty from 'lodash/isEmpty'
import _map from 'lodash/map'
+import { toast } from 'sonner'
import { generateRefCode, getPayoutsInfo, getReferrals, setPaypalEmail } from 'api'
import Tooltip from 'ui/Tooltip'
@@ -26,23 +27,13 @@ import { isValidEmail } from 'utils/validator'
interface IReferral {
user: IUser
- genericError: (message: string) => void
updateUserData: (data: Partial<IUser>) => void
setCache: (key: string, value: any) => void
activeReferrals: any[]
referralStatistics: any
- accountUpdated: (t: string) => void
}
-const Referral = ({
- user,
- genericError,
- updateUserData,
- referralStatistics,
- activeReferrals,
- setCache,
- accountUpdated,
-}: IReferral) => {
+const Referral = ({ user, updateUserData, referralStatistics, activeReferrals, setCache }: IReferral) => {
const {
t,
i18n: { language },
@@ -72,7 +63,7 @@ const Referral = ({
setCache('referralStatistics', info)
} catch (reason) {
console.error('[Referral][getRefStats] Something went wrong whilst requesting payouts information', reason)
- genericError(t('apiNotifications.payoutInfoError'))
+ toast.error(t('apiNotifications.payoutInfoError'))
}
}
@@ -82,7 +73,7 @@ const Referral = ({
setCache('activeReferrals', info)
} catch (reason) {
console.error('[Referral][getActiveReferrals] Something went wrong whilst requesting active referrals', reason)
- genericError(t('apiNotifications.payoutInfoError'))
+ toast.error(t('apiNotifications.payoutInfoError'))
}
}
@@ -95,7 +86,7 @@ const Referral = ({
setActiveReferralsRequested(true)
getActiveReferrals()
}
- }, [referralStatistics, referralStatsRequested, setCache, genericError, activeReferralsRequested, activeReferrals, t])
+ }, [referralStatistics, referralStatsRequested, setCache, activeReferralsRequested, activeReferrals, t])
const onRefCodeGenerate = async () => {
if (refCodeGenerating || user.refCode) {
@@ -109,8 +100,8 @@ const Referral = ({
updateUserData({
refCode,
})
- } catch (e) {
- genericError(t('apiNotifications.somethingWentWrong'))
+ } catch {
+ toast.error(t('apiNotifications.somethingWentWrong'))
} finally {
setRefCodeGenerating(false)
}
@@ -138,10 +129,10 @@ const Referral = ({
updateUserData({
paypalPaymentsEmail: paypalEmailAddress,
})
- accountUpdated(t('profileSettings.referral.payoutEmailUpdated'))
+ toast.success(t('profileSettings.referral.payoutEmailUpdated'))
} catch (reason) {
console.error('[Referral][updatePaypalEmail] Something went wrong whilst updating paypal email', reason)
- genericError(t('apiNotifications.somethingWentWrong'))
+ toast.error(t('apiNotifications.somethingWentWrong'))
}
setIsPaypalEmailLoading(false)
diff --git a/app/pages/UserSettings/components/Socialisations.tsx b/app/pages/UserSettings/components/Socialisations.tsx
index d124b17c8..704acb3cd 100644
--- a/app/pages/UserSettings/components/Socialisations.tsx
+++ b/app/pages/UserSettings/components/Socialisations.tsx
@@ -3,6 +3,7 @@ import type i18next from 'i18next'
import { useTranslation } from 'react-i18next'
import _map from 'lodash/map'
import { CheckCircleIcon, XCircleIcon } from '@heroicons/react/24/solid'
+import { toast } from 'sonner'
import Button from 'ui/Button'
import Google from 'ui/icons/GoogleG'
@@ -51,11 +52,10 @@ interface ISocialisations {
user: IUser
linkSSO: (t: typeof i18next.t, callback: (e: any) => void, provider: string) => void
unlinkSSO: (t: typeof i18next.t, callback: (e: any) => void, provider: string) => void
- genericError: (message: string) => void
theme: string
}
-const Socialisations = ({ user, linkSSO, unlinkSSO, genericError, theme }: ISocialisations) => {
+const Socialisations = ({ user, linkSSO, unlinkSSO, theme }: ISocialisations) => {
const { t } = useTranslation('common')
const [isLoading, setIsLoading] = useState(false)
@@ -125,7 +125,7 @@ const Socialisations = ({ user, linkSSO, unlinkSSO, genericError, theme }: ISoci
</div>
<div className='mt-2 flex justify-center sm:mt-0 sm:block'>
{connected && !unlinkable && (
- <Button onClick={() => genericError(t('profileSettings.cantUnlinkSocialisation'))} small danger>
+ <Button onClick={() => toast.error(t('profileSettings.cantUnlinkSocialisation'))} small danger>
{t('common.unlink')}
</Button>
)}
diff --git a/app/pages/UserSettings/components/TwoFA.tsx b/app/pages/UserSettings/components/TwoFA.tsx
index 11a2cf8f9..9fec8c900 100644
--- a/app/pages/UserSettings/components/TwoFA.tsx
+++ b/app/pages/UserSettings/components/TwoFA.tsx
@@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next'
import cx from 'clsx'
import _isNull from 'lodash/isNull'
import _isString from 'lodash/isString'
+import { toast } from 'sonner'
import Input from 'ui/Input'
import Button from 'ui/Button'
@@ -16,12 +17,10 @@ const TwoFA = ({
user,
dontRemember,
updateUserData,
- genericError,
}: {
user: IUser
dontRemember: boolean
updateUserData: (data: Partial<IUser>) => void
- genericError: (message: string) => void
}): JSX.Element => {
const { t } = useTranslation('common')
const [twoFAConfigurating, setTwoFAConfigurating] = useState<boolean>(false)
@@ -52,13 +51,13 @@ const TwoFA = ({
const result = await generate2FA()
setTwoFAConfigurating(true)
setTwoFAConfigData(result)
- } catch (e) {
- if (_isString(e)) {
- genericError(e)
+ } catch (reason) {
+ if (_isString(reason)) {
+ toast.error(reason)
} else {
- genericError(t('apiNotifications.generate2FAError'))
+ toast.error(t('apiNotifications.generate2FAError'))
}
- console.error(`[ERROR] Failed to generate 2FA: ${e}`)
+ console.error(`[ERROR] Failed to generate 2FA: ${reason}`)
setTwoFAConfigurating(false)
setTwoFAConfigData({})
}
@@ -77,9 +76,9 @@ const TwoFA = ({
setAccessToken(accessToken, dontRemember)
updateUserData({ isTwoFactorAuthenticationEnabled: true })
setTwoFARecovery(twoFactorRecoveryCode)
- } catch (e) {
- if (_isString(e)) {
- genericError(e)
+ } catch (reason) {
+ if (_isString(reason)) {
+ toast.error(reason)
}
setTwoFACodeError(t('profileSettings.invalid2fa'))
}
@@ -96,9 +95,9 @@ const TwoFA = ({
try {
await disable2FA(twoFACode)
updateUserData({ isTwoFactorAuthenticationEnabled: false })
- } catch (e) {
- if (_isString(e)) {
- genericError(e)
+ } catch (reason) {
+ if (_isString(reason)) {
+ toast.error(reason)
}
setTwoFACodeError(t('profileSettings.invalid2fa'))
}
diff --git a/app/redux/reducers/alerts.ts b/app/redux/reducers/alerts.ts
deleted file mode 100644
index ba1a6a86b..000000000
--- a/app/redux/reducers/alerts.ts
+++ /dev/null
@@ -1,41 +0,0 @@
-/* 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 || 'info'
-}
-
-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/app/redux/reducers/errors.ts b/app/redux/reducers/errors.ts
deleted file mode 100644
index 58ce4ecce..000000000
--- a/app/redux/reducers/errors.ts
+++ /dev/null
@@ -1,39 +0,0 @@
-/* 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 }>) => {
- state.error = payload.message
-}
-
-const errorsSlice = createSlice({
- name: 'alerts',
- initialState,
- reducers: {
- genericError: errorsCreate,
- setError: 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 errorsActions = errorsSlice.actions
-export default errorsSlice.reducer
diff --git a/app/redux/sagas/auth/workers/deleteUserAccount.ts b/app/redux/sagas/auth/workers/deleteUserAccount.ts
index 8509ba463..eeafd2236 100644
--- a/app/redux/sagas/auth/workers/deleteUserAccount.ts
+++ b/app/redux/sagas/auth/workers/deleteUserAccount.ts
@@ -1,8 +1,8 @@
import { call, put } from 'redux-saga/effects'
import type i18next from 'i18next'
+import { toast } from 'sonner'
import { authActions } from 'redux/reducers/auth'
-import { alertsActions } from 'redux/reducers/alerts'
const { deleteUser } = require('api')
export default function* deleteUserAccountWorker({
@@ -19,12 +19,7 @@ export default function* deleteUserAccountWorker({
yield call(deleteUser, deletionFeedback)
yield call(successCallback)
yield put(authActions.deleteAccountSuccess())
- yield put(
- alertsActions.accountDeleted({
- message: t('apiNotifications.accountDeleted'),
- type: 'success',
- }),
- )
+ toast.success(t('apiNotifications.accountDeleted'))
} catch (error) {
let message
diff --git a/app/redux/sagas/auth/workers/signin.ts b/app/redux/sagas/auth/workers/signin.ts
index 1698e2a28..fe8c63041 100644
--- a/app/redux/sagas/auth/workers/signin.ts
+++ b/app/redux/sagas/auth/workers/signin.ts
@@ -1,8 +1,8 @@
import { call, put } from 'redux-saga/effects'
import _isObject from 'lodash/isPlainObject'
import _omit from 'lodash/omit'
+import { toast } from 'sonner'
import { authActions } from 'redux/reducers/auth'
-import { errorsActions } from 'redux/reducers/errors'
import UIActions from 'redux/reducers/ui'
import { setAccessToken } from 'utils/accessToken'
@@ -46,14 +46,10 @@ export default function* singinWorker({ payload: { credentials, callback } }: IS
yield put(sagaActions.loadProjectAlerts())
yield put(sagaActions.loadMonitors())
callback(true, false)
- } catch (error) {
- // @ts-ignore
+ } catch (error: any) {
const err = _isObject(error) ? error.message : error
- yield put(
- errorsActions.loginFailed({
- message: err || 'apiNotifications.somethingWentWrong',
- }),
- )
+
+ toast.error(err || 'apiNotifications.somethingWentWrong')
callback(false, false)
} finally {
yield put(authActions.finishLoading())
diff --git a/app/redux/sagas/auth/workers/signup.ts b/app/redux/sagas/auth/workers/signup.ts
index 9c928cca5..f5cfc8f50 100644
--- a/app/redux/sagas/auth/workers/signup.ts
+++ b/app/redux/sagas/auth/workers/signup.ts
@@ -1,6 +1,6 @@
import { call, put } from 'redux-saga/effects'
import { authActions } from 'redux/reducers/auth'
-import { errorsActions } from 'redux/reducers/errors'
+import { toast } from 'sonner'
import { setAccessToken } from 'utils/accessToken'
import { setRefreshToken } from 'utils/refreshToken'
@@ -52,11 +52,10 @@ export default function* signupWorder({
yield put(sagaActions.loadProjectAlerts())
yield put(sagaActions.loadMonitors())
callback(true)
- } catch (error: unknown) {
- // @ts-ignore
+ } catch (error: any) {
const message = error.message || (typeof error === 'string' ? error : error[0])
- // @ts-ignore
- yield put(errorsActions.signupFailed(message || 'apiNotifications.somethingWentWrong'))
+
+ toast.error(message)
callback(false)
} finally {
yield put(authActions.finishLoading())
diff --git a/app/redux/sagas/auth/workers/sso_auth.ts b/app/redux/sagas/auth/workers/sso_auth.ts
index d0a6815bb..d4627c8ff 100644
--- a/app/redux/sagas/auth/workers/sso_auth.ts
+++ b/app/redux/sagas/auth/workers/sso_auth.ts
@@ -1,8 +1,8 @@
import { call, put, delay } from 'redux-saga/effects'
import type i18next from 'i18next'
+import { toast } from 'sonner'
import { authActions } from 'redux/reducers/auth'
-import { errorsActions } from 'redux/reducers/errors'
import { setAccessToken } from 'utils/accessToken'
import { setRefreshToken } from 'utils/refreshToken'
import { openBrowserWindow } from 'utils/generic'
@@ -29,11 +29,7 @@ export default function* ssoAuth({ payload: { callback, dontRemember, t, provide
const authWindow = openBrowserWindow('', AUTH_WINDOW_WIDTH, AUTH_WINDOW_HEIGHT)
if (!authWindow) {
- yield put(
- errorsActions.loginFailed({
- message: t('apiNotifications.socialisationAuthGenericError'),
- }),
- )
+ toast.error(t('apiNotifications.socialisationAuthGenericError'))
callback(false, false)
return
}
@@ -91,11 +87,7 @@ export default function* ssoAuth({ payload: { callback, dontRemember, t, provide
}
}
} catch (reason) {
- yield put(
- errorsActions.loginFailed({
- message: t('apiNotifications.socialisationAuthGenericError'),
- }),
- )
+ toast.error(t('apiNotifications.socialisationAuthGenericError'))
callback(false, false)
}
}
diff --git a/app/redux/sagas/auth/workers/sso_link.ts b/app/redux/sagas/auth/workers/sso_link.ts
index a5ea1c995..0c509a282 100644
--- a/app/redux/sagas/auth/workers/sso_link.ts
+++ b/app/redux/sagas/auth/workers/sso_link.ts
@@ -1,9 +1,8 @@
-import { call, put, delay } from 'redux-saga/effects'
import type i18next from 'i18next'
+import { call, put, delay } from 'redux-saga/effects'
+import { toast } from 'sonner'
import { authActions } from 'redux/reducers/auth'
-import { errorsActions } from 'redux/reducers/errors'
-import { alertsActions } from 'redux/reducers/alerts'
import { openBrowserWindow } from 'utils/generic'
const { linkBySSOHash, generateSSOAuthURL, authMe } = require('api')
@@ -24,11 +23,7 @@ export default function* ssoLink({ payload: { callback, t, provider } }: ISSOLin
const authWindow = openBrowserWindow('', AUTH_WINDOW_WIDTH, AUTH_WINDOW_HEIGHT)
if (!authWindow) {
- yield put(
- errorsActions.loginFailed({
- message: t('apiNotifications.socialisationGenericError'),
- }),
- )
+ toast.error(t('apiNotifications.socialisationGenericError'))
callback(false)
return
}
@@ -53,12 +48,7 @@ export default function* ssoLink({ payload: { callback, t, provider } }: ISSOLin
const user = yield call(authMe)
yield put(authActions.loginSuccessful(user))
- yield put(
- alertsActions.generateAlerts({
- message: t('apiNotifications.socialAccountLinked'),
- type: 'success',
- }),
- )
+ toast.success(t('apiNotifications.socialAccountLinked'))
callback(true)
return
@@ -71,11 +61,7 @@ export default function* ssoLink({ payload: { callback, t, provider } }: ISSOLin
}
}
} catch (reason) {
- yield put(
- errorsActions.loginFailed({
- message: t('apiNotifications.socialisationGenericError'),
- }),
- )
+ toast.error(t('apiNotifications.socialisationGenericError'))
callback(false)
}
}
diff --git a/app/redux/sagas/auth/workers/sso_unlink.ts b/app/redux/sagas/auth/workers/sso_unlink.ts
index 6092f8c22..b9868fcbe 100644
--- a/app/redux/sagas/auth/workers/sso_unlink.ts
+++ b/app/redux/sagas/auth/workers/sso_unlink.ts
@@ -1,11 +1,10 @@
-import { call, put } from 'redux-saga/effects'
import type i18next from 'i18next'
+import { call, put } from 'redux-saga/effects'
import _values from 'lodash/values'
import _includes from 'lodash/includes'
+import { toast } from 'sonner'
import { authActions } from 'redux/reducers/auth'
-import { errorsActions } from 'redux/reducers/errors'
-import { alertsActions } from 'redux/reducers/alerts'
import { SSO_PROVIDERS } from 'redux/constants'
const { unlinkSSO, authMe } = require('api')
@@ -30,19 +29,10 @@ export default function* ssoUnlink({ payload: { provider, t, callback } }: ISSOU
const user = yield call(authMe)
yield put(authActions.loginSuccessful(user))
- yield put(
- alertsActions.generateAlerts({
- message: t('apiNotifications.socialAccountUninked'),
- type: 'success',
- }),
- )
+ toast.success(t('apiNotifications.socialAccountUninked'))
callback(true)
} catch (reason) {
- yield put(
- errorsActions.loginFailed({
- message: t('apiNotifications.socialisationUnlinkGenericError'),
- }),
- )
+ toast.error(t('apiNotifications.socialisationUnlinkGenericError'))
callback(false)
}
}
diff --git a/app/redux/sagas/auth/workers/updateUserProfile.ts b/app/redux/sagas/auth/workers/updateUserProfile.ts
index 2cad7741b..fc1897b01 100644
--- a/app/redux/sagas/auth/workers/updateUserProfile.ts
+++ b/app/redux/sagas/auth/workers/updateUserProfile.ts
@@ -1,7 +1,7 @@
import { call, put } from 'redux-saga/effects'
+import { toast } from 'sonner'
import { authActions } from 'redux/reducers/auth'
-import { errorsActions } from 'redux/reducers/errors'
import { IUser } from '../../../models/IUser'
const { changeUserDetails } = require('api')
@@ -19,14 +19,8 @@ export default function* updateUserProfileWorker({
yield put(authActions.updateUserProfileSuccess(user))
isSuccess = true
- } catch (e: unknown) {
- const error = e as { message: string } | string[] | string
- yield put(
- errorsActions.updateUserProfileFailed({
- // @ts-ignore
- message: error?.message || (typeof error === 'string' ? error : error[0]),
- }),
- )
+ } catch (reason: any) {
+ toast.error(reason?.message || (typeof reason === 'string' ? reason : reason[0]))
} finally {
yield put(authActions.finishLoading())
callback(isSuccess)
diff --git a/app/redux/sagas/auth/workers/update_show_live_visitors_in_title.ts b/app/redux/sagas/auth/workers/update_show_live_visitors_in_title.ts
index 7fe8de266..cdb9a19a4 100644
--- a/app/redux/sagas/auth/workers/update_show_live_visitors_in_title.ts
+++ b/app/redux/sagas/auth/workers/update_show_live_visitors_in_title.ts
@@ -1,7 +1,7 @@
import { call, put } from 'redux-saga/effects'
+import { toast } from 'sonner'
import { authActions } from 'redux/reducers/auth'
-import { errorsActions } from 'redux/reducers/errors'
import { IUser } from '../../../models/IUser'
const { setShowLiveVisitorsInTitle } = require('api')
@@ -18,14 +18,8 @@ export default function* updateShowLiveVisitorsInTitle({ payload: { show, callba
yield put(authActions.partiallyOverwriteUser(user))
isSuccess = true
- } catch (e: unknown) {
- const error = e as { message: string } | string[] | string
- yield put(
- errorsActions.updateUserProfileFailed({
- // @ts-ignore
- message: error?.message || (typeof error === 'string' ? error : error[0]),
- }),
- )
+ } catch (reason: any) {
+ toast.error(reason?.message || (typeof reason === 'string' ? reason : reason[0]))
} finally {
callback(isSuccess)
}
diff --git a/app/redux/sagas/ui/load_alerts.ts b/app/redux/sagas/ui/load_alerts.ts
index 76bd137c8..e27069d05 100644
--- a/app/redux/sagas/ui/load_alerts.ts
+++ b/app/redux/sagas/ui/load_alerts.ts
@@ -1,8 +1,8 @@
import { put, call } from 'redux-saga/effects'
+import { toast } from 'sonner'
import Debug from 'debug'
import _isString from 'lodash/isString'
import UIActions from 'redux/reducers/ui'
-import { errorsActions } from 'redux/reducers/errors'
import { DEFAULT_ALERTS_TAKE, isSelfhosted } from 'redux/constants'
const { getAlerts } = require('api')
@@ -28,11 +28,7 @@ export default function* loadProjectAlerts({ payload: { take = DEFAULT_ALERTS_TA
} catch (e: unknown) {
const { message } = e as { message: string }
if (_isString(message)) {
- yield put(
- errorsActions.setError({
- message,
- }),
- )
+ toast.error(message)
}
debug('failed to load extensions: %s', message)
} finally {
diff --git a/app/redux/sagas/ui/load_monitors.ts b/app/redux/sagas/ui/load_monitors.ts
index 6ad0af6e9..0eb5e3961 100644
--- a/app/redux/sagas/ui/load_monitors.ts
+++ b/app/redux/sagas/ui/load_monitors.ts
@@ -1,7 +1,7 @@
import { put, call } from 'redux-saga/effects'
+import { toast } from 'sonner'
import _isString from 'lodash/isString'
import UIActions from 'redux/reducers/ui'
-import { errorsActions } from 'redux/reducers/errors'
import { DEFAULT_MONITORS_TAKE, isSelfhosted } from 'redux/constants'
const { getAllMonitors } = require('api')
@@ -25,11 +25,7 @@ export default function* loadMonitors({ payload: { take = DEFAULT_MONITORS_TAKE,
} catch (e: unknown) {
const { message } = e as { message: string }
if (_isString(message)) {
- yield put(
- errorsActions.setError({
- message,
- }),
- )
+ toast.error(message)
}
} finally {
yield put(UIActions.setMonitorsLoading(false))
diff --git a/app/redux/store/index.ts b/app/redux/store/index.ts
index 91dbe9297..4bfe28cc3 100644
--- a/app/redux/store/index.ts
+++ b/app/redux/store/index.ts
@@ -4,8 +4,6 @@ import { useDispatch } from 'react-redux'
import { isDevelopment } from 'redux/constants'
import rootSaga from '../sagas'
import authSlice from '../reducers/auth'
-import errorsSlice from '../reducers/errors'
-import alertsSlice from '../reducers/alerts'
import miscSlice from '../reducers/ui/misc'
import projectsSlice from '../reducers/ui/projects'
import alertsProjectsSlice from '../reducers/ui/alerts'
@@ -15,8 +13,6 @@ import monitorsSlice from '../reducers/ui/monitors'
const rootReducer = combineReducers({
auth: authSlice,
- errors: errorsSlice,
- alerts: alertsSlice,
ui: combineReducers({
misc: miscSlice,
projects: projectsSlice,
diff --git a/app/root.tsx b/app/root.tsx
index 3896add6a..09c264698 100644
--- a/app/root.tsx
+++ b/app/root.tsx
@@ -19,11 +19,8 @@ import { ExclamationTriangleIcon, ChevronDownIcon, ChevronUpIcon } from '@heroic
import { Provider } from 'react-redux'
import clsx from 'clsx'
import _replace from 'lodash/replace'
-// @ts-ignore
-import { transitions, positions, Provider as AlertProvider } from '@blaumaus/react-alert'
import BillboardCss from 'billboard.js/dist/billboard.min.css'
-import AlertTemplate from 'ui/Alert'
import { trackViews, trackErrors } from 'utils/analytics'
import { useChangeLanguage } from 'remix-i18next/react'
import { useTranslation } from 'react-i18next'
@@ -51,13 +48,6 @@ declare global {
}
}
-const options = {
- position: positions.BOTTOM_RIGHT,
- timeout: 8000,
- offset: '30px',
- transition: transitions.SCALE,
-}
-
if (isBrowser && process.env.NODE_ENV !== 'production') {
localStorage.debug = 'swetrix:*'
}
@@ -270,9 +260,7 @@ export default function App() {
})}
>
<Provider store={store}>
- <AlertProvider template={AlertTemplate} {...options}>
- <AppWrapper ssrTheme={theme} ssrAuthenticated={isAuthed} />
- </AlertProvider>
+ <AppWrapper ssrTheme={theme} ssrAuthenticated={isAuthed} />
</Provider>
<ScrollRestoration />
<Scripts />
diff --git a/app/ui/Alert.tsx b/app/ui/Alert.tsx
deleted file mode 100644
index cdebea1dc..000000000
--- a/app/ui/Alert.tsx
+++ /dev/null
@@ -1,58 +0,0 @@
-// Custom Alert template for react-alert
-import React, { memo } from 'react'
-import { useTranslation } from 'react-i18next'
-import { CheckCircleIcon, InformationCircleIcon, XCircleIcon, XMarkIcon } from '@heroicons/react/24/solid'
-
-interface IAlert {
- /* (string): The message to be displayed in the alert. */
- message: string
- // (object): An object containing the options for the alert, including the type property, which can have the values 'info', 'success', or 'error'.
- options: {
- type: 'info' | 'success' | 'error'
- }
- // (function): A callback function to be called when the alert is closed.
- close: () => void
-}
-
-// AlertTemplate component
-const AlertTemplate = ({ message, options, close }: IAlert): JSX.Element => {
- const { t } = useTranslation('common')
- const { type } = options || {}
- const isInfo = type === 'info'
- const isSuccess = type === 'success'
- const isError = type === 'error'
-
- return (
- <div className='pointer-events-auto z-50 mb-5 mr-2 w-72 overflow-hidden rounded-lg bg-white shadow-lg ring-1 ring-black ring-opacity-5 dark:bg-slate-900 dark:ring-slate-800 min-[425px]:mr-5 min-[425px]:w-96'>
- <div className='p-4'>
- <div className='flex items-start'>
- <div className='flex-shrink-0'>
- {isInfo && <InformationCircleIcon className='h-6 w-6 text-blue-400' aria-hidden='true' />}
- {isSuccess && <CheckCircleIcon className='h-6 w-6 text-green-400' aria-hidden='true' />}
- {isError && <XCircleIcon className='h-6 w-6 text-red-400' aria-hidden='true' />}
- </div>
- <div className='ml-3 w-0 flex-1 pt-0.5'>
- <p className='text-sm font-medium text-gray-900 dark:text-gray-50'>
- {isInfo && t('common.info')}
- {isSuccess && t('common.success')}
- {isError && t('common.error')}
- </p>
- <p className='mt-1 text-sm text-gray-500 dark:text-gray-300'>{message}</p>
- </div>
- <div className='ml-4 flex flex-shrink-0'>
- <button
- type='button'
- className='inline-flex rounded-md bg-white text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 dark:bg-slate-900 dark:text-gray-200 dark:hover:text-gray-400'
- onClick={close}
- >
- <span className='sr-only'>{t('common.close')}</span>
- <XMarkIcon className='h-5 w-5' aria-hidden='true' />
- </button>
- </div>
- </div>
- </div>
- </div>
- )
-}
-
-export default memo(AlertTemplate)
diff --git a/package.json b/package.json
index a1bb53240..cc1161a32 100644
--- a/package.json
+++ b/package.json
@@ -18,7 +18,6 @@
"knip": "knip"
},
"dependencies": {
- "@blaumaus/react-alert": "^7.0.7",
"@headlessui/react": "^2.1.3",
"@heroicons/react": "^2.1.5",
"@nivo/sankey": "^0.87.0",
@@ -63,6 +62,7 @@
"remix-i18next": "^6.3.0",
"remix-sitemap": "^3.2.0",
"remix-utils": "^7.6.0",
+ "sonner": "^1.5.0",
"spacetime": "^7.6.1",
"swetrix": "^3.3.0",
"timezone-soft": "^1.5.2"