-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jamesb
committed
Mar 2, 2024
1 parent
924d125
commit d198a01
Showing
7 changed files
with
2,824 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
import { Button } from "@react-email/button"; | ||
import { | ||
Body, | ||
Container, | ||
Head, | ||
Heading, | ||
Html, | ||
Preview, | ||
Row, | ||
Section, | ||
Text, | ||
Tailwind, | ||
Img, | ||
Link, | ||
Column, | ||
} from "@react-email/components"; | ||
import React from "react"; | ||
import { AddRecommendationInput } from "../addRecomendations"; | ||
|
||
interface RecommendationsEmailProps { | ||
input: AddRecommendationInput; | ||
} | ||
|
||
const defaults: RecommendationsEmailProps = { | ||
input: { | ||
username: "experilearning", | ||
clips: { | ||
"How to make a website": { | ||
"How to make a website from scratch": [ | ||
{ | ||
title: "How to make a website from scratch", | ||
question: "How to make a website from scratch", | ||
text: "This is a video about how to make a website from scratch", | ||
articleTitle: "How to make a website from scratch", | ||
type: "article", | ||
articleUrl: "https://example.com", | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default function RecommendationsEmail({ | ||
input = defaults.input, | ||
}: RecommendationsEmailProps) { | ||
return ( | ||
<Html> | ||
<Head /> | ||
<Preview>Open Recommender Recommendations</Preview> | ||
<Tailwind | ||
config={{ | ||
theme: { | ||
extend: { | ||
colors: { | ||
brand: "#2250f4", | ||
offwhite: "#fafbfb", | ||
}, | ||
spacing: { | ||
0: "0px", | ||
10: "10px", | ||
20: "20px", | ||
45: "45px", | ||
}, | ||
}, | ||
}, | ||
}} | ||
> | ||
<Body className="font-sans text-base bg-offwhite"> | ||
<Img | ||
src={`https://open-recommender.com/logo.webp`} | ||
width="184" | ||
alt="Open Recommender" | ||
className="mx-auto my-20" | ||
/> | ||
<Container className="bg-white px-45"> | ||
<Heading className="my-0 leading-8 text-center"> | ||
New Recommendations | ||
</Heading> | ||
<Section> | ||
<Row> | ||
<Text className="text-base text-center"> | ||
View your latest recommendations below or in your feed. | ||
</Text> | ||
</Row> | ||
</Section> | ||
<Section className="text-center"> | ||
<Button | ||
href={`https://open-recommender.com/#/${input.username}/feed`} | ||
className="bg-brand text-white rounded-lg py-3 px-[18px]" | ||
> | ||
Go to your feed | ||
</Button> | ||
</Section> | ||
{input.username === "experilearning" && ( | ||
<Section> | ||
<pre>{JSON.stringify(input, null, 2)}</pre> | ||
</Section> | ||
)} | ||
|
||
<Section> | ||
{ | ||
// Loop through the recommendations and create a section for each query | ||
Object.entries(input.clips).map(([query, clusters], i) => { | ||
return ( | ||
<Section key={i}> | ||
<Heading as="h2">{query}</Heading> | ||
{ | ||
// Loop through the clusters and create a section for each question | ||
Object.entries(clusters).map(([question, clips], i) => { | ||
return ( | ||
<React.Fragment key={i}> | ||
<Heading as="h4">{question}</Heading> | ||
{clips.map((clip) => { | ||
return ( | ||
<Row> | ||
<Text>{clip.text}</Text> | ||
</Row> | ||
); | ||
})} | ||
</React.Fragment> | ||
); | ||
}) | ||
} | ||
</Section> | ||
); | ||
}) | ||
} | ||
</Section> | ||
<Container className="mt-20"> | ||
<Section> | ||
<Row> | ||
<Column className="px-20 text-right"> | ||
<Link>Give Feedback</Link> | ||
</Column> | ||
<Column className="text-left"> | ||
<Link>Manage Preferences</Link> | ||
</Column> | ||
</Row> | ||
</Section> | ||
</Container> | ||
</Container> | ||
</Body> | ||
</Tailwind> | ||
</Html> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { User } from "@prisma/client"; | ||
import { Resend } from "resend"; | ||
import { AddRecommendationInput } from "./addRecomendations"; | ||
import RecommendationsEmail from "./email/RecommendationsEmail"; | ||
import React from "react"; | ||
|
||
const subjectLines = [ | ||
"Fresh recommendations", | ||
"New nuggets", | ||
"New recommendations", | ||
]; | ||
|
||
export async function sendRecommendationsEmail( | ||
toUser: User, | ||
input: AddRecommendationInput | ||
) { | ||
const resend = new Resend(process.env.RESEND_API_KEY); | ||
const subject = subjectLines[Math.floor(Math.random() * subjectLines.length)]; | ||
await resend.emails.send({ | ||
from: process.env.NO_REPLY_EMAIL!, | ||
to: toUser.email, | ||
subject, | ||
react: <RecommendationsEmail input={input} />, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.