-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
2fa9706
commit 4b4a52c
Showing
8 changed files
with
300 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import Jobs from '@/emails/jobs' | ||
import { queryGetJobs } from '@/lib/db/queries' | ||
import { render } from '@react-email/render' | ||
import { ReasonPhrases, StatusCodes } from 'http-status-codes' | ||
import { headers } from 'next/headers' | ||
import { Resend } from 'resend' | ||
|
||
const resend = new Resend(process.env.RESEND_API_KEY) | ||
|
||
export const POST = async () => { | ||
try { | ||
const headerList = headers() | ||
const auth = headerList.get('Authorization') | ||
|
||
if (auth !== `Bearer ${process.env.CRON_SECRET}`) { | ||
return Response.json( | ||
{ | ||
message: ReasonPhrases.UNAUTHORIZED, | ||
}, | ||
{ | ||
status: StatusCodes.UNAUTHORIZED, | ||
}, | ||
) | ||
} | ||
|
||
const recipients = process.env.PERSONAL_EMAIL | ||
|
||
if (!recipients) { | ||
throw new Error('No recipients found') | ||
} | ||
|
||
const { data: jobs } = await queryGetJobs(['new']) | ||
const { data: savedJobs } = await queryGetJobs(['topChoice']) | ||
|
||
const { data, error } = await resend.emails.send({ | ||
from: 'OWAT <[email protected]>', | ||
to: [recipients], | ||
subject: "Today's Jobs", | ||
html: render(<Jobs newJobs={jobs} savedJobs={savedJobs} />), | ||
}) | ||
|
||
if (error) { | ||
throw error | ||
} | ||
|
||
return Response.json({ data }, { status: StatusCodes.OK }) | ||
} catch (error) { | ||
return Response.json( | ||
{ error }, | ||
{ status: StatusCodes.INTERNAL_SERVER_ERROR }, | ||
) | ||
} | ||
} | ||
|
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,63 @@ | ||
import type { TailwindConfig } from '@react-email/tailwind' | ||
|
||
export const tailwindConfig = { | ||
theme: { | ||
extend: { | ||
colors: { | ||
brand: '#FFBA18', | ||
}, | ||
}, | ||
fontSize: { | ||
xs: ['12px', { lineHeight: '16px' }], | ||
sm: ['14px', { lineHeight: '20px' }], | ||
base: ['16px', { lineHeight: '24px' }], | ||
lg: ['18px', { lineHeight: '28px' }], | ||
xl: ['20px', { lineHeight: '28px' }], | ||
'2xl': ['24px', { lineHeight: '32px' }], | ||
'3xl': ['30px', { lineHeight: '36px' }], | ||
'4xl': ['36px', { lineHeight: '36px' }], | ||
'5xl': ['48px', { lineHeight: '1' }], | ||
'6xl': ['60px', { lineHeight: '1' }], | ||
'7xl': ['72px', { lineHeight: '1' }], | ||
'8xl': ['96px', { lineHeight: '1' }], | ||
'9xl': ['144px', { lineHeight: '1' }], | ||
}, | ||
spacing: { | ||
px: '1px', | ||
0: '0', | ||
0.5: '2px', | ||
1: '4px', | ||
1.5: '6px', | ||
2: '8px', | ||
2.5: '10px', | ||
3: '12px', | ||
3.5: '14px', | ||
4: '16px', | ||
5: '20px', | ||
6: '24px', | ||
7: '28px', | ||
8: '32px', | ||
9: '36px', | ||
10: '40px', | ||
11: '44px', | ||
12: '48px', | ||
14: '56px', | ||
16: '64px', | ||
20: '80px', | ||
24: '96px', | ||
28: '112px', | ||
32: '128px', | ||
36: '144px', | ||
40: '160px', | ||
44: '176px', | ||
48: '192px', | ||
52: '208px', | ||
56: '224px', | ||
60: '240px', | ||
64: '256px', | ||
72: '288px', | ||
80: '320px', | ||
96: '384px', | ||
}, | ||
}, | ||
} satisfies TailwindConfig |
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,83 @@ | ||
import type { QueryGetJobsResult } from '@/lib/db/queries' | ||
import { Font, Head, Tailwind } from '@react-email/components' | ||
import { tailwindConfig } from './config/tailwind' | ||
import { mockJobsList } from './mock/jobs-list' | ||
|
||
const CompanyJobs = ({ | ||
company, | ||
jobs, | ||
}: { company: string; jobs: Awaited<QueryGetJobsResult>['data'] }) => ( | ||
<section className="bg-blue-50 pt-2 p-4 rounded-md"> | ||
<h3 className="mt-2 font-semibold mb-4">{company}</h3> | ||
{jobs.map(job => ( | ||
<article key={job.id} className="py-2 px-4 bg-white rounded-md"> | ||
<h4 className="my-2 font-semibold">{job.title}</h4> | ||
|
||
<p className="text-sm text-slate-500">{job.departments.join(', ')}</p> | ||
<p className="mb-4 text-sm">{job.location}</p> | ||
|
||
<a | ||
className="block mb-2 text-brand underline" | ||
href={job.url} | ||
target="_blank" | ||
rel="noreferrer" | ||
> | ||
More info ... | ||
</a> | ||
</article> | ||
))} | ||
</section> | ||
) | ||
|
||
const groupJobsByCompany = (jobs: Awaited<QueryGetJobsResult>['data']) => | ||
jobs.reduce( | ||
(acc, job) => { | ||
if (!acc[job.company.name]) { | ||
acc[job.company.name] = [] | ||
} | ||
|
||
acc[job.company.name].push(job) | ||
|
||
return acc | ||
}, | ||
{} as Record<string, Awaited<QueryGetJobsResult>['data']>, | ||
) | ||
|
||
const Jobs = ({ | ||
newJobs, | ||
savedJobs, | ||
}: { | ||
newJobs: Awaited<QueryGetJobsResult>['data'] | ||
savedJobs: Awaited<QueryGetJobsResult>['data'] | ||
}) => { | ||
const newJobsGrouped = groupJobsByCompany(newJobs || mockJobsList) | ||
const savedJobsGrouped = groupJobsByCompany(savedJobs || mockJobsList) | ||
|
||
return ( | ||
<Tailwind config={tailwindConfig}> | ||
<Head> | ||
<Font | ||
fontFamily="Work Sans" | ||
fallbackFontFamily="Helvetica" | ||
webFont={{ | ||
url: 'https://fonts.googleapis.com/css2?family=Work+Sans:wght@400;500;600&display=swap', | ||
format: 'opentype', | ||
}} | ||
/> | ||
</Head> | ||
<main className="md:container mx-auto"> | ||
<h2>✨ New Jobs</h2> | ||
{Object.entries(newJobsGrouped).map(([company, jobs]) => ( | ||
<CompanyJobs key={company} company={company} jobs={jobs} /> | ||
))} | ||
|
||
<h2>♥️ Saved Jobs</h2> | ||
{Object.entries(savedJobsGrouped).map(([company, jobs]) => ( | ||
<CompanyJobs key={company} company={company} jobs={jobs} /> | ||
))} | ||
</main> | ||
</Tailwind> | ||
) | ||
} | ||
|
||
export default Jobs |
Large diffs are not rendered by default.
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
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