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.

fix analytics toggle

Steven Tey1ce73ca38b57
diff --git a/apps/web/ui/analytics/filter-bar.tsx b/apps/web/ui/analytics/filter-bar.tsx
index 47c2a285f3..e3bde4a704 100644
--- a/apps/web/ui/analytics/filter-bar.tsx
+++ b/apps/web/ui/analytics/filter-bar.tsx
@@ -1,11 +1,14 @@
+import { ClientOnly } from "@dub/ui";
import DomainSelector from "./domain-selector";
import TagSelector from "./tag-selector";
export default function FilterBar() {
return (
- <div className="grid w-full grid-cols-2 gap-1 rounded-lg bg-gray-100 p-1 min-[550px]:w-auto lg:flex">
- <DomainSelector />
- <TagSelector />
- </div>
+ <ClientOnly>
+ <div className="grid w-full grid-cols-2 gap-1 rounded-lg bg-gray-100 p-1 min-[550px]:w-auto lg:flex">
+ <DomainSelector />
+ <TagSelector />
+ </div>
+ </ClientOnly>
);
}
diff --git a/apps/web/ui/analytics/tag-selector.tsx b/apps/web/ui/analytics/tag-selector.tsx
index 1cabed5e4e..2a860a4b04 100644
--- a/apps/web/ui/analytics/tag-selector.tsx
+++ b/apps/web/ui/analytics/tag-selector.tsx
@@ -11,19 +11,22 @@ export default function TagSelector() {
const searchParams = useSearchParams();
const selectedTagId = searchParams?.get("tagId");
- return tags ? (
+ return (
<InputSelect
adjustForMobile
- items={tags.map(({ id, name, color }) => ({
- id,
- color,
- value: name,
- }))}
+ disabled={!tags}
+ items={
+ tags?.map(({ id, name, color }) => ({
+ id,
+ color,
+ value: name,
+ })) || []
+ }
icon={<Tag className="h-4 w-4 text-black" />}
selectedItem={{
id: selectedTagId!,
- value: tags.find(({ id }) => id === selectedTagId)?.name || "",
- color: tags.find(({ id }) => id === selectedTagId)?.color,
+ value: tags?.find(({ id }) => id === selectedTagId)?.name || "",
+ color: tags?.find(({ id }) => id === selectedTagId)?.color,
}}
setSelectedItem={(tag) => {
if (tag && typeof tag !== "function" && tag.id)
@@ -43,7 +46,5 @@ export default function TagSelector() {
}}
className="lg:w-48"
/>
- ) : (
- <div className="h-10.5 flex w-full animate-pulse items-center space-x-2 rounded-md bg-gray-200 opacity-50 md:w-48" />
);
}
diff --git a/apps/web/ui/analytics/toggle.tsx b/apps/web/ui/analytics/toggle.tsx
index 0138124d54..0999ab7436 100644
--- a/apps/web/ui/analytics/toggle.tsx
+++ b/apps/web/ui/analytics/toggle.tsx
@@ -1,14 +1,21 @@
-import { useScroll } from "@dub/ui";
-import { cn } from "@dub/utils";
+import { BlurImage, ExpandingArrow, useScroll } from "@dub/ui";
+import {
+ DUB_LOGO,
+ GOOGLE_FAVICON_URL,
+ cn,
+ getApexDomain,
+ linkConstructor,
+} from "@dub/utils";
import { useContext } from "react";
import { AnalyticsContext } from ".";
import ExportButton from "./export-button";
import SharePopover from "./share-popover";
import DateRangePicker from "./date-range-picker";
import FilterBar from "./filter-bar";
+import punycode from "punycode/";
export default function Toggle() {
- const { basePath, key, admin } = useContext(AnalyticsContext);
+ const { basePath, domain, key, url, admin } = useContext(AnalyticsContext);
const scrolled = useScroll(80);
@@ -39,14 +46,39 @@ export default function Toggle() {
},
)}
>
- <h2 className="truncate text-2xl text-gray-600">Analytics</h2>
+ {isPublicStatsPage ? (
+ <a
+ className="group flex items-center text-lg font-semibold text-gray-800"
+ href={linkConstructor({ domain, key })}
+ target="_blank"
+ rel="noreferrer"
+ >
+ <BlurImage
+ alt={url || "Dub.co"}
+ src={
+ url ? `${GOOGLE_FAVICON_URL}${getApexDomain(url)}` : DUB_LOGO
+ }
+ className="mr-2 h-6 w-6 flex-shrink-0 overflow-hidden rounded-full"
+ width={48}
+ height={48}
+ />
+ {linkConstructor({
+ domain: punycode.toUnicode(domain),
+ key,
+ pretty: true,
+ })}
+ <ExpandingArrow className="h-5 w-5" />
+ </a>
+ ) : (
+ <h2 className="truncate text-2xl text-gray-600">Analytics</h2>
+ )}
<div
className={cn("flex items-center gap-2", {
"w-full flex-col min-[550px]:flex-row md:w-auto": !key,
"w-full md:w-auto": key,
})}
>
- {!isPublicStatsPage && !key && <FilterBar />}
+ {!isPublicStatsPage && !key && !admin && <FilterBar />}
{!isPublicStatsPage && key && <SharePopover />}
<div
className={cn("flex w-full items-center gap-2", {
diff --git a/packages/ui/src/input-select.tsx b/packages/ui/src/input-select.tsx
index 799bb0134c..11d6449ce6 100644
--- a/packages/ui/src/input-select.tsx
+++ b/packages/ui/src/input-select.tsx
@@ -29,6 +29,7 @@ export function InputSelect({
selectedItem,
setSelectedItem,
className,
+ disabled,
adjustForMobile,
icon,
inputAttrs,
@@ -37,6 +38,7 @@ export function InputSelect({
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
className?: string;
+ disabled?: boolean;
adjustForMobile?: boolean;
icon?: ReactNode;
inputAttrs?: InputHTMLAttributes<HTMLInputElement>;
@@ -92,6 +94,7 @@ export function InputSelect({
setOpenCommandList(true);
}
}}
+ disabled={disabled}
className="block w-full truncate rounded-md border-none px-0 text-base text-gray-900 placeholder-gray-400 outline-none outline-0 transition-all duration-300 focus:ring-0 md:text-sm"
/>
</>