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-16 02:34:07 +02:00
|
|
|
import Button from "@material-ui/core/Button";
|
2020-12-23 03:37:26 +02:00
|
|
|
import { authenticate } from "../../../utils/identity";
|
|
|
|
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);
|
|
|
|
const dispatchActions = useContext(ApplicationDispatchContext);
|
2020-12-16 02:34:07 +02:00
|
|
|
|
2020-12-23 03:37:26 +02:00
|
|
|
const handleLogin = async () => {
|
|
|
|
const { userName, password } = state.credentials;
|
|
|
|
const token = await authenticate(userName, password);
|
|
|
|
dispatchActions.onAuthorizationTokenChange(token);
|
2020-12-16 02:34:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<LoginComponent />
|
2020-12-23 03:37:26 +02:00
|
|
|
<Button variant="contained" color="primary" onClick={handleLogin}>
|
|
|
|
Login
|
2020-12-16 02:34:07 +02:00
|
|
|
</Button>
|
|
|
|
</>
|
|
|
|
);
|
2020-12-08 03:03:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default LoginContainer;
|