Guest User

Untitled

a guest
Sep 24th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. export const createUser = values => {
  2. const email = values.get("user_attributes[email]");
  3. const password = values.get("user_attributes[password]");
  4. return dispatch => {
  5. dispatch({
  6. [RSAA]: {
  7. endpoint: `${globalVar.API_URL}/users/`,
  8. method: "POST",
  9. body: values,
  10. types: [
  11. CREATE_USER,
  12. {
  13. type: CREATE_USER_SUCCESS,
  14. payload: (action, state, response) => {
  15. return response.json().then(json => {
  16. dispatch(login(email, password));
  17. dispatch(sendFlashMessage("success", json.message));
  18. return json;
  19. });
  20. }
  21. },
  22. CREATE_USER_FAILURE
  23. ]
  24. }
  25. });
  26. };
  27. };
  28.  
  29. class UserNew extends Component {
  30. constructor(props) {
  31. super(props);
  32. this.onSubmit = this.onSubmit.bind(this);
  33. }
  34.  
  35. onSubmit(values) {
  36. values = { user_attributes: values };
  37. const data = objectToFormData(values);
  38. this.props.actions.createUser(data);
  39. }
  40.  
  41. render() {
  42. const { handleSubmit, errors } = this.props;
  43. return (
  44. <UserForm
  45. handleSubmit={handleSubmit}
  46. onSubmit={this.onSubmit}
  47. errors={errors}
  48. />
  49. );
  50. }
  51. }
  52.  
  53. it("create new user", done => {
  54. wrapper
  55. .find("#sign-up")
  56. .hostNodes()
  57. .simulate("click");
  58.  
  59. wrapper
  60. .find('[name="first_name"]')
  61. .hostNodes()
  62. .simulate("change", { target: { value: "User" } });
  63.  
  64. ...
  65.  
  66. wrapper
  67. .find("form")
  68. .hostNodes()
  69. .simulate("submit");
Add Comment
Please, Sign In to add comment