Skip to content

Commit 1ebf731

Browse files
authored
Merge pull request #122 from kube-js/develop
fix: refactored redux hoc into hooks
2 parents f5d32de + fa21b6f commit 1ebf731

File tree

30 files changed

+571
-667
lines changed

30 files changed

+571
-667
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.22
5+
appVersion: 1.6.23
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.22
9+
tag: 1.6.23
1010
pullPolicy: Always
1111
containerPort: 80
1212

src/app.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ 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/CartView';
7-
import CheckoutView from './components/CheckoutView';
8-
import CourseView from './components/CourseView';
96
import ErrorBoundary from './components/ErrorBoundaries/Page/index';
10-
import InstructorView from './components/InstructorView';
117
import Layout from './components/Layout';
128
import {
139
CART,
@@ -22,7 +18,11 @@ import {
2218
ROOT,
2319
VERIFY,
2420
} from './constants/routes';
21+
import CartView from './pages/Cart';
22+
import CheckoutView from './pages/Checkout';
23+
import CourseView from './pages/Course';
2524
import Home from './pages/Home';
25+
import InstructorView from './pages/Instructor';
2626
import Loading from './pages/Loading';
2727
import Login from './pages/Login';
2828
import NotFound from './pages/NotFound';

src/components/CartCheckoutSidebar/index.tsx

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { Button, Typography } from '@material-ui/core';
33
import Paper from '@material-ui/core/Paper';
44
import _isNil from 'ramda/src/isNil';
5-
import React, { useRef } from 'react';
5+
import React, { useRef, useState } from 'react';
66
import { useTranslation } from 'react-i18next';
77
import { useSelector } from 'react-redux';
88
import { Redirect, useHistory } from 'react-router';
@@ -11,14 +11,34 @@ import { State } from '../../redux/rootReducer';
1111
import sumBy from '../../utils/helpers/sumBy';
1212
import LoginForm from '../LoginForm';
1313
import Modal from '../Modal';
14+
import RegisterForm from '../RegisterForm';
1415
import useStyles from './styles';
1516

1617
const CartItems = ({ items }: any) => {
1718
const classes = useStyles();
1819
const { t } = useTranslation();
1920
const history = useHistory();
2021
const noUser = useRef({});
21-
22+
const [open, setOpen] = useState(false);
23+
const [authView, setAuthView] = useState('register');
24+
25+
const showRegister = () => {
26+
setAuthView('register');
27+
};
28+
29+
const showLogin = () => {
30+
setAuthView('login');
31+
};
32+
33+
const handleOpen = (e: any) => {
34+
e.preventDefault();
35+
setOpen(true);
36+
};
37+
38+
const handleClose = () => {
39+
setOpen(false);
40+
};
41+
2242
const { user } = useSelector(({ auth }: State) => auth);
2343

2444
if (!user) {
@@ -37,37 +57,33 @@ const CartItems = ({ items }: any) => {
3757
return <Redirect push to={CHECKOUT} />;
3858
}
3959

60+
const ctaProps = !_isNil(user)
61+
? { onClick: goTo(CHECKOUT) }
62+
: { onClick: handleOpen };
63+
64+
const registerLinkProps = { to: undefined, onClick: showRegister };
65+
const loginLinkProps = { to: undefined, onClick: showLogin };
66+
4067
return (
4168
<Paper className={classes.paper} square>
4269
<Typography>
4370
{t('cart.total')} ({items.length} {courses}): £{total.toFixed(2)}
4471
</Typography>
4572

46-
{!_isNil(user) ? (
47-
<Button
48-
variant="contained"
49-
fullWidth
50-
color="secondary"
51-
onClick={goTo(CHECKOUT)}
52-
>
53-
{t('cart.proceedToCheckout')}
54-
</Button>
55-
) : (
56-
<Modal
57-
renderCta={({ handleClickOpen }: any) => (
58-
<Button
59-
variant="contained"
60-
fullWidth
61-
color="secondary"
62-
onClick={handleClickOpen}
63-
>
64-
{t('cart.proceedToCheckout')}
65-
</Button>
66-
)}
67-
>
68-
<LoginForm />
69-
</Modal>
70-
)}
73+
<Button variant="contained" fullWidth color="secondary" {...ctaProps}>
74+
{t('cart.proceedToCheckout')}
75+
</Button>
76+
<Modal open={open} handleClose={handleClose}>
77+
{authView === 'register' && (
78+
<RegisterForm loginLinkProps={loginLinkProps} />
79+
)}
80+
{authView === 'login' && (
81+
<LoginForm
82+
showRemindPassword={false}
83+
registerLinkProps={registerLinkProps}
84+
/>
85+
)}
86+
</Modal>
7187
</Paper>
7288
);
7389
};

src/components/Home/index.tsx

Lines changed: 0 additions & 76 deletions
This file was deleted.

src/components/LoginForm/index.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@ import { State } from '../../redux/rootReducer';
1717
import loginSchema from '../../utils/schemas/login';
1818
import useStyles from './styles';
1919

20-
const LoginForm = () => {
20+
export interface Props {
21+
readonly showRemindPassword?: boolean;
22+
readonly registerLinkProps?: any;
23+
}
24+
25+
const LoginForm = ({
26+
showRemindPassword = true,
27+
registerLinkProps = {},
28+
}: Props) => {
2129
const classes = useStyles();
2230

2331
const { t } = useTranslation();
@@ -102,11 +110,15 @@ const LoginForm = () => {
102110
</Button>
103111

104112
<Grid container>
105-
<Grid item xs>
106-
<Link to={REMIND_PASSWORD}>{t('auth.forgotPassword')}</Link>
107-
</Grid>
113+
{showRemindPassword && (
114+
<Grid item xs>
115+
<Link to={REMIND_PASSWORD}>{t('auth.forgotPassword')}</Link>
116+
</Grid>
117+
)}
108118
<Grid item>
109-
<Link to={REGISTER}>{t('auth.dontHaveAccount')}</Link>
119+
<Link to={REGISTER} {...registerLinkProps}>
120+
{t('auth.dontHaveAccount')}
121+
</Link>
110122
</Grid>
111123
</Grid>
112124
</form>

src/components/LoginForm/styles.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ const useStyles = makeStyles((theme: Theme) => ({
1212
margin: theme.spacing(1),
1313
},
1414
form: {
15-
marginTop: theme.spacing(1),
15+
marginBottom: theme.spacing(2),
16+
marginTop: theme.spacing(2),
1617
width: '100%', // Fix IE 11 issue.
1718
},
1819
paper: {

src/components/Modal/index.tsx

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
11
import { Dialog, DialogContent } from '@material-ui/core';
22
import React from 'react';
33

4-
const Modal = ({ children, renderCta }: any) => {
5-
const [open, setOpen] = React.useState(false);
6-
7-
const handleClickOpen = () => {
8-
setOpen(true);
9-
};
10-
11-
const handleClose = () => {
12-
setOpen(false);
13-
};
14-
15-
return (
16-
<div>
17-
{renderCta({ handleClickOpen })}
18-
<Dialog
19-
open={open}
20-
maxWidth="xs"
21-
onClose={handleClose}
22-
aria-labelledby="form-dialog-title"
23-
>
24-
<DialogContent>{children}</DialogContent>
25-
</Dialog>
26-
</div>
27-
);
28-
};
4+
const Modal = ({ open, handleClose, children }: any) => (
5+
<Dialog
6+
open={open}
7+
maxWidth="xs"
8+
onClose={handleClose}
9+
aria-labelledby="form-dialog-title"
10+
>
11+
<DialogContent>{children}</DialogContent>
12+
</Dialog>
13+
);
2914

3015
export default Modal;

0 commit comments

Comments
 (0)