-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from DIM-Squad/registerd-user-cart-#113
Registered user cart #113
- Loading branch information
Showing
16 changed files
with
1,469 additions
and
1,854 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,223 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import React, {Component} from 'react' | ||
//import PropTypes from 'prop-types' | ||
import {connect} from 'react-redux' | ||
import {Link} from 'react-router-dom' | ||
import {logout} from '../store' | ||
import store, {logout, postCart, emptyCart} from '../store' | ||
import {SearchBar} from './' | ||
import CategoryDropdown from './CategoryDropdown' | ||
import {Menu, Icon, Button} from 'semantic-ui-react' | ||
//import {postCart} from '../store/cart' | ||
|
||
const Navbar = ({handleClick, isLoggedIn, userId}) => ( | ||
<Menu attached="top" stackable> | ||
<Menu.Item as="h1"> | ||
<span>I </span> | ||
<span> | ||
<Link to="/products"> | ||
{' '} | ||
<Icon name="heart" /> | ||
</Link> | ||
</span>{' '} | ||
<span> Art</span> | ||
</Menu.Item> | ||
<Menu.Item as={SearchBar} type="products" /> | ||
<Menu.Item as={CategoryDropdown} /> | ||
<Menu.Menu position="right"> | ||
<Menu.Item as={Link} to="/home"> | ||
Home | ||
</Menu.Item> | ||
{isLoggedIn ? ( | ||
<React.Fragment> | ||
<Menu.Item as={Link} to={`/users/${userId}`}> | ||
My Account | ||
</Menu.Item> | ||
<Menu.Item as="a" href="#" onClick={handleClick}> | ||
Logout | ||
</Menu.Item> | ||
<Menu.Item> | ||
<Link to="/cart"> | ||
<Button color="pink"> | ||
<Icon name="shopping cart" /> | ||
</Button> | ||
</Link> | ||
</Menu.Item> | ||
</React.Fragment> | ||
) : ( | ||
<React.Fragment> | ||
{/* The navbar will show these links before you log in */} | ||
<Menu.Item as={Link} to="/login"> | ||
Login | ||
</Menu.Item> | ||
<Menu.Item as={Link} to="/signup"> | ||
Sign Up | ||
</Menu.Item> | ||
<Menu.Item> | ||
<Link to="/cart"> | ||
<Button color="pink"> | ||
<Icon name="shopping cart" /> | ||
</Button> | ||
</Link> | ||
</Menu.Item> | ||
</React.Fragment> | ||
)} | ||
</Menu.Menu> | ||
</Menu> | ||
) | ||
class Navbar extends Component { | ||
constructor() { | ||
super() | ||
this.handleClick = this.handleClick.bind(this) | ||
} | ||
|
||
handleClick() { | ||
this.props.logout() | ||
this.props.postCart(this.props.cart, this.props.user.id) | ||
this.props.emptyCart() | ||
} | ||
render() { | ||
return ( | ||
<Menu attached="top" stackable> | ||
<Menu.Item as="h1"> | ||
<span>I </span> | ||
<span> | ||
<Icon name="heart" /> | ||
</span>{' '} | ||
<span> Art</span> | ||
</Menu.Item> | ||
<Menu.Item as={SearchBar} type="products" /> | ||
<Menu.Item as={CategoryDropdown} /> | ||
<Menu.Menu position="right"> | ||
{this.props.isLoggedIn ? ( | ||
<React.Fragment> | ||
<Menu.Item as={Link} to="/home"> | ||
{/* The navbar will show these links after you log in */} | ||
Home | ||
</Menu.Item> | ||
<Menu.Item as={Link} to={`/users/${this.props.user.id}`}> | ||
My Account | ||
</Menu.Item> | ||
<Menu.Item as="a" href="#" onClick={this.handleClick}> | ||
Logout | ||
</Menu.Item> | ||
<Menu.Item> | ||
<Link to="/cart"> | ||
<Button color="pink"> | ||
<Icon name="shopping cart" /> | ||
</Button> | ||
</Link> | ||
</Menu.Item> | ||
</React.Fragment> | ||
) : ( | ||
<React.Fragment> | ||
{/* The navbar will show these links before you log in */} | ||
<Menu.Item as={Link} to="/login"> | ||
Login | ||
</Menu.Item> | ||
<Menu.Item as={Link} to="/signup"> | ||
Sign Up | ||
</Menu.Item> | ||
<Menu.Item> | ||
<Link to="/cart"> | ||
<Button color="pink"> | ||
<Icon name="shopping cart" /> | ||
</Button> | ||
</Link> | ||
</Menu.Item> | ||
</React.Fragment> | ||
)} | ||
</Menu.Menu> | ||
</Menu> | ||
) | ||
} | ||
} | ||
// const Navbar = ({handleClick, isLoggedIn, userId}) => ( | ||
// <Menu attached="top" stackable> | ||
// <Menu.Item as="h1"> | ||
// <span>I </span> | ||
// <span> | ||
// <Link to="/products"> | ||
// {' '} | ||
// <Icon name="heart" /> | ||
// </Link> | ||
// </span>{' '} | ||
// <span> Art</span> | ||
// </Menu.Item> | ||
// <Menu.Item as={SearchBar} type="products" /> | ||
// <Menu.Item as={CategoryDropdown} /> | ||
// <Menu.Menu position="right"> | ||
// <Menu.Item as={Link} to="/home"> | ||
// Home | ||
// </Menu.Item> | ||
// {isLoggedIn ? ( | ||
// <React.Fragment> | ||
// <Menu.Item as={Link} to={`/users/${userId}`}> | ||
// My Account | ||
// </Menu.Item> | ||
// <Menu.Item as="a" href="#" onClick={handleClick}> | ||
// Logout | ||
// </Menu.Item> | ||
// <Menu.Item> | ||
// <Link to="/cart"> | ||
// <Button color="pink"> | ||
// <Icon name="shopping cart" /> | ||
// </Button> | ||
// </Link> | ||
// </Menu.Item> | ||
// </React.Fragment> | ||
// ) : ( | ||
// <React.Fragment> | ||
// {/* The navbar will show these links before you log in */} | ||
// <Menu.Item as={Link} to="/login"> | ||
// Login | ||
// </Menu.Item> | ||
// <Menu.Item as={Link} to="/signup"> | ||
// Sign Up | ||
// </Menu.Item> | ||
// <Menu.Item> | ||
// <Link to="/cart"> | ||
// <Button color="pink"> | ||
// <Icon name="shopping cart" /> | ||
// </Button> | ||
// </Link> | ||
// </Menu.Item> | ||
// </React.Fragment> | ||
// )} | ||
// </Menu.Menu> | ||
// </Menu> | ||
// ) | ||
|
||
/** | ||
* CONTAINER | ||
*/ | ||
const mapState = state => { | ||
return { | ||
isLoggedIn: !!state.user.id, | ||
userId: state.user.id | ||
} | ||
} | ||
const mapState = state => ({ | ||
isLoggedIn: !!state.user.id, | ||
cart: state.cart, | ||
user: state.user, | ||
userId: state.user.id | ||
}) | ||
|
||
const mapDispatch = dispatch => { | ||
return { | ||
handleClick() { | ||
dispatch(logout()) | ||
} | ||
} | ||
} | ||
const mapDispatch = dispatch => ({ | ||
logout: () => dispatch(logout()), | ||
postCart: (cartItems, userId) => dispatch(postCart(cartItems, userId)), | ||
emptyCart: () => dispatch(emptyCart()) | ||
// dispatch(postCart(cartItems)) | ||
//dispatch(logout()) | ||
}) | ||
|
||
export default connect(mapState, mapDispatch)(Navbar) | ||
|
||
/** | ||
* PROP TYPES | ||
*/ | ||
Navbar.propTypes = { | ||
handleClick: PropTypes.func.isRequired, | ||
isLoggedIn: PropTypes.bool.isRequired | ||
} | ||
// Navbar.propTypes = { | ||
// handleClick: PropTypes.func.isRequired, | ||
// isLoggedIn: PropTypes.bool.isRequired | ||
// } | ||
|
||
// const Navbar = ({ handleClick, isLoggedIn, cart }) => ( | ||
// <Menu attached="top" stackable> | ||
// <Menu.Item as="h1"> | ||
// <span>I </span> | ||
// <span> | ||
// <Icon name="heart" /> | ||
// </span>{' '} | ||
// <span> Art</span> | ||
// </Menu.Item> | ||
// <Menu.Item as={SearchBar} type="products" /> | ||
// <Menu.Item as={CategoryDropdown} /> | ||
// <Menu.Menu position="right"> | ||
// {isLoggedIn ? ( | ||
// <React.Fragment> | ||
// <Menu.Item as={Link} to="/home"> | ||
// {/* The navbar will show these links after you log in */} | ||
// Home | ||
// </Menu.Item> | ||
// <Menu.Item as="a" href="#" onClick={handleClick}> | ||
// Logout | ||
// </Menu.Item> | ||
// <Menu.Item> | ||
// <Link to="/cart"> | ||
// <Button color="pink"> | ||
// <Icon name="shopping cart" /> | ||
// </Button> | ||
// </Link> | ||
// </Menu.Item> | ||
// </React.Fragment> | ||
// ) : ( | ||
// <React.Fragment> | ||
// {/* The navbar will show these links before you log in */} | ||
// <Menu.Item as={Link} to="/login"> | ||
// Login | ||
// </Menu.Item> | ||
// <Menu.Item as={Link} to="/signup"> | ||
// Sign Up | ||
// </Menu.Item> | ||
// </React.Fragment> | ||
// )} | ||
// </Menu.Menu> | ||
// </Menu> | ||
// ) | ||
|
||
// /** | ||
// * CONTAINER | ||
// */ | ||
// const mapState = state => { | ||
// return { | ||
// isLoggedIn: !!state.user.id, | ||
// cart: state.cart | ||
// } | ||
// } | ||
|
||
// const mapDispatch = dispatch => { | ||
// return { | ||
// handleClick() { | ||
// // dispatch(postCart(cartItems)) | ||
// dispatch(logout()) | ||
// } | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.