Skip to content

Commit ce947fd

Browse files
authored
Merge pull request #115 from kube-js/develop
fix: changed cart dropdown
2 parents 3aa0085 + d95b2f8 commit ce947fd

File tree

9 files changed

+143
-37
lines changed

9 files changed

+143
-37
lines changed

k8s/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v1
22
description: A Helm chart for kube-ts-react-client
33
name: kube-ts-react-client
44
version: 1.0.0
5-
appVersion: 1.6.2
5+
appVersion: 1.6.8
66
home: https://cloud.docker.com/u/kubejs/repository/docker/kubejs/kube-ts-react-client
77
icon: https://avatars2.githubusercontent.com/u/47761918?s=200&v=4
88
sources:

k8s/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ replicaCount: 2
66

77
image:
88
repository: kubejs/kube-ts-react-client
9-
tag: 1.6.2
9+
tag: 1.6.8
1010
pullPolicy: Always
1111
containerPort: 80
1212

src/app.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import React, { Fragment, lazy, StrictMode, Suspense } from 'react';
33
import { Route, Switch } from 'react-router';
44
import AuthenticatedRoute from './components/Auth/AuthenticatedRoute';
55
import UnauthenticatedRoute from './components/Auth/UnauthenticatedRoute';
6+
import CartView from './components/Cart';
67
import CourseView from './components/CourseView';
78
import ErrorBoundary from './components/ErrorBoundaries/Page/index';
89
import InstructorView from './components/InstructorView';
910
import Layout from './components/Layout';
1011
import {
12+
CART,
1113
COURSE_VIEW,
1214
DASHBOARD,
1315
INSTRUCTOR_VIEW,
@@ -63,6 +65,8 @@ const App = () => (
6365
component={Dashboard}
6466
/>
6567

68+
<Route exact path={CART} component={CartView} />
69+
6670
<Route component={NotFound} />
6771
</Switch>
6872
</ErrorBoundary>

src/atoms/CartDropdown/index.tsx

Lines changed: 108 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,36 @@
11
// tslint:disable:no-magic-numbers
2-
import { Badge, Typography } from '@material-ui/core';
2+
import {
3+
Badge,
4+
ListItemAvatar,
5+
ListItemText,
6+
MenuItem,
7+
MenuList,
8+
Typography,
9+
} from '@material-ui/core';
310
import Button from '@material-ui/core/Button';
411
import Menu from '@material-ui/core/Menu';
512
import { withStyles } from '@material-ui/core/styles';
613
import ShoppingCartIcon from '@material-ui/icons/ShoppingCart';
14+
import _isNil from 'ramda/src/isNil';
715
import React from 'react';
16+
import { useHistory } from 'react-router';
17+
import courseImagePlaceholder from '../../images/course_400x180.png';
18+
import assetsUrl from '../../utils/helpers/assetsUrl';
819

920
const StyledMenu = withStyles({
21+
list: {
22+
padding: 0,
23+
},
1024
paper: {
1125
border: '1px solid #d3d4d5',
26+
borderRadius: 0,
1227
},
1328
})((props: any) => (
1429
<Menu
30+
autoFocus={false}
1531
elevation={0}
1632
getContentAnchorEl={null}
33+
variant="menu"
1734
anchorOrigin={{
1835
horizontal: 'center',
1936
vertical: 'bottom',
@@ -29,6 +46,7 @@ const StyledMenu = withStyles({
2946
const CartDropdown = () => {
3047
// TODO: refactor component
3148
const [anchorEl, setAnchorEl] = React.useState(null);
49+
const history = useHistory();
3250

3351
const handleClick = (event: any) => {
3452
setAnchorEl(event.currentTarget);
@@ -38,19 +56,47 @@ const CartDropdown = () => {
3856
setAnchorEl(null);
3957
};
4058

59+
const goToCart = () => {
60+
handleClose();
61+
history.push('/cart');
62+
};
63+
64+
const goToCourse = (slug: string) => () => {
65+
handleClose();
66+
history.push(`/courses/${slug}`);
67+
};
68+
69+
const cartItems: any[] = [
70+
{
71+
author: 'Martin Cook',
72+
price: '£19.99',
73+
slug: 'designing-microservices-architecture',
74+
title: 'Designing microservices architecture',
75+
},
76+
{
77+
author: 'Thomas Tik',
78+
price: '£19.99',
79+
slug: 'designing-microservices-architecture',
80+
title: 'Designing microservices architecture',
81+
},
82+
{
83+
author: 'Thomas Tik',
84+
price: '£19.99',
85+
slug: 'designing-microservices-architecture',
86+
title: 'Designing microservices architecture',
87+
},
88+
];
89+
4190
return (
42-
<div style={{ display: 'flex', alignItems: 'center'}}>
91+
<div style={{ display: 'flex', alignItems: 'center' }}>
4392
<Button
4493
aria-controls="customized-menu"
4594
aria-haspopup="true"
46-
variant="text"
4795
color="inherit"
4896
onClick={handleClick}
97+
onMouseOver={handleClick}
4998
>
50-
<Badge
51-
badgeContent={2}
52-
color="secondary"
53-
>
99+
<Badge badgeContent={cartItems.length || null} color="secondary" >
54100
<ShoppingCartIcon />
55101
</Badge>
56102
</Button>
@@ -61,7 +107,61 @@ const CartDropdown = () => {
61107
open={Boolean(anchorEl)}
62108
onClose={handleClose}
63109
>
64-
<Typography style={{padding: 10}}>Learn React from scratch - £17.99</Typography>
110+
<MenuList
111+
onMouseLeave={handleClose}
112+
disablePadding
113+
style={{ maxWidth: 400, width: '100%' }}
114+
>
115+
{cartItems.map(item => {
116+
const imageUrl = _isNil(item.imageUrl)
117+
? courseImagePlaceholder
118+
: assetsUrl(item.imageUrl);
119+
120+
return (
121+
<MenuItem onClick={goToCourse(item.slug)}>
122+
<ListItemAvatar style={{ marginRight: 10 }}>
123+
<img
124+
src={imageUrl}
125+
style={{ width: 100, height: 60 }}
126+
alt={item.title}
127+
/>
128+
</ListItemAvatar>
129+
<ListItemText
130+
primary={item.title}
131+
secondary={
132+
<>
133+
<span>Instructor: {item.author}</span>
134+
<br />
135+
Price:
136+
<span
137+
style={{
138+
color: '#000',
139+
fontWeight: 'bold',
140+
marginLeft: 5,
141+
textAlign: 'right',
142+
}}
143+
>
144+
{item.price}
145+
</span>
146+
</>
147+
}
148+
/>
149+
</MenuItem>
150+
);
151+
})}
152+
<li style={{ padding: 10 }}>
153+
<Typography variant="h6" style={{marginBottom: 10}}>Total: £59.97</Typography>
154+
155+
<Button
156+
variant="contained"
157+
fullWidth
158+
color="secondary"
159+
onClick={goToCart}
160+
>
161+
Go to cart
162+
</Button>
163+
</li>
164+
</MenuList>
65165
</StyledMenu>
66166
</div>
67167
);

src/components/Cart/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react';
2+
3+
const Cart = () => <div>Cart</div>;
4+
5+
export default Cart;

src/constants/routes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export const LOGIN = '/login';
77
export const DASHBOARD = '/dashboard';
88
export const COURSE_VIEW = '/courses/:courseSlug';
99
export const INSTRUCTOR_VIEW = '/instructors/:username';
10+
export const CART = '/cart';

src/containers/Dashboard/index.tsx

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import ErrorOutlineIcon from '@material-ui/icons/ErrorOutline';
33
import _isNil from 'ramda/src/isNil';
44
import React, { Fragment, SyntheticEvent } from 'react';
55
import { useTranslation } from 'react-i18next';
6-
import { connect } from 'react-redux';
7-
import { Dispatch } from 'redux';
6+
import { useDispatch, useSelector } from 'react-redux';
87
import ErrorMessage from '../../components/ErrorMessage';
98
import {
109
ResendVerifyTokenOptions,
@@ -27,11 +26,20 @@ export interface HandleVerifyOptions {
2726
readonly email: string;
2827
}
2928

30-
const Dashboard = ({ user, resendVerifyToken }: Props) => {
31-
const isVerified = !_isNil(user) && !_isNil((user as any).verifiedAt);
29+
const Dashboard = () => {
3230
const { t } = useTranslation();
33-
// TODO: allow to log in without being verified in kube-ts-server
31+
const dispatch = useDispatch();
32+
const { user } = useSelector(({ auth }: State) => auth);
33+
const isVerified = !_isNil(user) && !_isNil((user as any).verifiedAt);
34+
35+
const resendVerifyToken = ({ email }: ResendVerifyTokenOptions) =>
36+
dispatch(
37+
resendVerifyTokenRequested({
38+
email,
39+
})
40+
);
3441

42+
// TODO: allow to log in without being verified in kube-ts-server
3543
return (
3644
<div>
3745
<h2>{t('dashboard.mainHeader')}</h2>
@@ -40,40 +48,22 @@ const Dashboard = ({ user, resendVerifyToken }: Props) => {
4048
<ErrorMessage>
4149
<Fragment>
4250
<ErrorOutlineIcon />
43-
Account has not been verified yet. Click
51+
{t('dashboard.accountHasBeenVerified')}
4452
<Link
4553
style={{ margin: '0 5px', cursor: 'pointer' }}
4654
onClick={(e: SyntheticEvent) => {
4755
e.preventDefault();
4856
resendVerifyToken({ email: user.email });
4957
}}
5058
>
51-
here
59+
{t('global.here')}
5260
</Link>
53-
to verify your account.
61+
{t('dashboard.toVerifyYourAccount')}
5462
</Fragment>
5563
</ErrorMessage>
5664
)}
5765
</div>
5866
);
5967
};
6068

61-
const mapStateToProps = (state: State) => ({ user: state.auth.user });
62-
63-
const mapDispatchToProps = (dispatch: Dispatch) => ({
64-
resendVerifyToken: ({ email }: ResendVerifyTokenOptions) =>
65-
dispatch(
66-
// TODO: implement debounce and server throttling
67-
// TODO: implement redux hooks
68-
resendVerifyTokenRequested({
69-
email,
70-
})
71-
),
72-
});
73-
74-
// TODO: how redux connect compare to hooks
75-
76-
export default connect(
77-
mapStateToProps,
78-
mapDispatchToProps
79-
)(Dashboard);
69+
export default Dashboard;

src/i18n/translations/enGB/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ export default {
2828
learningContent: 'Learning content:'
2929
},
3030
dashboard: {
31+
accountHasBeenVerified: 'Account has not been verified yet. Click',
3132
mainHeader: 'Dashboard',
33+
toVerifyYourAccount: 'to verify your account.'
3234
},
3335
global: {
36+
here: 'here',
3437
loading: 'loading...',
3538
refreshThePage: ' Refresh the page',
3639
somethingWentWrong: 'Something went wrong...',

src/i18n/translations/plPL/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ export default {
2828
learningContent: 'Treść kursu:'
2929
},
3030
dashboard: {
31+
accountHasBeenVerified: 'Konto nie zostało jeszcze zweryfikowane. Kliknij',
3132
mainHeader: 'Panel roboczy',
33+
toVerifyYourAccount: 'aby zweryfikować swoje konto.'
3234
},
3335
global: {
36+
here: 'tutaj',
3437
loading: 'ładowanie...',
3538
refreshThePage: ' Odśwież stronę',
3639
somethingWentWrong: 'Coś poszło nie tak...'

0 commit comments

Comments
 (0)