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.

Add rewards/discounts/bounties

Tim Wilson871d267bd8d1
diff --git a/apps/web/lib/actions/partners/create-program.ts b/apps/web/lib/actions/partners/create-program.ts
index 22cbaabd1d..9f8c94e4a7 100644
--- a/apps/web/lib/actions/partners/create-program.ts
+++ b/apps/web/lib/actions/partners/create-program.ts
@@ -2,6 +2,7 @@ import { recordAuditLog } from "@/lib/api/audit-logs/record-audit-log";
import { createId } from "@/lib/api/create-id";
import { getDomainOrThrow } from "@/lib/api/domains/get-domain-or-throw";
import { createAndEnrollPartner } from "@/lib/api/partners/create-and-enroll-partner";
+import { getPartnerInviteRewardsAndBounties } from "@/lib/api/partners/get-partner-invite-rewards-and-bounties";
import { generateRandomString } from "@/lib/api/utils/generate-random-string";
import { getPlanCapabilities } from "@/lib/plan-capabilities";
import { isStored, storage } from "@/lib/storage";
@@ -261,18 +262,24 @@ async function invitePartner({
});
waitUntil(
- sendEmail({
- subject: `${program.name} invited you to join Dub Partners`,
- variant: "notifications",
- to: partner.email,
- react: ProgramInvite({
- email: partner.email,
- program: {
- name: program.name,
- slug: program.slug,
- logo: program.logo,
- },
- }),
- }),
+ (async () => {
+ await sendEmail({
+ subject: `${program.name} invited you to join Dub Partners`,
+ variant: "notifications",
+ to: partner.email,
+ react: ProgramInvite({
+ email: partner.email,
+ program: {
+ name: program.name,
+ slug: program.slug,
+ logo: program.logo,
+ },
+ ...(await getPartnerInviteRewardsAndBounties({
+ programId: program.id,
+ groupId: program.defaultGroupId,
+ })),
+ }),
+ });
+ })(),
);
}
diff --git a/apps/web/lib/actions/partners/invite-partner-from-network.ts b/apps/web/lib/actions/partners/invite-partner-from-network.ts
index ab67e71ab0..d7efb168d2 100644
--- a/apps/web/lib/actions/partners/invite-partner-from-network.ts
+++ b/apps/web/lib/actions/partners/invite-partner-from-network.ts
@@ -4,6 +4,7 @@ import { recordAuditLog } from "@/lib/api/audit-logs/record-audit-log";
import { createId } from "@/lib/api/create-id";
import { createAndEnrollPartner } from "@/lib/api/partners/create-and-enroll-partner";
import { getNetworkInvitesUsage } from "@/lib/api/partners/get-network-invites-usage";
+import { getPartnerInviteRewardsAndBounties } from "@/lib/api/partners/get-partner-invite-rewards-and-bounties";
import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
import { invitePartnerFromNetworkSchema } from "@/lib/zod/schemas/partner-network";
import { sendEmail } from "@dub/email";
@@ -85,20 +86,27 @@ export const invitePartnerFromNetworkAction = authActionClient
waitUntil(
Promise.allSettled([
- sendEmail({
- subject: `${program.name} invited you to join on Dub Partners`,
- variant: "notifications",
- to: partner.email,
- react: ProgramNetworkInvite({
- email: partner.email,
- name: partner.name,
- program: {
- name: program.name,
- slug: program.slug,
- logo: program.logo,
- },
- }),
- }),
+ (async () => {
+ if (!partner.email) return;
+ await sendEmail({
+ subject: `${program.name} invited you to join on Dub Partners`,
+ variant: "notifications",
+ to: partner.email,
+ react: ProgramNetworkInvite({
+ email: partner.email,
+ name: partner.name,
+ program: {
+ name: program.name,
+ slug: program.slug,
+ logo: program.logo,
+ },
+ ...(await getPartnerInviteRewardsAndBounties({
+ programId,
+ groupId: enrolledPartner.groupId || program.defaultGroupId,
+ })),
+ }),
+ });
+ })(),
recordAuditLog({
workspaceId: workspace.id,
diff --git a/apps/web/lib/actions/partners/invite-partner.ts b/apps/web/lib/actions/partners/invite-partner.ts
index e9e34999ac..4d3b28e52f 100644
--- a/apps/web/lib/actions/partners/invite-partner.ts
+++ b/apps/web/lib/actions/partners/invite-partner.ts
@@ -2,6 +2,7 @@
import { recordAuditLog } from "@/lib/api/audit-logs/record-audit-log";
import { createAndEnrollPartner } from "@/lib/api/partners/create-and-enroll-partner";
+import { getPartnerInviteRewardsAndBounties } from "@/lib/api/partners/get-partner-invite-rewards-and-bounties";
import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
import { invitePartnerSchema } from "@/lib/zod/schemas/partners";
import { sendEmail } from "@dub/email";
@@ -70,19 +71,26 @@ export const invitePartnerAction = authActionClient
waitUntil(
Promise.allSettled([
- sendEmail({
- subject: `${program.name} invited you to join Dub Partners`,
- variant: "notifications",
- to: email,
- react: ProgramInvite({
- email,
- program: {
- name: program.name,
- slug: program.slug,
- logo: program.logo,
- },
- }),
- }),
+ (async () => {
+ await sendEmail({
+ subject: `${program.name} invited you to join Dub Partners`,
+ variant: "notifications",
+ to: email,
+ react: ProgramInvite({
+ email,
+ name: enrolledPartner.name,
+ program: {
+ name: program.name,
+ slug: program.slug,
+ logo: program.logo,
+ },
+ ...(await getPartnerInviteRewardsAndBounties({
+ programId,
+ groupId: enrolledPartner.groupId || program.defaultGroupId,
+ })),
+ }),
+ });
+ })(),
recordAuditLog({
workspaceId: workspace.id,
diff --git a/apps/web/lib/actions/partners/resend-program-invite.ts b/apps/web/lib/actions/partners/resend-program-invite.ts
index b5755e9606..8c628e1f5d 100644
--- a/apps/web/lib/actions/partners/resend-program-invite.ts
+++ b/apps/web/lib/actions/partners/resend-program-invite.ts
@@ -1,6 +1,7 @@
"use server";
import { recordAuditLog } from "@/lib/api/audit-logs/record-audit-log";
+import { getPartnerInviteRewardsAndBounties } from "@/lib/api/partners/get-partner-invite-rewards-and-bounties";
import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
import { sendEmail } from "@dub/email";
import ProgramInvite from "@dub/email/templates/program-invite";
@@ -50,19 +51,26 @@ export const resendProgramInviteAction = authActionClient
}
await Promise.allSettled([
- sendEmail({
- subject: `${program.name} invited you to join Dub Partners`,
- variant: "notifications",
- to: partner.email!,
- react: ProgramInvite({
- email: partner.email!,
- program: {
- name: program.name,
- slug: program.slug,
- logo: program.logo,
- },
- }),
- }),
+ (async () => {
+ await sendEmail({
+ subject: `${program.name} invited you to join Dub Partners`,
+ variant: "notifications",
+ to: partner.email!,
+ react: ProgramInvite({
+ email: partner.email!,
+ name: partner.name,
+ program: {
+ name: program.name,
+ slug: program.slug,
+ logo: program.logo,
+ },
+ ...(await getPartnerInviteRewardsAndBounties({
+ programId,
+ groupId: programEnrollment.groupId || program.defaultGroupId,
+ })),
+ }),
+ });
+ })(),
prisma.programEnrollment.update({
where: {
diff --git a/apps/web/lib/api/partners/get-partner-invite-rewards-and-bounties.ts b/apps/web/lib/api/partners/get-partner-invite-rewards-and-bounties.ts
new file mode 100644
index 0000000000..a23dd598df
--- /dev/null
+++ b/apps/web/lib/api/partners/get-partner-invite-rewards-and-bounties.ts
@@ -0,0 +1,99 @@
+import { sortRewardsByEventOrder } from "@/lib/partners/sort-rewards-by-event-order";
+import { formatDiscountDescription } from "@/ui/partners/format-discount-description";
+import { formatRewardDescription } from "@/ui/partners/format-reward-description";
+import { prisma } from "@dub/prisma";
+import { BountyType, EventType } from "@dub/prisma/client";
+import { getGroupOrThrow } from "../groups/get-group-or-throw";
+
+const REWARD_ICONS: Record<EventType, string> = {
+ click: "https://assets.dub.co/email-assets/icons/cursor-rays.png",
+ lead: "https://assets.dub.co/email-assets/icons/user-plus.png",
+ sale: "https://assets.dub.co/email-assets/icons/invoice-dollar.png",
+};
+
+const BOUNTY_ICONS: Record<BountyType, string> = {
+ submission: "https://assets.dub.co/email-assets/icons/heart.png",
+ performance: "https://assets.dub.co/email-assets/icons/trophy.png",
+};
+
+export async function getPartnerInviteRewardsAndBounties({
+ programId,
+ groupId,
+}: {
+ programId: string;
+ groupId: string;
+}) {
+ const now = new Date();
+
+ const [group, bounties] = await Promise.all([
+ getGroupOrThrow({
+ programId,
+ groupId,
+ includeExpandedFields: true,
+ }),
+ prisma.bounty.findMany({
+ where: {
+ programId,
+ startsAt: {
+ lte: now,
+ },
+ // Check if the bounty is active
+ OR: [
+ {
+ endsAt: null,
+ },
+ {
+ endsAt: {
+ gt: now,
+ },
+ },
+ ],
+ // If bounty has no groups, it's available to all partners
+ // If bounty has groups, only partners in those groups can see it
+ AND: [
+ {
+ OR: [
+ {
+ groups: {
+ none: {},
+ },
+ },
+ {
+ groups: {
+ some: {
+ groupId,
+ },
+ },
+ },
+ ],
+ },
+ ],
+ },
+ }),
+ ]);
+
+ return {
+ rewards: [
+ ...sortRewardsByEventOrder([
+ ...(group.clickReward ? [group.clickReward] : []),
+ ...(group.leadReward ? [group.leadReward] : []),
+ ...(group.saleReward ? [group.saleReward] : []),
+ ]).map((reward) => ({
+ label: formatRewardDescription({ reward }),
+ icon: REWARD_ICONS[reward.event],
+ })),
+ ...(group.discount
+ ? [
+ {
+ label: formatDiscountDescription({ discount: group.discount }),
+ icon: "https://assets.dub.co/email-assets/icons/gift.png",
+ },
+ ]
+ : []),
+ ],
+ bounties: bounties.map((bounty) => ({
+ icon: BOUNTY_ICONS[bounty.type],
+ label: bounty.name,
+ })),
+ };
+}
diff --git a/packages/email/src/templates/program-invite.tsx b/packages/email/src/templates/program-invite.tsx
index 67f742e571..3822568f54 100644
--- a/packages/email/src/templates/program-invite.tsx
+++ b/packages/email/src/templates/program-invite.tsx
@@ -1,6 +1,7 @@
import { DUB_WORDMARK } from "@dub/utils";
import {
Body,
+ Column,
Container,
Head,
Heading,
@@ -8,6 +9,7 @@ import {
Img,
Link,
Preview,
+ Row,
Section,
Tailwind,
Text,
@@ -22,6 +24,26 @@ export default function PartnerInvite({
slug: "acme",
logo: DUB_WORDMARK,
},
+ rewards = [
+ {
+ icon: "https://assets.dub.co/email-assets/icons/invoice-dollar.png",
+ label: "Earn up to 65% per sale for 1 year",
+ },
+ {
+ icon: "https://assets.dub.co/email-assets/icons/gift.png",
+ label: "New users get 20% off for 3 months",
+ },
+ ],
+ bounties = [
+ {
+ icon: "https://assets.dub.co/email-assets/icons/heart.png",
+ label: "Create a YouTube video about Acme",
+ },
+ {
+ icon: "https://assets.dub.co/email-assets/icons/trophy.png",
+ label: "Earn $100 after generating $1,000 in revenue",
+ },
+ ],
}: {
email: string;
name?: string;
@@ -30,6 +52,8 @@ export default function PartnerInvite({
slug: string;
logo: string | null;
};
+ rewards: { icon: string; label: string }[] | null;
+ bounties: { icon: string; label: string }[] | null;
}) {
return (
<Html>
@@ -68,7 +92,7 @@ export default function PartnerInvite({
like you!
</Text>
- <Section className="mb-12 mt-8">
+ <Section className="my-8">
<Link
className="rounded-lg bg-neutral-900 px-4 py-3 text-[12px] font-semibold text-white no-underline"
href={`https://partners.dub.co/${program.slug}/register?email=${encodeURIComponent(email)}&next=/programs/${program.slug}`}
@@ -76,6 +100,58 @@ export default function PartnerInvite({
Accept Invite
</Link>
</Section>
+
+ {(rewards?.length || bounties?.length) && (
+ <>
+ <Text className="text-sm leading-6 text-neutral-600">
+ If you accept the invite, you're immediately eligible for the
+ following:
+ </Text>
+ <Section className="rounded-xl border border-solid border-neutral-200 bg-neutral-50 px-5 py-4">
+ {rewards?.length && (
+ <>
+ <Text className="my-0 text-base font-semibold text-black">
+ Rewards
+ </Text>
+ {rewards.map((reward) => (
+ <Row key={reward.label} className="mb-0 mt-2">
+ <Column className="align-center">
+ <Img src={reward.icon} height="16" alt="" />
+ </Column>
+ <Column className="w-full pl-2">
+ <Text className="my-0 text-sm font-medium text-neutral-600">
+ {reward.label}
+ </Text>
+ </Column>
+ </Row>
+ ))}
+ </>
+ )}
+ {bounties?.length && (
+ <>
+ <Text
+ className={`mb-0 text-base font-semibold text-black ${rewards?.length ? "mt-5" : "mt-0"}`}
+ >
+ Bounties
+ </Text>
+ {bounties.map((bounty) => (
+ <Row key={bounty.label} className="mb-0 mt-2">
+ <Column className="align-center">
+ <Img src={bounty.icon} height="16" alt="" />
+ </Column>
+ <Column className="w-full pl-2">
+ <Text className="my-0 text-sm font-medium text-neutral-600">
+ {bounty.label}
+ </Text>
+ </Column>
+ </Row>
+ ))}
+ </>
+ )}
+ </Section>
+ </>
+ )}
+
<Footer email={email} />
</Container>
</Body>
diff --git a/packages/email/src/templates/program-network-invite.tsx b/packages/email/src/templates/program-network-invite.tsx
index 78596191b4..802796f597 100644
--- a/packages/email/src/templates/program-network-invite.tsx
+++ b/packages/email/src/templates/program-network-invite.tsx
@@ -1,6 +1,7 @@
import { DUB_WORDMARK } from "@dub/utils";
import {
Body,
+ Column,
Container,
Head,
Heading,
@@ -8,6 +9,7 @@ import {
Img,
Link,
Preview,
+ Row,
Section,
Tailwind,
Text,
@@ -22,6 +24,26 @@ export default function ProgramNetworkInvite({
slug: "acme",
logo: DUB_WORDMARK,
},
+ rewards = [
+ {
+ icon: "https://assets.dub.co/email-assets/icons/invoice-dollar.png",
+ label: "Earn up to 65% per sale for 1 year",
+ },
+ {
+ icon: "https://assets.dub.co/email-assets/icons/gift.png",
+ label: "New users get 20% off for 3 months",
+ },
+ ],
+ bounties = [
+ {
+ icon: "https://assets.dub.co/email-assets/icons/heart.png",
+ label: "Create a YouTube video about Acme",
+ },
+ {
+ icon: "https://assets.dub.co/email-assets/icons/trophy.png",
+ label: "Earn $100 after generating $1,000 in revenue",
+ },
+ ],
}: {
email: string;
name?: string;
@@ -30,6 +52,8 @@ export default function ProgramNetworkInvite({
slug: string;
logo: string | null;
};
+ rewards: { icon: string; label: string }[] | null;
+ bounties: { icon: string; label: string }[] | null;
}) {
return (
<Html>
@@ -46,7 +70,7 @@ export default function ProgramNetworkInvite({
/>
</Section>
- <Heading className="bt-5 mx-0 mt-10 p-0 text-lg font-medium text-black">
+ <Heading className="mx-0 mt-10 p-0 text-lg font-medium text-black">
You're getting noticed!
</Heading>
@@ -56,7 +80,7 @@ export default function ProgramNetworkInvite({
join their partner program.
</Text>
- <Section className="mb-12 mt-8">
+ <Section className="my-8">
<Link
className="rounded-lg bg-neutral-900 px-4 py-3 text-[12px] font-semibold text-white no-underline"
href={`https://partners.dub.co/${program.slug}/register?email=${encodeURIComponent(email)}&next=/programs/${program.slug}`}
@@ -64,6 +88,57 @@ export default function ProgramNetworkInvite({
Accept Invite
</Link>
</Section>
+
+ {(rewards?.length || bounties?.length) && (
+ <>
+ <Text className="text-sm leading-6 text-neutral-600">
+ If you accept the invite, you're immediately eligible for the
+ following:
+ </Text>
+ <Section className="rounded-xl border border-solid border-neutral-200 bg-neutral-50 px-5 py-4">
+ {rewards?.length && (
+ <>
+ <Text className="my-0 text-base font-semibold text-black">
+ Rewards
+ </Text>
+ {rewards.map((reward) => (
+ <Row key={reward.label} className="mb-0 mt-2">
+ <Column className="align-center">
+ <Img src={reward.icon} height="16" alt="" />
+ </Column>
+ <Column className="w-full pl-2">
+ <Text className="my-0 text-sm font-medium text-neutral-600">
+ {reward.label}
+ </Text>
+ </Column>
+ </Row>
+ ))}
+ </>
+ )}
+ {bounties?.length && (
+ <>
+ <Text
+ className={`mb-0 text-base font-semibold text-black ${rewards?.length ? "mt-5" : "mt-0"}`}
+ >
+ Bounties
+ </Text>
+ {bounties.map((bounty) => (
+ <Row key={bounty.label} className="mb-0 mt-2">
+ <Column className="align-center">
+ <Img src={bounty.icon} height="16" alt="" />
+ </Column>
+ <Column className="w-full pl-2">
+ <Text className="my-0 text-sm font-medium text-neutral-600">
+ {bounty.label}
+ </Text>
+ </Column>
+ </Row>
+ ))}
+ </>
+ )}
+ </Section>
+ </>
+ )}
<Footer email={email} />
</Container>
</Body>