From 3fea7708c492e02a159bbe951f34b2763ad1692f Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Thu, 24 Dec 2020 02:39:48 +0200 Subject: [PATCH] login step refactor --- public/locales/en/translations.json | 3 +- public/locales/ro/translations.json | 3 +- .../login/components/LoginComponent.js | 36 +++++++++---------- .../login/components/LoginContainer.js | 20 +++++++---- 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/public/locales/en/translations.json b/public/locales/en/translations.json index 90383a1..06ed6aa 100644 --- a/public/locales/en/translations.json +++ b/public/locales/en/translations.json @@ -19,6 +19,7 @@ }, "Login": { "Username": "Username", - "Password": "Password" + "Password": "Password", + "Label": "Login" } } diff --git a/public/locales/ro/translations.json b/public/locales/ro/translations.json index f44da64..644e73e 100644 --- a/public/locales/ro/translations.json +++ b/public/locales/ro/translations.json @@ -10,6 +10,7 @@ }, "Login": { "Username": "Utilizator", - "Password": "Parolă" + "Password": "Parolă", + "Label": "Autentificare" } } diff --git a/src/features/login/components/LoginComponent.js b/src/features/login/components/LoginComponent.js index 997f9f7..155fa24 100644 --- a/src/features/login/components/LoginComponent.js +++ b/src/features/login/components/LoginComponent.js @@ -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 { TextField, InputAdornment } from "@material-ui/core"; +import { TextField, InputAdornment, Button } from "@material-ui/core"; import { AccountCircleOutlined } from "@material-ui/icons"; import PasswordField from "../../../components/common/inputs/PasswordField"; -import { - ApplicationStateContext, - ApplicationDispatchContext -} from "../../../state/ApplicationContexts"; import { useTranslation } from "react-i18next"; const useStyles = makeStyles(theme => ({ @@ -16,25 +13,18 @@ const useStyles = makeStyles(theme => ({ } })); -const LoginComponent = () => { +const LoginComponent = ({ credentials, onChange, onLogin }) => { const classes = useStyles(); const { t } = useTranslation(); - const state = useContext(ApplicationStateContext); - const dispatchActions = useContext(ApplicationDispatchContext); - - const handleChange = prop => event => { - dispatchActions.onCredentialsChange(prop, event.target.value); - }; - return (
@@ -48,11 +38,21 @@ const LoginComponent = () => { id="password" label={t("Login.Password")} className={classes.field} - onChange={handleChange("password")} - value={state.credentials.password} + onChange={onChange("password")} + value={credentials.password} /> +
+
); }; +LoginComponent.propTypes = { + credentials: PropTypes.object.isRequired, + onChange: PropTypes.func.isRequired, + onLogin: PropTypes.func.isRequired +}; + export default LoginComponent; diff --git a/src/features/login/components/LoginContainer.js b/src/features/login/components/LoginContainer.js index ef6353a..60f784b 100644 --- a/src/features/login/components/LoginContainer.js +++ b/src/features/login/components/LoginContainer.js @@ -1,11 +1,18 @@ import React, { useContext } from "react"; import LoginComponent from "./LoginComponent"; -import Button from "@material-ui/core/Button"; import { authenticate } from "../../../utils/identity"; -import { ApplicationStateContext } from "../../../state/ApplicationContexts"; +import { + ApplicationStateContext, + ApplicationDispatchContext +} from "../../../state/ApplicationContexts"; const LoginContainer = () => { const state = useContext(ApplicationStateContext); + const dispatchActions = useContext(ApplicationDispatchContext); + + const handleChange = prop => event => { + dispatchActions.onCredentialsChange(prop, event.target.value); + }; const handleLogin = async () => { const { userName, password } = state.credentials; @@ -14,10 +21,11 @@ const LoginContainer = () => { return ( <> - - + ); };