Parcourir la source

sign up is finally done

Maxim il y a 5 ans
Parent
commit
1fa808c423

+ 2 - 3
src/components/public/SignUp/Form/index.js

@@ -7,15 +7,14 @@ import formInput from './../../../common/formInput';
 class Form extends React.Component {
 
     submit = ({ name, email, password }) => {
-        const { signIn } = this.props;
-        signIn({
+        const { signUp } = this.props;
+        signUp({
             name,
             email,
             password
         })
     }
 
-
     render() {
         const { handleSubmit, requestError, invalid } = this.props;
 

+ 3 - 3
src/components/public/SignUp/index.js

@@ -2,7 +2,7 @@ import React from 'react';
 import Form from './Form';
 import { bindActionCreators } from 'redux';
 import { connect } from 'react-redux';
-import { Redirect } from 'react-router-dom'
+import { Redirect } from 'react-router-dom';
 
 import Spinner from './../../common/spinner';
 import { signUp } from './../../../actions/auth/signUp';
@@ -11,9 +11,9 @@ const SignUp = ({ status, signUp }) => (
     status.isFetching
         ?
         <Spinner />
-        : status.data
+        : status.isSuccessful
             ?
-            <Redirect to='/' />
+            <Redirect to='/sign-in' />
             : status.error
                 ?
                 <Form signUp={signUp} requestError={status.error} />

+ 1 - 1
src/constants/auth.js

@@ -3,7 +3,7 @@ export const SIGN_IN_REQUEST = 'SIGN_IN_REQUEST';
 export const SIGN_IN_REQUEST_SUCCESS = 'SIGN_IN_REQUEST_SUCCESS';
 export const SIGN_IN_REQUEST_FAILURE = 'SIGN_IN_REQUEST_FAILURE';
 
-export const SIGN_UP_URL = '';
+export const SIGN_UP_URL = 'https://test-app-a-level.herokuapp.com/auth/register';
 export const SIGN_UP_REQUEST = 'SIGN_UP_REQUEST';
 export const SIGN_UP_REQUEST_SUCCESS = 'SIGN_UP_REQUEST_SUCCESS';
 export const SIGN_UP_REQUEST_FAILURE = 'SIGN_UP_REQUEST_FAILURE';

+ 3 - 3
src/reducers/auth/signUp.js

@@ -3,14 +3,14 @@ import initialState from './../initialState';
 
 export default function signInReducer(state = initialState.signUp, {type, payload, error}) {
     switch(type) {
-        case actionTypes.SIGN_IN_REQUEST: {
+        case actionTypes.SIGN_UP_REQUEST: {
             return {
                 ...state,
                 isFetching: true
             }
         }
         
-        case actionTypes.SIGN_IN_REQUEST_SUCCESS: {
+        case actionTypes.SIGN_UP_REQUEST_SUCCESS: {
             return {
                 ...state,
                 isFetching: false,
@@ -18,7 +18,7 @@ export default function signInReducer(state = initialState.signUp, {type, payloa
             }
         }
 
-        case actionTypes.SIGN_IN_REQUEST_FAILURE: {
+        case actionTypes.SIGN_UP_REQUEST_FAILURE: {
             return {
                 ...state,
                 isFetching: false,

+ 1 - 5
src/sagas/auth/signIn.js

@@ -18,15 +18,11 @@ export default function* ({ payload }) {
                 .then(({ data }) => data)
         )
 
-        console.log('\n\n', 'SignIn worker-saga', user, '\n\n\n')
-
+        //TODO: TOKEN
         // yield call(localStorage.setItem, storageKey, user.token);
         yield put(signInSuccess(user));
     }
     catch ({ message }) {
-        window.someError = message;
-        console.warn('\n\n', 'SignIn worker-saga', message, '\n\n\n')
-
         yield put(signInFailure(message));
     }
 }

+ 24 - 2
src/sagas/auth/signUp.js

@@ -1,3 +1,25 @@
-export default function* () {
-    
+import { put, call } from 'redux-saga/effects';
+import axios from 'axios';
+
+import { SIGN_UP_URL } from './../../constants/auth';
+import { signUpSuccess, signUpFailure } from './../../actions/auth/signUp';
+
+export default function* ({payload}) {
+    try {
+        const config = {
+            headers: {
+                "Content-Type": "application/json"
+            }
+        }
+
+        const report = yield call(() =>
+            axios.post(SIGN_UP_URL, payload, config)
+                .then(({ data }) => data)
+        )
+
+        yield put(signUpSuccess(report));
+    }
+    catch ({ message }) {
+        yield put(signUpFailure(message));
+    }
 }