Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add preloader to Login process and tests #49

Merged
merged 1 commit into from
Oct 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
23,043 changes: 0 additions & 23,043 deletions package-lock.json

This file was deleted.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
"node-sass-chokidar": "1.3.4",
"npm-check": "5.9.0",
"npm-run-all": "4.1.3",

"nyc": "13.1.0",
"prettier": "1.14.3",
"redux-devtools-extension": "2.13.5",
Expand Down
74 changes: 57 additions & 17 deletions src/client/components/Login/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ import Check from "@material-ui/icons/Check";
import Button from "@material-ui/core/Button";
import IconButton from "@material-ui/core/IconButton";
import { Redirect, Link } from "react-router-dom";
import classNames from "classnames";
import CircularProgress from "@material-ui/core/CircularProgress";
import green from "@material-ui/core/colors/green";

const styles = theme => ({
root: {
flexGrow: 1
},
paper: {
padding: theme.spacing.unit * 2,
height: '100vh',
height: "100vh",
display: "flex",
alignItems: "center"
},
Expand All @@ -29,9 +32,6 @@ const styles = theme => ({
text: {
width: "100%"
},
button: {
margin: theme.spacing.unit
},
link: {
textDecoration: "none",
color: theme.palette.secondary.main,
Expand All @@ -42,17 +42,44 @@ const styles = theme => ({
learnMore: {
color: "white",
borderColor: "white"
},
wrapper: {
margin: theme.spacing.unit,
position: "relative"
},
buttonProgress: {
color: green[500],
position: "absolute",
top: "50%",
right: 133.69 / 2 - 33 / 2,
marginTop: -12,
marginLeft: -12
},
buttonSuccess: {
backgroundColor: green[500],
"&:hover": {
backgroundColor: green[700]
}
}
});

type Props = {
classes: Object,
state: Object,
onLogin: Function
onLogin: Function,
success: boolean,
showPreloader: boolean
};

const Login = ({ onLogin, classes }: Props) => {
const Login = ({
onLogin,
classes,
state: { showPreloader, success }
}: Props) => {
let email: HTMLInputElement, password: HTMLInputElement;
const buttonClassname = classNames({
[classes.buttonSuccess]: success
});

if (typeof window !== "undefined" && window.localStorage.getItem("token")) {
return <Redirect to="/" />;
Expand Down Expand Up @@ -126,6 +153,7 @@ const Login = ({ onLogin, classes }: Props) => {
}}
>
<TextField
disabled={showPreloader}
inputRef={el => (email = el)}
className={classes.text}
label="Type your email"
Expand All @@ -138,6 +166,7 @@ const Login = ({ onLogin, classes }: Props) => {
}}
/>
<TextField
disabled={showPreloader}
inputRef={el => (password = el)}
type="password"
className={classes.text}
Expand All @@ -156,16 +185,26 @@ const Login = ({ onLogin, classes }: Props) => {
}}
>
<br />
<Button
onClick={() => onLogin(email, password)}
size="large"
variant="raised"
color="primary"
className={classes.button}
>
Sign in
<Check />
</Button>
<div className={classes.wrapper}>
<Button
onClick={() => onLogin(email, password)}
size="large"
variant="raised"
color="primary"
className={buttonClassname}
disabled={showPreloader}
>
Sign In
<Check />
</Button>
{showPreloader && (
<CircularProgress
size={24}
className={classes.buttonProgress}
/>
)}
<br />
</div>
<br />
<Typography
component="p"
Expand All @@ -182,7 +221,8 @@ const Login = ({ onLogin, classes }: Props) => {
</div>
<br />
<div>
Sign in with:<br />
Sign in with:
<br />
<IconButton className={classes.button}>
<i
className="fa fa-facebook-square fa-2x"
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/Signup/Signup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe("<Signup /> User", () => {
expect(toJson(wrapper)).toMatchSnapshot();
});

it("should to change state qhen type in TextField", () => {
it("should to change state when type in TextField", () => {
let expectedState = {
confirmPassword: "",
email: "email@example.com",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ exports[`<Signup /> User should return a redirect component, bacause success pro
/>
`;

exports[`<Signup /> User should to change state qhen type in TextField 1`] = `
exports[`<Signup /> User should to change state when type in TextField 1`] = `
<WithStyles(Grid)
className="Signup-root-1"
container={true}
Expand Down
2 changes: 1 addition & 1 deletion src/client/reducers/__tests__/UserReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe("USer reducer", () => {
let action = {
type: actionTypes.LOADING_LOGIN
};
let newState = { ...initialState, message: "Loading..." };
let newState = { ...initialState, showPreloader: true };
let state = userReducer(initialState, action);

expect(state).toEqual(newState);
Expand Down
4 changes: 2 additions & 2 deletions src/client/reducers/userReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ export default function userReducer(state = initialState, action) {
case actionsType.LOADING_LOGIN:
return {
...state,
message: "Loading..."
showPreloader: true
};
case actionsType.LOGIN_SUCCESS:
case actionsType.LOGIN_ERROR:
var { message, success, user } = action;

return { ...state, message, success, user };
return { ...state,showPreloader: false, message, success, user };

case actionsType.LOGOUT_SUCCESS:
return { ...initialState };
Expand Down