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 reminder email

Tim Wilson63fe35d7be7a
diff --git a/apps/web/app/api/cron/program-application-reminder/route.ts b/apps/web/app/api/cron/program-application-reminder/route.ts
new file mode 100644
index 0000000000..e02b95d7c4
--- /dev/null
+++ b/apps/web/app/api/cron/program-application-reminder/route.ts
@@ -0,0 +1,67 @@
+import { handleAndReturnErrorResponse } from "@/lib/api/errors";
+import { verifyQstashSignature } from "@/lib/cron/verify-qstash";
+import { sendEmail } from "@dub/email";
+import ProgramApplicationReminder from "@dub/email/templates/program-application-reminder";
+import { prisma } from "@dub/prisma";
+
+// POST - /api/cron/program-application-reminder
+// Sends an email if a program application hasn't received an associated partner
+export async function POST(req: Request) {
+ try {
+ const rawBody = await req.text();
+ await verifyQstashSignature({ req, rawBody });
+
+ const { applicationId } = JSON.parse(rawBody);
+
+ const application = await prisma.programApplication.findUnique({
+ where: {
+ id: applicationId,
+ partner: null,
+ },
+ include: {
+ program: {
+ select: {
+ id: true,
+ name: true,
+ },
+ },
+ },
+ });
+
+ if (!application)
+ return new Response(
+ `Application ${applicationId} without partner not found. Skipping...`,
+ );
+
+ try {
+ await sendEmail({
+ subject: `Complete your application to ${application.program.name}`,
+ email: application.email,
+ react: ProgramApplicationReminder({
+ email: application.email,
+ program: {
+ name: application.program.name,
+ },
+ }),
+ });
+
+ console.log(
+ `Sent application reminder email to ${application.email} for application ${applicationId}`,
+ );
+ } catch (e) {
+ console.error(
+ `Failed to send application reminder email to ${application.email} for application ${applicationId}`,
+ e,
+ );
+ return new Response(
+ `Failed to send application reminder email to ${application.email} for application ${applicationId}`,
+ );
+ }
+
+ return new Response(
+ `Email sent to ${application.email} for application ${applicationId}.`,
+ );
+ } catch (error) {
+ return handleAndReturnErrorResponse(error);
+ }
+}
diff --git a/apps/web/lib/actions/partners/create-program-application.ts b/apps/web/lib/actions/partners/create-program-application.ts
index c0a0dad526..7819321716 100644
--- a/apps/web/lib/actions/partners/create-program-application.ts
+++ b/apps/web/lib/actions/partners/create-program-application.ts
@@ -4,14 +4,17 @@ import { createId } from "@/lib/api/create-id";
import { notifyPartnerApplication } from "@/lib/api/partners/notify-partner-application";
import { getIP } from "@/lib/api/utils";
import { getSession } from "@/lib/auth";
+import { qstash } from "@/lib/cron";
import { ratelimit } from "@/lib/upstash";
import { prisma } from "@dub/prisma";
import { Partner, Program, ProgramEnrollment } from "@dub/prisma/client";
+import { APP_DOMAIN_WITH_NGROK } from "@dub/utils";
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),
@@ -68,10 +71,21 @@ export const createProgramApplicationAction = actionClient
});
}
- return createApplication({
+ const application = await createApplication({
program,
data: parsedInput,
});
+
+ await qstash.publishJSON({
+ url: `${APP_DOMAIN_WITH_NGROK}/api/cron/program-application-reminder`,
+ delay: 15 * 60, // 15 minutes
+ body: {
+ applicationId: application.programApplicationId,
+ },
+ contentBasedDeduplication: true,
+ });
+
+ return application;
},
);
diff --git a/packages/email/src/templates/program-application-reminder.tsx b/packages/email/src/templates/program-application-reminder.tsx
new file mode 100644
index 0000000000..8e6bb9ca21
--- /dev/null
+++ b/packages/email/src/templates/program-application-reminder.tsx
@@ -0,0 +1,68 @@
+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 "src/components/footer";
+
+export default function ProgramApplicationReminder({
+ email = "[email protected]",
+ program = {
+ name: "Acme",
+ },
+}: {
+ email: string;
+ program: {
+ name: string;
+ };
+}) {
+ return (
+ <Html>
+ <Head />
+ <Preview>
+ Your application to {program.name} has been saved, but you still need to
+ create your Dub Partner account to complete your 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">
+ You're almost ready!
+ </Heading>
+
+ <Text className="text-sm leading-6 text-neutral-600">
+ Your application to {program.name} has been saved, but you still
+ need to create your Dub Partners account to finish your
+ application. This is required to earn rewards and access your
+ dashboard.
+ </Text>
+
+ <Section className="mt-8 text-center">
+ <Link
+ href={"https://partners.dub.co/register"}
+ className="box-border block w-full rounded-md bg-black px-0 py-4 text-center text-sm font-medium leading-none text-white no-underline"
+ >
+ Create your Dub Partners account
+ </Link>
+ </Section>
+
+ <Footer email={email} />
+ </Container>
+ </Body>
+ </Tailwind>
+ </Html>
+ );
+}