Last active
December 29, 2015 12:23
-
-
Save LuizMoreira/28b9d49920bc2b0c31df to your computer and use it in GitHub Desktop.
Error setState - lines 401-408
This file contains hidden or 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 { createHistory, useBasename } from 'history' | |
import { Router, Route, Link, History, Lifecycle } from 'react-router' | |
import classNames from 'classnames'; | |
import SidebarMixin from 'global/jsx/sidebar_component'; | |
import Header from 'common/header'; | |
import Sidebar from 'common/sidebar'; | |
import Footer from 'common/footer'; | |
import Helpers from '../util/Helpers'; | |
import auth from '../util/auth' | |
var Body = React.createClass({ | |
mixins: [ History ], | |
// statics: { | |
// willTransitionTo: function(transition){ | |
// console.log('atualizaCliente willTransitionTo -->'+ transition); | |
// if(!auth.loggedIn()){ | |
// transition.redirect('/app/login'); | |
// } | |
// } | |
// }, | |
propTypes:{ | |
callBackLogin: React.PropTypes.func.isRequired | |
}, | |
getInitialState: function(){ | |
console.log('login - getInitialState '); | |
return { | |
cliente:{}, | |
returnStatus:{}, | |
loggedIn: auth.loggedIn(), | |
error: false | |
}; | |
}, | |
updateAuth(loggedIn) { | |
this.setState({ | |
loggedIn: loggedIn | |
}) | |
}, | |
callBackLogin:function(){ | |
this.props.callBackLogin(this.state.cliente); | |
}, | |
//login pixma | |
submitPixma: function(e) { | |
e.preventDefault(); | |
e.stopPropagation(); | |
if($('#form').valid()){ | |
self = this | |
console.log('React.getDOMNode(this.refs.email).value = ' +React.findDOMNode(this.refs.email).value); | |
console.log('React.getDOMNode(this.refs.senha).value = ' +React.findDOMNode(this.refs.senha).value); | |
var data = { | |
email: React.findDOMNode(this.refs.email).value, | |
senha: React.findDOMNode(this.refs.senha).value | |
} | |
Helpers.Post('/cliente/autentica', data, this.success, this.error) | |
} | |
}, | |
//retorno de sucesso do Helpers | |
success: function (result) { | |
console.log('++++++ logou!!! ++++' + result.dataObject.codigo) | |
if(this.isMounted()){ | |
this.setState({ | |
cliente: result.dataObject, | |
resultStatus: result.resultStatus | |
}); | |
console.log('STATE CLIENTE'+ this.state.cliente.nome); | |
this.callBackLogin(); | |
auth.login(this.state.cliente.email, React.findDOMNode(this.refs.senha).value , (loggedIn) => { | |
if (loggedIn){ | |
console.log('LOGIN COOKIE --> PASSOU -->'+ loggedIn); | |
if(!result.returnStatus.isError){ | |
//https://github.com/rackt/react-router/blob/latest/examples/transitions/app.js | |
this.history.pushState(null, '/app/atualizaCliente'); | |
} | |
} | |
}) | |
} | |
}, | |
//retorno de erro do Helpers | |
error: function (xhr, textStatus, errorThrown) { | |
React.findDOMNode(this.refs.senha).value= ''; | |
vex.dialog.alert(xhr.returnStatus.description); | |
}, | |
clearForm: function() { | |
this.setState({ | |
cliente: {}, | |
resultStatus: {}, | |
email: "", | |
senha: "" | |
}); | |
}, | |
submitTwitter: function(e) { | |
e.preventDefault(); | |
if($('#form').valid()){ | |
e.stopPropagation(); | |
this.transitionTo('/app/wizard'); | |
} | |
}, | |
submitFacebook: function(e) { | |
e.preventDefault(); | |
if($('#form').valid()){ | |
e.stopPropagation(); | |
this.transitionTo('/app/wizard'); | |
} | |
}, | |
componentDidMount: function() { | |
$('html').addClass('authentication'); | |
$('#form').validate({ | |
rules: { | |
txtEmail: { | |
required: true, | |
email: true | |
}, | |
txtSenha: { | |
required: true, | |
minlength:6 | |
} | |
}, | |
messages: { | |
txtEmail: { | |
required: "Email é obrigatório", | |
email: "Email ta errado....", | |
remote: 'email já existente' | |
}, | |
txtSenha: { | |
required: "Senha é um campo obrigatório", | |
minlength: "É necessário informar ao menos 6 caracteres para o campo senha." | |
} | |
}, | |
highlight: function(element) { | |
$(element).closest('.form-group').addClass('has-error'); | |
}, | |
unhighlight: function(element) { | |
$(element).closest('.form-group').removeClass('has-error'); | |
}, | |
errorElement: 'span', | |
errorClass: 'help-block', | |
errorPlacement: function(error, element) { | |
if(element.parent('.input-group').length) { | |
error.insertAfter(element.parent()); | |
} else { | |
error.insertAfter(element); | |
} | |
} | |
}); | |
}, | |
componentWillUnmount: function() { | |
$('html').removeClass('authentication'); | |
}, | |
render: function() { | |
return ( | |
<Container id='auth-container' className='login'> | |
<Container id='auth-row'> | |
<Container id='auth-cell'> | |
<Grid> | |
<Row> | |
<Col sm={12}> | |
<PanelContainer noControls> | |
<Panel> | |
<PanelBody style={{padding: 0}}> | |
<div className='text-center bg-darkblue fg-white'> | |
<h3 style={{margin: 0, padding: 25}}>Logar no <img src='/imgs/logo.png' alt='Pixma' width='111' height='28' /></h3> | |
</div> | |
<div className='bg-hoverblue fg-black50 text-center' style={{padding: 12.5}}> | |
<div>Você precisa logar para obter orçamento</div> | |
<div style={{marginTop: 12.5, marginBottom: 12.5}}> | |
<Button id='facebook-btn' lg bsStyle='darkblue' type='submit' onClick={this.back}> | |
<Icon glyph='icon-fontello-facebook' /> | |
<span>Logar <span className='hidden-xs'>com facebook</span></span> | |
</Button> | |
</div> | |
<div> | |
<a id='twitter-link' href='#' onClick={this.submitPixma}><Icon glyph='icon-fontello-twitter' /><span> ou com twitter</span></a> | |
</div> | |
</div> | |
<div> | |
<div className='text-center' style={{padding: 12.5}}> | |
ou use sua conta no Pixma | |
</div> | |
<div style={{padding: 25, paddingTop: 0, paddingBottom: 0, margin: 'auto', marginBottom: 25, marginTop: 25}}> | |
<Form id='form' onSubmit={this.submitPixma} > | |
<FormGroup> | |
<InputGroup lg> | |
<InputGroupAddon> | |
<Icon glyph='icon-fontello-mail' /> | |
</InputGroupAddon> | |
<Input autoFocus type='email' id='txtEmail' name='txtEmail' ref='email' className='border-focus-blue' placeholder='[email protected]' /> | |
</InputGroup> | |
</FormGroup> | |
<FormGroup> | |
<InputGroup lg> | |
<InputGroupAddon> | |
<Icon glyph='icon-fontello-key' /> | |
</InputGroupAddon> | |
<Input type='password' id='txtSenha' name='txtSenha' ref='senha' className='border-focus-blue' placeholder='password' /> | |
</InputGroup> | |
</FormGroup> | |
<FormGroup> | |
<Grid> | |
<Row> | |
<Col xs={6} collapseLeft collapseRight style={{paddingTop: 10}}> | |
<Link to='/app/signup'>Criar uma conta Pixma</Link> | |
</Col> | |
<Col xs={6} collapseLeft collapseRight className='text-right'> | |
<Button outlined lg type='submit' bsStyle='blue' onClick={this.submitPixma} >Logar</Button> | |
</Col> | |
</Row> | |
</Grid> | |
</FormGroup> | |
</Form> | |
</div> | |
</div> | |
</PanelBody> | |
</Panel> | |
</PanelContainer> | |
</Col> | |
</Row> | |
</Grid> | |
</Container> | |
</Container> | |
</Container> | |
); | |
} | |
}); | |
@SidebarMixin | |
export default class extends React.Component { | |
// static propTypes : { | |
// cliente: React.PropTypes.object.isRequired | |
// } | |
constructor(props) { | |
super(props); | |
this.state = { | |
cliente: {} | |
}; | |
} | |
didObterLogin(clienteLogin){ | |
console.log('didObterLogin --'+clienteLogin.nome); | |
this.setState({ | |
cliente: clienteLogin | |
}); | |
} | |
componentWillUnmount () { | |
//console.log('login mesmo --'+props.cliente); | |
console.log('componentWillUnmount --'+this.state.cliente.nome); | |
} | |
render() { | |
var classes = classNames({ | |
'container-open': this.props.open | |
}); | |
return ( | |
<Container id='container' className={classes}> | |
<Sidebar/> | |
<Header /> | |
<Body callBackLogin={this.didObterLogin.bind(this)} /> | |
<Footer /> | |
</Container> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment