network-resurrector-frontend/src/features/login/components/LoginComponent.js

59 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-12-19 04:22:38 +02:00
import React, { useContext } from "react";
2020-12-16 01:29:56 +02:00
import { makeStyles } from "@material-ui/core/styles";
import { TextField, InputAdornment } from "@material-ui/core";
2020-12-19 03:12:10 +02:00
import { AccountCircleOutlined } from "@material-ui/icons";
import PasswordField from "../../../components/common/inputs/PasswordField";
2020-12-19 04:22:38 +02:00
import {
ApplicationStateContext,
ApplicationDispatchContext
} from "../../../state/ApplicationContexts";
2020-12-23 02:24:38 +02:00
import { useTranslation } from "react-i18next";
2020-12-16 01:29:56 +02:00
2020-12-19 02:28:20 +02:00
const useStyles = makeStyles(theme => ({
2020-12-19 03:12:10 +02:00
field: {
margin: theme.spacing(1),
width: "20ch"
2020-12-19 02:28:20 +02:00
}
2020-12-16 01:29:56 +02:00
}));
2020-12-08 03:03:15 +02:00
const LoginComponent = () => {
2020-12-16 01:29:56 +02:00
const classes = useStyles();
2020-12-23 02:24:38 +02:00
const { t } = useTranslation();
2020-12-19 04:22:38 +02:00
const state = useContext(ApplicationStateContext);
const dispatchActions = useContext(ApplicationDispatchContext);
const handleChange = prop => event => {
dispatchActions.onCredentialsChange(prop, event.target.value);
};
2020-12-16 01:29:56 +02:00
return (
<div>
<TextField
2020-12-19 03:12:10 +02:00
className={classes.field}
2020-12-16 01:29:56 +02:00
id="username"
2020-12-23 02:24:38 +02:00
label={t("Login.Username")}
2020-12-19 04:22:38 +02:00
onChange={handleChange("userName")}
value={state.credentials.userName}
2020-12-16 01:29:56 +02:00
InputProps={{
startAdornment: (
<InputAdornment position="start">
<AccountCircleOutlined />
</InputAdornment>
2020-12-19 02:28:20 +02:00
)
2020-12-16 01:29:56 +02:00
}}
/>
<br />
2020-12-19 04:22:38 +02:00
<PasswordField
id="password"
2020-12-23 02:24:38 +02:00
label={t("Login.Password")}
2020-12-19 04:22:38 +02:00
className={classes.field}
onChange={handleChange("password")}
value={state.credentials.password}
/>
2020-12-16 01:29:56 +02:00
</div>
);
2020-12-08 03:03:15 +02:00
};
export default LoginComponent;