The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Link bounty submissions to all their commissions via bountySubmissionId filter
Kiran Keff6a3f24258
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-details-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-details-sheet.tsxindex d220105ef1..d86997517a 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-details-sheet.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-details-sheet.tsx@@ -43,6 +43,7 @@ import {pluralize,timeAgo,} from "@dub/utils";+import { CommissionStatus } from "@prisma/client";import Linkify from "linkify-react";import Link from "next/link";import {@@ -54,6 +55,13 @@ import {} from "react";import { toast } from "sonner";+const PAYABLE_COMMISSION_STATUSES: CommissionStatus[] = [+ "pending",+ "processed",+ "paid",+ "hold",+];+type BountySubmissionDetailsSheetProps = {submission: BountySubmissionProps;onNext?: () => void;@@ -201,6 +209,17 @@ function BountySubmissionDetailsSheetContent({: 100;const socialMetricComplete = socialMetricPercent >= 100;+ const viewCommissionsLink =+ submission.commissions.length > 0 ? (+ <Link+ href={`/${workspaceSlug}/program/commissions?bountySubmissionId=${submission.id}&interval=all`}+ target="_blank"+ className="w-full"+ >+ <Button variant="secondary" text="View commissions" />+ </Link>+ ) : null;+return (<div className="flex h-full flex-col"><div className="sticky top-0 z-10 border-b border-neutral-200 bg-white">@@ -337,7 +356,10 @@ function BountySubmissionDetailsSheetContent({if (submission.commissions.length > 0) {return currencyFormatter(submission.commissions.reduce(- (total, { earnings }) => total + earnings,+ (total, { earnings, status }) =>+ PAYABLE_COMMISSION_STATUSES.includes(status)+ ? total + earnings+ : total,0,),);@@ -554,17 +576,11 @@ function BountySubmissionDetailsSheetContent({<div className="sticky bottom-0 z-10 border-t border-neutral-200 bg-white"><div className="flex items-center justify-between gap-2 p-5">- {submission.status === "approved" &&- submission.commissions.length > 0 ? (- <Link- href={`/${workspaceSlug}/program/commissions/${submission.commissions[0].id}`}- target="_blank"- className="w-full"- >- <Button variant="secondary" text="View commission" />- </Link>+ {submission.status === "approved" && viewCommissionsLink ? (+ viewCommissionsLink) : (<div className="flex w-full flex-col gap-4">+ {viewCommissionsLink}{!bounty?.rewardAmount && (<div><label className="text-sm font-medium text-neutral-800">diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commissions-table.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commissions-table.tsxindex 6e757931cb..8ab438a947 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commissions-table.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commissions-table.tsx@@ -1,11 +1,11 @@"use client";+import { formatCommissionDescriptionTooltip } from "@/lib/commissions/format-commission-description-tooltip";import useCommissionsCount from "@/lib/swr/use-commissions-count";import useGroups from "@/lib/swr/use-groups";import useProgram from "@/lib/swr/use-program";import useWorkspace from "@/lib/swr/use-workspace";import { CommissionResponse } from "@/lib/types";-import { formatCommissionDescriptionTooltip } from "@/lib/commissions/format-commission-description-tooltip";import { CustomerRowItem } from "@/ui/customers/customer-row-item";import { useBulkEditCommissionsModal } from "@/ui/partners/bulk-edit-commissions-modal";import { CommissionRowMenu } from "@/ui/partners/commission-row-menu";@@ -32,7 +32,7 @@ import {useRouterStuff,useTable,} from "@dub/ui";-import { MoneyBill2, Pen2 } from "@dub/ui/icons";+import { MoneyBill2, Pen2, Trophy } from "@dub/ui/icons";import {cn,currencyFormatter,@@ -492,6 +492,12 @@ function CommissionsFilters() {label: "Payout",options: [],},+ {+ key: "bountySubmissionId",+ icon: Trophy,+ label: "Bounty submission",+ options: [],+ },]}activeFilters={activeFilters}onSelect={onSelect}diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/use-commission-filters.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/use-commission-filters.tsxindex df7aaa6ebc..8f9e6abcd9 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/use-commission-filters.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/use-commission-filters.tsx@@ -173,6 +173,7 @@ export function useCommissionFilters() {"status","type","payoutId",+ "bountySubmissionId","groupId","partnerTagId",] as const;@@ -190,6 +191,7 @@ export function useCommissionFilters() {searchParamsObj.status,searchParamsObj.type,searchParamsObj.payoutId,+ searchParamsObj.bountySubmissionId,searchParamsObj.groupId,searchParamsObj.partnerTagId,]);@@ -251,6 +253,7 @@ export function useCommissionFilters() {"partnerId","customerId","payoutId",+ "bountySubmissionId","groupId","partnerTagId","type",diff --git a/apps/web/lib/api/commissions/get-commissions-count.ts b/apps/web/lib/api/commissions/get-commissions-count.tsindex 65a28ed824..017c263f12 100644--- a/apps/web/lib/api/commissions/get-commissions-count.ts+++ b/apps/web/lib/api/commissions/get-commissions-count.ts@@ -23,6 +23,7 @@ export async function getCommissionsCount(filters: CommissionsCountFilters) {type,partnerId,payoutId,+ bountySubmissionId,customerId,groupId,partnerTagId,@@ -55,7 +56,7 @@ export async function getCommissionsCount(filters: CommissionsCountFilters) {const statusFilter = status? status- : type || customerId || payoutId || partnerId+ : type || customerId || payoutId || bountySubmissionId || partnerId? undefined: {notIn: [@@ -109,6 +110,7 @@ export async function getCommissionsCount(filters: CommissionsCountFilters) {: { in: typeFilter.values as CommissionType[] },}),payoutId,+ bountySubmissionId,...(customerFilter && {customerId:customerFilter.sqlOperator === "NOT IN"diff --git a/apps/web/lib/api/commissions/get-commissions.ts b/apps/web/lib/api/commissions/get-commissions.tsindex 874b6ad53d..f142b16da9 100644--- a/apps/web/lib/api/commissions/get-commissions.ts+++ b/apps/web/lib/api/commissions/get-commissions.ts@@ -41,6 +41,7 @@ export async function getCommissions(filters: CommissionsFilters) {type,customerId,payoutId,+ bountySubmissionId,groupId,partnerTagId,fraudEventGroupId,@@ -139,7 +140,7 @@ export async function getCommissions(filters: CommissionsFilters) {const statusFilter = status? status- : type || customerId || payoutId || partnerId+ : type || customerId || payoutId || bountySubmissionId || partnerId? undefined: {notIn: [@@ -185,6 +186,7 @@ export async function getCommissions(filters: CommissionsFilters) {}),customerId,payoutId,+ bountySubmissionId,...(eventIds && {eventId: {in: eventIds,diff --git a/apps/web/lib/zod/schemas/commissions.ts b/apps/web/lib/zod/schemas/commissions.tsindex 252350ab9b..e315405a84 100644--- a/apps/web/lib/zod/schemas/commissions.ts+++ b/apps/web/lib/zod/schemas/commissions.ts@@ -158,6 +158,12 @@ export const getCommissionsQuerySchema = z.string().optional().describe("Filter the list of commissions by the associated payout."),+ bountySubmissionId: z+ .string()+ .optional()+ .describe(+ "Filter the list of commissions by the associated bounty submission.",+ ),partnerId: z.string().optional()diff --git a/apps/web/lib/zod/schemas/partner-profile.ts b/apps/web/lib/zod/schemas/partner-profile.tsindex 8b6c8aa36e..2f12c84533 100644--- a/apps/web/lib/zod/schemas/partner-profile.ts+++ b/apps/web/lib/zod/schemas/partner-profile.ts@@ -53,6 +53,7 @@ export const PartnerEarningsSchema = CommissionSchema.omit({export const getPartnerEarningsQuerySchema = getCommissionsQuerySchema.omit({partnerId: true,+ bountySubmissionId: true,sortBy: true,query: true,})@@ -70,6 +71,7 @@ export const getPartnerEarningsQuerySchema = getCommissionsQuerySchemaexport const getPartnerEarningsCountQuerySchema = getCommissionsCountQuerySchema.omit({partnerId: true,+ bountySubmissionId: true,query: true,}).extend({diff --git a/apps/web/scripts/migrations/backfill-bounty-approved-threshold.ts b/apps/web/scripts/migrations/backfill-bounty-approved-threshold.tsindex 6d8f3d7258..83d954627d 100644--- a/apps/web/scripts/migrations/backfill-bounty-approved-threshold.ts+++ b/apps/web/scripts/migrations/backfill-bounty-approved-threshold.ts@@ -50,6 +50,11 @@ async function main() {socialMetricCount: {not: null,},+ ...(cursor && {+ id: {+ gt: cursor,+ },+ }),},select: {id: true,@@ -64,12 +69,6 @@ async function main() {id: "asc",},take: BATCH_SIZE,- ...(cursor && {- skip: 1,- cursor: {- id: cursor,- },- }),});if (submissions.length === 0) {