diff --git a/apps/client/src/features/group/queries/group-query.ts b/apps/client/src/features/group/queries/group-query.ts index 38c2db33..370b548a 100644 --- a/apps/client/src/features/group/queries/group-query.ts +++ b/apps/client/src/features/group/queries/group-query.ts @@ -16,11 +16,14 @@ import { updateGroup, } from "@/features/group/services/group-service"; import { notifications } from "@mantine/notifications"; +import { QueryParams } from "@/lib/types.ts"; -export function useGetGroupsQuery(): UseQueryResult { +export function useGetGroupsQuery( + params?: QueryParams, +): UseQueryResult { return useQuery({ - queryKey: ["groups"], - queryFn: () => getGroups(), + queryKey: ["groups", params], + queryFn: () => getGroups(params), }); } @@ -77,9 +80,12 @@ export function useDeleteGroupMutation() { mutationFn: (groupId: string) => deleteGroup({ groupId }), onSuccess: (data, variables) => { 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) => { const errorMessage = error["response"]?.data?.message; diff --git a/apps/client/src/features/group/services/group-service.ts b/apps/client/src/features/group/services/group-service.ts index 1a04c93b..a5e97605 100644 --- a/apps/client/src/features/group/services/group-service.ts +++ b/apps/client/src/features/group/services/group-service.ts @@ -1,9 +1,10 @@ import api from "@/lib/api-client"; import { IGroup } from "@/features/group/types/group.types"; +import { QueryParams } from "@/lib/types.ts"; -export async function getGroups(): Promise { +export async function getGroups(params?: QueryParams): Promise { // TODO: returns paginated. Fix type - const req = await api.post("/groups"); + const req = await api.post("/groups", params); return req.data; } @@ -12,11 +13,6 @@ export async function getGroupById(groupId: string): Promise { 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): Promise { const req = await api.post("/groups/create", data); return req.data; @@ -31,16 +27,21 @@ export async function deleteGroup(data: { groupId: string }): Promise { 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: { groupId: string; userIds: string[]; }): Promise { - await api.post("/groups/members/add", data); + await api.post("/groups/members/add", data); } export async function removeGroupMember(data: { groupId: string; userId: string; }): Promise { - await api.post("/groups/members/remove", data); + await api.post("/groups/members/remove", data); }