Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export const createUser = values => {
- const email = values.get("user_attributes[email]");
- const password = values.get("user_attributes[password]");
- return dispatch => {
- dispatch({
- [RSAA]: {
- endpoint: `${globalVar.API_URL}/users/`,
- method: "POST",
- body: values,
- types: [
- CREATE_USER,
- {
- type: CREATE_USER_SUCCESS,
- payload: (action, state, response) => {
- return response.json().then(json => {
- dispatch(login(email, password));
- dispatch(sendFlashMessage("success", json.message));
- return json;
- });
- }
- },
- CREATE_USER_FAILURE
- ]
- }
- });
- };
- };
- class UserNew extends Component {
- constructor(props) {
- super(props);
- this.onSubmit = this.onSubmit.bind(this);
- }
- onSubmit(values) {
- values = { user_attributes: values };
- const data = objectToFormData(values);
- this.props.actions.createUser(data);
- }
- render() {
- const { handleSubmit, errors } = this.props;
- return (
- <UserForm
- handleSubmit={handleSubmit}
- onSubmit={this.onSubmit}
- errors={errors}
- />
- );
- }
- }
- it("create new user", done => {
- wrapper
- .find("#sign-up")
- .hostNodes()
- .simulate("click");
- wrapper
- .find('[name="first_name"]')
- .hostNodes()
- .simulate("change", { target: { value: "User" } });
- ...
- wrapper
- .find("form")
- .hostNodes()
- .simulate("submit");
Add Comment
Please, Sign In to add comment