Skip to content

Commit 4d39ece

Browse files
committed
Stop redirecting to / on MyAccount save, show Toast instead.
1 parent ec44842 commit 4d39ece

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/app/components/pages/MyAccount.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
import {UserAuthenticationSettingsDTO} from "../../../IsaacApiTypes";
2020
import {AppState, ErrorState} from "../../state/reducers";
2121
import {updateCurrentUser, resetPassword} from "../../state/actions";
22-
import {LoggedInUser, UserPreferencesDTO, LoggedInValidationUser} from "../../../IsaacAppTypes";
22+
import {LoggedInUser, UserPreferencesDTO, LoggedInValidationUser, Toast} from "../../../IsaacAppTypes";
2323
import {UserDetails} from "../elements/UserDetails";
2424
import {UserPassword} from "../elements/UserPassword";
2525
import {UserEmailPreference} from "../elements/UserEmailPreferences";
@@ -28,6 +28,8 @@ import {Link} from "react-router-dom";
2828
import {BreadcrumbTrail} from "../elements/BreadcrumbTrail";
2929
import {EXAM_BOARD} from "../../services/constants";
3030
import {history} from "../../services/history"
31+
import {showToast} from "../../state/actions";
32+
import { Toasts } from '../navigation/Toasts';
3133

3234
const stateToProps = (state: AppState) => ({
3335
errorMessage: state ? state.error : null,
@@ -39,6 +41,7 @@ const stateToProps = (state: AppState) => ({
3941
const dispatchToProps = {
4042
updateCurrentUser,
4143
resetPassword,
44+
showToast,
4245
};
4346

4447
interface AccountPageProps {
@@ -51,9 +54,10 @@ interface AccountPageProps {
5154
currentUser: LoggedInUser
5255
) => void;
5356
firstLogin: boolean;
57+
showToast: (toast: Toast) => void;
5458
}
5559

56-
const AccountPageComponent = ({user, updateCurrentUser, errorMessage, userAuthSettings, userPreferences, firstLogin}: AccountPageProps) => {
60+
const AccountPageComponent = ({user, updateCurrentUser, errorMessage, userAuthSettings, userPreferences, firstLogin, showToast}: AccountPageProps) => {
5761

5862
// Catch the (unlikely?) case where a user does not have email preferences in the database.
5963
if (userPreferences && !userPreferences.EMAIL_PREFERENCE) {
@@ -137,8 +141,15 @@ const AccountPageComponent = ({user, updateCurrentUser, errorMessage, userAuthSe
137141
registeredUser: myUser,
138142
userPreferences: myUserPreferences,
139143
passwordCurrent: currentPassword
140-
}, user)
144+
}, user);
141145
}
146+
showToast({
147+
title: "Preferences updated",
148+
body: "Your user preferences were saved correctly.",
149+
color: "success",
150+
timeout: 5000,
151+
closable: false,
152+
});
142153
}}>
143154
<TabContent activeTab={activeTab}>
144155
<TabPane tabId={0}>

src/app/state/actions.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ export const updateCurrentUser = (
9898
dispatch({type: ACTION_TYPE.USER_DETAILS_UPDATE_RESPONSE_SUCCESS, user: currentUser.data});
9999
if (initialLogin) {
100100
history.push('/account', {firstLogin: initialLogin});
101-
} else {
102-
history.push('/');
103101
}
104102
} catch (e) {
105103
dispatch({type: ACTION_TYPE.USER_DETAILS_UPDATE_RESPONSE_FAILURE, errorMessage: e.response.data.errorMessage});

0 commit comments

Comments
 (0)