{"size": 1345, "ext": "js", "max_stars_repo_path": "client/components/user-home.js", "max_stars_repo_name": "grace-shopper-team-c/grace-shopper", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "client/components/user-home.js", "max_issues_repo_name": "grace-shopper-team-c/grace-shopper", "max_issues_repo_issues_event_min_datetime": "2020-09-24T17:28:31.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-29T17:15:44.000Z", "max_forks_repo_path": "client/components/user-home.js", "max_forks_repo_name": "grace-shopper-team-c/grace-shopper", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 19, "max_forks_count": null, "avg_line_length": 22.0491803279, "max_line_length": 82, "alphanum_fraction": 0.6617100372}
import React from 'react'
import {connect} from 'react-redux'
import PropTypes from 'prop-types'
import {updateUser} from '../store/user'
import AdminSidebar from './AdminSidebar'
import UpdateForm from './UpdateForm'

/**
 * COMPONENT
 */
//Account information page.
//Show user infomation about their account and allows them to update thier address
//Grants Admins access to their admin only routes
export const UserHome = props => {
  const {email, isAdmin} = props

  return (
    <div className="all_product_container">
      {isAdmin ? <AdminSidebar /> : ''}
      <div>
        <h3 className="welcome">Welcome, {email}</h3>
        <UpdateForm updateAddress={props.handleSubmit} />
      </div>
    </div>
  )
}

/**
 * CONTAINER
 */
const mapState = state => {
  return {
    id: state.user.id,
    email: state.user.email,
    isAdmin: state.user.isAdmin
  }
}

const mapDispatch = dispatch => {
  return {
    handleSubmit(evt, id) {
      evt.preventDefault()
      const address = evt.target.address.value
      const city = evt.target.city.value
      const state = evt.target.state.value
      const zip = evt.target.zip.value
      dispatch(updateUser(id, {address, city, state, zip}))
    }
  }
}

export default connect(mapState, mapDispatch)(UserHome)

/**
 * PROP TYPES
 */

UserHome.propTypes = {
  email: PropTypes.string
}
