Skip to content

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

feat(plan): update plan to include dataroom trial

Marc Seitz4792c485d62d
diff --git a/components/Sidebar.tsx b/components/Sidebar.tsx
index cf72dcc6..7c1422af 100644
--- a/components/Sidebar.tsx
+++ b/components/Sidebar.tsx
@@ -63,7 +63,7 @@ export default function Sidebar() {
export const SidebarComponent = ({ className }: { className?: string }) => {
const [showProBanner, setShowProBanner] = useState<boolean | null>(null);
const { data: session, status } = useSession();
- const { plan, loading } = usePlan();
+ const { plan, trial: userTrial, loading } = usePlan();
const router = useRouter();
const { currentTeam, teams, isLoading }: TeamContextType =
@@ -77,7 +77,7 @@ export const SidebarComponent = ({ className }: { className?: string }) => {
}
}, []);
- const userPlan = plan && plan.plan;
+ const userPlan = plan;
const navigation = [
// {
@@ -110,7 +110,8 @@ export const SidebarComponent = ({ className }: { className?: string }) => {
icon: ServerIcon,
current: router.pathname.includes("datarooms"),
active: false,
- disabled: userPlan === "business" ? false : true,
+ disabled:
+ userPlan === "business" || userTrial === "drtrial" ? false : true,
},
{
name: "Branding",
@@ -210,7 +211,11 @@ export const SidebarComponent = ({ className }: { className?: string }) => {
</div>
);
}
- if (userPlan !== "business" && item.name === "Datarooms") {
+ if (
+ userPlan !== "business" &&
+ userTrial !== "drtrial" &&
+ item.name === "Datarooms"
+ ) {
return (
<UpgradePlanModal
key={item.name}
diff --git a/components/chat/chat.tsx b/components/chat/chat.tsx
index a0f64fb9..18def189 100644
--- a/components/chat/chat.tsx
+++ b/components/chat/chat.tsx
@@ -12,6 +12,7 @@ import { ChatScrollAnchor } from "./chat-scroll-anchor";
import { EmptyScreen } from "./empty-screen";
import { useEffect, useState } from "react";
import { nanoid } from "nanoid";
+import { BasePlan } from "@/lib/swr/use-billing";
export interface ChatProps extends React.ComponentProps<"div"> {
initialMessages: Message[];
@@ -19,7 +20,7 @@ export interface ChatProps extends React.ComponentProps<"div"> {
firstPage?: string;
isPublic?: boolean;
userId?: string;
- plan?: string;
+ plan?: BasePlan | null;
}
export function Chat({
diff --git a/components/datarooms/add-dataroom-modal.tsx b/components/datarooms/add-dataroom-modal.tsx
index 006eab20..8503bb34 100644
--- a/components/datarooms/add-dataroom-modal.tsx
+++ b/components/datarooms/add-dataroom-modal.tsx
@@ -71,7 +71,7 @@ export function AddDataroomModal({ children }: { children?: React.ReactNode }) {
};
// If the team is on a free plan, show the upgrade modal
- if (plan && plan.plan === "free") {
+ if (plan === "free") {
if (children) {
return (
<UpgradePlanModal clickedPlan="Pro" trigger={"add_dataroom_overview"}>
diff --git a/components/document-upload.tsx b/components/document-upload.tsx
index c886327e..a35a4331 100644
--- a/components/document-upload.tsx
+++ b/components/document-upload.tsx
@@ -41,7 +41,7 @@ export default function DocumentUpload({
setCurrentFile: React.Dispatch<React.SetStateAction<File | null>>;
}) {
const { plan, loading } = usePlan();
- const maxSize = plan?.plan === "pro" ? 100 : 30;
+ const maxSize = plan === "pro" ? 100 : 30;
const { getRootProps, getInputProps } = useDropzone({
accept: {
"application/pdf": [], // ".pdf"
diff --git a/components/domains/add-domain-modal.tsx b/components/domains/add-domain-modal.tsx
index 3e828dbd..bc8a35cd 100644
--- a/components/domains/add-domain-modal.tsx
+++ b/components/domains/add-domain-modal.tsx
@@ -79,7 +79,7 @@ export function AddDomainModal({
};
// If the team is on a free plan, show the upgrade modal
- if (plan && plan.plan === "free") {
+ if (plan === "free") {
if (children) {
return (
<UpgradePlanModal clickedPlan="Pro" trigger={"add_domain_overview"}>
diff --git a/components/folders/add-folder-modal.tsx b/components/folders/add-folder-modal.tsx
index 6a6a35d7..8f1800a8 100644
--- a/components/folders/add-folder-modal.tsx
+++ b/components/folders/add-folder-modal.tsx
@@ -102,7 +102,7 @@ export function AddFolderModal({
};
// If the team is on a free plan, show the upgrade modal
- if (plan && plan.plan === "free") {
+ if (plan === "free") {
if (children) {
return (
<UpgradePlanModal clickedPlan="Pro" trigger={"add_folder_button"}>
diff --git a/components/links/link-sheet/link-options.tsx b/components/links/link-sheet/link-options.tsx
index 34b64657..444bf394 100644
--- a/components/links/link-sheet/link-options.tsx
+++ b/components/links/link-sheet/link-options.tsx
@@ -30,8 +30,8 @@ export const LinkOptions = ({
setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>;
}) => {
const { plan } = usePlan();
- const hasFreePlan = plan?.plan === "free";
- const isNotBusiness = plan?.plan !== "business";
+ const hasFreePlan = plan === "free";
+ const isNotBusiness = plan !== "business";
const [openUpgradeModal, setOpenUpgradeModal] = useState<boolean>(false);
const [trigger, setTrigger] = useState<string>("");
diff --git a/components/links/links-table.tsx b/components/links/links-table.tsx
index c365c9c4..ddaebf38 100644
--- a/components/links/links-table.tsx
+++ b/components/links/links-table.tsx
@@ -145,7 +145,7 @@ export default function LinksTable({
? links.filter((link) => link.isArchived).length
: 0;
- const hasFreePlan = plan && plan.plan === "free";
+ const hasFreePlan = plan === "free";
console.log("links", links);
diff --git a/components/visitors/visitors-table.tsx b/components/visitors/visitors-table.tsx
index 3d0bc0b2..cfb1bfcf 100644
--- a/components/visitors/visitors-table.tsx
+++ b/components/visitors/visitors-table.tsx
@@ -49,7 +49,7 @@ export default function VisitorsTable({ numPages }: { numPages: number }) {
const { views, loading, error } = useDocumentVisits(currentPage, limit);
const { plan } = usePlan();
- const isFreePlan = plan?.plan === "free";
+ const isFreePlan = plan === "free";
return (
<div className="w-full">
diff --git a/lib/swr/use-billing.ts b/lib/swr/use-billing.ts
index a8e74621..5c71769d 100644
--- a/lib/swr/use-billing.ts
+++ b/lib/swr/use-billing.ts
@@ -3,6 +3,7 @@ import useSWR from "swr";
import { fetcher } from "@/lib/utils";
import { useMemo } from "react";
import { useTeam } from "@/context/team-context";
+import { parse } from "path";
interface BillingProps {
id: string;
@@ -33,8 +34,27 @@ export function useBilling() {
};
}
-interface PlanResponse {
- plan: "free" | "starter" | "pro" | "trial" | "business";
+export type BasePlan = "free" | "starter" | "pro" | "trial" | "business";
+type PlanWithTrial = `${BasePlan}+drtrial`;
+
+type PlanResponse = {
+ plan: BasePlan | PlanWithTrial;
+};
+
+interface PlanDetails {
+ plan: BasePlan | null;
+ trial: string | null;
+}
+
+function parsePlan(plan: BasePlan | PlanWithTrial): PlanDetails {
+ if (!plan) return { plan: null, trial: null };
+
+ // Split the plan on '+'
+ const parts = plan.split("+");
+ return {
+ plan: parts[0] as BasePlan, // Always the base plan
+ trial: parts.length > 1 ? parts[1] : null, // 'drtrial' if present, otherwise null
+ };
}
export function usePlan() {
@@ -49,8 +69,12 @@ export function usePlan() {
},
);
+ // Parse the plan using the parsing function
+ const parsedPlan = plan ? parsePlan(plan.plan) : { plan: null, trial: null };
+
return {
- plan,
+ plan: parsedPlan.plan,
+ trial: parsedPlan.trial,
loading: !plan && !error,
error,
};
diff --git a/pages/documents/[id]/chat.tsx b/pages/documents/[id]/chat.tsx
index 271773ff..6674bad8 100644
--- a/pages/documents/[id]/chat.tsx
+++ b/pages/documents/[id]/chat.tsx
@@ -134,7 +134,7 @@ export default function ChatPage({
threadId={threadId}
firstPage={firstPage}
userId={userId}
- plan={plan?.plan}
+ plan={plan}
/>
</>
);
diff --git a/pages/documents/[id]/settings.tsx b/pages/documents/[id]/settings.tsx
index 94402c39..b3362c35 100644
--- a/pages/documents/[id]/settings.tsx
+++ b/pages/documents/[id]/settings.tsx
@@ -57,7 +57,7 @@ export default function Settings() {
// },
// );
- const isNotBusiness = plan?.plan !== "business";
+ const isNotBusiness = plan !== "business";
const [loading, setLoading] = useState(false);
const [loadingStatus, setLoadingStatus] = useState(false);
diff --git a/pages/settings/branding.tsx b/pages/settings/branding.tsx
index 33608f78..4e1ba843 100644
--- a/pages/settings/branding.tsx
+++ b/pages/settings/branding.tsx
@@ -269,7 +269,7 @@ export default function Branding() {
</div>
</CardContent>
<CardFooter className="border-t p-6">
- {plan && plan.plan === "free" ? (
+ {plan === "free" ? (
<UpgradePlanModal clickedPlan="Pro" trigger={"branding_page"}>
<Button>Upgrade to Save Branding</Button>
</UpgradePlanModal>
diff --git a/pages/settings/people.tsx b/pages/settings/people.tsx
index 6b8fb039..400de06d 100644
--- a/pages/settings/people.tsx
+++ b/pages/settings/people.tsx
@@ -185,7 +185,7 @@ export default function Billing() {
Teammates that have access to this project.
</p>
</div>
- {userPlan && userPlan.plan !== "free" ? (
+ {userPlan !== "free" ? (
<AddTeamMembers
open={isTeamMemberInviteModalOpen}
setOpen={setTeamMemberInviteModalOpen}
diff --git a/pages/view/[linkId]/chat.tsx b/pages/view/[linkId]/chat.tsx
index 692079a6..f982d030 100644
--- a/pages/view/[linkId]/chat.tsx
+++ b/pages/view/[linkId]/chat.tsx
@@ -132,7 +132,7 @@ export default function ChatPage({
threadId={threadId}
firstPage={firstPage}
userId={userId}
- plan={plan?.plan}
+ plan={plan}
/>
</>
);