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
parent
0e181f6d9f
commit
376b38d4ed
|
@ -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"
|
||||||
|
|
|
@ -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({
|
||||||
|
|
|
@ -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,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -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 }],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue