Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Add referral program popup

Tim Wilsonddb0fda666f3
diff --git a/apps/web/app/app.dub.co/(dashboard)/layout.tsx b/apps/web/app/app.dub.co/(dashboard)/layout.tsx
index 49d9d10504..c3f053715e 100644
--- a/apps/web/app/app.dub.co/(dashboard)/layout.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/layout.tsx
@@ -18,7 +18,7 @@ export default async function Layout({ children }: { children: ReactNode }) {
sidebar={AppSidebarNav}
toolContent={
<>
- <ReferButton />
+ <ReferButton affiliatePopupEnabled={true} />
<HelpButtonRSC />
</>
}
diff --git a/apps/web/ui/layout/sidebar/affiliate-program-popup.tsx b/apps/web/ui/layout/sidebar/affiliate-program-popup.tsx
new file mode 100644
index 0000000000..284e04d8b1
--- /dev/null
+++ b/apps/web/ui/layout/sidebar/affiliate-program-popup.tsx
@@ -0,0 +1,106 @@
+"use client";
+
+import { BlurImage, Button } from "@dub/ui";
+import {
+ arrow,
+ autoUpdate,
+ FloatingArrow,
+ FloatingPortal,
+ offset,
+ shift,
+ useFloating,
+} from "@floating-ui/react";
+import { useRef } from "react";
+
+export function AffiliateProgramPopup({
+ referenceElement,
+ onCTA,
+ onDismiss,
+}: {
+ referenceElement: HTMLElement | null;
+ onCTA: () => void;
+ onDismiss: () => void;
+}) {
+ const arrowRef = useRef<SVGSVGElement>(null);
+
+ const { refs, floatingStyles, context } = useFloating({
+ placement: "bottom-start",
+ strategy: "fixed",
+ whileElementsMounted(referenceEl, floatingEl, update) {
+ return autoUpdate(referenceEl, floatingEl, update, {
+ // Not good for performance but keeps the arrow and floating element in the right spot
+ animationFrame: true,
+ });
+ },
+ elements: {
+ reference: referenceElement,
+ },
+ middleware: [
+ offset({
+ mainAxis: 12,
+ crossAxis: -10,
+ }),
+ shift({
+ padding: 32,
+ }),
+ arrow({
+ element: arrowRef,
+ }),
+ ],
+ });
+
+ return (
+ <FloatingPortal>
+ <div
+ ref={refs.setFloating}
+ style={floatingStyles}
+ className="drop-shadow-sm"
+ >
+ <div className="animate-slide-up-fade relative flex w-[244px] flex-col rounded-lg border border-neutral-200 bg-white p-3 text-left">
+ <div className="relative aspect-video w-full overflow-hidden rounded-md border border-neutral-200 bg-neutral-100">
+ <BlurImage
+ src="https://assets.dub.co/misc/affiliate-program-thumbnail.jpg"
+ alt="thumbnail"
+ fill
+ className="object-cover"
+ />
+ </div>
+ <h2 className="mt-4 text-sm font-semibold text-neutral-700">
+ New Dub Referrals
+ </h2>
+ <p className="mt-1.5 text-xs text-neutral-500">
+ You can share your love for Dub and{" "}
+ <strong className="font-medium">
+ earn 30% for each referral for up to 12 months
+ </strong>
+ .
+ </p>
+ <div className="mt-4 grid w-full grid-cols-2 gap-2">
+ <Button
+ type="button"
+ variant="secondary"
+ className="h-7 px-2.5 text-xs"
+ text="Maybe later"
+ onClick={onDismiss}
+ />
+ <Button
+ type="button"
+ variant="primary"
+ className="h-7 px-2.5 text-xs"
+ text="View referrals"
+ onClick={onCTA}
+ />
+ </div>
+ <FloatingArrow
+ ref={arrowRef}
+ context={context}
+ className="stroke-neutral-200"
+ fill="white"
+ strokeWidth={1}
+ height={10}
+ />
+ </div>
+ </div>
+ </FloatingPortal>
+ );
+}
diff --git a/apps/web/ui/layout/sidebar/refer-button.tsx b/apps/web/ui/layout/sidebar/refer-button.tsx
index 41b7147000..fee369fd8c 100644
--- a/apps/web/ui/layout/sidebar/refer-button.tsx
+++ b/apps/web/ui/layout/sidebar/refer-button.tsx
@@ -1,15 +1,55 @@
"use client";
+import { useLocalStorage, useMediaQuery } from "@dub/ui";
import { Gift } from "@dub/ui/icons";
import Link from "next/link";
+import { useRouter } from "next/navigation";
+import { useState } from "react";
+import { AffiliateProgramPopup } from "./affiliate-program-popup";
+
+export function ReferButton({
+ affiliatePopupEnabled = false,
+}: {
+ affiliatePopupEnabled?: boolean;
+}) {
+ const { width } = useMediaQuery();
+ const [linkRef, setLinkRef] = useState<HTMLAnchorElement | null>(null);
+
+ return (
+ <>
+ <Link
+ ref={affiliatePopupEnabled ? setLinkRef : undefined}
+ href="/account/settings/referrals"
+ className="animate-fade-in size-4 shrink-0 rounded-full"
+ >
+ <Gift className="size-4" />
+ </Link>
+ {affiliatePopupEnabled && width && width >= 768 && (
+ <AffiliateProgramPopupWrapper referenceElement={linkRef} />
+ )}
+ </>
+ );
+}
+
+function AffiliateProgramPopupWrapper({
+ referenceElement,
+}: {
+ referenceElement: HTMLAnchorElement | null;
+}) {
+ const router = useRouter();
+
+ const [show, setShow] = useLocalStorage(`show-affiliate-program-popup`, true);
+
+ if (!show) return null;
-export function ReferButton() {
return (
- <Link
- href="/account/settings/referrals"
- className="animate-fade-in size-4 shrink-0 rounded-full"
- >
- <Gift className="size-4" />
- </Link>
+ <AffiliateProgramPopup
+ referenceElement={referenceElement}
+ onCTA={() => {
+ setShow(false);
+ router.push("/account/settings/referrals");
+ }}
+ onDismiss={() => setShow(false)}
+ />
);
}