Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function storeUsers({ data }) {
const { users, pagination: { total } } = data
const { entities, result } = normalize(users, [userSchema])
return batch('STORE_USERS',
merge(entities),
setCurrentPage(DOMAIN, result),
setTotal(DOMAIN, total)
)
}
return (dispatch,getState) => {
const currentUser = Object.assign({},getState().entities.users[getState().userReducer.authUserID],{favorites:[]});
const normalized = normalize(currentUser,Schemas.USER);
dispatch({type:LOGOUT_USER,entities:normalized.entities});
const normalizedAppointments = normalize({},Schemas.APPOINTMENT_ARRAY);
dispatch({type:LOGOUT_USER,entities:normalizedAppointments.entities});
}
}
.then(res => {
const medias = res.data;
const normalizedMedia = normalize(medias, arrayOfMedia);
dispatch({
type: t.FETCH_MEDIAS_SUCCESS,
payload: normalizedMedia,
});
})
.catch(err => {
function loginSuccess(payload) {
const normalized = normalize({users:payload.data},[userSchema]);
return {
type: LOGIN_SUCCESS,
userID:payload.data.id,
entities:normalized.entities
};
}
response => {
dispatch({
type: 'FETCH_ARTISTS_SUCCESS',
filter,
response: normalize(response, schema.artistList),
});
},
error => {
try {
if (isOpenDropdown) {
dispatch(ActionCreators.startToGetCollectionsInPaperShowDropdown());
} else {
dispatch(ActionCreators.startToGetCollectionsInPaperShow());
}
const res = await axios.get(`/members/me/collections`, {
params: {
paper_id: String(paperId),
},
cancelToken,
});
const data = res.data.data;
const collections = res.data.data.content.map(getSafeCollection);
const normalizedCollections = normalize(collections, [collectionSchema]);
const myCollections = { ...data, ...normalizedCollections };
dispatch(ActionCreators.addEntity(myCollections));
dispatch(ActionCreators.succeededToGetCollectionsInPaperShow(myCollections));
} catch (err) {
if (!Axios.isCancel(err)) {
dispatch(ActionCreators.failedToGetCollectionsInPaperShow());
const error = PlutoAxios.getGlobalError(err);
if (error) {
alertToast({
type: 'error',
message: error.message,
});
}
}
}
return async (dispatch, _getState, { axios }) => {
try {
dispatch(ActionCreators.startToGetPaper());
const res = await axios.get(`/papers/${params.paperId}`, {
cancelToken: params.cancelToken,
});
const paper: Paper = getIdSafePaper(res.data);
const paperResponse = normalize(paper, paperSchema);
dispatch(ActionCreators.addEntity(paperResponse));
dispatch(ActionCreators.getPaper({ paperId: paperResponse.result }));
} catch (err) {
if (!Axios.isCancel(err)) {
const error = PlutoAxios.getGlobalError(err);
dispatch(ActionCreators.failedToGetPaper({ statusCode: (error as CommonError).status }));
throw err;
}
}
};
}
response.json().then(json => {
if (!response.ok) return Promise.reject({ ...json, status: response.status })
if (responseSchema) return normalize(json, responseSchema)
if (schema) return normalize(json, schema)
return json
})
)
receivedAt = action.receivedAt;
playlist = clone(action.playlist);
playlists = clone(state.playlists);
let trackToAdd = clone(action.track);
playlist.isOpen = false;
if (playlists.entities && playlists.entities.playlists[playlist.id]) {
playlist = playlists.entities.playlists[playlist.id];
playlist.tracks.list.push(trackToAdd.id);
playlists.entities.tracks[trackToAdd.id] = trackToAdd;
} else {
playlist.tracks.list = playlist.tracks.list.filter(
track => track.id === trackToAdd.id
);
normalizedPlaylist = normalize(playlist, playlistSchema);
playlists = mergeDeepLeft(state.playlists, normalizedPlaylist);
}
return Object.assign({}, state, {
lastUpdated: receivedAt,
playlists
});
case REMOVE_PLAYLIST_FROM_FINAL:
receivedAt = action.receivedAt;
let statePlaylists = clone(state.playlists);
playlists = statePlaylists.entities.playlists;
delete playlists[action.playlist.id];
return Object.assign({}, state, {
playlists: statePlaylists,
.then(data => {
const typeMap = flow(
filter(isTrack),
map(toIdAndType)
)(data.collection);
dispatch(mergeTrackTypesTrack(filter((value) => value.type === trackTypes.TRACK, typeMap)));
dispatch(mergeTrackTypesRepost(filter((value) => value.type === trackTypes.TRACK_REPOST, typeMap)));
const activitiesMap = flow(
filter(isTrack),
map('origin')
)(data.collection);
const normalized = normalize(activitiesMap, arrayOf(trackSchema));
dispatch(mergeEntities(normalized.entities));
dispatch(mergeActivities(normalized.result));
dispatch(setPaginateLink(data.next_href, paginateLinkTypes.ACTIVITIES));
dispatch(setRequestInProcess(false, requestType));
});
};