Skip to content

Commit 1fd0fe0

Browse files
authored
Update commission email subject (dubinc#3661)
1 parent 530d873 commit 1fd0fe0

3 files changed

Lines changed: 41 additions & 40 deletions

File tree

apps/web/app/(ee)/api/cron/partner-program-summary/process/route.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,22 +250,22 @@ export const POST = withCron(async ({ rawBody }) => {
250250
return {
251251
partner,
252252
previousMonth: {
253+
earnings: _previousMonthEarnings?._sum.earnings ?? 0,
253254
clicks: _previousMonthAnalytics?.clicks ?? 0,
254255
leads: _previousMonthAnalytics?.leads ?? 0,
255256
sales: _previousMonthAnalytics?.sales ?? 0,
256-
earnings: _previousMonthEarnings?._sum.earnings ?? 0,
257257
},
258258
currentMonth: {
259+
earnings: _currentMonthEarnings?._sum.earnings ?? 0,
259260
clicks: _currentMonthAnalytics?.clicks ?? 0,
260261
leads: _currentMonthAnalytics?.leads ?? 0,
261262
sales: _currentMonthAnalytics?.sales ?? 0,
262-
earnings: _currentMonthEarnings?._sum.earnings ?? 0,
263263
},
264264
lifetime: {
265+
earnings: _lifetimeEarnings?._sum.earnings ?? 0,
265266
clicks: _lifetimeAnalytics?.clicks ?? 0,
266267
leads: _lifetimeAnalytics?.leads ?? 0,
267268
sales: _lifetimeAnalytics?.sales ?? 0,
268-
earnings: _lifetimeEarnings?._sum.earnings ?? 0,
269269
},
270270
};
271271
});
@@ -274,14 +274,14 @@ export const POST = withCron(async ({ rawBody }) => {
274274
summary.map((s) => ({
275275
partner: s.partner.email,
276276
program: program.name,
277+
currentEarnings: s.currentMonth.earnings,
277278
currentClicks: s.currentMonth.clicks,
278279
currentLeads: s.currentMonth.leads,
279280
currentSales: s.currentMonth.sales,
280-
currentEarnings: s.currentMonth.earnings,
281+
lifetimeEarnings: s.lifetime.earnings,
281282
lifetimeClicks: s.lifetime.clicks,
282283
lifetimeLeads: s.lifetime.leads,
283284
lifetimeSales: s.lifetime.sales,
284-
lifetimeEarnings: s.lifetime.earnings,
285285
})),
286286
);
287287

apps/web/lib/api/partners/notify-partner-commission.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
Project,
1414
User,
1515
} from "@dub/prisma/client";
16-
import { chunk } from "@dub/utils";
16+
import { chunk, currencyFormatter } from "@dub/utils";
1717

1818
// Send email to partner and program owners when a commission is created
1919
export async function notifyPartnerCommission({
@@ -136,7 +136,7 @@ export async function notifyPartnerCommission({
136136
...partnerEmailsToNotify.map(
137137
(email) =>
138138
({
139-
subject: "You just made a commission via Dub Partners!",
139+
subject: `You've made a ${currencyFormatter(commission.earnings)} commission from ${program.name}`,
140140
variant: "notifications",
141141
to: email,
142142
replyTo: program.supportEmail || "noreply",
@@ -151,7 +151,7 @@ export async function notifyPartnerCommission({
151151
? workspaceUsers.map(
152152
({ user }) =>
153153
({
154-
subject: `New customer referred by ${partner.name}`,
154+
subject: `New ${currencyFormatter(commission.amount)} sale referred by ${partner.name}`,
155155
variant: "notifications",
156156
to: user.email!,
157157
react: NewSaleAlertProgramOwner({

packages/email/src/templates/partner-program-summary.tsx

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,22 @@ export default function PartnerProgramSummary({
8282
createdAt: new Date(),
8383
},
8484
previousMonth = {
85+
earnings: 12500,
8586
clicks: 200,
86-
leads: 300,
87-
sales: 50,
88-
earnings: 100,
87+
leads: 50,
88+
sales: 25,
8989
},
9090
currentMonth = {
91-
clicks: 100,
92-
leads: 100,
93-
sales: 100,
94-
earnings: 100,
91+
earnings: 12850,
92+
clicks: 210,
93+
leads: 45,
94+
sales: 25,
9595
},
9696
lifetime = {
97-
clicks: 200,
98-
leads: 200,
99-
sales: 200,
100-
earnings: 200,
97+
earnings: 11241050,
98+
clicks: 398585,
99+
leads: 23409,
100+
sales: 1492,
101101
},
102102
reportingPeriod = {
103103
month: "May 2025",
@@ -115,22 +115,22 @@ export default function PartnerProgramSummary({
115115
createdAt: Date;
116116
};
117117
previousMonth: {
118+
earnings: number;
118119
clicks: number;
119120
leads: number;
120121
sales: number;
121-
earnings: number;
122122
};
123123
currentMonth: {
124+
earnings: number;
124125
clicks: number;
125126
leads: number;
126127
sales: number;
127-
earnings: number;
128128
};
129129
lifetime: {
130+
earnings: number;
130131
clicks: number;
131132
leads: number;
132133
sales: number;
133-
earnings: number;
134134
};
135135
reportingPeriod: {
136136
month: string;
@@ -139,6 +139,11 @@ export default function PartnerProgramSummary({
139139
};
140140
}) {
141141
const monthlyStats = [
142+
{
143+
title: "Earnings",
144+
value: currencyFormatter(currentMonth.earnings),
145+
percent: getPercentChange(currentMonth.earnings, previousMonth.earnings),
146+
},
142147
{
143148
title: "Clicks",
144149
value: nFormatter(currentMonth.clicks),
@@ -154,14 +159,13 @@ export default function PartnerProgramSummary({
154159
value: nFormatter(currentMonth.sales),
155160
percent: getPercentChange(currentMonth.sales, previousMonth.sales),
156161
},
157-
{
158-
title: "Earnings",
159-
value: currencyFormatter(currentMonth.earnings),
160-
percent: getPercentChange(currentMonth.earnings, previousMonth.earnings),
161-
},
162162
];
163163

164164
const lifetimeStats = [
165+
{
166+
title: "Earnings",
167+
value: currencyFormatter(lifetime.earnings),
168+
},
165169
{
166170
title: "Clicks",
167171
value: nFormatter(lifetime.clicks),
@@ -174,16 +178,19 @@ export default function PartnerProgramSummary({
174178
title: "Sales",
175179
value: nFormatter(lifetime.sales),
176180
},
177-
{
178-
title: "Earnings",
179-
value: currencyFormatter(lifetime.earnings),
180-
},
181181
];
182182

183+
const previewText = monthlyStats
184+
.map(
185+
({ title, value, percent }) =>
186+
`${title.toUpperCase()} ${value} (${getPercentState(percent).sign}${Math.abs(percent)}%)`,
187+
)
188+
.join(" | ");
189+
183190
return (
184191
<Html>
185192
<Head />
186-
<Preview>{`Your ${reportingPeriod.month} performance report for ${program.name} program.`}</Preview>
193+
<Preview>{previewText}</Preview>
187194
<Tailwind>
188195
<Body className="mx-auto my-auto bg-white font-sans">
189196
<Container className="mx-auto my-10 max-w-[600px] space-y-10 px-3 py-5">
@@ -221,10 +228,7 @@ export default function PartnerProgramSummary({
221228

222229
<Section className="space-y-6 rounded-xl border-t border-solid border-neutral-200 bg-white p-6">
223230
<Section>
224-
<Heading
225-
as="h4"
226-
className="mt-0 text-base font-semibold leading-6 text-neutral-800"
227-
>
231+
<Heading className="mb-4 mt-0 text-base font-semibold leading-6 text-neutral-800">
228232
Stats for {reportingPeriod.month} (vs previous month)
229233
</Heading>
230234

@@ -234,10 +238,7 @@ export default function PartnerProgramSummary({
234238
<Hr className="mx-0 my-8 w-full border border-neutral-200" />
235239

236240
<Section>
237-
<Heading
238-
as="h4"
239-
className="mt-0 text-base font-semibold leading-6 text-neutral-800"
240-
>
241+
<Heading className="mb-4 mt-0 text-base font-semibold leading-6 text-neutral-800">
241242
All-time Performance
242243
</Heading>
243244

0 commit comments

Comments
 (0)