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.

fix isFirstConversion flag in createManualCommission

Steven Tey098d92f09b8a
diff --git a/apps/web/lib/actions/partners/create-manual-commission.ts b/apps/web/lib/actions/partners/create-manual-commission.ts
index 543a2be775..15b02dc773 100644
--- a/apps/web/lib/actions/partners/create-manual-commission.ts
+++ b/apps/web/lib/actions/partners/create-manual-commission.ts
@@ -453,10 +453,12 @@ export const createManualCommissionAction = authActionClient
finalCommissionsToTransferEventIds,
);
- const firstConversionFlag = isFirstConversion({
- customer,
- linkId,
- });
+ const firstConversionFlag =
+ commissionType === "sale" &&
+ isFirstConversion({
+ customer,
+ linkId,
+ });
const updatedRes = await Promise.all([
// update link stats
@@ -465,14 +467,18 @@ export const createManualCommissionAction = authActionClient
id: link.id,
},
data: {
+ // we'll always create click + lead events, so need to increment the stats
+ clicks: {
+ increment: 1,
+ },
+ leads: {
+ increment: 1,
+ },
+ lastLeadAt: updateLinkStatsForImporter({
+ currentTimestamp: link.lastLeadAt,
+ newTimestamp: leadEventTimestamp || new Date(),
+ }),
...(firstConversionFlag && {
- leads: {
- increment: 1,
- },
- lastLeadAt: updateLinkStatsForImporter({
- currentTimestamp: link.lastLeadAt,
- newTimestamp: leadEventTimestamp || new Date(),
- }),
conversions: {
increment: 1,
},
@@ -481,12 +487,14 @@ export const createManualCommissionAction = authActionClient
newTimestamp: saleEventTimestamp || new Date(),
}),
}),
- sales: {
- increment: saleAmount ? 1 : totalSales,
- },
- saleAmount: {
- increment: saleAmount ?? totalSaleAmount,
- },
+ ...(commissionType === "sale" && {
+ sales: {
+ increment: saleAmount ? 1 : totalSales,
+ },
+ saleAmount: {
+ increment: saleAmount ?? totalSaleAmount,
+ },
+ }),
},
}),