package react.user; import react.ReactDOM; import react.ReactComponent; import react.ReactMacro.jsx; typedef RegisterBoxState = {firstName:String, lastName:String, email:String, password:String, error:String, phone:String}; typedef RegisterBoxProps = {redirectUrl:String,message:String,phoneRequired:Bool}; /** * Registration box ( sign up ) * @author fbarbut */ class RegisterBox extends react.ReactComponentOfPropsAndState { public function new(props:RegisterBoxProps) { if (props.redirectUrl == null) props.redirectUrl = "/"; super(props); this.state = {firstName:"",lastName:"",email:"",password:"",error:null,phone:""}; } override public function render(){ //tips for conditionnal rendering : https://github.com/massiveinteractive/haxe-react#gotchas var phone = null; if (props.phoneRequired){ phone = jsx('
'); } return jsx('
<$Error error="${state.error}" /> <$Message message="${props.message}" />
${phone}

Inscription


Déjà inscrit ? Connectez-vous ici

'); } /** * @doc https://facebook.github.io/react/docs/forms.html */ function onChange(e:js.html.Event){ e.preventDefault(); var name :String = untyped e.target.name; var value :String = untyped e.target.value; //trace('onChange : $name = $value'); Reflect.setField(state, name, value); this.setState(this.state); } /** * displays a login box */ public function loginBox(){ var body = js.Browser.document.querySelector('#myModal .modal-body'); ReactDOM.unmountComponentAtNode( body ); js.Browser.document.querySelector("#myModal .modal-title").innerHTML = "Connexion"; ReactDOM.render(jsx('<$LoginBox redirectUrl="${props.redirectUrl}" />'), body ); } public function submit(e:js.html.Event ){ if (state.email == ""){ setError("Veuillez saisir votre email"); return; } if (state.password == ""){ setError("Veuillez saisir un mot de passe"); return; } if (state.firstName == ""){ setError("Veuillez saisir votre prénom"); return; } if (state.lastName == ""){ setError("Veuillez saisir votre nom de famille"); return; } if (state.phone == "" && props.phoneRequired){ setError("Veuillez saisir votre numéro de téléphone"); return; } //lock button var el : js.html.Element = cast e.target; el.classList.add("disabled"); var req = new haxe.Http("/api/user/register"); req.addParameter("firstName", state.firstName); req.addParameter("lastName", state.lastName); req.addParameter("email", state.email); req.addParameter("password", state.password); req.addParameter("redirecturl", props.redirectUrl); if(props.phoneRequired) req.addParameter("phone", state.phone); req.onData = req.onError = function(d){ var d = req.responseData; el.classList.remove("disabled"); var d = haxe.Json.parse(d); if (Reflect.hasField(d, "error")) setError(d.error.message); if (Reflect.hasField(d, "success")) js.Browser.window.location.href = props.redirectUrl; } req.request(true); } function setError(err:String){ this.setState(cast {error:err}); } }