Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat: update blocking modal with userteam status

Marc Seitzb7c4abb5858a
diff --git a/components/layouts/blocking-modal.tsx b/components/layouts/blocking-modal.tsx
index 3e800569..b51a3495 100644
--- a/components/layouts/blocking-modal.tsx
+++ b/components/layouts/blocking-modal.tsx
@@ -5,7 +5,7 @@ import { useTeam } from "@/context/team-context";
import { TeamContextType } from "@/context/team-context";
import { PlanEnum } from "@/ee/stripe/constants";
import { InfoIcon, ShieldAlertIcon } from "lucide-react";
-import { useSession } from "next-auth/react";
+import { signOut, useSession } from "next-auth/react";
import { usePlan } from "@/lib/swr/use-billing";
import { useGetTeam } from "@/lib/swr/use-team";
@@ -20,10 +20,10 @@ import {
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
+import { Button } from "@/components/ui/button";
import { UpgradePlanModal } from "../billing/upgrade-plan-modal";
import { AddTeamModal } from "../teams/add-team-modal";
-import { Button } from "../ui/button";
export const BlockingModal = () => {
const { isFree, isTrial } = usePlan();
@@ -40,17 +40,29 @@ export const BlockingModal = () => {
const userTeam = teams?.find((t) => t.id !== team?.id);
const multipleUsers = team?.users?.length && team?.users?.length > 1;
- const shouldShowBanner = isFree && !isTrial && isAdmin && multipleUsers;
+ // const shouldShowBanner = isFree && !isTrial && isAdmin && multipleUsers;
const [showModal, setShowModal] = useState(false);
+ // Check if current user is blocked due to trial expiration
+ const currentUserTeam = team?.users.find(
+ (user) => user.userId === currentUserId,
+ );
+
+ const isBlockedDueToTrial =
+ currentUserTeam?.status === "BLOCKED_TRIAL_EXPIRED";
+
const shouldShowModal =
- isFree && !isTrial && !isAdmin && multipleUsers && showModal;
+ (isFree && !isTrial && !isAdmin && multipleUsers && showModal) ||
+ isBlockedDueToTrial;
useEffect(() => {
- if (isFree && !isTrial && !isAdmin && multipleUsers) {
+ if (
+ (isFree && !isTrial && !isAdmin && multipleUsers) ||
+ isBlockedDueToTrial
+ ) {
setShowModal(true);
}
- }, [isFree, isTrial, isAdmin, multipleUsers]);
+ }, [isFree, isTrial, isAdmin, multipleUsers, isBlockedDueToTrial]);
useEffect(() => {
if (shouldShowModal) {
@@ -102,7 +114,7 @@ export const BlockingModal = () => {
return (
<>
- <div className="flex w-full px-4">
+ {/* <div className="flex w-full px-4">
{shouldShowBanner && (
<div className="flex w-full items-center gap-3 rounded-md border border-yellow-200 bg-yellow-50 p-4 text-sm dark:border-yellow-800 dark:bg-yellow-900/50 dark:text-yellow-100">
<div className="flex-shrink-0">
@@ -118,19 +130,23 @@ export const BlockingModal = () => {
</p>
</div>
<UpgradePlanModal
- clickedPlan={PlanEnum.DataRooms}
+ clickedPlan={PlanEnum.Pro}
trigger="trial_end_blocking_modal"
>
<Button type="button" variant="orange">
Upgrade
</Button>
</UpgradePlanModal>
+ <Button type="button" variant="outline">
+ Dismiss
+ </Button>
</div>
)}
- </div>
+ </div> */}
<AlertDialog open={!!shouldShowModal} onOpenChange={setShowModal}>
<AlertDialogContent
- className="w-full max-w-md"
+ className="w-full max-w-lg"
+ overlayClassName="backdrop-blur"
onContextMenu={(e) => e.preventDefault()}
>
<AlertDialogHeader className="flex flex-col items-center text-center">
@@ -140,48 +156,56 @@ export const BlockingModal = () => {
<AlertDialogTitle className="text-2xl font-semibold">
Account Access Limited
</AlertDialogTitle>
- <AlertDialogDescription className="mt-2 text-muted-foreground">
- Your team is now on a free solo plan. You no longer have access to
- this workspace.
- </AlertDialogDescription>
- <AlertDialogDescription className="my-2 text-muted-foreground">
- {userTeam ? (
- <>
- Switch to{" "}
- <Button
- variant="link"
- className="p-0 font-bold text-primary"
- onClick={handleSwitchTeam}
- >
- {userTeam.name}
- </Button>{" "}
- to continue using the platform.
- </>
- ) : (
- "Create a new team to continue using the platform."
- )}
+ <AlertDialogDescription className="mt-2 space-y-2 text-muted-foreground">
+ <div>
+ Your team is now on a free solo plan. Your access to this team
+ has been limited.
+ </div>
+ <div>
+ Contact your team owner, upgrade the team or{" "}
+ {userTeam ? (
+ <span>
+ switch to another team to continue using the platform.
+ </span>
+ ) : (
+ <span>create a new team to continue using the platform.</span>
+ )}
+ </div>
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
+ <Button
+ variant="link"
+ className="w-full sm:w-auto"
+ onClick={() => signOut()}
+ >
+ Log out
+ </Button>
<UpgradePlanModal
- clickedPlan={PlanEnum.DataRooms}
+ clickedPlan={PlanEnum.Pro}
trigger="trial_end_blocking_modal_for_team_member"
>
- <Button
- className="w-full sm:w-auto"
- variant="outline"
- type="button"
- >
+ <Button className="w-full sm:w-auto" type="button">
Upgrade
</Button>
</UpgradePlanModal>
{userTeam ? (
- <Button className="w-full sm:w-auto" onClick={handleSwitchTeam}>
- Switch to &quot;{userTeam.name}&quot;
+ <Button
+ variant="outline"
+ className="w-full gap-0 sm:w-auto"
+ onClick={handleSwitchTeam}
+ >
+ Switch to &quot;
+ <span className="w-[15ch] max-w-fit truncate">
+ {userTeam.name}
+ </span>
+ &quot;
</Button>
) : (
<AddTeamModal setCurrentTeam={setCurrentTeam}>
- <Button className="w-full sm:w-auto">Create New Team</Button>
+ <Button variant="outline" className="w-full sm:w-auto">
+ Create New Team
+ </Button>
</AddTeamModal>
)}
</AlertDialogFooter>
diff --git a/components/ui/alert-dialog.tsx b/components/ui/alert-dialog.tsx
index 923392bb..d49272a6 100644
--- a/components/ui/alert-dialog.tsx
+++ b/components/ui/alert-dialog.tsx
@@ -31,10 +31,12 @@ AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName;
const AlertDialogContent = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Content>,
- React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Content>
->(({ className, ...props }, ref) => (
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Content> & {
+ overlayClassName?: string;
+ }
+>(({ className, overlayClassName, ...props }, ref) => (
<AlertDialogPortal>
- <AlertDialogOverlay />
+ <AlertDialogOverlay className={overlayClassName} />
<AlertDialogPrimitive.Content
ref={ref}
className={cn(
diff --git a/lib/types.ts b/lib/types.ts
index 4f22cefe..9778ae7c 100644
--- a/lib/types.ts
+++ b/lib/types.ts
@@ -310,18 +310,16 @@ export interface Team {
export interface TeamDetail {
id: string;
name: string;
- documents: {
- owner: {
- id: string;
- name: string;
- };
- }[];
users: {
role: "ADMIN" | "MANAGER" | "MEMBER";
+ status: "ACTIVE" | "BLOCKED_TRIAL_EXPIRED";
teamId: string;
user: {
email: string;
name: string;
+ _count: {
+ documents: number;
+ };
};
userId: string;
}[];
diff --git a/pages/api/teams/[teamId]/index.ts b/pages/api/teams/[teamId]/index.ts
index f00b67e6..33e89266 100644
--- a/pages/api/teams/[teamId]/index.ts
+++ b/pages/api/teams/[teamId]/index.ts
@@ -41,20 +41,18 @@ export default async function handle(
role: true,
teamId: true,
userId: true,
+ status: true,
user: {
select: {
email: true,
name: true,
- },
- },
- },
- },
- documents: {
- select: {
- owner: {
- select: {
- name: true,
- id: true,
+ _count: {
+ select: {
+ documents: {
+ where: { teamId: teamId },
+ },
+ },
+ },
},
},
},
diff --git a/pages/api/teams/[teamId]/remove-teammate.ts b/pages/api/teams/[teamId]/remove-teammate.ts
index 4169a2f4..1d4aa53f 100644
--- a/pages/api/teams/[teamId]/remove-teammate.ts
+++ b/pages/api/teams/[teamId]/remove-teammate.ts
@@ -39,14 +39,28 @@ export default async function handle(
return res.status(401).json("You can't remove the Admin");
}
- await prisma.userTeam.delete({
- where: {
- userId_teamId: {
- userId: userToBeDeleted,
+ await Promise.all([
+ // update all documents owned by the user to be deleted to be owned by the team
+ prisma.document.updateMany({
+ where: {
teamId,
+ ownerId: userToBeDeleted,
},
- },
- });
+ data: {
+ ownerId: null,
+ },
+ }),
+ // delete the user from the team
+ prisma.userTeam.delete({
+ where: {
+ userId_teamId: {
+ userId: userToBeDeleted,
+ teamId,
+ },
+ },
+ }),
+ ]);
+
return res.status(204).end();
} catch (error) {
errorhandler(error, res);
diff --git a/pages/settings/people.tsx b/pages/settings/people.tsx
index 85552504..69bc9520 100644
--- a/pages/settings/people.tsx
+++ b/pages/settings/people.tsx
@@ -52,10 +52,8 @@ export default function Billing() {
const router = useRouter();
const getUserDocumentCount = (userId: string) => {
- const documents = team?.documents.filter(
- (document) => document.owner?.id === userId,
- );
- return documents?.length;
+ return team?.users.find((user) => user.userId === userId)?.user._count
+ .documents;
};
const isCurrentUser = (userId: string) => {
@@ -302,9 +300,16 @@ export default function Billing() {
</div>
</div>
<div className="flex items-center gap-12">
- <span className="text-sm capitalize text-foreground">
- {member.role.toLowerCase()}
- </span>
+ <div className="flex flex-col items-end gap-1">
+ <span className="text-sm capitalize text-foreground">
+ {member.role.toLowerCase()}
+ </span>
+ {member.status === "BLOCKED_TRIAL_EXPIRED" && (
+ <span className="text-xs font-medium text-red-500">
+ Blocked (Trial Expired)
+ </span>
+ )}
+ </div>
{leavingUserId === member.userId ? (
<span className="text-xs">leaving...</span>
) : (