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

34 lines
862 B
JavaScript
Raw Normal View History

2020-12-23 03:37:26 +02:00
import React, { useContext } from "react";
2020-12-08 03:03:15 +02:00
import LoginComponent from "./LoginComponent";
2020-12-23 03:37:26 +02:00
import { authenticate } from "../../../utils/identity";
2020-12-24 02:39:48 +02:00
import {
ApplicationStateContext,
ApplicationDispatchContext
} from "../../../state/ApplicationContexts";
2020-12-08 03:03:15 +02:00
const LoginContainer = () => {
2020-12-23 03:37:26 +02:00
const state = useContext(ApplicationStateContext);
2020-12-24 02:39:48 +02:00
const dispatchActions = useContext(ApplicationDispatchContext);
const handleChange = prop => event => {
dispatchActions.onCredentialsChange(prop, event.target.value);
};
2020-12-16 02:34:07 +02:00
2020-12-23 03:37:26 +02:00
const handleLogin = async () => {
const { userName, password } = state.credentials;
2020-12-23 10:42:20 +02:00
await authenticate(userName, password);
2020-12-16 02:34:07 +02:00
};
return (
<>
2020-12-24 02:39:48 +02:00
<LoginComponent
credentials={state.credentials}
onChange={handleChange}
onLogin={handleLogin}
/>
2020-12-16 02:34:07 +02:00
</>
);
2020-12-08 03:03:15 +02:00
};
export default LoginContainer;