mirror of
https://github.com/docmost/docmost.git
synced 2025-11-13 09:42:37 +10:00
fix
This commit is contained in:
@ -16,11 +16,14 @@ import {
|
|||||||
updateGroup,
|
updateGroup,
|
||||||
} from "@/features/group/services/group-service";
|
} from "@/features/group/services/group-service";
|
||||||
import { notifications } from "@mantine/notifications";
|
import { notifications } from "@mantine/notifications";
|
||||||
|
import { QueryParams } from "@/lib/types.ts";
|
||||||
|
|
||||||
export function useGetGroupsQuery(): UseQueryResult<any, Error> {
|
export function useGetGroupsQuery(
|
||||||
|
params?: QueryParams,
|
||||||
|
): UseQueryResult<any, Error> {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ["groups"],
|
queryKey: ["groups", params],
|
||||||
queryFn: () => getGroups(),
|
queryFn: () => getGroups(params),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,9 +80,12 @@ export function useDeleteGroupMutation() {
|
|||||||
mutationFn: (groupId: string) => deleteGroup({ groupId }),
|
mutationFn: (groupId: string) => deleteGroup({ groupId }),
|
||||||
onSuccess: (data, variables) => {
|
onSuccess: (data, variables) => {
|
||||||
notifications.show({ message: "Group deleted successfully" });
|
notifications.show({ message: "Group deleted successfully" });
|
||||||
queryClient.refetchQueries({
|
|
||||||
queryKey: ["groups"],
|
const groups = queryClient.getQueryData(["groups"]) as any;
|
||||||
});
|
if (groups) {
|
||||||
|
groups.items?.filter((group: IGroup) => group.id !== variables);
|
||||||
|
queryClient.setQueryData(["groups"], groups);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
const errorMessage = error["response"]?.data?.message;
|
const errorMessage = error["response"]?.data?.message;
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
import api from "@/lib/api-client";
|
import api from "@/lib/api-client";
|
||||||
import { IGroup } from "@/features/group/types/group.types";
|
import { IGroup } from "@/features/group/types/group.types";
|
||||||
|
import { QueryParams } from "@/lib/types.ts";
|
||||||
|
|
||||||
export async function getGroups(): Promise<any> {
|
export async function getGroups(params?: QueryParams): Promise<any> {
|
||||||
// TODO: returns paginated. Fix type
|
// TODO: returns paginated. Fix type
|
||||||
const req = await api.post<any>("/groups");
|
const req = await api.post<any>("/groups", params);
|
||||||
return req.data;
|
return req.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -12,11 +13,6 @@ export async function getGroupById(groupId: string): Promise<IGroup> {
|
|||||||
return req.data as IGroup;
|
return req.data as IGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getGroupMembers(groupId: string) {
|
|
||||||
const req = await api.post("/groups/members", { groupId });
|
|
||||||
return req.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function createGroup(data: Partial<IGroup>): Promise<IGroup> {
|
export async function createGroup(data: Partial<IGroup>): Promise<IGroup> {
|
||||||
const req = await api.post<IGroup>("/groups/create", data);
|
const req = await api.post<IGroup>("/groups/create", data);
|
||||||
return req.data;
|
return req.data;
|
||||||
@ -31,16 +27,21 @@ export async function deleteGroup(data: { groupId: string }): Promise<void> {
|
|||||||
await api.post("/groups/delete", data);
|
await api.post("/groups/delete", data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getGroupMembers(groupId: string) {
|
||||||
|
const req = await api.post("/groups/members", { groupId });
|
||||||
|
return req.data;
|
||||||
|
}
|
||||||
|
|
||||||
export async function addGroupMember(data: {
|
export async function addGroupMember(data: {
|
||||||
groupId: string;
|
groupId: string;
|
||||||
userIds: string[];
|
userIds: string[];
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
await api.post<IGroup>("/groups/members/add", data);
|
await api.post("/groups/members/add", data);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function removeGroupMember(data: {
|
export async function removeGroupMember(data: {
|
||||||
groupId: string;
|
groupId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
await api.post<IGroup>("/groups/members/remove", data);
|
await api.post("/groups/members/remove", data);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user