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.

wip

Kiran K9bc3e7d16cde
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/activity-list.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/events.tsx
similarity index 97%
rename from apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/activity-list.tsx
rename to apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/events.tsx
index a92c79b012..50f37bf588 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/activity-list.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/events.tsx
@@ -20,15 +20,11 @@ import {
} from "dub/dist/commonjs/models/components";
import { useSearchParams } from "next/navigation";
-export function ActivityList({
- events,
- totalEvents,
- demo,
-}: {
- events: ConversionEvent[];
- totalEvents: number;
- demo?: boolean;
-}) {
+interface EventsProps {
+ //
+}
+
+export const Events = (props: EventsProps) => {
const searchParams = useSearchParams();
const event = (searchParams.get("event") || "clicks") as EventType;
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/placeholders.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/placeholders.tsx
new file mode 100644
index 0000000000..5ebaa1a852
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/placeholders.tsx
@@ -0,0 +1,50 @@
+import { randomValue } from "@dub/utils";
+import { subDays } from "date-fns";
+
+export const placeholderEvents = {
+ clicks: [...Array(10)].map(
+ (_, idx) =>
+ ({
+ timestamp: subDays(new Date(), idx).toISOString(),
+ click_id: "1",
+ link_id: "1",
+ domain: "refer.dub.co",
+ key: "",
+ url: "https://dub.co",
+ country: randomValue(["US", "GB", "CA", "AU", "DE", "FR", "ES", "IT"]),
+ }) as any,
+ ),
+
+ leads: [...Array(10)].map(
+ (_, idx) =>
+ ({
+ timestamp: subDays(new Date(), idx).toISOString(),
+ click_id: "1",
+ link_id: "1",
+ domain: "refer.dub.co",
+ key: "",
+ url: "https://dub.co",
+ country: randomValue(["US", "GB", "CA", "AU", "DE", "FR", "ES", "IT"]),
+ }) as any,
+ ),
+
+ sales: [...Array(10)].map(
+ (_, idx) =>
+ ({
+ timestamp: subDays(new Date(), idx).toISOString(),
+ click_id: "1",
+ link_id: "1",
+ domain: "refer.dub.co",
+ key: "",
+ url: "https://dub.co",
+ country: randomValue(["US", "GB", "CA", "AU", "DE", "FR", "ES", "IT"]),
+ event_name: [
+ "Subscription creation",
+ "Subscription paid",
+ "Plan upgraded",
+ ][idx % 3],
+ // TODO update to saleAmount
+ amount: [1100, 4900, 2400][idx % 3],
+ }) as any,
+ ),
+};
diff --git a/packages/blocks/package.json b/packages/blocks/package.json
index f366666dde..2872efa211 100644
--- a/packages/blocks/package.json
+++ b/packages/blocks/package.json
@@ -43,7 +43,8 @@
"@visx/scale": "^3.3.0",
"@visx/shape": "^2.12.2",
"class-variance-authority": "^0.7.0",
- "framer-motion": "^10.16.16"
+ "framer-motion": "^10.16.16",
+ "swr": "^2.1.5"
},
"author": "Steven Tey <[email protected]>",
"homepage": "https://dub.co",
diff --git a/packages/blocks/src/hooks/use-analytics.ts b/packages/blocks/src/hooks/use-analytics.ts
new file mode 100644
index 0000000000..9bd91503ed
--- /dev/null
+++ b/packages/blocks/src/hooks/use-analytics.ts
@@ -0,0 +1,12 @@
+import { fetcher } from "@dub/utils";
+import useSWR from "swr";
+
+export const useAnalytics = () => {
+ const { error, data, isLoading } = useSWR(`/api/analytics/client`, fetcher);
+
+ return {
+ analytics: data,
+ error,
+ isLoading,
+ };
+};
diff --git a/packages/blocks/src/hooks/use-events.ts b/packages/blocks/src/hooks/use-events.ts
new file mode 100644
index 0000000000..d299dea28a
--- /dev/null
+++ b/packages/blocks/src/hooks/use-events.ts
@@ -0,0 +1,12 @@
+import { fetcher } from "@dub/utils";
+import useSWR from "swr";
+
+export const useEvents = () => {
+ const { error, data, isLoading } = useSWR(`/api/events/client`, fetcher);
+
+ return {
+ events: data,
+ error,
+ isLoading,
+ };
+};
diff --git a/packages/blocks/src/index.ts b/packages/blocks/src/index.ts
index 3a63f7417a..3a7736b51e 100644
--- a/packages/blocks/src/index.ts
+++ b/packages/blocks/src/index.ts
@@ -4,6 +4,8 @@ import "./styles.css";
export * from "./empty-state";
export * from "./event-list";
export * from "./gauge";
+export * from "./hooks/use-analytics";
+export * from "./hooks/use-events";
export * from "./mini-area-chart";
export * from "./pagination-controls";
export * from "./stats-card";