Last active
July 16, 2020 13:27
-
-
Save mikaelhadler/d6748b590083b92f32e10dcfab09eb84 to your computer and use it in GitHub Desktop.
Nuxt.js problems mailchimp
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
import Head from 'next/head' | |
import { useState } from 'react'; | |
const Home = (props) => { | |
let [email, setEmail] = useState(''); | |
const handleChange = (event, set) => set(event.value) | |
const addSubscribe = async () => { | |
console.log('Aqui os metodos de mailchimp nao estao disponiveis: ', props); | |
// ele somente traz a referencia dos dados de __api_key e __base_url | |
mailchimp.post('/lists/id/members', { | |
method: 'POST', | |
body: JSON.stringify({ | |
email_address : email, | |
status : 'subscribed' | |
}) | |
}) | |
.then(function(results) { | |
console.log(results); | |
}) | |
.catch(function (err) { | |
console.log(err); | |
}) | |
event.preventDefault(); | |
} | |
return ( | |
<div className="container"> | |
<Head> | |
<title>Gabriel Silvestri</title> | |
<link rel="icon" href="/favicon.ico" /> | |
</Head> | |
<main> | |
<form onSubmit={addSubscribe}> | |
<div className="grid"> | |
<input type="email" value={email} onChange={(event) => handleChange(event.target, setEmail)}></input> | |
<button type="submit"> | |
Subscribe | |
</button> | |
</div> | |
</form> | |
</main> | |
<footer> | |
<a | |
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app" | |
target="_blank" | |
rel="noopener noreferrer" | |
> | |
Powered by{' '} | |
<img src="/vercel.svg" alt="Vercel Logo" className="logo" /> | |
</a> | |
</footer> | |
</div> | |
) | |
} | |
Home.getInitialProps = async () => { | |
let mailchimp = new (require('mailchimp-api-v3'))('c286b51c9c32893c5b32a683ea42f875-us10') | |
// Aqui os metodos de mailchimp estao disponiveis | |
// Ex: mailchimp.post, mailchimp.put | |
return { | |
mailchimp | |
} | |
} | |
export default Home |
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
module.exports = { | |
webpack (config, options) { | |
config.node = { | |
...config.node, | |
fs: 'empty', | |
net: 'empty', | |
tls: 'empty' | |
} | |
return config | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment