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 auto-polyfill status in GET /partners

Steven Teya0219ed6f4ce
diff --git a/apps/web/app/(ee)/api/partners/count/route.ts b/apps/web/app/(ee)/api/partners/count/route.ts
index 788235b5e2..8ec013c38d 100644
--- a/apps/web/app/(ee)/api/partners/count/route.ts
+++ b/apps/web/app/(ee)/api/partners/count/route.ts
@@ -35,7 +35,7 @@ export const GET = withWorkspace(
}),
},
every: {
- status: status || "approved",
+ status,
},
},
...commonWhere,
@@ -100,7 +100,7 @@ export const GET = withWorkspace(
}),
...commonWhere,
},
- status: status || "approved",
+ status,
},
_count: true,
orderBy: {
@@ -117,7 +117,7 @@ export const GET = withWorkspace(
const count = await prisma.programEnrollment.count({
where: {
programId,
- status: status || "approved",
+ status,
...(groupId && {
groupId,
}),
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/partners-table.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/partners-table.tsx
index 98c966a9c1..66bcbc1212 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/partners-table.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/partners-table.tsx
@@ -52,6 +52,7 @@ import {
formatDate,
} from "@dub/utils";
import { nFormatter } from "@dub/utils/src/functions";
+import { ProgramEnrollmentStatus } from "@prisma/client";
import { Row } from "@tanstack/react-table";
import { Command } from "cmdk";
import { LockOpen } from "lucide-react";
@@ -103,6 +104,8 @@ export function PartnersTable() {
const router = useRouter();
const { queryParams, searchParams, getQueryString } = useRouterStuff();
+ const status = (searchParams.get("status") ||
+ "approved") as ProgramEnrollmentStatus;
const sortBy = searchParams.get("sortBy") || "totalSaleAmount";
const sortOrder = searchParams.get("sortOrder") === "asc" ? "asc" : "desc";
@@ -113,9 +116,11 @@ export function PartnersTable() {
onRemove,
onRemoveAll,
isFiltered,
- } = usePartnerFilters({ sortBy, sortOrder });
+ } = usePartnerFilters({ sortBy, sortOrder, status });
- const { partnersCount, error: countError } = usePartnersCount<number>();
+ const { partnersCount, error: countError } = usePartnersCount<number>({
+ status,
+ });
const {
data: partners,
@@ -124,7 +129,7 @@ export function PartnersTable() {
} = useSWR<EnrolledPartnerProps[]>(
`/api/partners${getQueryString({
workspaceId,
- includeExpandedFields: true,
+ status,
})}`,
fetcher,
{
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/use-partner-filters.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/use-partner-filters.tsx
index 5aadcbe0d3..9fa1136ebf 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/use-partner-filters.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/use-partner-filters.tsx
@@ -6,11 +6,14 @@ import { PartnerStatusBadges } from "@/ui/partners/partner-status-badges";
import { useRouterStuff } from "@dub/ui";
import { CircleDotted, FlagWavy, Users6 } from "@dub/ui/icons";
import { cn, COUNTRIES, nFormatter } from "@dub/utils";
+import { ProgramEnrollmentStatus } from "@prisma/client";
import { useMemo } from "react";
export function usePartnerFilters(extraSearchParams: Record<string, string>) {
const { searchParamsObj, queryParams } = useRouterStuff();
const { id: workspaceId, slug } = useWorkspace();
+ const status = (searchParamsObj.status ||
+ "approved") as ProgramEnrollmentStatus;
const { groups } = useGroups();
@@ -22,6 +25,7 @@ export function usePartnerFilters(extraSearchParams: Record<string, string>) {
| undefined
>({
groupBy: "country",
+ status,
});
const { partnersCount: statusCount } = usePartnersCount<
@@ -31,7 +35,7 @@ export function usePartnerFilters(extraSearchParams: Record<string, string>) {
}[]
| undefined
>({
- groupBy: "status",
+ groupBy: "status", // here we include all statuses to get the groupBy count
});
const { partnersCount: groupsCount } = usePartnersCount<
@@ -42,6 +46,7 @@ export function usePartnerFilters(extraSearchParams: Record<string, string>) {
| undefined
>({
groupBy: "groupId",
+ status,
});
const filters = useMemo(
diff --git a/apps/web/lib/api/partners/get-partners.ts b/apps/web/lib/api/partners/get-partners.ts
index a2ea21f2c4..11d5bf87f1 100644
--- a/apps/web/lib/api/partners/get-partners.ts
+++ b/apps/web/lib/api/partners/get-partners.ts
@@ -43,7 +43,7 @@ export async function getPartners(filters: PartnerFilters) {
},
}),
tenantId,
- status: status ?? "approved",
+ status,
groupId,
...(country || search || email
? {
diff --git a/apps/web/lib/zod/schemas/partners.ts b/apps/web/lib/zod/schemas/partners.ts
index be4089af78..8a47296271 100644
--- a/apps/web/lib/zod/schemas/partners.ts
+++ b/apps/web/lib/zod/schemas/partners.ts
@@ -20,7 +20,6 @@ import { analyticsResponse } from "./analytics-response";
import { createLinkBodySchema } from "./links";
import {
base64ImageSchema,
- booleanQuerySchema,
getPaginationQuerySchema,
publicHostedImageSchema,
storedR2ImageUrlSchema,
@@ -157,12 +156,6 @@ export const getPartnersQuerySchema = z
"A search query to filter partners by ID, name, email, or link.",
)
.openapi({ example: "john" }),
- includeExpandedFields: booleanQuerySchema
- .optional()
- .describe(
- "Whether to include stats fields on the partner (`clicks`, `leads`, `conversions`, `sales`, `saleAmount`, `commissions`, `netRevenue`). If false, those fields will be returned as 0.",
- )
- .openapi({ example: "true" }),
})
.merge(getPaginationQuerySchema({ pageSize: PARTNERS_MAX_PAGE_SIZE }));
@@ -369,45 +362,37 @@ export const EnrolledPartnerSchema = PartnerSchema.pick({
totalClicks: z
.number()
.default(0)
- .describe(
- "The total number of clicks on the partner's links. Defaults to 0 if `includeExpandedFields` is false.",
- ),
+ .describe("The total number of clicks on the partner's links"),
totalLeads: z
.number()
.default(0)
- .describe(
- "The total number of leads generated by the partner's links. Defaults to 0 if `includeExpandedFields` is false.",
- ),
+ .describe("The total number of leads generated by the partner's links"),
totalConversions: z
.number()
.default(0)
- .describe(
- "The total number of leads that converted to paying customers. Defaults to 0 if `includeExpandedFields` is false.",
- ),
+ .describe("The total number of leads that converted to paying customers"),
totalSales: z
.number()
.default(0)
.describe(
- "The total number of sales generated by the partner's links (includes recurring sales). Defaults to 0 if `includeExpandedFields` is false.",
+ "The total number of sales generated by the partner's links (includes recurring sales)",
),
totalSaleAmount: z
.number()
.default(0)
.describe(
- "The total amount of sales (in cents) generated by the partner's links. Defaults to 0 if `includeExpandedFields` is false.",
+ "The total amount of sales (in cents) generated by the partner's links",
),
totalCommissions: z
.number()
.default(0)
.describe(
- "The total commissions paid to the partner for their referrals. Defaults to 0 if `includeExpandedFields` is false.",
+ "The total commissions paid to the partner for their referrals",
),
netRevenue: z
.number()
.default(0)
- .describe(
- "The total net revenue generated by the partner. Defaults to 0 if `includeExpandedFields` is false.",
- ),
+ .describe("The total net revenue generated by the partner"),
})
.merge(
PartnerOnlinePresenceSchema.pick({