Invite and Session API/Services; Home view; Sidebar Items; Modals

This commit is contained in:
Aslan 2026-01-10 19:24:10 -05:00
parent 280158470a
commit e36587b99d
80 changed files with 1343 additions and 71 deletions

View file

@ -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,
};