Skip to content

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

fix: distinguish unsupported file type from plan limit in upload drawer

Marc Seitzbf02e594fb74
diff --git a/components/upload-notification.tsx b/components/upload-notification.tsx
index 9bd5b70b..d6559306 100644
--- a/components/upload-notification.tsx
+++ b/components/upload-notification.tsx
@@ -48,6 +48,27 @@ function formatTimeLeft(ms: number): string {
return `${minutes} min left...`;
}
+function downloadRejectedFileNames(files: RejectedFile[], downloadName: string) {
+ const allNames: string[] = [];
+ for (const rf of files) {
+ if (rf.skippedFileNames?.length) {
+ allNames.push(...rf.skippedFileNames);
+ } else {
+ allNames.push(rf.fileName);
+ }
+ }
+ if (allNames.length === 0) return;
+
+ const content = allNames.join("\n");
+ const blob = new Blob([content], { type: "text/plain" });
+ const url = URL.createObjectURL(blob);
+ const a = document.createElement("a");
+ a.href = url;
+ a.download = downloadName;
+ a.click();
+ URL.revokeObjectURL(url);
+}
+
const ItemRow = memo(
function ItemRow({
item,
@@ -305,17 +326,24 @@ export function UploadNotificationDrawer({
const isPreparing = batch === null || itemCount === 0;
// js-combine-iterations: single pass to partition rejected files
- const { skippedFiles, failedFiles } = useMemo(() => {
+ const { skippedFiles, unsupportedFiles, failedFiles } = useMemo(() => {
const skipped: RejectedFile[] = [];
+ const unsupported: RejectedFile[] = [];
const failed: RejectedFile[] = [];
for (const rf of rejectedFiles) {
if (rf.reason === "plan-limit" || rf.reason === "max-files") {
skipped.push(rf);
+ } else if (rf.reason === "file-type") {
+ unsupported.push(rf);
} else {
failed.push(rf);
}
}
- return { skippedFiles: skipped, failedFiles: failed };
+ return {
+ skippedFiles: skipped,
+ unsupportedFiles: unsupported,
+ failedFiles: failed,
+ };
}, [rejectedFiles]);
const skippedCta = useMemo(() => {
@@ -343,31 +371,24 @@ export function UploadNotificationDrawer({
}, [skippedFiles]);
const handleDownloadSkipped = useCallback(() => {
- const allNames: string[] = [];
- for (const rf of skippedFiles) {
- if (rf.skippedFileNames?.length) {
- allNames.push(...rf.skippedFileNames);
- } else {
- allNames.push(rf.fileName);
- }
- }
- if (allNames.length === 0) return;
-
- const content = allNames.join("\n");
- const blob = new Blob([content], { type: "text/plain" });
- const url = URL.createObjectURL(blob);
- const a = document.createElement("a");
- a.href = url;
- a.download = "skipped-files.txt";
- a.click();
- URL.revokeObjectURL(url);
+ downloadRejectedFileNames(skippedFiles, "skipped-files.txt");
}, [skippedFiles]);
+ const handleDownloadUnsupported = useCallback(() => {
+ downloadRejectedFileNames(unsupportedFiles, "unsupported-files.txt");
+ }, [unsupportedFiles]);
+
const hasDownloadableSkipped = useMemo(
() => skippedFiles.some((rf) => rf.skippedFileNames?.length || rf.fileName),
[skippedFiles],
);
+ const hasDownloadableUnsupported = useMemo(
+ () =>
+ unsupportedFiles.some((rf) => rf.skippedFileNames?.length || rf.fileName),
+ [unsupportedFiles],
+ );
+
const timeLeftLabel = useMemo(() => {
if (!batch || isDone) return null;
const elapsed = Date.now() - batch.startedAt;
@@ -492,6 +513,24 @@ export function UploadNotificationDrawer({
/>
) : null}
+ {unsupportedFiles.length > 0 ? (
+ <CollapsibleSection
+ icon={
+ <AlertTriangleIcon className="h-3.5 w-3.5 text-amber-600 dark:text-amber-400" />
+ }
+ label="not uploaded (unsupported file type)"
+ count={unsupportedFiles.length}
+ colorClass="text-amber-600 dark:text-amber-400"
+ bgClass="bg-amber-50/60 dark:bg-amber-950/30"
+ items={unsupportedFiles}
+ onDownload={
+ hasDownloadableUnsupported
+ ? handleDownloadUnsupported
+ : undefined
+ }
+ />
+ ) : null}
+
{failedFiles.length > 0 ? (
<CollapsibleSection
icon={
diff --git a/components/upload-zone.tsx b/components/upload-zone.tsx
index 30ced175..63f55eec 100644
--- a/components/upload-zone.tsx
+++ b/components/upload-zone.tsx
@@ -67,7 +67,7 @@ interface FileWithPaths extends File {
export interface RejectedFile {
fileName: string;
message: string;
- reason?: "error" | "plan-limit" | "max-files";
+ reason?: "error" | "plan-limit" | "max-files" | "file-type";
/** Individual file paths skipped due to limits — used for downloadable list */
skippedFileNames?: string[];
}
@@ -590,18 +590,21 @@ export default function UploadZone({
return;
}
- const rejected = rejectedFiles.map(({ file, errors }) => {
+ const rejected = rejectedFiles.map<RejectedFile>(({ file, errors }) => {
let message = "";
+ let reason: RejectedFile["reason"] = "error";
if (errors.find(({ code }) => code === "file-too-large")) {
const fileSizeLimitMB = getFileSizeLimit(file.type, fileSizeLimits);
message = `File size too big (max. ${fileSizeLimitMB} MB). Upgrade to a paid plan to increase the limit.`;
} else if (errors.find(({ code }) => code === "file-invalid-type")) {
const isSupported = SUPPORTED_DOCUMENT_MIME_TYPES.includes(file.type);
- message = `File type not supported ${
- isFree && !isTrial && isSupported ? `on free plan` : ""
- }`;
+ // Supported on a paid plan but blocked on free → upgrading helps.
+ // Otherwise the type is simply unsupported and upgrading won't help.
+ const isPlanLimited = isFree && !isTrial && isSupported;
+ message = `File type not supported${isPlanLimited ? " on free plan" : ""}`;
+ reason = isPlanLimited ? "plan-limit" : "file-type";
}
- return { fileName: file.name, message };
+ return { fileName: file.name, message, reason };
});
onUploadRejected(rejected);
},
@@ -1598,15 +1601,18 @@ export default function UploadZone({
if (rejectedTypePerTopLevel.size > 0) {
const rejectedEntries: RejectedFile[] = [];
for (const [name, { paths, supportedOnPaid }] of rejectedTypePerTopLevel) {
+ // Only a genuine plan limit when the file type would be accepted on a
+ // paid plan and the user is actually on a free plan. Otherwise the
+ // type is simply unsupported, so upgrading wouldn't help.
+ const isPlanLimited = isFree && !isTrial && supportedOnPaid;
rejectedEntries.push({
fileName: `${name}: ${paths.length} file${
paths.length !== 1 ? "s" : ""
} not uploaded`,
- message:
- isFree && !isTrial && supportedOnPaid
- ? "File type not supported on free plan"
- : "File type not supported",
- reason: "plan-limit",
+ message: isPlanLimited
+ ? "File type not supported on free plan"
+ : "File type not supported",
+ reason: isPlanLimited ? "plan-limit" : "file-type",
skippedFileNames: paths,
});
}