fix: adding team members from organization tab that alredy exist (#11689)
* fix: adding team members from organization tab that alredy exist * changed organizations.listOtherTeamMembers from useQuery to useInfiniteQuery * undo yarn.lock * fix: invalidate the organizations.getMembers query on removeMember and inviteMember Mutation --------- Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: Hariom <[email protected]>
This commit is contained in:
6 files changed
+69
-39
No files matched your search
@@ -50,6 +50,24 @@ export const getMembersHandler = async ({ input, ctx }: CreateOptions) => {
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (teamIdToExclude && teamQuery?.members) {
|
||||
const excludedteamUsers = await prisma.team.findUnique({
|
||||
where: {
|
||||
id: teamIdToExclude,
|
||||
},
|
||||
select: {
|
||||
members: {
|
||||
select: {
|
||||
userId: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const excludedUserIds = excludedteamUsers?.members.map((item) => item.userId) ?? [];
|
||||
teamQuery.members = teamQuery?.members.filter((member) => !excludedUserIds.includes(member.userId));
|
||||
}
|
||||
|
||||
return teamQuery?.members || [];
|
||||
};
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@ import type { TrpcSessionUser } from "../../../trpc";
|
||||
export const ZListOtherTeamMembersSchema = z.object({
|
||||
teamId: z.number(),
|
||||
query: z.string().optional(),
|
||||
limit: z.number().optional(),
|
||||
limit: z.number(),
|
||||
offset: z.number().optional(),
|
||||
cursor: z.number().nullish(), // <-- "cursor" needs to exist when using useInfiniteQuery, but can be any type
|
||||
});
|
||||
|
||||
export type TListOtherTeamMembersSchema = z.infer<typeof ZListOtherTeamMembersSchema>;
|
||||
@@ -25,11 +26,12 @@ export const listOtherTeamMembers = async ({ input }: ListOptions) => {
|
||||
const whereConditional: Prisma.MembershipWhereInput = {
|
||||
teamId: input.teamId,
|
||||
};
|
||||
const { limit = 20 } = input;
|
||||
let { offset = 0 } = input;
|
||||
// const { limit = 20 } = input;
|
||||
// let { offset = 0 } = input;
|
||||
|
||||
const { cursor, limit } = input;
|
||||
|
||||
if (input.query) {
|
||||
offset = 0;
|
||||
whereConditional.user = {
|
||||
OR: [
|
||||
{
|
||||
@@ -73,11 +75,19 @@ export const listOtherTeamMembers = async ({ input }: ListOptions) => {
|
||||
},
|
||||
distinct: ["userId"],
|
||||
orderBy: { role: "desc" },
|
||||
take: limit,
|
||||
skip: offset,
|
||||
cursor: cursor ? { id: cursor } : undefined,
|
||||
take: limit + 1, // We take +1 as itll be used for the next cursor
|
||||
});
|
||||
let nextCursor: typeof cursor | undefined = undefined;
|
||||
if (members && members.length > limit) {
|
||||
const nextItem = members.pop();
|
||||
nextCursor = nextItem?.id || null;
|
||||
}
|
||||
|
||||
return members;
|
||||
return {
|
||||
rows: members || [],
|
||||
nextCursor,
|
||||
};
|
||||
};
|
||||
|
||||
export default listOtherTeamMembers;
|
||||
Reference in new issue
Block a user