Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
chore: cleanup plan helpers
Marc Seitz2541546e5ed3
diff --git a/components/document-upload.tsx b/components/document-upload.tsxindex 31bcfadc..9f6905ce 100644--- a/components/document-upload.tsx+++ b/components/document-upload.tsx@@ -29,27 +29,23 @@ export default function DocumentUpload({const { theme, systemTheme } = useTheme();const isLight =theme === "light" || (theme === "system" && systemTheme === "light");- const { plan, trial } = usePlan();+ const { isFree, isTrial } = usePlan();const { limits } = useLimits();- const isFreePlan = plan === "free";- const isTrial = !!trial;- // const maxSize = isFreePlan && !isTrial ? 30 : 100;- // const maxNumPages = isFreePlan && !isTrial ? 100 : 500;// Get file size limitsconst fileSizeLimits = useMemo(() =>getFileSizeLimits({limits,- isFreePlan,+ isFree,isTrial,}),- [limits, isFreePlan, isTrial],+ [limits, isFree, isTrial],);const { getRootProps, getInputProps } = useDropzone({accept:- isFreePlan && !isTrial+ isFree && !isTrial? {"application/pdf": [], // ".pdf""application/vnd.ms-excel": [], // ".xls"@@ -101,7 +97,7 @@ export default function DocumentUpload({if (file.size > fileSizeLimit) {const message = `File size too big for ${fileType} (max. ${fileSizeLimitMB} MB)`;- if (isFreePlan && !isTrial) {+ if (isFree && !isTrial) {toast.error(message, {description: "Upgrade to a paid plan to increase the limit",action: {@@ -144,7 +140,7 @@ export default function DocumentUpload({if (errors[0].code === "file-too-large") {const fileSizeLimitMB = getFileSizeLimit(file.type, fileSizeLimits);message = `File size too big (max. ${fileSizeLimitMB} MB)`;- if (isFreePlan && !isTrial) {+ if (isFree && !isTrial) {toast.error(message, {description: "Upgrade to a paid plan to increase the limit",action: {@@ -158,7 +154,7 @@ export default function DocumentUpload({} else if (errors[0].code === "file-invalid-type") {const isSupported = SUPPORTED_DOCUMENT_MIME_TYPES.includes(file.type);message = "File type not supported";- if (isFreePlan && !isTrial && isSupported) {+ if (isFree && !isTrial && isSupported) {toast.error(`${message} on free plan`, {description: `Upgrade to a paid plan to upload ${file.type} files`,action: {@@ -227,7 +223,7 @@ export default function DocumentUpload({<p className="text-xs leading-5 text-gray-500">{currentFile? "Replace file?"- : isFreePlan && !isTrial+ : isFree && !isTrial? `Only *.pdf, *.xls, *.xlsx, *.csv, *.ods, *.png, *.jpeg, *.jpg`: `Only *.pdf, *.pptx, *.docx, *.xlsx, *.xls, *.xlsm, *.csv, *.ods, *.ppt, *.odp, *.doc, *.odt, *.dwg, *.dxf, *.png, *.jpg, *.jpeg, *.mp4, *.mov, *.avi, *.webm, *.ogg`}</p>diff --git a/components/upload-zone.tsx b/components/upload-zone.tsxindex 74d47c58..44813c74 100644--- a/components/upload-zone.tsx+++ b/components/upload-zone.tsx@@ -104,14 +104,11 @@ export default function UploadZone({dataroomId?: string;}) {const analytics = useAnalytics();- const { plan, trial } = usePlan();+ const { plan, isFree, isTrial } = usePlan();const router = useRouter();const teamInfo = useTeam();const { data: session } = useSession();- const isFreePlan = plan === "free";- const isTrial = !!trial;- // const maxSize = isFreePlan && !isTrial ? 30 : 350;- // const maxNumPages = isFreePlan && !isTrial ? 100 : 500;+const { limits, canAddDocuments } = useLimits();const remainingDocuments = limits?.documents? limits?.documents - limits?.usage?.documents@@ -125,14 +122,14 @@ export default function UploadZone({() =>getFileSizeLimits({limits,- isFreePlan,+ isFree,isTrial,}),- [limits, isFreePlan, isTrial],+ [limits, isFree, isTrial],);const acceptableDropZoneFileTypes =- isFreePlan && !isTrial+ isFree && !isTrial? acceptableDropZoneMimeTypesWhenIsFreePlanAndNotTrail: allAcceptableDropZoneMimeTypes;@@ -151,14 +148,14 @@ export default function UploadZone({} else if (errors.find(({ code }) => code === "file-invalid-type")) {const isSupported = SUPPORTED_DOCUMENT_MIME_TYPES.includes(file.type);message = `File type not supported ${- isFreePlan && !isTrial && isSupported ? `on free plan` : ""+ isFree && !isTrial && isSupported ? `on free plan` : ""}`;}return { fileName: file.name, message };});onUploadRejected(rejected);},- [onUploadRejected, fileSizeLimits, isFreePlan, isTrial],+ [onUploadRejected, fileSizeLimits, isFree, isTrial],);const onDrop = useCallback(@@ -181,7 +178,7 @@ export default function UploadZone({acc.invalid.push({fileName: file.name,message: `File size too big (max. ${fileSizeLimitMB} MB)${- isFreePlan && !isTrial+ isFree && !isTrial? ". Upgrade to a paid plan to increase the limit": ""}`,@@ -408,7 +405,7 @@ export default function UploadZone({onUploadProgress,endpointTargetType,fileSizeLimits,- isFreePlan,+ isFree,isTrial,],);@@ -658,7 +655,7 @@ export default function UploadZone({Drop your file(s) here</span><p className="mt-1 text-xs leading-5 text-muted-foreground">- {isFreePlan && !isTrial+ {isFree && !isTrial? `Only *.pdf, *.xls, *.xlsx, *.csv, *.ods, *.png, *.jpeg, *.jpg`: `Only *.pdf, *.pptx, *.docx, *.xlsx, *.xls, *.csv, *.ods, *.ppt, *.odp, *.doc, *.odt, *.dwg, *.dxf, *.png, *.jpg, *.jpeg, *.mp4, *.mov, *.avi, *.webm, *.ogg`}</p>diff --git a/lib/utils/get-file-size-limits.ts b/lib/utils/get-file-size-limits.tsindex 375de672..1c3bb390 100644--- a/lib/utils/get-file-size-limits.ts+++ b/lib/utils/get-file-size-limits.ts@@ -9,21 +9,21 @@ type FileSizeLimits = {export function getFileSizeLimits({limits,- isFreePlan,+ isFree,isTrial,}: {limits?: { fileSizeLimits?: Partial<FileSizeLimits> } | null;- isFreePlan: boolean;+ isFree: boolean;isTrial: boolean;}): FileSizeLimits {// Default limits based on plan typeconst defaultLimits: FileSizeLimits = {video: 500, // 500MB- document: isFreePlan && !isTrial ? 100 : 350, // 100MB free, 350MB paid- image: isFreePlan && !isTrial ? 30 : 100, // 30MB free, 100MB paid+ document: isFree && !isTrial ? 100 : 350, // 100MB free, 350MB paid+ image: isFree && !isTrial ? 30 : 100, // 30MB free, 100MB paidexcel: 40, // 40MBmaxFiles: 150,- maxPages: isFreePlan && !isTrial ? 100 : 500,+ maxPages: isFree && !isTrial ? 100 : 500,};// If no custom limits are set, return default limits