Skip to content

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

ui: handle reused or revoked invites

Ashish Viradiya9594d6a93d76
diff --git a/app/(auth)/verify/invitation/InvitationStatusContent.tsx b/app/(auth)/verify/invitation/InvitationStatusContent.tsx
new file mode 100644
index 00000000..c36db7bd
--- /dev/null
+++ b/app/(auth)/verify/invitation/InvitationStatusContent.tsx
@@ -0,0 +1,80 @@
+"use client";
+
+import Link from "next/link";
+
+import { AlertCircleIcon, MailIcon } from "lucide-react";
+
+import { Button } from "@/components/ui/button";
+
+interface InvitationStatusContentProps {
+ email?: string;
+ status: "expired" | "revoked";
+}
+
+export default function InvitationStatusContent({
+ email,
+ status,
+}: InvitationStatusContentProps) {
+ const statusConfig = {
+ expired: {
+ title: "Invitation Link Expired",
+ message: "This invitation link has expired.\nIt is no longer valid.",
+ iconColor: "bg-amber-100",
+ iconTextColor: "text-amber-600",
+ },
+ revoked: {
+ title: "Invitation No Longer Available",
+ message: "It may have been used or revoked by the team administrator.",
+ iconColor: "bg-red-100",
+ iconTextColor: "text-red-600",
+ },
+ };
+
+ const config = statusConfig[status];
+
+ return (
+ <div className="flex flex-col items-center space-y-6">
+ <div
+ className={`flex items-center justify-center rounded-full ${config.iconColor} p-4`}
+ >
+ <AlertCircleIcon className={`h-8 w-8 ${config.iconTextColor}`} />
+ </div>
+
+ <div className="w-full text-center">
+ <h3 className="text-2xl font-bold text-gray-800">{config.title}</h3>
+ <p className="mx-auto mt-2 max-w-xs whitespace-pre-line break-words text-sm text-gray-600">
+ {config.message}
+ </p>
+ </div>
+ <div className="w-full space-y-4">
+ <h4 className="text-center text-sm font-medium text-gray-800">
+ Create your own Papermark account
+ </h4>
+ <div className="space-y-3">
+ <Link href="/login" className="block w-full">
+ <Button className="w-full bg-gray-800 hover:bg-gray-900">
+ Sign In
+ </Button>
+ </Link>
+ </div>
+ </div>
+
+ <div className="mt-4 w-full text-center text-xs text-gray-500">
+ <p>
+ Papermark helps you share documents with analytics and engagement
+ tracking.
+ <br />
+ Join thousands of teams already using{" "}
+ <Link
+ href="https://www.papermark.com"
+ target="_blank"
+ className="underline hover:text-gray-900"
+ >
+ Papermark
+ </Link>
+ .
+ </p>
+ </div>
+ </div>
+ );
+}
diff --git a/app/(auth)/verify/invitation/page.tsx b/app/(auth)/verify/invitation/page.tsx
index 165c65ff..b1db04ec 100644
--- a/app/(auth)/verify/invitation/page.tsx
+++ b/app/(auth)/verify/invitation/page.tsx
@@ -5,10 +5,12 @@ import NotFound from "@/pages/404";
import { format } from "date-fns";
import { ClockIcon, MailIcon } from "lucide-react";
+import prisma from "@/lib/prisma";
import { generateChecksum } from "@/lib/utils/generate-checksum";
import { verifyJWT } from "@/lib/utils/generate-jwt";
import AcceptInvitationButton from "./AcceptInvitationButton";
+import InvitationStatusContent from "./InvitationStatusContent";
const data = {
description: "Accept your team invitation on Papermark",
@@ -44,7 +46,7 @@ export const metadata: Metadata = {
},
};
-export default function VerifyInvitationPage({
+export default async function VerifyInvitationPage({
searchParams,
}: {
searchParams: {
@@ -70,81 +72,111 @@ export default function VerifyInvitationPage({
if (!verification_url || !teamId || !token || !email) {
return <NotFound />;
}
+ const isExpired = expiresAt ? new Date() > new Date(expiresAt) : false;
+ let isRevoked = false;
+ try {
+ const invitation = await prisma.invitation.findUnique({
+ where: {
+ token: token,
+ },
+ });
+ isRevoked = !invitation;
+ } catch (error) {
+ console.error("Error checking invitation status:", error);
+ }
return (
<div className="flex h-screen w-full flex-wrap">
{/* Left part */}
- <div className="flex w-full justify-center bg-white md:w-1/2 lg:w-2/5">
+ <div className="flex h-full w-full items-center justify-center bg-white md:w-1/2 lg:w-2/5">
<div
className="absolute inset-x-0 top-10 -z-10 flex transform-gpu justify-center overflow-hidden blur-3xl"
aria-hidden="true"
></div>
- <div className="z-10 mx-5 mt-[calc(20vh)] h-fit w-full max-w-md overflow-hidden rounded-lg sm:mx-0">
+ <div className="z-10 mx-auto h-fit w-full max-w-md overflow-hidden rounded-lg">
<div className="flex flex-col items-center justify-center space-y-3 px-4 py-6 pt-8 text-center sm:px-16">
<Link href="/">
<span className="text-balance text-2xl font-semibold text-gray-800">
Welcome to Papermark
</span>
</Link>
- <h3 className="text-balance py-1 text-sm font-normal text-gray-800">
- You&apos;ve been invited to join a team on Papermark
- </h3>
- <div className="mt-2 flex items-center gap-2 rounded-full bg-gray-50 px-4 py-2 text-sm text-gray-600 shadow-sm">
- <MailIcon className="h-4 w-4 text-gray-400" />
- {email}
- </div>
+ {!isExpired && !isRevoked && (
+ <>
+ <h3 className="text-balance py-1 text-sm font-normal text-gray-800">
+ You&apos;ve been invited to join a team on Papermark
+ </h3>
+ <div className="mt-2 flex w-auto items-center justify-center gap-2 rounded-full bg-gray-50 px-5 py-2.5 text-sm text-gray-600 shadow-sm">
+ <MailIcon className="h-4 w-4 text-gray-400" />
+ {email}
+ </div>
+ </>
+ )}
</div>
- <div className="flex flex-col gap-4 px-4 pt-8 sm:px-16">
- <div className="relative">
- <AcceptInvitationButton verificationUrl={verification_url} />
+
+ {isRevoked ? (
+ <div className="px-4 py-6 sm:px-16">
+ <InvitationStatusContent email={email} status="revoked" />
</div>
- {expiresAt ? (
- <div className="text-center text-sm text-gray-500">
- <p className="flex items-center justify-center gap-1.5 rounded-md bg-amber-50 px-3 py-2 text-amber-700">
- <ClockIcon className="h-4 w-4 text-amber-500" />
- <span>
- Expires on{" "}
- <span className="font-medium">
- {format(new Date(expiresAt!), "MMM d, yyyy")}
- </span>{" "}
- at{" "}
- <span className="font-medium">
- {format(new Date(expiresAt!), "h:mm a")}
- </span>
- </span>
- </p>
+ ) : isExpired ? (
+ <div className="px-4 py-6 sm:px-16">
+ <InvitationStatusContent email={email} status="expired" />
+ </div>
+ ) : (
+ <>
+ <div className="flex flex-col gap-4 px-4 pt-8 sm:px-16">
+ <div className="relative">
+ <AcceptInvitationButton verificationUrl={verification_url} />
+ </div>
+ {expiresAt ? (
+ <div className="text-center text-sm text-gray-500">
+ <p className="flex items-center justify-center gap-1.5 rounded-md bg-amber-50 px-3 py-2 text-amber-700">
+ <ClockIcon className="h-4 w-4 text-amber-500" />
+ <span>
+ Expires on{" "}
+ <span className="font-medium">
+ {format(new Date(expiresAt), "MMM d, yyyy")}
+ </span>{" "}
+ at{" "}
+ <span className="font-medium">
+ {format(new Date(expiresAt), "h:mm a")}
+ </span>
+ </span>
+ </p>
+ </div>
+ ) : null}
</div>
- ) : null}
- </div>
- <p className="mt-10 w-full max-w-md px-4 text-xs text-muted-foreground sm:px-16">
- By accepting this invitation, you acknowledge that you have read and
- agree to Papermark&apos;s{" "}
- <a
- href="https://www.papermark.com/terms"
- target="_blank"
- className="underline hover:text-gray-900"
- >
- Terms of Service
- </a>{" "}
- and{" "}
- <a
- href="https://www.papermark.com/privacy"
- target="_blank"
- className="underline hover:text-gray-900"
- >
- Privacy Policy
- </a>
- .
- </p>
+ <p className="mt-10 w-full max-w-md px-4 text-xs text-muted-foreground sm:px-16">
+ By accepting this invitation, you acknowledge that you have read
+ and agree to Papermark&apos;s{" "}
+ <a
+ href="https://www.papermark.com/terms"
+ target="_blank"
+ className="underline hover:text-gray-900"
+ >
+ Terms of Service
+ </a>{" "}
+ and{" "}
+ <a
+ href="https://www.papermark.com/privacy"
+ target="_blank"
+ className="underline hover:text-gray-900"
+ >
+ Privacy Policy
+ </a>
+ .
+ </p>
+ </>
+ )}
</div>
</div>
- <div className="hidden w-full justify-center bg-gray-800 md:flex md:w-1/2 lg:w-3/5">
+ {/* Right part */}
+ <div className="hidden h-full w-full justify-center bg-gray-800 md:flex md:w-1/2 lg:w-3/5">
<div className="flex w-full max-w-5xl px-4 py-20 md:px-8">
<div
className="mx-auto flex w-full max-w-5xl justify-center rounded-3xl bg-gray-800 px-4 py-20 md:px-8"
id="features"
>
- <div className="flex flex-col items-center">
+ <div className="flex flex-col items-center justify-center">
{/* Image container */}
<div className="mb-4 h-64 w-64">
<img
@@ -177,4 +209,4 @@ export default function VerifyInvitationPage({
</div>
</div>
);
-}
+}
\ No newline at end of file
diff --git a/pages/api/teams/[teamId]/invitations/index.ts b/pages/api/teams/[teamId]/invitations/index.ts
index 89a6b039..84b92863 100644
--- a/pages/api/teams/[teamId]/invitations/index.ts
+++ b/pages/api/teams/[teamId]/invitations/index.ts
@@ -15,7 +15,7 @@ export default async function handle(
// GET /api/teams/:teamId/invitations
const session = await getServerSession(req, res, authOptions);
if (!session) {
- return res.status(401).end("Unauhorized");
+ return res.status(401).end("Unauthorized");
}
const { teamId } = req.query as { teamId: string };
@@ -57,7 +57,7 @@ export default async function handle(
// DELETE /api/teams/:teamId/invitations
const session = await getServerSession(req, res, authOptions);
if (!session) {
- return res.status(401).end("Unauhorized");
+ return res.status(401).end("Unauthorized");
}
const { teamId } = req.query as { teamId: string };