diff --git a/app/(frontend)/not-found.tsx b/app/(frontend)/not-found.tsx
index 6e7d603..2786575 100644
--- a/app/(frontend)/not-found.tsx
+++ b/app/(frontend)/not-found.tsx
@@ -11,7 +11,7 @@ export default function NotFound() {
href="/"
className="inline-flex items-center gap-2 px-4 py-2 mt-4 text-xs font-bold text-white uppercase transition-colors bg-red-600 rounded-full w-max hover:bg-red-700"
>
- Return Home
Check-in Opens
-Doors Open
diff --git a/app/(frontend)/renaissance/speakers/page.tsx b/app/(frontend)/renaissance/speakers/page.tsx index f81c71f..540e0db 100644 --- a/app/(frontend)/renaissance/speakers/page.tsx +++ b/app/(frontend)/renaissance/speakers/page.tsx @@ -1,4 +1,5 @@ import { ArrowRightIcon } from 'lucide-react' +import { Metadata } from 'next' import Image, { StaticImageData } from 'next/image' import Link from 'next/link' import { Fragment } from 'react' diff --git a/app/api/subscribe/subscribe.ts b/app/api/subscribe/subscribe.ts new file mode 100644 index 0000000..44775a1 --- /dev/null +++ b/app/api/subscribe/subscribe.ts @@ -0,0 +1,45 @@ +// pages/api/subscribe.ts +import type { NextApiRequest, NextApiResponse } from 'next'; +import mailchimp from '@mailchimp/mailchimp_marketing'; + +mailchimp.setConfig({ + apiKey: process.env.MAILCHIMP_API_KEY, + server: process.env.MAILCHIMP_SERVER_PREFIX, +}); + +async function subscribe(email: string) { + try { + const response = await mailchimp.lists.addListMember(process.env.MAILCHIMP_LIST_ID, { + email_address: email, + status: "pending", // Use "subscribed" for no double opt-in + }); + return response; + } catch (error) { + throw error; + } +} + +export default async function handler(req: NextApiRequest, res: NextApiResponse) { + if (req.method === 'POST') { + const { email_address } = req.body; + + if (!email_address) { + return res.status(400).json({ error: 'Email address is required' }); + } + + try { + const response = await subscribe(email_address); + res.status(200).json({ status: 'success', data: response }); + } catch (error) { + // Log detailed error for server-side debugging + console.error(error); + + // Send generic error message to client + res.status(500).json({ status: 'error', message: 'Failed to subscribe, please try again.' }); + } + } else { + // If not a POST request, indicate allowed method + res.setHeader('Allow', ['POST']); + res.status(405).end('Method ${req.method} Not Allowed'); + } +} \ No newline at end of file diff --git a/app/mailinglist.ts b/app/mailinglist.ts new file mode 100644 index 0000000..eb02598 --- /dev/null +++ b/app/mailinglist.ts @@ -0,0 +1,30 @@ +// mailingList.ts + +import { z } from 'zod'; +import { subscribeToMailingListService } from '@/components/services/MailingListService'; + +export async function subscribeToMailingList(formData: FormData) { + const schema = z.object({ + email: z.string().email(), + }); + + const validatedFields = schema.safeParse({ + email: formData.get('email'), + }); + + if (!validatedFields.success) { + return { + message: 'Failed to subscribe to newsletter', + errors: validatedFields.error.flatten().fieldErrors, + }; + } + + const { email } = validatedFields.data; + + try { + await subscribeToMailingListService(email); + return { message: 'Subscribed to newsletter!', success: true }; + } catch (error) { + return { message: 'Failed to subscribe to newsletter' }; + } +} diff --git a/app/not-found.tsx b/app/not-found.tsx index da7aaa7..c9e95f7 100644 --- a/app/not-found.tsx +++ b/app/not-found.tsx @@ -11,7 +11,7 @@ export default function NotFound() { href="/" className="inline-flex items-center gap-2 px-4 py-2 mt-4 text-xs font-bold text-white uppercase transition-colors bg-red-600 rounded-full w-max hover:bg-red-700" > - Return Home© {year} TEDxNortheasternU · All Rights Reserved
diff --git a/components/global/Footer/mail-signup.tsx b/components/global/Footer/mail-signup.tsx new file mode 100644 index 0000000..35a959e --- /dev/null +++ b/components/global/Footer/mail-signup.tsx @@ -0,0 +1,87 @@ +'use client' + +import React, { FormEvent, useState } from 'react' +const mailchimp = require('@mailchimp/mailchimp_marketing') + +mailchimp.setConfig({ + apiKey: process.env.MAILCHIMP_API_KEY, + server: 'us17', +}) + +interface EmailState { + email: string + subscriptionResponse: string + error: boolean +} + +const NewsLetterSignUpForm: React.FC = () => { + const [email, setEmail] = useState+ TEDxNortheasternU was created in the spirit of TED’s mission of ideas + worth spreading to the Northeastern University community. Subscribe to + learn more about our xLabs, fundraisers, and Spring conference. +
+