Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

Add simple testing route for email (#362)

Sean Boult9104ec4b8447
diff --git a/apps/email/emails/index.ts b/apps/email/emails/index.ts
new file mode 100644
index 00000000..ed66fa1e
--- /dev/null
+++ b/apps/email/emails/index.ts
@@ -0,0 +1 @@
+export * from './waitlist-user-signup';
diff --git a/apps/email/emails/waitlist-user-signup.tsx b/apps/email/emails/waitlist-user-signup.tsx
index 5aa803f8..2f11f3c1 100644
--- a/apps/email/emails/waitlist-user-signup.tsx
+++ b/apps/email/emails/waitlist-user-signup.tsx
@@ -12,41 +12,36 @@ import {
} from '@react-email/components';
import * as React from 'react';
-interface VercelInviteUserEmailProps {}
+// so that we can access the assets from the typehero-email vercel app that is running as a "static site"
+const baseUrl =
+ process.env.NODE_ENV === 'production'
+ ? `https://email.typehero.dev`
+ : 'http://127.0.0.1:6969/static';
-// This means we'd deploy all the email assets to a static host
-// so that we can access them from a CDN
-const baseUrl = process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : '';
-
-export const VercelInviteUserEmail = ({}: VercelInviteUserEmailProps) => {
+export const UserSignupEmail = () => {
return (
<Html>
<Head />
- <Preview>Thanks for joining the Typehero waitlist</Preview>
+ <Preview>You're on the Typehero Waitlist!</Preview>
<Tailwind>
<Body className="mx-auto my-auto bg-white font-sans">
<Container className="mx-auto my-[40px] w-[465px] rounded border border-solid border-[#eaeaea] p-[20px]">
<Section className="mt-[32px]">
<Img
- src={`${baseUrl}/static/typehero.png`}
- width="40"
- height="37"
- alt="Vercel"
+ src={`${baseUrl}/typehero.png`}
+ width="64"
+ height="auto"
+ alt="Typehero"
className="mx-auto my-0"
/>
</Section>
<Heading className="mx-0 my-[30px] p-0 text-center text-[24px] font-bold text-black">
- You're on the Waitlist!
+ You're on the Typehero Waitlist!
</Heading>
<Text className="pb-2 text-[20px] leading-[24px] text-black">Hey there πŸ‘‹</Text>
<Text className="text-[14px] leading-[24px] text-black">
Thank you so much for signing up for the typehero waitlist, we really apperciate it.
</Text>
- <Img
- src={`${baseUrl}/static/signup.gif`}
- alt="Vercel"
- className="mx-auto my-0"
- />
<Text className="text-[14px] leading-[24px] text-black">
We are cooking extremelly hard to bring you the best experience for doing type
challenges.
@@ -58,4 +53,4 @@ export const VercelInviteUserEmail = ({}: VercelInviteUserEmailProps) => {
);
};
-export default VercelInviteUserEmail;
+export default UserSignupEmail;
diff --git a/apps/email/package.json b/apps/email/package.json
index 9d526564..d0ed2fa8 100644
--- a/apps/email/package.json
+++ b/apps/email/package.json
@@ -1,15 +1,21 @@
{
- "name": "emails",
+ "name": "@repo/emails",
"version": "0.0.18",
"private": true,
"workspaces": [
".react-email"
],
+ "export": {
+ ".": {
+ "import": "email/index.ts"
+ }
+ },
"scripts": {
"dev": "email dev -p 6969",
"clean": "rm -rf node_modules .react-email",
"build": "email export"
},
+ "files": [],
"dependencies": {
"@react-email/components": "0.0.6",
"react-email": "1.9.3"
diff --git a/apps/email/static/signup.gif b/apps/email/static/signup.gif
index 8776935c..302e8266 100644
Binary files a/apps/email/static/signup.gif and b/apps/email/static/signup.gif differ
diff --git a/apps/web/global.d.ts b/apps/web/global.d.ts
index 6bcc22c3..256daf24 100644
--- a/apps/web/global.d.ts
+++ b/apps/web/global.d.ts
@@ -10,5 +10,6 @@ declare namespace NodeJS {
GITHUB_ID: string;
GITHUB_SECRET: string;
PORT: number;
+ RESEND_API_KEY: string;
}
}
diff --git a/apps/web/package.json b/apps/web/package.json
index 986d553b..fcb80faa 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -20,6 +20,7 @@
"@radix-ui/react-dialog": "^1.0.4",
"@repo/auth": "workspace:*",
"@repo/db": "workspace:*",
+ "@repo/emails": "workspace:*",
"@repo/lint": "workspace:*",
"@repo/ui": "workspace:*",
"@t3-oss/env-nextjs": "^0.6.0",
@@ -48,6 +49,7 @@
"react-syntax-highlighter": "^15.5.0",
"react-wrap-balancer": "^1.0.0",
"remark-gfm": "^3.0.1",
+ "resend": "^0.17.2",
"superjson": "1.12.4",
"tailwindcss-animate": "^1.0.6",
"unified": "^10.1.2",
diff --git a/apps/web/src/app/api/lol/route.ts b/apps/web/src/app/api/auth/creds/route.ts
similarity index 100%
rename from apps/web/src/app/api/lol/route.ts
rename to apps/web/src/app/api/auth/creds/route.ts
diff --git a/apps/web/src/app/api/email/route.ts b/apps/web/src/app/api/email/route.ts
new file mode 100644
index 00000000..176e086d
--- /dev/null
+++ b/apps/web/src/app/api/email/route.ts
@@ -0,0 +1,39 @@
+// TODO: fix the import paths
+import { UserSignupEmail } from '@repo/emails/emails/index';
+import type { NextRequest } from 'next/server';
+import { NextResponse } from 'next/server';
+import { Resend } from 'resend';
+
+// TODO: this is awaiting trash to setup on vercel
+const resend = new Resend(process.env.RESEND_API_KEY);
+
+// TODO: THIS HAS TO BE REMOVED
+export async function GET(request: NextRequest) {
+ const { searchParams } = new URL(request.url);
+ // TODO: remove this default email
+ const to = searchParams.get('to') ?? '[email protected]';
+
+ try {
+ return NextResponse.json(sendUserSignupEmail(to));
+ } catch (error) {
+ return NextResponse.json({ error });
+ }
+}
+
+/**
+ * send a signup email that will use resend to send an email
+ * using the template from the app/email package
+ */
+export const sendUserSignupEmail = async (to: string) => {
+ const data = await resend.emails.send({
+ from: 'Typehero <[email protected]>',
+ to: [to],
+ subject: 'πŸ”₯ Thanks for signing up to Typehero!',
+ react: UserSignupEmail(),
+ });
+
+ return {
+ emailId: data.id,
+ to,
+ };
+};
diff --git a/apps/web/src/components/landing/waitlist/create.action.ts b/apps/web/src/components/landing/waitlist/create.action.ts
index 3dcd839b..b1671f23 100644
--- a/apps/web/src/components/landing/waitlist/create.action.ts
+++ b/apps/web/src/components/landing/waitlist/create.action.ts
@@ -1,6 +1,7 @@
'use server';
import { prisma } from '@repo/db';
+import { sendUserSignupEmail } from '~/app/api/email/route';
import { type WaitlistFormSchema } from '~/components/landing/waitlist/waitlist-form';
export async function uploadWaitlistEntry(data: WaitlistFormSchema) {
@@ -17,11 +18,13 @@ export async function uploadWaitlistEntry(data: WaitlistFormSchema) {
throw new Error('You are already on the waitlist!');
}
- return await prisma.waitlist.create({
+ await prisma.waitlist.create({
data: {
name: data.name,
email: data.email,
intention: isUser ? 'USER' : isBuilder ? 'BUILDER' : 'BOTH',
},
});
+
+ await sendUserSignupEmail(data.email);
}
diff --git a/apps/web/src/components/landing/waitlist/waitlist-form.tsx b/apps/web/src/components/landing/waitlist/waitlist-form.tsx
index 56747929..af0e2221 100644
--- a/apps/web/src/components/landing/waitlist/waitlist-form.tsx
+++ b/apps/web/src/components/landing/waitlist/waitlist-form.tsx
@@ -51,6 +51,8 @@ export function WaitlistForm() {
setState('success');
} catch (e) {
setState('error');
+ } finally {
+ form.reset();
}
}
diff --git a/apps/web/src/middleware.ts b/apps/web/src/middleware.ts
index 3cf87824..e8a03f02 100644
--- a/apps/web/src/middleware.ts
+++ b/apps/web/src/middleware.ts
@@ -13,7 +13,9 @@ export function middleware(req: NextRequest) {
return NextResponse.next();
}
}
- url.pathname = '/api/lol';
+
+ // Make the user get some damn creds
+ url.pathname = '/api/auth/creds';
return NextResponse.rewrite(url);
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 03c6426d..1d917783 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -67,6 +67,9 @@ importers:
'@repo/db':
specifier: workspace:*
version: link:../../packages/db
+ '@repo/emails':
+ specifier: workspace:*
+ version: link:../email
'@repo/lint':
specifier: workspace:*
version: link:../../tooling/config-eslint
@@ -151,6 +154,9 @@ importers:
remark-gfm:
specifier: ^3.0.1
version: 3.0.1
+ resend:
+ specifier: ^0.17.2
+ version: 0.17.2
superjson:
specifier: 1.12.4
version: 1.12.4
@@ -3877,7 +3883,6 @@ packages:
resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==}
- dev: true
resolution: {integrity: sha512-7prDjvt9HmqiZ0cl5CRjtS84sEyhsHP2coDkaZKRKVfCDo9s7iw7ChVmar78Gu9pC4SoR/28wFu/G5JJhTnqEg==}
@@ -3908,6 +3913,16 @@ packages:
resolution: {integrity: sha512-zIURGIS1E1Q4pcrMjp+nnEh+16G56eG/MUllJH8yEvw7asDo7Ac9uhC9KIH5jzpITueEZolfYglnCGIuSBz39g==}
engines: {node: '>=4'}
+ resolution: {integrity: sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==}
+ dependencies:
+ follow-redirects: 1.15.2
+ form-data: 4.0.0
+ proxy-from-env: 1.1.0
+ transitivePeerDependencies:
+ - debug
+ dev: false
+
resolution: {integrity: sha512-jsyHu61e6N4Vbz/v18DHwWYKK0bSWLqn47eeDSKPB7m8tqMHF9YJ+mhIk2lVteyZrY8tnSj/jHOv4YiTCuCJgg==}
dependencies:
@@ -4243,7 +4258,6 @@ packages:
engines: {node: '>= 0.8'}
dependencies:
delayed-stream: 1.0.0
- dev: true
resolution: {integrity: sha512-GHuDRO12Sypu2cV70d1dkA2EUmXHgntrzbpvOB+Qy+49ypNfGgFQIC2fhhXbnyrJRynDCAARsT7Ou0M6hirpfw==}
@@ -4429,7 +4443,6 @@ packages:
resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==}
engines: {node: '>=0.4.0'}
- dev: true
resolution: {integrity: sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==}
@@ -5573,6 +5586,16 @@ packages:
resolution: {integrity: sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==}
+ resolution: {integrity: sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==}
+ engines: {node: '>=4.0'}
+ peerDependencies:
+ debug: '*'
+ peerDependenciesMeta:
+ debug:
+ optional: true
+ dev: false
+
resolution: {integrity: sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==}
dependencies:
@@ -5587,6 +5610,15 @@ packages:
mime-types: 2.1.35
dev: true
+ resolution: {integrity: sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==}
+ engines: {node: '>= 6'}
+ dependencies:
+ asynckit: 0.4.0
+ combined-stream: 1.0.8
+ mime-types: 2.1.35
+ dev: false
+
resolution: {integrity: sha512-wzsgA6WOq+09wrU1tsJ09udeR/YZRaeArL9e1wPbFg3GG2yDnC2ldKpxs4xunpFF9DgqCqOIra3bc1HWrJ37Ww==}
engines: {node: '>=0.4.x'}
@@ -7056,14 +7088,12 @@ packages:
resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==}
engines: {node: '>= 0.6'}
- dev: true
resolution: {integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==}
engines: {node: '>= 0.6'}
dependencies:
mime-db: 1.52.0
- dev: true
resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==}
@@ -7892,6 +7922,10 @@ packages:
resolution: {integrity: sha512-vtK/94akxsTMhe0/cbfpR+syPuszcuwhqVjJq26CuNDgFGj682oRBXOP5MJpv2r7JtE8MsiepGIqvvOTBwn2vA==}
dev: false
+ resolution: {integrity: sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==}
+ dev: false
+
resolution: {integrity: sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==}
engines: {node: '>=6'}
@@ -8358,6 +8392,16 @@ packages:
unified: 10.1.2
dev: false
+ resolution: {integrity: sha512-lakm76u4MiIDeMF1s2tCmjtksOhwZOs4WcAXkA7aUTvl+63/h+0h6Q6WnkB8RGtj6GakUhQuUkiZshfXgtIrGw==}
+ dependencies:
+ '@react-email/render': 0.0.7
+ axios: 1.4.0
+ type-fest: 3.13.0
+ transitivePeerDependencies:
+ - debug
+ dev: false
+
resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==}
engines: {node: '>=4'}
@@ -9143,6 +9187,11 @@ packages:
engines: {node: '>=8'}
dev: false
+ resolution: {integrity: sha512-Gur3yQGM9qiLNs0KPP7LPgeRbio2QTt4xXouobMCarR0/wyW3F+F/+OWwshg3NG0Adon7uQfSZBpB46NfhoF1A==}
+ engines: {node: '>=14.16'}
+ dev: false
+
resolution: {integrity: sha512-Y8KTSIglk9OZEr8zywiIHG/kmQ7KWyjseXs1CbSo8vC42w7hg2HgYTxSWwP0+is7bWDc1H+Fo026CpHFwm8tkw==}
engines: {node: '>= 0.4'}
diff --git a/turbo.json b/turbo.json
index 89f4588a..ee942295 100644
--- a/turbo.json
+++ b/turbo.json
@@ -13,6 +13,7 @@
"UPLOADTHING_APP_ID",
"NEXTAUTH_SECRET",
"NEXTAUTH_URL",
+ "RESEND_API_KEY",
"PORT"
]
},