diff --git a/src/ui/components/AppShell/index.tsx b/src/ui/components/AppShell/index.tsx index 10f65329..cd699507 100644 --- a/src/ui/components/AppShell/index.tsx +++ b/src/ui/components/AppShell/index.tsx @@ -4,6 +4,7 @@ import { Group, LoadingOverlay, NavLink, + Skeleton, Text, useMantineColorScheme, } from '@mantine/core'; @@ -142,6 +143,7 @@ export const renderNavItems = ( resourceDef={{ service: 'core', validRoles: item.validRoles }} isAppShell={false} key={`${item.name}-wrap`} + loadingSkeleton={} > {link} diff --git a/src/ui/components/AuthGuard/index.tsx b/src/ui/components/AuthGuard/index.tsx index cf7e12b9..ed20cb05 100644 --- a/src/ui/components/AuthGuard/index.tsx +++ b/src/ui/components/AuthGuard/index.tsx @@ -23,7 +23,7 @@ export type ResourceDefinition = { const getAuthCacheKey = (service: ValidService, route: string) => `${CACHE_KEY_PREFIX}${service}_${route}`; -const getCachedResponse = (service: ValidService, route: string): CacheData | null => { +export const getCachedResponse = (service: ValidService, route: string): CacheData | null => { const cached = sessionStorage.getItem(getAuthCacheKey(service, route)); if (!cached) return null; @@ -65,14 +65,16 @@ export const AuthGuard: React.FC< resourceDef: ResourceDefinition; children: ReactNode; isAppShell?: boolean; + loadingSkeleton?: ReactNode; } & AcmAppShellProps -> = ({ resourceDef, children, isAppShell = true, ...appShellProps }) => { +> = ({ resourceDef, children, isAppShell = true, loadingSkeleton, ...appShellProps }) => { const { service, validRoles } = resourceDef; const { baseEndpoint, authCheckRoute, friendlyName } = getRunEnvironmentConfig().ServiceConfiguration[service]; const [isAuthenticated, setIsAuthenticated] = useState(null); const [username, setUsername] = useState(null); const [roles, setRoles] = useState(null); + const [isLoading, setIsLoading] = useState(true); const api = useApi(service); useEffect(() => { @@ -88,6 +90,7 @@ export const AuthGuard: React.FC< } // Check for cached response first + setIsLoading(true); const cachedData = getCachedResponse(service, authCheckRoute); if (cachedData !== null) { const userRoles = cachedData.data.roles; @@ -101,6 +104,7 @@ export const AuthGuard: React.FC< setUsername(cachedData.data.username); setRoles(cachedData.data.roles); setIsAuthenticated(authenticated); + setIsLoading(false); return; } @@ -120,15 +124,19 @@ export const AuthGuard: React.FC< setIsAuthenticated(authenticated); setRoles(result.data.roles); setUsername(result.data.username); + setIsLoading(false); } catch (e) { setIsAuthenticated(false); + setIsLoading(false); console.error(e); } } getAuth(); }, [baseEndpoint, authCheckRoute, service]); - + if (isLoading && loadingSkeleton) { + return loadingSkeleton; + } if (isAuthenticated === null) { if (isAppShell) { return ; diff --git a/src/ui/pages/events/ManageEvent.page.tsx b/src/ui/pages/events/ManageEvent.page.tsx index 9d6e7a5e..9dc36e7c 100644 --- a/src/ui/pages/events/ManageEvent.page.tsx +++ b/src/ui/pages/events/ManageEvent.page.tsx @@ -155,8 +155,10 @@ export const ManageEventPage: React.FC = () => { return ( - {isEditing ? `Edit` : `Add`} Event + + {isEditing ? `Edit` : `Create`} Event +