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 bar list NumberTooltip units

Tim Wilson257d67c598fa
diff --git a/apps/web/ui/analytics/bar-list.tsx b/apps/web/ui/analytics/bar-list.tsx
index 9e68b7e27d..f07705ee12 100644
--- a/apps/web/ui/analytics/bar-list.tsx
+++ b/apps/web/ui/analytics/bar-list.tsx
@@ -12,8 +12,8 @@ import LinkPreviewTooltip from "./link-preview";
export default function BarList({
tab,
+ unit,
data,
- isCurrency,
barBackground,
hoverBackground,
maxValue,
@@ -21,6 +21,7 @@ export default function BarList({
limit,
}: {
tab: string;
+ unit: string;
data: {
icon: ReactNode;
title: string;
@@ -28,7 +29,6 @@ export default function BarList({
value: number;
linkId?: string;
}[];
- isCurrency?: boolean;
maxValue: number;
barBackground: string;
hoverBackground: string;
@@ -60,10 +60,10 @@ export default function BarList({
{...data}
maxValue={maxValue}
tab={tab}
+ unit={unit}
setShowModal={setShowModal}
barBackground={barBackground}
hoverBackground={hoverBackground}
- isCurrency={isCurrency}
/>
))}
</div>
@@ -99,11 +99,11 @@ export function LineItem({
value,
maxValue,
tab,
+ unit,
setShowModal,
barBackground,
hoverBackground,
linkData,
- isCurrency,
}: {
icon: ReactNode;
title: string;
@@ -111,11 +111,11 @@ export function LineItem({
value: number;
maxValue: number;
tab: string;
+ unit: string;
setShowModal: Dispatch<SetStateAction<boolean>>;
barBackground: string;
hoverBackground: string;
linkData?: LinkProps;
- isCurrency?: boolean;
}) {
const lineItem = useMemo(() => {
return (
@@ -161,10 +161,14 @@ export function LineItem({
animate={{ transform: "scaleX(1)" }}
/>
</div>
- <NumberTooltip value={value}>
+ <NumberTooltip
+ value={unit === "sales" ? value / 100 : value}
+ unit={`total ${unit}`}
+ prefix={unit === "sales" ? "$" : undefined}
+ >
<p className="z-10 px-2 text-sm text-gray-600">
- {isCurrency && "$"}
- {nFormatter(isCurrency ? value / 100 : value)}
+ {unit === "sales" && "$"}
+ {nFormatter(unit === "sales" ? value / 100 : value)}
</p>
</NumberTooltip>
</div>
diff --git a/apps/web/ui/analytics/devices.tsx b/apps/web/ui/analytics/devices.tsx
index 6ad6596c37..73a2012b87 100644
--- a/apps/web/ui/analytics/devices.tsx
+++ b/apps/web/ui/analytics/devices.tsx
@@ -57,7 +57,7 @@ export default function Devices() {
}))
?.sort((a, b) => b.value - a.value) || []
}
- isCurrency={dataKey === "amount"}
+ unit={selectedTab}
maxValue={Math.max(...data?.map((d) => d[dataKey] ?? 0)) ?? 0}
barBackground="bg-green-100"
hoverBackground="hover:bg-gradient-to-r hover:from-green-50 hover:to-transparent hover:border-green-500"
diff --git a/apps/web/ui/analytics/locations.tsx b/apps/web/ui/analytics/locations.tsx
index 9c80e1dfdf..39a9e0e1ee 100644
--- a/apps/web/ui/analytics/locations.tsx
+++ b/apps/web/ui/analytics/locations.tsx
@@ -70,7 +70,7 @@ export default function Locations() {
}))
?.sort((a, b) => b.value - a.value) || []
}
- isCurrency={dataKey === "amount"}
+ unit={selectedTab}
maxValue={Math.max(...data?.map((d) => d[dataKey] ?? 0)) ?? 0}
barBackground="bg-blue-100"
hoverBackground="hover:bg-gradient-to-r hover:from-blue-50 hover:to-transparent hover:border-blue-500"
diff --git a/apps/web/ui/analytics/referer.tsx b/apps/web/ui/analytics/referer.tsx
index 3f2a5f655b..f00f3af642 100644
--- a/apps/web/ui/analytics/referer.tsx
+++ b/apps/web/ui/analytics/referer.tsx
@@ -54,7 +54,7 @@ export default function Referer() {
}))
?.sort((a, b) => b.value - a.value) || []
}
- isCurrency={dataKey === "amount"}
+ unit={selectedTab}
maxValue={Math.max(...data?.map((d) => d[dataKey] ?? 0)) ?? 0}
barBackground="bg-red-100"
hoverBackground="hover:bg-gradient-to-r hover:from-red-50 hover:to-transparent hover:border-red-500"
diff --git a/apps/web/ui/analytics/top-links.tsx b/apps/web/ui/analytics/top-links.tsx
index 45d12190d5..d3f70ee243 100644
--- a/apps/web/ui/analytics/top-links.tsx
+++ b/apps/web/ui/analytics/top-links.tsx
@@ -62,7 +62,7 @@ export default function TopLinks() {
}))
?.sort((a, b) => b.value - a.value) || []
}
- isCurrency={dataKey === "amount"}
+ unit={selectedTab}
maxValue={Math.max(...data?.map((d) => d[dataKey] ?? 0)) ?? 0}
barBackground="bg-orange-100"
hoverBackground="hover:bg-gradient-to-r hover:from-orange-50 hover:to-transparent hover:border-orange-500"
diff --git a/packages/ui/src/tooltip.tsx b/packages/ui/src/tooltip.tsx
index a893fb4a33..b18eedb990 100644
--- a/packages/ui/src/tooltip.tsx
+++ b/packages/ui/src/tooltip.tsx
@@ -155,11 +155,13 @@ export function InfoTooltip(props: Omit<TooltipProps, "children">) {
export function NumberTooltip({
value,
unit = "total clicks",
+ prefix,
children,
lastClicked,
}: {
value?: number | null;
unit?: string;
+ prefix?: string;
children: ReactNode;
lastClicked?: Date | null;
}) {
@@ -171,6 +173,7 @@ export function NumberTooltip({
content={
<div className="block max-w-xs px-4 py-2 text-center text-sm text-gray-700">
<p className="text-sm font-semibold text-gray-700">
+ {prefix}
{nFormatter(value || 0, { full: true })} {unit}
</p>
{lastClicked && (