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.

WIP program apply page

Tim Wilson2c19cd63fc3d
diff --git a/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/auth.tsx b/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/auth.tsx
index 78abaf81e0..dd4aac05bb 100644
--- a/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/auth.tsx
+++ b/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/auth.tsx
@@ -10,13 +10,16 @@ export function ProgramEnrollmentAuth({
children: React.ReactNode;
}) {
const { programSlug } = useParams();
- const { error, loading } = useProgramEnrollment();
+ const { programEnrollment, error, loading } = useProgramEnrollment();
if (loading) {
return <LayoutLoader />;
}
- if (error && error.status === 404) {
+ if (
+ (error && error.status === 404) ||
+ (programEnrollment && programEnrollment.status !== "approved")
+ ) {
redirect(`/programs/${programSlug}/apply`);
}
diff --git a/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/apply/page.tsx b/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/apply/page.tsx
index be07d58703..7de65f08e4 100644
--- a/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/apply/page.tsx
+++ b/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/apply/page.tsx
@@ -1,12 +1,11 @@
import { getProgram } from "@/lib/fetchers/get-program";
import { programLanderSchema } from "@/lib/zod/schemas/program-lander";
import { BLOCK_COMPONENTS } from "@/ui/partners/lander-blocks";
-import { ProgramRewardList } from "@/ui/partners/program-reward-list";
+import { BackLink } from "@/ui/shared/back-link";
import { MaxWidthWrapper } from "@dub/ui";
-import { cn } from "@dub/utils";
-import { ApplyButton } from "app/partners.dub.co/(apply)/[programSlug]/apply-button";
import { notFound } from "next/navigation";
import { CSSProperties } from "react";
+import { ProgramSidebar } from "./program-sidebar";
export default async function ProgramDetailsPage({
params: { programSlug },
@@ -18,94 +17,52 @@ export default async function ProgramDetailsPage({
include: ["rewards", "defaultDiscount"],
});
- if (!program) {
- notFound();
- }
+ if (!program) notFound();
- // TODO: reuse from /(apply)/[programSlug]/page.tsx
return (
- <MaxWidthWrapper>
- <div
- className="relative"
- style={
- {
- "--brand": "#000000",
- "--brand-ring": "rgb(from var(--brand) r g b / 0.2)",
- } as CSSProperties
- }
- >
- <div className="p-6">
- {/* Hero section */}
- <div className="grid grid-cols-1 gap-5 sm:pt-20">
- <span
- className={cn(
- "font-mono text-xs font-medium uppercase text-[var(--brand)]",
- "animate-slide-up-fade [--offset:5px] [animation-duration:1s] [animation-fill-mode:both]",
- )}
- >
- Affiliate Program
- </span>
- <h1
- className={cn(
- "text-4xl font-semibold",
- "animate-slide-up-fade [--offset:5px] [animation-delay:100ms] [animation-duration:1s] [animation-fill-mode:both]",
- )}
- >
- Join the {program.name} affiliate program
- </h1>
- <p
- className={cn(
- "text-base text-neutral-700",
- "animate-slide-up-fade [--offset:5px] [animation-delay:200ms] [animation-duration:1s] [animation-fill-mode:both]",
- )}
- >
- Share {program.name} with your audience and for each subscription
- generated through your referral, you'll earn a share of the
- revenue on any plans they purchase.
- </p>
- {/* <p className="text-xs text-neutral-500">
- Read our{" "}
- <a
- href="#"
- className="underline transition-colors duration-100 hover:text-neutral-600"
- >
- Terms of Service
- </a>{" "}
- for more details.
- </p> */}
- </div>
-
- {/* Program details grid */}
- <div className="mt-10">
- <h2 className="mb-2 text-base font-semibold text-neutral-800">
- Rewards
- </h2>
- <ProgramRewardList
- rewards={program.rewards}
- discount={program.defaultDiscount}
- className="bg-neutral-100"
- />
- </div>
-
- {/* Buttons */}
- <div className="animate-scale-in-fade mt-10 flex flex-col gap-2 [animation-delay:400ms] [animation-fill-mode:both]">
- <ApplyButton programSlug={program.slug} />
- </div>
+ <MaxWidthWrapper className="my-10">
+ <BackLink href="/programs">Programs</BackLink>
+ <div className="mt-8 grid grid-cols-1 gap-x-16 lg:grid-cols-[300px_minmax(0,600px)]">
+ <div>
+ <ProgramSidebar />
</div>
+ <div>
+ <div
+ className="relative"
+ style={
+ {
+ "--brand": "#000000",
+ "--brand-ring": "rgb(from var(--brand) r g b / 0.2)",
+ } as CSSProperties
+ }
+ >
+ {/* Hero section */}
+ <div className="grid grid-cols-1 gap-5">
+ <h1 className="text-4xl font-semibold">
+ Join the {program.name} affiliate program
+ </h1>
+ <p className="text-base text-neutral-700">
+ Share {program.name} with your audience and for each
+ subscription generated through your referral, you'll earn a
+ share of the revenue on any plans they purchase.
+ </p>
+ </div>
- {/* Content blocks */}
- {program.landerData && (
- <div className="mt-16 grid grid-cols-1 gap-10">
- {programLanderSchema
- .parse(program.landerData)
- .blocks.map((block, idx) => {
- const Component = BLOCK_COMPONENTS[block.type];
- return Component ? (
- <Component key={idx} block={block} logo={program.logo} />
- ) : null;
- })}
+ {/* Content blocks */}
+ {program.landerData && (
+ <div className="mt-10 grid grid-cols-1 gap-10">
+ {programLanderSchema
+ .parse(program.landerData)
+ .blocks.map((block, idx) => {
+ const Component = BLOCK_COMPONENTS[block.type];
+ return Component ? (
+ <Component key={idx} block={block} logo={program.logo} />
+ ) : null;
+ })}
+ </div>
+ )}
</div>
- )}
+ </div>
</div>
</MaxWidthWrapper>
);
diff --git a/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/apply/program-sidebar.tsx b/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/apply/program-sidebar.tsx
new file mode 100644
index 0000000000..1237342f5a
--- /dev/null
+++ b/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/apply/program-sidebar.tsx
@@ -0,0 +1,136 @@
+"use client";
+
+import { acceptProgramInviteAction } from "@/lib/actions/partners/accept-program-invite";
+import { mutatePrefix } from "@/lib/swr/mutate";
+import useProgramEnrollment from "@/lib/swr/use-program-enrollment";
+import { PartnerStatusBadges } from "@/ui/partners/partner-status-badges";
+import { ProgramRewardList } from "@/ui/partners/program-reward-list";
+import { BlurImage, Button, Link4, StatusBadge } from "@dub/ui";
+import { capitalize, OG_AVATAR_URL } from "@dub/utils";
+import { useAction } from "next-safe-action/hooks";
+import { useRouter } from "next/navigation";
+import { useMemo } from "react";
+import { toast } from "sonner";
+
+export function ProgramSidebar() {
+ const router = useRouter();
+
+ const { programEnrollment, loading: isLoadingProgramEnrollment } =
+ useProgramEnrollment();
+
+ const program = programEnrollment?.program;
+
+ const statusBadge = programEnrollment
+ ? {
+ ...PartnerStatusBadges,
+ pending: {
+ ...PartnerStatusBadges.pending,
+ label: "Applied",
+ },
+ }[programEnrollment.status]
+ : null;
+
+ const buttonText = useMemo(() => {
+ if (!programEnrollment) return "Apply";
+
+ switch (programEnrollment.status) {
+ case "pending":
+ return "Applied";
+ case "invited":
+ return "Accept invite";
+ case "approved":
+ return "Enrolled";
+ default:
+ return capitalize(programEnrollment.status);
+ }
+ }, [programEnrollment]);
+
+ const { executeAsync: executeAcceptInvite, isPending: isAcceptingInvite } =
+ useAction(acceptProgramInviteAction, {
+ onSuccess: async () => {
+ await mutatePrefix("/api/partner-profile/programs");
+ toast.success("Program invite accepted!");
+ if (program) {
+ router.push(`/programs/${program.slug}`);
+ }
+ },
+ onError: ({ error }) => {
+ toast.error(error.serverError);
+ },
+ });
+
+ return (
+ <div>
+ <div className="flex items-start justify-between gap-2">
+ {program ? (
+ <BlurImage
+ width={128}
+ height={128}
+ src={program.logo || `${OG_AVATAR_URL}${program.name}`}
+ alt={program.name}
+ className="size-16 rounded-full border border-black/10"
+ />
+ ) : (
+ <div className="size-16 animate-pulse rounded-full bg-neutral-200" />
+ )}
+ {statusBadge && (
+ <StatusBadge icon={statusBadge.icon} variant={statusBadge.variant}>
+ {statusBadge.label}
+ </StatusBadge>
+ )}
+ </div>
+ <div className="mt-4 flex flex-col">
+ {program ? (
+ <>
+ <span className="text-lg font-semibold text-neutral-800">
+ {program.name}
+ </span>
+ {program.domain && (
+ <div className="flex items-center gap-1 text-neutral-500">
+ <Link4 className="size-3" />
+ <span className="text-base font-medium">{program.domain}</span>
+ </div>
+ )}
+ </>
+ ) : (
+ <>
+ <div className="my-0.5 h-6 w-24 animate-pulse rounded-md bg-neutral-100" />
+ <div className="my-0.5 h-5 w-32 animate-pulse rounded-md bg-neutral-100" />
+ </>
+ )}
+ </div>
+
+ <div className="mt-8">
+ <h2 className="mb-2 text-base font-semibold text-neutral-800">
+ Rewards
+ </h2>
+ {programEnrollment ? (
+ <ProgramRewardList
+ rewards={programEnrollment.rewards ?? []}
+ discount={programEnrollment.discount}
+ className="bg-neutral-100"
+ />
+ ) : (
+ <div className="h-24 w-full animate-pulse rounded-md bg-neutral-100" />
+ )}
+ </div>
+
+ {!isLoadingProgramEnrollment && (
+ <Button
+ className="mt-8"
+ text={buttonText}
+ disabled={programEnrollment && programEnrollment.status !== "invited"}
+ onClick={() => {
+ if (programEnrollment?.status === "invited") {
+ executeAcceptInvite({
+ partnerId: programEnrollment.partnerId,
+ programId: programEnrollment.programId,
+ });
+ }
+ }}
+ loading={isAcceptingInvite}
+ />
+ )}
+ </div>
+ );
+}
diff --git a/apps/web/ui/layout/sidebar/partner-program-dropdown.tsx b/apps/web/ui/layout/sidebar/partner-program-dropdown.tsx
index 15ac97922c..4f740ffb82 100644
--- a/apps/web/ui/layout/sidebar/partner-program-dropdown.tsx
+++ b/apps/web/ui/layout/sidebar/partner-program-dropdown.tsx
@@ -52,6 +52,7 @@ export function PartnerProgramDropdown() {
...program.program,
logo:
program.program.logo || `${OG_AVATAR_URL}${program.program.name}`,
+ status: program.status,
}
: undefined;
}, [programSlug, programEnrollments]);
@@ -162,13 +163,15 @@ export function PartnerProgramDropdown() {
<div className="truncate text-sm font-medium leading-5 text-neutral-900">
{selectedProgram?.name || partner.name}
</div>
- <div
- className={cn(
- "truncate text-xs capitalize leading-tight text-neutral-600",
- )}
- >
- {selectedProgram ? "Enrolled" : "Partner"}
- </div>
+ {(!selectedProgram || selectedProgram.status === "approved") && (
+ <div
+ className={cn(
+ "truncate text-xs capitalize leading-tight text-neutral-600",
+ )}
+ >
+ {selectedProgram ? "Enrolled" : "Partner"}
+ </div>
+ )}
</div>
</div>
<ChevronsUpDown
diff --git a/apps/web/ui/partners/program-card.tsx b/apps/web/ui/partners/program-card.tsx
index d7b515f843..1951692a2f 100644
--- a/apps/web/ui/partners/program-card.tsx
+++ b/apps/web/ui/partners/program-card.tsx
@@ -50,7 +50,7 @@ export function ProgramCard({
: "",
)}
>
- <div className="">
+ <div>
<BlurImage
width={96}
height={96}