fix: Fixes username invite issue (#10998)

* Fixes username invite issue

* Ensure we only suggest email invites in org members

---------

Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
pull/11039/head^2
sean-brydon 2023-09-01 13:01:45 +01:00 committed by GitHub
parent 0e181f6d9f
commit 376b38d4ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 5 deletions

View File

@ -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 } }) => (
<>
<TextField
label={t("email_or_username")}
label={props.justEmailInvites ? t("email") : t("email_or_username")}
id="inviteUser"
name="inviteUser"
placeholder="email@example.com"

View File

@ -60,6 +60,7 @@ export function InviteMemberModal(props: Props) {
});
}}
teamId={orgId}
justEmailInvites={!!orgId}
isLoading={inviteMemberMutation.isLoading}
onSubmit={(values) => {
inviteMemberMutation.mutate({

View File

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

View File

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