-
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
af9b29a
commit 4e900d6
Showing
15 changed files
with
141 additions
and
742 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
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,64 @@ | ||
import { Container } from '~/routes/_marketing+/ui+/components/layout/container.tsx' | ||
import { Resend } from 'resend' | ||
import { json, type ActionArgs } from '@remix-run/node' | ||
import { parse } from '@conform-to/zod' | ||
import { z } from 'zod' | ||
import { emailSchema } from '~/utils/user-validation.ts' | ||
import { Newsletter as NewsletterComponent } from '~/components/newsletter.tsx' | ||
import { validateCSRF } from '~/utils/csrf.server.ts' | ||
import { checkHoneypot } from '~/utils/honeypot.server.ts' | ||
|
||
export default function Newsletter() { | ||
return ( | ||
<Container> | ||
<NewsletterComponent | ||
className="mt-32 sm:mt-44" | ||
title="Get exclusive web dev tips that I only share with email subscribers" | ||
description="Golden nuggets of code knowledge you can read in 5 minutes. Delivered to your inbox every 2 weeks." | ||
buttonText="I want my tips" | ||
/> | ||
</Container> | ||
) | ||
} | ||
|
||
export const newsletterEmailQueryParam = 'email' | ||
export const newsletterOTPQueryParam = 'code' | ||
export const newsletterVerificationType = 'newsletter' | ||
|
||
export const newsletterSchema = z.object({ | ||
email: emailSchema, | ||
}) | ||
|
||
export async function action({ request }: ActionArgs) { | ||
const formData = await request.formData() | ||
|
||
// Check for bots | ||
await validateCSRF(formData, request.headers) | ||
checkHoneypot(formData, '/newsletter') | ||
|
||
// Parse form | ||
const submission = parse(formData, { schema: newsletterSchema }) | ||
if (submission.intent !== 'submit') { | ||
return json({ status: 'error', submission } as const) | ||
} | ||
if (!submission.value) { | ||
return json({ status: 'error', submission } as const, { status: 400 }) | ||
} | ||
|
||
// Extract data | ||
const { email } = submission.value | ||
|
||
// Subscribe to newsletter | ||
const resend = new Resend(process.env.RESEND_API_KEY) | ||
const result = await resend.contacts.create({ | ||
email, | ||
unsubscribed: false, | ||
audienceId: process.env.RESEND_GENERAL_AUDIENCE, | ||
}) | ||
if (result.error) { | ||
return json({ status: 'error', submission } as const, { status: 400 }) | ||
} | ||
|
||
// Everything ok | ||
return json({ status: 'success', submission } as const) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.