The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Go back to the first page when the Programs page no longer exists
Rafi5ffc2b915b80
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.tsxindex e93688eb64..c934333411 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@@ -211,7 +211,7 @@ function ProgramsGrid({countError?: unknown;}) {const { programEnrollments, isLoading, error, pagination, setPagination } =- useProgramsPage({ tab, search });+ useProgramsPage({ tab, search, count });// like the table, since without the count the grid cannot show its pagesif (error || countError) {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.tsxindex 2febeec005..dea317f1f5 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@@ -53,6 +53,7 @@ export function ProgramsTable({} = useProgramsPage({tab,search,+ count,includeInactiveDates: tab.id === "inactive",});diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/use-programs-page.ts b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/use-programs-page.tsindex cfc0eefc6c..1a0c58d825 100644--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/use-programs-page.ts+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/use-programs-page.ts@@ -1,5 +1,6 @@import useProgramEnrollments from "@/lib/swr/use-program-enrollments";import { usePagination, useRouterStuff } from "@dub/ui";+import { useEffect } from "react";import { PROGRAMS_PAGE_SIZE, ProgramTab } from "./program-tabs";// one page of the programs of a tab, with the sort from the URL. The grid and@@ -8,15 +9,29 @@ import { PROGRAMS_PAGE_SIZE, ProgramTab } from "./program-tabs";export function useProgramsPage({tab,search,+ count,includeInactiveDates,}: {tab: ProgramTab;search?: string;+ // the number of programs in the tab, when known+ count?: number;includeInactiveDates?: boolean;}) {- const { searchParams } = useRouterStuff();+ const { searchParams, queryParams } = useRouterStuff();const { pagination, setPagination } = usePagination(PROGRAMS_PAGE_SIZE);+ // a page past the end (an old link, or the last invite of a page accepted)+ // has no programs and no footer, so go back to the first page+ useEffect(() => {+ if (+ count &&+ pagination.pageIndex > Math.ceil(count / pagination.pageSize)+ ) {+ queryParams({ del: "page" });+ }+ }, [count, pagination.pageIndex, pagination.pageSize]);+const sortBy: "name" | undefined =searchParams.get("sortBy") === "name" ? "name" : undefined;const sortOrder: "asc" | "desc" =