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.

improve `usePartners` search

Steven Teye49188e6a7ee
diff --git a/apps/web/lib/swr/use-partners.ts b/apps/web/lib/swr/use-partners.ts
index ba56607800..7e9be5b3d8 100644
--- a/apps/web/lib/swr/use-partners.ts
+++ b/apps/web/lib/swr/use-partners.ts
@@ -7,12 +7,36 @@ import useWorkspace from "./use-workspace";
const partialQuerySchema = getPartnersQuerySchemaExtended.partial();
+type PartnersQuery = z.infer<typeof partialQuerySchema>;
+
+// Blank search is not a query, and URLSearchParams stringifies `undefined` to
+// the literal "undefined". Relevance ordering is only valid with a real search.
+function buildPartnersQueryString(workspaceId: string, query?: PartnersQuery) {
+ const search = query?.search?.trim() || undefined;
+ const params = new URLSearchParams();
+
+ for (const [key, value] of Object.entries({
+ ...query,
+ workspaceId,
+ search,
+ sortBy:
+ query?.sortBy ??
+ (search && query?.sortOrder !== "asc" ? "relevance" : undefined),
+ })) {
+ if (value == null || value === "") continue;
+
+ params.set(key, Array.isArray(value) ? value.join(",") : String(value));
+ }
+
+ return params.toString();
+}
+
export default function usePartners(
{
query,
enabled = true,
}: {
- query?: z.infer<typeof partialQuerySchema>;
+ query?: PartnersQuery;
enabled?: boolean;
} = {},
swrOptions: SWRConfiguration = {},
@@ -21,10 +45,7 @@ export default function usePartners(
const { data, isLoading, error } = useSWR<EnrolledPartnerProps[]>(
enabled && workspaceId
- ? `/api/partners?${new URLSearchParams({
- workspaceId: workspaceId,
- ...query,
- } as Record<string, any>).toString()}`
+ ? `/api/partners?${buildPartnersQueryString(workspaceId, query)}`
: undefined,
fetcher,
{
diff --git a/apps/web/ui/submitted-leads/partner-profile-submitted-leads-empty-state.tsx b/apps/web/ui/submitted-leads/partner-profile-submitted-leads-empty-state.tsx
index 5aef9e799b..3d1aafd895 100644
--- a/apps/web/ui/submitted-leads/partner-profile-submitted-leads-empty-state.tsx
+++ b/apps/web/ui/submitted-leads/partner-profile-submitted-leads-empty-state.tsx
@@ -90,7 +90,7 @@ export function PartnerProfileSubmittedLeadsEmptyState() {
? "Submit leads and track their progress through the sales process."
: "You can still earn from regular referrals using your links and codes."
}
- learnMoreHref="https://dub.co/help/article/submitted-referrals"
+ learnMoreHref="https://dub.co/help/article/submitted-leads"
addButton={
submittedLeadsEnabled ? (
<Button
diff --git a/apps/web/ui/submitted-leads/submitted-lead-table.tsx b/apps/web/ui/submitted-leads/submitted-lead-table.tsx
index 858db2299e..fdb1fb0975 100644
--- a/apps/web/ui/submitted-leads/submitted-lead-table.tsx
+++ b/apps/web/ui/submitted-leads/submitted-lead-table.tsx
@@ -262,7 +262,7 @@ export function SubmittedLeadTable() {
<AnimatedEmptyState
title="No leads submitted"
description="Allow partners to submit leads and track their progress through the sales process."
- learnMoreHref="https://dub.co/help/article/partner-rewards"
+ learnMoreHref="https://dub.co/help/article/submitted-leads"
cardContent={
<>
<div className="bg-bg-emphasis h-2.5 w-24 min-w-0 rounded-sm" />