Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add user to order form #5

Merged
merged 2 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions application/src/components/order-form/orderForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

Expand All @@ -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'
Expand Down
16 changes: 8 additions & 8 deletions application/src/redux/reducers/authReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}