Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
'use strict';var _createClass=function(){function a(b,c){for(var f,d=0;d<c.length;d++)f=c[d],f.enumerable=f.enumerable||!1,f.configurable=!0,'value'in f&&(f.writable=!0),Object.defineProperty(b,f.key,f)}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}();function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError('Cannot call a class as a function')}function _possibleConstructorReturn(a,b){if(!a)throw new ReferenceError('this hasn\'t been initialised - super() hasn\'t been called');return b&&('object'==typeof b||'function'==typeof b)?b:a}function _inherits(a,b){if('function'!=typeof b&&null!==b)throw new TypeError('Super expression must either be null or a function, not '+typeof b);a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),b&&(Object.setPrototypeOf?Object.setPrototypeOf(a,b):a.__proto__=b)}var Form=function(a){function b(){var n,h,j,k;_classCallCheck(this,b);for(var l=arguments.length,g=Array(l),m=0;m<l;m++)g[m]=arguments[m];return k=(h=(j=_possibleConstructorReturn(this,(n=b.__proto__||Object.getPrototypeOf(b)).call.apply(n,[this].concat(g))),j),j.state={email:'',error:'',isValid:!1},j.handleSubmit=function(o){o.preventDefault();var p=j.state.email;if(console.log(p),!validator.isEmail(p))j.setState({error:'Veuillez entrer un e-mail correct.'});else{console.log('fetch'),fetch('<mautic url>',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded;charset=UTF-8'},body:'mauticform[email]='+p+'&mauticform[formId]=1'});j.setState({isValid:!0,successMessage:'Vous avez souscrit avec succ\xE8s au Blog de ston3o avec l\'adresse e-mail '+p+'.',email:''})}},h),_possibleConstructorReturn(j,k)}return _inherits(b,a),_createClass(b,[{key:'render',value:function render(){var l=this,g=this.state.email,h=this.state.isValid,j=this.state.error,k=this.state.successMessage;return React.createElement('div',null,React.createElement('form',null,React.createElement('div',{'class':'form-group'},React.createElement('input',{'class':'subscribe-email',type:'email',name:'email',value:g,onChange:function onChange(m){return l.setState({email:m.target.value,error:''})},placeholder:'Entrer votre email'})),React.createElement('button',{onClick:this.handleSubmit},React.createElement('span',null,'Me suivre'))),j&&React.createElement('p',{style:{color:'red'}},j),h&&React.createElement('p',{style:{color:'green'}},k))}}]),b}(React.Component);ReactDOM.render(React.createElement(Form,null),document.getElementById('form'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.