automat
This commit is contained in:
31
src/App.jsx
31
src/App.jsx
@@ -1,9 +1,8 @@
|
||||
import { Component, Suspense } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { PureComponent, Suspense } from 'react';
|
||||
import Box from '@mui/material/Box';
|
||||
import CircularProgress from '@mui/material/CircularProgress';
|
||||
import { RouterProvider } from 'react-router-dom';
|
||||
import { selectAuthStatus, selectNeedsCompanySetup } from './store/authSlice';
|
||||
import authAutomat from './automats/authAutomat';
|
||||
import LoginPage from './components/LoginPage';
|
||||
import CompanySetupDialog from './components/CompanySetupDialog';
|
||||
import { router } from './appRouter';
|
||||
@@ -24,9 +23,22 @@ function PageFallback() {
|
||||
);
|
||||
}
|
||||
|
||||
class App extends Component {
|
||||
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, needsCompanySetup } = this.props;
|
||||
const { status, user } = this.state;
|
||||
|
||||
if (status === 'loading') {
|
||||
return (
|
||||
@@ -48,7 +60,7 @@ class App extends Component {
|
||||
return <LoginPage />;
|
||||
}
|
||||
|
||||
if (needsCompanySetup) {
|
||||
if (user?.selectedCompanyId == null) {
|
||||
return <CompanySetupDialog />;
|
||||
}
|
||||
|
||||
@@ -60,9 +72,4 @@ class App extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
status: selectAuthStatus(state),
|
||||
needsCompanySetup: selectNeedsCompanySetup(state),
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps)(App);
|
||||
export default App;
|
||||
|
||||
Reference in New Issue
Block a user