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.

New partner application email notification

Kiran K086d95a412dd
diff --git a/apps/web/lib/actions/partners/create-program-application.ts b/apps/web/lib/actions/partners/create-program-application.ts
index e0871ab656..777fe0e5de 100644
--- a/apps/web/lib/actions/partners/create-program-application.ts
+++ b/apps/web/lib/actions/partners/create-program-application.ts
@@ -3,14 +3,17 @@
import { createId } from "@/lib/api/create-id";
import { getIP } from "@/lib/api/utils";
import { getSession } from "@/lib/auth";
+import { limiter } from "@/lib/cron/limiter";
import { ratelimit } from "@/lib/upstash";
+import { sendEmail } from "@dub/email";
+import { PartnerApplicationReceived } from "@dub/email/templates/partner-application-received";
import { prisma } from "@dub/prisma";
import { Partner, Program, ProgramEnrollment } from "@dub/prisma/client";
+import { waitUntil } from "@vercel/functions";
import { addDays } from "date-fns";
import { cookies } from "next/headers";
import z from "../../zod";
import { actionClient } from "../safe-action";
-
const createProgramApplicationSchema = z.object({
programId: z.string(),
name: z.string().trim().min(1).max(100),
@@ -112,6 +115,52 @@ async function createApplicationAndEnrollment({
}),
]);
+ waitUntil(
+ (async () => {
+ const workspaceUsers = await prisma.projectUsers.findMany({
+ where: {
+ projectId: program.workspaceId,
+ // notificationPreference: {
+ // newPartnerSale: true, // TODO: change to newPartnerApplication
+ // },
+ },
+ include: {
+ user: {
+ select: {
+ email: true,
+ },
+ },
+ },
+ });
+
+ await Promise.all([
+ ...workspaceUsers.map(({ user }) =>
+ limiter.schedule(() =>
+ sendEmail({
+ subject: `New partner application for ${program.name}.`,
+ email: "[email protected]", //partner.email!,
+ react: PartnerApplicationReceived({
+ email: partner.email!,
+ partner: {
+ id: partner.id,
+ name: partner.name,
+ email: partner.email!,
+ image: partner.image,
+ country: partner.country,
+ proposal: data.proposal,
+ comments: data.comments,
+ },
+ program: {
+ id: program.id,
+ },
+ }),
+ }),
+ ),
+ ),
+ ]);
+ })(),
+ );
+
return {
programApplicationId: applicationId,
programEnrollmentId: enrollmentId,
diff --git a/packages/email/src/templates/partner-application-received.tsx b/packages/email/src/templates/partner-application-received.tsx
new file mode 100644
index 0000000000..773d0c531a
--- /dev/null
+++ b/packages/email/src/templates/partner-application-received.tsx
@@ -0,0 +1,179 @@
+import { DUB_WORDMARK } 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 function PartnerApplicationReceived({
+ email = "[email protected]",
+ partner = {
+ id: "pn_1JPBEGP7EXF76CXT1W99VERW5",
+ name: "John Doe",
+ email: "[email protected]",
+ image:
+ "https://www.gravatar.com/avatar/2c7d99fe281ecd3bcd65ab915bac6dd5?s=250",
+ country: "US",
+ proposal:
+ "This is a text field the applicant can fill out with details about the question asked above.",
+ comments:
+ "This is a text field the applicant can fill out with details about the question asked above.",
+ },
+ program = {
+ id: "prog_CYCu7IMAapjkRpTnr8F1azjN",
+ },
+}: {
+ email: string;
+ partner: {
+ id: string;
+ name: string;
+ email: string;
+ image: string | null;
+ country: string | null;
+ proposal: string;
+ comments?: string;
+ };
+ program: {
+ id: string;
+ };
+}) {
+ const applicationUrl = `https://app.dub.co/acme/programs/${program.id}/partners?partnerId=${partner.id}`;
+
+ return (
+ <Html>
+ <Head />
+ <Preview>New partner application</Preview>
+ <Tailwind>
+ <Body className="mx-auto my-auto bg-white font-sans">
+ <Container className="mx-auto my-10 max-w-[600px] rounded border border-solid border-neutral-200 px-10 py-5">
+ <Section className="mb-8 mt-6">
+ <Img src={DUB_WORDMARK} width="65" height="32" alt="dub" />
+ </Section>
+
+ <Heading className="mx-0 p-0 text-lg font-medium text-neutral-800">
+ New partner application
+ </Heading>
+
+ <Text className="text-sm leading-6 text-neutral-600">
+ You have a new pending application to review, view their
+ application below and or{" "}
+ <Link
+ href={applicationUrl}
+ className="text-neutral-600 underline underline-offset-4"
+ >
+ review on Dub
+ </Link>
+ .
+ </Text>
+
+ <Container className="mb-8 mt-10 rounded-lg border border-solid border-neutral-200">
+ <Section className="p-4">
+ <Container className="mb-4 w-full rounded-lg bg-[#f9fafb] p-6">
+ <div>
+ <div
+ style={{
+ position: "relative",
+ marginBottom: "16px",
+ display: "inline-block",
+ }}
+ >
+ <Img
+ src={partner.image ?? undefined}
+ width="64"
+ height="64"
+ alt={partner.name}
+ style={{ borderRadius: "9999px" }}
+ />
+
+ {partner.country && (
+ <Img
+ src={`https://flag.vercel.app/${partner.country}.svg`}
+ width="18"
+ height="18"
+ alt={partner.country}
+ style={{
+ position: "absolute",
+ bottom: "0",
+ right: "0",
+ borderRadius: "50%",
+ border: "2px solid white",
+ }}
+ />
+ )}
+ </div>
+ <div>
+ <Text className="m-0 p-0 text-2xl font-medium text-black">
+ {partner.name}
+ </Text>
+ <Text className="m-0 p-0 text-sm text-neutral-500">
+ {partner.email}
+ </Text>
+ </div>
+ </div>
+ </Container>
+
+ <Section className="mb-6">
+ <Text className="m-0 mb-2 p-0 text-base font-medium text-neutral-900">
+ How do you plan on promoting Cal.com
+ </Text>
+ <Text className="m-0 p-0 leading-6 text-neutral-600">
+ {partner.proposal}
+ </Text>
+ </Section>
+
+ {partner.comments && (
+ <Section className="mb-6">
+ <Text className="m-0 mb-2 p-0 text-base font-medium text-neutral-900">
+ Any additional question or comments{" "}
+ <span className="font-normal text-neutral-500">
+ (optional)
+ </span>
+ </Text>
+ <Text className="m-0 p-0 leading-6 text-neutral-600">
+ {partner.comments}
+ </Text>
+ </Section>
+ )}
+
+ <Section className="mt-8 text-center">
+ <Link
+ href={applicationUrl}
+ style={{
+ backgroundColor: "#111111",
+ borderRadius: "6px",
+ color: "#fff",
+ display: "block",
+ fontSize: "14px",
+ fontWeight: "500",
+ lineHeight: "100%",
+ padding: "16px 0",
+ textDecoration: "none",
+ textAlign: "center",
+ width: "100%",
+ boxSizing: "border-box",
+ }}
+ >
+ Review application on Dub
+ </Link>
+ </Section>
+ </Section>
+ </Container>
+
+ <Footer email={email} />
+ </Container>
+ </Body>
+ </Tailwind>
+ </Html>
+ );
+}
+
+export default PartnerApplicationReceived;