Skip to content

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

Reverse trial (#84)

Marc Seitz942f955d2c54
diff --git a/components/Sidebar.tsx b/components/Sidebar.tsx
index 753e70b3..74b81d5c 100644
--- a/components/Sidebar.tsx
+++ b/components/Sidebar.tsx
@@ -1,15 +1,18 @@
import { Fragment, useState } from "react";
import { Menu, Dialog, Transition } from "@headlessui/react";
import { signOut, useSession } from "next-auth/react";
-import {
- Bars3Icon,
- ChevronUpIcon,
-} from "@heroicons/react/20/solid";
-import { FolderIcon, HomeIcon, XMarkIcon, ChartBarIcon } from "@heroicons/react/24/outline";
+import HomeIcon from "@/components/shared/icons/home";
+import FolderIcon from "@/components/shared/icons/folder";
+import PieChartIcon from "@/components/shared/icons/pie-chart";
+import SettingsIcon from "@/components/shared/icons/settings";
+import MenuIcon from "@/components/shared/icons/menu";
+import ChevronUp from "@/components/shared/icons/chevron-up";
+import X from "@/components/shared/icons/x";
import Link from "next/link";
import { cn } from "@/lib/utils";
import { useRouter } from "next/router";
import { ModeToggle } from "./theme-toggle";
+import { Button } from "./ui/button";
export default function Sidebar() {
const { data: session } = useSession();
@@ -17,13 +20,13 @@ export default function Sidebar() {
const router = useRouter();
const navigation = [
- {
- name: "Overview",
- href: "/overview",
- icon: HomeIcon,
- current: router.pathname.includes("overview"),
- disabled: true,
- },
+ // {
+ // name: "Overview",
+ // href: "/overview",
+ // icon: HomeIcon,
+ // current: router.pathname.includes("overview"),
+ // disabled: true,
+ // },
{
name: "Documents",
href: "/documents",
@@ -34,10 +37,17 @@ export default function Sidebar() {
{
name: "Analytics",
href: "/analytics",
- icon: ChartBarIcon,
+ icon: PieChartIcon,
current: router.pathname.includes("analytics"),
disabled: true,
},
+ {
+ name: "Settings",
+ href: "/settings/domains",
+ icon: SettingsIcon,
+ current: router.pathname.includes("settings"),
+ disabled: false,
+ },
];
return (
@@ -87,7 +97,7 @@ export default function Sidebar() {
onClick={() => setSidebarOpen(false)}
>
<span className="sr-only">Close sidebar</span>
- <XMarkIcon
+ <X
className="h-6 w-6 text-foreground"
aria-hidden="true"
/>
@@ -172,6 +182,19 @@ export default function Sidebar() {
</ul>
</li>
<li className="-mx-2 mt-auto mb-4">
+ <aside className="flex flex-col justify-center w-full bg-gray-900 text-gray-50 p-4 mb-2 rounded-lg border border-gray-700">
+ <div className="flex space-x-2">
+ <span className="font-bold text-sm">✨ Pro Trial ✨</span>
+ </div>
+ <p className="my-4 text-sm">
+ You are on the Pro trial for the next 30 days.
+ </p>
+ <Button>
+ <Link href="/settings/domains" target="_blank">
+ Connect custom domain
+ </Link>
+ </Button>
+ </aside>
<div className="flex justify-between items-center space-x-2">
<Menu as="div" className="relative grow">
<Menu.Button className="flex items-center group rounded-md gap-x-3 p-2 w-full text-sm font-semibold leading-6 text-foreground hover:bg-gray-200 hover:dark:bg-secondary">
@@ -183,7 +206,7 @@ export default function Sidebar() {
<span className="flex items-center w-full justify-between">
<span className="sr-only">Your profile</span>
<span aria-hidden="true">{session?.user?.name}</span>
- <ChevronUpIcon
+ <ChevronUp
className="ml-2 h-5 w-5 text-muted-foreground"
aria-hidden="true"
/>
@@ -241,7 +264,7 @@ export default function Sidebar() {
onClick={() => setSidebarOpen(true)}
>
<span className="sr-only">Open sidebar</span>
- <Bars3Icon className="h-6 w-6" aria-hidden="true" />
+ <MenuIcon className="h-6 w-6" aria-hidden="true" />
</button>
<div className="flex flex-1 gap-x-4 self-stretch items-center lg:gap-x-6 justify-end">
diff --git a/components/billing/upgrade-plan-modal.tsx b/components/billing/upgrade-plan-modal.tsx
index 51e953c5..1a08cf34 100644
--- a/components/billing/upgrade-plan-modal.tsx
+++ b/components/billing/upgrade-plan-modal.tsx
@@ -19,7 +19,7 @@ import { Badge } from "../ui/badge";
export function UpgradePlanModal({ children }: { children: React.ReactNode }) {
const [plan, setPlan] = useState<"Pro">("Pro");
- const [period, setPeriod] = useState<"monthly" | "yearly">("yearly");
+ const [period, setPeriod] = useState<"monthly" | "yearly">("monthly");
const [clicked, setClicked] = useState<boolean>(false);
const features = useMemo(() => {
return [
diff --git a/components/domains/add-domain-modal.tsx b/components/domains/add-domain-modal.tsx
index d8928014..fcc47713 100644
--- a/components/domains/add-domain-modal.tsx
+++ b/components/domains/add-domain-modal.tsx
@@ -14,18 +14,22 @@ import { useState } from "react";
import { toast } from "sonner";
export function AddDomainModal({
+ open,
+ setOpen,
onAddition,
children,
}: {
- onAddition: (newDomain: string) => void;
- children: React.ReactNode;
+ open: boolean;
+ setOpen: React.Dispatch<React.SetStateAction<boolean>>;
+ onAddition?: (newDomain: string) => void;
+ children?: React.ReactNode;
}) {
const [domain, setDomain] = useState<string>("");
const [loading, setLoading] = useState<boolean>(false);
- const [open, setOpen] = useState<boolean>(false);
const handleSubmit = async (event: any) => {
event.preventDefault();
+ event.stopPropagation();
if (domain == "") return;
@@ -45,18 +49,23 @@ export function AddDomainModal({
setLoading(false);
setOpen(false);
toast.error(error);
+ return;
}
const newDomain = await response.json();
+ toast.success("Domain added successfully! 🎉")
+
// console.log(newDomain);
// Update local data with the new link
- onAddition(newDomain);
+ onAddition && onAddition(newDomain);
setOpen(false);
setLoading(false);
+
+ !onAddition && window.open("/settings/domains", "_blank")
};
return (
diff --git a/components/links/link-sheet/domain-section.tsx b/components/links/link-sheet/domain-section.tsx
new file mode 100644
index 00000000..b2086ddd
--- /dev/null
+++ b/components/links/link-sheet/domain-section.tsx
@@ -0,0 +1,109 @@
+import { Dispatch, SetStateAction, useState, useEffect } from "react";
+import { cn } from "@/lib/utils";
+import { DEFAULT_LINK_TYPE } from ".";
+import { Label } from "@/components/ui/label";
+import { Domain } from "@prisma/client";
+import { AddDomainModal } from "@/components/domains/add-domain-modal";
+import { Button } from "@/components/ui/button";
+import { mutate } from "swr";
+import Link from "next/link";
+
+export default function DomainSection({
+ data,
+ setData,
+ domains,
+}: {
+ data: DEFAULT_LINK_TYPE;
+ setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>;
+ domains?: Domain[];
+}) {
+ const [isModalOpen, setModalOpen] = useState(false);
+
+ const handleDomainChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
+ const value = event.target.value;
+
+ if (value === "add_domain") {
+ // Redirect to the add domain page
+ setModalOpen(true);
+ return;
+ }
+
+ setData({ ...data, domain: value });
+ };
+
+ const handleSelectFocus = () => {
+ // Assuming your fetcher key for domains is '/api/domains'
+ mutate("/api/domains");
+ };
+
+ const currentDomain = domains?.find(domain => domain.slug === data.domain);
+ const isDomainVerified = currentDomain?.verified;
+
+ return (
+ <>
+ <Label htmlFor="link-domain">Domain</Label>
+ <div className="flex">
+ <select
+ value={data.domain || "papermark.io"}
+ onChange={handleDomainChange}
+ onFocus={handleSelectFocus}
+ className={cn(
+ "w-48 rounded-l-md border border-r-0 border-border bg-secondary px-5 text-sm text-secondary-foreground focus:border-border focus:outline-none focus:ring-0",
+ data.domain && data.domain !== "papermark.io"
+ ? ""
+ : "rounded-r-md border-r-1"
+ )}
+ >
+ <option key="papermark.io" value="papermark.io">
+ papermark.io
+ </option>
+ {domains
+ // ?.filter((domain) => domain.verified)
+ ?.map(({ slug }) => (
+ <option key={slug} value={slug}>
+ {slug}
+ </option>
+ ))}
+ <option value="add_domain">Add a custom domain ✨</option>
+ </select>
+
+ {data.domain && data.domain !== "papermark.io" ? (
+ <input
+ type="text"
+ name="key"
+ required
+ value={data.slug || ""}
+ pattern="[\p{L}\p{N}\p{Pd}\/]+"
+ onInvalid={(e) => {
+ e.currentTarget.setCustomValidity(
+ "Only letters, numbers, '-', and '/' are allowed."
+ );
+ }}
+ autoComplete="off"
+ className={cn(
+ "hidden w-full rounded-r-md border-0 py-1.5 text-foreground bg-background shadow-sm ring-1 ring-inset ring-input placeholder:text-muted-foreground focus:ring-2 focus:ring-inset focus:ring-gray-400 sm:text-sm sm:leading-6",
+ data.domain && data.domain !== "papermark.io" ? "flex" : ""
+ )}
+ placeholder="deck"
+ onChange={(e) => {
+ e.currentTarget.setCustomValidity("");
+ setData({ ...data, slug: e.target.value });
+ }}
+ aria-invalid="true"
+ />
+ ) : null}
+ </div>
+
+ {data.domain && data.domain !== "papermark.io" && !isDomainVerified ? (
+ <div className="text-sm text-red-500 mt-4">
+ Your domain is not verified yet! <Link className="underline hover:text-red-500/80" href="/settings/domains" target="_blank">Verify now</Link>
+ </div>
+ ) : null}
+
+ <AddDomainModal
+ open={isModalOpen}
+ setOpen={setModalOpen}
+ />
+ </>
+ );
+}
diff --git a/components/links/link-sheet/index.tsx b/components/links/link-sheet/index.tsx
index 467c15f2..98673a03 100644
--- a/components/links/link-sheet/index.tsx
+++ b/components/links/link-sheet/index.tsx
@@ -1,6 +1,5 @@
import {
Sheet,
- SheetClose,
SheetContent,
SheetDescription,
SheetFooter,
@@ -20,8 +19,9 @@ import { Button } from "@/components/ui/button";
import { toast } from "sonner";
import { Label } from "@/components/ui/label";
import { cn } from "@/lib/utils";
-import { set } from "date-fns";
import { UpgradePlanModal } from "@/components/billing/upgrade-plan-modal";
+import Link from "next/link";
+import DomainSection from "./domain-section";
export const DEFAULT_LINK_PROPS = {
id: null,
@@ -118,6 +118,7 @@ export default function LinkSheet({ isOpen, setIsOpen, currentLink }: { isOpen:
setIsLoading(false);
}
+
// console.log("current Data", data)
@@ -154,68 +155,7 @@ export default function LinkSheet({ isOpen, setIsOpen, currentLink }: { isOpen:
</div>
<div className="space-y-2">
- <Label htmlFor="link-domain">Domain</Label>
- <div className="flex">
- <select
- value={data.domain || "papermark.io"}
- onChange={(e) => {
- setData({ ...data, domain: e.target.value });
- }}
- className={cn(
- "w-48 rounded-l-md border border-r-0 border-border bg-secondary px-5 text-sm text-secondary-foreground focus:border-border focus:outline-none focus:ring-0",
- data.domain && data.domain !== "papermark.io"
- ? ""
- : "rounded-r-md border-r-1"
- )}
- >
- <option key="papermark.io" value="papermark.io">
- papermark.io
- </option>
- {domains
- ?.filter((domain) => domain.verified)
- .map(({ slug }) => (
- <option key={slug} value={slug}>
- {slug}
- </option>
- ))}
- </select>
-
- {!data.domain || data.domain === "papermark.io" ? (
- <UpgradePlanModal>
- <Button type="button" variant="ghost" className="h-8">
- ✨ Get a custom domain ✨
- </Button>
- </UpgradePlanModal>
- ) : null}
-
- {data.domain && data.domain !== "papermark.io" ? (
- <input
- type="text"
- name="key"
- required
- value={data.slug || ""}
- pattern="[\p{L}\p{N}\p{Pd}\/]+"
- onInvalid={(e) => {
- e.currentTarget.setCustomValidity(
- "Only letters, numbers, '-', and '/' are allowed."
- );
- }}
- autoComplete="off"
- className={cn(
- "hidden w-full rounded-r-md border-0 py-1.5 text-foreground bg-background shadow-sm ring-1 ring-inset ring-input placeholder:text-muted-foreground focus:ring-2 focus:ring-inset focus:ring-gray-400 sm:text-sm sm:leading-6",
- data.domain && data.domain !== "papermark.io"
- ? "flex"
- : ""
- )}
- placeholder="deck"
- onChange={(e) => {
- e.currentTarget.setCustomValidity("");
- setData({ ...data, slug: e.target.value });
- }}
- aria-invalid="true"
- />
- ) : null}
- </div>
+ <DomainSection {...{ data, setData, domains }} />
</div>
<div className="flex items-center relative">
diff --git a/components/shared/icons/chevron-up.tsx b/components/shared/icons/chevron-up.tsx
new file mode 100644
index 00000000..47cdb334
--- /dev/null
+++ b/components/shared/icons/chevron-up.tsx
@@ -0,0 +1,18 @@
+export default function ChevronUp({ className }: { className?: string }) {
+ return (
+ <svg
+ width="14"
+ height="14"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="2"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ className={className}
+ shapeRendering="geometricPrecision"
+ >
+ <path d="m18 15-6-6-6 6" />
+ </svg>
+ );
+}
\ No newline at end of file
diff --git a/components/shared/icons/folder.tsx b/components/shared/icons/folder.tsx
new file mode 100644
index 00000000..1edbc478
--- /dev/null
+++ b/components/shared/icons/folder.tsx
@@ -0,0 +1,19 @@
+export default function Folder({ className }: { className?: string }) {
+ return (
+ <svg
+ width="14"
+ height="14"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="2"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ shapeRendering="geometricPrecision"
+ className={className}
+ >
+ <path d="M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.93a2 2 0 0 1-1.66-.9l-.82-1.2A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13c0 1.1.9 2 2 2Z" />
+ <path d="M2 10h20" />
+ </svg>
+ );
+}
\ No newline at end of file
diff --git a/components/shared/icons/home.tsx b/components/shared/icons/home.tsx
new file mode 100644
index 00000000..458dc2f9
--- /dev/null
+++ b/components/shared/icons/home.tsx
@@ -0,0 +1,19 @@
+export default function Home({ className }: { className?: string }) {
+ return (
+ <svg
+ width="14"
+ height="14"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="2"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ shapeRendering="geometricPrecision"
+ className={className}
+ >
+ <path d="m3 9 9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z" />
+ <polyline points="9 22 9 12 15 12 15 22" />
+ </svg>
+ );
+}
\ No newline at end of file
diff --git a/components/shared/icons/menu.tsx b/components/shared/icons/menu.tsx
new file mode 100644
index 00000000..aa60b166
--- /dev/null
+++ b/components/shared/icons/menu.tsx
@@ -0,0 +1,20 @@
+export default function Menu({ className }: { className?: string }) {
+ return (
+ <svg
+ width="14"
+ height="14"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="2"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ className={className}
+ shapeRendering="geometricPrecision"
+ >
+ <line x1="4" x2="20" y1="12" y2="12" />
+ <line x1="4" x2="20" y1="6" y2="6" />
+ <line x1="4" x2="20" y1="18" y2="18" />
+ </svg>
+ );
+}
\ No newline at end of file
diff --git a/components/shared/icons/pie-chart.tsx b/components/shared/icons/pie-chart.tsx
new file mode 100644
index 00000000..e9a9d86e
--- /dev/null
+++ b/components/shared/icons/pie-chart.tsx
@@ -0,0 +1,19 @@
+export default function PieChart({ className }: { className?: string }) {
+ return (
+ <svg
+ width="14"
+ height="14"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="2"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ shapeRendering="geometricPrecision"
+ className={className}
+ >
+ <path d="M21.21 15.89A10 10 0 1 1 8 2.83" />
+ <path d="M22 12A10 10 0 0 0 12 2v10z" />
+ </svg>
+ );
+}
\ No newline at end of file
diff --git a/components/shared/icons/settings.tsx b/components/shared/icons/settings.tsx
new file mode 100644
index 00000000..aefb683a
--- /dev/null
+++ b/components/shared/icons/settings.tsx
@@ -0,0 +1,19 @@
+export default function Settings({ className }: { className?: string }) {
+ return (
+ <svg
+ width="14"
+ height="14"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="2"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ shapeRendering="geometricPrecision"
+ className={className}
+ >
+ <path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z" />
+ <circle cx="12" cy="12" r="3" />
+ </svg>
+ );
+}
\ No newline at end of file
diff --git a/pages/settings/billing.tsx b/pages/settings/billing.tsx
index f366e374..80bcce01 100644
--- a/pages/settings/billing.tsx
+++ b/pages/settings/billing.tsx
@@ -49,7 +49,7 @@ export default function Billing() {
<p className="text-sm text-secondary-foreground">
You are currently on the{" "}
{plan ? (
- <Badge>{plan}</Badge>
+ <Badge>Pro</Badge>
) : (
<span className="rounded-full bg-border px-2 py-0.5 text-xs text-foreground">
load
diff --git a/pages/settings/domains.tsx b/pages/settings/domains.tsx
index 3f318413..906b9051 100644
--- a/pages/settings/domains.tsx
+++ b/pages/settings/domains.tsx
@@ -4,11 +4,12 @@ import AppLayout from "@/components/layouts/app";
import Navbar from "@/components/settings/navbar";
import { Button } from "@/components/ui/button";
import { useDomains } from "@/lib/swr/use-domains";
+import { useState } from "react";
import { mutate } from "swr";
export default function Domains() {
-
const { domains } = useDomains();
+ const [open, setOpen] = useState<boolean>(false);
const handleDomainDeletion = (deletedDomain: string) => {
mutate(
@@ -31,17 +32,16 @@ export default function Domains() {
<h3 className="text-2xl text-foreground font-semibold tracking-tight">
Domains
</h3>
- <p className="text-sm text-muted-foreground">Manage your custom domains</p>
+ <p className="text-sm text-muted-foreground">Manage your custom domain for document sharing</p>
</div>
<ul className="flex items-center justify-between gap-4">
- <AddDomainModal onAddition={handleDomainAddition}>
+ <AddDomainModal open={open} setOpen={setOpen} onAddition={handleDomainAddition}>
<Button>Add Domain</Button>
</AddDomainModal>
</ul>
</div>
{(domains && domains.length !== 0) ? (
<div>
- <h2 className="text-2xl font-semibold">Domains</h2>
<ul>
{domains.map((domain, index) => (
<li key={index} className="mt-4">