feat: Add copy invite link (#8355)
* feat: Add shared invite link * refactor: Rename Invite to Team Invite model * feat: add admin check for team invite link procedures * Replace TeamInvite with VerificationToken * Add team invite null checks * Migrates tRPC procedures to new format * Type fixes * Update common.json --------- Co-authored-by: zomars <[email protected]> Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: Joe Au-Yeung <[email protected]> Co-authored-by: alannnc <[email protected]> Co-authored-by: Efraín Rochín <[email protected]> Co-authored-by: Keith Williams <[email protected]>
This commit is contained in:
22 files changed
+655
-49
No files matched your search
@@ -3,14 +3,23 @@ import { useRouter } from "next/router";
|
||||
import { useState } from "react";
|
||||
import { z } from "zod";
|
||||
|
||||
import InviteLinkSettingsModal from "@calcom/features/ee/teams/components/InviteLinkSettingsModal";
|
||||
import MemberInvitationModal from "@calcom/features/ee/teams/components/MemberInvitationModal";
|
||||
import { classNames } from "@calcom/lib";
|
||||
import { WEBAPP_URL, APP_NAME } from "@calcom/lib/constants";
|
||||
import { APP_NAME, WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import type { RouterOutputs } from "@calcom/trpc/react";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Avatar, Badge, Button, showToast, SkeletonContainer, SkeletonText } from "@calcom/ui";
|
||||
import { Plus, ArrowRight, Trash2 } from "@calcom/ui/components/icon";
|
||||
import {
|
||||
Avatar,
|
||||
Badge,
|
||||
Button,
|
||||
showToast,
|
||||
SkeletonButton,
|
||||
SkeletonContainer,
|
||||
SkeletonText,
|
||||
} from "@calcom/ui";
|
||||
import { ArrowRight, Plus, Trash2 } from "@calcom/ui/components/icon";
|
||||
|
||||
const querySchema = z.object({
|
||||
id: z.string().transform((val) => parseInt(val)),
|
||||
@@ -40,10 +49,16 @@ export const AddNewTeamMembersForm = ({
|
||||
teamId: number;
|
||||
}) => {
|
||||
const { t, i18n } = useLocale();
|
||||
|
||||
const router = useRouter();
|
||||
const utils = trpc.useContext();
|
||||
|
||||
const showDialog = router.query.inviteModal === "true";
|
||||
const [memberInviteModal, setMemberInviteModal] = useState(showDialog);
|
||||
const utils = trpc.useContext();
|
||||
const [inviteLinkSettingsModal, setInviteLinkSettingsModal] = useState(false);
|
||||
|
||||
const { data: team, isLoading } = trpc.viewer.teams.get.useQuery({ teamId });
|
||||
|
||||
const inviteMemberMutation = trpc.viewer.teams.inviteMember.useMutation({
|
||||
async onSuccess(data) {
|
||||
await utils.viewer.teams.get.invalidate();
|
||||
@@ -70,6 +85,7 @@ export const AddNewTeamMembersForm = ({
|
||||
showToast(error.message, "error");
|
||||
},
|
||||
});
|
||||
|
||||
const publishTeamMutation = trpc.viewer.teams.publish.useMutation({
|
||||
onSuccess(data) {
|
||||
router.push(data.url);
|
||||
@@ -96,20 +112,44 @@ export const AddNewTeamMembersForm = ({
|
||||
{t("add_team_member")}
|
||||
</Button>
|
||||
</div>
|
||||
<MemberInvitationModal
|
||||
isOpen={memberInviteModal}
|
||||
onExit={() => setMemberInviteModal(false)}
|
||||
onSubmit={(values) => {
|
||||
inviteMemberMutation.mutate({
|
||||
teamId,
|
||||
language: i18n.language,
|
||||
role: values.role,
|
||||
usernameOrEmail: values.emailOrUsername,
|
||||
sendEmailInvitation: values.sendInviteEmail,
|
||||
});
|
||||
}}
|
||||
members={defaultValues.members}
|
||||
/>
|
||||
{isLoading ? (
|
||||
<SkeletonButton />
|
||||
) : (
|
||||
<>
|
||||
<MemberInvitationModal
|
||||
isOpen={memberInviteModal}
|
||||
teamId={teamId}
|
||||
token={team?.inviteToken?.token}
|
||||
onExit={() => setMemberInviteModal(false)}
|
||||
onSubmit={(values) => {
|
||||
inviteMemberMutation.mutate({
|
||||
teamId,
|
||||
language: i18n.language,
|
||||
role: values.role,
|
||||
usernameOrEmail: values.emailOrUsername,
|
||||
sendEmailInvitation: values.sendInviteEmail,
|
||||
});
|
||||
}}
|
||||
onSettingsOpen={() => {
|
||||
setMemberInviteModal(false);
|
||||
setInviteLinkSettingsModal(true);
|
||||
}}
|
||||
members={defaultValues.members}
|
||||
/>
|
||||
{team?.inviteToken && (
|
||||
<InviteLinkSettingsModal
|
||||
isOpen={inviteLinkSettingsModal}
|
||||
teamId={team.id}
|
||||
token={team.inviteToken?.token}
|
||||
expiresInDays={team.inviteToken?.expiresInDays || undefined}
|
||||
onExit={() => {
|
||||
setInviteLinkSettingsModal(false);
|
||||
setMemberInviteModal(true);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
<hr className="border-subtle my-6" />
|
||||
<Button
|
||||
EndIcon={ArrowRight}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
import { useMemo } from "react";
|
||||
import { Controller, useForm } from "react-hook-form";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { trpc } from "@calcom/trpc";
|
||||
import { Button, Dialog, DialogContent, DialogFooter, Form, Label, Select, showToast } from "@calcom/ui";
|
||||
|
||||
type InvitationLinkSettingsModalProps = {
|
||||
isOpen: boolean;
|
||||
teamId: number;
|
||||
token: string;
|
||||
expiresInDays?: number;
|
||||
onExit: () => void;
|
||||
};
|
||||
|
||||
export interface LinkSettingsForm {
|
||||
expiresInDays: number | undefined;
|
||||
}
|
||||
|
||||
export default function InviteLinkSettingsModal(props: InvitationLinkSettingsModalProps) {
|
||||
const { t } = useLocale();
|
||||
const trpcContext = trpc.useContext();
|
||||
|
||||
const deleteInviteMutation = trpc.viewer.teams.deleteInvite.useMutation({
|
||||
onSuccess: () => {
|
||||
showToast(t("invite_link_deleted"), "success");
|
||||
trpcContext.viewer.teams.get.invalidate();
|
||||
trpcContext.viewer.teams.list.invalidate();
|
||||
props.onExit();
|
||||
},
|
||||
onError: (e) => {
|
||||
showToast(e.message, "error");
|
||||
},
|
||||
});
|
||||
|
||||
const setInviteExpirationMutation = trpc.viewer.teams.setInviteExpiration.useMutation({
|
||||
onSuccess: () => {
|
||||
showToast(t("invite_link_updated"), "success");
|
||||
trpcContext.viewer.teams.get.invalidate();
|
||||
trpcContext.viewer.teams.list.invalidate();
|
||||
},
|
||||
onError: (e) => {
|
||||
showToast(e.message, "error");
|
||||
},
|
||||
});
|
||||
|
||||
const expiresInDaysOption = useMemo(() => {
|
||||
return [
|
||||
{ value: 1, label: t("one_day") },
|
||||
{ value: 7, label: t("seven_days") },
|
||||
{ value: 30, label: t("thirty_days") },
|
||||
{ value: undefined, label: t("never_expire") },
|
||||
];
|
||||
}, [t]);
|
||||
|
||||
const linkSettingsFormMethods = useForm<LinkSettingsForm>();
|
||||
|
||||
const handleSubmit = (values: LinkSettingsForm) => {
|
||||
setInviteExpirationMutation.mutate({
|
||||
token: props.token,
|
||||
expiresInDays: values.expiresInDays,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
open={props.isOpen}
|
||||
onOpenChange={() => {
|
||||
props.onExit();
|
||||
linkSettingsFormMethods.reset();
|
||||
}}>
|
||||
<DialogContent type="creation" title="Invite link settings">
|
||||
<Form form={linkSettingsFormMethods} handleSubmit={handleSubmit}>
|
||||
<Controller
|
||||
name="expiresInDays"
|
||||
control={linkSettingsFormMethods.control}
|
||||
render={({ field: { onChange } }) => (
|
||||
<div>
|
||||
<Label className="text-emphasis font-medium" htmlFor="expiresInDays">
|
||||
{t("link_expires_after")}
|
||||
</Label>
|
||||
<Select
|
||||
options={expiresInDaysOption}
|
||||
defaultValue={expiresInDaysOption.find((option) => option.value === props.expiresInDays)}
|
||||
className="w-full"
|
||||
onChange={(val) => onChange(val?.value)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
/>
|
||||
<DialogFooter>
|
||||
<Button
|
||||
type="button"
|
||||
color="secondary"
|
||||
onClick={() => deleteInviteMutation.mutate({ token: props.token })}
|
||||
className="mr-auto"
|
||||
data-testid="copy-invite-link-button">
|
||||
{t("delete")}
|
||||
</Button>
|
||||
<Button type="button" color="minimal" onClick={props.onExit}>
|
||||
{t("back")}
|
||||
</Button>
|
||||
<Button
|
||||
type="submit"
|
||||
color="primary"
|
||||
className="ms-2 me-2"
|
||||
data-testid="invite-new-member-button">
|
||||
{t("save")}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</Form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -3,9 +3,11 @@ import { Trans } from "next-i18next";
|
||||
import { useMemo, useState } from "react";
|
||||
import { Controller, useForm } from "react-hook-form";
|
||||
|
||||
import { IS_TEAM_BILLING_ENABLED } from "@calcom/lib/constants";
|
||||
import { classNames } from "@calcom/lib";
|
||||
import { IS_TEAM_BILLING_ENABLED, WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
import { trpc } from "@calcom/trpc";
|
||||
import {
|
||||
Button,
|
||||
Checkbox as CheckboxField,
|
||||
@@ -13,12 +15,14 @@ import {
|
||||
DialogContent,
|
||||
DialogFooter,
|
||||
Form,
|
||||
TextField,
|
||||
Label,
|
||||
showToast,
|
||||
TextField,
|
||||
ToggleGroup,
|
||||
Select,
|
||||
TextAreaField,
|
||||
} from "@calcom/ui";
|
||||
import { Link } from "@calcom/ui/components/icon";
|
||||
|
||||
import type { PendingMember } from "../lib/types";
|
||||
import { GoogleWorkspaceInviteButton } from "./GoogleWorkspaceInviteButton";
|
||||
@@ -27,7 +31,10 @@ type MemberInvitationModalProps = {
|
||||
isOpen: boolean;
|
||||
onExit: () => void;
|
||||
onSubmit: (values: NewMemberForm) => void;
|
||||
onSettingsOpen: () => void;
|
||||
teamId: number;
|
||||
members: PendingMember[];
|
||||
token?: string;
|
||||
};
|
||||
|
||||
type MembershipRoleOption = {
|
||||
@@ -45,7 +52,27 @@ type ModalMode = "INDIVIDUAL" | "BULK";
|
||||
|
||||
export default function MemberInvitationModal(props: MemberInvitationModalProps) {
|
||||
const { t } = useLocale();
|
||||
const trpcContext = trpc.useContext();
|
||||
|
||||
const [modalImportMode, setModalInputMode] = useState<ModalMode>("INDIVIDUAL");
|
||||
|
||||
const createInviteMutation = trpc.viewer.teams.createInvite.useMutation({
|
||||
onSuccess(token) {
|
||||
copyInviteLinkToClipboard(token);
|
||||
trpcContext.viewer.teams.get.invalidate();
|
||||
trpcContext.viewer.teams.list.invalidate();
|
||||
},
|
||||
onError: (error) => {
|
||||
showToast(error.message, "error");
|
||||
},
|
||||
});
|
||||
|
||||
const copyInviteLinkToClipboard = async (token: string) => {
|
||||
const inviteLink = `${WEBAPP_URL}/teams?token=${token}`;
|
||||
await navigator.clipboard.writeText(inviteLink);
|
||||
showToast(t("invite_link_copied"), "success");
|
||||
};
|
||||
|
||||
const options: MembershipRoleOption[] = useMemo(() => {
|
||||
return [
|
||||
{ value: MembershipRole.MEMBER, label: t("member") },
|
||||
@@ -215,6 +242,35 @@ export default function MemberInvitationModal(props: MemberInvitationModalProps)
|
||||
/>
|
||||
</div>
|
||||
<DialogFooter showDivider>
|
||||
<div className="mr-auto flex">
|
||||
<Button
|
||||
type="button"
|
||||
color="minimal"
|
||||
variant="icon"
|
||||
onClick={() =>
|
||||
props.token
|
||||
? copyInviteLinkToClipboard(props.token)
|
||||
: createInviteMutation.mutate({ teamId: props.teamId })
|
||||
}
|
||||
className={classNames("gap-2", props.token && "opacity-50")}
|
||||
data-testid="copy-invite-link-button">
|
||||
<Link className="text-default h-4 w-4" aria-hidden="true" />
|
||||
{t("copy_invite_link")}
|
||||
</Button>
|
||||
{props.token && (
|
||||
<Button
|
||||
type="button"
|
||||
color="minimal"
|
||||
className="ms-2 me-2"
|
||||
onClick={() => {
|
||||
props.onSettingsOpen();
|
||||
newMemberFormMethods.reset();
|
||||
}}
|
||||
data-testid="edit-invite-link-button">
|
||||
{t("edit_invite_link")}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<Button
|
||||
type="button"
|
||||
color="minimal"
|
||||
|
||||
@@ -2,6 +2,7 @@ import Link from "next/link";
|
||||
import { useRouter } from "next/router";
|
||||
import { useState } from "react";
|
||||
|
||||
import InviteLinkSettingsModal from "@calcom/ee/teams/components/InviteLinkSettingsModal";
|
||||
import MemberInvitationModal from "@calcom/ee/teams/components/MemberInvitationModal";
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { getPlaceholderAvatar } from "@calcom/lib/defaultAvatarImage";
|
||||
@@ -26,16 +27,16 @@ import {
|
||||
Tooltip,
|
||||
} from "@calcom/ui";
|
||||
import {
|
||||
MoreHorizontal,
|
||||
Check,
|
||||
X,
|
||||
Link as LinkIcon,
|
||||
Edit2,
|
||||
ExternalLink,
|
||||
Trash,
|
||||
LogOut,
|
||||
Globe,
|
||||
Link as LinkIcon,
|
||||
LogOut,
|
||||
MoreHorizontal,
|
||||
Send,
|
||||
Trash,
|
||||
X,
|
||||
} from "@calcom/ui/components/icon";
|
||||
|
||||
import { TeamRole } from "./TeamPill";
|
||||
@@ -51,11 +52,15 @@ interface Props {
|
||||
|
||||
export default function TeamListItem(props: Props) {
|
||||
const { t, i18n } = useLocale();
|
||||
|
||||
const router = useRouter();
|
||||
const utils = trpc.useContext();
|
||||
const team = props.team;
|
||||
const router = useRouter();
|
||||
|
||||
const showDialog = router.query.inviteModal === "true";
|
||||
const [openMemberInvitationModal, setOpenMemberInvitationModal] = useState(showDialog);
|
||||
const [openInviteLinkSettingsModal, setOpenInviteLinkSettingsModal] = useState(false);
|
||||
|
||||
const teamQuery = trpc.viewer.teams.get.useQuery({ teamId: team?.id });
|
||||
const inviteMemberMutation = trpc.viewer.teams.inviteMember.useMutation({
|
||||
async onSuccess(data) {
|
||||
@@ -129,6 +134,8 @@ export default function TeamListItem(props: Props) {
|
||||
<li className="">
|
||||
<MemberInvitationModal
|
||||
isOpen={openMemberInvitationModal}
|
||||
teamId={team.id}
|
||||
token={team.inviteToken?.token}
|
||||
onExit={() => {
|
||||
setOpenMemberInvitationModal(false);
|
||||
}}
|
||||
@@ -141,8 +148,24 @@ export default function TeamListItem(props: Props) {
|
||||
sendEmailInvitation: values.sendInviteEmail,
|
||||
});
|
||||
}}
|
||||
onSettingsOpen={() => {
|
||||
setOpenMemberInvitationModal(false);
|
||||
setOpenInviteLinkSettingsModal(true);
|
||||
}}
|
||||
members={teamQuery?.data?.members || []}
|
||||
/>
|
||||
{team.inviteToken && (
|
||||
<InviteLinkSettingsModal
|
||||
isOpen={openInviteLinkSettingsModal}
|
||||
teamId={team.id}
|
||||
token={team.inviteToken?.token}
|
||||
expiresInDays={team.inviteToken?.expiresInDays || undefined}
|
||||
onExit={() => {
|
||||
setOpenInviteLinkSettingsModal(false);
|
||||
setOpenMemberInvitationModal(true);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<div className={classNames("flex items-center justify-between", !isInvitee && "hover:bg-muted group")}>
|
||||
{!isInvitee ? (
|
||||
<Link
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { useState, useMemo } from "react";
|
||||
import { useRouter } from "next/router";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
|
||||
import { WEBAPP_URL, APP_NAME } from "@calcom/lib/constants";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Alert, Button, ButtonGroup, Label } from "@calcom/ui";
|
||||
import { Users, RefreshCcw, UserPlus, Mail, Video, EyeOff } from "@calcom/ui/components/icon";
|
||||
import { Alert, Button, ButtonGroup, Label, showToast } from "@calcom/ui";
|
||||
import { EyeOff, Mail, RefreshCcw, UserPlus, Users, Video } from "@calcom/ui/components/icon";
|
||||
|
||||
import { UpgradeTip } from "../../../tips";
|
||||
import SkeletonLoaderTeamList from "./SkeletonloaderTeamList";
|
||||
@@ -12,14 +13,32 @@ import TeamList from "./TeamList";
|
||||
|
||||
export function TeamsListing() {
|
||||
const { t } = useLocale();
|
||||
const trpcContext = trpc.useContext();
|
||||
const router = useRouter();
|
||||
|
||||
const [inviteTokenChecked, setInviteTokenChecked] = useState(false);
|
||||
const [errorMessage, setErrorMessage] = useState("");
|
||||
|
||||
const { data, isLoading } = trpc.viewer.teams.list.useQuery(undefined, {
|
||||
enabled: inviteTokenChecked,
|
||||
onError: (e) => {
|
||||
setErrorMessage(e.message);
|
||||
},
|
||||
});
|
||||
|
||||
const { mutate: inviteMemberByToken } = trpc.viewer.teams.inviteMemberByToken.useMutation({
|
||||
onSuccess: (teamName) => {
|
||||
trpcContext.viewer.teams.list.invalidate();
|
||||
showToast(t("team_invite_received", { teamName }), "success");
|
||||
},
|
||||
onError: (e) => {
|
||||
showToast(e.message, "error");
|
||||
},
|
||||
onSettled: () => {
|
||||
setInviteTokenChecked(true);
|
||||
},
|
||||
});
|
||||
|
||||
const teams = useMemo(() => data?.filter((m) => m.accepted) || [], [data]);
|
||||
const invites = useMemo(() => data?.filter((m) => !m.accepted) || [], [data]);
|
||||
|
||||
@@ -56,7 +75,13 @@ export function TeamsListing() {
|
||||
},
|
||||
];
|
||||
|
||||
if (isLoading) {
|
||||
useEffect(() => {
|
||||
if (!router) return;
|
||||
if (router.query.token) inviteMemberByToken({ token: router.query.token as string });
|
||||
else setInviteTokenChecked(true);
|
||||
}, [router, inviteMemberByToken, setInviteTokenChecked]);
|
||||
|
||||
if (isLoading || !inviteTokenChecked) {
|
||||
return <SkeletonLoaderTeamList />;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import { Plus } from "@calcom/ui/components/icon";
|
||||
|
||||
import { getLayout } from "../../../settings/layouts/SettingsLayout";
|
||||
import DisableTeamImpersonation from "../components/DisableTeamImpersonation";
|
||||
import InviteLinkSettingsModal from "../components/InviteLinkSettingsModal";
|
||||
import MemberInvitationModal from "../components/MemberInvitationModal";
|
||||
import MemberListItem from "../components/MemberListItem";
|
||||
import TeamInviteList from "../components/TeamInviteList";
|
||||
@@ -63,12 +64,16 @@ function MembersList(props: MembersListProps) {
|
||||
|
||||
const MembersView = () => {
|
||||
const { t, i18n } = useLocale();
|
||||
|
||||
const router = useRouter();
|
||||
const session = useSession();
|
||||
|
||||
const utils = trpc.useContext();
|
||||
const teamId = Number(router.query.id);
|
||||
|
||||
const showDialog = router.query.inviteModal === "true";
|
||||
const [showMemberInvitationModal, setShowMemberInvitationModal] = useState(showDialog);
|
||||
const teamId = Number(router.query.id);
|
||||
const [showInviteLinkSettingsModal, setInviteLinkSettingsModal] = useState(false);
|
||||
|
||||
const { data: team, isLoading } = trpc.viewer.teams.get.useQuery(
|
||||
{ teamId },
|
||||
@@ -169,6 +174,8 @@ const MembersView = () => {
|
||||
<MemberInvitationModal
|
||||
isOpen={showMemberInvitationModal}
|
||||
members={team.members}
|
||||
teamId={team.id}
|
||||
token={team.inviteToken?.token}
|
||||
onExit={() => setShowMemberInvitationModal(false)}
|
||||
onSubmit={(values) => {
|
||||
inviteMemberMutation.mutate({
|
||||
@@ -179,6 +186,22 @@ const MembersView = () => {
|
||||
sendEmailInvitation: values.sendInviteEmail,
|
||||
});
|
||||
}}
|
||||
onSettingsOpen={() => {
|
||||
setShowMemberInvitationModal(false);
|
||||
setInviteLinkSettingsModal(true);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{showInviteLinkSettingsModal && team?.inviteToken && (
|
||||
<InviteLinkSettingsModal
|
||||
isOpen={showInviteLinkSettingsModal}
|
||||
teamId={team.id}
|
||||
token={team.inviteToken.token}
|
||||
expiresInDays={team.inviteToken.expiresInDays || undefined}
|
||||
onExit={() => {
|
||||
setInviteLinkSettingsModal(false);
|
||||
setShowMemberInvitationModal(true);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
|
||||
Reference in new issue
Block a user