{
@@ -144,5 +131,7 @@ export default function Scanners() {
dataSource={getTableItems()}
/>
>
- );
+ ); */
+
+ return <>>;
}
diff --git a/src/Pages/UserProfile/index.js b/src/Pages/UserProfile/index.js
index ca29c1f..dd996f5 100644
--- a/src/Pages/UserProfile/index.js
+++ b/src/Pages/UserProfile/index.js
@@ -38,10 +38,14 @@ import {
import { MyUserAvatar } from "../../Components/MyAvatar";
import { useUserProfileContext } from "../../Contexts/UserProfileContext";
import { useWebSocketContext } from "../../Contexts/WebSocketContext";
+import { useAppContext } from "../../Contexts/AppContext";
+import { useSideBarContext } from "../../Contexts/SideBarContext";
export default function UserProfile() {
const webSocketContext = useWebSocketContext();
- const { userProfile, setUserProfile } = useUserProfileContext();
+ const appContext = useAppContext();
+ const sideBarContext = useSideBarContext();
+ const userProfileContext = useUserProfileContext();
const [notificationApi, notificationContextHolder] =
notification.useNotification();
const { t, i18n } = useTranslation();
@@ -182,7 +186,7 @@ export default function UserProfile() {
const getApiKeyTableItems = () => {
let items = [];
- userProfile.apiKeys.forEach((apiKey) => {
+ userProfileContext.apiKeys.forEach((apiKey) => {
items.push({
key: apiKey.Id,
name: apiKey.Name,
@@ -199,11 +203,11 @@ export default function UserProfile() {
const getSessionTableItems = () => {
let items = [];
- userProfile.sessions.sort(
+ userProfileContext.sessions.sort(
(a, b) => b.ConnectionStatus - a.ConnectionStatus
);
- userProfile.sessions.forEach((session) => {
+ userProfileContext.sessions.forEach((session) => {
items.push({
key: session.IdForDeletion,
userAgent: session.UserAgent,
@@ -233,14 +237,14 @@ export default function UserProfile() {
const isButtonDisabled = () => {
if (
!isEmailValid(email) ||
- userProfile.username.length < Constants.GLOBALS.MIN_USERNAME_LENGTH
+ sideBarContext.username.length < Constants.GLOBALS.MIN_USERNAME_LENGTH
) {
return true;
}
if (
- username !== userProfile.username ||
- email !== userProfile.email ||
+ username !== sideBarContext.username ||
+ email !== userProfileContext.email ||
(oldPassword !== "" &&
newPassword !== "" &&
newPassword === repeatedNewPassword)
@@ -254,11 +258,11 @@ export default function UserProfile() {
const handleOnSubmit = () => {
const changes = {};
- if (userProfile.username !== username) {
+ if (sideBarContext.username !== username) {
changes.username = username;
}
- if (userProfile.email !== email) {
+ if (userProfileContext.email !== email) {
changes.email = email;
}
@@ -287,20 +291,24 @@ export default function UserProfile() {
useEffect(() => {
myFetch("/user/profile", "GET").then((data) => {
- setUserProfile({
- id: data.Id,
- avatar: data.Avatar,
- username: data.Username,
- email: data.Email,
- sessions: data.Sessions,
- apiKeys: data.ApiKeys,
- });
+ userProfileContext.setEmail(data.Email);
+ userProfileContext.setSessions(data.Sessions);
+ userProfileContext.setApiKeys(data.ApiKeys);
- setUsername(data.Username);
setEmail(data.Email);
});
}, []);
+ useEffect(
+ () => setUsername(sideBarContext.username),
+ [sideBarContext.username]
+ );
+
+ useEffect(
+ () => setEmail(userProfileContext.email),
+ [userProfileContext.email]
+ );
+
return (
<>
{notificationContextHolder}
@@ -323,7 +331,7 @@ export default function UserProfile() {
"X-Authorization": getUserSessionFromLocalStorage(),
}}
>
-
+
@@ -356,10 +364,8 @@ export default function UserProfile() {
}
>
- setUserProfile({ ...userProfile, Username: e.target.value })
- }
+ value={username}
+ onChange={(e) => setUsername(e.target.value)}
minLength={Constants.GLOBALS.MIN_USERNAME_LENGTH}
maxLength={Constants.GLOBALS.MAX_USERNAME_LENGTH}
/>
@@ -367,14 +373,12 @@ export default function UserProfile() {
- setUserProfile({ ...userProfile, Email: e.target.value })
- }
+ value={email}
+ onChange={(e) => setEmail(e.target.value)}
/>
- {t("userProfile.header.yourSessions")} ({userProfile.sessions.length})
+ {t("userProfile.header.yourSessions")} (
+ {userProfileContext.sessions.length})
{hasPermission(
- userProfile.Permissions,
+ appContext.userPermissions,
Constants.PERMISSIONS.USER_PROFILE.API_KEYS
) && (
<>
@@ -460,7 +465,7 @@ export default function UserProfile() {
>
{t("userProfile.header.yourApiKeys")} (
- {userProfile.apiKeys.length}){" "}
+ {userProfileContext.apiKeys.length}){" "}
);
-}
-
+} */
+/*
function scrollToNextStep(groupTaskId, step) {
setTimeout(
() =>
@@ -1182,22 +1181,7 @@ function scrollToNextStep(groupTaskId, step) {
?.scrollIntoView({ behavior: "smooth" }),
200
);
-}
-
-// https://stackoverflow.com/a/52486921
-function setNativeValue(element, value) {
- let lastValue = element.value;
- element.value = value;
- let event = new Event("input", { target: element, bubbles: true });
- // React 15
- event.simulated = true;
- // React 16
- let tracker = element._valueTracker;
- if (tracker) {
- tracker.setValue(lastValue);
- }
- element.dispatchEvent(event);
-}
+} */
export function FormatDatetime(datetime) {
if (datetime === undefined || datetime === "0001-01-01T00:00:00Z") {
@@ -1273,31 +1257,33 @@ export function CapitalizeFirstLetter(string) {
}
export function hasPermission(userPermissions, permission) {
- return true;
- //return userPermissions.includes(permission);
+ if (userPermissions === null) return false;
+
+ return userPermissions.includes(permission);
}
export function hasXYPermission(userPermissions, permission, xyValue) {
- return true;
- /*return userPermissions.includes(
+ if (userPermissions === null) return false;
+
+ return userPermissions.includes(
permission.replace("XY", xyValue.toLowerCase())
- ); */
+ );
}
export function hasOnePermission(userPermissions, ...permissions) {
- return true;
- /*for (const permission of permissions) {
+ if (userPermissions === null) return false;
+
+ for (const permission of permissions) {
if (userPermissions.includes(permission)) {
return true;
}
}
- return false; */
+ return false;
}
export function hasOneXYPermission(userPermissions, xyValue, ...permissions) {
- return true;
- /* for (const permission of permissions) {
+ for (const permission of permissions) {
if (
userPermissions.includes(permission.replace("XY", xyValue.toLowerCase()))
) {
@@ -1305,7 +1291,7 @@ export function hasOneXYPermission(userPermissions, xyValue, ...permissions) {
}
}
- return false; */
+ return false;
}
export function EncodeStringToBase64(value) {