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.

Update analytics card UI

Tim Wilson88c052fd99a3
diff --git a/apps/web/ui/analytics/analytics-card.tsx b/apps/web/ui/analytics/analytics-card.tsx
new file mode 100644
index 0000000000..29512aa318
--- /dev/null
+++ b/apps/web/ui/analytics/analytics-card.tsx
@@ -0,0 +1,133 @@
+import useWorkspace from "@/lib/swr/use-workspace";
+import {
+ Crosshairs,
+ CursorRays,
+ InvoiceDollar,
+ Modal,
+ TabSelect,
+} from "@dub/ui";
+import { cn } from "@dub/utils";
+import {
+ ComponentType,
+ Dispatch,
+ ReactNode,
+ SVGProps,
+ SetStateAction,
+ useContext,
+ useMemo,
+ useState,
+} from "react";
+import { AnalyticsContext } from ".";
+
+type EventType = "clicks" | "leads" | "sales";
+
+export function AnalyticsCard<T extends string>({
+ tabs,
+ selectedTabId,
+ onSelectTab,
+ expandLimit,
+ hasMore,
+ children,
+ className,
+}: {
+ tabs: { id: T; label: string }[];
+ selectedTabId: T;
+ onSelectTab?: Dispatch<SetStateAction<T>> | ((tabId: T) => void);
+ expandLimit: number;
+ hasMore?: boolean;
+ children: (props: {
+ limit?: number;
+ event: EventType;
+ setShowModal: (show: boolean) => void;
+ }) => ReactNode;
+ className?: string;
+}) {
+ const { demo } = useContext(AnalyticsContext);
+ const { betaTester } = useWorkspace();
+
+ const [showModal, setShowModal] = useState(false);
+
+ const eventTabs: {
+ id: EventType;
+ icon: ComponentType<SVGProps<SVGSVGElement>>;
+ label: string;
+ }[] = useMemo(
+ () =>
+ (demo && betaTester) || true
+ ? [
+ { id: "clicks", icon: CursorRays, label: "Clicks" },
+ { id: "leads", icon: Crosshairs, label: "Leads" },
+ { id: "sales", icon: InvoiceDollar, label: "Sales" },
+ ]
+ : [{ id: "clicks", icon: CursorRays, label: "Clicks" }],
+ [demo, betaTester],
+ );
+
+ const [eventTab, setEventTab] = useState<EventType>("clicks");
+
+ const selectedTab = tabs.find(({ id }) => id === selectedTabId);
+
+ return (
+ <>
+ <Modal
+ showModal={showModal}
+ setShowModal={setShowModal}
+ className="max-w-lg"
+ >
+ <div className="border-b border-gray-200 px-6 py-4">
+ <h1 className="text-lg font-semibold">{selectedTab?.label}</h1>
+ </div>
+ {children({ event: eventTab, setShowModal })}
+ </Modal>
+ <div
+ className={cn(
+ "relative z-0 max-h-[520px] min-h-[320px] overflow-hidden border border-gray-200 bg-white sm:rounded-xl",
+ className,
+ )}
+ >
+ <div className="flex items-center justify-between border-b border-gray-200 px-4">
+ {/* Main tabs */}
+ <TabSelect
+ options={tabs}
+ selected={selectedTabId}
+ onSelect={onSelectTab}
+ />
+
+ {/* Event (clicks, leads, sales) tabs */}
+ <div className="flex gap-2">
+ {eventTabs.map(({ id, icon: Icon, label }) => (
+ <button
+ onClick={() => setEventTab(id)}
+ title={label}
+ className={cn(
+ "rounded-md border border-white p-2",
+ id === eventTab
+ ? "border-gray-200 bg-gray-100"
+ : "hover:bg-gray-100 active:border-gray-100",
+ )}
+ >
+ <Icon className="h-4 w-4" />
+ </button>
+ ))}
+ </div>
+ </div>
+ <div className="p-4">
+ {children({ limit: expandLimit, event: eventTab, setShowModal })}
+ </div>
+ {hasMore && (
+ <div className="absolute bottom-0 left-0 z-10 flex w-full items-end">
+ <div className="pointer-events-none absolute bottom-0 left-0 h-48 w-full bg-gradient-to-t from-white" />
+ <button
+ onClick={() => setShowModal(true)}
+ className="group relative flex w-full items-center justify-center py-4"
+ >
+ <div className="rounded-md border border-gray-200 bg-white px-2.5 py-1 text-sm text-gray-950 group-hover:bg-gray-100 group-active:border-gray-300">
+ View All
+ </div>
+ </button>
+ </div>
+ )}
+ </div>
+ </>
+ );
+}
diff --git a/apps/web/ui/analytics/bar-list.tsx b/apps/web/ui/analytics/bar-list.tsx
index 7bd9da7a13..7c8581fb87 100644
--- a/apps/web/ui/analytics/bar-list.tsx
+++ b/apps/web/ui/analytics/bar-list.tsx
@@ -60,7 +60,7 @@ export default function BarList({
const { isMobile } = useMediaQuery();
const bars = (
- <div className="grid gap-1">
+ <div className="grid gap-2">
{filteredData.map((data, idx) => (
<LineItem
key={idx}
@@ -130,7 +130,7 @@ export function LineItem({
}) {
const lineItem = useMemo(() => {
return (
- <div className="z-10 flex items-center space-x-2 px-2">
+ <div className="z-10 flex items-center space-x-4 px-3">
{icon}
<div
className={cn(
@@ -146,8 +146,8 @@ export function LineItem({
return (
<Link href={href} scroll={false} onClick={() => setShowModal(false)}>
- <div className="group flex items-center justify-between hover:bg-gray-50">
- <div className="relative z-10 flex h-8 w-full max-w-[calc(100%-2rem)] items-center">
+ <div className="group flex items-center justify-between">
+ <div className="relative z-10 flex h-10 w-full max-w-[calc(100%-2rem)] items-center">
{tab === "link" && linkData ? (
<Tooltip content={<LinkPreviewTooltip data={linkData} />}>
{lineItem}
@@ -166,7 +166,7 @@ export function LineItem({
width: `${(value / (maxValue || 0)) * 100}%`,
}}
className={cn(
- "absolute h-full origin-left rounded-sm",
+ "absolute h-full origin-left rounded-md group-hover:brightness-[97%] group-hover:saturate-150",
barBackground,
)}
transition={{ ease: "easeOut", duration: 0.3 }}
diff --git a/apps/web/ui/analytics/devices.tsx b/apps/web/ui/analytics/devices.tsx
index 8b1ef8d066..522a1d4879 100644
--- a/apps/web/ui/analytics/devices.tsx
+++ b/apps/web/ui/analytics/devices.tsx
@@ -1,79 +1,61 @@
import { SINGULAR_ANALYTICS_ENDPOINTS } from "@/lib/analytics/constants";
import { DeviceTabs } from "@/lib/analytics/types";
-import { Modal, TabSelect, useRouterStuff } from "@dub/ui";
-import { Maximize } from "lucide-react";
-import { useMemo, useState } from "react";
+import { useRouterStuff } from "@dub/ui";
+import { useState } from "react";
+import { AnalyticsCard } from "./analytics-card";
import { AnalyticsLoadingSpinner } from "./analytics-loading-spinner";
import BarList from "./bar-list";
import DeviceIcon from "./device-icon";
import { useAnalyticsFilterOption } from "./utils";
export default function Devices() {
- const [tab, setTab] = useState<DeviceTabs>("devices");
- const singularTabName = useMemo(
- () => SINGULAR_ANALYTICS_ENDPOINTS[tab],
- [tab],
- );
-
- const data = useAnalyticsFilterOption(tab);
-
const { queryParams } = useRouterStuff();
- const [showModal, setShowModal] = useState(false);
- const barList = (limit?: number) => (
- <BarList
- tab={singularTabName}
- data={
- data?.map((d) => ({
- icon: (
- <DeviceIcon
- display={d[singularTabName]}
- tab={tab}
- className="h-4 w-4"
- />
- ),
- title: d[singularTabName],
- href: queryParams({
- set: {
- [singularTabName]: d[singularTabName],
- },
- getNewPath: true,
- }) as string,
- value: d.count || 0,
- })) || []
- }
- maxValue={(data && data[0]?.count) || 0}
- barBackground="bg-green-100"
- setShowModal={setShowModal}
- {...(limit && { limit })}
- />
- );
+ const [tab, setTab] = useState<DeviceTabs>("devices");
+ const data = useAnalyticsFilterOption(tab);
+ const singularTabName = SINGULAR_ANALYTICS_ENDPOINTS[tab];
return (
- <>
- <Modal
- showModal={showModal}
- setShowModal={setShowModal}
- className="max-w-lg"
- >
- <div className="border-b border-gray-200 px-6 py-4">
- <h1 className="text-lg font-semibold">Devices</h1>
- </div>
- {barList()}
- </Modal>
- <div className="scrollbar-hide relative z-0 h-[400px] border border-gray-200 bg-white px-7 py-5 sm:rounded-xl">
- <div className="mb-3 flex justify-between">
- <h1 className="text-lg font-semibold">Devices</h1>
- <TabSelect
- options={["devices", "browsers", "os"]}
- selected={tab}
- // @ts-ignore
- selectAction={setTab}
- />
- </div>
- {data ? (
+ <AnalyticsCard
+ tabs={[
+ { id: "devices", label: "Devices" },
+ { id: "browsers", label: "Browsers" },
+ { id: "os", label: "OS" },
+ ]}
+ selectedTabId={tab}
+ onSelectTab={setTab}
+ expandLimit={8}
+ hasMore={(data?.length ?? 0) > 8}
+ >
+ {({ limit, event, setShowModal }) =>
+ data ? (
data.length > 0 ? (
- barList(9)
+ <BarList
+ tab={singularTabName}
+ data={
+ data?.map((d) => ({
+ icon: (
+ <DeviceIcon
+ display={d[singularTabName]}
+ tab={tab}
+ className="h-4 w-4"
+ />
+ ),
+ title: d[singularTabName],
+ href: queryParams({
+ set: {
+ [singularTabName]: d[singularTabName],
+ },
+ getNewPath: true,
+ }) as string,
+ value: d[event] || 0,
+ })) || []
+ }
+ maxValue={(data && data[0]?.[event]) || 0}
+ barBackground="bg-green-100"
+ setShowModal={setShowModal}
+ {...(limit && { limit })}
+ />
) : (
<div className="flex h-[300px] items-center justify-center">
<p className="text-sm text-gray-600">No data available</p>
@@ -83,17 +65,8 @@ export default function Devices() {
<div className="flex h-[300px] items-center justify-center">
<AnalyticsLoadingSpinner />
</div>
- )}
- {data && data.length > 9 && (
- <button
- onClick={() => setShowModal(true)}
- className="absolute inset-x-0 bottom-4 z-10 mx-auto flex w-full items-center justify-center space-x-2 rounded-md bg-gradient-to-b from-transparent to-white py-2 text-gray-500 transition-all hover:text-gray-800 active:scale-95"
- >
- <Maximize className="h-4 w-4" />
- <p className="text-xs font-semibold uppercase">View all</p>
- </button>
- )}
- </div>
- </>
+ )
+ }
+ </AnalyticsCard>
);
}
diff --git a/apps/web/ui/analytics/index.tsx b/apps/web/ui/analytics/index.tsx
index 04089899ef..4f3e890f7c 100644
--- a/apps/web/ui/analytics/index.tsx
+++ b/apps/web/ui/analytics/index.tsx
@@ -213,8 +213,8 @@ export default function Analytics({
<div className="mx-auto grid max-w-screen-xl gap-5 px-2.5 lg:px-20">
<Main />
<div className="grid grid-cols-1 gap-5 md:grid-cols-2">
- <Locations />
{!isPublicStatsPage && <TopLinks />}
+ <Locations />
<Devices />
<Referer />
{isPublicStatsPage && <TopLinks />}
diff --git a/apps/web/ui/analytics/locations.tsx b/apps/web/ui/analytics/locations.tsx
index 3b751fc68c..b30031f2e9 100644
--- a/apps/web/ui/analytics/locations.tsx
+++ b/apps/web/ui/analytics/locations.tsx
@@ -1,78 +1,59 @@
import { SINGULAR_ANALYTICS_ENDPOINTS } from "@/lib/analytics/constants";
-import { LocationTabs } from "@/lib/analytics/types";
-import { Modal, TabSelect, useRouterStuff } from "@dub/ui";
+import { useRouterStuff } from "@dub/ui";
import { COUNTRIES } from "@dub/utils";
-import { Maximize } from "lucide-react";
-import { useMemo, useState } from "react";
+import { useState } from "react";
+import { AnalyticsCard } from "./analytics-card";
import { AnalyticsLoadingSpinner } from "./analytics-loading-spinner";
import BarList from "./bar-list";
import { useAnalyticsFilterOption } from "./utils";
export default function Locations() {
- const [tab, setTab] = useState<LocationTabs>("countries");
- const singularTabName = useMemo(
- () => SINGULAR_ANALYTICS_ENDPOINTS[tab],
- [tab],
- );
-
- const data = useAnalyticsFilterOption(tab);
const { queryParams } = useRouterStuff();
- const [showModal, setShowModal] = useState(false);
- const barList = (limit?: number) => (
- <BarList
- tab={singularTabName}
- data={
- data?.map((d) => ({
- icon: (
- <img
- alt={d.country}
- src={`https://flag.vercel.app/m/${d.country}.svg`}
- className="h-3 w-5"
- />
- ),
- title: tab === "countries" ? COUNTRIES[d.country] : d.city,
- href: queryParams({
- set: {
- [singularTabName]: d[singularTabName],
- },
- getNewPath: true,
- }) as string,
- value: d.count || 0,
- })) || []
- }
- maxValue={(data && data[0]?.count) || 0}
- barBackground="bg-orange-100"
- setShowModal={setShowModal}
- {...(limit && { limit })}
- />
- );
+ const [tab, setTab] = useState<"countries" | "cities">("countries");
+ const data = useAnalyticsFilterOption(tab);
+ const singularTabName = SINGULAR_ANALYTICS_ENDPOINTS[tab];
return (
- <>
- <Modal
- showModal={showModal}
- setShowModal={setShowModal}
- className="max-w-lg"
- >
- <div className="border-b border-gray-200 px-6 py-4">
- <h1 className="text-lg font-semibold">Locations</h1>
- </div>
- {barList()}
- </Modal>
- <div className="scrollbar-hide relative z-0 h-[400px] border border-gray-200 bg-white px-7 py-5 sm:rounded-xl">
- <div className="mb-3 flex justify-between">
- <h1 className="text-lg font-semibold">Locations</h1>
- <TabSelect
- options={["countries", "cities"]}
- selected={tab}
- // @ts-ignore
- selectAction={setTab}
- />
- </div>
- {data ? (
+ <AnalyticsCard
+ tabs={[
+ { id: "countries", label: "Countries" },
+ { id: "cities", label: "Cities" },
+ ]}
+ selectedTabId={tab}
+ onSelectTab={setTab}
+ expandLimit={8}
+ hasMore={(data?.length ?? 0) > 8}
+ >
+ {({ limit, event, setShowModal }) =>
+ data ? (
data.length > 0 ? (
- barList(9)
+ <BarList
+ tab={singularTabName}
+ data={
+ data?.map((d) => ({
+ icon: (
+ <img
+ alt={d.country}
+ src={`https://flag.vercel.app/m/${d.country}.svg`}
+ className="h-3 w-5"
+ />
+ ),
+ title: tab === "countries" ? COUNTRIES[d.country] : d.city,
+ href: queryParams({
+ set: {
+ [singularTabName]: d[singularTabName],
+ },
+ getNewPath: true,
+ }) as string,
+ value: d[event] || 0,
+ })) || []
+ }
+ maxValue={(data && data[0]?.[event]) || 0}
+ barBackground="bg-blue-100"
+ setShowModal={setShowModal}
+ {...(limit && { limit })}
+ />
) : (
<div className="flex h-[300px] items-center justify-center">
<p className="text-sm text-gray-600">No data available</p>
@@ -82,17 +63,8 @@ export default function Locations() {
<div className="flex h-[300px] items-center justify-center">
<AnalyticsLoadingSpinner />
</div>
- )}
- {data && data.length > 9 && (
- <button
- onClick={() => setShowModal(true)}
- className="absolute inset-x-0 bottom-4 z-10 mx-auto flex w-full items-center justify-center space-x-2 rounded-md bg-gradient-to-b from-transparent to-white py-2 text-gray-500 transition-all hover:text-gray-800 active:scale-95"
- >
- <Maximize className="h-4 w-4" />
- <p className="text-xs font-semibold uppercase">View all</p>
- </button>
- )}
- </div>
- </>
+ )
+ }
+ </AnalyticsCard>
);
}
diff --git a/apps/web/ui/analytics/referer.tsx b/apps/web/ui/analytics/referer.tsx
index 6b24cc2e11..ad50107e7c 100644
--- a/apps/web/ui/analytics/referer.tsx
+++ b/apps/web/ui/analytics/referer.tsx
@@ -2,11 +2,12 @@ import { BlurImage, Modal, useRouterStuff } from "@dub/ui";
import { GOOGLE_FAVICON_URL } from "@dub/utils";
import { Link2, Maximize } from "lucide-react";
import { useState } from "react";
+import { AnalyticsCard } from "./analytics-card";
import { AnalyticsLoadingSpinner } from "./analytics-loading-spinner";
import BarList from "./bar-list";
import { useAnalyticsFilterOption } from "./utils";
-export default function Referer() {
+function RefererOld() {
const data = useAnalyticsFilterOption("referers");
const { queryParams } = useRouterStuff();
@@ -88,3 +89,64 @@ export default function Referer() {
</>
);
}
+
+export default function Referer() {
+ const { queryParams } = useRouterStuff();
+
+ const data = useAnalyticsFilterOption("referers");
+
+ return (
+ <AnalyticsCard
+ tabs={[{ id: "referers", label: "Referers" }]}
+ selectedTabId={"referers"}
+ expandLimit={8}
+ hasMore={(data?.length ?? 0) > 8}
+ >
+ {({ limit, event, setShowModal }) =>
+ data ? (
+ data.length > 0 ? (
+ <BarList
+ tab="Referrer"
+ data={
+ data?.map((d) => ({
+ icon:
+ d.referer === "(direct)" ? (
+ <Link2 className="h-4 w-4" />
+ ) : (
+ <BlurImage
+ src={`${GOOGLE_FAVICON_URL}${d.referer}`}
+ alt={d.referer}
+ width={20}
+ height={20}
+ className="h-4 w-4 rounded-full"
+ />
+ ),
+ title: d.referer,
+ href: queryParams({
+ set: {
+ referer: d.referer,
+ },
+ getNewPath: true,
+ }) as string,
+ value: d[event] || 0,
+ })) || []
+ }
+ maxValue={(data && data[0]?.[event]) || 0}
+ barBackground="bg-red-100"
+ setShowModal={setShowModal}
+ {...(limit && { limit })}
+ />
+ ) : (
+ <div className="flex h-[300px] items-center justify-center">
+ <p className="text-sm text-gray-600">No data available</p>
+ </div>
+ )
+ ) : (
+ <div className="flex h-[300px] items-center justify-center">
+ <AnalyticsLoadingSpinner />
+ </div>
+ )
+ }
+ </AnalyticsCard>
+ );
+}
diff --git a/apps/web/ui/analytics/top-links.tsx b/apps/web/ui/analytics/top-links.tsx
index e7aad5558b..dcca98c527 100644
--- a/apps/web/ui/analytics/top-links.tsx
+++ b/apps/web/ui/analytics/top-links.tsx
@@ -1,133 +1,95 @@
-import { TopLinksTabs } from "@/lib/analytics/types";
-import { Modal, TabSelect, useRouterStuff } from "@dub/ui";
-import { getApexDomain, linkConstructor, truncate } from "@dub/utils";
-import { Maximize, X } from "lucide-react";
-import Link from "next/link";
+import { useRouterStuff } from "@dub/ui";
+import { getApexDomain } from "@dub/utils";
import { useSearchParams } from "next/navigation";
-import { useContext, useEffect, useState } from "react";
+import { useContext } from "react";
import { AnalyticsContext } from ".";
import LinkLogo from "../links/link-logo";
+import { AnalyticsCard } from "./analytics-card";
import { AnalyticsLoadingSpinner } from "./analytics-loading-spinner";
import BarList from "./bar-list";
import { useAnalyticsFilterOption } from "./utils";
export default function TopLinks() {
- const [tab, setTab] = useState<TopLinksTabs>("link");
-
- const { basePath, domain, key } = useContext(AnalyticsContext);
-
- useEffect(() => {
- if (domain && key) {
- setTab("url");
- } else {
- setTab("link");
- }
- }, [domain, key]);
-
- const data = useAnalyticsFilterOption(`top_${tab}s`);
-
const { queryParams } = useRouterStuff();
const searchParams = useSearchParams();
const root = searchParams.get("root");
- const [showModal, setShowModal] = useState(false);
- const barList = (limit?: number) => (
- <BarList
- tab={tab}
- data={
- data?.map((d) => ({
- icon: (
- <LinkLogo
- apexDomain={getApexDomain(d.url)}
- className="h-5 w-5 sm:h-5 sm:w-5"
- />
- ),
- title:
- tab === "link" && d["shortLink"]
- ? d["shortLink"].replace(/^https?:\/\//, "")
- : d.url,
- href: queryParams({
- set: {
- ...(tab === "link"
- ? { domain: d.domain, key: d.key || "_root" }
- : {
- url: d.url,
- }),
- },
- getNewPath: true,
- }) as string,
- value: d.count || 0,
- ...(tab === "link" && { linkData: d }),
- })) || []
- }
- maxValue={(data && data[0]?.count) || 0}
- barBackground="bg-blue-100"
- setShowModal={setShowModal}
- {...(limit && { limit })}
- />
- );
+ const { domain, key } = useContext(AnalyticsContext);
+ const showUrls = domain && key;
+
+ const data = useAnalyticsFilterOption(`top_${showUrls ? "urls" : "links"}`);
return (
- <>
- <Modal
- showModal={showModal}
- setShowModal={setShowModal}
- className="max-w-lg"
- >
- <div className="border-b border-gray-200 px-6 py-4">
- <h1 className="text-lg font-semibold">
- {tab === "link" ? "Links" : "URLs"}
- </h1>
- </div>
- {barList()}
- </Modal>
- <div className="scrollbar-hide relative z-0 h-[400px] border border-gray-200 bg-white px-7 py-5 sm:rounded-xl">
- <div className="mb-3 flex justify-between">
- <h1 className="text-lg font-semibold capitalize">
- {tab === "link" ? "Links" : "URLs"}
- </h1>
- {domain && key ? (
- !basePath.startsWith("/stats") && (
- <Link
- className="flex items-center space-x-1 rounded-lg border border-gray-200 bg-gray-50 px-3 py-1 text-sm text-gray-500 transition-all hover:bg-gray-100"
- href={
- queryParams({
- del: ["domain", "key"],
+ <AnalyticsCard
+ tabs={
+ showUrls
+ ? [{ id: "urls", label: "URLs" }]
+ : [
+ { id: "links", label: "Links" },
+ { id: "domains", label: "Domains" },
+ ]
+ }
+ expandLimit={8}
+ hasMore={(data?.length ?? 0) > 8}
+ selectedTabId={
+ showUrls
+ ? "urls"
+ : root === "false"
+ ? "links"
+ : root === "true"
+ ? "domains"
+ : "links"
+ }
+ onSelectTab={(tabId) =>
+ queryParams({
+ ...((root === "false" && tabId === "links") ||
+ (root === "true" && tabId === "domains")
+ ? { del: ["root"] }
+ : {
+ set: {
+ root: tabId === "links" ? "false" : "true",
+ },
+ }),
+ replace: true,
+ })
+ }
+ >
+ {({ limit, event, setShowModal }) =>
+ data ? (
+ data.length > 0 ? (
+ <BarList
+ tab={showUrls ? "url" : "link"}
+ data={
+ data?.map((d) => ({
+ icon: (
+ <LinkLogo
+ apexDomain={getApexDomain(d.url)}
+ className="h-5 w-5 sm:h-5 sm:w-5"
+ />
+ ),
+ title:
+ !showUrls && d["shortLink"]
+ ? d["shortLink"].replace(/^https?:\/\//, "")
+ : d.url,
+ href: queryParams({
+ set: {
+ ...(!showUrls
+ ? { domain: d.domain, key: d.key || "_root" }
+ : {
+ url: d.url,
+ }),
+ },
getNewPath: true,
- }) as string
- }
- >
- <strong className="text-gray-800">
- {truncate(linkConstructor({ domain, key, pretty: true }), 24)}
- </strong>
- <X className="h-4 w-4" />
- </Link>
- )
- ) : (
- <TabSelect
- options={["Links", "Domains"]}
- selected={
- root === "false" ? "Links" : root === "true" ? "Domains" : null
- }
- selectAction={(option) =>
- queryParams({
- ...((root === "false" && option === "Links") ||
- (root === "true" && option === "Domains")
- ? { del: ["root"] }
- : {
- set: {
- root: option === "Links" ? "false" : "true",
- },
- }),
- replace: true,
- })
+ }) as string,
+ value: d[event] || 0,
+ ...(!showUrls && { linkData: d }),
+ })) || []
}
+ maxValue={(data && data[0]?.[event]) || 0}
+ barBackground="bg-orange-100"
+ setShowModal={setShowModal}
+ {...(limit && { limit })}
/>
- )}
- </div>
- {data ? (
- data.length > 0 ? (
- barList(9)
) : (
<div className="flex h-[300px] items-center justify-center">
<p className="text-sm text-gray-600">No data available</p>
@@ -137,19 +99,8 @@ export default function TopLinks() {
<div className="flex h-[300px] items-center justify-center">
<AnalyticsLoadingSpinner />
</div>
- )}
- {data && data.length > 9 && (
- <button
- onClick={() => setShowModal(true)}
- className="absolute inset-x-0 bottom-4 z-10 mx-auto flex w-full items-center justify-center rounded-md bg-gradient-to-b from-transparent to-white text-gray-500 transition-all hover:text-gray-800 active:scale-95"
- >
- <div className="flex items-center space-x-1 bg-white px-4 py-2">
- <Maximize className="h-4 w-4" />
- <p className="text-xs font-semibold uppercase">View all</p>
- </div>
- </button>
- )}
- </div>
- </>
+ )
+ }
+ </AnalyticsCard>
);
}
diff --git a/packages/ui/src/icons/index.tsx b/packages/ui/src/icons/index.tsx
index 5578775cd5..ecdc52186f 100644
--- a/packages/ui/src/icons/index.tsx
+++ b/packages/ui/src/icons/index.tsx
@@ -20,3 +20,6 @@ export { default as ProductHunt } from "./product-hunt";
export { default as Twitter } from "./twitter";
export { default as Unsplash } from "./unsplash";
export { default as YouTube } from "./youtube";
+
+// Nucleo icons
+export * from "./nucleo";
diff --git a/packages/ui/src/icons/nucleo/crosshairs.tsx b/packages/ui/src/icons/nucleo/crosshairs.tsx
new file mode 100644
index 0000000000..74e76e17c8
--- /dev/null
+++ b/packages/ui/src/icons/nucleo/crosshairs.tsx
@@ -0,0 +1,80 @@
+import { SVGProps } from "react";
+
+export function Crosshairs(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ height="18"
+ width="18"
+ viewBox="0 0 18 18"
+ xmlns="http://www.w3.org/2000/svg"
+ {...props}
+ >
+ <g fill="#212121">
+ <circle
+ cx="9"
+ cy="9"
+ fill="none"
+ r="6.5"
+ stroke="#212121"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <circle
+ cx="9"
+ cy="9"
+ fill="none"
+ r="2.25"
+ stroke="#212121"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <line
+ fill="none"
+ stroke="#212121"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="9"
+ x2="9"
+ y1="1"
+ y2="2.5"
+ />
+ <line
+ fill="none"
+ stroke="#212121"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="17"
+ x2="15.5"
+ y1="9"
+ y2="9"
+ />
+ <line
+ fill="none"
+ stroke="#212121"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="9"
+ x2="9"
+ y1="17"
+ y2="15.5"
+ />
+ <line
+ fill="none"
+ stroke="#212121"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="1"
+ x2="2.5"
+ y1="9"
+ y2="9"
+ />
+ </g>
+ </svg>
+ );
+}
diff --git a/packages/ui/src/icons/nucleo/cursor-rays.tsx b/packages/ui/src/icons/nucleo/cursor-rays.tsx
new file mode 100644
index 0000000000..9f64e61194
--- /dev/null
+++ b/packages/ui/src/icons/nucleo/cursor-rays.tsx
@@ -0,0 +1,90 @@
+import { SVGProps } from "react";
+
+export function CursorRays(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ height="18"
+ width="18"
+ viewBox="0 0 18 18"
+ xmlns="http://www.w3.org/2000/svg"
+ {...props}
+ >
+ <g fill="#212121">
+ <path
+ d="M8.095,7.778l7.314,2.51c.222,.076,.226,.388,.007,.47l-3.279,1.233c-.067,.025-.121,.079-.146,.146l-1.233,3.279c-.083,.219-.394,.215-.47-.007l-2.51-7.314c-.068-.197,.121-.385,.318-.318Z"
+ fill="none"
+ stroke="#212121"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <line
+ fill="none"
+ stroke="#212121"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="12.031"
+ x2="16.243"
+ y1="12.031"
+ y2="16.243"
+ />
+ <line
+ fill="none"
+ stroke="#212121"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="7.75"
+ x2="7.75"
+ y1="1.75"
+ y2="3.75"
+ />
+ <line
+ fill="none"
+ stroke="#212121"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="11.993"
+ x2="10.578"
+ y1="3.507"
+ y2="4.922"
+ />
+ <line
+ fill="none"
+ stroke="#212121"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="3.507"
+ x2="4.922"
+ y1="11.993"
+ y2="10.578"
+ />
+ <line
+ fill="none"
+ stroke="#212121"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="1.75"
+ x2="3.75"
+ y1="7.75"
+ y2="7.75"
+ />
+ <line
+ fill="none"
+ stroke="#212121"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="3.507"
+ x2="4.922"
+ y1="3.507"
+ y2="4.922"
+ />
+ </g>
+ </svg>
+ );
+}
diff --git a/packages/ui/src/icons/nucleo/index.ts b/packages/ui/src/icons/nucleo/index.ts
new file mode 100644
index 0000000000..3f0fda4497
--- /dev/null
+++ b/packages/ui/src/icons/nucleo/index.ts
@@ -0,0 +1,3 @@
+export * from "./crosshairs";
+export * from "./cursor-rays";
+export * from "./invoice-dollar";
diff --git a/packages/ui/src/icons/nucleo/invoice-dollar.tsx b/packages/ui/src/icons/nucleo/invoice-dollar.tsx
new file mode 100644
index 0000000000..8d9b06b18f
--- /dev/null
+++ b/packages/ui/src/icons/nucleo/invoice-dollar.tsx
@@ -0,0 +1,54 @@
+import { SVGProps } from "react";
+
+export function InvoiceDollar(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ height="18"
+ width="18"
+ viewBox="0 0 18 18"
+ xmlns="http://www.w3.org/2000/svg"
+ {...props}
+ >
+ <g fill="#212121">
+ <path
+ d="M14.75,3.75v12.5l-2.75-1.5-3,1.5-3-1.5-2.75,1.5V3.75c0-1.105,.895-2,2-2h7.5c1.105,0,2,.895,2,2Z"
+ fill="none"
+ stroke="#212121"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <path
+ d="M10.724,6.556c-.374-.885-1.122-1.086-1.688-1.086-.526,0-1.907,.28-1.779,1.606,.09,.931,.967,1.277,1.734,1.414s1.88,.429,1.907,1.551c.023,.949-.83,1.597-1.861,1.597-.985,0-1.67-.383-1.934-1.25"
+ fill="none"
+ stroke="#212121"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <line
+ fill="none"
+ stroke="#212121"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="9"
+ x2="9"
+ y1="4.75"
+ y2="5.47"
+ />
+ <line
+ fill="none"
+ stroke="#212121"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="9"
+ x2="9"
+ y1="11.638"
+ y2="12.25"
+ />
+ </g>
+ </svg>
+ );
+}
diff --git a/packages/ui/src/tab-select.tsx b/packages/ui/src/tab-select.tsx
index 4b435319de..8df91fc498 100644
--- a/packages/ui/src/tab-select.tsx
+++ b/packages/ui/src/tab-select.tsx
@@ -1,41 +1,50 @@
import { cn } from "@dub/utils";
-import { motion } from "framer-motion";
+import { LayoutGroup, motion } from "framer-motion";
+import { Dispatch, SetStateAction, useId } from "react";
-export function TabSelect({
+export function TabSelect<T extends string>({
options,
selected,
- selectAction,
+ onSelect,
}: {
- options: string[];
+ options: { id: T; label: string }[];
selected: string | null;
- selectAction: (option: string) => void;
+ onSelect?: Dispatch<SetStateAction<T>> | ((id: T) => void);
}) {
+ const layoutGroupId = useId();
+
return (
- <div className="relative inline-flex items-center space-x-1">
- {options.map((option) => (
- <button
- key={option}
- className={cn(
- "relative z-10 px-3 py-1 text-sm font-medium capitalize",
- {
- "transition-all hover:text-gray-500": option !== selected,
- },
- )}
- onClick={() => selectAction(option)}
- >
- <p>
- {option === "devices" ? "Type" : option === "os" ? "OS" : option}
- </p>
- {option === selected && (
- <motion.div
- layoutId={options.join("-")}
- className="absolute left-0 top-0 h-full w-full rounded-lg border border-gray-200 bg-gray-50"
- style={{ zIndex: -1 }}
- transition={{ duration: 0.25 }}
- />
- )}
- </button>
- ))}
+ <div className="flex text-sm">
+ <LayoutGroup id={layoutGroupId}>
+ {options.map(({ id, label }) => (
+ <div className="relative">
+ <button
+ type="button"
+ onClick={() => onSelect?.(id)}
+ className={cn(
+ "px-3 py-4 transition-colors duration-75",
+ id === selected
+ ? "text-black"
+ : "text-gray-400 hover:text-gray-500",
+ )}
+ aria-selected={id === selected}
+ >
+ {label}
+ </button>
+ {id === selected && (
+ <motion.div
+ layoutId="indicator"
+ transition={{
+ duration: 0.1,
+ }}
+ className="absolute bottom-0 w-full px-1.5"
+ >
+ <div className="h-0.5 bg-black" />
+ </motion.div>
+ )}
+ </div>
+ ))}
+ </LayoutGroup>
</div>
);
}