added last online and unauthorized status handling
parent
027713fedd
commit
5ab2dfa0f1
|
@ -746,7 +746,6 @@ function InputRequiredHandler({
|
|||
/>
|
||||
</Form.Item>
|
||||
);
|
||||
break;
|
||||
default:
|
||||
notificationApi["error"]({
|
||||
message: `Type ${groupTaskParameter.type} not implemented`,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { LockOutlined, LoginOutlined, UserOutlined } from "@ant-design/icons";
|
||||
import { Button, Form, Input, Modal, notification } from "antd";
|
||||
import PropTypes from "prop-types";
|
||||
import { Constants } from "../../utils";
|
||||
import { Constants, setUserSessionToLocalStorage } from "../../utils";
|
||||
import { useState } from "react";
|
||||
import { Buffer } from "buffer";
|
||||
|
||||
|
@ -44,7 +44,7 @@ export default function Login({ setUserSession }) {
|
|||
return Promise.reject(res.status);
|
||||
})
|
||||
.then((data) => {
|
||||
setUserSession(data.Session);
|
||||
setUserSessionToLocalStorage(data.Session);
|
||||
window.location.href = "/";
|
||||
})
|
||||
.catch((err) => {
|
||||
|
|
|
@ -5,6 +5,7 @@ import {
|
|||
WebSocketContext,
|
||||
getUserId,
|
||||
getUserSessionFromLocalStorage,
|
||||
handleUnauthorizedStatus,
|
||||
} from "../../utils";
|
||||
import { useContext } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
|
@ -59,7 +60,9 @@ const columns = [
|
|||
"Content-Type": "application/json",
|
||||
"X-Authorization": getUserSessionFromLocalStorage(),
|
||||
},
|
||||
}).catch((err) => console.error(err));
|
||||
})
|
||||
.then((res) => handleUnauthorizedStatus(res.status))
|
||||
.catch((err) => console.error(err));
|
||||
}}
|
||||
>
|
||||
<Link to="#">Use scanner</Link>
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
WebSocketContext,
|
||||
getConnectionStatusItem,
|
||||
getUserSessionFromLocalStorage,
|
||||
handleUnauthorizedStatus,
|
||||
} from "../../utils";
|
||||
import { Link } from "react-router-dom";
|
||||
|
||||
|
@ -47,9 +48,11 @@ const columns = [
|
|||
"Content-Type": "application/json",
|
||||
"X-Authorization": getUserSessionFromLocalStorage(),
|
||||
},
|
||||
}).catch((err) => {
|
||||
console.error(err);
|
||||
});
|
||||
})
|
||||
.then((res) => handleUnauthorizedStatus(res.status))
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
});
|
||||
}}
|
||||
>
|
||||
Sign out
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { Popover, Table } from "antd";
|
||||
import {
|
||||
FormatDatetime,
|
||||
MyAvatar,
|
||||
WebSocketContext,
|
||||
getConnectionStatusItem,
|
||||
|
@ -55,6 +56,7 @@ export default function Users() {
|
|||
),
|
||||
connectionStatus: getConnectionStatusItem(user.ConnectionStatus),
|
||||
username: user.Username,
|
||||
lastOnline: FormatDatetime(user.LastOnline),
|
||||
});
|
||||
});
|
||||
|
||||
|
|
22
src/utils.js
22
src/utils.js
|
@ -62,7 +62,7 @@ export function UseUserSession() {
|
|||
if (session === undefined) {
|
||||
localStorage.removeItem("session");
|
||||
} else {
|
||||
localStorage.setItem("session", JSON.stringify(session));
|
||||
setUserSessionToLocalStorage(session);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -73,7 +73,18 @@ export function UseUserSession() {
|
|||
}
|
||||
|
||||
export function getUserSessionFromLocalStorage() {
|
||||
return JSON.parse(localStorage.getItem("session"));
|
||||
return localStorage.getItem("session");
|
||||
}
|
||||
|
||||
export function setUserSessionToLocalStorage(session) {
|
||||
localStorage.setItem("session", session);
|
||||
}
|
||||
|
||||
export function handleUnauthorizedStatus(status) {
|
||||
if (status === 401) {
|
||||
setUserSessionToLocalStorage("");
|
||||
window.location.href = "/";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -187,9 +198,10 @@ export function WebSocketProvider({
|
|||
setAllUsers((arr) => {
|
||||
const newArr = [...arr];
|
||||
|
||||
newArr[
|
||||
arr.findIndex((arr1) => arr1.Id === body.UserId)
|
||||
].ConnectionStatus = body.ConnectionStatus;
|
||||
const arrIndex = arr.findIndex((arr1) => arr1.Id === body.UserId);
|
||||
|
||||
newArr[arrIndex].ConnectionStatus = body.ConnectionStatus;
|
||||
newArr[arrIndex].LastOnline = body.LastOnline;
|
||||
|
||||
return newArr;
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue