From 05338c4780b074b925905699e05f25c3bfad8bd4 Mon Sep 17 00:00:00 2001 From: Neda Rohani Date: Wed, 29 Jul 2020 12:43:23 -0700 Subject: [PATCH 1/2] fix: change login to email --- application/src/redux/reducers/authReducer.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/application/src/redux/reducers/authReducer.js b/application/src/redux/reducers/authReducer.js index 4f3da462..3a6d1ea5 100644 --- a/application/src/redux/reducers/authReducer.js +++ b/application/src/redux/reducers/authReducer.js @@ -3,12 +3,12 @@ import { LOGIN, LOGOUT } from '../actions/types' const INITIAL_STATE = { email: null, token: null }; export default (state = INITIAL_STATE, action) => { - switch (action.type) { - case LOGIN: - return { ...state, email: action.payload.login, token: action.payload.token } - case LOGOUT: - return { ...state, ...INITIAL_STATE } - default: - return state; - } + switch (action.type) { + case LOGIN: + return { ...state, email: action.payload.email, token: action.payload.token } + case LOGOUT: + return { ...state, ...INITIAL_STATE } + default: + return state; + } } \ No newline at end of file From bde619d7b13e2f9c28e13c375c6326aaad7d94f5 Mon Sep 17 00:00:00 2001 From: Neda Rohani Date: Wed, 29 Jul 2020 12:46:16 -0700 Subject: [PATCH 2/2] style: deconstruct auth in mapStateToProps --- application/src/components/order-form/orderForm.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/application/src/components/order-form/orderForm.js b/application/src/components/order-form/orderForm.js index ae46253f..033126b6 100644 --- a/application/src/components/order-form/orderForm.js +++ b/application/src/components/order-form/orderForm.js @@ -6,16 +6,17 @@ import './orderForm.css'; const ADD_ORDER_URL = `${SERVER_IP}/api/add-order` -const mapStateToProps = (state) => ({ - auth: state.auth, +const mapStateToProps = ({ auth }) => ({ + email: auth.email, + token: auth.token }) class OrderForm extends Component { constructor(props) { super(props); this.state = { - order_item: "", - quantity: "1" + order_item: "", + quantity: "1" } } @@ -35,7 +36,7 @@ class OrderForm extends Component { body: JSON.stringify({ order_item: this.state.order_item, quantity: this.state.quantity, - ordered_by: this.props.auth.email || 'Unknown!' + ordered_by: this.props.email || 'Unknown!' }), headers: { 'Content-Type': 'application/json'