Skip to content

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

refactor(link): add link item component to cleanup link options

Marc Seitz110b1e73cd00
diff --git a/components/billing/plan-badge.tsx b/components/billing/plan-badge.tsx
new file mode 100644
index 00000000..73a60cb1
--- /dev/null
+++ b/components/billing/plan-badge.tsx
@@ -0,0 +1,9 @@
+import { CrownIcon } from "lucide-react";
+
+export default function PlanBadge({ plan }: { plan: string }) {
+ return (
+ <span className="ml-2 inline-flex items-center gap-1 rounded-full bg-muted px-2 py-0.5 text-xs uppercase text-gray-700 ring-1 ring-gray-400 hover:bg-gray-200 dark:text-foreground dark:ring-gray-500 hover:dark:bg-gray-700">
+ <CrownIcon className="h-3 w-3" /> {plan}
+ </span>
+ );
+}
diff --git a/components/links/link-sheet/agreement-section.tsx b/components/links/link-sheet/agreement-section.tsx
index cd7c81d3..08e0db7d 100644
--- a/components/links/link-sheet/agreement-section.tsx
+++ b/components/links/link-sheet/agreement-section.tsx
@@ -1,4 +1,4 @@
-import { Dispatch, SetStateAction, useEffect, useState } from "react";
+import { useEffect, useState } from "react";
import { motion } from "framer-motion";
@@ -9,14 +9,14 @@ import {
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
-import { Switch } from "@/components/ui/switch";
import { FADE_IN_ANIMATION_SETTINGS } from "@/lib/constants";
import { useAgreements } from "@/lib/swr/use-agreements";
-import { cn } from "@/lib/utils";
import { DEFAULT_LINK_TYPE } from ".";
import AgreementSheet from "./agreement-panel";
+import LinkItem from "./link-item";
+import { LinkUpgradeOptions } from "./link-options";
export default function AgreementSection({
data,
@@ -25,13 +25,13 @@ export default function AgreementSection({
handleUpgradeStateChange,
}: {
data: DEFAULT_LINK_TYPE;
- setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>;
+ setData: React.Dispatch<React.SetStateAction<DEFAULT_LINK_TYPE>>;
hasFreePlan: boolean;
- handleUpgradeStateChange: (
- state: boolean,
- trigger: string,
- plan?: "Pro" | "Business" | "Data Rooms",
- ) => void;
+ handleUpgradeStateChange: ({
+ state,
+ trigger,
+ plan,
+ }: LinkUpgradeOptions) => void;
}) {
const { agreements } = useAgreements();
const { enableAgreement, agreementId, emailProtected } = data;
@@ -66,52 +66,20 @@ export default function AgreementSection({
return (
<div className="pb-5">
- <div className="flex items-center justify-between">
- <div className="flex items-center justify-between space-x-2">
- <h2
- className={cn(
- "flex items-center gap-x-2 text-sm font-medium leading-6",
- enabled ? "text-foreground" : "text-muted-foreground",
- hasFreePlan ? "cursor-pointer" : undefined,
- )}
- onClick={
- hasFreePlan
- ? () =>
- handleUpgradeStateChange(
- true,
- "link_sheet_agreement_section",
- "Data Rooms",
- )
- : undefined
- }
- >
- Require NDA to view
- {/* <span>
- <HelpCircleIcon className="text-muted-foreground h-4 w-4" />
- </span> */}
- {hasFreePlan && (
- <span className="ml-2 rounded-full bg-background px-2 py-0.5 text-xs text-foreground ring-1 ring-gray-800 dark:ring-gray-500">
- Datarooms
- </span>
- )}
- </h2>
- </div>
- <Switch
- checked={enabled}
- onClick={
- hasFreePlan
- ? () =>
- handleUpgradeStateChange(
- true,
- "link_sheet_agreement_section",
- "Data Rooms",
- )
- : undefined
- }
- className={hasFreePlan ? "opacity-50" : undefined}
- onCheckedChange={hasFreePlan ? undefined : handleAgreement}
- />
- </div>
+ <LinkItem
+ title="Require NDA to view"
+ enabled={enabled}
+ action={handleAgreement}
+ hasFreePlan={hasFreePlan}
+ requiredPlan="datarooms"
+ upgradeAction={() =>
+ handleUpgradeStateChange({
+ state: true,
+ trigger: "link_sheet_agreement_section",
+ plan: "Data Rooms",
+ })
+ }
+ />
{enabled && (
<motion.div
diff --git a/components/links/link-sheet/allow-download-section.tsx b/components/links/link-sheet/allow-download-section.tsx
index cf65af55..12d26843 100644
--- a/components/links/link-sheet/allow-download-section.tsx
+++ b/components/links/link-sheet/allow-download-section.tsx
@@ -1,17 +1,14 @@
-import { Dispatch, SetStateAction, useEffect, useState } from "react";
-
-import { Switch } from "@/components/ui/switch";
-
-import { cn } from "@/lib/utils";
+import { useEffect, useState } from "react";
import { DEFAULT_LINK_TYPE } from ".";
+import LinkItem from "./link-item";
export default function AllowDownloadSection({
data,
setData,
}: {
data: DEFAULT_LINK_TYPE;
- setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>;
+ setData: React.Dispatch<React.SetStateAction<DEFAULT_LINK_TYPE>>;
}) {
const { allowDownload } = data;
const [enabled, setEnabled] = useState<boolean>(false);
@@ -28,19 +25,11 @@ export default function AllowDownloadSection({
return (
<div className="pb-5">
- <div className="flex items-center justify-between">
- <div className="flex items-center justify-between space-x-2">
- <h2
- className={cn(
- "text-sm font-medium leading-6",
- enabled ? "text-foreground" : "text-muted-foreground",
- )}
- >
- Allow downloading
- </h2>
- </div>
- <Switch checked={enabled} onCheckedChange={handleAllowDownload} />
- </div>
+ <LinkItem
+ title="Allow downloading"
+ enabled={enabled}
+ action={handleAllowDownload}
+ />
</div>
);
}
diff --git a/components/links/link-sheet/allow-list-section.tsx b/components/links/link-sheet/allow-list-section.tsx
index c8efad58..2b77501f 100644
--- a/components/links/link-sheet/allow-list-section.tsx
+++ b/components/links/link-sheet/allow-list-section.tsx
@@ -1,19 +1,13 @@
-import {
- ChangeEvent,
- Dispatch,
- SetStateAction,
- useEffect,
- useState,
-} from "react";
+import { useEffect, useState } from "react";
import { motion } from "framer-motion";
-import { Switch } from "@/components/ui/switch";
-
import { FADE_IN_ANIMATION_SETTINGS } from "@/lib/constants";
-import { cn, sanitizeAllowDenyList } from "@/lib/utils";
+import { sanitizeAllowDenyList } from "@/lib/utils";
import { DEFAULT_LINK_TYPE } from ".";
+import LinkItem from "./link-item";
+import { LinkUpgradeOptions } from "./link-options";
export default function AllowListSection({
data,
@@ -22,9 +16,13 @@ export default function AllowListSection({
handleUpgradeStateChange,
}: {
data: DEFAULT_LINK_TYPE;
- setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>;
+ setData: React.Dispatch<React.SetStateAction<DEFAULT_LINK_TYPE>>;
hasFreePlan: boolean;
- handleUpgradeStateChange: (state: boolean, trigger: string) => void;
+ handleUpgradeStateChange: ({
+ state,
+ trigger,
+ plan,
+ }: LinkUpgradeOptions) => void;
}) {
const { emailAuthenticated, allowList } = data;
@@ -65,52 +63,30 @@ export default function AllowListSection({
}
};
- const handleAllowListChange = (event: ChangeEvent<HTMLTextAreaElement>) => {
+ const handleAllowListChange = (
+ event: React.ChangeEvent<HTMLTextAreaElement>,
+ ) => {
setAllowListInput(event.target.value);
};
return (
<div className="pb-5">
<div className="flex flex-col space-y-4">
- <div className="flex items-center justify-between">
- <h2
- className={cn(
- "text-sm font-medium leading-6",
- enabled ? "text-foreground" : "text-muted-foreground",
- hasFreePlan ? "cursor-pointer" : undefined,
- )}
- onClick={
- hasFreePlan
- ? () =>
- handleUpgradeStateChange(
- true,
- "link_sheet_allowlist_section",
- )
- : undefined
- }
- >
- Allow specified viewers
- {hasFreePlan && (
- <span className="ml-2 rounded-full bg-background px-2 py-0.5 text-xs text-foreground ring-1 ring-gray-800 dark:ring-gray-500">
- Pro
- </span>
- )}
- </h2>
- <Switch
- checked={enabled}
- onClick={
- hasFreePlan
- ? () =>
- handleUpgradeStateChange(
- true,
- "link_sheet_allowlist_section",
- )
- : undefined
- }
- className={hasFreePlan ? "opacity-50" : undefined}
- onCheckedChange={hasFreePlan ? undefined : handleEnableAllowList}
- />
- </div>
+ <LinkItem
+ title="Allow specified viewers"
+ enabled={enabled}
+ hasFreePlan={hasFreePlan}
+ action={handleEnableAllowList}
+ requiredPlan="business"
+ upgradeAction={() =>
+ handleUpgradeStateChange({
+ state: true,
+ trigger: "link_sheet_allowlist_section",
+ plan: "Business",
+ })
+ }
+ />
+
{enabled && (
<motion.div
className="mt-1 block w-full"
@@ -119,7 +95,7 @@ export default function AllowListSection({
<textarea
className="form-textarea w-full rounded-md border-0 bg-background py-1.5 text-sm leading-6 text-foreground shadow-sm ring-1 ring-inset ring-input placeholder:text-muted-foreground focus:ring-2 focus:ring-inset focus:ring-gray-400"
rows={5}
- placeholder="Enter allowed emails/domains, one per line, e.g. [email protected] @example.org"
+ placeholder="Enter allowed emails/domains, one per line, e.g. [email protected] @example.org"
value={allowListInput}
onChange={handleAllowListChange}
/>
diff --git a/components/links/link-sheet/allow-notification-section.tsx b/components/links/link-sheet/allow-notification-section.tsx
index d24e2a40..82b0c995 100644
--- a/components/links/link-sheet/allow-notification-section.tsx
+++ b/components/links/link-sheet/allow-notification-section.tsx
@@ -1,17 +1,14 @@
-import { Dispatch, SetStateAction, useEffect, useState } from "react";
-
-import { Switch } from "@/components/ui/switch";
-
-import { cn } from "@/lib/utils";
+import { useEffect, useState } from "react";
import { DEFAULT_LINK_TYPE } from ".";
+import LinkItem from "./link-item";
export default function AllowNotificationSection({
data,
setData,
}: {
data: DEFAULT_LINK_TYPE;
- setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>;
+ setData: React.Dispatch<React.SetStateAction<DEFAULT_LINK_TYPE>>;
}) {
const { enableNotification } = data;
const [enabled, setEnabled] = useState<boolean>(true);
@@ -28,19 +25,11 @@ export default function AllowNotificationSection({
return (
<div className="pb-5">
- <div className="flex items-center justify-between">
- <div className="flex items-center justify-between space-x-2">
- <h2
- className={cn(
- "text-sm font-medium leading-6",
- enabled ? "text-foreground" : "text-muted-foreground",
- )}
- >
- Receive email notification
- </h2>
- </div>
- <Switch checked={enabled} onCheckedChange={handleEnableNotification} />
- </div>
+ <LinkItem
+ title="Receive email notification"
+ enabled={enabled}
+ action={handleEnableNotification}
+ />
</div>
);
}
diff --git a/components/links/link-sheet/deny-list-section.tsx b/components/links/link-sheet/deny-list-section.tsx
index 39f8c684..3f97c671 100644
--- a/components/links/link-sheet/deny-list-section.tsx
+++ b/components/links/link-sheet/deny-list-section.tsx
@@ -1,19 +1,13 @@
-import {
- ChangeEvent,
- Dispatch,
- SetStateAction,
- useEffect,
- useState,
-} from "react";
+import { useEffect, useState } from "react";
import { motion } from "framer-motion";
-import { Switch } from "@/components/ui/switch";
-
import { FADE_IN_ANIMATION_SETTINGS } from "@/lib/constants";
-import { cn, sanitizeAllowDenyList } from "@/lib/utils";
+import { sanitizeAllowDenyList } from "@/lib/utils";
import { DEFAULT_LINK_TYPE } from ".";
+import LinkItem from "./link-item";
+import { LinkUpgradeOptions } from "./link-options";
export default function DenyListSection({
data,
@@ -22,9 +16,13 @@ export default function DenyListSection({
handleUpgradeStateChange,
}: {
data: DEFAULT_LINK_TYPE;
- setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>;
+ setData: React.Dispatch<React.SetStateAction<DEFAULT_LINK_TYPE>>;
hasFreePlan: boolean;
- handleUpgradeStateChange: (state: boolean, trigger: string) => void;
+ handleUpgradeStateChange: ({
+ state,
+ trigger,
+ plan,
+ }: LinkUpgradeOptions) => void;
}) {
const { emailAuthenticated, denyList } = data;
// Initialize enabled state based on whether denyList is not null and not empty
@@ -64,52 +62,30 @@ export default function DenyListSection({
}
};
- const handleDenyListChange = (event: ChangeEvent<HTMLTextAreaElement>) => {
+ const handleDenyListChange = (
+ event: React.ChangeEvent<HTMLTextAreaElement>,
+ ) => {
setDenyListInput(event.target.value);
};
return (
<div className="pb-5">
<div className="flex flex-col space-y-4">
- <div className="flex items-center justify-between">
- <h2
- className={cn(
- "text-sm font-medium leading-6",
- enabled ? "text-foreground" : "text-muted-foreground",
- hasFreePlan ? "cursor-pointer" : undefined,
- )}
- onClick={
- hasFreePlan
- ? () =>
- handleUpgradeStateChange(
- true,
- "link_sheet_denylist_section",
- )
- : undefined
- }
- >
- Block specified viewers
- {hasFreePlan && (
- <span className="ml-2 rounded-full bg-background px-2 py-0.5 text-xs text-foreground ring-1 ring-gray-800 dark:ring-gray-500">
- Pro
- </span>
- )}
- </h2>
- <Switch
- checked={enabled}
- onClick={
- hasFreePlan
- ? () =>
- handleUpgradeStateChange(
- true,
- "link_sheet_denylist_section",
- )
- : undefined
- }
- className={hasFreePlan ? "opacity-50" : undefined}
- onCheckedChange={hasFreePlan ? undefined : handleEnableDenyList}
- />
- </div>
+ <LinkItem
+ title="Block specified viewers"
+ enabled={enabled}
+ action={handleEnableDenyList}
+ hasFreePlan={hasFreePlan}
+ requiredPlan="business"
+ upgradeAction={() =>
+ handleUpgradeStateChange({
+ state: true,
+ trigger: "link_sheet_denylist_section",
+ plan: "Business",
+ })
+ }
+ />
+
{enabled && (
<motion.div
className="mt-1 block w-full"
@@ -118,7 +94,7 @@ export default function DenyListSection({
<textarea
className="form-textarea w-full rounded-md border-0 bg-background py-1.5 text-sm leading-6 text-foreground shadow-sm ring-1 ring-inset ring-input placeholder:text-muted-foreground focus:ring-2 focus:ring-inset focus:ring-gray-400"
rows={5}
- placeholder="Enter blocked emails/domains, one per line, e.g. [email protected] @example.org"
+ placeholder="Enter blocked emails/domains, one per line, e.g. [email protected] @example.org"
value={denyListInput}
onChange={handleDenyListChange}
/>
diff --git a/components/links/link-sheet/email-authentication-section.tsx b/components/links/link-sheet/email-authentication-section.tsx
index 392146dd..8c07061b 100644
--- a/components/links/link-sheet/email-authentication-section.tsx
+++ b/components/links/link-sheet/email-authentication-section.tsx
@@ -1,10 +1,8 @@
-import { Dispatch, SetStateAction, useEffect, useState } from "react";
-
-import { Switch } from "@/components/ui/switch";
-
-import { cn } from "@/lib/utils";
+import { useEffect, useState } from "react";
import { DEFAULT_LINK_TYPE } from ".";
+import LinkItem from "./link-item";
+import { LinkUpgradeOptions } from "./link-options";
export default function EmailAuthenticationSection({
data,
@@ -13,9 +11,13 @@ export default function EmailAuthenticationSection({
handleUpgradeStateChange,
}: {
data: DEFAULT_LINK_TYPE;
- setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>;
+ setData: React.Dispatch<React.SetStateAction<DEFAULT_LINK_TYPE>>;
hasFreePlan: boolean;
- handleUpgradeStateChange: (state: boolean, trigger: string) => void;
+ handleUpgradeStateChange: ({
+ state,
+ trigger,
+ plan,
+ }: LinkUpgradeOptions) => void;
}) {
const { emailProtected, emailAuthenticated } = data;
const [enabled, setEnabled] = useState<boolean>(emailAuthenticated);
@@ -38,47 +40,20 @@ export default function EmailAuthenticationSection({
return (
<div className="pb-5">
- <div className="flex items-center justify-between">
- <div className="flex items-center justify-between space-x-2">
- <h2
- className={cn(
- "text-sm font-medium leading-6",
- enabled ? "text-foreground" : "text-muted-foreground",
- hasFreePlan ? "cursor-pointer" : undefined,
- )}
- onClick={
- hasFreePlan
- ? () =>
- handleUpgradeStateChange(
- true,
- "link_sheet_email_auth_section",
- )
- : undefined
- }
- >
- Require email verification
- {hasFreePlan && (
- <span className="ml-2 rounded-full bg-background px-2 py-0.5 text-xs text-foreground ring-1 ring-gray-800 dark:ring-gray-500">
- Pro
- </span>
- )}
- </h2>
- </div>
- <Switch
- checked={enabled}
- onClick={
- hasFreePlan
- ? () =>
- handleUpgradeStateChange(
- true,
- "link_sheet_email_auth_section",
- )
- : undefined
- }
- className={hasFreePlan ? "opacity-50" : undefined}
- onCheckedChange={hasFreePlan ? undefined : handleEnableAuthentication}
- />
- </div>
+ <LinkItem
+ title="Require email verification"
+ enabled={enabled}
+ action={handleEnableAuthentication}
+ hasFreePlan={hasFreePlan}
+ requiredPlan="pro"
+ upgradeAction={() =>
+ handleUpgradeStateChange({
+ state: true,
+ trigger: "link_sheet_email_auth_section",
+ plan: "Pro",
+ })
+ }
+ />
</div>
);
}
diff --git a/components/links/link-sheet/email-protection-section.tsx b/components/links/link-sheet/email-protection-section.tsx
index aa64ae87..6e11bc1d 100644
--- a/components/links/link-sheet/email-protection-section.tsx
+++ b/components/links/link-sheet/email-protection-section.tsx
@@ -1,17 +1,14 @@
-import { Dispatch, SetStateAction, useEffect, useState } from "react";
-
-import { Switch } from "@/components/ui/switch";
-
-import { cn } from "@/lib/utils";
+import { useEffect, useState } from "react";
import { DEFAULT_LINK_TYPE } from ".";
+import LinkItem from "./link-item";
export default function EmailProtectionSection({
data,
setData,
}: {
data: DEFAULT_LINK_TYPE;
- setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>;
+ setData: React.Dispatch<React.SetStateAction<DEFAULT_LINK_TYPE>>;
}) {
const { emailProtected } = data;
const [enabled, setEnabled] = useState<boolean>(emailProtected);
@@ -33,19 +30,11 @@ export default function EmailProtectionSection({
return (
<div className="pb-5">
- <div className="flex items-center justify-between">
- <div className="flex items-center justify-between space-x-2">
- <h2
- className={cn(
- "text-sm font-medium leading-6",
- enabled ? "text-foreground" : "text-muted-foreground",
- )}
- >
- Require email to view
- </h2>
- </div>
- <Switch checked={enabled} onCheckedChange={handleEnableProtection} />
- </div>
+ <LinkItem
+ title="Require email to view"
+ enabled={enabled}
+ action={handleEnableProtection}
+ />
</div>
);
}
diff --git a/components/links/link-sheet/expiration-section.tsx b/components/links/link-sheet/expiration-section.tsx
index 4043ea1b..8e1d8aaa 100644
--- a/components/links/link-sheet/expiration-section.tsx
+++ b/components/links/link-sheet/expiration-section.tsx
@@ -1,20 +1,19 @@
-import { Dispatch, SetStateAction, useEffect, useState } from "react";
+import { useEffect, useState } from "react";
import { motion } from "framer-motion";
-import { Switch } from "@/components/ui/switch";
-
import { FADE_IN_ANIMATION_SETTINGS } from "@/lib/constants";
-import { cn, getDateTimeLocal } from "@/lib/utils";
+import { getDateTimeLocal } from "@/lib/utils";
import { DEFAULT_LINK_TYPE } from ".";
+import LinkItem from "./link-item";
export default function ExpirationSection({
data,
setData,
}: {
data: DEFAULT_LINK_TYPE;
- setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>;
+ setData: React.Dispatch<React.SetStateAction<DEFAULT_LINK_TYPE>>;
}) {
const { expiresAt } = data;
const [enabled, setEnabled] = useState<boolean>(false);
@@ -33,19 +32,12 @@ export default function ExpirationSection({
return (
<div className="pb-5">
- <div className="flex items-center justify-between">
- <div className="flex items-center justify-between space-x-2">
- <h2
- className={cn(
- "text-sm font-medium leading-6",
- enabled ? "text-foreground" : "text-muted-foreground",
- )}
- >
- Expiration Date
- </h2>
- </div>
- <Switch checked={enabled} onCheckedChange={handleEnableExpiration} />
- </div>
+ <LinkItem
+ title="Expiration Date"
+ enabled={enabled}
+ action={handleEnableExpiration}
+ />
+
{enabled && (
<motion.div className="mt-3" {...FADE_IN_ANIMATION_SETTINGS}>
<input
diff --git a/components/links/link-sheet/feedback-section.tsx b/components/links/link-sheet/feedback-section.tsx
index f8d390e6..3bdb0181 100644
--- a/components/links/link-sheet/feedback-section.tsx
+++ b/components/links/link-sheet/feedback-section.tsx
@@ -1,17 +1,14 @@
-import { Dispatch, SetStateAction, useEffect, useState } from "react";
-
-import { Switch } from "@/components/ui/switch";
-
-import { cn } from "@/lib/utils";
+import { useEffect, useState } from "react";
import { DEFAULT_LINK_TYPE } from ".";
+import LinkItem from "./link-item";
export default function FeedbackSection({
data,
setData,
}: {
data: DEFAULT_LINK_TYPE;
- setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>;
+ setData: React.Dispatch<React.SetStateAction<DEFAULT_LINK_TYPE>>;
}) {
const { enableFeedback } = data;
const [enabled, setEnabled] = useState<boolean>(true);
@@ -28,19 +25,11 @@ export default function FeedbackSection({
return (
<div className="pb-5">
- <div className="flex items-center justify-between">
- <div className="flex items-center justify-between space-x-2">
- <h2
- className={cn(
- "text-sm font-medium leading-6",
- enabled ? "text-foreground" : "text-muted-foreground",
- )}
- >
- Receive feedback from visitors
- </h2>
- </div>
- <Switch checked={enabled} onCheckedChange={handleEnableFeedback} />
- </div>
+ <LinkItem
+ title="Enable feedback from visitors"
+ enabled={enabled}
+ action={handleEnableFeedback}
+ />
</div>
);
}
diff --git a/components/links/link-sheet/link-item.tsx b/components/links/link-sheet/link-item.tsx
new file mode 100644
index 00000000..cbe617c6
--- /dev/null
+++ b/components/links/link-sheet/link-item.tsx
@@ -0,0 +1,45 @@
+import PlanBadge from "@/components/billing/plan-badge";
+import { Switch } from "@/components/ui/switch";
+
+import { cn } from "@/lib/utils";
+
+import { LinkUpgradeOptions } from "./link-options";
+
+export default function LinkItem({
+ title,
+ enabled,
+ action,
+ hasFreePlan,
+ requiredPlan,
+ upgradeAction,
+}: {
+ title: string;
+ enabled: boolean;
+ action: () => void;
+ hasFreePlan?: boolean;
+ requiredPlan?: string;
+ upgradeAction?: () => void;
+}) {
+ return (
+ <div className="flex items-center justify-between">
+ <div className="flex items-center justify-between space-x-2">
+ <h2
+ className={cn(
+ "cursor-pointer text-sm font-medium leading-6",
+ enabled ? "text-foreground" : "text-muted-foreground",
+ )}
+ onClick={hasFreePlan ? () => upgradeAction?.() : action}
+ >
+ {title}
+ {hasFreePlan && requiredPlan && <PlanBadge plan={requiredPlan} />}
+ </h2>
+ </div>
+ <Switch
+ checked={enabled}
+ onClick={hasFreePlan ? () => upgradeAction?.() : undefined}
+ className={hasFreePlan ? "opacity-50" : undefined}
+ onCheckedChange={hasFreePlan ? undefined : action}
+ />
+ </div>
+ );
+}
diff --git a/components/links/link-sheet/og-section.tsx b/components/links/link-sheet/og-section.tsx
index 00eb6a4d..fc09343f 100644
--- a/components/links/link-sheet/og-section.tsx
+++ b/components/links/link-sheet/og-section.tsx
@@ -1,23 +1,17 @@
-import {
- Dispatch,
- SetStateAction,
- useCallback,
- useEffect,
- useState,
-} from "react";
+import { useCallback, useEffect, useState } from "react";
import { motion } from "framer-motion";
import { Upload as ArrowUpTrayIcon } from "lucide-react";
import { Input } from "@/components/ui/input";
import LoadingSpinner from "@/components/ui/loading-spinner";
-import { Switch } from "@/components/ui/switch";
import { Textarea } from "@/components/ui/textarea";
import { FADE_IN_ANIMATION_SETTINGS } from "@/lib/constants";
-import { cn } from "@/lib/utils";
import { DEFAULT_LINK_TYPE } from ".";
+import LinkItem from "./link-item";
+import { LinkUpgradeOptions } from "./link-options";
export default function OGSection({
data,
@@ -26,9 +20,13 @@ export default function OGSection({
handleUpgradeStateChange,
}: {
data: DEFAULT_LINK_TYPE;
- setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>;
+ setData: React.Dispatch<React.SetStateAction<DEFAULT_LINK_TYPE>>;
hasFreePlan: boolean;
- handleUpgradeStateChange: (state: boolean, trigger: string) => void;
+ handleUpgradeStateChange: ({
+ state,
+ trigger,
+ plan,
+ }: LinkUpgradeOptions) => void;
}) {
const { enableCustomMetatag, metaTitle, metaDescription, metaImage } = data;
const [enabled, setEnabled] = useState<boolean>(false);
@@ -73,39 +71,20 @@ export default function OGSection({
return (
<div className="pb-5">
- <div className="flex items-center justify-between">
- <div className="flex items-center justify-between space-x-2">
- <h2
- className={cn(
- "text-sm font-medium leading-6",
- enabled ? "text-foreground" : "text-muted-foreground",
- hasFreePlan ? "cursor-pointer" : undefined,
- )}
- onClick={
- hasFreePlan
- ? () => handleUpgradeStateChange(true, "link_sheet_og_section")
- : undefined
- }
- >
- Custom social media cards
- {hasFreePlan && (
- <span className="ml-2 rounded-full bg-background px-2 py-0.5 text-xs text-foreground ring-1 ring-gray-800 dark:ring-gray-500">
- Pro
- </span>
- )}
- </h2>
- </div>
- <Switch
- checked={enabled}
- onClick={
- hasFreePlan
- ? () => handleUpgradeStateChange(true, "link_sheet_og_section")
- : undefined
- }
- className={hasFreePlan ? "opacity-50" : undefined}
- onCheckedChange={hasFreePlan ? undefined : handleCustomMetatag}
- />
- </div>
+ <LinkItem
+ title="Custom social media cards"
+ enabled={enableCustomMetatag}
+ action={handleCustomMetatag}
+ hasFreePlan={hasFreePlan}
+ requiredPlan="Business"
+ upgradeAction={() =>
+ handleUpgradeStateChange({
+ state: true,
+ trigger: "link_sheet_og_section",
+ plan: "Business",
+ })
+ }
+ />
{enabled && (
<motion.div
diff --git a/components/links/link-sheet/password-section.tsx b/components/links/link-sheet/password-section.tsx
index 4d5e0b1b..92eee347 100644
--- a/components/links/link-sheet/password-section.tsx
+++ b/components/links/link-sheet/password-section.tsx
@@ -1,22 +1,21 @@
-import { Dispatch, SetStateAction, useEffect, useState } from "react";
+import { useEffect, useState } from "react";
import { motion } from "framer-motion";
import Eye from "@/components/shared/icons/eye";
import EyeOff from "@/components/shared/icons/eye-off";
-import { Switch } from "@/components/ui/switch";
import { FADE_IN_ANIMATION_SETTINGS } from "@/lib/constants";
-import { cn } from "@/lib/utils";
import { DEFAULT_LINK_TYPE } from ".";
+import LinkItem from "./link-item";
export default function PasswordSection({
data,
setData,
}: {
data: DEFAULT_LINK_TYPE;
- setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>;
+ setData: React.Dispatch<React.SetStateAction<DEFAULT_LINK_TYPE>>;
}) {
const { password } = data;
const [enabled, setEnabled] = useState<boolean>(false);
@@ -36,19 +35,12 @@ export default function PasswordSection({
return (
<div className="pb-5">
- <div className="flex items-center justify-between">
- <div className="flex items-center justify-between space-x-2">
- <h2
- className={cn(
- "text-sm font-medium leading-6",
- enabled ? "text-foreground" : "text-muted-foreground",
- )}
- >
- Require password to view
- </h2>
- </div>
- <Switch checked={enabled} onCheckedChange={handleEnablePassword} />
- </div>
+ <LinkItem
+ title="Require password to view"
+ enabled={enabled}
+ action={handleEnablePassword}
+ />
+
{enabled && (
<motion.div
className="relative mt-4 rounded-md shadow-sm"
diff --git a/components/links/link-sheet/question-section.tsx b/components/links/link-sheet/question-section.tsx
index d21bea2f..8dbd6ddf 100644
--- a/components/links/link-sheet/question-section.tsx
+++ b/components/links/link-sheet/question-section.tsx
@@ -1,21 +1,9 @@
-import {
- Dispatch,
- SetStateAction,
- useCallback,
- useEffect,
- useState,
-} from "react";
+import { useEffect, useState } from "react";
import { motion } from "framer-motion";
-import {
- Upload as ArrowUpTrayIcon,
- BadgeInfoIcon,
- HelpCircleIcon,
-} from "lucide-react";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
-import LoadingSpinner from "@/components/ui/loading-spinner";
import {
Select,
SelectContent,
@@ -23,13 +11,12 @@ import {
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
-import { Switch } from "@/components/ui/switch";
-import { Textarea } from "@/components/ui/textarea";
import { FADE_IN_ANIMATION_SETTINGS } from "@/lib/constants";
-import { cn } from "@/lib/utils";
import { DEFAULT_LINK_TYPE } from ".";
+import LinkItem from "./link-item";
+import { LinkUpgradeOptions } from "./link-options";
export default function QuestionSection({
data,
@@ -38,13 +25,13 @@ export default function QuestionSection({
handleUpgradeStateChange,
}: {
data: DEFAULT_LINK_TYPE;
- setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>;
+ setData: React.Dispatch<React.SetStateAction<DEFAULT_LINK_TYPE>>;
hasFreePlan: boolean;
- handleUpgradeStateChange: (
- state: boolean,
- trigger: string,
- plan?: "Pro" | "Business" | "Data Rooms",
- ) => void;
+ handleUpgradeStateChange: ({
+ state,
+ trigger,
+ plan,
+ }: LinkUpgradeOptions) => void;
}) {
const { enableQuestion, questionText, questionType } = data;
const [enabled, setEnabled] = useState<boolean>(false);
@@ -62,52 +49,20 @@ export default function QuestionSection({
return (
<div className="pb-5">
- <div className="flex items-center justify-between">
- <div className="flex items-center justify-between space-x-2">
- <h2
- className={cn(
- "flex items-center gap-x-2 text-sm font-medium leading-6",
- enabled ? "text-foreground" : "text-muted-foreground",
- hasFreePlan ? "cursor-pointer" : undefined,
- )}
- onClick={
- hasFreePlan
- ? () =>
- handleUpgradeStateChange(
- true,
- "link_sheet_question_section",
- "Business",
- )
- : undefined
- }
- >
- Feedback Question
- {/* <span>
- <HelpCircleIcon className="text-muted-foreground h-4 w-4" />
- </span> */}
- {hasFreePlan && (
- <span className="ml-2 rounded-full bg-background px-2 py-0.5 text-xs text-foreground ring-1 ring-gray-800 dark:ring-gray-500">
- Business
- </span>
- )}
- </h2>
- </div>
- <Switch
- checked={enabled}
- onClick={
- hasFreePlan
- ? () =>
- handleUpgradeStateChange(
- true,
- "link_sheet_question_section",
- "Business",
- )
- : undefined
- }
- className={hasFreePlan ? "opacity-50" : undefined}
- onCheckedChange={hasFreePlan ? undefined : handleQuestion}
- />
- </div>
+ <LinkItem
+ title="Feedback Question"
+ enabled={enabled}
+ action={handleQuestion}
+ hasFreePlan={hasFreePlan}
+ requiredPlan="business"
+ upgradeAction={() =>
+ handleUpgradeStateChange({
+ state: true,
+ trigger: "link_sheet_question_section",
+ plan: "Business",
+ })
+ }
+ />
{enabled && (
<motion.div
diff --git a/components/links/link-sheet/screenshot-protection-section.tsx b/components/links/link-sheet/screenshot-protection-section.tsx
index bf703b2c..1cd0d85c 100644
--- a/components/links/link-sheet/screenshot-protection-section.tsx
+++ b/components/links/link-sheet/screenshot-protection-section.tsx
@@ -1,10 +1,8 @@
-import { Dispatch, SetStateAction, useEffect, useState } from "react";
-
-import { Switch } from "@/components/ui/switch";
-
-import { cn } from "@/lib/utils";
+import { useEffect, useState } from "react";
import { DEFAULT_LINK_TYPE } from ".";
+import LinkItem from "./link-item";
+import { LinkUpgradeOptions } from "./link-options";
export default function ScreenshotProtectionSection({
data,
@@ -13,13 +11,13 @@ export default function ScreenshotProtectionSection({
handleUpgradeStateChange,
}: {
data: DEFAULT_LINK_TYPE;
- setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>;
+ setData: React.Dispatch<React.SetStateAction<DEFAULT_LINK_TYPE>>;
hasFreePlan: boolean;
- handleUpgradeStateChange: (
- state: boolean,
- trigger: string,
- plan?: "Pro" | "Business",
- ) => void;
+ handleUpgradeStateChange: ({
+ state,
+ trigger,
+ plan,
+ }: LinkUpgradeOptions) => void;
}) {
const { enableScreenshotProtection } = data;
const [enabled, setEnabled] = useState<boolean>(true);
@@ -39,51 +37,20 @@ export default function ScreenshotProtectionSection({
return (
<div className="pb-5">
- <div className="flex items-center justify-between">
- <div className="flex items-center justify-between space-x-2">
- <h2
- className={cn(
- "text-sm font-medium leading-6",
- enabled ? "text-foreground" : "text-muted-foreground",
- hasFreePlan ? "cursor-pointer" : undefined,
- )}
- onClick={
- hasFreePlan
- ? () =>
- handleUpgradeStateChange(
- true,
- "link_sheet_screenshot_protection_section",
- "Business",
- )
- : undefined
- }
- >
- Enable screenshot protection*
- {hasFreePlan && (
- <span className="ml-2 rounded-full bg-background px-2 py-0.5 text-xs text-foreground ring-1 ring-gray-800 dark:ring-gray-500">
- Business
- </span>
- )}
- </h2>
- </div>
- <Switch
- checked={enabled}
- onClick={
- hasFreePlan
- ? () =>
- handleUpgradeStateChange(
- true,
- "link_sheet_screenshot_protection_section",
- "Business",
- )
- : undefined
- }
- className={hasFreePlan ? "opacity-50" : undefined}
- onCheckedChange={
- hasFreePlan ? undefined : handleEnableScreenshotProtection
- }
- />
- </div>
+ <LinkItem
+ title="Enable screenshot protection"
+ enabled={enabled}
+ action={handleEnableScreenshotProtection}
+ hasFreePlan={hasFreePlan}
+ requiredPlan="business"
+ upgradeAction={() =>
+ handleUpgradeStateChange({
+ state: true,
+ trigger: "link_sheet_screenshot_protection_section",
+ plan: "Business",
+ })
+ }
+ />
</div>
);
}