fix: org invite (#11356)
Co-authored-by: Leo Giovanetti <[email protected]>
This commit is contained in:
1 parent
45cded6b48
commit
50970dc249
8 files changed
+122
-46
No files matched your search
@@ -42,6 +42,7 @@ type MemberInvitationModalProps = {
|
||||
token?: string;
|
||||
isLoading?: boolean;
|
||||
disableCopyLink?: boolean;
|
||||
isOrg?: boolean;
|
||||
};
|
||||
|
||||
type MembershipRoleOption = {
|
||||
@@ -68,7 +69,7 @@ function toggleElementInArray(value: string[] | string | undefined, element: str
|
||||
|
||||
export default function MemberInvitationModal(props: MemberInvitationModalProps) {
|
||||
const { t } = useLocale();
|
||||
const { disableCopyLink = false } = props;
|
||||
const { disableCopyLink = false, isOrg = false } = props;
|
||||
const trpcContext = trpc.useContext();
|
||||
|
||||
const [modalImportMode, setModalInputMode] = useState<ModalMode>(
|
||||
@@ -87,7 +88,12 @@ export default function MemberInvitationModal(props: MemberInvitationModalProps)
|
||||
});
|
||||
|
||||
const copyInviteLinkToClipboard = async (token: string) => {
|
||||
const inviteLink = `${WEBAPP_URL}/teams?token=${token}`;
|
||||
const isOrgInvite = isOrg;
|
||||
const teamInviteLink = `${WEBAPP_URL}/teams?token=${token}`;
|
||||
const orgInviteLink = `${WEBAPP_URL}/signup?token=${token}&callbackUrl=/getting-started`;
|
||||
|
||||
const inviteLink =
|
||||
isOrgInvite || (props?.orgMembers && props.orgMembers?.length > 0) ? orgInviteLink : teamInviteLink;
|
||||
await navigator.clipboard.writeText(inviteLink);
|
||||
showToast(t("invite_link_copied"), "success");
|
||||
};
|
||||
|
||||
@@ -90,13 +90,14 @@ const MembersView = () => {
|
||||
distinctUser: true,
|
||||
},
|
||||
{
|
||||
enabled: searchParams !== null,
|
||||
enabled: searchParams !== null && !!teamId,
|
||||
}
|
||||
);
|
||||
|
||||
const { data: team, isLoading: isTeamsLoading } = trpc.viewer.teams.get.useQuery(
|
||||
{ teamId },
|
||||
{
|
||||
enabled: !!teamId,
|
||||
onError: () => {
|
||||
router.push("/settings");
|
||||
},
|
||||
|
||||
@@ -60,6 +60,7 @@ export function InviteMemberModal(props: Props) {
|
||||
});
|
||||
}}
|
||||
teamId={orgId}
|
||||
isOrg={true}
|
||||
justEmailInvites={!!orgId}
|
||||
isLoading={inviteMemberMutation.isLoading}
|
||||
onSubmit={(values) => {
|
||||
|
||||
@@ -170,10 +170,15 @@ export async function getTeamWithMembers(args: {
|
||||
}));
|
||||
/** Don't leak invite tokens to the frontend */
|
||||
const { inviteTokens, ...teamWithoutInviteTokens } = team;
|
||||
|
||||
return {
|
||||
...teamWithoutInviteTokens,
|
||||
/** To prevent breaking we only return non-email attached token here, if we have one */
|
||||
inviteToken: inviteTokens.find((token) => token.identifier === "invite-link-for-teamId-" + team.id),
|
||||
inviteToken: inviteTokens.find(
|
||||
(token) =>
|
||||
token.identifier === "invite-link-for-teamId-" + team.id &&
|
||||
token.expires > new Date(new Date().setHours(24))
|
||||
),
|
||||
metadata: teamMetadataSchema.parse(team.metadata),
|
||||
eventTypes,
|
||||
members,
|
||||
|
||||
@@ -24,7 +24,7 @@ export const createInviteHandler = async ({ ctx, input }: CreateInviteOptions) =
|
||||
data: {
|
||||
identifier: "invite-link-for-teamId-" + teamId,
|
||||
token,
|
||||
expires: new Date(),
|
||||
expires: new Date(new Date().setHours(168)), // +1 week,
|
||||
teamId,
|
||||
},
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user