user changed notification

master
Tudor Stanciu 2020-12-24 18:39:28 +02:00
parent 2d53a734d4
commit a134c36553
4 changed files with 14 additions and 1 deletions

View File

@ -22,6 +22,7 @@
"Password": "Password", "Password": "Password",
"Label": "Login", "Label": "Login",
"ChangeUser": "Change user", "ChangeUser": "Change user",
"UserChanged": "User changed",
"Logout": "Logout", "Logout": "Logout",
"IncorrectCredentials": "Incorrect credentials.", "IncorrectCredentials": "Incorrect credentials.",
"Hello": "Hi, {{username}}", "Hello": "Hi, {{username}}",

View File

@ -13,6 +13,7 @@
"Password": "Parolă", "Password": "Parolă",
"Label": "Autentificare", "Label": "Autentificare",
"ChangeUser": "Schimbă utilizatorul", "ChangeUser": "Schimbă utilizatorul",
"UserChanged": "Utilizator schimbat",
"Logout": "Deconectare", "Logout": "Deconectare",
"IncorrectCredentials": "Credențiale incorecte.", "IncorrectCredentials": "Credențiale incorecte.",
"Hello": "Salut, {{username}}", "Hello": "Salut, {{username}}",

View File

@ -16,6 +16,7 @@ import {
import { AccountBox, RotateLeft, ExitToApp } from "@material-ui/icons"; import { AccountBox, RotateLeft, ExitToApp } from "@material-ui/icons";
import LoginComponent from "./LoginComponent"; import LoginComponent from "./LoginComponent";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useToast } from "../../../hooks";
const useStyles = makeStyles(theme => ({ const useStyles = makeStyles(theme => ({
card: { card: {
@ -42,6 +43,7 @@ const LoggedInComponent = ({
const classes = useStyles(); const classes = useStyles();
const { t } = useTranslation(); const { t } = useTranslation();
const [expanded, setExpanded] = useState(false); const [expanded, setExpanded] = useState(false);
const { info } = useToast();
const handleExpandLogin = () => { const handleExpandLogin = () => {
setExpanded(!expanded); setExpanded(!expanded);
@ -58,6 +60,14 @@ const LoggedInComponent = ({
return "N/A"; return "N/A";
}, [token, t]); }, [token, t]);
const handleLogin = async () => {
const result = await onLogin();
if (result) {
setExpanded(false);
info(t("Login.UserChanged"));
}
};
return ( return (
<Card className={classes.card}> <Card className={classes.card}>
<CardHeader <CardHeader
@ -107,7 +117,7 @@ const LoggedInComponent = ({
<LoginComponent <LoginComponent
credentials={credentials} credentials={credentials}
onChange={onChange} onChange={onChange}
onLogin={onLogin} onLogin={handleLogin}
/> />
</CardContent> </CardContent>
</Collapse> </Collapse>

View File

@ -27,6 +27,7 @@ const LoginContainer = () => {
const response = await authenticate(userName, password); const response = await authenticate(userName, password);
if (response.status === "SUCCESS") { if (response.status === "SUCCESS") {
dispatchActions.onAuthorizationTokenChange(response.token); dispatchActions.onAuthorizationTokenChange(response.token);
return response.token;
} else if (response.status === "BAD_CREDENTIALS") { } else if (response.status === "BAD_CREDENTIALS") {
error(t("Login.IncorrectCredentials")); error(t("Login.IncorrectCredentials"));
} }