login step refactor
parent
324c35f7f4
commit
3fea7708c4
|
@ -19,6 +19,7 @@
|
||||||
},
|
},
|
||||||
"Login": {
|
"Login": {
|
||||||
"Username": "Username",
|
"Username": "Username",
|
||||||
"Password": "Password"
|
"Password": "Password",
|
||||||
|
"Label": "Login"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
},
|
},
|
||||||
"Login": {
|
"Login": {
|
||||||
"Username": "Utilizator",
|
"Username": "Utilizator",
|
||||||
"Password": "Parolă"
|
"Password": "Parolă",
|
||||||
|
"Label": "Autentificare"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
import React, { useContext } from "react";
|
import React from "react";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
import { makeStyles } from "@material-ui/core/styles";
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
import { TextField, InputAdornment } from "@material-ui/core";
|
import { TextField, InputAdornment, Button } from "@material-ui/core";
|
||||||
import { AccountCircleOutlined } from "@material-ui/icons";
|
import { AccountCircleOutlined } from "@material-ui/icons";
|
||||||
import PasswordField from "../../../components/common/inputs/PasswordField";
|
import PasswordField from "../../../components/common/inputs/PasswordField";
|
||||||
import {
|
|
||||||
ApplicationStateContext,
|
|
||||||
ApplicationDispatchContext
|
|
||||||
} from "../../../state/ApplicationContexts";
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
const useStyles = makeStyles(theme => ({
|
const useStyles = makeStyles(theme => ({
|
||||||
|
@ -16,25 +13,18 @@ const useStyles = makeStyles(theme => ({
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const LoginComponent = () => {
|
const LoginComponent = ({ credentials, onChange, onLogin }) => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const state = useContext(ApplicationStateContext);
|
|
||||||
const dispatchActions = useContext(ApplicationDispatchContext);
|
|
||||||
|
|
||||||
const handleChange = prop => event => {
|
|
||||||
dispatchActions.onCredentialsChange(prop, event.target.value);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<TextField
|
<TextField
|
||||||
className={classes.field}
|
className={classes.field}
|
||||||
id="username"
|
id="username"
|
||||||
label={t("Login.Username")}
|
label={t("Login.Username")}
|
||||||
onChange={handleChange("userName")}
|
onChange={onChange("userName")}
|
||||||
value={state.credentials.userName}
|
value={credentials.userName}
|
||||||
InputProps={{
|
InputProps={{
|
||||||
startAdornment: (
|
startAdornment: (
|
||||||
<InputAdornment position="start">
|
<InputAdornment position="start">
|
||||||
|
@ -48,11 +38,21 @@ const LoginComponent = () => {
|
||||||
id="password"
|
id="password"
|
||||||
label={t("Login.Password")}
|
label={t("Login.Password")}
|
||||||
className={classes.field}
|
className={classes.field}
|
||||||
onChange={handleChange("password")}
|
onChange={onChange("password")}
|
||||||
value={state.credentials.password}
|
value={credentials.password}
|
||||||
/>
|
/>
|
||||||
|
<br />
|
||||||
|
<Button variant="contained" color="primary" onClick={onLogin}>
|
||||||
|
{t("Login.Label")}
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
LoginComponent.propTypes = {
|
||||||
|
credentials: PropTypes.object.isRequired,
|
||||||
|
onChange: PropTypes.func.isRequired,
|
||||||
|
onLogin: PropTypes.func.isRequired
|
||||||
|
};
|
||||||
|
|
||||||
export default LoginComponent;
|
export default LoginComponent;
|
||||||
|
|
|
@ -1,11 +1,18 @@
|
||||||
import React, { useContext } from "react";
|
import React, { useContext } from "react";
|
||||||
import LoginComponent from "./LoginComponent";
|
import LoginComponent from "./LoginComponent";
|
||||||
import Button from "@material-ui/core/Button";
|
|
||||||
import { authenticate } from "../../../utils/identity";
|
import { authenticate } from "../../../utils/identity";
|
||||||
import { ApplicationStateContext } from "../../../state/ApplicationContexts";
|
import {
|
||||||
|
ApplicationStateContext,
|
||||||
|
ApplicationDispatchContext
|
||||||
|
} from "../../../state/ApplicationContexts";
|
||||||
|
|
||||||
const LoginContainer = () => {
|
const LoginContainer = () => {
|
||||||
const state = useContext(ApplicationStateContext);
|
const state = useContext(ApplicationStateContext);
|
||||||
|
const dispatchActions = useContext(ApplicationDispatchContext);
|
||||||
|
|
||||||
|
const handleChange = prop => event => {
|
||||||
|
dispatchActions.onCredentialsChange(prop, event.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
const handleLogin = async () => {
|
const handleLogin = async () => {
|
||||||
const { userName, password } = state.credentials;
|
const { userName, password } = state.credentials;
|
||||||
|
@ -14,10 +21,11 @@ const LoginContainer = () => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<LoginComponent />
|
<LoginComponent
|
||||||
<Button variant="contained" color="primary" onClick={handleLogin}>
|
credentials={state.credentials}
|
||||||
Login
|
onChange={handleChange}
|
||||||
</Button>
|
onLogin={handleLogin}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue