Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
refactor: move calculateDaysLeft to utils
Marc Seitz0c28741d3ddf
diff --git a/components/banner.tsx b/components/banner.tsxindex 841843ce..bb6c7d64 100644--- a/components/banner.tsx+++ b/components/banner.tsx@@ -1,6 +1,6 @@import Link from "next/link";import { Button } from "./ui/button";-import { daysLeft } from "@/lib/utils";+import { calculateDaysLeft } from "@/lib/utils";import { CustomUser } from "@/lib/types";import { Session } from "next-auth";import { useDomains } from "@/lib/swr/use-domains";@@ -9,20 +9,6 @@ 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)diff --git a/lib/utils.ts b/lib/utils.tsindex 2602dd68..290bd2a4 100644--- a/lib/utils.ts+++ b/lib/utils.ts@@ -241,4 +241,17 @@ export const daysLeft = (accountCreationDate: Date, maxDays: number): number =>// Convert milliseconds to days and returnreturn Math.ceil(diffInMilliseconds / (1000 * 60 * 60 * 24));-}\ No newline at end of file+}++const cutoffDate = new Date("2023-10-12T00:00:00.000Z");++export const calculateDaysLeft = (accountCreationDate: Date): number => {+ let maxDays;+ if (accountCreationDate < cutoffDate) {+ maxDays = 30;+ accountCreationDate = new Date("2023-10-01T00:00:00.000Z");+ } else {+ maxDays = 14;+ }+ return daysLeft(accountCreationDate, maxDays);+};\ No newline at end of file