The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
added Stats Locked modal
Steven Teyf1cdacb970a8
diff --git a/components/shared/icons/index.tsx b/components/shared/icons/index.tsxindex cd50d430e1..fbe8392c99 100644--- a/components/shared/icons/index.tsx+++ b/components/shared/icons/index.tsx@@ -24,3 +24,4 @@ export { default as Infinity } from "./infinity";export { default as Drag } from "./drag";export { default as Airplay } from "./airplay";export { default as UploadCloud } from "./upload-cloud";+export { default as Lock } from "./lock";diff --git a/components/shared/icons/lock.tsx b/components/shared/icons/lock.tsxnew file mode 100644index 0000000000..16801d9198--- /dev/null+++ b/components/shared/icons/lock.tsx@@ -0,0 +1,19 @@+export default function Lock({ className }: { className: string }) {+ return (+ <svg+ fill="none"+ shapeRendering="geometricPrecision"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ viewBox="0 0 24 24"+ width="24"+ height="24"+ className={className}+ >+ <rect x="3" y="11" width="18" height="11" rx="2" ry="2" />+ <path d="M7 11V7a5 5 0 0110 0v4" />+ </svg>+ );+}diff --git a/lib/auth.ts b/lib/auth.tsindex 89426e4108..7ac7ef47cc 100644--- a/lib/auth.ts+++ b/lib/auth.ts@@ -33,10 +33,12 @@ const withProjectAuth =(handler: WithProjectNextApiHandler,{+ excludeGet, // if the action doesn't need to be gated for GET requestsneedVerifiedDomain, // if the action needs a verified domainneedProSubscription, // if the action needs a pro subscriptionneedNotExceededUsage, // if the action needs the user to not have exceeded their usage}: {+ excludeGet?: boolean;needVerifiedDomain?: boolean;needProSubscription?: boolean;needNotExceededUsage?: boolean;@@ -72,8 +74,10 @@ const withProjectAuth =if (!project) return res.status(404).json({ error: "Project not found" });- if (req.method === "GET") return handler(req, res, project);+ // if the action doesn't need to be gated for GET requests, return handler now+ if (req.method === "GET" && excludeGet) return handler(req, res, project);+ // if the action needs a verified domain, check if the project has one, if not return 403if (needVerifiedDomain && !project.domainVerified) {return res.status(403).json({ error: "Domain not verified." });}diff --git a/pages/api/projects/[slug]/domains/[domain]/links/[key]/stats.ts b/pages/api/projects/[slug]/domains/[domain]/links/[key]/stats.tsindex ad522682b6..b396ab7b37 100644--- a/pages/api/projects/[slug]/domains/[domain]/links/[key]/stats.ts+++ b/pages/api/projects/[slug]/domains/[domain]/links/[key]/stats.ts@@ -35,5 +35,6 @@ export default withProjectAuth(.status(405).json({ error: `Method ${req.method} Not Allowed` });}- }+ },+ { needNotExceededUsage: true });diff --git a/pages/api/projects/[slug]/domains/[domain]/links/index.ts b/pages/api/projects/[slug]/domains/[domain]/links/index.tsindex 8179925b01..0f40c1464b 100644--- a/pages/api/projects/[slug]/domains/[domain]/links/index.ts+++ b/pages/api/projects/[slug]/domains/[domain]/links/index.ts@@ -45,6 +45,7 @@ export default withProjectAuth(}},{+ excludeGet: true,needVerifiedDomain: true,needNotExceededUsage: true,}diff --git a/pages/api/projects/[slug]/domains/[domain]/root/index.ts b/pages/api/projects/[slug]/domains/[domain]/root/index.tsindex 455d5858e1..c77cccbfdf 100644--- a/pages/api/projects/[slug]/domains/[domain]/root/index.ts+++ b/pages/api/projects/[slug]/domains/[domain]/root/index.ts@@ -24,6 +24,7 @@ export default withProjectAuth(}},{+ excludeGet: true,needVerifiedDomain: true,needNotExceededUsage: true,// TODO: For when we make this a pro featurediff --git a/pages/app/[slug]/[key].tsx b/pages/app/[slug]/[key].tsxindex 3fce6fa644..5c62b614f9 100644--- a/pages/app/[slug]/[key].tsx+++ b/pages/app/[slug]/[key].tsx@@ -1,21 +1,53 @@+import Link from "next/link";import Stats from "@/components/stats";+import BlurImage from "@/components/shared/blur-image";+import MaxWidthWrapper from "@/components/shared/max-width-wrapper";+import { Lock } from "@/components/shared/icons";import AppLayout from "@/components/layout/app";-import { useRouter } from "next/router";import useProject from "@/lib/swr/use-project";import ErrorPage from "next/error";+import useUsage from "@/lib/swr/use-usage";export default function StatsPage() {- const router = useRouter();- const { slug } = router.query as {- slug: string;- };-const { project, error } = useProject();+ const { exceededUsage } = useUsage();// handle error pageif (error && error.status === 404) {return <ErrorPage statusCode={404} />;}- return <AppLayout>{project && <Stats domain={project.domain} />}</AppLayout>;+ return (+ <AppLayout>+ {exceededUsage && (+ <MaxWidthWrapper>+ <div className="border border-gray-200 rounded-md bg-white my-10 py-12 flex flex-col justify-center items-center">+ <div className="bg-gray-100 rounded-full p-3">+ <Lock className="w-6 h-6 text-gray-600" />+ </div>+ <h1 className="text-xl font-semibold text-gray-700 my-3">+ Stats Locked+ </h1>+ <p className="text-gray-600 text-sm max-w-sm text-center z-10">+ You have exceeded your usage limits. We're still collecting data+ on your link, but you need to upgrade to view them.+ </p>+ <BlurImage+ src="/static/illustrations/video-park.svg"+ alt="No links yet"+ width={400}+ height={400}+ className="-my-8"+ />+ <Link href="/settings">+ <a className="text-white hover:text-black bg-black hover:bg-white font-medium text-sm px-10 py-2 border rounded-md border-black transition-all duration-75 z-10">+ Upgrade now+ </a>+ </Link>+ </div>+ </MaxWidthWrapper>+ )}+ {project && !exceededUsage && <Stats domain={project.domain} />}+ </AppLayout>+ );}diff --git a/pages/app/index.tsx b/pages/app/index.tsxindex cb314939ae..26816f6ed1 100644--- a/pages/app/index.tsx+++ b/pages/app/index.tsx@@ -22,7 +22,7 @@ export default function App() {<MaxWidthWrapper><div className="flex justify-between items-center"><h1 className="text-2xl text-gray-600">My Projects</h1>- {plan === "Free" && data.length >= 1 ? (+ {plan === "Free" && data?.length >= 1 ? (<Tooltipcontent={<TooltipContent