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 overview-chart.tsx

Tim Wilsonb92e297a8690
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/overview-chart.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/overview-chart.tsx
index d887ad4fcd..0336795acc 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/overview-chart.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/overview-chart.tsx
@@ -1,5 +1,7 @@
import { editQueryString } from "@/lib/analytics/utils";
+import useWorkspace from "@/lib/swr/use-workspace";
import { AnalyticsContext } from "@/ui/analytics/analytics-provider";
+import { ButtonLink } from "@/ui/placeholders/button-link";
import { Combobox, LoadingSpinner, useRouterStuff } from "@dub/ui";
import { fetcher } from "@dub/utils";
import NumberFlow from "@number-flow/react";
@@ -18,6 +20,8 @@ export function OverviewChart() {
const { selectedTab, saleUnit, queryString, totalEvents } =
useContext(AnalyticsContext);
+ const { slug } = useWorkspace();
+
const { data, error, isLoading } = useSWR<
{
start: Date;
@@ -50,49 +54,59 @@ export function OverviewChart() {
return (
<div className="flex size-full flex-col gap-6">
- <div className="flex flex-col">
- <Combobox
- selected={
- chartOptions.find((opt) => opt.value === selectedTab) || null
- }
- setSelected={(option) =>
- option && queryParams({ set: { event: option.value } })
- }
- options={chartOptions.slice()}
- optionClassName="w-36"
- caret={true}
- hideSearch={true}
- buttonProps={{
- variant: "outline",
- className: "h-7 w-fit px-2 -ml-2 -mt-1.5",
- }}
- />
- {totalEvents ? (
- <NumberFlow
- value={
- selectedTab === "sales" && saleUnit === "saleAmount"
- ? totalEvents.saleAmount / 100
- : totalEvents[selectedTab]
+ <div className="flex items-start justify-between">
+ <div className="flex flex-col">
+ <Combobox
+ selected={
+ chartOptions.find((opt) => opt.value === selectedTab) || null
}
- className="text-content-emphasis block text-3xl font-medium"
- format={
- selectedTab === "sales" && saleUnit === "saleAmount"
- ? {
- style: "currency",
- currency: "USD",
- trailingZeroDisplay: "stripIfInteger",
- }
- : {
- notation:
- totalEvents[selectedTab] > 999999
- ? "compact"
- : "standard",
- }
+ setSelected={(option) =>
+ option && queryParams({ set: { event: option.value } })
}
+ options={chartOptions.slice()}
+ optionClassName="w-36"
+ caret={true}
+ hideSearch={true}
+ buttonProps={{
+ variant: "outline",
+ className: "h-7 w-fit px-2 -ml-2 -mt-1.5",
+ }}
/>
- ) : (
- <div className="mb-1 mt-px h-10 w-24 animate-pulse rounded-md bg-neutral-200" />
- )}
+ {totalEvents ? (
+ <NumberFlow
+ value={
+ selectedTab === "sales" && saleUnit === "saleAmount"
+ ? totalEvents.saleAmount / 100
+ : totalEvents[selectedTab]
+ }
+ className="text-content-emphasis block text-3xl font-medium"
+ format={
+ selectedTab === "sales" && saleUnit === "saleAmount"
+ ? {
+ style: "currency",
+ currency: "USD",
+ trailingZeroDisplay: "stripIfInteger",
+ }
+ : {
+ notation:
+ totalEvents[selectedTab] > 999999
+ ? "compact"
+ : "standard",
+ }
+ }
+ />
+ ) : (
+ <div className="mb-1 mt-px h-10 w-24 animate-pulse rounded-md bg-neutral-200" />
+ )}
+ </div>
+
+ <ButtonLink
+ href={`/${slug}/program/analytics`}
+ variant="secondary"
+ className="h-8 px-3 text-sm"
+ >
+ View all
+ </ButtonLink>
</div>
<div className="relative min-h-0 grow">
@@ -100,6 +114,10 @@ export function OverviewChart() {
<div className="flex size-full items-center justify-center">
<LoadingSpinner />
</div>
+ ) : error ? (
+ <div className="text-content-subtle flex size-full items-center justify-center text-sm">
+ Failed to load data
+ </div>
) : (
<AnalyticsTimeseriesChart data={chartData} />
)}