The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add program welcome email functionality
Kiran K8d4826632fef
diff --git a/apps/web/lib/actions/partners/create-program.ts b/apps/web/lib/actions/partners/create-program.tsindex 6ff5b77006..dc6f7202ad 100644--- a/apps/web/lib/actions/partners/create-program.ts+++ b/apps/web/lib/actions/partners/create-program.ts@@ -8,6 +8,7 @@ import { PlanProps } from "@/lib/types";import { programDataSchema } from "@/lib/zod/schemas/program-onboarding";import { sendEmail } from "@dub/email";import { PartnerInvite } from "@dub/email/templates/partner-invite";+import { ProgramWelcome } from "@dub/email/templates/program-welcome";import { prisma } from "@dub/prisma";import { generateRandomString, nanoid, R2_URL } from "@dub/utils";import { Program, Project, User } from "@prisma/client";@@ -23,7 +24,7 @@ export const createProgram = async ({Project,"id" | "slug" | "plan" | "store" | "webhookEnabled" | "invoicePrefix">;- user: Pick<User, "id">;+ user: Pick<User, "id" | "email">;}) => {const store = workspace.store as Record<string, any>;if (!store.programOnboarding) {@@ -161,6 +162,7 @@ export const createProgram = async ({}),): []),+// update the program with the logo and default rewardprisma.program.update({where: {@@ -178,6 +180,20 @@ export const createProgram = async ({uploadedLogo &&isStored(uploadedLogo) &&storage.delete(uploadedLogo.replace(`${R2_URL}/`, "")),++ // send email about the new program+ sendEmail({+ subject: `Your program ${program.name} is created and ready to share with your partners.`,+ email: user.email!,+ react: ProgramWelcome({+ email: user.email!,+ workspace,+ program: {+ ...program,+ logo: logoUrl,+ },+ }),+ }),]),);diff --git a/apps/web/lib/actions/partners/onboard-program.ts b/apps/web/lib/actions/partners/onboard-program.tsindex 0c42470f42..bcc2888c13 100644--- a/apps/web/lib/actions/partners/onboard-program.ts+++ b/apps/web/lib/actions/partners/onboard-program.ts@@ -14,13 +14,7 @@ export const onboardProgramAction = authActionClient.action(async ({ ctx, parsedInput: data }) => {const { workspace, user } = ctx;- const programsCount = await prisma.program.count({- where: {- workspaceId: workspace.id,- },- });-- if (programsCount > 0 || !workspace.partnersEnabled) {+ if (workspace.defaultProgramId || !workspace.partnersEnabled) {throw new Error("You are not allowed to create a new program.");}diff --git a/packages/email/src/templates/program-welcome.tsx b/packages/email/src/templates/program-welcome.tsxindex 424f1cc8f9..688af73cb3 100644--- a/packages/email/src/templates/program-welcome.tsx+++ b/packages/email/src/templates/program-welcome.tsx@@ -23,20 +23,29 @@ import { Footer } from "../components/footer";export function ProgramWelcome({email = "[email protected]",+ workspace = {+ slug: "acme",+ },program = {+ id: "prog_CYCu7IMAapjkRpTnr8F1azjN",+ slug: "acme",name: "Acme",logo: DUB_LOGO,- slug: "acme",},}: {email: string;+ workspace: {+ slug: string;+ };program: {+ id: string;+ slug: string;name: string;logo: string | null;- slug: string;};}) {- const programUrl = `https://partners.dub.co/${program.slug}`;+ const programLandingUrl = `https://partners.dub.co/${program.slug}`;+ const programDashboardUrl = `https://app.dub.co/${workspace.slug}/programs/${program.id}`;return (<Html>@@ -82,10 +91,10 @@ export function ProgramWelcome({</Text><Link- href={programUrl}+ href={programLandingUrl}className="m-0 text-xs font-medium text-neutral-800 underline">- {getPrettyUrl(programUrl)}+ {getPrettyUrl(programLandingUrl)}</Link></Column></Row>@@ -102,7 +111,7 @@ export function ProgramWelcome({1. <span className="font-medium">Customize your dashboard</span> -Make it yours.{" "}<Link- href="https://partners.dub.co/settings/branding"+ href={`${programDashboardUrl}/branding`}className="font-semibold text-neutral-800 underline underline-offset-2">Update the logo and colors@@ -114,7 +123,7 @@ export function ProgramWelcome({2. <span className="font-medium">Invite partners</span> - Bringyour friends, family, and VIP customers to your program; to{" "}<Link- href="https://partners.dub.co/settings/branding"+ href={`${programDashboardUrl}/partners`}className="font-semibold text-neutral-800 underline underline-offset-2">turn fans into advocates@@ -123,9 +132,9 @@ export function ProgramWelcome({</Text><Text className="mb-4 text-sm leading-5 text-neutral-800">- 3. <span className="font-medium">Build your landing page</span> -+ 3. <span className="font-medium">Build your landing page</span> -{" "}<Link- href="https://partners.dub.co/settings/branding"+ href={`${programDashboardUrl}/branding`}className="font-semibold text-neutral-800 underline underline-offset-2">Add content@@ -147,7 +156,7 @@ export function ProgramWelcome({</span>{" "}-{" "}<Link- href="https://partners.dub.co/settings/branding"+ href={`${programDashboardUrl}/settings/rewards`}className="font-semibold text-neutral-800 underline underline-offset-2">Add more rewards@@ -158,7 +167,7 @@ export function ProgramWelcome({<Section className="my-10"><Link- href={`https://partners.dub.co/programs/${program.slug}`}+ href={programDashboardUrl}className="box-border h-10 w-fit rounded-lg bg-black px-4 py-3 text-center text-sm leading-none text-white no-underline">Go to your dashboard