diff --git a/packages/features/ee/teams/components/MemberInvitationModal.tsx b/packages/features/ee/teams/components/MemberInvitationModal.tsx index f6fad884f0..b72ace316f 100644 --- a/packages/features/ee/teams/components/MemberInvitationModal.tsx +++ b/packages/features/ee/teams/components/MemberInvitationModal.tsx @@ -32,6 +32,7 @@ import { GoogleWorkspaceInviteButton } from "./GoogleWorkspaceInviteButton"; type MemberInvitationModalProps = { isOpen: boolean; + justEmailInvites?: boolean; onExit: () => void; orgMembers?: RouterOutputs["viewer"]["organizations"]["getMembers"]; onSubmit: (values: NewMemberForm, resetFields: () => void) => void; @@ -206,7 +207,7 @@ export default function MemberInvitationModal(props: MemberInvitationModalProps) render={({ field: { onChange }, fieldState: { error } }) => ( <> { inviteMemberMutation.mutate({ diff --git a/packages/trpc/server/routers/viewer/teams/inviteMember/inviteMember.handler.ts b/packages/trpc/server/routers/viewer/teams/inviteMember/inviteMember.handler.ts index 79536c7547..39b4356e36 100644 --- a/packages/trpc/server/routers/viewer/teams/inviteMember/inviteMember.handler.ts +++ b/packages/trpc/server/routers/viewer/teams/inviteMember/inviteMember.handler.ts @@ -56,7 +56,7 @@ export const inviteMemberHandler = async ({ ctx, input }: InviteMemberOptions) = }); const invitee = await getUserToInviteOrThrowIfExists({ usernameOrEmail, - orgId: input.teamId, + teamId: input.teamId, isOrg: input.isOrg, }); diff --git a/packages/trpc/server/routers/viewer/teams/inviteMember/utils.ts b/packages/trpc/server/routers/viewer/teams/inviteMember/utils.ts index 744349e7c3..e4142789fa 100644 --- a/packages/trpc/server/routers/viewer/teams/inviteMember/utils.ts +++ b/packages/trpc/server/routers/viewer/teams/inviteMember/utils.ts @@ -66,17 +66,21 @@ export async function getEmailsToInvite(usernameOrEmail: string | string[]) { export async function getUserToInviteOrThrowIfExists({ usernameOrEmail, - orgId, + teamId, isOrg, }: { usernameOrEmail: string; - orgId: number; + teamId: number; isOrg?: boolean; }) { // Check if user exists in ORG or exists all together + + const orgWhere = isOrg && { + organizationId: teamId, + }; const invitee = await prisma.user.findFirst({ where: { - OR: [{ username: usernameOrEmail, organizationId: orgId }, { email: usernameOrEmail }], + OR: [{ username: usernameOrEmail, ...orgWhere }, { email: usernameOrEmail }], }, });