Skip to content

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

Merge remote-tracking branch 'refs/remotes/origin/main' into papermark-team-feature

Aashish-Upadhyay-10101a13e39328c
diff --cc components/Sidebar.tsx
index 579d31cd,efac1a79..57356d15
--- a/components/Sidebar.tsx
+++ b/components/Sidebar.tsx
@@@ -10,21 -10,22 +10,28 @@@ import ChevronUp from "@/components/sha
import X from "@/components/shared/icons/x";
import Link from "next/link";
import { cn } from "@/lib/utils";
++import { cn } from "@/lib/utils";
import { useRouter } from "next/router";
import { ModeToggle } from "./theme-toggle";
import LoadingSpinner from "./ui/loading-spinner";
import Banner from "./banner";
+ import ProBanner from "./billing/pro-banner";
+ import Cookies from "js-cookie";
+ import { usePlan } from "@/lib/swr/use-billing";
+ import Image from "next/image";
+import SelectTeam from "./teams/select-team";
+import { TeamContextType, initialState, useTeam } from "@/context/team-context";
export default function Sidebar() {
const { data: session, status } = useSession();
+ const { plan, loading } = usePlan();
const [sidebarOpen, setSidebarOpen] = useState<boolean>(false);
+ const [showProBanner, setShowProBanner] = useState<boolean | null>(null);
const router = useRouter();
-
+
+ const { currentTeam, teams, isLoading }: TeamContextType =
+ useTeam() || initialState;
+
const navigation = [
// {
// name: "Overview",
@@@ -55,7 -56,18 +62,19 @@@
disabled: false,
},
];
- if (status === "loading") return <LoadingSpinner className="mr-1 h-5 w-5" />;
+
+ useEffect(() => {
+ if (Cookies.get("hideProBanner") !== "pro-banner") {
+ setShowProBanner(true);
+ } else {
+ setShowProBanner(false);
+ }
+ }, []);
+
- if (status === "loading" && loading) return <LoadingSpinner className="mr-1 h-5 w-5" />;
++ if (status === "loading" && loading)
++ return <LoadingSpinner className="mr-1 h-5 w-5" />;
+
+ const userPlan = plan && plan.plan;
return (
<>
diff --cc lib/types.ts
index ac6c21a2,922b50e8..15eeb295
--- a/lib/types.ts
+++ b/lib/types.ts
@@@ -147,29 -141,8 +147,33 @@@ export type AnalyticsEvents
| {
event: "Domain Verified";
slug: string;
+ }
+ | {
+ event: "Domain Deleted";
+ slug: string;
- };
+ };
+
+export interface Team {
+ id: string;
+ name?: string;
+}
+
+export interface TeamDetail {
+ id: string;
+ name: string;
+ documents: {
+ owner: {
+ id: string;
+ name: string;
+ };
+ }[];
+ users: {
+ role: "ADMIN" | "MEMBER";
+ teamId: string;
+ user: {
+ email: string;
+ name: string;
+ };
+ userId: string;
+ }[];
+}
diff --cc pages/api/teams/[teamId]/billing/plan.ts
index 00000000,8d41e97b..2e2dec71
mode 000000,100644..100644
--- a/pages/api/teams/[teamId]/billing/plan.ts
+++ b/pages/api/teams/[teamId]/billing/plan.ts
@@@ -1,0 -1,34 +1,34 @@@
+ import { NextApiRequest, NextApiResponse } from "next";
+ import { getServerSession } from "next-auth/next";
+ import prisma from "@/lib/prisma";
-import { authOptions } from "../auth/[...nextauth]";
++import { authOptions } from "../../../auth/[...nextauth]";
+ import { CustomUser } from "@/lib/types";
+
+ export default async function handle(
+ req: NextApiRequest,
+ res: NextApiResponse
+ ) {
+ if (req.method === "GET") {
+ // GET /api/billing/plan
+ const session = await getServerSession(req, res, authOptions);
+ if (!session) {
+ return res.status(401).end("Unauthorized");
+ }
+
+ const user = await prisma.user.findUnique({
+ where: {
+ id: (session.user as CustomUser).id,
+ },
+ select: {
+ plan: true,
+ },
+ });
+
+ // console.log("Domains from GET", domains)
+ return res.status(200).json(user);
+ } else {
+ // We only allow GET and POST requests
+ res.setHeader("Allow", ["GET"]);
+ return res.status(405).end(`Method ${req.method} Not Allowed`);
+ }
+ }
diff --cc pages/settings/billing.tsx
index b00ae8ac,ac73e3b7..f9c32bc2
--- a/pages/settings/billing.tsx
+++ b/pages/settings/billing.tsx
@@@ -3,13 -3,24 +3,23 @@@ import AppLayout from "@/components/lay
import Navbar from "@/components/settings/navbar";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
+import { useTeam } from "@/context/team-context";
import { useBilling } from "@/lib/swr/use-billing";
- import { formattedDate, getFirstAndLastDay } from "@/lib/utils";
+ import { cn, formattedDate, getFirstAndLastDay } from "@/lib/utils";
import { useRouter } from "next/router";
import { useEffect, useMemo, useState } from "react";
import { toast } from "sonner";
-
+ interface Tier {
+ id: number;
+ title: string;
+ priceMonthly: string;
+ currentPlan: boolean;
+ isTrial?: boolean;
+ description: string;
+ features: string[];
+ }
+
-
export default function Billing() {
const router = useRouter();
const { plan, startsAt, endsAt } = useBilling();
@@@ -46,6 -102,123 +103,115 @@@
</div>
<div>
+ <div className="grid grid-cols-1 gap-6 items-center sm:grid-cols-3 sm:gap-4">
+ {tiers.map((tier) => (
+ <div
+ key={tier.id}
+ className={cn(
+ `rounded-3xl p-8 sm:p-10 bg-white dark:bg-gray-800`,
+ tier.currentPlan || tier.isTrial
+ ? "ring-2 ring-primary"
+ : "ring-1 ring-gray-900/10 dark:ring-gray-200/10"
- )}
- >
++ )}>
+ <h2 className="text-xl font-bold mb-4 inline-flex items-center gap-x-2">
+ {tier.title}{" "}
+ {tier.currentPlan ? (
+ <Badge className="rounded-none">Current Plan</Badge>
+ ) : null}
+ {tier.isTrial ? (
+ <Badge className="rounded-none">Trial</Badge>
+ ) : null}
+ </h2>
+ <div className="text-3xl font-bold mb-4">
+ {tier.priceMonthly}
+ </div>
+ <div className="text-gray-900 dark:text-gray-400 mb-6">
+ {tier.description}
+ </div>
+ {tier.features.map((feature) => (
+ <div key={feature} className="flex items-center mb-2">
+ <svg
+ className="h-5 w-5 text-green-500 dark:text-green-300 mr-2"
+ fill="none"
+ stroke="currentColor"
+ viewBox="0 0 24 24"
- xmlns="http://www.w3.org/2000/svg"
- >
++ xmlns="http://www.w3.org/2000/svg">
+ <path
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="2"
- d="M5 13l4 4L19 7"
- ></path>
++ d="M5 13l4 4L19 7"></path>
+ </svg>
+ {feature}
+ </div>
+ ))}
+ <div className="mt-6 flex items-center justify-center gap-x-6">
+ {tier.id === 1 &&
+ (plan ? (
+ tier.currentPlan ? (
+ <UpgradePlanModal>
- <Button type="button">
- Upgrade to Pro
- </Button>
++ <Button type="button">Upgrade to Pro</Button>
+ </UpgradePlanModal>
+ ) : (
+ <Button
+ type="button"
+ variant="ghost"
+ className="border border-gray-700"
- disabled
- >
++ disabled>
+ Change plan
+ </Button>
+ )
+ ) : (
+ <div className="h-10 w-24 animate-pulse rounded-md bg-border" />
+ ))}
+ {tier.id === 2 &&
+ (plan ? (
+ tier.currentPlan ? (
+ <Button
+ onClick={() => {
+ setClicked(true);
+ fetch(`/api/billing/manage`, {
+ method: "POST",
+ })
+ .then(async (res) => {
+ const url = await res.json();
+ router.push(url);
+ })
+ .catch((err) => {
+ alert(err);
+ setClicked(false);
+ });
+ }}
- loading={clicked}
- >
++ loading={clicked}>
+ Manage Subscription
+ </Button>
+ ) : (
+ <UpgradePlanModal>
+ <Button type="button">
+ {tier.isTrial
+ ? "Upgrade to remain on Pro"
+ : "Upgrade to Pro"}
+ </Button>
+ </UpgradePlanModal>
+ )
+ ) : (
+ <div className="h-10 w-24 animate-pulse rounded-md bg-border" />
+ ))}
+ {tier.id === 3 && (
+ <Button
+ type="button"
+ variant="ghost"
- className="border border-gray-700"
- >
++ className="border border-gray-700">
+ Contact us
+ </Button>
+ )}
+ </div>
+ </div>
+ ))}
+ </div>
+ </div>
+
+ {/* <div>
<div className="rounded-lg border border-border bg-secondary">
<div className="flex flex-col space-y-3 p-10">
<h2 className="text-xl font-medium">Plan &amp; Usage</h2>
diff --cc prisma/schema.prisma
index bdc3779e,22054389..49cd1815
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@@ -47,9 -46,8 +46,9 @@@ model User
accounts Account[]
sessions Session[]
documents Document[]
+ teams UserTeam[]
domains Domain[]
- plan String @default("free")
+ plan String @default("trial")
stripeId String? @unique // Stripe subscription / customer ID
subscriptionId String? @unique // Stripe subscription ID
startsAt DateTime? // Stripe subscription start date