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

[RFR] Use hooks on demo (last PR) #3345

Merged
merged 2 commits into from
Jul 14, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions examples/demo/src/layout/Login.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { propTypes, reduxForm, Field } from 'redux-form';
import { connect } from 'react-redux';
import { useDispatch, useSelector } from 'react-redux';
import compose from 'recompose/compose';

import Avatar from '@material-ui/core/Avatar';
Expand All @@ -10,15 +10,15 @@ import Card from '@material-ui/core/Card';
import CardActions from '@material-ui/core/CardActions';
import CircularProgress from '@material-ui/core/CircularProgress';
import TextField from '@material-ui/core/TextField';
import { createMuiTheme, withStyles } from '@material-ui/core/styles';
import { createMuiTheme, makeStyles } from '@material-ui/core/styles';
import { ThemeProvider } from '@material-ui/styles';
import LockIcon from '@material-ui/icons/Lock';

import { Notification, useTranslate, translate, userLogin } from 'react-admin';

import { lightTheme } from './themes';

const styles = theme => ({
const useStyles = makeStyles(theme => ({
main: {
display: 'flex',
flexDirection: 'column',
Expand Down Expand Up @@ -56,7 +56,7 @@ const styles = theme => ({
actions: {
padding: '0 1em 1em 1em',
},
});
}));

// see http://redux-form.com/6.4.3/examples/material-ui/
const renderInput = ({
Expand All @@ -73,10 +73,16 @@ const renderInput = ({
/>
);

const Login = ({ classes, handleSubmit, isLoading, location, userLogin }) => {
const Login = ({ handleSubmit, location }) => {
const translate = useTranslate();
const classes = useStyles();
const dispatch = useDispatch();
const isLoading = useSelector(state => state.admin.loading > 0);

const login = auth =>
userLogin(auth, location.state ? location.state.nextPathname : '/');
dispatch(
userLogin(auth, location.state ? location.state.nextPathname : '/')
);

return (
<div className={classes.main}>
Expand Down Expand Up @@ -133,13 +139,9 @@ const Login = ({ classes, handleSubmit, isLoading, location, userLogin }) => {
Login.propTypes = {
...propTypes,
authProvider: PropTypes.func,
classes: PropTypes.object,
previousRoute: PropTypes.string,
userLogin: PropTypes.func.isRequired,
};

const mapStateToProps = state => ({ isLoading: state.admin.loading > 0 });

const enhance = compose(
translate,
fzaninotto marked this conversation as resolved.
Show resolved Hide resolved
reduxForm({
Expand All @@ -155,12 +157,7 @@ const enhance = compose(
}
return errors;
},
}),
connect(
mapStateToProps,
{ userLogin }
),
withStyles(styles)
})
);

const EnhancedLogin = enhance(Login);
Expand Down
Loading