Skip to content

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

feat: add limits to certain link options

Marc Seitz42ff0793864a
diff --git a/components/links/link-sheet/allow-list-section.tsx b/components/links/link-sheet/allow-list-section.tsx
index 3d8c2459..b0ab195c 100644
--- a/components/links/link-sheet/allow-list-section.tsx
+++ b/components/links/link-sheet/allow-list-section.tsx
@@ -1,4 +1,10 @@
-import { Dispatch, SetStateAction, useState, useEffect, ChangeEvent } from "react";
+import {
+ Dispatch,
+ SetStateAction,
+ useState,
+ useEffect,
+ ChangeEvent,
+} from "react";
import { Switch } from "@/components/ui/switch";
import { motion } from "framer-motion";
import { FADE_IN_ANIMATION_SETTINGS } from "@/lib/constants";
@@ -8,14 +14,23 @@ import { DEFAULT_LINK_TYPE } from ".";
export default function AllowListSection({
data,
setData,
+ hasFreePlan,
+ setOpenUpgradeModal,
}: {
data: DEFAULT_LINK_TYPE;
setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>;
+ hasFreePlan: boolean;
+ setOpenUpgradeModal: Dispatch<SetStateAction<boolean>>;
}) {
const { emailAuthenticated, allowList } = data;
+
// Initialize enabled state based on whether allowList is not null and not empty
- const [enabled, setEnabled] = useState<boolean>(!!allowList && allowList.length > 0);
- const [allowListInput, setAllowListInput] = useState<string>(allowList?.join("\n") || "");
+ const [enabled, setEnabled] = useState<boolean>(
+ !!allowList && allowList.length > 0,
+ );
+ const [allowListInput, setAllowListInput] = useState<string>(
+ allowList?.join("\n") || "",
+ );
useEffect(() => {
// Update the allowList in the data state when their inputs change
@@ -36,7 +51,7 @@ export default function AllowListSection({
...prevData,
allowList: updatedEnabled ? sanitizeAllowDenyList(allowListInput) : [],
emailAuthenticated: true, // Turn on email authentication
- emailProtected: true // Turn on email protection
+ emailProtected: true, // Turn on email protection
}));
} else {
setData((prevData) => ({
@@ -50,7 +65,6 @@ export default function AllowListSection({
setAllowListInput(event.target.value);
};
-
return (
<div className="pb-5">
<div className="flex flex-col space-y-4">
@@ -59,13 +73,22 @@ export default function AllowListSection({
className={cn(
"text-sm font-medium leading-6",
enabled ? "text-foreground" : "text-muted-foreground",
+ hasFreePlan ? "cursor-pointer" : undefined,
)}
+ onClick={hasFreePlan ? () => setOpenUpgradeModal(true) : undefined}
>
Allow specified viewers
+ {hasFreePlan && (
+ <span className="bg-background text-foreground ring-1 ring-gray-800 dark:ring-gray-500 rounded-full px-2 py-0.5 text-xs ml-2">
+ Pro
+ </span>
+ )}
</h2>
<Switch
checked={enabled}
- onCheckedChange={handleEnableAllowList}
+ onClick={hasFreePlan ? () => setOpenUpgradeModal(true) : undefined}
+ className={hasFreePlan ? "opacity-50" : undefined}
+ onCheckedChange={hasFreePlan ? undefined : handleEnableAllowList}
/>
</div>
{enabled && (
diff --git a/components/links/link-sheet/deny-list-section.tsx b/components/links/link-sheet/deny-list-section.tsx
index d296cdd3..bfa7472b 100644
--- a/components/links/link-sheet/deny-list-section.tsx
+++ b/components/links/link-sheet/deny-list-section.tsx
@@ -1,4 +1,10 @@
-import { Dispatch, SetStateAction, useState, useEffect, ChangeEvent } from "react";
+import {
+ Dispatch,
+ SetStateAction,
+ useState,
+ useEffect,
+ ChangeEvent,
+} from "react";
import { Switch } from "@/components/ui/switch";
import { motion } from "framer-motion";
import { FADE_IN_ANIMATION_SETTINGS } from "@/lib/constants";
@@ -8,15 +14,22 @@ import { DEFAULT_LINK_TYPE } from ".";
export default function DenyListSection({
data,
setData,
+ hasFreePlan,
+ setOpenUpgradeModal,
}: {
data: DEFAULT_LINK_TYPE;
setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>;
+ hasFreePlan: boolean;
+ setOpenUpgradeModal: Dispatch<SetStateAction<boolean>>;
}) {
const { emailAuthenticated, denyList } = data;
// Initialize enabled state based on whether denyList is not null and not empty
- const [enabled, setEnabled] = useState<boolean>(!!denyList && denyList.length > 0);
- const [denyListInput, setDenyListInput] = useState<string>(denyList?.join("\n") || "");
-
+ const [enabled, setEnabled] = useState<boolean>(
+ !!denyList && denyList.length > 0,
+ );
+ const [denyListInput, setDenyListInput] = useState<string>(
+ denyList?.join("\n") || "",
+ );
useEffect(() => {
// Update the denyList in the data state when their inputs change
@@ -37,7 +50,7 @@ export default function DenyListSection({
...prevData,
denyList: updatedEnabled ? sanitizeAllowDenyList(denyListInput) : [],
emailAuthenticated: true, // Turn on email authentication
- emailProtected: true // Turn on email protection
+ emailProtected: true, // Turn on email protection
}));
} else {
setData((prevData) => ({
@@ -51,7 +64,6 @@ export default function DenyListSection({
setDenyListInput(event.target.value);
};
-
return (
<div className="pb-5">
<div className="flex flex-col space-y-4">
@@ -60,13 +72,22 @@ export default function DenyListSection({
className={cn(
"text-sm font-medium leading-6",
enabled ? "text-foreground" : "text-muted-foreground",
+ hasFreePlan ? "cursor-pointer" : undefined,
)}
+ onClick={hasFreePlan ? () => setOpenUpgradeModal(true) : undefined}
>
Block specified viewers
+ {hasFreePlan && (
+ <span className="bg-background text-foreground ring-1 ring-gray-800 dark:ring-gray-500 rounded-full px-2 py-0.5 text-xs ml-2">
+ Pro
+ </span>
+ )}
</h2>
<Switch
checked={enabled}
- onCheckedChange={handleEnableDenyList}
+ onClick={hasFreePlan ? () => setOpenUpgradeModal(true) : undefined}
+ className={hasFreePlan ? "opacity-50" : undefined}
+ onCheckedChange={hasFreePlan ? undefined : handleEnableDenyList}
/>
</div>
{enabled && (
diff --git a/components/links/link-sheet/email-authentication-section.tsx b/components/links/link-sheet/email-authentication-section.tsx
index 3eaeb167..9c6fda82 100644
--- a/components/links/link-sheet/email-authentication-section.tsx
+++ b/components/links/link-sheet/email-authentication-section.tsx
@@ -6,9 +6,13 @@ import { DEFAULT_LINK_TYPE } from ".";
export default function EmailAuthenticationSection({
data,
setData,
+ hasFreePlan,
+ setOpenUpgradeModal,
}: {
data: DEFAULT_LINK_TYPE;
setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>;
+ hasFreePlan: boolean;
+ setOpenUpgradeModal: Dispatch<SetStateAction<boolean>>;
}) {
const { emailProtected, emailAuthenticated } = data;
const [enabled, setEnabled] = useState<boolean>(emailAuthenticated);
@@ -37,14 +41,23 @@ export default function EmailAuthenticationSection({
className={cn(
"text-sm font-medium leading-6",
enabled ? "text-foreground" : "text-muted-foreground",
+ hasFreePlan ? "cursor-pointer" : undefined,
)}
+ onClick={hasFreePlan ? () => setOpenUpgradeModal(true) : undefined}
>
Require email verification
+ {hasFreePlan && (
+ <span className="bg-background text-foreground ring-1 ring-gray-800 dark:ring-gray-500 rounded-full px-2 py-0.5 text-xs ml-2">
+ Pro
+ </span>
+ )}
</h2>
</div>
<Switch
checked={enabled}
- onCheckedChange={handleEnableAuthentication}
+ onClick={hasFreePlan ? () => setOpenUpgradeModal(true) : undefined}
+ className={hasFreePlan ? "opacity-50" : undefined}
+ onCheckedChange={hasFreePlan ? undefined : handleEnableAuthentication}
/>
</div>
</div>
diff --git a/components/links/link-sheet/link-options.tsx b/components/links/link-sheet/link-options.tsx
index 4057c80a..cfec65d9 100644
--- a/components/links/link-sheet/link-options.tsx
+++ b/components/links/link-sheet/link-options.tsx
@@ -1,4 +1,4 @@
-import { Dispatch, SetStateAction } from "react";
+import { Dispatch, SetStateAction, useState } from "react";
import { DEFAULT_LINK_TYPE } from "@/components/links/link-sheet";
import EmailProtectionSection from "@/components/links/link-sheet/email-protection-section";
@@ -17,6 +17,8 @@ import DenyListSection from "@/components/links/link-sheet/deny-list-section";
import PasswordSection from "@/components/links/link-sheet/password-section";
import OGSection from "@/components/links/link-sheet/og-section";
import FeedbackSection from "@/components/links/link-sheet/feedback-section";
+import { UpgradePlanModal } from "@/components/billing/upgrade-plan-modal";
+import { usePlan } from "@/lib/swr/use-billing";
export const LinkOptions = ({
data,
@@ -25,12 +27,22 @@ export const LinkOptions = ({
data: DEFAULT_LINK_TYPE;
setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>;
}) => {
+ const { plan } = usePlan();
+ const hasFreePlan = plan?.plan === "free";
+
+ const [openUpgradeModal, setOpenUpgradeModal] = useState<boolean>(false);
+
return (
<div>
<EmailProtectionSection {...{ data, setData }} />
<AllowNotificationSection {...{ data, setData }} />
<AllowDownloadSection {...{ data, setData }} />
<ExpirationSection {...{ data, setData }} />
+ <OGSection
+ {...{ data, setData }}
+ hasFreePlan={hasFreePlan}
+ setOpenUpgradeModal={setOpenUpgradeModal}
+ />
<Accordion type="single" collapsible>
<AccordionItem value="item-1" className="border-none">
@@ -40,15 +52,33 @@ export const LinkOptions = ({
</span>
</AccordionTrigger>
<AccordionContent className="first:pt-5">
- <EmailAuthenticationSection {...{ data, setData }} />
- <AllowListSection {...{ data, setData }} />
- <DenyListSection {...{ data, setData }} />
+ <EmailAuthenticationSection
+ {...{ data, setData }}
+ hasFreePlan={hasFreePlan}
+ setOpenUpgradeModal={setOpenUpgradeModal}
+ />
+ <AllowListSection
+ {...{ data, setData }}
+ hasFreePlan={hasFreePlan}
+ setOpenUpgradeModal={setOpenUpgradeModal}
+ />
+ <DenyListSection
+ {...{ data, setData }}
+ hasFreePlan={hasFreePlan}
+ setOpenUpgradeModal={setOpenUpgradeModal}
+ />
<PasswordSection {...{ data, setData }} />
- <OGSection {...{ data, setData }} />
<FeedbackSection {...{ data, setData }} />
</AccordionContent>
</AccordionItem>
</Accordion>
+ {hasFreePlan ? (
+ <UpgradePlanModal
+ clickedPlan="Pro"
+ open={openUpgradeModal}
+ setOpen={setOpenUpgradeModal}
+ />
+ ) : null}
</div>
);
};
diff --git a/components/links/link-sheet/og-section.tsx b/components/links/link-sheet/og-section.tsx
index deddaccd..f6a8e9d1 100644
--- a/components/links/link-sheet/og-section.tsx
+++ b/components/links/link-sheet/og-section.tsx
@@ -18,9 +18,13 @@ import { Textarea } from "@/components/ui/textarea";
export default function OGSection({
data,
setData,
+ hasFreePlan,
+ setOpenUpgradeModal,
}: {
data: DEFAULT_LINK_TYPE;
setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>;
+ hasFreePlan: boolean;
+ setOpenUpgradeModal: Dispatch<SetStateAction<boolean>>;
}) {
const { enableCustomMetatag, metaTitle, metaDescription, metaImage } = data;
const [enabled, setEnabled] = useState<boolean>(false);
@@ -71,12 +75,24 @@ export default function OGSection({
className={cn(
"text-sm font-medium leading-6",
enabled ? "text-foreground" : "text-muted-foreground",
+ hasFreePlan ? "cursor-pointer" : undefined,
)}
+ onClick={hasFreePlan ? () => setOpenUpgradeModal(true) : undefined}
>
Custom social media cards
+ {hasFreePlan && (
+ <span className="bg-background text-foreground ring-1 ring-gray-800 dark:ring-gray-500 rounded-full px-2 py-0.5 text-xs ml-2">
+ Pro
+ </span>
+ )}
</h2>
</div>
- <Switch checked={enabled} onCheckedChange={handleCustomMetatag} />
+ <Switch
+ checked={enabled}
+ onClick={hasFreePlan ? () => setOpenUpgradeModal(true) : undefined}
+ className={hasFreePlan ? "opacity-50" : undefined}
+ onCheckedChange={hasFreePlan ? undefined : handleCustomMetatag}
+ />
</div>
{enabled && (