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.

Skip the tab count request when there is no search

Rafid62b1d2be9c1
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/page-client.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/page-client.tsx
index a81c8ba787..2bcca79ced 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/page-client.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/page-client.tsx
@@ -108,7 +108,13 @@ export function PartnersDashboardPageClient() {
/>
<div className="border-border-subtle -mx-px -mb-px overflow-clip rounded-xl border bg-white">
{tab ? (
- <ProgramsTabContent tab={tab} search={search} view={view} />
+ <ProgramsTabContent
+ tab={tab}
+ search={search}
+ view={view}
+ tabCount={getTabCount(tab)}
+ statusCountsFailed={!!statusCountsError}
+ />
) : (
<ProgramsGridSkeleton />
)}
@@ -122,22 +128,37 @@ function ProgramsTabContent({
tab,
search,
view,
+ tabCount,
+ statusCountsFailed,
}: {
tab: ProgramTab;
search?: string;
view: ProgramsView;
+ tabCount?: number;
+ statusCountsFailed: boolean;
}) {
- const { count } = useProgramEnrollmentsCount({
- status: tab.statuses.join(","),
- search,
- });
+ // without a search, the status counts already give the count of the tab
+ const needsCountRequest = !!search || statusCountsFailed;
+
+ const { count: requestedCount, error: countError } =
+ useProgramEnrollmentsCount(
+ { status: tab.statuses.join(","), search },
+ { enabled: needsCountRequest },
+ );
+
+ const count = needsCountRequest ? requestedCount : tabCount;
if (count === 0) {
return <ProgramsEmptyState tab={tab} search={search} />;
}
return view === "table" ? (
- <ProgramsTable tab={tab} search={search} />
+ <ProgramsTable
+ tab={tab}
+ search={search}
+ count={count}
+ countError={countError}
+ />
) : (
<ProgramsGrid tab={tab} search={search} />
);
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/programs-table.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/programs-table.tsx
index 4cb8a1269b..994180c277 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/programs-table.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/programs-table.tsx
@@ -3,7 +3,6 @@
import { constructPartnerLink } from "@/lib/partners/construct-partner-link";
import { usePartnerProgramActivity } from "@/lib/swr/use-partner-profile-earnings";
import useProgramEnrollments from "@/lib/swr/use-program-enrollments";
-import useProgramEnrollmentsCount from "@/lib/swr/use-program-enrollments-count";
import { ProgramEnrollmentProps } from "@/lib/types";
import { PartnerStatusBadges } from "@/ui/partners/partner-status-badges";
import { ProgramInviteActions } from "@/ui/partners/program-invite-actions";
@@ -32,9 +31,14 @@ type ProgramColumn = ColumnDef<ProgramEnrollmentProps>;
export function ProgramsTable({
tab,
search,
+ count,
+ countError,
}: {
tab: ProgramTab;
search?: string;
+ // the page gets the count, from the status counts or a count request
+ count?: number;
+ countError?: unknown;
}) {
const router = useRouter();
const { searchParams, queryParams } = useRouterStuff();
@@ -55,11 +59,6 @@ export function ProgramsTable({
pageSize: pagination.pageSize,
});
- const { count, error: countError } = useProgramEnrollmentsCount({
- status,
- search,
- });
-
const columns = useMemo(() => getColumns(tab), [tab]);
const { table, ...tableProps } = useTable({
diff --git a/apps/web/lib/swr/use-program-enrollments-count.ts b/apps/web/lib/swr/use-program-enrollments-count.ts
index 86251786ca..890d060518 100644
--- a/apps/web/lib/swr/use-program-enrollments-count.ts
+++ b/apps/web/lib/swr/use-program-enrollments-count.ts
@@ -9,6 +9,7 @@ export default function useProgramEnrollmentsCount(
z.input<typeof partnerProfileProgramsCountQuerySchema>,
"groupBy"
> = {},
+ { enabled = true }: { enabled?: boolean } = {},
) {
const { data: session } = useSession();
const partnerId = session?.user?.["defaultPartnerId"];
@@ -18,7 +19,8 @@ export default function useProgramEnrollmentsCount(
isLoading,
error,
} = useSWR<number>(
- partnerId &&
+ enabled &&
+ partnerId &&
`/api/partner-profile/programs/count?${new URLSearchParams(
Object.entries(query).filter(
(entry): entry is [string, string] => entry[1] !== undefined,