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 = {
|
||||
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"
|
||||
|
|
|
@ -60,6 +60,7 @@ export function InviteMemberModal(props: Props) {
|
|||
});
|
||||
}}
|
||||
teamId={orgId}
|
||||
justEmailInvites={!!orgId}
|
||||
isLoading={inviteMemberMutation.isLoading}
|
||||
onSubmit={(values) => {
|
||||
inviteMemberMutation.mutate({
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
|
||||
|
|
|
@ -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 }],
|
||||
},
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue