Invite and Session API/Services; Home view; Sidebar Items; Modals
This commit is contained in:
parent
280158470a
commit
e36587b99d
80 changed files with 1343 additions and 71 deletions
|
|
@ -30,10 +30,15 @@ const createChannel = async (name: string, communityId: string) => {
|
|||
});
|
||||
};
|
||||
|
||||
const updateChannel = async (id: string, name?: string) => {
|
||||
const updateChannel = async (
|
||||
id: string,
|
||||
name?: string,
|
||||
description?: string,
|
||||
) => {
|
||||
const data = await updateChannelApi({
|
||||
id: id,
|
||||
name: name,
|
||||
description: description,
|
||||
});
|
||||
|
||||
dispatch({
|
||||
|
|
|
|||
|
|
@ -1,14 +1,19 @@
|
|||
import {
|
||||
fetchCommunityApi,
|
||||
createCommunityApi,
|
||||
updateCommunityApi,
|
||||
removeCommunityApi,
|
||||
fetchCommunityChannelsApi,
|
||||
fetchCommunityRolesApi,
|
||||
fetchCommunityMembersApi,
|
||||
fetchCommunityInvitesApi,
|
||||
} from "../../api/community";
|
||||
import { CommunityActionTypes } from "../../store/community";
|
||||
import { ChannelActionTypes } from "../../store/channel";
|
||||
import { RoleActionTypes } from "../../store/role";
|
||||
import { UserActionTypes } from "../../store/user";
|
||||
import { dispatch } from "../../store/state";
|
||||
import { dispatch, state } from "../../store/state";
|
||||
import { InviteActionTypes } from "../../store/invite";
|
||||
|
||||
const fetchCommunity = async (id: string) => {
|
||||
const data = await fetchCommunityApi({
|
||||
|
|
@ -21,6 +26,66 @@ const fetchCommunity = async (id: string) => {
|
|||
});
|
||||
};
|
||||
|
||||
const createCommunity = async (name: string) => {
|
||||
const data = await createCommunityApi({
|
||||
name: name,
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: CommunityActionTypes.CREATE_COMMUNITY_FINISH,
|
||||
payload: data,
|
||||
});
|
||||
|
||||
if (state.user.loggedUserId) {
|
||||
dispatch({
|
||||
type: UserActionTypes.FETCH_USER_COMMUNITIES_START,
|
||||
payload: state.user.loggedUserId,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const updateCommunity = async (
|
||||
id: string,
|
||||
name?: string,
|
||||
description?: string,
|
||||
) => {
|
||||
const data = await updateCommunityApi({
|
||||
id: id,
|
||||
name: name,
|
||||
description: description,
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: CommunityActionTypes.UPDATE_COMMUNITY_FINISH,
|
||||
payload: data,
|
||||
});
|
||||
|
||||
if (state.user.loggedUserId) {
|
||||
dispatch({
|
||||
type: UserActionTypes.FETCH_USER_COMMUNITIES_START,
|
||||
payload: state.user.loggedUserId,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const removeCommunity = async (id: string) => {
|
||||
const data = await removeCommunityApi({
|
||||
id: id,
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: CommunityActionTypes.REMOVE_COMMUNITY_FINISH,
|
||||
payload: data,
|
||||
});
|
||||
|
||||
if (state.user.loggedUserId) {
|
||||
dispatch({
|
||||
type: UserActionTypes.FETCH_USER_COMMUNITIES_START,
|
||||
payload: state.user.loggedUserId,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const fetchCommunityChannels = async (id: string) => {
|
||||
const data = await fetchCommunityChannelsApi({
|
||||
id: id,
|
||||
|
|
@ -75,9 +140,31 @@ const fetchCommunityMembers = async (id: string) => {
|
|||
});
|
||||
};
|
||||
|
||||
const fetchCommunityInvites = async (id: string) => {
|
||||
const data = await fetchCommunityInvitesApi({
|
||||
id: id,
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: CommunityActionTypes.FETCH_COMMUNITY_INVITES_FINISH,
|
||||
payload: data,
|
||||
});
|
||||
|
||||
data.invites.forEach((invite) => {
|
||||
dispatch({
|
||||
type: InviteActionTypes.SET_INVITE,
|
||||
payload: invite,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export {
|
||||
fetchCommunity,
|
||||
createCommunity,
|
||||
updateCommunity,
|
||||
removeCommunity,
|
||||
fetchCommunityChannels,
|
||||
fetchCommunityRoles,
|
||||
fetchCommunityMembers,
|
||||
fetchCommunityInvites,
|
||||
};
|
||||
|
|
|
|||
1
src/services/invite/index.ts
Normal file
1
src/services/invite/index.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * from "./invite";
|
||||
50
src/services/invite/invite.ts
Normal file
50
src/services/invite/invite.ts
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import {
|
||||
fetchInviteApi,
|
||||
removeInviteApi,
|
||||
acceptInviteApi,
|
||||
} from "../../api/invite";
|
||||
import { InviteActionTypes } from "../../store/invite";
|
||||
import { dispatch, state } from "../../store/state";
|
||||
import { UserActionTypes } from "../../store/user";
|
||||
|
||||
const fetchInvite = async (id: string) => {
|
||||
const data = await fetchInviteApi({
|
||||
id: id,
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: InviteActionTypes.FETCH_INVITE_FINISH,
|
||||
payload: data,
|
||||
});
|
||||
};
|
||||
|
||||
const removeInvite = async (id: string) => {
|
||||
const data = await removeInviteApi({
|
||||
id: id,
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: InviteActionTypes.REMOVE_INVITE_FINISH,
|
||||
payload: data,
|
||||
});
|
||||
};
|
||||
|
||||
const acceptInvite = async (id: string) => {
|
||||
const data = await acceptInviteApi({
|
||||
id: id,
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: InviteActionTypes.ACCEPT_INVITE_FINISH,
|
||||
payload: data,
|
||||
});
|
||||
|
||||
if (state.user.loggedUserId) {
|
||||
dispatch({
|
||||
type: UserActionTypes.FETCH_USER_COMMUNITIES_START,
|
||||
payload: state.user.loggedUserId,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export { fetchInvite, removeInvite, acceptInvite };
|
||||
1
src/services/session/index.ts
Normal file
1
src/services/session/index.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * from "./session";
|
||||
27
src/services/session/session.ts
Normal file
27
src/services/session/session.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { fetchSessionApi, removeSessionApi } from "../../api/session";
|
||||
import { SessionActionTypes } from "../../store/session";
|
||||
import { dispatch } from "../../store/state";
|
||||
|
||||
const fetchSession = async (id: string) => {
|
||||
const data = await fetchSessionApi({
|
||||
id: id,
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: SessionActionTypes.FETCH_SESSION_FINISH,
|
||||
payload: data,
|
||||
});
|
||||
};
|
||||
|
||||
const removeSession = async (id: string) => {
|
||||
const data = await removeSessionApi({
|
||||
id: id,
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: SessionActionTypes.REMOVE_SESSION_FINISH,
|
||||
payload: data,
|
||||
});
|
||||
};
|
||||
|
||||
export { fetchSession, removeSession };
|
||||
|
|
@ -1,11 +1,13 @@
|
|||
import {
|
||||
fetchLoggedUserApi,
|
||||
fetchUserApi,
|
||||
fetchUserSessionsApi,
|
||||
fetchUserCommunitiesApi,
|
||||
} from "../../api/user";
|
||||
import { UserActionTypes } from "../../store/user";
|
||||
import { CommunityActionTypes } from "../../store/community";
|
||||
import { dispatch } from "../../store/state";
|
||||
import { SessionActionTypes } from "../../store/session";
|
||||
|
||||
const fetchLoggedUser = async () => {
|
||||
const data = await fetchLoggedUserApi();
|
||||
|
|
@ -27,6 +29,24 @@ const fetchUser = async (id: string) => {
|
|||
});
|
||||
};
|
||||
|
||||
const fetchUserSessions = async (id: string) => {
|
||||
const data = await fetchUserSessionsApi({
|
||||
id: id,
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: UserActionTypes.FETCH_USER_SESSIONS_FINISH,
|
||||
payload: data,
|
||||
});
|
||||
|
||||
data.sessions.forEach((session) => {
|
||||
dispatch({
|
||||
type: SessionActionTypes.SET_SESSION,
|
||||
payload: session,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const fetchUserCommunities = async (id: string) => {
|
||||
const data = await fetchUserCommunitiesApi({
|
||||
id: id,
|
||||
|
|
@ -45,4 +65,4 @@ const fetchUserCommunities = async (id: string) => {
|
|||
});
|
||||
};
|
||||
|
||||
export { fetchLoggedUser, fetchUser, fetchUserCommunities };
|
||||
export { fetchLoggedUser, fetchUser, fetchUserSessions, fetchUserCommunities };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue