The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
improve remove teammate/invite/self modal
Steven Teyf4d49b442f5e
diff --git a/components/app/modals/remove-teammate-modal.tsx b/components/app/modals/remove-teammate-modal.tsxindex cd72880d14..b57a2cdd59 100644--- a/components/app/modals/remove-teammate-modal.tsx+++ b/components/app/modals/remove-teammate-modal.tsx@@ -14,6 +14,7 @@ import { toast } from "sonner";import Button from "#/ui/button";import { UserProps } from "#/lib/types";import { Logo } from "#/ui/icons";+import { useSession } from "next-auth/react";function RemoveTeammateModal({showRemoveTeammateModal,@@ -29,9 +30,31 @@ function RemoveTeammateModal({const router = useRouter();const { slug } = router.query as { slug: string };const [removing, setRemoving] = useState(false);- const { logo } = useProject();+ const { name: projectName, logo } = useProject();+ const { data: session } = useSession();const { id, name, email, image } = user;+ const { title, description } = useMemo(() => {+ if (invite) {+ return {+ title: "Remove Invitation",+ description: `This will remove <strong>${+ name || email+ }</stromg>'s invitation to join your project.`,+ };+ } else if (session?.user?.email === email) {+ return {+ title: "Leave Project",+ description: `You are about to leave ${projectName}. To regain access, the Project Owner will need to re-invite you.`,+ };+ } else {+ return {+ title: "Remove Teammate",+ description: `This will remove ${name || email} from your project.`,+ };+ }+ }, [invite, session, name, email]);+return (<ModalshowModal={showRemoveTeammateModal}@@ -50,14 +73,27 @@ function RemoveTeammateModal({<Logo />)}<h3 className="text-lg font-medium">- Remove {invite ? "Invitation" : "Teammate"}+ {invite+ ? "Revoke Invitation"+ : session?.user?.email === email+ ? "Leave Project"+ : "Remove Teammate"}</h3><p className="text-center text-sm text-gray-500">- This will remove{" "}- <span className="font-semibold text-black">{name || email}</span>{invite- ? "'s invitation to join your project."- : " from your project. Are you sure you want to continue?"}+ ? "This will revoke "+ : session?.user?.email === email+ ? "You're about to leave "+ : "This will remove "}+ <span className="font-semibold text-black">+ {session?.user?.email === email ? projectName : name || email}+ </span>+ {invite+ ? "'s invitation to join your project. "+ : session?.user?.email === email+ ? ". You will lose all access to this project. "+ : " from your project. "}+ Are you sure you want to continue?</p></div>@@ -76,7 +112,7 @@ function RemoveTeammateModal({</div></div><Button- text="Confirm remove"+ text="Confirm"variant="danger"loading={removing}onClick={() => {@@ -93,10 +129,18 @@ function RemoveTeammateModal({setRemoving(false);if (res.status === 200) {toast.success(- `${invite ? "Invite" : "User"} removed from project!`,+ session?.user?.email === email+ ? "You have left the project!"+ : invite+ ? "Successfully revoked invitation!"+ : "Successfully removed teammate!",);mutate(`/api/projects/${slug}/${invite ? "invites" : "users"}`);setShowRemoveTeammateModal(false);+ if (session?.user?.email === email) {+ mutate("/api/projects");+ router.push("/");+ }} else {const error = await res.text();toast.error(error);diff --git a/pages/app/[slug]/settings/people.tsx b/pages/app/[slug]/settings/people.tsxindex 536c2b87b3..89945cb0b3 100644--- a/pages/app/[slug]/settings/people.tsx+++ b/pages/app/[slug]/settings/people.tsx@@ -11,6 +11,7 @@ import { ThreeDots } from "@/components/shared/icons";import { useRemoveTeammateModal } from "@/components/app/modals/remove-teammate-modal";import Badge from "#/ui/badge";import useUsers from "#/lib/swr/use-users";+import { useSession } from "next-auth/react";const tabs: Array<"Members" | "Invitations"> = ["Members", "Invitations"];@@ -103,6 +104,8 @@ const UserCard = ({const { name, email, image, joinedAt } = user;+ const { data: session } = useSession();+// invites expire after 14 days of being sentconst expiredInvite =currentTab === "Invitations" &&@@ -152,7 +155,13 @@ const UserCard = ({className="rounded-md p-2 text-left text-sm font-medium text-red-600 transition-all duration-75 hover:bg-red-600 hover:text-white"><IconMenu- text="Remove"+ text={+ session?.user?.email === email+ ? "Leave project"+ : currentTab === "Members"+ ? "Remove member"+ : "Revoke invite"+ }icon={<UserMinus className="h-4 w-4" />}/></button>