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 nav button

Tim Wilson38bc760ca820
diff --git a/apps/web/ui/layout/sidebar/conversions/conversions-onboarding-popup.tsx b/apps/web/ui/layout/sidebar/conversions/conversions-onboarding-popup.tsx
new file mode 100644
index 0000000000..3b1d87cf9d
--- /dev/null
+++ b/apps/web/ui/layout/sidebar/conversions/conversions-onboarding-popup.tsx
@@ -0,0 +1,124 @@
+"use client";
+
+import { X } from "@/ui/shared/icons";
+import { Button } from "@dub/ui";
+import {
+ arrow,
+ autoUpdate,
+ FloatingArrow,
+ FloatingPortal,
+ offset,
+ shift,
+ useFloating,
+} from "@floating-ui/react";
+import { Play } from "lucide-react";
+import Link from "next/link";
+import { useRef } from "react";
+
+export function ConversionOnboardingPopup({
+ referenceElement,
+ onCTA,
+ onDismiss,
+}: {
+ referenceElement: HTMLDivElement | null;
+ onCTA: () => void;
+ onDismiss: () => void;
+}) {
+ const arrowRef = useRef<SVGSVGElement>(null);
+
+ const { refs, floatingStyles, context } = useFloating({
+ placement: "right-end",
+ strategy: "fixed",
+ whileElementsMounted(referenceEl, floatingEl, update) {
+ const cleanup = autoUpdate(referenceEl, floatingEl, update, {
+ // Not good for performance but keeps the arrow and floating element in the right spot
+ animationFrame: true,
+ });
+ return cleanup;
+ },
+ elements: {
+ reference: referenceElement,
+ },
+ middleware: [
+ offset({
+ mainAxis: 32,
+ crossAxis: 7,
+ }),
+ 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">
+ <Link
+ href="https://dub.co/help/article/dub-conversions"
+ target="_blank"
+ className="group relative flex aspect-video w-full items-center justify-center overflow-hidden rounded-md border border-neutral-200 bg-neutral-100"
+ >
+ {/* TODO: Add video thumbnail */}
+ {/* <Image
+ src=""
+ alt="Video thumbnail"
+ fill
+ className="object-cover"
+ /> */}
+ <div className="relative flex size-10 items-center justify-center rounded-full bg-neutral-900 ring-[6px] ring-black/5 transition-all duration-75 group-hover:ring-[8px] group-active:ring-[7px]">
+ <Play className="size-4 fill-current text-white" />
+ </div>
+ </Link>
+ <button
+ type="button"
+ onClick={onDismiss}
+ className="absolute right-2 top-2 rounded-md border border-neutral-200 bg-white p-1.5 shadow-sm transition-colors duration-75 hover:bg-neutral-50"
+ >
+ <X className="size-4 text-neutral-500" />
+ </button>
+ </div>
+ <h2 className="mt-4 text-sm font-semibold text-neutral-700">
+ Conversion tracking unlocked
+ </h2>
+ <p className="mt-1.5 text-xs text-neutral-500">
+ Follow our guides to get set up and track your short link
+ conversions
+ </p>
+ <div className="mt-4 grid w-full grid-cols-2 gap-2">
+ <Button
+ type="button"
+ variant="secondary"
+ className="h-7 text-xs"
+ text="Maybe later"
+ onClick={onDismiss}
+ />
+ <Button
+ type="button"
+ variant="primary"
+ className="h-7 text-xs"
+ text="View guides"
+ 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/conversions/conversions-onboarding.tsx b/apps/web/ui/layout/sidebar/conversions/conversions-onboarding.tsx
new file mode 100644
index 0000000000..37df46c890
--- /dev/null
+++ b/apps/web/ui/layout/sidebar/conversions/conversions-onboarding.tsx
@@ -0,0 +1,73 @@
+"use client";
+
+import useWorkspace from "@/lib/swr/use-workspace";
+import {
+ STORE_KEYS,
+ useWorkspaceStore,
+} from "@/lib/workspace/use-workspace-store";
+import { X } from "@/ui/shared/icons";
+import { Book2Small, useMediaQuery } from "@dub/ui";
+import { ConversionOnboardingPopup } from "./conversions-onboarding-popup";
+
+export function ConversionsOnboarding({
+ referenceElement,
+}: {
+ referenceElement: HTMLDivElement | null;
+}) {
+ const { isMobile } = useMediaQuery();
+
+ const { salesUsage, salesLimit, loading } = useWorkspace({
+ swrOpts: { keepPreviousData: true },
+ });
+
+ const [
+ conversionsOnboarding,
+ setConversionsOnboarding,
+ { loading: loadingConversionsOnboarding },
+ ] = useWorkspaceStore<undefined | "nav-button" | "dismissed">(
+ STORE_KEYS.conversionsOnboarding,
+ );
+
+ const showConversionsOnboarding =
+ !loading &&
+ !loadingConversionsOnboarding &&
+ conversionsOnboarding !== "dismissed" &&
+ salesUsage === 0 &&
+ salesLimit &&
+ salesLimit > 0;
+
+ if (!showConversionsOnboarding) return null;
+
+ const showPopup = !isMobile && !conversionsOnboarding;
+
+ return showPopup ? (
+ <ConversionOnboardingPopup
+ referenceElement={referenceElement}
+ onCTA={() => {
+ alert("open modal");
+ setConversionsOnboarding("nav-button");
+ }}
+ onDismiss={() => setConversionsOnboarding("nav-button")}
+ />
+ ) : (
+ <div className="relative mt-3">
+ <button
+ type="button"
+ className="flex w-full items-center gap-2 rounded-md bg-neutral-900/5 px-2 py-1.5 text-xs text-neutral-600 transition-colors duration-100 hover:bg-neutral-900/10"
+ onClick={() => alert("open modal")}
+ >
+ <Book2Small className="size-3 text-neutral-800" />
+ View setup guides
+ </button>
+ <div className="absolute right-0 top-0 flex h-full items-center p-1">
+ <button
+ type="button"
+ className="rounded p-1 transition-colors duration-100 hover:bg-neutral-900/5"
+ onClick={() => setConversionsOnboarding("dismissed")}
+ >
+ <X className="size-3 text-neutral-500" />
+ </button>
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/ui/layout/sidebar/usage.tsx b/apps/web/ui/layout/sidebar/usage.tsx
index 099cf00e52..c1cef65a90 100644
--- a/apps/web/ui/layout/sidebar/usage.tsx
+++ b/apps/web/ui/layout/sidebar/usage.tsx
@@ -1,15 +1,9 @@
"use client";
import useWorkspace from "@/lib/swr/use-workspace";
-import {
- STORE_KEYS,
- useWorkspaceStore,
-} from "@/lib/workspace/use-workspace-store";
-import { X } from "@/ui/shared/icons";
import ManageSubscriptionButton from "@/ui/workspaces/manage-subscription-button";
import {
AnimatedSizeContainer,
- Button,
buttonVariants,
Icon,
useMediaQuery,
@@ -22,21 +16,13 @@ import {
INFINITY_NUMBER,
nFormatter,
} from "@dub/utils";
-import {
- arrow,
- autoUpdate,
- FloatingArrow,
- FloatingPortal,
- offset,
- shift,
- useFloating,
-} from "@floating-ui/react";
import NumberFlow from "@number-flow/react";
import { AnimatePresence, motion } from "framer-motion";
-import { ChevronRight, Play } from "lucide-react";
+import { ChevronRight } from "lucide-react";
import Link from "next/link";
import { useParams } from "next/navigation";
-import { CSSProperties, forwardRef, useMemo, useRef, useState } from "react";
+import { CSSProperties, forwardRef, useMemo, useState } from "react";
+import { ConversionsOnboarding } from "./conversions/conversions-onboarding";
export function Usage() {
const { slug } = useParams() as { slug?: string };
@@ -97,17 +83,6 @@ function UsageInner() {
const warning = warnings.some((w) => w);
const [salesRef, setSalesRef] = useState<HTMLDivElement | null>(null);
- const [
- conversionsOnboarding,
- setConversionsOnboarding,
- { loading: loadingConversionsOnboarding },
- ] = useWorkspaceStore<string>(STORE_KEYS.conversionsOnboarding);
-
- const showConversionOnboarding =
- salesUsage === 0 &&
- salesLimit &&
- salesLimit > 0 &&
- !loadingConversionsOnboarding;
return loading || usage !== undefined ? (
<>
@@ -156,6 +131,8 @@ function UsageInner() {
) : null}
</div>
+ <ConversionsOnboarding referenceElement={salesRef} />
+
<div className="mt-3">
{loading ? (
<div className="h-4 w-2/3 animate-pulse rounded-md bg-neutral-500/10" />
@@ -204,12 +181,6 @@ function UsageInner() {
) : null}
</div>
</AnimatedSizeContainer>
- {showConversionOnboarding && !isMobile && !conversionsOnboarding && (
- <ConversionOnboardingPopup
- reference={salesRef}
- onDismiss={() => setConversionsOnboarding("modal-dismissed")}
- />
- )}
</>
) : null;
}
@@ -351,112 +322,3 @@ const formatNumber = (value: number) =>
full: value !== undefined && value < 99999,
digits: 1,
});
-
-function ConversionOnboardingPopup({
- reference,
- onDismiss,
-}: {
- reference: HTMLDivElement | null;
- onDismiss: () => void;
-}) {
- const arrowRef = useRef<SVGSVGElement>(null);
-
- const { refs, floatingStyles, context } = useFloating({
- placement: "right-end",
- strategy: "fixed",
- whileElementsMounted(referenceEl, floatingEl, update) {
- const cleanup = autoUpdate(referenceEl, floatingEl, update, {
- // Not good for performance but keeps the arrow and floating element in the right spot
- animationFrame: true,
- });
- return cleanup;
- },
- elements: {
- reference,
- },
- middleware: [
- offset({
- mainAxis: 32,
- crossAxis: 7,
- }),
- 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">
- <Link
- href="https://dub.co/help/article/dub-conversions"
- target="_blank"
- className="group relative flex aspect-video w-full items-center justify-center overflow-hidden rounded-md border border-neutral-200 bg-neutral-100"
- >
- {/* TODO: Add video thumbnail */}
- {/* <Image
- src=""
- alt="Video thumbnail"
- fill
- className="object-cover"
- /> */}
- <div className="relative flex size-10 items-center justify-center rounded-full bg-neutral-900 ring-[6px] ring-black/5 transition-all duration-75 group-hover:ring-[8px] group-active:ring-[7px]">
- <Play className="size-4 fill-current text-white" />
- </div>
- </Link>
- <button
- type="button"
- onClick={onDismiss}
- className="absolute right-2 top-2 rounded-md border border-neutral-200 bg-white p-1.5 shadow-sm transition-colors duration-75 hover:bg-neutral-50"
- >
- <X className="size-4 text-neutral-500" />
- </button>
- </div>
- <h2 className="mt-4 text-sm font-semibold text-neutral-700">
- Conversion tracking unlocked
- </h2>
- <p className="mt-1.5 text-xs text-neutral-500">
- Follow our guides to get set up and track your short link
- conversions
- </p>
- <div className="mt-4 grid w-full grid-cols-2 gap-2">
- <Button
- type="button"
- variant="secondary"
- className="h-7 text-xs"
- text="Maybe later"
- onClick={onDismiss}
- />
- <Link
- href={`https://dub.co/help/article/dub-conversions`}
- target="_blank"
- className={cn(
- buttonVariants({ variant: "primary" }),
- "flex h-7 items-center justify-center whitespace-nowrap rounded-lg border px-3 text-sm text-xs",
- )}
- >
- View guides
- </Link>
- </div>
- <FloatingArrow
- ref={arrowRef}
- context={context}
- className="stroke-neutral-200"
- fill="white"
- strokeWidth={1}
- height={10}
- />
- </div>
- </div>
- </FloatingPortal>
- );
-}
diff --git a/packages/ui/src/icons/nucleo/book2-small.tsx b/packages/ui/src/icons/nucleo/book2-small.tsx
new file mode 100644
index 0000000000..61f80d2d3f
--- /dev/null
+++ b/packages/ui/src/icons/nucleo/book2-small.tsx
@@ -0,0 +1,43 @@
+import { SVGProps } from "react";
+
+export function Book2Small(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ height="12"
+ width="12"
+ viewBox="0 0 12 12"
+ xmlns="http://www.w3.org/2000/svg"
+ {...props}
+ >
+ <g fill="currentColor">
+ <path
+ d="m1.75,9.75h0c0,.828.672,1.5,1.5,1.5h7"
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <path
+ d="m1.75,9.75V2.25c0-.828.672-1.5,1.5-1.5h5.5c.828,0,1.5.672,1.5,1.5v6H3.25c-.828,0-1.5.672-1.5,1.5Z"
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <line
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="7.25"
+ x2="4.75"
+ y1="4.25"
+ y2="4.25"
+ />
+ </g>
+ </svg>
+ );
+}
diff --git a/packages/ui/src/icons/nucleo/index.ts b/packages/ui/src/icons/nucleo/index.ts
index 47ba97c9a0..7eb1ca1d46 100644
--- a/packages/ui/src/icons/nucleo/index.ts
+++ b/packages/ui/src/icons/nucleo/index.ts
@@ -13,6 +13,7 @@ export * from "./bolt-fill";
export * from "./book-open";
export * from "./book2";
export * from "./book2-fill";
+export * from "./book2-small";
export * from "./books2";
export * from "./box-archive";
export * from "./bullet-list";