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.

improve analytics mobile UI

Steven Tey0a444476a6f5
diff --git a/apps/web/ui/analytics/analytics-card.tsx b/apps/web/ui/analytics/analytics-card.tsx
index 3f5b2f27ec..ea750f239c 100644
--- a/apps/web/ui/analytics/analytics-card.tsx
+++ b/apps/web/ui/analytics/analytics-card.tsx
@@ -1,7 +1,8 @@
import { EventType } from "@/lib/analytics/types";
-import { Modal, TabSelect } from "@dub/ui";
+import { Button, Modal, Popover, TabSelect, useMediaQuery } from "@dub/ui";
import { CursorRays, InvoiceDollar, UserCheck } from "@dub/ui/src/icons";
import { cn } from "@dub/utils";
+import { Command } from "cmdk";
import {
Dispatch,
ReactNode,
@@ -20,7 +21,7 @@ export function AnalyticsCard<T extends string>({
children,
className,
}: {
- tabs: { id: T; label: string }[];
+ tabs: { id: T; label: string; icon: React.ElementType }[];
selectedTabId: T;
onSelectTab?: Dispatch<SetStateAction<T>> | ((tabId: T) => void);
expandLimit: number;
@@ -35,8 +36,11 @@ export function AnalyticsCard<T extends string>({
const { selectedTab: event } = useContext(AnalyticsContext);
const [showModal, setShowModal] = useState(false);
+ const [isOpen, setIsOpen] = useState(false);
- const selectedTab = tabs.find(({ id }) => id === selectedTabId);
+ const selectedTab = tabs.find(({ id }) => id === selectedTabId) || tabs[0];
+ const SelectedTabIcon = selectedTab.icon;
+ const { isMobile } = useMediaQuery();
return (
<>
@@ -58,21 +62,58 @@ export function AnalyticsCard<T extends string>({
>
<div className="flex items-center justify-between border-b border-gray-200 px-4">
{/* Main tabs */}
- <TabSelect
- options={tabs}
- selected={selectedTabId}
- onSelect={onSelectTab}
- />
+ {isMobile ? (
+ <Popover
+ openPopover={isOpen}
+ setOpenPopover={setIsOpen}
+ content={
+ <Command tabIndex={0} loop className="focus:outline-none">
+ <Command.List className="flex w-screen flex-col gap-1 p-1.5 text-sm sm:w-auto sm:min-w-[130px]">
+ {tabs.map(({ id, label, icon: Icon }) => (
+ <Command.Item
+ className={cn(
+ "flex cursor-pointer select-none items-center gap-2 whitespace-nowrap rounded-md p-2 text-sm text-neutral-600",
+ "data-[selected=true]:bg-gray-100",
+ )}
+ onSelect={() => {
+ onSelectTab?.(id);
+ setIsOpen(false);
+ }}
+ >
+ {<Icon className="size-4" />}
+ {label}
+ </Command.Item>
+ ))}
+ </Command.List>
+ </Command>
+ }
+ align="end"
+ >
+ <Button
+ type="button"
+ className="my-2 h-8 w-fit whitespace-nowrap px-2"
+ variant="outline"
+ icon={<SelectedTabIcon className="size-4" />}
+ text={selectedTab.label}
+ />
+ </Popover>
+ ) : (
+ <TabSelect
+ options={tabs}
+ selected={selectedTabId}
+ onSelect={onSelectTab}
+ />
+ )}
<div className="flex items-center gap-1 pr-2 text-gray-500">
{event === "sales" ? (
- <InvoiceDollar className="h-4 w-4" />
+ <InvoiceDollar className="hidden h-4 w-4 sm:block" />
) : event === "leads" ? (
- <UserCheck className="h-4 w-4" />
+ <UserCheck className="hidden h-4 w-4 sm:block" />
) : (
- <CursorRays className="h-4 w-4" />
+ <CursorRays className="hidden h-4 w-4 sm:block" />
)}
- <p className="hidden text-xs uppercase sm:block">{event}</p>
+ <p className="text-xs uppercase">{event}</p>
</div>
</div>
<div className="py-4">
diff --git a/apps/web/ui/analytics/devices.tsx b/apps/web/ui/analytics/devices.tsx
index 33bd19a230..d16663df92 100644
--- a/apps/web/ui/analytics/devices.tsx
+++ b/apps/web/ui/analytics/devices.tsx
@@ -4,6 +4,7 @@ import {
} from "@/lib/analytics/constants";
import { DeviceTabs } from "@/lib/analytics/types";
import { useRouterStuff } from "@dub/ui";
+import { Cube, CursorRays, MobilePhone, Window } from "@dub/ui/src/icons";
import { useContext, useState } from "react";
import { AnalyticsCard } from "./analytics-card";
import { AnalyticsLoadingSpinner } from "./analytics-loading-spinner";
@@ -25,10 +26,10 @@ export default function Devices() {
return (
<AnalyticsCard
tabs={[
- { id: "devices", label: "Devices" },
- { id: "browsers", label: "Browsers" },
- { id: "os", label: "OS" },
- { id: "triggers", label: "Triggers" },
+ { id: "devices", label: "Devices", icon: MobilePhone },
+ { id: "browsers", label: "Browsers", icon: Window },
+ { id: "os", label: "OS", icon: Cube },
+ { id: "triggers", label: "Triggers", icon: CursorRays },
]}
selectedTabId={tab}
onSelectTab={setTab}
diff --git a/apps/web/ui/analytics/index.tsx b/apps/web/ui/analytics/index.tsx
index cf89398c67..e1e8355fe7 100644
--- a/apps/web/ui/analytics/index.tsx
+++ b/apps/web/ui/analytics/index.tsx
@@ -36,7 +36,7 @@ export default function Analytics({
<div className="mx-auto grid max-w-screen-xl gap-5 px-3 lg:px-10">
<Main />
<div className="grid grid-cols-1 gap-5 md:grid-cols-2">
- {!partnerPage && <TopLinks />}
+ {!dashboardProps && !partnerPage && <TopLinks />}
<Locations />
<Devices />
<Referer />
diff --git a/apps/web/ui/analytics/locations.tsx b/apps/web/ui/analytics/locations.tsx
index 4eee2219a5..22d0df4d52 100644
--- a/apps/web/ui/analytics/locations.tsx
+++ b/apps/web/ui/analytics/locations.tsx
@@ -1,5 +1,11 @@
import { SINGULAR_ANALYTICS_ENDPOINTS } from "@/lib/analytics/constants";
import { useRouterStuff } from "@dub/ui";
+import {
+ FlagWavy,
+ LocationPin,
+ MapPosition,
+ OfficeBuilding,
+} from "@dub/ui/src/icons";
import { CONTINENTS, COUNTRIES, REGIONS } from "@dub/utils";
import { useContext, useState } from "react";
import { AnalyticsCard } from "./analytics-card";
@@ -25,10 +31,10 @@ export default function Locations() {
return (
<AnalyticsCard
tabs={[
- { id: "countries", label: "Countries" },
- { id: "cities", label: "Cities" },
- { id: "regions", label: "Regions" },
- { id: "continents", label: "Continents" },
+ { id: "countries", label: "Countries", icon: FlagWavy },
+ { id: "cities", label: "Cities", icon: OfficeBuilding },
+ { id: "regions", label: "Regions", icon: LocationPin },
+ { id: "continents", label: "Continents", icon: MapPosition },
]}
selectedTabId={tab}
onSelectTab={setTab}
diff --git a/apps/web/ui/analytics/referer.tsx b/apps/web/ui/analytics/referer.tsx
index 2361a631c8..e122eb9805 100644
--- a/apps/web/ui/analytics/referer.tsx
+++ b/apps/web/ui/analytics/referer.tsx
@@ -1,5 +1,6 @@
import { SINGULAR_ANALYTICS_ENDPOINTS } from "@/lib/analytics/constants";
import { BlurImage, useRouterStuff } from "@dub/ui";
+import { ReferredVia } from "@dub/ui/src/icons";
import { getApexDomain, GOOGLE_FAVICON_URL } from "@dub/utils";
import { Link2 } from "lucide-react";
import { useContext, useState } from "react";
@@ -22,8 +23,8 @@ export default function Referer() {
return (
<AnalyticsCard
tabs={[
- { id: "referers", label: "Referrers" },
- { id: "referer_urls", label: "Referrer URLs" },
+ { id: "referers", label: "Referrers", icon: ReferredVia },
+ { id: "referer_urls", label: "Referrer URLs", icon: ReferredVia },
]}
selectedTabId={tab}
onSelectTab={setTab}
diff --git a/apps/web/ui/analytics/top-links.tsx b/apps/web/ui/analytics/top-links.tsx
index a369ae056e..0263e8d91b 100644
--- a/apps/web/ui/analytics/top-links.tsx
+++ b/apps/web/ui/analytics/top-links.tsx
@@ -1,4 +1,5 @@
import { LinkLogo, useRouterStuff } from "@dub/ui";
+import { Globe, Hyperlink } from "@dub/ui/src/icons";
import { getApexDomain } from "@dub/utils";
import { useContext, useState } from "react";
import { AnalyticsCard } from "./analytics-card";
@@ -21,8 +22,8 @@ export default function TopLinks() {
return (
<AnalyticsCard
tabs={[
- { id: "links", label: "Short Links" },
- { id: "urls", label: "Destination URLs" },
+ { id: "links", label: "Short Links", icon: Hyperlink },
+ { id: "urls", label: "Destination URLs", icon: Globe },
]}
expandLimit={8}
hasMore={(data?.length ?? 0) > 8}