upstream #1
@ -2,9 +2,10 @@ import { useRef, useState } from 'react'
|
|||||||
|
|
||||||
import siteMetadata from '@/data/siteMetadata'
|
import siteMetadata from '@/data/siteMetadata'
|
||||||
|
|
||||||
const FormSuscribe = () => {
|
const FormSubscribe = () => {
|
||||||
const inputEl = useRef(null)
|
const inputEl = useRef(null)
|
||||||
const [message, setMessage] = useState('')
|
const [message, setMessage] = useState('')
|
||||||
|
const [subscribed, setSubscribed] = useState(false)
|
||||||
|
|
||||||
const subscribe = async (e) => {
|
const subscribe = async (e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@ -19,16 +20,14 @@ const FormSuscribe = () => {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
})
|
})
|
||||||
|
|
||||||
// console.log('resultat : ', res)
|
|
||||||
const { error } = await res.json()
|
const { error } = await res.json()
|
||||||
// console.log('error :', error)
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log('error 2 : ', error)
|
setMessage('Your e-mail adress is invalid or you are already subscribed!')
|
||||||
setMessage('You are already subscribed!')
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
inputEl.current.value = ''
|
inputEl.current.value = ''
|
||||||
|
setSubscribed(true)
|
||||||
setMessage('Successfully! 🎉 You are now subscribed.')
|
setMessage('Successfully! 🎉 You are now subscribed.')
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,14 +50,16 @@ const FormSuscribe = () => {
|
|||||||
ref={inputEl}
|
ref={inputEl}
|
||||||
required
|
required
|
||||||
type="email"
|
type="email"
|
||||||
|
disabled={subscribed}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-2 flex-shrink-0 w-full flex rounded-md shadow-sm sm:mt-0 sm:ml-3 sm:w-auto sm:inline-flex">
|
<div className="mt-2 flex-shrink-0 w-full flex rounded-md shadow-sm sm:mt-0 sm:ml-3 sm:w-auto sm:inline-flex">
|
||||||
<button
|
<button
|
||||||
className="w-full bg-primary-500 dark:bg-primary-400 px-4 py-2 border border-transparent rounded-md flex items-center justify-center text-base font-medium text-white hover:bg-primary-700 dark:hover:bg-primary-300 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:primary-700 sm:w-auto sm:inline-flex"
|
className="w-full bg-primary-500 dark:bg-primary-400 px-4 py-2 border border-transparent rounded-md flex items-center justify-center text-base font-medium text-white hover:bg-primary-700 dark:hover:bg-primary-300 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:primary-700 sm:w-auto sm:inline-flex"
|
||||||
type="submit"
|
type="submit"
|
||||||
|
disabled={subscribed}
|
||||||
>
|
>
|
||||||
{message ? 'Thank you!' : 'Sign up'}
|
{subscribed ? 'Thank you!' : 'Sign up'}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@ -69,4 +70,4 @@ const FormSuscribe = () => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export { FormSuscribe }
|
export { FormSubscribe }
|
||||||
|
@ -23,13 +23,13 @@ const siteMetadata = {
|
|||||||
googleAnalyticsId: '', // e.g. UA-000000-2 or G-XXXXXXX
|
googleAnalyticsId: '', // e.g. UA-000000-2 or G-XXXXXXX
|
||||||
},
|
},
|
||||||
newsletter: {
|
newsletter: {
|
||||||
provider: 'buttondown', // supported providers: mailchimp
|
provider: 'mailchimp', // supported providers: mailchimp, buttondown
|
||||||
mailChimpConfig: {
|
mailChimpConfig: {
|
||||||
apiKey: process.env.NEXT_PUBLIC_MAILCHIMP_API_KEY,
|
apiKey: process.env.NEXT_PUBLIC_MAILCHIMP_API_KEY,
|
||||||
apiServer: process.env.NEXT_PUBLIC_MAILCHIMP_API_SERVER,
|
apiServer: process.env.NEXT_PUBLIC_MAILCHIMP_API_SERVER,
|
||||||
audienceId: process.env.NEXT_PUBLIC_MAILCHIMP_AUDIENCE_ID,
|
audienceId: process.env.NEXT_PUBLIC_MAILCHIMP_AUDIENCE_ID,
|
||||||
},
|
},
|
||||||
buttonDown: process.env.NEXT_PUBLIC_BUTTONDOWN,
|
buttondownConfig: process.env.NEXT_PUBLIC_BUTTONDOWN,
|
||||||
},
|
},
|
||||||
comment: {
|
comment: {
|
||||||
// Select a provider and use the environment variables associated to it
|
// Select a provider and use the environment variables associated to it
|
||||||
@ -68,7 +68,7 @@ const siteMetadata = {
|
|||||||
// theme when dark mode
|
// theme when dark mode
|
||||||
darkTheme: '',
|
darkTheme: '',
|
||||||
},
|
},
|
||||||
disqus: {
|
disqusConfig: {
|
||||||
// https://help.disqus.com/en/articles/1717111-what-s-a-shortname
|
// https://help.disqus.com/en/articles/1717111-what-s-a-shortname
|
||||||
shortname: process.env.NEXT_PUBLIC_DISQUS_SHORTNAME,
|
shortname: process.env.NEXT_PUBLIC_DISQUS_SHORTNAME,
|
||||||
},
|
},
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
"esbuild": "^0.12.15",
|
"esbuild": "^0.12.15",
|
||||||
"gray-matter": "^4.0.2",
|
"gray-matter": "^4.0.2",
|
||||||
"image-size": "1.0.0",
|
"image-size": "1.0.0",
|
||||||
"mailchimp": "^1.2.1",
|
|
||||||
"mdx-bundler": "^6.0.1",
|
"mdx-bundler": "^6.0.1",
|
||||||
"next": "11.1.0",
|
"next": "11.1.0",
|
||||||
"next-themes": "^0.0.14",
|
"next-themes": "^0.0.14",
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const { email } = req.body
|
const { email } = req.body
|
||||||
|
|
||||||
|
console.log('hello 1')
|
||||||
if (!email) {
|
if (!email) {
|
||||||
return res.status(400).json({ error: 'Email is required' })
|
return res.status(400).json({ error: 'Email is required' })
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const API_KEY = process.env.NEXT_PUBLIC_BUTTONDOWN
|
const API_KEY = process.env.NEXT_PUBLIC_BUTTONDOWN
|
||||||
// console.log('Api key : ', API_KEY)
|
|
||||||
|
|
||||||
const response = await fetch(`https://api.buttondown.email/v1/subscribers`, {
|
const response = await fetch(`https://api.buttondown.email/v1/subscribers`, {
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
email,
|
email,
|
||||||
@ -20,12 +19,10 @@ export default async (req, res) => {
|
|||||||
},
|
},
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
})
|
})
|
||||||
|
const responseMessage = await response.json()
|
||||||
const badReponse = await response.json()
|
|
||||||
// console.log('response : ', await response.json())
|
|
||||||
|
|
||||||
if (response.status >= 400) {
|
if (response.status >= 400) {
|
||||||
return badReponse
|
return res.status(500).json({ error: responseMessage[0] })
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.status(201).json({ error: '' })
|
return res.status(201).json({ error: '' })
|
||||||
|
@ -5,7 +5,7 @@ import siteMetadata from '@/data/siteMetadata'
|
|||||||
import { getAllFilesFrontMatter } from '@/lib/mdx'
|
import { getAllFilesFrontMatter } from '@/lib/mdx'
|
||||||
import formatDate from '@/lib/utils/formatDate'
|
import formatDate from '@/lib/utils/formatDate'
|
||||||
|
|
||||||
import { FormSuscribe } from '@/components/FormSuscribe'
|
import { FormSubscribe } from '@/components/FormSuscribe'
|
||||||
|
|
||||||
const MAX_DISPLAY = 5
|
const MAX_DISPLAY = 5
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ export default function Home({ posts }) {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PageSEO title={siteMetadata.title} description={siteMetadata.description} />
|
<PageSEO title={siteMetadata.title} description={siteMetadata.description} />
|
||||||
{siteMetadata.newsletter.provider !== '' && <FormSuscribe />}
|
{siteMetadata.newsletter.provider !== '' && <FormSubscribe />}
|
||||||
<div className="divide-y divide-gray-200 dark:divide-gray-700">
|
<div className="divide-y divide-gray-200 dark:divide-gray-700">
|
||||||
<div className="pt-6 pb-8 space-y-2 md:space-y-5">
|
<div className="pt-6 pb-8 space-y-2 md:space-y-5">
|
||||||
<h1 className="text-3xl font-extrabold leading-9 tracking-tight text-gray-900 dark:text-gray-100 sm:text-4xl sm:leading-10 md:text-6xl md:leading-14">
|
<h1 className="text-3xl font-extrabold leading-9 tracking-tight text-gray-900 dark:text-gray-100 sm:text-4xl sm:leading-10 md:text-6xl md:leading-14">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user