import { PureComponent, Suspense } from 'react';
import Box from '@mui/material/Box';
import CircularProgress from '@mui/material/CircularProgress';
import { RouterProvider } from 'react-router-dom';
import authAutomat from './automats/authAutomat';
import LoginPage from './components/LoginPage';
import CompanySetupDialog from './components/CompanySetupDialog';
import { router } from './appRouter';
function PageFallback() {
return (
);
}
class App extends PureComponent {
constructor(props) {
super(props);
this.state = authAutomat.state;
}
componentDidMount() {
this.unsubscribe = authAutomat.subscribe(this, ['status', 'user']);
}
componentWillUnmount() {
this.unsubscribe?.();
}
render() {
const { status, user } = this.state;
if (status === 'loading') {
return (
);
}
if (status !== 'authed') {
if (typeof window !== 'undefined' && window.location.pathname === '/oauth/authorize') {
const returnTo = encodeURIComponent(window.location.pathname + window.location.search);
window.history.replaceState(null, '', `/login?returnTo=${returnTo}`);
}
return ;
}
const isOAuthAuthorize = typeof window !== 'undefined' && window.location.pathname === '/oauth/authorize';
if (user?.selectedCompanyId == null && !isOAuthAuthorize) {
return ;
}
return (
}>
);
}
}
export default App;