fullstackreact / redux-modules

A better redux module helper
https://fullstackreact.github.io/redux-modules/
MIT License
59 stars 9 forks source link

Data on post request #1

Closed alvarosaavedra closed 8 years ago

alvarosaavedra commented 8 years ago

I can't make it work, I asume that shuold be somethink like


export const actions = {
  signIn: createApiAction(types.SIGN_IN)((client, {email,password}) => {
    console.debug(email,password)
    return client.post({
      path: '/school/sessions',   
      data: {user_session: {email: email, password:password}}
    }).then(res => {console.debug(res); return res})
  })
}

but I not reciving any inputs

auser commented 8 years ago

Ah interesting. How are you calling the action, @alvarosaavedra?

And are you seeing any inputs from your server?

alvarosaavedra commented 8 years ago

OK so I have a component: Login.js

import React, { PropTypes as T } from 'react'
import {Link} from 'react-router'

import styles from './styles.module.css';

let email;
let password;

export class Login extends React.Component {

  handleSubmit() {
    event.preventDefault();
    this.props.onSubmit(email.value, password.value)
  }
  render() {
    return (
      <div>
        <h1> Login</h1>
        <form className={styles.login} onSubmit={this.handleSubmit.bind(this)}>
          <input type="email" ref={node => {email = node }}/>
          <input type="password" ref={node => {password = node }}/>
          <button>Login</button>
        </form>
      </div>
    )
  }
}

Login.propTypes = {
  onSubmit: T.func
}

Login.defaultProps = {
}

export default Login

For this component I use a container: SignIn.js

import { connect } from 'react-redux'
import Login from '../../components/Login/Login'

const mapDispatchToProps = (dispatch, ownProps) => {
  return {
    onSubmit: (email,password) => {
      ownProps.actions.auth.signIn({email:email, password: password});
    }
  }
}

const SignIn = connect(
  mapDispatchToProps
)(Login)

export default SignIn

then I have the auth redux-module:

import {createConstants, createReducer} from 'redux-module-builder'
import {createApiHandler, createApiAction} from 'redux-module-builder/api'
import { normalize, Schema, arrayOf } from 'normalizr';

export const types = createConstants('auth')(
  { 'SIGN_IN': {api: true}}
);

export const actions = {
  signIn: createApiAction(types.SIGN_IN)((client, {email,password}) => {
    console.debug(email,password)
    return client.post({
      path: '/school/sessions',   
      data: {user_session: "HOla"}
    }).then(res => {console.debug(res); return res})
  })
}

/* TODO */
export const reducer = createReducer({
  [types.SIGN_IN]: (state, {email, password}) => ({
    ...state,
    email: email
  })
});

export const initialState = {
  loading: false,
  errors: null,
  email: null,
  token: null
};

At the backend the request come as POST request, and I dont get any data in the request just the url. When doing a get one everithing works as espected. I see that all your test ar for get, and not for post. Could be some implementation there??? I'm using the data param in the rigth way??

auser commented 8 years ago

Can you try something for me? Not sure how this "got" in the way, but can you try changing line 52 and 54 in apiClient to read with opts, instead of baseOpts?

Do you have a gchat id? I'd be willing to jump on gchat with you to try to work it out. I'll see if I can mimic that behavior over here/tests. Thanks for reporting!

auser commented 8 years ago

@alvarosaavedra yes, you're using the data param properly. It is sent as the body parameter.

alvarosaavedra commented 8 years ago

@auser thnx I change the lines in the node modules (they are diferent lines) just for try, it dosen't work, my gchat is asaabe@gmail.com, if you are interested. I also put the debug mode on, nothing importan I think, and in the developer tools of chrome the request it seem to bee empty also.

var requestTransforms = _this._parseOpt('requestTransforms', options, opts, []);
var responseTransforms = _this._parseOpt('responseTransforms', options, opts, [parseJson]);
auser commented 8 years ago

I just sent you a message on gchat. Feel free to ping me on there.

auser commented 8 years ago

What does the debugLog say is in the transformedOpts?

alvarosaavedra commented 8 years ago
requesting...
0.0.0.0/:1 POST http://0.0.0.0:5000/api-token-auth/ 400 (Bad Request)
apiClient.js?8a29:159 Response {type: "cors", url: "http://0.0.0.0:5000/api-token-auth/", status: 400, ok: false, statusText: "Bad Request"…}
auser commented 8 years ago

Thanks @alvarosaavedra

Pushed 0.3.2 to fix this bug.