diff --git a/components/FormSuscribe.js b/components/FormSuscribe.js index e6fa081..2c3a187 100644 --- a/components/FormSuscribe.js +++ b/components/FormSuscribe.js @@ -2,9 +2,10 @@ import { useRef, useState } from 'react' import siteMetadata from '@/data/siteMetadata' -const FormSuscribe = () => { +const FormSubscribe = () => { const inputEl = useRef(null) const [message, setMessage] = useState('') + const [subscribed, setSubscribed] = useState(false) const subscribe = async (e) => { e.preventDefault() @@ -19,16 +20,14 @@ const FormSuscribe = () => { method: 'POST', }) - // console.log('resultat : ', res) const { error } = await res.json() - // console.log('error :', error) if (error) { - console.log('error 2 : ', error) - setMessage('You are already subscribed!') + setMessage('Your e-mail adress is invalid or you are already subscribed!') return } inputEl.current.value = '' + setSubscribed(true) setMessage('Successfully! 🎉 You are now subscribed.') } @@ -51,14 +50,16 @@ const FormSuscribe = () => { ref={inputEl} required type="email" + disabled={subscribed} />
@@ -69,4 +70,4 @@ const FormSuscribe = () => { ) } -export { FormSuscribe } +export { FormSubscribe } diff --git a/data/siteMetadata.js b/data/siteMetadata.js index a029049..112a028 100644 --- a/data/siteMetadata.js +++ b/data/siteMetadata.js @@ -23,13 +23,13 @@ const siteMetadata = { googleAnalyticsId: '', // e.g. UA-000000-2 or G-XXXXXXX }, newsletter: { - provider: 'buttondown', // supported providers: mailchimp + provider: 'mailchimp', // supported providers: mailchimp, buttondown mailChimpConfig: { apiKey: process.env.NEXT_PUBLIC_MAILCHIMP_API_KEY, apiServer: process.env.NEXT_PUBLIC_MAILCHIMP_API_SERVER, audienceId: process.env.NEXT_PUBLIC_MAILCHIMP_AUDIENCE_ID, }, - buttonDown: process.env.NEXT_PUBLIC_BUTTONDOWN, + buttondownConfig: process.env.NEXT_PUBLIC_BUTTONDOWN, }, comment: { // Select a provider and use the environment variables associated to it @@ -68,7 +68,7 @@ const siteMetadata = { // theme when dark mode darkTheme: '', }, - disqus: { + disqusConfig: { // https://help.disqus.com/en/articles/1717111-what-s-a-shortname shortname: process.env.NEXT_PUBLIC_DISQUS_SHORTNAME, }, diff --git a/package.json b/package.json index 30ddea6..77681bc 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,6 @@ "esbuild": "^0.12.15", "gray-matter": "^4.0.2", "image-size": "1.0.0", - "mailchimp": "^1.2.1", "mdx-bundler": "^6.0.1", "next": "11.1.0", "next-themes": "^0.0.14", diff --git a/pages/api/buttondown.js b/pages/api/buttondown.js index 16c1c10..8c007c9 100644 --- a/pages/api/buttondown.js +++ b/pages/api/buttondown.js @@ -2,14 +2,13 @@ export default async (req, res) => { const { email } = req.body + console.log('hello 1') if (!email) { return res.status(400).json({ error: 'Email is required' }) } try { const API_KEY = process.env.NEXT_PUBLIC_BUTTONDOWN - // console.log('Api key : ', API_KEY) - const response = await fetch(`https://api.buttondown.email/v1/subscribers`, { body: JSON.stringify({ email, @@ -20,12 +19,10 @@ export default async (req, res) => { }, method: 'POST', }) - - const badReponse = await response.json() - // console.log('response : ', await response.json()) + const responseMessage = await response.json() if (response.status >= 400) { - return badReponse + return res.status(500).json({ error: responseMessage[0] }) } return res.status(201).json({ error: '' }) diff --git a/pages/index.js b/pages/index.js index 424b2d3..6a0f5d8 100644 --- a/pages/index.js +++ b/pages/index.js @@ -5,7 +5,7 @@ import siteMetadata from '@/data/siteMetadata' import { getAllFilesFrontMatter } from '@/lib/mdx' import formatDate from '@/lib/utils/formatDate' -import { FormSuscribe } from '@/components/FormSuscribe' +import { FormSubscribe } from '@/components/FormSuscribe' const MAX_DISPLAY = 5 @@ -19,7 +19,7 @@ export default function Home({ posts }) { return ( <> - {siteMetadata.newsletter.provider !== '' && } + {siteMetadata.newsletter.provider !== '' && }