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.

finalize requirements

Steven Teyd9dc1c3a9b79
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/profile-details-form.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/profile-details-form.tsx
index df57ec2aec..0416dc9afd 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/profile-details-form.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/profile-details-form.tsx
@@ -87,6 +87,7 @@ export function ProfileDetailsForm({ partner }: { partner?: PartnerProps }) {
</div>
<SettingsRow
+ id="info"
heading="Basic information"
description="Your core details, and information that's required to set up your Dub Partner account."
>
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/use-partner-discovery-requirements.ts b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/use-partner-discovery-requirements.ts
index 430a0b1844..cb1a68dc27 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/use-partner-discovery-requirements.ts
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/use-partner-discovery-requirements.ts
@@ -1,6 +1,4 @@
-import {
- getPartnerProfileChecklistProgress,
-} from "@/lib/network/get-discoverability-requirements";
+import { getPartnerProfileChecklistProgress } from "@/lib/network/get-discoverability-requirements";
import usePartnerProfile from "@/lib/swr/use-partner-profile";
import useProgramEnrollments from "@/lib/swr/use-program-enrollments";
import { useMemo } from "react";
@@ -17,10 +15,6 @@ export function usePartnerDiscoveryRequirements() {
programEnrollments,
});
- if (!checklistProgress.isApplicable) {
- return undefined;
- }
-
return checklistProgress.tasks;
}, [partner, programEnrollments]);
}
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/[programSlug]/header-controls.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/[programSlug]/header-controls.tsx
index f7af3d198f..9caa5baa51 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/[programSlug]/header-controls.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/[programSlug]/header-controls.tsx
@@ -4,7 +4,6 @@ import { acceptProgramInviteAction } from "@/lib/actions/partners/accept-program
import { getPartnerProfileChecklistProgress } from "@/lib/network/get-discoverability-requirements";
import { mutatePrefix } from "@/lib/swr/mutate";
import usePartnerProfile from "@/lib/swr/use-partner-profile";
-import useProgramEnrollment from "@/lib/swr/use-program-enrollment";
import useProgramEnrollments from "@/lib/swr/use-program-enrollments";
import { NetworkProgramProps } from "@/lib/types";
import { useProgramApplicationSheet } from "@/ui/partners/program-application-sheet";
@@ -12,7 +11,7 @@ import { Button, ProgressCircle, useKeyboardShortcut } from "@dub/ui";
import { useAction } from "next-safe-action/hooks";
import Link from "next/link";
import { useParams, useRouter } from "next/navigation";
-import { ReactNode } from "react";
+import { ReactNode, useMemo } from "react";
import { toast } from "sonner";
export function MarketplaceProgramHeaderControls({
@@ -52,52 +51,53 @@ function ApplyButton({ program }: { program: NetworkProgramProps }) {
const { partner } = usePartnerProfile();
const { programEnrollments } = useProgramEnrollments();
- const { programEnrollment } = useProgramEnrollment();
- const checklistProgress =
- partner && programEnrollments
+ const programEnrollment = useMemo(
+ () =>
+ programEnrollments?.find(
+ (programEnrollment) => programEnrollment.program.slug === program.slug,
+ ),
+ [programEnrollments, program.slug],
+ );
+
+ const checklistProgress = useMemo(() => {
+ return partner && programEnrollments
? getPartnerProfileChecklistProgress({
partner,
programEnrollments,
})
: undefined;
+ }, [partner, programEnrollments]);
const disabledTooltip: ReactNode =
- programEnrollment?.status === "banned"
- ? "You are banned from this program"
- : programEnrollment?.status === "pending"
- ? "Your application is under review"
- : programEnrollment?.status === "rejected"
- ? "Your application was rejected"
- : checklistProgress && !checklistProgress.isComplete
- ? (
- <div className="max-w-xs p-4">
- <div className="text-content-default text-sm leading-5">
- Complete your{" "}
- <Link
- href="/profile"
- className="underline underline-offset-2"
- >
- partner profile
- </Link>{" "}
- to apply
- </div>
- <div className="bg-bg-subtle mt-3 flex items-center justify-center gap-2 rounded-lg px-2.5 py-1.5">
- <ProgressCircle
- progress={
- checklistProgress.completedCount /
- checklistProgress.totalCount
- }
- className="text-green-500"
- />
- <span className="text-content-default text-sm font-medium">
- {checklistProgress.completedCount} of{" "}
- {checklistProgress.totalCount} tasks completed
- </span>
- </div>
- </div>
- )
- : undefined;
+ programEnrollment?.status === "banned" ? (
+ "You are banned from this program"
+ ) : programEnrollment?.status === "pending" ? (
+ "Your application is under review"
+ ) : programEnrollment?.status === "rejected" ? (
+ "Your application was rejected"
+ ) : checklistProgress && !checklistProgress.isComplete ? (
+ <div className="max-w-xs p-4">
+ <div className="text-content-default text-sm leading-5">
+ Complete your partner profile to apply
+ </div>
+ <Link
+ href="/profile"
+ className="bg-bg-subtle mt-3 flex items-center justify-center gap-2 rounded-lg px-2.5 py-1.5"
+ >
+ <ProgressCircle
+ progress={
+ checklistProgress.completedCount / checklistProgress.totalCount
+ }
+ className="text-green-500"
+ />
+ <span className="text-content-default text-sm font-medium">
+ {checklistProgress.completedCount} of {checklistProgress.totalCount}{" "}
+ tasks completed
+ </span>
+ </Link>
+ </div>
+ ) : undefined;
useKeyboardShortcut("a", () => setIsApplicationSheetOpen(true), {
enabled: !disabledTooltip,
diff --git a/apps/web/app/api/user/referrals-token/route.ts b/apps/web/app/api/user/referrals-token/route.ts
index 2826b529f7..b423cb5597 100644
--- a/apps/web/app/api/user/referrals-token/route.ts
+++ b/apps/web/app/api/user/referrals-token/route.ts
@@ -1,6 +1,9 @@
import { withSession } from "@/lib/auth";
import { dub } from "@/lib/dub";
-import { partnerCanViewMarketplace } from "@/lib/network/get-discoverability-requirements";
+import {
+ partnerHasEarnedCommissions,
+ partnerIsNotBanned,
+} from "@/lib/network/get-discoverability-requirements";
import { prisma } from "@dub/prisma";
import { NextResponse } from "next/server";
@@ -31,16 +34,19 @@ export const GET = withSession(async ({ session }) => {
},
});
const paidWorkspaces = user.projects.map((project) => project);
+
// for free users, need to do some extra checks
- if (!paidWorkspaces || paidWorkspaces.length === 0) {
- // if the free user has a partner account, they are only eligible if they can view the program marketplace
- const programEnrollments = user.partners[0]?.partner.programs;
+ if (paidWorkspaces.length === 0) {
+ // for partners with free workspaces, they are only eligible if they have a good reputation
+ const programEnrollments = user.partners[0]
+ ? user.partners[0].partner.programs
+ : [];
if (
- programEnrollments &&
- !partnerCanViewMarketplace({
- partner: user.partners[0]?.partner,
- programEnrollments,
- })
+ programEnrollments.length > 0 &&
+ !(
+ partnerHasEarnedCommissions(programEnrollments) &&
+ partnerIsNotBanned(programEnrollments)
+ )
) {
return NextResponse.json({ publicToken: null });
}
diff --git a/apps/web/lib/actions/partners/create-program-application.ts b/apps/web/lib/actions/partners/create-program-application.ts
index 390033d45c..0e18a141e0 100644
--- a/apps/web/lib/actions/partners/create-program-application.ts
+++ b/apps/web/lib/actions/partners/create-program-application.ts
@@ -170,18 +170,6 @@ export const createProgramApplicationAction = actionClient
})
: null;
- const checklistProgress = existingPartner
- ? getPartnerProfileChecklistProgress({
- partner: existingPartner,
- programEnrollments: existingPartner.programs,
- })
- : null;
-
- // if an existing partner has an incomplete profile, prompt them to complete it
- if (existingPartner && !checklistProgress?.isComplete) {
- throw new Error("Complete your partner profile to apply");
- }
-
// if the application form is not published and
// the partner is not logged in, throw an error
if (!group.applicationFormPublishedAt && !existingPartner) {
@@ -189,6 +177,16 @@ export const createProgramApplicationAction = actionClient
}
if (existingPartner) {
+ // if an existing partner has an incomplete profile, prompt them to complete it
+ const { isComplete } = getPartnerProfileChecklistProgress({
+ partner: existingPartner,
+ programEnrollments: existingPartner.programs,
+ });
+
+ if (!isComplete) {
+ throw new Error("Complete your partner profile to apply.");
+ }
+
return createApplicationAndEnrollment({
workspace: program.workspace,
program,
diff --git a/apps/web/lib/network/get-discoverability-requirements.ts b/apps/web/lib/network/get-discoverability-requirements.ts
index 5960538e6d..2dccca325c 100644
--- a/apps/web/lib/network/get-discoverability-requirements.ts
+++ b/apps/web/lib/network/get-discoverability-requirements.ts
@@ -22,31 +22,12 @@ export const partnerHasEarnedCommissions = (
);
};
-const partnerIsNotBanned = (
+export const partnerIsNotBanned = (
programEnrollments: Pick<EnrolledPartnerProps, "programId" | "status">[],
) => {
return programEnrollments.every((pe) => pe.status !== "banned");
};
-export const partnerCanViewMarketplace = ({
- partner,
- programEnrollments,
-}: {
- partner?: Pick<PartnerProps, "email">;
- programEnrollments: Pick<
- EnrolledPartnerProps,
- "programId" | "status" | "totalCommissions"
- >[];
-}) => {
- if (partner?.email?.endsWith("@dub.co")) {
- return true;
- }
- return (
- partnerHasEarnedCommissions(programEnrollments) &&
- partnerIsNotBanned(programEnrollments)
- );
-};
-
export type DiscoverabilityRequirement = {
label: string;
href?: string;
@@ -59,6 +40,7 @@ export function getPartnerProfileChecklistProgress({
}: {
partner: Pick<
PartnerProps,
+ | "image"
| "description"
| "monthlyTraffic"
| "preferredEarningStructures"
@@ -78,23 +60,11 @@ export function getPartnerProfileChecklistProgress({
const completedCount = tasks.filter(({ completed }) => completed).length;
const totalCount = tasks.length;
- const enrollmentProgramIds = new Set(
- programEnrollments.map((enrollment) => enrollment.programId),
- );
- const hasExcludedProgram = EXCLUDED_PROGRAM_IDS.some((id) =>
- enrollmentProgramIds.has(id),
- );
-
- const isApplicable = !(
- hasExcludedProgram && !partnerHasEarnedCommissions(programEnrollments)
- );
-
return {
tasks,
completedCount,
totalCount,
- isApplicable,
- isComplete: !isApplicable || completedCount === totalCount,
+ isComplete: completedCount === totalCount,
};
}
@@ -104,6 +74,7 @@ export function getDiscoverabilityRequirements({
}: {
partner: Pick<
PartnerProps,
+ | "image"
| "description"
| "monthlyTraffic"
| "preferredEarningStructures"
@@ -117,18 +88,20 @@ export function getDiscoverabilityRequirements({
}): DiscoverabilityRequirement[] {
return [
{
- label: "Add basic profile info",
- completed: true,
+ label: "Upload your logo",
+ href: "#info",
+ completed: !!partner.image,
},
{
- label: "Connect your website or social account",
+ label: "Verify at least 2 social accounts/website",
href: "#sites",
- completed: PARTNER_PLATFORM_FIELDS.some(
- (field) => field.data(partner.platforms).value, // TODO: update this to also check for "verified" in the future
- ),
+ completed:
+ PARTNER_PLATFORM_FIELDS.filter(
+ (field) => field.data(partner.platforms).verified,
+ ).length >= 2,
},
{
- label: "Update your profile description",
+ label: "Fill out your profile description",
href: "#about",
completed: !!partner.description,
},
@@ -147,13 +120,13 @@ export function getDiscoverabilityRequirements({
href: "#channels",
completed: Boolean(partner.salesChannels?.length),
},
- {
- label: "Maintain a healthy partner profile",
- completed: partnerIsNotBanned(programEnrollments),
- },
{
label: `Earn ${currencyFormatter(PARTNER_NETWORK_MIN_COMMISSIONS_CENTS, { trailingZeroDisplay: "stripIfInteger" })} in commissions`,
completed: partnerHasEarnedCommissions(programEnrollments),
},
+ {
+ label: "Maintain a healthy partner profile",
+ completed: partnerIsNotBanned(programEnrollments),
+ },
];
}
diff --git a/apps/web/lib/network/throw-if-partner-cannot-view-marketplace.ts b/apps/web/lib/network/throw-if-partner-cannot-view-marketplace.ts
deleted file mode 100644
index 90ac57d8b2..0000000000
--- a/apps/web/lib/network/throw-if-partner-cannot-view-marketplace.ts
+++ /dev/null
@@ -1,50 +0,0 @@
-import { DubApiError } from "@/lib/api/errors";
-import {
- EXCLUDED_PROGRAM_IDS,
- PARTNER_NETWORK_MIN_COMMISSIONS_CENTS,
-} from "@/lib/constants/partner-profile";
-import { PartnerProps } from "@/lib/types";
-import { prisma } from "@dub/prisma";
-
-// similar logic to partnerCanViewMarketplace but throws an error instead of returning a boolean
-export async function throwIfPartnerCannotViewMarketplace({
- partner,
-}: {
- partner: Pick<PartnerProps, "id">;
-}) {
- const data = await prisma.partner.findUnique({
- where: {
- id: partner.id,
- OR: [
- {
- email: {
- endsWith: "@dub.co",
- },
- },
- {
- programs: {
- some: {
- programId: {
- notIn: EXCLUDED_PROGRAM_IDS,
- },
- status: "approved",
- totalCommissions: {
- gte: PARTNER_NETWORK_MIN_COMMISSIONS_CENTS,
- },
- },
- none: {
- status: "banned",
- },
- },
- },
- ],
- },
- });
-
- if (!data) {
- throw new DubApiError({
- code: "forbidden",
- message: "Program marketplace is not available for this partner.",
- });
- }
-}
diff --git a/apps/web/tests/misc/partner-profile-checklist-progress.test.ts b/apps/web/tests/misc/partner-profile-checklist-progress.test.ts
index 327d17b057..9b0f1ff56a 100644
--- a/apps/web/tests/misc/partner-profile-checklist-progress.test.ts
+++ b/apps/web/tests/misc/partner-profile-checklist-progress.test.ts
@@ -8,6 +8,7 @@ import { describe, expect, it } from "vitest";
type ChecklistInput = Parameters<typeof getPartnerProfileChecklistProgress>[0];
const basePartner: ChecklistInput["partner"] = {
+ image: null,
description: null,
monthlyTraffic: null,
preferredEarningStructures: [],
@@ -15,6 +16,35 @@ const basePartner: ChecklistInput["partner"] = {
platforms: [],
};
+const completedPartner: ChecklistInput["partner"] = {
+ ...basePartner,
+ image: "https://example.com/logo.png",
+ description: "Creator profile",
+ monthlyTraffic: "OneHundredThousandPlus",
+ preferredEarningStructures: ["Per_Sale"],
+ salesChannels: ["Blogs"],
+ platforms: [
+ {
+ type: "website",
+ identifier: "https://example.com",
+ verifiedAt: new Date(),
+ platformId: null,
+ subscribers: BigInt(0),
+ posts: BigInt(0),
+ views: BigInt(0),
+ },
+ {
+ type: "youtube",
+ identifier: "UC1234567890",
+ verifiedAt: new Date(),
+ platformId: null,
+ subscribers: BigInt(0),
+ posts: BigInt(0),
+ views: BigInt(0),
+ },
+ ],
+};
+
describe("getPartnerProfileChecklistProgress", () => {
it("returns incomplete progress for an incomplete profile", () => {
const result = getPartnerProfileChecklistProgress({
@@ -22,32 +52,13 @@ describe("getPartnerProfileChecklistProgress", () => {
programEnrollments: [],
});
- expect(result.isApplicable).toBe(true);
expect(result.isComplete).toBe(false);
expect(result.completedCount).toBeLessThan(result.totalCount);
- expect(result.totalCount).toBe(8);
});
it("returns complete progress when all checklist tasks are complete", () => {
const result = getPartnerProfileChecklistProgress({
- partner: {
- ...basePartner,
- description: "Creator profile",
- monthlyTraffic: "OneHundredThousandPlus",
- preferredEarningStructures: ["Per_Sale"],
- salesChannels: ["Blogs"],
- platforms: [
- {
- type: "website",
- identifier: "https://example.com",
- verifiedAt: null,
- platformId: null,
- subscribers: BigInt(0),
- posts: BigInt(0),
- views: BigInt(0),
- },
- ],
- },
+ partner: completedPartner,
programEnrollments: [
{
programId: "prog_non_excluded",
@@ -57,28 +68,26 @@ describe("getPartnerProfileChecklistProgress", () => {
],
});
- expect(result.isApplicable).toBe(true);
expect(result.isComplete).toBe(true);
expect(result.completedCount).toBe(result.totalCount);
- expect(result.totalCount).toBe(8);
+ expect(result.completedCount).toBe(8);
});
it("handles the excluded-program edge case consistently", () => {
expect(EXCLUDED_PROGRAM_IDS.length).toBeGreaterThan(0);
const result = getPartnerProfileChecklistProgress({
- partner: basePartner,
+ partner: completedPartner,
programEnrollments: [
{
programId: EXCLUDED_PROGRAM_IDS[0],
status: "approved",
- totalCommissions: 0,
+ totalCommissions: PARTNER_NETWORK_MIN_COMMISSIONS_CENTS,
},
],
});
- expect(result.isApplicable).toBe(false);
- expect(result.isComplete).toBe(true);
- expect(result.totalCount).toBe(8);
+ expect(result.isComplete).toBe(false);
+ expect(result.completedCount).toBe(7);
});
});