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