// tslint:disable:no-magic-numbers import { Badge, ListItemAvatar, ListItemText, MenuItem, MenuList, Typography, } from '@material-ui/core'; import Button from '@material-ui/core/Button'; import Menu from '@material-ui/core/Menu'; import { withStyles } from '@material-ui/core/styles'; import ShoppingCartIcon from '@material-ui/icons/ShoppingCart'; import _isNil from 'ramda/src/isNil'; import React from 'react'; import { useTranslation } from 'react-i18next'; import { useSelector } from 'react-redux'; import { useHistory } from 'react-router'; import courseImagePlaceholder from '../../images/course_400x180.png'; import { State } from '../../redux/rootReducer'; import assetsUrl from '../../utils/helpers/assetsUrl'; import sumBy from '../../utils/helpers/sumBy'; const StyledMenu = withStyles({ list: { padding: 0, }, paper: { border: '1px solid #d3d4d5', borderRadius: 0, }, })((props: any) => (
)); const CartDropdown = () => { // TODO: refactor component const [anchorEl, setAnchorEl] = React.useState(null); const { t } = useTranslation(); const { items } = useSelector((state: State) => state.cart); const history = useHistory(); const handleClick = (event: any) => { setAnchorEl(event.currentTarget); }; const handleClose = () => { setAnchorEl(null); }; const goToCart = (e: any) => { e.preventDefault(); handleClose(); history.push('/cart'); }; const goToCourse = (slug: string) => () => { handleClose(); history.push(`/courses/${slug}`); }; // TODO: implements pricing on server const courseItems = items.map(item => ({ ...item, price: 19.99 })); const total = sumBy('price')(courseItems); return (