in src/amo/pages/UserProfileEdit/index.js [152:240]
componentDidUpdate(prevProps: InternalProps, prevState: State) {
const {
isUpdating: wasUpdating,
user: oldUser,
userId: oldUserId,
} = prevProps;
const {
clientApp,
currentUser,
dispatch,
errorHandler,
i18n,
isUpdating,
lang,
location,
user: newUser,
userId: newUserId,
} = this.props;
if (!currentUser) {
return;
}
if (oldUserId !== newUserId) {
if (!newUser && newUserId) {
dispatch(
fetchUserAccount({
errorHandlerId: errorHandler.id,
userId: newUserId,
}),
);
}
if ((!newUser && newUserId) || (newUser && !newUser.notifications)) {
dispatch(
fetchUserNotifications({
errorHandlerId: errorHandler.id,
userId: newUser ? newUser.id : newUserId,
}),
);
}
// eslint-disable-next-line react/no-did-update-set-state
this.setState({
...this.getFormValues(newUser),
pictureData: null,
successMessage: null,
});
} else if (
oldUser &&
oldUser.picture_url &&
newUser &&
!newUser.picture_url
) {
// eslint-disable-next-line react/no-did-update-set-state
this.setState({
picture: null,
pictureData: null,
successMessage: i18n.gettext('Picture successfully deleted'),
});
}
if (wasUpdating && !isUpdating && !errorHandler.hasError()) {
let toPath = location.query.to;
if (toPath && typeof toPath === 'string') {
toPath = url.parse(toPath).pathname;
if (toPath && !toPath.startsWith('//')) {
try {
this.props._window.location.assign(toPath);
return;
} catch (error) {
log.warn(`Error redirecting to location: ${toPath}: ${error}`);
}
}
}
this.props._window.location.assign(
`/${lang}/${clientApp}/user/${newUserId}/`,
);
}
if (
(!prevProps.errorHandler.hasError() &&
this.props.errorHandler.hasError()) ||
(!prevState.successMessage && this.state.successMessage)
) {
this.props._window.scroll(0, 0);
}
}