import * as React from "react"; import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { useAuth, AuthPage } from "../react-auth"; import { UploadProvider } from "./providers/UploadProvider"; import AdminLayout from "./components/AdminLayout"; import ResourceView from "./components/ResourceView"; import { getAppConfig } from "./config"; import { initializeApiClients } from "./api/client"; import { AppConfig } from "./types/config"; import { Box, Typography, Paper, CircularProgress } from "@mui/material"; import { Routes, Route, useNavigate, useParams, Navigate, } from "react-router-dom"; const queryClient = new QueryClient(); // Create a context for the app config export const ConfigContext = React.createContext(null); function Dashboard({ basePath }: { basePath: string }) { const config = React.useContext(ConfigContext); const navigate = useNavigate(); return ( Welcome to the Admin Panel Select a resource from the sidebar to manage data. {config?.resources.map((res) => ( navigate(`/admin/${res.name}`)} > {res.pluralLabel} Manage {res.pluralLabel.toLowerCase()} ))} ); } import ProfileView from "./components/ProfileView"; function AdminApp({ basePath }: { basePath: string }) { const { currentUser, login, logout, loading, error } = useAuth(); const config = React.useContext(ConfigContext); const navigate = useNavigate(); if (!currentUser) { return ( {}} // Disable registration for Admin loading={loading} error={error} onSwitchMode={() => {}} onBack={() => {}} currentUser={null} /> ); } return ( navigate(`/admin/${name}`)} resources={config?.resources || []} > } /> } /> } /> } /> } /> } /> ); } function ResourceRouteWrapper() { const { resourceName } = useParams(); const config = React.useContext(ConfigContext); const selectedResource = config?.resources.find((r) => r.name === resourceName); if (!selectedResource) return Resource not found; return ; } interface AdminProps { basePath?: string; resourceOverrides?: Record; profileConfig?: any; } export default function Admin({ basePath = "/admin", resourceOverrides = {}, profileConfig = {} }: AdminProps) { const [config, setConfig] = React.useState(null); React.useEffect(() => { getAppConfig(resourceOverrides, profileConfig).then((cfg) => { initializeApiClients(cfg.baseUrl, cfg.authBaseUrl); setConfig(cfg); }); }, [resourceOverrides, profileConfig]); if (!config) { return ( ); } return ( ); }