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.

Handle nullable saleAmount on partner profile enrollment types.

Kiran K2a826391d13f
diff --git a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/route.ts b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/route.ts
index 637a2e3325..8784f21d89 100644
--- a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/route.ts
+++ b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/route.ts
@@ -1,7 +1,7 @@
import { getProgramEnrollmentOrThrow } from "@/lib/api/programs/get-program-enrollment-or-throw";
import { withPartnerProfile } from "@/lib/auth/partner";
import { hidePartnerSaleAmount } from "@/lib/partners/hide-partner-revenue";
-import { ProgramEnrollmentSchema } from "@/lib/zod/schemas/programs";
+import { PartnerProfileProgramEnrollmentSchema } from "@/lib/zod/schemas/partner-profile";
import { Reward } from "@prisma/client";
import { NextResponse } from "next/server";
@@ -42,7 +42,7 @@ export const GET = withPartnerProfile(async ({ partner, params }) => {
const { partnerGroup } = programEnrollment;
return NextResponse.json(
- ProgramEnrollmentSchema.parse({
+ PartnerProfileProgramEnrollmentSchema.parse({
...programEnrollment,
links: programEnrollment.links?.map((link) =>
hidePartnerSaleAmount(link, partnerGroup),
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/messages/[programSlug]/page.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/messages/[programSlug]/page.tsx
index b13824d14b..4350be6e38 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/messages/[programSlug]/page.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/messages/[programSlug]/page.tsx
@@ -13,7 +13,7 @@ import usePartnerAnalytics from "@/lib/swr/use-partner-analytics";
import usePartnerProfile from "@/lib/swr/use-partner-profile";
import useProgramEnrollment from "@/lib/swr/use-program-enrollment";
import useUser from "@/lib/swr/use-user";
-import { ProgramEnrollmentProps } from "@/lib/types";
+import { PartnerProfileProgramEnrollmentProps } from "@/lib/types";
import {
COMMISSION_ELIGIBLE_ENROLLMENT_STATUSES,
INACTIVE_ENROLLMENT_STATUSES,
@@ -446,7 +446,7 @@ export default function PartnerMessagesProgramPage() {
function ProgramInfoPanel({
programEnrollment,
}: {
- programEnrollment: ProgramEnrollmentProps;
+ programEnrollment: PartnerProfileProgramEnrollmentProps;
}) {
const program = programEnrollment.program;
const partnerLink = constructPartnerLink({
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/unapproved-program-page.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/unapproved-program-page.tsx
index 2e1d675921..cd7784746e 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/unapproved-program-page.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/unapproved-program-page.tsx
@@ -1,6 +1,6 @@
import { withdrawProgramApplicationAction } from "@/lib/actions/partners/withdraw-program-application";
import { mutatePrefix } from "@/lib/swr/mutate";
-import { ProgramEnrollmentProps } from "@/lib/types";
+import { PartnerProfileProgramEnrollmentProps } from "@/lib/types";
import { PageContent } from "@/ui/layout/page-content";
import { PageWidthWrapper } from "@/ui/layout/page-width-wrapper";
import { useConfirmModal } from "@/ui/modals/confirm-modal";
@@ -14,7 +14,7 @@ import { toast } from "sonner";
const states: Record<
string,
- (programEnrollment: ProgramEnrollmentProps) => {
+ (programEnrollment: PartnerProfileProgramEnrollmentProps) => {
title: string;
description: ReactNode;
}
@@ -42,7 +42,7 @@ const states: Record<
export function UnapprovedProgramPage({
programEnrollment,
}: {
- programEnrollment: ProgramEnrollmentProps;
+ programEnrollment: PartnerProfileProgramEnrollmentProps;
}) {
const router = useRouter();
diff --git a/apps/web/lib/swr/use-program-enrollment.ts b/apps/web/lib/swr/use-program-enrollment.ts
index 7329b91f76..c54712b0be 100644
--- a/apps/web/lib/swr/use-program-enrollment.ts
+++ b/apps/web/lib/swr/use-program-enrollment.ts
@@ -6,7 +6,7 @@ import { fetcher } from "@dub/utils";
import { useSession } from "next-auth/react";
import { useParams } from "next/navigation";
import useSWR, { SWRConfiguration } from "swr";
-import { ProgramEnrollmentProps } from "../types";
+import { PartnerProfileProgramEnrollmentProps } from "../types";
export default function useProgramEnrollment({
enabled = true,
@@ -27,7 +27,7 @@ export default function useProgramEnrollment({
data: programEnrollment,
error,
isLoading,
- } = useSWR<ProgramEnrollmentProps>(
+ } = useSWR<PartnerProfileProgramEnrollmentProps>(
enabled && partnerId && programSlug
? `/api/partner-profile/programs/${programSlug}`
: undefined,
@@ -49,7 +49,7 @@ export default function useProgramEnrollment({
export function getShowDetailedAnalytics(
programEnrollment: Pick<
- ProgramEnrollmentProps,
+ PartnerProfileProgramEnrollmentProps,
"programId" | "status" | "totalCommissions"
>,
) {
diff --git a/apps/web/lib/zod/schemas/partner-profile.ts b/apps/web/lib/zod/schemas/partner-profile.ts
index c6eed98a03..0dc249b99a 100644
--- a/apps/web/lib/zod/schemas/partner-profile.ts
+++ b/apps/web/lib/zod/schemas/partner-profile.ts
@@ -31,7 +31,11 @@ import { DiscountSchema } from "./discount";
import { LinkSchema } from "./links";
import { booleanQuerySchema, getPaginationQuerySchema } from "./misc";
import { payoutsQuerySchema } from "./payouts";
-import { ProgramEnrollmentSchema, ProgramSchema } from "./programs";
+import {
+ ProgramEnrollmentSchema,
+ ProgramPartnerLinkSchema,
+ ProgramSchema,
+} from "./programs";
import { RewardSchema } from "./rewards";
import { submittedLeadFormDataSchema } from "./submitted-lead-form";
import { centsSchema } from "./utils";
@@ -239,6 +243,11 @@ export const partnerProfileEventsQuerySchema = eventsQuerySchema.omit({
folderId: true,
});
+export const PartnerProfileProgramPartnerLinkSchema =
+ ProgramPartnerLinkSchema.extend({
+ saleAmount: centsSchema.nullable(),
+ });
+
// GET /api/partner-profile/programs adds the reapplication timeframe, so that
// a rejected program can say when the partner can apply again
export const PartnerProfileProgramEnrollmentSchema =
@@ -250,6 +259,10 @@ export const PartnerProfileProgramEnrollmentSchema =
.describe(
"When the program banned, deactivated or archived the partner. For deactivated and archived enrollments, only set when `includeInactiveDates=true`. Null for other statuses, and when the date is not known.",
),
+ links: z
+ .array(PartnerProfileProgramPartnerLinkSchema)
+ .nullable()
+ .describe("The partner's referral links in this program."),
});
export const partnerProfileProgramsQuerySchema = z.object({
diff --git a/apps/web/lib/zod/schemas/programs.ts b/apps/web/lib/zod/schemas/programs.ts
index 7b5e010dc4..a0267bc3d5 100644
--- a/apps/web/lib/zod/schemas/programs.ts
+++ b/apps/web/lib/zod/schemas/programs.ts
@@ -22,7 +22,7 @@ import { programInviteEmailDataSchema } from "./program-invite-email";
import { RewardSchema } from "./rewards";
import { submittedLeadFormSchema } from "./submitted-lead-form";
import { UserSchema } from "./users";
-import { centsSchema, centsSchemaWithDefault, parseDateSchema } from "./utils";
+import { centsSchemaWithDefault, parseDateSchema } from "./utils";
export const eligibilityConditionSchema = z
.object({
@@ -124,8 +124,6 @@ export const ProgramPartnerLinkSchema = LinkSchema.pick({
conversions: true,
sales: true,
saleAmount: true,
-}).extend({
- saleAmount: centsSchema.nullable(),
});
// Internal-only fields used by the Dub UI.
diff --git a/apps/web/ui/partners/program-application-sheet.tsx b/apps/web/ui/partners/program-application-sheet.tsx
index f1b4ed3a6f..13401a50e6 100644
--- a/apps/web/ui/partners/program-application-sheet.tsx
+++ b/apps/web/ui/partners/program-application-sheet.tsx
@@ -3,7 +3,10 @@
import { parseActionError } from "@/lib/actions/parse-action-errors";
import { createProgramApplicationAction } from "@/lib/actions/partners/create-program-application";
import usePartnerProfile from "@/lib/swr/use-partner-profile";
-import { ProgramEnrollmentProps, ProgramProps } from "@/lib/types";
+import {
+ PartnerProfileProgramEnrollmentProps,
+ ProgramProps,
+} from "@/lib/types";
import { PartnerProgramGroupSchema } from "@/lib/zod/schemas/groups";
import { createProgramApplicationSchema } from "@/lib/zod/schemas/programs";
import { X } from "@/ui/shared/icons";
@@ -35,7 +38,7 @@ interface ProgramApplicationSheetProps {
ProgramProps,
"id" | "slug" | "defaultGroupId" | "name" | "domain" | "logo" | "termsUrl"
>;
- programEnrollment?: ProgramEnrollmentProps;
+ programEnrollment?: PartnerProfileProgramEnrollmentProps;
backDestination?: "programs" | "marketplace";
onSuccess?: () => void;
}
diff --git a/apps/web/ui/partners/program-invite-actions.tsx b/apps/web/ui/partners/program-invite-actions.tsx
index 54706db7f6..8f4c7b7663 100644
--- a/apps/web/ui/partners/program-invite-actions.tsx
+++ b/apps/web/ui/partners/program-invite-actions.tsx
@@ -1,6 +1,6 @@
import { acceptProgramInviteAction } from "@/lib/actions/partners/accept-program-invite";
import { mutatePrefix } from "@/lib/swr/mutate";
-import { ProgramEnrollmentProps } from "@/lib/types";
+import { PartnerProfileProgramEnrollmentProps } from "@/lib/types";
import { Button, buttonVariants } from "@dub/ui";
import { cn } from "@dub/utils";
import { useAction } from "next-safe-action/hooks";
@@ -14,7 +14,7 @@ export function ProgramInviteActions({
className,
buttonClassName,
}: {
- programEnrollment: ProgramEnrollmentProps;
+ programEnrollment: PartnerProfileProgramEnrollmentProps;
className?: string;
buttonClassName?: string;
}) {
diff --git a/apps/web/ui/partners/program-invite-card.tsx b/apps/web/ui/partners/program-invite-card.tsx
index 827b2b6e68..fc175c8f94 100644
--- a/apps/web/ui/partners/program-invite-card.tsx
+++ b/apps/web/ui/partners/program-invite-card.tsx
@@ -1,4 +1,4 @@
-import { ProgramEnrollmentProps } from "@/lib/types";
+import { PartnerProfileProgramEnrollmentProps } from "@/lib/types";
import { ProgramInviteActions } from "@/ui/partners/program-invite-actions";
import { ProgramLogo } from "@/ui/partners/program-logo";
import { ProgramRewardDescription } from "@/ui/partners/program-reward-description";
@@ -8,7 +8,7 @@ import { formatDateSmart } from "@dub/utils";
export function ProgramInviteCard({
programEnrollment,
}: {
- programEnrollment: ProgramEnrollmentProps;
+ programEnrollment: PartnerProfileProgramEnrollmentProps;
}) {
const { program } = programEnrollment;