-
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.
* feat: addToMailList from API Route * feat: email submit form * feat: mailgun integration * feat: toasts
- Loading branch information
Showing
10 changed files
with
289 additions
and
3 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 |
---|---|---|
|
@@ -34,3 +34,5 @@ yarn-error.log* | |
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts | ||
|
||
.env |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,24 @@ | ||
import { postRequest } from '@/utils/axios'; | ||
import { toast } from 'react-toastify'; | ||
|
||
const useAddMailList = () => { | ||
const addEmailToList = async (email: string) => { | ||
try { | ||
await postRequest('/joinMailList', { | ||
email, | ||
}); | ||
|
||
toast.success('Successfully Subscribed!', { | ||
position: 'top-right', | ||
}); | ||
} catch (error) { | ||
toast.error('Something went Wrong!', { | ||
position: 'top-right', | ||
}); | ||
} | ||
}; | ||
|
||
return { addEmailToList }; | ||
}; | ||
|
||
export default useAddMailList; |
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,16 @@ | ||
import formData from 'form-data'; | ||
import Mailgun from 'mailgun.js'; | ||
|
||
const mailgun = new Mailgun(formData); | ||
const mailListAddress = process.env.MAILGUN_MAILLIST || 'dummy'; | ||
|
||
const mg = mailgun.client({ | ||
username: 'API', | ||
key: process.env.MAILGUN_API_KEY || 'dummy', | ||
}); | ||
|
||
export const addToMailList = async (email: string) => { | ||
await mg.lists.members.createMember(mailListAddress, { | ||
address: email, | ||
}); | ||
}; |
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,26 @@ | ||
import type { NextApiRequest, NextApiResponse } from 'next'; | ||
|
||
import { addToMailList } from '@/libs/mailgun'; | ||
|
||
type ResponseData = { | ||
message: string; | ||
}; | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse<ResponseData>, | ||
) { | ||
try { | ||
const { email } = req.body; | ||
|
||
if (!email) { | ||
throw new Error('Missing Email'); | ||
} | ||
|
||
await addToMailList(email); | ||
res.status(200).json({ message: 'Thanks for Joining my Mail List!' }); | ||
} catch (error) { | ||
console.error(error); | ||
res.status(500).json({ message: '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,7 @@ | ||
import * as yup from 'yup'; | ||
|
||
export const mailListSchema = yup.object({ | ||
email: yup.string().trim().email().required(), | ||
}); | ||
|
||
export type MailListInputs = yup.InferType<typeof mailListSchema>; |
Oops, something went wrong.