The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add group pages and SWR hooks for partners dashboard
Kiran K7dba7cb61906
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/groups/[groupSlug]/discounts/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/groups/[groupSlug]/discounts/page.tsxnew file mode 100644index 0000000000..e69de29bb2diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/groups/[groupSlug]/group-header.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/groups/[groupSlug]/group-header.tsxnew file mode 100644index 0000000000..9483344748--- /dev/null+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/groups/[groupSlug]/group-header.tsx@@ -0,0 +1,130 @@+"use client";++import useGroup from "@/lib/swr/use-group";+import { GroupProps } from "@/lib/types";+import { GroupColorCircle } from "@/ui/partners/groups/group-color-circle";+import {+ ArrowUpRight,+ Button,+ ChevronRight,+ Discount,+ Gift,+ Sliders,+ Users,+} from "@dub/ui";+import { cn } from "@dub/utils";+import Link from "next/link";+import { useParams, usePathname } from "next/navigation";++// TODO:+// Handle error when the group doesn't exists++const GROUP_NAVIGATION_TABS = [+ {+ id: "rewards",+ label: "Rewards",+ icon: Gift,+ external: false,+ getHref(group: GroupProps) {+ return `/program/partners/groups/${group.slug}/rewards`;+ },+ isActive(pathname: string) {+ return pathname.includes("/rewards");+ },+ },+ {+ id: "discount",+ label: "Discount",+ icon: Discount,+ external: false,+ getHref(group: GroupProps) {+ return `/program/partners/groups/${group.slug}/discount`;+ },+ isActive(pathname: string) {+ return pathname.includes("/discounts");+ },+ },+ {+ id: "settings",+ label: "Settings",+ icon: Sliders,+ external: false,+ getHref(group: GroupProps) {+ return `/program/partners/groups/${group.slug}`;+ },+ isActive(pathname: string) {+ return pathname.includes("/");+ },+ },+ {+ id: "partners",+ label: "Partners",+ icon: Users,+ external: true,+ getHref(group: GroupProps) {+ return `/program/commissions?groupId=${group.id}`;+ },+ isActive(pathname: string) {+ return false;+ },+ },+] as const;++export function GroupHeader() {+ const pathname = usePathname();+ const { groupSlug } = useParams<{ groupSlug: string }>();++ const { group, loading } = useGroup({+ groupIdOrSlug: groupSlug,+ });++ if (loading || !group) {+ return <div className="h-7 w-32 animate-pulse rounded-md bg-neutral-200" />;+ }++ return (+ <div className="space-y-4">+ <div className="flex items-center gap-1">+ <div className="flex items-center justify-center rounded-lg bg-neutral-100 p-2">+ <Users className="size-4" />+ </div>+ <div className="flex items-center gap-1.5">+ <ChevronRight className="text-content-subtle size-2.5 shrink-0 [&_*]:stroke-2" />+ <div className="flex items-center gap-1.5">+ {<GroupColorCircle group={group} />}+ <span className="text-lg font-semibold leading-7 text-neutral-900">+ {group.name}+ </span>+ </div>+ </div>+ </div>++ <div className="flex gap-2.5">+ {GROUP_NAVIGATION_TABS.map((tab) => {+ const Icon = tab.icon;+ const isActive = tab.isActive(pathname);++ return (+ <Link+ key={tab.id}+ href={tab.getHref(group)}+ target={tab.external ? "_blank" : undefined}+ >+ <Button+ variant="secondary"+ icon={<Icon className="size-4" />}+ text={tab.label}+ right={+ tab.external ? <ArrowUpRight className="size-3" /> : undefined+ }+ className={cn("h-7 rounded-lg px-3 text-sm font-medium", {+ "bg-bg-subtle": isActive,+ })}+ />+ </Link>+ );+ })}+ </div>+ </div>+ );+}diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/groups/[groupSlug]/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/groups/[groupSlug]/page.tsxnew file mode 100644index 0000000000..2a4027a41d--- /dev/null+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/groups/[groupSlug]/page.tsx@@ -0,0 +1,13 @@+import { PageContent } from "@/ui/layout/page-content";+import { PageWidthWrapper } from "@/ui/layout/page-width-wrapper";+import { GroupHeader } from "./group-header";++export default function ProgramPartnersGroups() {+ return (+ <PageContent title={<GroupHeader />}>+ <PageWidthWrapper>+ <></>+ </PageWidthWrapper>+ </PageContent>+ );+}diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/groups/[groupSlug]/partners/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/groups/[groupSlug]/partners/page.tsxnew file mode 100644index 0000000000..8b13789179--- /dev/null+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/groups/[groupSlug]/partners/page.tsx@@ -0,0 +1 @@+diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/groups/[groupSlug]/rewards/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/groups/[groupSlug]/rewards/page.tsxnew file mode 100644index 0000000000..e69de29bb2diff --git a/apps/web/lib/swr/use-group.ts b/apps/web/lib/swr/use-group.tsnew file mode 100644index 0000000000..8229bcb6e5--- /dev/null+++ b/apps/web/lib/swr/use-group.ts@@ -0,0 +1,21 @@+import { fetcher } from "@dub/utils";+import useSWR from "swr";+import { GroupProps } from "../types";+import useWorkspace from "./use-workspace";++export default function useGroup({ groupIdOrSlug }: { groupIdOrSlug: string }) {+ const { id: workspaceId } = useWorkspace();++ const { data: group, error } = useSWR<GroupProps>(+ workspaceId && groupIdOrSlug+ ? `/api/groups/${groupIdOrSlug}?workspaceId=${workspaceId}`+ : undefined,+ fetcher,+ );++ return {+ group,+ error,+ loading: !group && !error,+ };+}diff --git a/apps/web/lib/swr/use-groups.ts b/apps/web/lib/swr/use-groups.tsindex af19df149b..8a1bee35fa 100644--- a/apps/web/lib/swr/use-groups.ts+++ b/apps/web/lib/swr/use-groups.ts@@ -18,11 +18,18 @@ export default function useGroups<T extends GroupProps>({const { id: workspaceId, defaultProgramId } = useWorkspace();const { getQueryString } = useRouterStuff();- const queryEnabled = enabled && defaultProgramId;-const { data, isLoading, error } = useSWR<T[]>(- queryEnabled- ? `/api/groups${getQueryString({ workspaceId, sortBy: "saleAmount", ...query }, { exclude: ["partnerId"] })}`+ enabled && defaultProgramId+ ? `/api/groups${getQueryString(+ {+ workspaceId,+ sortBy: "saleAmount",+ ...query,+ },+ {+ exclude: ["partnerId"],+ },+ )}`: null,fetcher,{