From 0a82ce915f3d711e90e30ab633ca58740c649ee3 Mon Sep 17 00:00:00 2001 From: Marc Seitz Date: Tue, 17 Sep 2024 17:44:28 +0200 Subject: [PATCH] feat: add filetypes to upload --- components/document-upload.tsx | 63 +++++++++++++++++++--------------- components/upload-zone.tsx | 56 +++++++++++++++++------------- 2 files changed, 68 insertions(+), 51 deletions(-) diff --git a/components/document-upload.tsx b/components/document-upload.tsx index cf77f2340..1c2b6955b 100644 --- a/components/document-upload.tsx +++ b/components/document-upload.tsx @@ -11,16 +11,10 @@ import { fileIcon } from "@/lib/utils/get-file-icon"; import { getPagesCount } from "@/lib/utils/get-page-number-count"; const fileSizeLimits: { [key: string]: number } = { - "application/vnd.ms-excel": 30, // 30 MB - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": 30, // 30 MB - "application/vnd.oasis.opendocument.spreadsheet": 30, // 30 MB - "application/vnd.ms-powerpoint": 30, // 30 MB - "application/vnd.openxmlformats-officedocument.presentationml.presentation": 30, // 30 MB - "application/vnd.oasis.opendocument.presentation": 30, // 30 MB - "application/msword": 30, // 30 MB - "application/vnd.openxmlformats-officedocument.wordprocessingml.document": 30, // 30 MB - "application/vnd.oasis.opendocument.text": 30, // 30 MB - "text/csv": 30, // 30 MB + "application/vnd.ms-excel": 40, // 40 MB + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": 40, // 40 MB + "application/vnd.oasis.opendocument.spreadsheet": 40, // 40 MB + "text/csv": 40, // 40 MB }; export default function DocumentUpload({ @@ -33,26 +27,39 @@ export default function DocumentUpload({ const { theme, systemTheme } = useTheme(); const isLight = theme === "light" || (theme === "system" && systemTheme === "light"); - const { plan } = usePlan(); + const { plan, trial } = usePlan(); + const isFreePlan = plan === "free"; + const isTrial = !!trial; const maxSize = plan === "business" || plan === "datarooms" ? 100 : 30; const maxNumPages = plan === "business" || plan === "datarooms" ? 500 : 100; const { getRootProps, getInputProps } = useDropzone({ - accept: { - "application/pdf": [], // ".pdf" - "application/vnd.ms-excel": [], // ".xls" - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": [], // ".xlsx" - "text/csv": [], // ".csv" - "application/vnd.oasis.opendocument.spreadsheet": [], // ".ods" - "application/vnd.ms-powerpoint": [], // ".ppt" - "application/vnd.openxmlformats-officedocument.presentationml.presentation": - [], // ".pptx" - "application/vnd.oasis.opendocument.presentation": [], // ".odp" - "application/msword": [], // ".doc" - "application/vnd.openxmlformats-officedocument.wordprocessingml.document": - [], // ".docx" - "application/vnd.oasis.opendocument.text": [], // ".odt" - }, + accept: + isFreePlan && !isTrial + ? { + "application/pdf": [], // ".pdf" + "application/vnd.ms-excel": [], // ".xls" + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": + [], // ".xlsx" + "text/csv": [], // ".csv" + "application/vnd.oasis.opendocument.spreadsheet": [], // ".ods" + } + : { + "application/pdf": [], // ".pdf" + "application/vnd.ms-excel": [], // ".xls" + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": + [], // ".xlsx" + "text/csv": [], // ".csv" + "application/vnd.oasis.opendocument.spreadsheet": [], // ".ods" + "application/vnd.ms-powerpoint": [], // ".ppt" + "application/vnd.openxmlformats-officedocument.presentationml.presentation": + [], // ".pptx" + "application/vnd.oasis.opendocument.presentation": [], // ".odp" + "application/msword": [], // ".doc" + "application/vnd.openxmlformats-officedocument.wordprocessingml.document": + [], // ".docx" + "application/vnd.oasis.opendocument.text": [], // ".odt" + }, multiple: false, maxSize: maxSize * 1024 * 1024, // 30 MB onDropAccepted: (acceptedFiles) => { @@ -151,7 +158,9 @@ export default function DocumentUpload({

{currentFile ? "Replace file?" - : `Only *.xls, *.xlsx, *.csv, *.ods, *.pdf & ${maxSize} MB limit`} + : isFreePlan && !isTrial + ? `Only *.pdf, *.xls, *.xlsx, *.csv, *.ods & ${maxSize} MB limit` + : `Only *.pdf, *.pptx, *.docx, *.xlsx, *.xls, *.csv, *.ods, *.ppt, *.odp, *.doc, *.odt & ${maxSize} MB limit`}

