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 = { type MemberInvitationModalProps = {
isOpen: boolean; isOpen: boolean;
justEmailInvites?: boolean;
onExit: () => void; onExit: () => void;
orgMembers?: RouterOutputs["viewer"]["organizations"]["getMembers"]; orgMembers?: RouterOutputs["viewer"]["organizations"]["getMembers"];
onSubmit: (values: NewMemberForm, resetFields: () => void) => void; onSubmit: (values: NewMemberForm, resetFields: () => void) => void;
@ -206,7 +207,7 @@ export default function MemberInvitationModal(props: MemberInvitationModalProps)
render={({ field: { onChange }, fieldState: { error } }) => ( render={({ field: { onChange }, fieldState: { error } }) => (
<> <>
<TextField <TextField
label={t("email_or_username")} label={props.justEmailInvites ? t("email") : t("email_or_username")}
id="inviteUser" id="inviteUser"
name="inviteUser" name="inviteUser"
placeholder="email@example.com" placeholder="email@example.com"

View File

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

View File

@ -56,7 +56,7 @@ export const inviteMemberHandler = async ({ ctx, input }: InviteMemberOptions) =
}); });
const invitee = await getUserToInviteOrThrowIfExists({ const invitee = await getUserToInviteOrThrowIfExists({
usernameOrEmail, usernameOrEmail,
orgId: input.teamId, teamId: input.teamId,
isOrg: input.isOrg, isOrg: input.isOrg,
}); });

View File

@ -66,17 +66,21 @@ export async function getEmailsToInvite(usernameOrEmail: string | string[]) {
export async function getUserToInviteOrThrowIfExists({ export async function getUserToInviteOrThrowIfExists({
usernameOrEmail, usernameOrEmail,
orgId, teamId,
isOrg, isOrg,
}: { }: {
usernameOrEmail: string; usernameOrEmail: string;
orgId: number; teamId: number;
isOrg?: boolean; isOrg?: boolean;
}) { }) {
// Check if user exists in ORG or exists all together // Check if user exists in ORG or exists all together
const orgWhere = isOrg && {
organizationId: teamId,
};
const invitee = await prisma.user.findFirst({ const invitee = await prisma.user.findFirst({
where: { where: {
OR: [{ username: usernameOrEmail, organizationId: orgId }, { email: usernameOrEmail }], OR: [{ username: usernameOrEmail, ...orgWhere }, { email: usernameOrEmail }],
}, },
}); });