diff --git a/src/profile/ProfilePage.jsx b/src/profile/ProfilePage.jsx index f0a140114..d8b2f109f 100644 --- a/src/profile/ProfilePage.jsx +++ b/src/profile/ProfilePage.jsx @@ -70,6 +70,14 @@ class ProfilePage extends React.Component { }); } + componentDidUpdate() { + const { username, navigate, saveState } = this.props; + + if (!username && saveState === 'error') { + navigate('/notfound'); + } + } + handleSaveProfilePhoto(formData) { this.props.saveProfilePhoto(this.context.authenticatedUser.username, formData); } @@ -330,6 +338,7 @@ ProfilePage.propTypes = { // Account data requiresParentalConsent: PropTypes.bool, dateJoined: PropTypes.string, + username: PropTypes.string, // Bio form data bio: PropTypes.string, @@ -395,6 +404,7 @@ ProfilePage.propTypes = { openForm: PropTypes.func.isRequired, closeForm: PropTypes.func.isRequired, updateDraft: PropTypes.func.isRequired, + navigate: PropTypes.func.isRequired, // Router params: PropTypes.shape({ @@ -407,6 +417,7 @@ ProfilePage.propTypes = { ProfilePage.defaultProps = { saveState: null, + username: '', savePhotoState: null, photoUploadError: {}, profileImage: {}, diff --git a/src/profile/data/reducers.js b/src/profile/data/reducers.js index 88a1bc9c0..4f10bc083 100644 --- a/src/profile/data/reducers.js +++ b/src/profile/data/reducers.js @@ -64,12 +64,14 @@ const profilePage = (state = initialState, action = {}) => { return { ...state, saveState: 'error', + isLoadingProfile: false, errors: { ...state.errors, ...action.payload.errors }, }; case SAVE_PROFILE.RESET: return { ...state, saveState: null, + isLoadingProfile: false, errors: {}, }; diff --git a/src/profile/data/sagas.js b/src/profile/data/sagas.js index cfece88bb..414f0824b 100644 --- a/src/profile/data/sagas.js +++ b/src/profile/data/sagas.js @@ -95,7 +95,11 @@ export function* handleFetchProfile(action) { yield put(fetchProfileReset()); } catch (e) { if (e.response.status === 404) { - history.push('/notfound'); + if (e.processedData && e.processedData.fieldErrors) { + yield put(saveProfileFailure(e.processedData.fieldErrors)); + } else { + yield put(saveProfileFailure(e.customAttributes)); + } } else { throw e; } diff --git a/src/routes/AppRoutes.jsx b/src/routes/AppRoutes.jsx index 84c84402e..8a7b085dd 100644 --- a/src/routes/AppRoutes.jsx +++ b/src/routes/AppRoutes.jsx @@ -4,17 +4,18 @@ import { AuthenticatedPageRoute, PageWrap, } from '@edx/frontend-platform/react'; -import { Routes, Route } from 'react-router-dom'; +import { Routes, Route, useNavigate } from 'react-router-dom'; import { ProfilePage, NotFoundPage } from '../profile'; import { ProfilePage as NewProfilePage, NotFoundPage as NewNotFoundPage } from '../profile-v2'; const AppRoutes = ({ isNewProfileEnabled }) => { const SelectedProfilePage = isNewProfileEnabled ? NewProfilePage : ProfilePage; const SelectedNotFoundPage = isNewProfileEnabled ? NewNotFoundPage : NotFoundPage; + const navigate = useNavigate(); return ( - } /> + } /> } /> } />