Skip to content

Commit

Permalink
feat: fixed reloading issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sundasnoreen12 committed Nov 25, 2024
1 parent c025310 commit e07050c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/profile/ProfilePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -330,6 +338,7 @@ ProfilePage.propTypes = {
// Account data
requiresParentalConsent: PropTypes.bool,
dateJoined: PropTypes.string,
username: PropTypes.string,

// Bio form data
bio: PropTypes.string,
Expand Down Expand Up @@ -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({
Expand All @@ -407,6 +417,7 @@ ProfilePage.propTypes = {

ProfilePage.defaultProps = {
saveState: null,
username: '',
savePhotoState: null,
photoUploadError: {},
profileImage: {},
Expand Down
2 changes: 2 additions & 0 deletions src/profile/data/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
};

Expand Down
6 changes: 5 additions & 1 deletion src/profile/data/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 3 additions & 2 deletions src/routes/AppRoutes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Routes>
<Route path="/u/:username" element={<AuthenticatedPageRoute><SelectedProfilePage /></AuthenticatedPageRoute>} />
<Route path="/u/:username" element={<AuthenticatedPageRoute><SelectedProfilePage navigate={navigate} /></AuthenticatedPageRoute>} />
<Route path="/notfound" element={<PageWrap><SelectedNotFoundPage /></PageWrap>} />
<Route path="*" element={<PageWrap><SelectedNotFoundPage /></PageWrap>} />
</Routes>
Expand Down

0 comments on commit e07050c

Please sign in to comment.