Web: People: added deleting cache and refactoring

This commit is contained in:
TatianaLopaeva 2020-10-13 09:45:23 +03:00
parent 358d53e2be
commit f6a5c8a30b
2 changed files with 17 additions and 17 deletions

View File

@ -14,7 +14,7 @@ import { connect } from "react-redux";
import { updateProfileCulture } from "../../../../../../store/profile/actions";
const { resendUserInvites } = api.people;
const { getCurrentCustomSchema, getModules } = store.auth.actions;
const InfoContainer = styled.div`
margin-bottom: 24px;
@ -142,22 +142,12 @@ class ProfileInfo extends React.PureComponent {
console.log("onLanguageSelect", language);
const {
profile,
updateProfileCulture,
nameSchemaId,
getModules,
getCurrentCustomSchema,
updateProfileCulture
} = this.props;
if (profile.cultureName === language.key) return;
updateProfileCulture(profile.id, language.key)
.then(() => {
if (!nameSchemaId) return getModules();
return (
axios.all([getModules(), getCurrentCustomSchema(nameSchemaId)]),
console.log("Update getModules", getModules())
);
})
.catch((err) => console.log(err));
};
@ -339,7 +329,7 @@ class ProfileInfo extends React.PureComponent {
}
function mapStateToProps(state) {
const { customNames, nameSchemaId } = state.auth.settings;
const { customNames } = state.auth.settings;
const {
groupCaption,
regDateCaption,
@ -354,13 +344,10 @@ function mapStateToProps(state) {
userPostCaption,
userCaption,
guestCaption,
nameSchemaId,
};
}
const mapDispatchToProps = (dispatch) => {
return {
getModules: () => getModules(dispatch),
getCurrentCustomSchema: (id) => getCurrentCustomSchema(dispatch, id),
updateProfileCulture: (id, culture) =>
dispatch(updateProfileCulture(id, culture)),
};

View File

@ -81,10 +81,23 @@ export function updateProfile(profile) {
};
}
export function updateProfileCulture(id, culture) {
return (dispatch) => {
return (dispatch, getState) => {
return api.people.updateUserCulture(id, culture).then((user) => {
dispatch(setCurrentUser(user));
return dispatch(setProfile(user));
})
.then(() => caches.delete("api-cache"))
.then(() => {
const { getCurrentCustomSchema, getModules } = store.auth.actions;
const state = getState();
const { nameSchemaId } = state.auth.settings;
if (!nameSchemaId) return getModules();
const requests = [(getModules(dispatch)), (getCurrentCustomSchema(dispatch, nameSchemaId))];
return Promise.all(requests);
});
};
}