Skip to content

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

feat: add upgrade button to export analytics

Marc Seitz21792bfab729
diff --git a/components/analytics/documents-table.tsx b/components/analytics/documents-table.tsx
index 1f3bc579..c4b93f3e 100644
--- a/components/analytics/documents-table.tsx
+++ b/components/analytics/documents-table.tsx
@@ -35,9 +35,13 @@ import {
} from "@/components/ui/table";
import { DataTablePagination } from "@/components/visitors/data-table-pagination";
+import { usePlan } from "@/lib/swr/use-billing";
import { fetcher, timeAgo } from "@/lib/utils";
import { downloadCSV } from "@/lib/utils/csv";
+import { PlanEnum } from "../billing/upgrade-plan-modal";
+import { UpgradePlanModal } from "../billing/upgrade-plan-modal";
+
interface Document {
id: string;
name: string;
@@ -164,6 +168,8 @@ export default function DocumentsTable({
}) {
const router = useRouter();
const teamInfo = useTeam();
+ const { plan, isTrial } = usePlan();
+ const isFree = plan === "free";
const [sorting, setSorting] = useState<SortingState>([
{ id: "lastViewed", desc: true },
]);
@@ -191,6 +197,11 @@ export default function DocumentsTable({
});
const handleExport = () => {
+ if (isFree && !isTrial) {
+ toast.error("Please upgrade to export data");
+ return;
+ }
+
if (!documents?.length) {
toast.error("No data to export");
return;
@@ -208,13 +219,36 @@ export default function DocumentsTable({
downloadCSV(exportData, "documents");
};
- return (
- <div className="space-y-4">
- <div className="flex justify-end">
+ const UpgradeOrExportButton = () => {
+ const [open, setOpen] = useState(false);
+ if (isFree && !isTrial) {
+ return (
+ <>
+ <Button variant="outline" size="sm" onClick={() => setOpen(true)}>
+ Upgrade to Export
+ </Button>
+ <UpgradePlanModal
+ clickedPlan={PlanEnum.Pro}
+ trigger="dashboard_documents_export"
+ open={open}
+ setOpen={setOpen}
+ />
+ </>
+ );
+ } else {
+ return (
<Button variant="outline" size="sm" onClick={handleExport}>
<Download className="!size-4" />
Export
</Button>
+ );
+ }
+ };
+
+ return (
+ <div className="space-y-4">
+ <div className="flex justify-end">
+ <UpgradeOrExportButton />
</div>
<div className="rounded-xl border">
<Table>
diff --git a/components/analytics/links-table.tsx b/components/analytics/links-table.tsx
index df8472e5..f25b9712 100644
--- a/components/analytics/links-table.tsx
+++ b/components/analytics/links-table.tsx
@@ -37,10 +37,14 @@ import {
} from "@/components/ui/table";
import { DataTablePagination } from "@/components/visitors/data-table-pagination";
+import { usePlan } from "@/lib/swr/use-billing";
import { cn, timeAgo } from "@/lib/utils";
import { fetcher } from "@/lib/utils";
import { downloadCSV } from "@/lib/utils/csv";
+import { UpgradePlanModal } from "../billing/upgrade-plan-modal";
+import { PlanEnum } from "../billing/upgrade-plan-modal";
+
interface Link {
id: string;
name: string;
@@ -225,8 +229,9 @@ export default function LinksTable({
endDate: Date;
}) {
const router = useRouter();
-
const teamInfo = useTeam();
+ const { plan, isTrial } = usePlan();
+ const isFree = plan === "free";
const [sorting, setSorting] = useState<SortingState>([
{ id: "lastViewed", desc: true },
]);
@@ -254,6 +259,11 @@ export default function LinksTable({
});
const handleExport = () => {
+ if (isFree && !isTrial) {
+ toast.error("Please upgrade to export data");
+ return;
+ }
+
if (!links?.length) {
toast.error("No data to export");
return;
@@ -273,13 +283,36 @@ export default function LinksTable({
downloadCSV(exportData, "links");
};
- return (
- <div className="space-y-4">
- <div className="flex justify-end">
+ const UpgradeOrExportButton = () => {
+ const [open, setOpen] = useState(false);
+ if (isFree && !isTrial) {
+ return (
+ <>
+ <Button variant="outline" size="sm" onClick={() => setOpen(true)}>
+ Upgrade to Export
+ </Button>
+ <UpgradePlanModal
+ clickedPlan={PlanEnum.Pro}
+ trigger="dashboard_links_export"
+ open={open}
+ setOpen={setOpen}
+ />
+ </>
+ );
+ } else {
+ return (
<Button variant="outline" size="sm" onClick={handleExport}>
<Download className="!size-4" />
Export
</Button>
+ );
+ }
+ };
+
+ return (
+ <div className="space-y-4">
+ <div className="flex justify-end">
+ <UpgradeOrExportButton />
</div>
<div className="rounded-xl border">
<Table>
diff --git a/components/analytics/time-range-select.tsx b/components/analytics/time-range-select.tsx
index 1238cb5d..4f3c17ee 100644
--- a/components/analytics/time-range-select.tsx
+++ b/components/analytics/time-range-select.tsx
@@ -1,7 +1,7 @@
import { useEffect, useState } from "react";
import { differenceInDays, format, startOfDay, subDays } from "date-fns";
-import { CalendarIcon, ChevronDown } from "lucide-react";
+import { CalendarIcon, ChevronDown, CrownIcon } from "lucide-react";
import { DateRange } from "react-day-picker";
import { toast } from "sonner";
@@ -15,6 +15,9 @@ import {
import { cn } from "@/lib/utils";
+import { PlanEnum } from "../billing/upgrade-plan-modal";
+import { UpgradePlanModal } from "../billing/upgrade-plan-modal";
+
const TIME_RANGES = [
{ value: "24h", label: "Last 24 hours", shortcut: "D" },
{ value: "7d", label: "Last 7 days", shortcut: "W" },
@@ -172,20 +175,25 @@ export function TimeRangeSelect({
</div>
<div className="flex flex-col gap-2">
<div className="grid gap-1">
- {TIME_RANGES.map((range) => (
- <Button
- key={range.value}
- variant={range.value === value ? "secondary" : "ghost"}
- className="justify-between"
- onClick={() => handleSelectOption(range.value)}
- disabled={!isPremium && range.value === "custom"}
- >
- <span>{range.label}</span>
- {/* <kbd className="pointer-events-none inline-flex h-5 select-none items-center gap-1 rounded border bg-muted px-1.5 font-mono text-[10px] font-medium text-muted-foreground opacity-100">
- {range.shortcut}
- </kbd> */}
- </Button>
- ))}
+ {TIME_RANGES.map((range) => {
+ if (isPremium || range.value !== "custom") {
+ return (
+ <Button
+ key={range.value}
+ variant={range.value === value ? "secondary" : "ghost"}
+ className="justify-between"
+ onClick={() => handleSelectOption(range.value)}
+ >
+ <span>{range.label}</span>
+ {/* <kbd className="pointer-events-none inline-flex h-5 select-none items-center gap-1 rounded border bg-muted px-1.5 font-mono text-[10px] font-medium text-muted-foreground opacity-100">
+ {range.shortcut}
+ </kbd> */}
+ </Button>
+ );
+ } else {
+ return <UpgradeButton />;
+ }
+ })}
</div>
</div>
</div>
@@ -193,3 +201,26 @@ export function TimeRangeSelect({
</Popover>
);
}
+
+const UpgradeButton = () => {
+ const [open, setOpen] = useState(false);
+
+ return (
+ <>
+ <Button
+ variant="ghost"
+ className="justify-between text-muted-foreground"
+ onClick={() => setOpen(true)}
+ title="Upgrade to view data beyond 30 days"
+ >
+ Custom Date <CrownIcon className="!size-4" />
+ </Button>
+ <UpgradePlanModal
+ clickedPlan={PlanEnum.Pro}
+ trigger="dashboard_time_range_custom_select"
+ open={open}
+ setOpen={setOpen}
+ />
+ </>
+ );
+};
diff --git a/components/analytics/views-table.tsx b/components/analytics/views-table.tsx
index f4a38864..1e5e4038 100644
--- a/components/analytics/views-table.tsx
+++ b/components/analytics/views-table.tsx
@@ -56,9 +56,13 @@ import VisitorCustomFields from "@/components/visitors/visitor-custom-fields";
import VisitorUserAgent from "@/components/visitors/visitor-useragent";
import VisitorVideoChart from "@/components/visitors/visitor-video-chart";
+import { usePlan } from "@/lib/swr/use-billing";
import { cn, durationFormat, fetcher, timeAgo } from "@/lib/utils";
import { downloadCSV } from "@/lib/utils/csv";
+import { UpgradePlanModal } from "../billing/upgrade-plan-modal";
+import { PlanEnum } from "../billing/upgrade-plan-modal";
+
interface View {
id: string;
viewerEmail: string | null;
@@ -283,6 +287,8 @@ export default function ViewsTable({
}) {
const router = useRouter();
const teamInfo = useTeam();
+ const { plan, isTrial } = usePlan();
+ const isFree = plan === "free";
const { interval = "7d" } = router.query;
const [sorting, setSorting] = useState<SortingState>([
{ id: "viewedAt", desc: true },
@@ -312,6 +318,11 @@ export default function ViewsTable({
});
const handleExport = () => {
+ if (isFree && !isTrial) {
+ toast.error("Please upgrade to export data");
+ return;
+ }
+
if (!views?.length) {
toast.error("No data to export");
return;
@@ -330,13 +341,36 @@ export default function ViewsTable({
downloadCSV(exportData, "views");
};
- return (
- <div className="space-y-4">
- <div className="flex justify-end">
+ const UpgradeOrExportButton = () => {
+ const [open, setOpen] = useState(false);
+ if (isFree && !isTrial) {
+ return (
+ <>
+ <Button variant="outline" size="sm" onClick={() => setOpen(true)}>
+ Upgrade to Export
+ </Button>
+ <UpgradePlanModal
+ clickedPlan={PlanEnum.Pro}
+ trigger="dashboard_views_export"
+ open={open}
+ setOpen={setOpen}
+ />
+ </>
+ );
+ } else {
+ return (
<Button variant="outline" size="sm" onClick={handleExport}>
<Download className="!size-4" />
Export
</Button>
+ );
+ }
+ };
+
+ return (
+ <div className="space-y-4">
+ <div className="flex justify-end">
+ <UpgradeOrExportButton />
</div>
<div className="rounded-xl border">
<Table>
diff --git a/components/analytics/visitors-table.tsx b/components/analytics/visitors-table.tsx
index 9d0d01dc..f51f62d8 100644
--- a/components/analytics/visitors-table.tsx
+++ b/components/analytics/visitors-table.tsx
@@ -38,9 +38,13 @@ import { BadgeTooltip } from "@/components/ui/tooltip";
import { DataTablePagination } from "@/components/visitors/data-table-pagination";
import { VisitorAvatar } from "@/components/visitors/visitor-avatar";
+import { usePlan } from "@/lib/swr/use-billing";
import { durationFormat, fetcher, timeAgo } from "@/lib/utils";
import { downloadCSV } from "@/lib/utils/csv";
+import { PlanEnum } from "../billing/upgrade-plan-modal";
+import { UpgradePlanModal } from "../billing/upgrade-plan-modal";
+
interface Visitor {
email: string;
viewerId: string | null;
@@ -212,6 +216,8 @@ export default function VisitorsTable({
}) {
const router = useRouter();
const teamInfo = useTeam();
+ const { plan, isTrial } = usePlan();
+ const isFree = plan === "free";
const { interval = "7d" } = router.query;
const [sorting, setSorting] = useState<SortingState>([
{ id: "lastActive", desc: true },
@@ -241,6 +247,11 @@ export default function VisitorsTable({
});
const handleExport = () => {
+ if (isFree && !isTrial) {
+ toast.error("Please upgrade to export data");
+ return;
+ }
+
if (!visitors?.length) {
toast.error("No data to export");
return;
@@ -258,13 +269,36 @@ export default function VisitorsTable({
downloadCSV(exportData, "visitors");
};
- return (
- <div className="space-y-4">
- <div className="flex justify-end">
+ const UpgradeOrExportButton = () => {
+ const [open, setOpen] = useState(false);
+ if (isFree && !isTrial) {
+ return (
+ <>
+ <Button variant="outline" size="sm" onClick={() => setOpen(true)}>
+ Upgrade to Export
+ </Button>
+ <UpgradePlanModal
+ clickedPlan={PlanEnum.Pro}
+ trigger="dashboard_visitors_export"
+ open={open}
+ setOpen={setOpen}
+ />
+ </>
+ );
+ } else {
+ return (
<Button variant="outline" size="sm" onClick={handleExport}>
<Download className="!size-4" />
Export
</Button>
+ );
+ }
+ };
+
+ return (
+ <div className="space-y-4">
+ <div className="flex justify-end">
+ <UpgradeOrExportButton />
</div>
<div className="rounded-xl border">
<Table>