Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
Add banner for uploaded excel files
Ashish Viradiya1a0608fa09f2
diff --git a/components/documents/alert.tsx b/components/documents/alert.tsxnew file mode 100644index 00000000..1a44cca8--- /dev/null+++ b/components/documents/alert.tsx@@ -0,0 +1,35 @@+import { AlertCircleIcon } from "lucide-react";++import {+ Alert,+ AlertClose,+ AlertDescription,+ AlertTitle,+} from "@/components/ui/alert";++interface AlertProps {+ id: string;+ variant: "default" | "destructive";+ title: string;+ description: React.ReactNode;+ onClose?: () => void;+}++const AlertBanner: React.FC<AlertProps> = ({+ id,+ variant,+ title,+ description,+ onClose,+}) => {+ return (+ <Alert id={id} variant={variant}>+ <AlertCircleIcon className="h-4 w-4" />+ <AlertTitle>{title}</AlertTitle>+ <AlertDescription>{description}</AlertDescription>+ <AlertClose onClick={onClose} />+ </Alert>+ );+};++export default AlertBanner;diff --git a/components/documents/document-header.tsx b/components/documents/document-header.tsxindex 574a081d..4173b043 100644--- a/components/documents/document-header.tsx+++ b/components/documents/document-header.tsx@@ -47,11 +47,11 @@ import PlanBadge from "../billing/plan-badge";import { PlanEnum, UpgradePlanModal } from "../billing/upgrade-plan-modal";import AdvancedSheet from "../shared/icons/advanced-sheet";import PortraitLandscape from "../shared/icons/portrait-landscape";-import { Alert, AlertClose, AlertDescription, AlertTitle } from "../ui/alert";import LoadingSpinner from "../ui/loading-spinner";import { ButtonTooltip } from "../ui/tooltip";import { AddDocumentModal } from "./add-document-modal";import { AddToDataroomModal } from "./add-document-to-dataroom-modal";+import AlertBanner from "./alert";export default function DocumentHeader({prismaDocument,@@ -80,6 +80,7 @@ export default function DocumentHeader({const [openAddDocModal, setOpenAddDocModal] = useState<boolean>(false);const [planModalOpen, setPlanModalOpen] = useState<boolean>(false);const [planModalTrigger, setPlanModalTrigger] = useState<string>("");+ const [selectedPlan, setSelectedPlan] = useState<PlanEnum>(PlanEnum.Pro);const nameRef = useRef<HTMLHeadingElement>(null);const enterPressedRef = useRef<boolean>(false);const dropdownRef = useRef<HTMLDivElement | null>(null);@@ -94,6 +95,19 @@ export default function DocumentHeader({}}+ const handleUpgradeClick = (plan: PlanEnum, trigger: string) => {+ setSelectedPlan(plan);+ setPlanModalTrigger(trigger);+ setPlanModalOpen(true);+ };++ const handleCloseAlert = (id: string) => {+ const alert = document.getElementById(id);+ if (alert) {+ alert.style.display = "none";+ }+ };+const currentTime = new Date();const formattedTime =currentTime.getFullYear() +@@ -273,6 +287,7 @@ export default function DocumentHeader({plausible("advancedExcelEnabled", {props: { documentId: document.id },}); // track the event+ handleCloseAlert("enable-advanced-excel-alert");toast.success(message);}} catch (error) {@@ -721,8 +736,10 @@ export default function DocumentHeader({<DropdownMenuItemonClick={() =>isFree- ? (setPlanModalTrigger("download-only-document"),- setPlanModalOpen(true))+ ? handleUpgradeClick(+ PlanEnum.Business,+ "download-only-document",+ ): toggleDownloadOnly()}>@@ -767,8 +784,10 @@ export default function DocumentHeader({<DropdownMenuItemonClick={() =>isFree- ? (setPlanModalTrigger("export-document-visits"),- setPlanModalOpen(true))+ ? handleUpgradeClick(+ PlanEnum.Business,+ "export-document-visits",+ ): exportVisitCounts(prismaDocument)}>@@ -802,34 +821,77 @@ export default function DocumentHeader({</div></div>- {isFree && prismaDocument.hasPageLinks ? (- <Alert id="in-document-links-alert" variant="destructive">- <AlertCircleIcon className="h-4 w-4" />- <AlertTitle>In-document links detected</AlertTitle>- <AlertDescription>- External in-document links are not available on the free plan.- Upgrade to a{" "}- <span- className="cursor-pointer underline underline-offset-4 hover:text-destructive/80"- onClick={() => {- setPlanModalTrigger("in-document-links");- setPlanModalOpen(true);- }}- >- higher plan- </span>{" "}- to use this feature.- </AlertDescription>- <AlertClose- onClick={() => {- const alert = document.getElementById("in-document-links-alert");- if (alert) {- alert.style.display = "none";- }- }}+ {isFree && prismaDocument.hasPageLinks && (+ <AlertBanner+ id="in-document-links-alert"+ variant="destructive"+ title="In-document links detected"+ description={+ <>+ External in-document links are not available on the free plan.{" "}+ <span+ className="cursor-pointer underline underline-offset-4 hover:text-destructive/80"+ onClick={() =>+ handleUpgradeClick(PlanEnum.Pro, "in-document-links")+ }+ >+ Upgrade+ </span>{" "}+ to a higher plan to use this feature.+ </>+ }+ onClose={() => handleCloseAlert("in-document-links-alert")}+ />+ )}++ {prismaDocument.type === "sheet" && (isFree || plan === "pro") && (+ <AlertBanner+ id="advanced-excel-alert"+ variant="default"+ title="Advanced Excel mode"+ description={+ <>+ You can turn on advanced excel mode by{" "}+ <span+ className="cursor-pointer underline underline-offset-4 hover:text-primary/80"+ onClick={() =>+ handleUpgradeClick(PlanEnum.Business, "advanced-excel-mode")+ }+ >+ upgrading+ </span>{" "}+ to Business to improve the file formatting.+ <br />+ The advanced mode uses Microsoft viewer.+ </>+ }+ onClose={() => handleCloseAlert("advanced-excel-alert")}+ />+ )}++ {prismaDocument.type === "sheet" &&+ !prismaDocument.advancedExcelEnabled &&+ (plan === "business" || plan === "datarooms" || isTrial) && (+ <AlertBanner+ id="enable-advanced-excel-alert"+ variant="default"+ title="Advanced Excel mode"+ description={+ <>+ You can{" "}+ <span+ className="cursor-pointer underline underline-offset-4 hover:text-primary/80"+ onClick={() => setMenuOpen(true)}+ >+ turn on+ </span>{" "}+ advanced excel mode to improve the file formatting.+ <br /> The advanced mode uses Microsoft viewer.+ </>+ }+ onClose={() => handleCloseAlert("enable-advanced-excel-alert")}/>- </Alert>- ) : null}+ )}{addDataRoomOpen ? (<AddToDataroomModal@@ -842,7 +904,7 @@ export default function DocumentHeader({{planModalOpen ? (<UpgradePlanModal- clickedPlan={PlanEnum.Pro}+ clickedPlan={selectedPlan}trigger={planModalTrigger}open={planModalOpen}setOpen={setPlanModalOpen}diff --git a/components/ui/alert.tsx b/components/ui/alert.tsxindex ed52479f..85dbb17c 100644--- a/components/ui/alert.tsx+++ b/components/ui/alert.tsx@@ -6,7 +6,7 @@ import { X } from "lucide-react";import { cn } from "@/lib/utils";const alertVariants = cva(- "relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground",+ "relative w-full rounded-lg border p-4 [&>svg~*:not(button)]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground",{variants: {variant: {