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 b92efcd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 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;

Check warning on line 74 in src/profile/ProfilePage.jsx

View check run for this annotation

Codecov / codecov/patch

src/profile/ProfilePage.jsx#L73-L74

Added lines #L73 - L74 were not covered by tests

if (!username && saveState === 'error') {
navigate('/notfound');

Check warning on line 77 in src/profile/ProfilePage.jsx

View check run for this annotation

Codecov / codecov/patch

src/profile/ProfilePage.jsx#L77

Added line #L77 was not covered by tests
}
}

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
7 changes: 5 additions & 2 deletions src/profile/data/sagas.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { history } from '@edx/frontend-platform';
import { getAuthenticatedUser } from '@edx/frontend-platform/auth';
import pick from 'lodash.pick';
import {
Expand Down Expand Up @@ -95,7 +94,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));

Check warning on line 100 in src/profile/data/sagas.js

View check run for this annotation

Codecov / codecov/patch

src/profile/data/sagas.js#L98-L100

Added lines #L98 - L100 were not covered by tests
}
} 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 b92efcd

Please sign in to comment.