Skip to content

Commit

Permalink
DASH-309 Fix notification emails settings state
Browse files Browse the repository at this point in the history
  • Loading branch information
trukhilio committed Aug 28, 2023
1 parent ff9807e commit 5a9180b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 3 additions & 1 deletion client/src/components/PrivateRoute/PrivateRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { faSpinner } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

import {
isAuthenticated as isAuthenticatedSelector,
loading as loadingSelector,
noProfileLoaded as noProfileLoadedSelector,
} from '../../redux/profile/selectors';
Expand All @@ -29,12 +30,13 @@ export const PrivateRoute: React.FC<RouteProps & OwnProps> = ({
}) => {
const loading = useSelector(loadingSelector);
const noProfileLoaded = useSelector(noProfileLoadedSelector);
const isAuthenticated = useSelector(isAuthenticatedSelector);

return (
<Route
{...rest}
render={(props: RouteComponentProps) => {
if (loading) {
if (loading && !isAuthenticated) {
return (
<FontAwesomeIcon
icon={faSpinner}
Expand Down
6 changes: 3 additions & 3 deletions client/src/pages/SettingsPage/SettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { changeRecoveryQuestionsOpen } from '../../redux/edge/actions';

import { showRecovery as showRecoverySelector } from '../../redux/modal/selectors';
import {
isAuthenticated as isAuthenticatedSelector,
loading as loadingSelector,
user as userSelector,
} from '../../redux/profile/selectors';

import useEffectOnce from '../../hooks/general';
Expand All @@ -32,9 +32,9 @@ export const PREOPENED_MODALS = {
};

const SettingsPage: React.FC = () => {
const user = useSelector(userSelector);
const loading = useSelector(loadingSelector);
const showRecovery = useSelector(showRecoverySelector);
const isAuthenticated = useSelector(isAuthenticatedSelector);

const dispatch = useDispatch();

Expand All @@ -55,7 +55,7 @@ const SettingsPage: React.FC = () => {
}
}, [dispatch, openSettingsModal, showRecovery]);

if (loading || user == null)
if (loading && !isAuthenticated)
return (
<LayoutContainer title="Settings">
<div className="d-flex justify-content-center align-items-center h-100 pt-5 pb-5">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { useCallback, useState } from 'react';

import { useSelector } from 'react-redux';
import { useDispatch, useSelector } from 'react-redux';

import { log } from '../../../../util/general';
import apis from '../../../../api';

import { loadProfile } from '../../../../redux/profile/actions';

import { user as userSelector } from '../../../../redux/profile/selectors';

import {
Expand Down Expand Up @@ -54,6 +56,8 @@ export const useContext = (): UseContextProps => {
const [loading, setLoading] = useState<boolean>(false);
const [showSuccessModal, toggleSuccessModal] = useState<boolean>(false);

const dispatch = useDispatch();

const toggleCheckClick = useCallback(
(emailNotificationType: EmailNotificationParamsNamesType) => {
setEmailNotificationParams(prevValue => {
Expand All @@ -79,6 +83,7 @@ export const useContext = (): UseContextProps => {

if (updateNotificationsRes?.success) {
toggleSuccessModal(true);
dispatch(loadProfile());
}
hasError && setHasError(false);
} catch (err) {
Expand All @@ -87,7 +92,7 @@ export const useContext = (): UseContextProps => {
} finally {
setLoading(false);
}
}, [emailNotificationParams, hasError]);
}, [dispatch, emailNotificationParams, hasError]);

const onSuccessClose = useCallback(() => toggleSuccessModal(false), []);

Expand Down

0 comments on commit 5a9180b

Please sign in to comment.