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.

split out partner side types, totalCommission → totalCommissions

Steven Teyc270b8c831db
diff --git a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/bounties/route.ts b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/bounties/route.ts
index dfb5f40e6b..d54735d6cd 100644
--- a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/bounties/route.ts
+++ b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/bounties/route.ts
@@ -1,7 +1,7 @@
import { getProgramEnrollmentOrThrow } from "@/lib/api/programs/get-program-enrollment-or-throw";
import { withPartnerProfile } from "@/lib/auth/partner";
import { aggregatePartnerLinksStats } from "@/lib/partners/aggregate-partner-links-stats";
-import { BountyWithPartnerDataSchema } from "@/lib/zod/schemas/bounties";
+import { PartnerBountySchema } from "@/lib/zod/schemas/partner-profile";
import { prisma } from "@dub/prisma";
import { NextResponse } from "next/server";
import { z } from "zod";
@@ -69,11 +69,8 @@ export const GET = withPartnerProfile(async ({ partner, params }) => {
},
});
- const { totalLeads, totalConversions, totalSaleAmount } =
- aggregatePartnerLinksStats(links);
-
return NextResponse.json(
- z.array(BountyWithPartnerDataSchema).parse(
+ z.array(PartnerBountySchema).parse(
bounties.map((bounty) => {
const triggerConditions = Array.isArray(
bounty.workflow?.triggerConditions,
@@ -85,12 +82,7 @@ export const GET = withPartnerProfile(async ({ partner, params }) => {
...bounty,
performanceCondition:
triggerConditions.length > 0 ? triggerConditions[0] : null,
- partner: {
- leads: totalLeads,
- conversions: totalConversions,
- saleAmount: totalSaleAmount,
- totalCommissions,
- },
+ partner: aggregatePartnerLinksStats(links),
};
}),
),
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/page-client.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/page-client.tsx
index 18c2badaaa..dfe47f9503 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/page-client.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/page-client.tsx
@@ -4,7 +4,10 @@ import usePartnerProgramBounties from "@/lib/swr/use-partner-program-bounties";
import { PageWidthWrapper } from "@/ui/layout/page-width-wrapper";
import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
import { Heart, Trophy } from "@dub/ui/icons";
-import { BountyCard, BountyCardSkeleton } from "./bounty-card";
+import {
+ PartnerBountyCard,
+ PartnerBountyCardSkeleton,
+} from "./partner-bounty-card";
export function BountiesPageClient() {
const { bounties, isLoading } = usePartnerProgramBounties();
@@ -15,10 +18,10 @@ export function BountiesPageClient() {
<div className="grid grid-cols-1 gap-6 md:grid-cols-2 xl:grid-cols-3">
{bounties?.length
? bounties?.map((bounty) => (
- <BountyCard key={bounty.id} bounty={bounty} />
+ <PartnerBountyCard key={bounty.id} bounty={bounty} />
))
: Array.from({ length: 3 }, (_, index) => (
- <BountyCardSkeleton key={index} />
+ <PartnerBountyCardSkeleton key={index} />
))}
</div>
) : (
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/bounty-card.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/partner-bounty-card.tsx
similarity index 95%
rename from apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/bounty-card.tsx
rename to apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/partner-bounty-card.tsx
index 8a09fa7659..cc02aeee8d 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/bounty-card.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/partner-bounty-card.tsx
@@ -1,4 +1,4 @@
-import { BountyWithPartnerDataProps } from "@/lib/types";
+import { PartnerBountyProps } from "@/lib/types";
import { BountyPerformance } from "@/ui/partners/bounties/bounty-performance";
import { BountyThumbnailImage } from "@/ui/partners/bounties/bounty-thumbnail-image";
import { useClaimBountyModal } from "@/ui/partners/bounties/claim-bounty-modal";
@@ -6,7 +6,7 @@ import { StatusBadge } from "@dub/ui";
import { Calendar6 } from "@dub/ui/icons";
import { formatDate } from "@dub/utils";
-export function BountyCard({ bounty }: { bounty: BountyWithPartnerDataProps }) {
+export function PartnerBountyCard({ bounty }: { bounty: PartnerBountyProps }) {
const submission = bounty.submissions?.[0];
const { claimBountyModal, setShowClaimBountyModal } = useClaimBountyModal({
@@ -89,7 +89,7 @@ export function BountyCard({ bounty }: { bounty: BountyWithPartnerDataProps }) {
);
}
-export const BountyCardSkeleton = () => {
+export const PartnerBountyCardSkeleton = () => {
return (
<div className="border-border-subtle rounded-xl border bg-white p-5">
<div className="flex flex-col gap-5">
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx
index 8465531a70..31a7938ab8 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx
@@ -221,7 +221,7 @@ export function BountySubmissionsTable() {
value = row.original.partner.conversions;
} else if (attribute === "totalSaleAmount") {
value = row.original.partner.saleAmount;
- } else if (attribute === "totalCommission") {
+ } else if (attribute === "totalCommissions") {
value = row.original.partner.totalCommissions;
}
diff --git a/apps/web/lib/api/workflows/execute-workflows.ts b/apps/web/lib/api/workflows/execute-workflows.ts
index e62145206f..f4f7dc7d1f 100644
--- a/apps/web/lib/api/workflows/execute-workflows.ts
+++ b/apps/web/lib/api/workflows/execute-workflows.ts
@@ -79,7 +79,7 @@ export async function executeWorkflows({
totalLeads,
totalConversions,
totalSaleAmount,
- totalCommission: programEnrollment.totalCommissions,
+ totalCommissions: programEnrollment.totalCommissions,
};
// Execute each workflow for the program
diff --git a/apps/web/lib/api/workflows/utils.ts b/apps/web/lib/api/workflows/utils.ts
index 61741b354e..d6e47eac35 100644
--- a/apps/web/lib/api/workflows/utils.ts
+++ b/apps/web/lib/api/workflows/utils.ts
@@ -1,4 +1,4 @@
import { WorkflowConditionAttribute } from "@/lib/types";
export const isCurrencyAttribute = (activity: WorkflowConditionAttribute) =>
- activity === "totalCommission" || activity === "totalSaleAmount";
+ activity === "totalCommissions" || activity === "totalSaleAmount";
diff --git a/apps/web/lib/swr/use-partner-program-bounties.ts b/apps/web/lib/swr/use-partner-program-bounties.ts
index dfb1044b29..d66a67fd9b 100644
--- a/apps/web/lib/swr/use-partner-program-bounties.ts
+++ b/apps/web/lib/swr/use-partner-program-bounties.ts
@@ -1,7 +1,7 @@
import { fetcher } from "@dub/utils";
import { useParams } from "next/navigation";
import useSWR from "swr";
-import { BountyWithPartnerDataProps } from "../types";
+import { PartnerBountyProps } from "../types";
export default function usePartnerProgramBounties({
enabled = true,
@@ -14,7 +14,7 @@ export default function usePartnerProgramBounties({
data: bounties,
isLoading,
error,
- } = useSWR<BountyWithPartnerDataProps[]>(
+ } = useSWR<PartnerBountyProps[]>(
enabled &&
programSlug &&
`/api/partner-profile/programs/${programSlug}/bounties`,
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index 6ebb6aa709..4bb5a258e7 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -1,5 +1,6 @@
import z from "@/lib/zod";
import {
+ PartnerBountySchema,
PartnerEarningsSchema,
PartnerProfileCustomerSchema,
PartnerProfileLinkSchema,
@@ -26,9 +27,7 @@ import { WEBHOOK_TRIGGER_DESCRIPTIONS } from "./webhook/constants";
import {
BountySchema,
BountySchemaExtended,
- bountyStatsSchema,
BountySubmissionExtendedSchema,
- BountyWithPartnerDataSchema,
getBountySubmissionsQuerySchema,
SUBMISSION_REQUIREMENTS,
} from "./zod/schemas/bounties";
@@ -530,9 +529,7 @@ export type BountyProps = z.infer<typeof BountySchema>;
export type BountyExtendedProps = z.infer<typeof BountySchemaExtended>;
-export type BountyWithPartnerDataProps = z.infer<
- typeof BountyWithPartnerDataSchema
->;
+export type PartnerBountyProps = z.infer<typeof PartnerBountySchema>;
export type BountySubmissionProps = z.infer<
typeof BountySubmissionExtendedSchema
@@ -541,8 +538,6 @@ export type BountySubmissionProps = z.infer<
export type BountySubmissionRequirement =
(typeof SUBMISSION_REQUIREMENTS)[number];
-export type BountyStats = z.infer<typeof bountyStatsSchema>;
-
export type WorkflowCondition = z.infer<typeof workflowConditionSchema>;
export type WorkflowConditionAttribute = (typeof WORKFLOW_ATTRIBUTES)[number];
diff --git a/apps/web/lib/zod/schemas/bounties.ts b/apps/web/lib/zod/schemas/bounties.ts
index 8cf8dd41b3..bc465c5ba8 100644
--- a/apps/web/lib/zod/schemas/bounties.ts
+++ b/apps/web/lib/zod/schemas/bounties.ts
@@ -72,7 +72,7 @@ export const BountySchemaExtended = BountySchema.extend({
submissions: z.record(z.nativeEnum(BountySubmissionStatus), z.number()),
});
-const BountySubmissionSchema = z.object({
+export const BountySubmissionSchema = z.object({
id: z.string(),
description: z.string().nullable(),
urls: z.array(z.string()).nullable(),
@@ -116,23 +116,6 @@ export const BountySubmissionExtendedSchema = z.object({
}).nullable(),
});
-export const BountyWithPartnerDataSchema = BountySchema.extend({
- submissions: z.array(BountySubmissionSchema).nullable(),
- partner: EnrolledPartnerSchema.pick({
- leads: true,
- conversions: true,
- saleAmount: true,
- totalCommissions: true,
- }),
-});
-
-export const bountyStatsSchema = z.object({
- id: z.string(),
- submissions: z.number(),
- pendingSubmissions: z.number(),
- partners: z.number(),
-});
-
export const rejectBountySubmissionSchema = z.object({
workspaceId: z.string(),
submissionId: z.string(),
diff --git a/apps/web/lib/zod/schemas/partner-profile.ts b/apps/web/lib/zod/schemas/partner-profile.ts
index 662c0ccc31..e137b7f926 100644
--- a/apps/web/lib/zod/schemas/partner-profile.ts
+++ b/apps/web/lib/zod/schemas/partner-profile.ts
@@ -5,6 +5,7 @@ import {
import { CommissionType, ProgramEnrollmentStatus } from "@prisma/client";
import { z } from "zod";
import { analyticsQuerySchema, eventsQuerySchema } from "./analytics";
+import { BountySchema, BountySubmissionSchema } from "./bounties";
import {
CommissionSchema,
getCommissionsCountQuerySchema,
@@ -13,6 +14,7 @@ import {
import { customerActivityResponseSchema } from "./customer-activity";
import { CustomerEnrichedSchema } from "./customers";
import { LinkSchema } from "./links";
+import { workflowConditionSchema } from "./workflows";
export const PartnerEarningsSchema = CommissionSchema.omit({
userId: true,
@@ -131,3 +133,18 @@ export const partnerNotificationTypes = z.enum([
"commissionCreated",
"applicationApproved",
]);
+
+export const PartnerBountySchema = BountySchema.omit({
+ groups: true,
+ submissionsCount: true,
+}).extend({
+ submissions: z.array(BountySubmissionSchema).nullable(),
+ performanceCondition: workflowConditionSchema.nullable().default(null),
+ partner: z.object({
+ totalClicks: z.number(),
+ totalLeads: z.number(),
+ totalConversions: z.number(),
+ totalSales: z.number(),
+ totalSaleAmount: z.number(),
+ }),
+});
diff --git a/apps/web/lib/zod/schemas/workflows.ts b/apps/web/lib/zod/schemas/workflows.ts
index 02e12e1d51..1bcd492146 100644
--- a/apps/web/lib/zod/schemas/workflows.ts
+++ b/apps/web/lib/zod/schemas/workflows.ts
@@ -10,7 +10,7 @@ export const WORKFLOW_ATTRIBUTES = [
"totalLeads",
"totalConversions",
"totalSaleAmount",
- "totalCommission",
+ "totalCommissions",
] as const;
export const WORKFLOW_ATTRIBUTE_LABELS: Record<
@@ -20,7 +20,7 @@ export const WORKFLOW_ATTRIBUTE_LABELS: Record<
totalLeads: "Leads",
totalConversions: "Conversions",
totalSaleAmount: "Revenue",
- totalCommission: "Commissions",
+ totalCommissions: "Commissions",
} as const;
export const WORKFLOW_ATTRIBUTE_TRIGGER_MAP: Record<
@@ -30,7 +30,7 @@ export const WORKFLOW_ATTRIBUTE_TRIGGER_MAP: Record<
totalLeads: WorkflowTrigger.leadRecorded,
totalConversions: WorkflowTrigger.saleRecorded,
totalSaleAmount: WorkflowTrigger.saleRecorded,
- totalCommission: WorkflowTrigger.commissionEarned,
+ totalCommissions: WorkflowTrigger.commissionEarned,
} as const;
export const WORKFLOW_COMPARISON_OPERATORS = ["gte"] as const;
diff --git a/apps/web/ui/partners/bounties/bounty-logic.tsx b/apps/web/ui/partners/bounties/bounty-logic.tsx
index 32c0fec87a..3e81f6cc50 100644
--- a/apps/web/ui/partners/bounties/bounty-logic.tsx
+++ b/apps/web/ui/partners/bounties/bounty-logic.tsx
@@ -17,7 +17,7 @@ const WORKFLOW_ATTRIBUTE_LABELS: Record<WorkflowConditionAttribute, string> = {
totalLeads: "total leads",
totalConversions: "total conversions",
totalSaleAmount: "total revenue",
- totalCommission: "total commissions",
+ totalCommissions: "total commissions",
} as const;
export const generateBountyName = ({
diff --git a/apps/web/ui/partners/bounties/bounty-performance.tsx b/apps/web/ui/partners/bounties/bounty-performance.tsx
index 568280724a..76a314f68c 100644
--- a/apps/web/ui/partners/bounties/bounty-performance.tsx
+++ b/apps/web/ui/partners/bounties/bounty-performance.tsx
@@ -1,26 +1,16 @@
import { isCurrencyAttribute } from "@/lib/api/workflows/utils";
-import { BountyWithPartnerDataProps } from "@/lib/types";
+import { PartnerBountyProps } from "@/lib/types";
import { WORKFLOW_ATTRIBUTE_LABELS } from "@/lib/zod/schemas/workflows";
import { currencyFormatter, nFormatter } from "@dub/utils";
-export function BountyPerformance({
- bounty,
-}: {
- bounty: BountyWithPartnerDataProps;
-}) {
+export function BountyPerformance({ bounty }: { bounty: PartnerBountyProps }) {
const performanceCondition = bounty.performanceCondition;
if (!performanceCondition) return null;
const attribute = performanceCondition.attribute;
const target = performanceCondition.value;
- let value: number | undefined = undefined;
-
- if (attribute === "totalLeads") value = bounty.partner.leads;
- else if (attribute === "totalConversions") value = bounty.partner.conversions;
- else if (attribute === "totalSaleAmount") value = bounty.partner.saleAmount;
- else if (attribute === "totalCommission")
- value = bounty.partner.totalCommissions;
+ const value = bounty.partner[attribute];
const formattedValue =
value === undefined
diff --git a/apps/web/ui/partners/bounties/claim-bounty-modal.tsx b/apps/web/ui/partners/bounties/claim-bounty-modal.tsx
index f151d10b8a..bbc544f786 100644
--- a/apps/web/ui/partners/bounties/claim-bounty-modal.tsx
+++ b/apps/web/ui/partners/bounties/claim-bounty-modal.tsx
@@ -2,7 +2,7 @@ import { createBountySubmissionAction } from "@/lib/actions/partners/create-boun
import { uploadBountySubmissionFileAction } from "@/lib/actions/partners/upload-bounty-submission-file";
import { mutatePrefix } from "@/lib/swr/mutate";
import useProgramEnrollment from "@/lib/swr/use-program-enrollment";
-import { BountySubmissionProps, BountyWithPartnerDataProps } from "@/lib/types";
+import { BountySubmissionProps, PartnerBountyProps } from "@/lib/types";
import {
MAX_SUBMISSION_FILES,
MAX_SUBMISSION_URLS,
@@ -34,7 +34,7 @@ import { BountyThumbnailImage } from "./bounty-thumbnail-image";
type ClaimBountyModalProps = {
setShowModal: Dispatch<SetStateAction<boolean>>;
- bounty: BountyWithPartnerDataProps;
+ bounty: PartnerBountyProps;
submission?: BountySubmissionProps["submission"];
};