2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 19:46:46 +00:00

Tweak checks for error messages (#7598)

* Tweak checks for error messages

- Ensure user is logged in before checking permissions

* Fix <InstanceDetail/>

* Tweak notification check
This commit is contained in:
Oliver 2024-07-10 13:15:21 +10:00 committed by GitHub
parent cd1d4a4be0
commit 2d8f5e9006
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 38 additions and 7 deletions

View File

@ -47,6 +47,10 @@ export function Header() {
queryKey: ['notification-count'], queryKey: ['notification-count'],
enabled: isLoggedIn(), enabled: isLoggedIn(),
queryFn: async () => { queryFn: async () => {
if (!isLoggedIn()) {
return null;
}
try { try {
const params = { const params = {
params: { params: {
@ -62,7 +66,7 @@ export function Header() {
setNotificationCount(response?.data?.count ?? 0); setNotificationCount(response?.data?.count ?? 0);
return response?.data ?? null; return response?.data ?? null;
} catch (error) { } catch (error) {
return error; return null;
} }
}, },
refetchInterval: 30000, refetchInterval: 30000,

View File

@ -1,5 +1,6 @@
import { LoadingOverlay } from '@mantine/core'; import { LoadingOverlay } from '@mantine/core';
import { useUserState } from '../../states/UserState';
import ClientError from '../errors/ClientError'; import ClientError from '../errors/ClientError';
import ServerError from '../errors/ServerError'; import ServerError from '../errors/ServerError';
@ -12,7 +13,9 @@ export default function InstanceDetail({
loading: boolean; loading: boolean;
children: React.ReactNode; children: React.ReactNode;
}) { }) {
if (loading) { const user = useUserState();
if (loading || !user.isLoggedIn()) {
return <LoadingOverlay />; return <LoadingOverlay />;
} }

View File

@ -1,5 +1,13 @@
import { Trans, t } from '@lingui/macro'; import { Trans, t } from '@lingui/macro';
import { Divider, Paper, SimpleGrid, Stack, Text, Title } from '@mantine/core'; import {
Divider,
Paper,
SimpleGrid,
Skeleton,
Stack,
Text,
Title
} from '@mantine/core';
import { import {
IconCoins, IconCoins,
IconCpu, IconCpu,
@ -201,6 +209,10 @@ export default function AdminCenter() {
</Stack> </Stack>
); );
if (!user.isLoggedIn()) {
return <Skeleton />;
}
return ( return (
<> <>
{user.isStaff() ? ( {user.isStaff() ? (

View File

@ -1,5 +1,5 @@
import { Trans, t } from '@lingui/macro'; import { Trans, t } from '@lingui/macro';
import { Stack } from '@mantine/core'; import { Skeleton, Stack } from '@mantine/core';
import { import {
IconBellCog, IconBellCog,
IconCategory, IconCategory,
@ -306,6 +306,10 @@ export default function SystemSettings() {
const [server] = useServerApiState((state) => [state.server]); const [server] = useServerApiState((state) => [state.server]);
if (!user.isLoggedIn()) {
return <Skeleton />;
}
return ( return (
<> <>
{user.isStaff() ? ( {user.isStaff() ? (

View File

@ -1,5 +1,5 @@
import { Trans, t } from '@lingui/macro'; import { Trans, t } from '@lingui/macro';
import { Stack } from '@mantine/core'; import { Skeleton, Stack } from '@mantine/core';
import { import {
IconBellCog, IconBellCog,
IconDeviceDesktop, IconDeviceDesktop,
@ -23,6 +23,11 @@ import { AccountContent } from './AccountSettings/UserPanel';
* User settings page * User settings page
*/ */
export default function UserSettings() { export default function UserSettings() {
const [user, isLoggedIn] = useUserState((state) => [
state.user,
state.isLoggedIn
]);
const userSettingsPanels: PanelType[] = useMemo(() => { const userSettingsPanels: PanelType[] = useMemo(() => {
return [ return [
{ {
@ -109,7 +114,10 @@ export default function UserSettings() {
} }
]; ];
}, []); }, []);
const [user] = useUserState((state) => [state.user]);
if (!isLoggedIn()) {
return <Skeleton />;
}
return ( return (
<> <>

View File

@ -23,7 +23,7 @@ import {
IconVersions IconVersions
} from '@tabler/icons-react'; } from '@tabler/icons-react';
import { useSuspenseQuery } from '@tanstack/react-query'; import { useSuspenseQuery } from '@tanstack/react-query';
import { ReactNode, useEffect, useMemo, useState } from 'react'; import { ReactNode, useMemo, useState } from 'react';
import { useNavigate, useParams } from 'react-router-dom'; import { useNavigate, useParams } from 'react-router-dom';
import { api } from '../../App'; import { api } from '../../App';