File tree 6 files changed +70
-27
lines changed
6 files changed +70
-27
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,16 @@ NEXT_PUBLIC_GISCUS_CATEGORY=
4
4
NEXT_PUBLIC_GISCUS_CATEGORY_ID =
5
5
NEXT_PUBLIC_UTTERANCES_REPO =
6
6
NEXT_PUBLIC_DISQUS_SHORTNAME =
7
- NEXT_PUBLIC_MAILCHIMP_API_KEY =
8
- NEXT_PUBLIC_MAILCHIMP_API_SERVER =
9
- NEXT_PUBLIC_MAILCHIMP_AUDIENCE_ID =
10
- NEXT_PUBLIC_BUTTONDOWN =
7
+
8
+
9
+ MAILCHIMP_API_KEY =
10
+ MAILCHIMP_API_SERVER =
11
+ MAILCHIMP_AUDIENCE_ID =
12
+
13
+ BUTTONDOWN_API_URL = https://api.buttondown.email/v1/
14
+ BUTTONDOWN_API_KEY =
15
+
16
+ CONVERTKIT_API_URL = https://api.convertkit.com/v3/
17
+ CONVERTKIT_API_KEY =
18
+ CONVERTKIT_TIPS_FORM_ID =
19
+ CONVERTKIT_MONTHLY_FORM_ID =
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ const FormSubscribe = () => {
46
46
className = "appearance-none w-full px-4 py-2 border border-neutrals-cool-grey-300 text-base rounded-md text-neutrals-cool-grey-900 bg-white dark:bg-black placeholder-gray-500 focus:outline-none focus:ring-primary-400 dark:focus:border-primary-600 lg:max-w-xs"
47
47
id = "email-input"
48
48
name = "email"
49
- placeholder = " Enter your email"
49
+ placeholder = { subscribed ? "You're subscribed !" : ' Enter your email' }
50
50
ref = { inputEl }
51
51
required
52
52
type = "email"
Original file line number Diff line number Diff line change @@ -23,13 +23,9 @@ const siteMetadata = {
23
23
googleAnalyticsId : '' , // e.g. UA-000000-2 or G-XXXXXXX
24
24
} ,
25
25
newsletter : {
26
- provider : 'mailchimp' , // supported providers: mailchimp, buttondown
27
- mailChimpConfig : {
28
- apiKey : process . env . NEXT_PUBLIC_MAILCHIMP_API_KEY ,
29
- apiServer : process . env . NEXT_PUBLIC_MAILCHIMP_API_SERVER ,
30
- audienceId : process . env . NEXT_PUBLIC_MAILCHIMP_AUDIENCE_ID ,
31
- } ,
32
- buttondownConfig : process . env . NEXT_PUBLIC_BUTTONDOWN ,
26
+ // supports mailchimp, buttondown, convertkit
27
+ // Please add your .env file and modify it according to your selection
28
+ provider : 'mailchimp' ,
33
29
} ,
34
30
comment : {
35
31
// Select a provider and use the environment variables associated to it
Original file line number Diff line number Diff line change 1
1
// eslint-disable-next-line import/no-anonymous-default-export
2
2
export default async ( req , res ) => {
3
3
const { email } = req . body
4
-
5
- console . log ( 'hello 1' )
6
4
if ( ! email ) {
7
5
return res . status ( 400 ) . json ( { error : 'Email is required' } )
8
6
}
9
7
10
8
try {
11
- const API_KEY = process . env . NEXT_PUBLIC_BUTTONDOWN
12
- const response = await fetch ( `https://api.buttondown.email/v1/subscribers` , {
9
+ const API_KEY = process . env . BUTTONDOWN_API_KEY
10
+ const buttondownRoute = `${ process . env . BUTTONDOWN_API_URL } subscribers`
11
+ console . log ( 'route : ' , buttondownRoute )
12
+ const response = await fetch ( buttondownRoute , {
13
13
body : JSON . stringify ( {
14
14
email,
15
15
} ) ,
@@ -19,10 +19,9 @@ export default async (req, res) => {
19
19
} ,
20
20
method : 'POST' ,
21
21
} )
22
- const responseMessage = await response . json ( )
23
22
24
23
if ( response . status >= 400 ) {
25
- return res . status ( 500 ) . json ( { error : responseMessage [ 0 ] } )
24
+ return res . status ( 500 ) . json ( { error : `There was an error subscribing to the list.` } )
26
25
}
27
26
28
27
return res . status ( 201 ) . json ( { error : '' } )
Original file line number Diff line number Diff line change
1
+ /* eslint-disable import/no-anonymous-default-export */
2
+ export default async ( req , res ) => {
3
+ const { email, list } = req . query
4
+
5
+ if ( ! email ) {
6
+ return res . status ( 400 ) . json ( { error : 'Email is required' } )
7
+ }
8
+
9
+ if ( ! list ) {
10
+ return res . status ( 400 ) . json ( { error : 'List is required' } )
11
+ }
12
+
13
+ try {
14
+ const FORM_ID =
15
+ list === '12-tips-production-apps'
16
+ ? process . env . CONVERTKIT_TIPS_FORM_ID
17
+ : process . env . CONVERTKIT_MONTHLY_FORM_ID
18
+ const API_KEY = process . env . CONVERTKIT_API_KEY
19
+ const API_URL = process . env . CONVERTKIT_API_URL
20
+
21
+ // Send request to ConvertKit
22
+ const data = { email, api_key : API_KEY }
23
+
24
+ const response = await fetch ( `${ API_URL } forms/${ FORM_ID } /subscribe` , {
25
+ body : JSON . stringify ( data ) ,
26
+ headers : {
27
+ 'Content-Type' : 'application/json' ,
28
+ } ,
29
+ method : 'POST' ,
30
+ } )
31
+
32
+ if ( response . status >= 400 ) {
33
+ return res . status ( 400 ) . json ( {
34
+ error : `There was an error subscribing to the list.` ,
35
+ } )
36
+ }
37
+
38
+ return res . status ( 201 ) . json ( { error : '' } )
39
+ } catch ( error ) {
40
+ return res . status ( 500 ) . json ( { error : error . message || error . toString ( ) } )
41
+ }
42
+ }
Original file line number Diff line number Diff line change 1
1
import mailchimp from '@mailchimp/mailchimp_marketing'
2
2
3
3
mailchimp . setConfig ( {
4
- apiKey : process . env . NEXT_PUBLIC_MAILCHIMP_API_KEY ,
5
- server : process . env . NEXT_PUBLIC_MAILCHIMP_API_SERVER , // E.g. us1
4
+ apiKey : process . env . MAILCHIMP_API_KEY ,
5
+ server : process . env . MAILCHIMP_API_SERVER , // E.g. us1
6
6
} )
7
7
8
8
// eslint-disable-next-line import/no-anonymous-default-export
@@ -14,13 +14,10 @@ export default async (req, res) => {
14
14
}
15
15
16
16
try {
17
- const test = await mailchimp . lists . addListMember (
18
- process . env . NEXT_PUBLIC_MAILCHIMP_AUDIENCE_ID ,
19
- {
20
- email_address : email ,
21
- status : 'subscribed' ,
22
- }
23
- )
17
+ const test = await mailchimp . lists . addListMember ( process . env . MAILCHIMP_AUDIENCE_ID , {
18
+ email_address : email ,
19
+ status : 'subscribed' ,
20
+ } )
24
21
return res . status ( 201 ) . json ( { error : '' } )
25
22
} catch ( error ) {
26
23
return res . status ( 500 ) . json ( { error : error . message || error . toString ( ) } )
You can’t perform that action at this time.
0 commit comments