Skip to content

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

feat: Add Slack integration banner and logic

Cursor Agent7564f3940106
diff --git a/components/billing/slack-banner.tsx b/components/billing/slack-banner.tsx
new file mode 100644
index 00000000..d2879564
--- /dev/null
+++ b/components/billing/slack-banner.tsx
@@ -0,0 +1,60 @@
+import { Dispatch, SetStateAction } from "react";
+
+import { useRouter } from "next/router";
+import Cookies from "js-cookie";
+import { usePlausible } from "next-plausible";
+
+import X from "@/components/shared/icons/x";
+import { SlackIcon } from "@/components/shared/icons/slack-icon";
+import { Button } from "@/components/ui/button";
+
+export default function SlackBanner({
+ setShowSlackBanner,
+}: {
+ setShowSlackBanner: Dispatch<SetStateAction<boolean | null>>;
+}) {
+ const router = useRouter();
+ const plausible = usePlausible();
+
+ const handleHideBanner = () => {
+ setShowSlackBanner(false);
+ plausible("clickedHideSlackBanner");
+ Cookies.set("hideSlackBanner", "slack-banner", {
+ expires: 30, // Hide for 30 days
+ });
+ };
+
+ const handleConnectSlack = () => {
+ plausible("clickedSlackBanner");
+ router.push("/settings/slack");
+ };
+
+ return (
+ <aside className="relative mb-2 flex w-full flex-col justify-center rounded-lg border border-gray-700 bg-background p-4 text-foreground">
+ <button
+ type="button"
+ onClick={handleHideBanner}
+ className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground"
+ >
+ <X className="h-4 w-4" />
+ <span className="sr-only">Close</span>
+ </button>
+ <div className="flex items-center space-x-2">
+ <SlackIcon className="h-5 w-5" />
+ <span className="text-sm font-bold">Connect Slack</span>
+ </div>
+ <p className="my-4 text-sm">
+ Get notified in Slack when documents are viewed, downloaded, or accessed.
+ </p>
+ <div className="flex">
+ <Button
+ type="button"
+ className="grow"
+ onClick={handleConnectSlack}
+ >
+ Set up Slack
+ </Button>
+ </div>
+ </aside>
+ );
+}
\ No newline at end of file
diff --git a/components/sidebar/app-sidebar.tsx b/components/sidebar/app-sidebar.tsx
index 9d282f41..1b75201f 100644
--- a/components/sidebar/app-sidebar.tsx
+++ b/components/sidebar/app-sidebar.tsx
@@ -22,6 +22,7 @@ import {
import { usePlan } from "@/lib/swr/use-billing";
import useLimits from "@/lib/swr/use-limits";
+import { useSlackIntegration } from "@/lib/swr/use-slack-integration";
import { nFormatter } from "@/lib/utils";
import { NavMain } from "@/components/sidebar/nav-main";
@@ -38,6 +39,7 @@ import {
import ProAnnualBanner from "../billing/pro-annual-banner";
import ProBanner from "../billing/pro-banner";
+import SlackBanner from "../billing/slack-banner";
import { Progress } from "../ui/progress";
export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
@@ -46,6 +48,7 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
const [showProAnnualBanner, setShowProAnnualBanner] = useState<
boolean | null
>(null);
+ const [showSlackBanner, setShowSlackBanner] = useState<boolean | null>(null);
const { currentTeam, teams, setCurrentTeam, isLoading }: TeamContextType =
useTeam() || initialState;
const {
@@ -63,6 +66,11 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
const linksLimit = limits?.links;
const documentsLimit = limits?.documents;
+ // Check Slack integration status
+ const { integration: slackIntegration } = useSlackIntegration({
+ enabled: !!currentTeam?.id,
+ });
+
useEffect(() => {
if (Cookies.get("hideProBanner") !== "pro-banner") {
setShowProBanner(true);
@@ -74,6 +82,11 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
} else {
setShowProAnnualBanner(false);
}
+ if (Cookies.get("hideSlackBanner") !== "slack-banner") {
+ setShowSlackBanner(true);
+ } else {
+ setShowSlackBanner(false);
+ }
}, []);
const data = {
@@ -215,6 +228,12 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
<SidebarMenu className="group-data-[collapsible=icon]:hidden">
<SidebarMenuItem>
<div>
+ {/*
+ * Show Slack banner to all users if they haven't dismissed it and don't have Slack connected
+ */}
+ {!slackIntegration && showSlackBanner ? (
+ <SlackBanner setShowSlackBanner={setShowSlackBanner} />
+ ) : null}
{/*
* if user is free and showProBanner is true show pro banner
*/}