The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
send email after transfer
Kiran K507328cdd694
diff --git a/apps/web/app/api/cron/domains/transfer/route.ts b/apps/web/app/api/cron/domains/transfer/route.tsindex c6512e7ada..c2ca3c9194 100644--- a/apps/web/app/api/cron/domains/transfer/route.ts+++ b/apps/web/app/api/cron/domains/transfer/route.ts@@ -5,12 +5,10 @@ import { formatRedisLink, redis } from "@/lib/upstash";import z from "@/lib/zod";import { APP_DOMAIN_WITH_NGROK, log } from "@dub/utils";import { Link } from "@prisma/client";+import { sendEmail } from "emails";+import DomainTransferred from "emails/domain-transferred";import { NextResponse } from "next/server";-// TODO:-// Update TB-// Send email-const schema = z.object({currentWorkspaceId: z.string(),newWorkspaceId: z.string(),@@ -56,21 +54,74 @@ export async function POST(req: Request) {where: { linkId: { in: linkIds } },}),updateLinksInRedis({ links, newWorkspaceId, domain }),- updateAnalytics({ links, newWorkspaceId, currentWorkspaceId }),+ updateUsage({ links, newWorkspaceId, currentWorkspaceId }),]);// wait 500 ms before making another requestawait new Promise((resolve) => setTimeout(resolve, 500));- await qstash.publishJSON({- url: `${APP_DOMAIN_WITH_NGROK}/api/cron/domains/transfer`,- body: {- currentWorkspaceId,- newWorkspaceId,- domain,- },+ const hasMoreLinks = await prisma.link.count({+ where: { domain, projectId: currentWorkspaceId },});+ // No more links to transfer+ if (hasMoreLinks === 0) {+ const currentWorkspace = await prisma.project.findUnique({+ where: {+ id: currentWorkspaceId,+ },+ select: {+ name: true,+ slug: true,+ users: {+ where: {+ role: "owner",+ },+ select: {+ user: {+ select: {+ email: true,+ },+ },+ },+ },+ },+ });++ const newWorkspace = await prisma.project.findUniqueOrThrow({+ where: {+ id: newWorkspaceId,+ },+ select: {+ name: true,+ slug: true,+ },+ });++ const ownerEmail = currentWorkspace?.users[0]?.user?.email!;++ sendEmail({+ subject: "Domain transfer completed",+ email: ownerEmail,+ react: DomainTransferred({+ email: ownerEmail,+ domain,+ newWorkspace,+ }),+ });+ }++ if (hasMoreLinks > 0) {+ await qstash.publishJSON({+ url: `${APP_DOMAIN_WITH_NGROK}/api/cron/domains/transfer`,+ body: {+ currentWorkspaceId,+ newWorkspaceId,+ domain,+ },+ });+ }+return NextResponse.json({response: "success",});@@ -118,7 +169,7 @@ const updateLinksInRedis = async ({};// Update links & click usage-const updateAnalytics = async ({+const updateUsage = async ({currentWorkspaceId,newWorkspaceId,links,diff --git a/apps/web/emails/domain-transferred.tsx b/apps/web/emails/domain-transferred.tsxnew file mode 100644index 0000000000..19ab03ddf0--- /dev/null+++ b/apps/web/emails/domain-transferred.tsx@@ -0,0 +1,62 @@+import { DUB_LOGO } from "@dub/utils";+import { Project } from "@prisma/client";+import {+ Body,+ Container,+ Head,+ Heading,+ Html,+ Img,+ Link,+ Preview,+ Section,+ Tailwind,+ Text,+} from "@react-email/components";+import Footer from "./components/footer";++export default function DomainTransferred({+ email = "[email protected]",+ domain = "dub.sh",+ newWorkspace = { name: "Dub", slug: "dub" },+}: {+ email: string;+ domain: string;+ newWorkspace: Pick<Project, "name" | "slug">;+}) {+ return (+ <Html>+ <Head />+ <Preview>Domain Transferred</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_LOGO}+ width="40"+ height="40"+ alt="Dub"+ className="mx-auto my-0"+ />+ </Section>+ <Heading className="mx-0 my-7 p-0 text-center text-xl font-semibold text-black">+ Domain Transferred+ </Heading>+ <Text className="text-sm leading-6 text-black">+ Your domain <code className="text-purple-600">{domain}</code> and+ its links has been transferred to the workspace{" "}+ <Link+ href={`https://app.dub.co/${newWorkspace.slug}/domains`}+ className="font-medium text-blue-600 no-underline"+ >+ {newWorkspace.name}↗+ </Link>+ </Text>+ <Footer email={email} />+ </Container>+ </Body>+ </Tailwind>+ </Html>+ );+}