diff --git a/components/upload-zone.tsx b/components/upload-zone.tsx index 56d84bf10..706d9eac0 100644 --- a/components/upload-zone.tsx +++ b/components/upload-zone.tsx @@ -21,13 +21,6 @@ interface FileWithPath extends File { path?: string; } -const fileSizeLimits: { [key: string]: number } = { - "application/vnd.ms-excel": 100, // 30 MB - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": 30, // 30 MB - "text/csv": 30, // 30 MB - "application/vnd.oasis.opendocument.spreadsheet": 30, // 30 MB -}; - export default function UploadZone({ children, onUploadStart, @@ -60,10 +53,12 @@ export default function UploadZone({ dataroomId?: string; }) { const analytics = useAnalytics(); - const { plan, loading } = usePlan(); + const { plan, trial } = usePlan(); const router = useRouter(); const teamInfo = useTeam(); const { data: session } = useSession(); + const isFreePlan = plan === "free"; + const isTrial = !!trial; const maxSize = plan === "business" || plan === "datarooms" ? 250 : 30; const maxNumPages = plan === "business" || plan === "datarooms" ? 500 : 100; @@ -237,21 +232,32 @@ export default function UploadZone({ ); const { getRootProps, getInputProps, isDragActive } = useDropzone({ - accept: { - "application/pdf": [], // ".pdf" - "application/vnd.ms-excel": [], // ".xls" - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": [], // ".xlsx" - "text/csv": [], // ".csv" - "application/vnd.oasis.opendocument.spreadsheet": [], // ".ods" - "application/vnd.openxmlformats-officedocument.wordprocessingml.document": - [], // ".docx" - "application/vnd.openxmlformats-officedocument.presentationml.presentation": - [], // ".pptx" - "application/vnd.ms-powerpoint": [], // ".ppt" - "application/msword": [], // ".doc" - "application/vnd.oasis.opendocument.text": [], // ".odt" - "application/vnd.oasis.opendocument.presentation": [], // ".odp" - }, + accept: + isFreePlan && !isTrial + ? { + "application/pdf": [], // ".pdf" + "application/vnd.ms-excel": [], // ".xls" + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": + [], // ".xlsx" + "text/csv": [], // ".csv" + "application/vnd.oasis.opendocument.spreadsheet": [], // ".ods" + } + : { + "application/pdf": [], // ".pdf" + "application/vnd.ms-excel": [], // ".xls" + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": + [], // ".xlsx" + "text/csv": [], // ".csv" + "application/vnd.oasis.opendocument.spreadsheet": [], // ".ods" + "application/vnd.openxmlformats-officedocument.wordprocessingml.document": + [], // ".docx" + "application/vnd.openxmlformats-officedocument.presentationml.presentation": + [], // ".pptx" + "application/vnd.ms-powerpoint": [], // ".ppt" + "application/msword": [], // ".doc" + "application/vnd.oasis.opendocument.text": [], // ".odt" + "application/vnd.oasis.opendocument.presentation": [], // ".odp" + }, multiple: true, maxSize: maxSize * 1024 * 1024, // 30 MB onDrop, @@ -285,7 +291,9 @@ export default function UploadZone({
Drop your file(s) to upload here

- {`Only *.pdf, *.xls, *.xlsx, *.csv, *.ods & ${maxSize} MB limit`} + {isFreePlan && !isTrial + ? `Only *.pdf, *.xls, *.xlsx, *.csv, *.ods & ${maxSize} MB limit` + : `Only *.pdf, *.pptx, *.docx, *.xlsx, *.xls, *.csv, *.ods, *.ppt, *.odp, *.doc, *.odt & ${maxSize} MB limit`}