48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
import {
|
|
fetchLoggedUserApi,
|
|
fetchUserApi,
|
|
fetchUserCommunitiesApi,
|
|
} from "../../api/user";
|
|
import { UserActionTypes } from "../../store/user";
|
|
import { CommunityActionTypes } from "../../store/community";
|
|
import { dispatch } from "../../store/state";
|
|
|
|
const fetchLoggedUser = async () => {
|
|
const data = await fetchLoggedUserApi();
|
|
|
|
dispatch({
|
|
type: UserActionTypes.FETCH_LOGGED_USER_ID_FINISH,
|
|
payload: data,
|
|
});
|
|
};
|
|
|
|
const fetchUser = async (id: string) => {
|
|
const data = await fetchUserApi({
|
|
id: id,
|
|
});
|
|
|
|
dispatch({
|
|
type: UserActionTypes.FETCH_USER_FINISH,
|
|
payload: data,
|
|
});
|
|
};
|
|
|
|
const fetchUserCommunities = async (id: string) => {
|
|
const data = await fetchUserCommunitiesApi({
|
|
id: id,
|
|
});
|
|
|
|
dispatch({
|
|
type: UserActionTypes.FETCH_USER_COMMUNITIES_FINISH,
|
|
payload: data,
|
|
});
|
|
|
|
data.communities.forEach((community) => {
|
|
dispatch({
|
|
type: CommunityActionTypes.SET_COMMUNITY,
|
|
payload: community,
|
|
});
|
|
});
|
|
};
|
|
|
|
export { fetchLoggedUser, fetchUser, fetchUserCommunities };
|