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.

simplify even more

Steven Tey47834c99e481
diff --git a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/analytics/route.ts b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/analytics/route.ts
index e93f5a86db..5a958f6700 100644
--- a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/analytics/route.ts
+++ b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/analytics/route.ts
@@ -22,6 +22,12 @@ export const GET = withPartnerProfile(
partnerProfileAnalyticsQuerySchema.parse(searchParams);
if (program.id === "prog_1K0QHV7MP3PR05CJSCF5VN93X") {
+ if (rest.groupBy !== "count") {
+ throw new DubApiError({
+ code: "forbidden",
+ message: "This feature is not available for your program.",
+ });
+ }
const { success } = await ratelimit(10, "30 m").limit(
`partnerProgramAnalytics:${partner.id}:${program.id}`,
);
@@ -54,6 +60,10 @@ export const GET = withPartnerProfile(
linkId = foundLink.id;
}
+ if (links.length === 0) {
+ return NextResponse.json([], { status: 200 });
+ }
+
const response = await getAnalytics({
...rest,
...(linkId ? { linkId } : { linkIds: links.map((link) => link.id) }),
diff --git a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/customers/[customerId]/route.ts b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/customers/[customerId]/route.ts
index ef9f2c06b1..eea1ad02cd 100644
--- a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/customers/[customerId]/route.ts
+++ b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/customers/[customerId]/route.ts
@@ -24,7 +24,10 @@ export const GET = withPartnerProfile(async ({ partner, params }) => {
});
if (program.id === "prog_1K0QHV7MP3PR05CJSCF5VN93X") {
- return NextResponse.json([], { status: 200 });
+ throw new DubApiError({
+ code: "forbidden",
+ message: "This feature is not available for your program.",
+ });
}
const customer = await prisma.customer.findUnique({
diff --git a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/events/route.ts b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/events/route.ts
index 958914cf77..664da74d26 100644
--- a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/events/route.ts
+++ b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/events/route.ts
@@ -1,4 +1,5 @@
import { getEvents } from "@/lib/analytics/get-events";
+import { DubApiError } from "@/lib/api/errors";
import { getProgramEnrollmentOrThrow } from "@/lib/api/programs/get-program-enrollment-or-throw";
import { withPartnerProfile } from "@/lib/auth/partner";
import { generateRandomName } from "@/lib/names";
@@ -23,7 +24,10 @@ export const GET = withPartnerProfile(
});
if (program.id === "prog_1K0QHV7MP3PR05CJSCF5VN93X") {
- return NextResponse.json([], { status: 200 });
+ throw new DubApiError({
+ code: "forbidden",
+ message: "This feature is not available for your program.",
+ });
}
let { linkId, domain, key, ...rest } =
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/page-client.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/page-client.tsx
index 2ce0d75538..1ad4b8c3e3 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/page-client.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/page-client.tsx
@@ -200,9 +200,19 @@ export default function ProgramPageClient() {
<PayoutsCard programId={program?.id} />
<NumberFlowGroup>
- <StatCard title="Clicks" event="clicks" />
- <StatCard title="Leads" event="leads" />
- <StatCard title="Sales" event="sales" />
+ {programSlug === "perplexity" ? (
+ <>
+ <StatCardSimple title="Clicks" event="clicks" />
+ <StatCardSimple title="Leads" event="leads" />
+ <StatCardSimple title="Sales" event="sales" />
+ </>
+ ) : (
+ <>
+ <StatCard title="Clicks" event="clicks" />
+ <StatCard title="Leads" event="leads" />
+ <StatCard title="Sales" event="sales" />
+ </>
+ )}
</NumberFlowGroup>
</div>
</ChartTooltipSync>
@@ -382,6 +392,48 @@ function StatCard({
);
}
+function StatCardSimple({
+ title,
+ event,
+}: {
+ title: string;
+ event: "clicks" | "leads" | "sales";
+}) {
+ const { programSlug } = useParams();
+ const { getQueryString } = useRouterStuff();
+ const { start, end, interval } = useContext(ProgramOverviewContext);
+
+ const { data: total } = usePartnerAnalytics({
+ event: "composite",
+ interval,
+ start,
+ end,
+ });
+
+ return (
+ <div className="group block rounded-lg border border-neutral-300 bg-white p-6">
+ <div className="flex flex-col items-center text-center">
+ <span className="mb-3 block text-sm font-medium text-neutral-600">
+ {title}
+ </span>
+ {total !== undefined ? (
+ <div className="flex items-center justify-center">
+ <NumberFlow
+ className="text-3xl font-semibold text-neutral-900"
+ value={total[event]}
+ format={{
+ notation: total[event] > 999999 ? "compact" : "standard",
+ }}
+ />
+ </div>
+ ) : (
+ <div className="h-12 w-20 animate-pulse rounded-md bg-neutral-200" />
+ )}
+ </div>
+ </div>
+ );
+}
+
function BrandedChart({
data: dataProp,
currency,