This commit is contained in:
seb
2026-09-21 03:19:32 +02:00
parent 5594c59d88
commit 366d2517d6
17 changed files with 467 additions and 269 deletions

View File

@@ -1,5 +1,4 @@
import { Component } from 'react';
import { connect } from 'react-redux';
import { PureComponent } from 'react';
import Avatar from '@mui/material/Avatar';
import Box from '@mui/material/Box';
import IconButton from '@mui/material/IconButton';
@@ -11,12 +10,12 @@ import LogoutIcon from '@mui/icons-material/Logout';
import BusinessIcon from '@mui/icons-material/Business';
import SettingsIcon from '@mui/icons-material/Settings';
import { StorageManagerContext } from '../api/storageManagerContext';
import { logout } from '../store/authSlice';
import authAutomat from '../automats/authAutomat';
import CompanySettingsDialog from './CompanySettingsDialog';
import SettingsDialog from './settings/SettingsDialog';
import { notifyError } from '../utils/notify';
class UserMenu extends Component {
class UserMenu extends PureComponent {
static contextType = StorageManagerContext;
constructor(props) {
@@ -25,7 +24,7 @@ class UserMenu extends Component {
anchorEl: null,
settingsOpen: false,
numbersOpen: false,
user: null,
user: authAutomat.state.user,
};
this.handleOpenMenu = this.handleOpenMenu.bind(this);
this.handleCloseMenu = this.handleCloseMenu.bind(this);
@@ -37,16 +36,11 @@ class UserMenu extends Component {
}
componentDidMount() {
void this.loadUser();
this.unsubscribe = authAutomat.subscribe(this, 'user');
}
async loadUser() {
try {
const session = await this.context.authMePromise;
this.setState({ user: session.user });
} catch (err) {
notifyError(err);
}
componentWillUnmount() {
this.unsubscribe?.();
}
handleOpenMenu(event) {
@@ -76,7 +70,7 @@ class UserMenu extends Component {
async handleLogout() {
this.setState({ anchorEl: null });
try {
await this.props.logout().unwrap();
await authAutomat.actions.logout();
await this.context.updateAuthMe();
} catch (err) {
notifyError(err);
@@ -134,8 +128,4 @@ class UserMenu extends Component {
}
}
const mapDispatchToProps = (dispatch) => ({
logout: () => dispatch(logout()),
});
export default connect(null, mapDispatchToProps)(UserMenu);
export default UserMenu;