Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
refactor: make banner into a component
Marc Seitz74c2acba1800
diff --git a/components/Sidebar.tsx b/components/Sidebar.tsxindex a2023f06..2ff64d64 100644--- a/components/Sidebar.tsx+++ b/components/Sidebar.tsx@@ -15,6 +15,7 @@ import { ModeToggle } from "./theme-toggle";import { Button } from "./ui/button";import { CustomUser } from "@/lib/types";import LoadingSpinner from "./ui/loading-spinner";+import Banner from "./banner";export default function Sidebar() {const { data: session, status } = useSession();@@ -51,28 +52,8 @@ export default function Sidebar() {disabled: false,},];-- const cutoffDate = new Date('2023-10-12T00:00:00.000Z');-- const calculateDaysLeft = (accountCreationDate: Date): number => {- let maxDays;- if (accountCreationDate < cutoffDate) {- // If the user signed up before the 12th of October 2023- maxDays = 30;- // Override account creation date to 1st of October for correct calculation- accountCreationDate = new Date('2023-10-01T00:00:00.000Z');- } else {- // If the user signed up on or after the 12th of October 2023- maxDays = 14;- }- return daysLeft(accountCreationDate, maxDays);- }-if (status === "loading") return <LoadingSpinner className="mr-1 h-5 w-5" />;;- const userDaysLeft = calculateDaysLeft(new Date((session?.user as CustomUser).createdAt || 0));--return (<><Transition.Root show={sidebarOpen} as={Fragment}>@@ -205,19 +186,7 @@ export default function Sidebar() {</ul></li><li className="-mx-2 mt-auto mb-4">- <aside className="flex flex-col justify-center w-full bg-background text-foreground 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 ${userDaysLeft} days.`}- </p>- <Button>- <Link href="/settings/domains" target="_blank">- Connect custom domain- </Link>- </Button>- </aside>+ <Banner session={session} /><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">diff --git a/components/banner.tsx b/components/banner.tsxnew file mode 100644index 00000000..da2d1c32--- /dev/null+++ b/components/banner.tsx@@ -0,0 +1,58 @@+import Link from "next/link";+import { Button } from "./ui/button";+import { daysLeft } from "@/lib/utils";+import { CustomUser } from "@/lib/types";+import { Session } from "next-auth";+import { useDomains } from "@/lib/swr/use-domains";++const cutoffDate = new Date("2023-10-12T00:00:00.000Z");++export default function Banner({ session }: { session: Session | null }) {+ const { domains } = useDomains();++ const calculateDaysLeft = (accountCreationDate: Date): number => {+ let maxDays;+ if (accountCreationDate < cutoffDate) {+ // If the user signed up before the 12th of October 2023+ maxDays = 30;+ // Override account creation date to 1st of October for correct calculation+ accountCreationDate = new Date("2023-10-01T00:00:00.000Z");+ } else {+ // If the user signed up on or after the 12th of October 2023+ maxDays = 14;+ }+ return daysLeft(accountCreationDate, maxDays);+ };++ const userDaysLeft = calculateDaysLeft(+ new Date((session?.user as CustomUser).createdAt || 0)+ );++ const someNotVerified = domains && domains.some((domain) => !domain.verified);++ const allVerified = domains && domains.every((domain) => domain.verified);++ return (+ <aside className="flex flex-col justify-center w-full bg-background text-foreground 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 ${userDaysLeft} days.`}+ </p>+ {allVerified ? (+ <p className="text-sm text-green-500">+ {`Your domain is verified.`}+ </p>+ ) : (+ <Button variant={someNotVerified ? `destructive` : `default`}>+ <Link href="/settings/domains" target="_blank">+ {someNotVerified+ ? `Please verify your domain`+ : `Connect custom domain`}+ </Link>+ </Button>+ )}+ </aside>+ );+}\ No newline at end of file