The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add referral signup email notification
Steven Tey378da2d0b29e
diff --git a/apps/web/app/api/dub/webhook/lead-created.ts b/apps/web/app/api/dub/webhook/lead-created.tsindex 91ff730d19..84ae1db523 100644--- a/apps/web/app/api/dub/webhook/lead-created.ts+++ b/apps/web/app/api/dub/webhook/lead-created.ts@@ -1,4 +1,6 @@import { prisma } from "@/lib/prisma";+import { sendEmail } from "emails";+import NewReferralSignup from "emails/new-referral-signup";export async function leadCreated(data: any) {const referralLink = data.link;@@ -11,32 +13,60 @@ export async function leadCreated(data: any) {return `Referral limit reached for ${referralLink.id}. Skipping...`;}- // Update the referrer's workspace- const workspace = await prisma.project.update({+ const workspace = await prisma.project.findUnique({where: {referralLinkId: referralLink.id,},- data: {- referredSignups: {- increment: 1,- },- usageLimit: {- increment: 500,- },- },include: {users: {select: {user: true,},+ where: {+ role: "owner",+ },},},});- if (data.link.leads === 10) {- // TODO: Send merch link for cap- // const userEmails = workspace.users.map((user) => user.user.email);+ if (!workspace) {+ return "Workspace not found";}+ const workspaceOwners = workspace.users.map(({ user }) => user);++ await Promise.all([+ // Update the referrer's workspace usage+ prisma.project.update({+ where: {+ id: workspace.id,+ },++ data: {+ referredSignups: {+ increment: 1,+ },+ usageLimit: {+ increment: 500,+ },+ },+ }),+ workspaceOwners.map(+ (owner) =>+ owner.email &&+ sendEmail({+ email: owner.email,+ subject: "Someone signed up for Dub via your referral link!",+ react: NewReferralSignup({+ email: owner.email,+ workspace,+ }),+ }),+ ),+ // TODO: Send merch link for cap+ // data.link.leads === 10 &&+ // sendMerchLink(workspace.id),+ ]);+return `Successfully tracked referral signup for ${workspace.name} (slug: ${workspace.slug})`;}diff --git a/apps/web/emails/api-key-created.tsx b/apps/web/emails/api-key-created.tsxindex 8668eb49b0..76164a0b01 100644--- a/apps/web/emails/api-key-created.tsx+++ b/apps/web/emails/api-key-created.tsx@@ -15,7 +15,7 @@ import {import Footer from "./components/footer";export default function APIKeyCreated({- email = "[email protected]",+ email = "[email protected]",workspace = {name: "Acme, Inc",slug: "acme",diff --git a/apps/web/emails/new-referral-signup.tsx b/apps/web/emails/new-referral-signup.tsxnew file mode 100644index 0000000000..7745c6e370--- /dev/null+++ b/apps/web/emails/new-referral-signup.tsx@@ -0,0 +1,86 @@+import { REFERRAL_CLICKS_QUOTA_BONUS } from "@/lib/referrals/constants";+import { DUB_WORDMARK, getPrettyUrl } from "@dub/utils";+import {+ Body,+ Container,+ Head,+ Heading,+ Html,+ Img,+ Link,+ Preview,+ Section,+ Tailwind,+ Text,+} from "@react-email/components";+import Footer from "./components/footer";++export default function NewReferralSignup({+ email = "[email protected]",+ workspace = {+ name: "Acme, Inc",+ slug: "acme",+ },+}: {+ email: string;+ workspace: {+ name: string;+ slug: string;+ };+}) {+ const referralLink = `https://refer.dub.co/${workspace.slug}`;+ return (+ <Html>+ <Head />+ <Preview>New referral signup</Preview>+ <Tailwind>+ <Body className="mx-auto my-auto bg-white font-sans">+ <Container className="mx-auto my-10 max-w-[500px] rounded border border-solid border-gray-200 px-10 py-5">+ <Section className="mt-8">+ <Img+ src={DUB_WORDMARK}+ height="40"+ alt="Dub.co"+ className="mx-auto my-0"+ />+ </Section>+ <Heading className="mx-0 my-7 p-0 text-center text-xl font-semibold text-black">+ New referral signup+ </Heading>+ <Text className="text-sm leading-6 text-black">+ Congratulations – someone just signed up for Dub using your+ referral link:{" "}+ <a+ href={referralLink}+ className="text-semibold font-medium text-black underline"+ >+ {getPrettyUrl(referralLink)}+ </a>+ </Text>+ <Text className="text-sm leading-6 text-black">+ As a thank you from us for spreading the word about Dub, you've+ earned an additional {REFERRAL_CLICKS_QUOTA_BONUS} clicks quota+ for your{" "}+ <a+ href={`https://app.dub.co/${workspace.slug}`}+ className="text-semibold font-medium text-black underline"+ >+ {workspace.name}+ </a>{" "}+ workspace on Dub.+ </Text>+ <Section className="my-8 text-center">+ <Link+ className="rounded-full bg-black px-6 py-3 text-center text-[12px] font-semibold text-white no-underline"+ href={`https://app.dub.co/${workspace.slug}/settings/referrals`}+ >+ View your referral stats+ </Link>+ </Section>+ <Footer email={email} />+ </Container>+ </Body>+ </Tailwind>+ </Html>+ );+}diff --git a/apps/web/emails/referral-invite.tsx b/apps/web/emails/referral-invite.tsxindex f0beb628be..dcb954ca36 100644--- a/apps/web/emails/referral-invite.tsx+++ b/apps/web/emails/referral-invite.tsx@@ -15,7 +15,7 @@ import {import Footer from "./components/footer";export default function ReferralInvite({- email = "[email protected]",+ email = "[email protected]",appName = "Dub.co",url = "https://dub.co",workspaceUser = "Brendon Urie",diff --git a/apps/web/emails/webhook-added.tsx b/apps/web/emails/webhook-added.tsxindex 691103fbd6..94a81496c6 100644--- a/apps/web/emails/webhook-added.tsx+++ b/apps/web/emails/webhook-added.tsx@@ -15,7 +15,7 @@ import {import Footer from "./components/footer";export default function WebhookAdded({- email = "[email protected]",+ email = "[email protected]",workspace = {name: "Acme, Inc",slug: "acme",diff --git a/apps/web/emails/workspace-invite.tsx b/apps/web/emails/workspace-invite.tsxindex 6c1b8566c1..1647813a60 100644--- a/apps/web/emails/workspace-invite.tsx+++ b/apps/web/emails/workspace-invite.tsx@@ -15,7 +15,7 @@ import {import Footer from "./components/footer";export default function WorkspaceInvite({- email = "[email protected]",+ email = "[email protected]",appName = "Dub.co",url = "http://localhost:8888/api/auth/callback/email?callbackUrl=http%3A%2F%2Fapp.localhost%3A3000%2Flogin&token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&[email protected]",workspaceName = "Acme",