Plop user data into the store when loading up the base component
This commit is contained in:
parent
328347fab7
commit
e20a768182
5 changed files with 87 additions and 28 deletions
|
@ -6,25 +6,47 @@ import AccountRouter from '@/routers/AccountRouter';
|
|||
import ServerOverviewContainer from '@/components/ServerOverviewContainer';
|
||||
import { StoreProvider } from 'easy-peasy';
|
||||
import { store } from '@/state';
|
||||
import { UserData } from '@/state/types';
|
||||
|
||||
class App extends React.PureComponent {
|
||||
componentDidMount () {
|
||||
|
||||
}
|
||||
|
||||
render () {
|
||||
return (
|
||||
<StoreProvider store={store}>
|
||||
<Router basename={'/'}>
|
||||
<div className={'mx-auto px-10 w-auto'} style={{ maxWidth: '1000px' }}>
|
||||
<Route exact path="/" component={ServerOverviewContainer}/>
|
||||
<Route path="/auth" component={AuthenticationRouter}/>
|
||||
<Route path="/account" component={AccountRouter}/>
|
||||
</div>
|
||||
</Router>
|
||||
</StoreProvider>
|
||||
);
|
||||
}
|
||||
interface WindowWithUser extends Window {
|
||||
PterodactylUser?: {
|
||||
uuid: string;
|
||||
username: string;
|
||||
email: string;
|
||||
root_admin: boolean;
|
||||
use_totp: boolean;
|
||||
language: string;
|
||||
updated_at: string;
|
||||
created_at: string;
|
||||
};
|
||||
}
|
||||
|
||||
const App = () => {
|
||||
const data = (window as WindowWithUser).PterodactylUser;
|
||||
if (data) {
|
||||
store.getActions().user.setUserData({
|
||||
uuid: data.uuid,
|
||||
username: data.username,
|
||||
email: data.email,
|
||||
language: data.language,
|
||||
rootAdmin: data.root_admin,
|
||||
useTotp: data.use_totp,
|
||||
createdAt: new Date(data.created_at),
|
||||
updatedAt: new Date(data.updated_at),
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<StoreProvider store={store}>
|
||||
<Router basename={'/'}>
|
||||
<div className={'mx-auto px-10 w-auto'} style={{ maxWidth: '1000px' }}>
|
||||
<Route exact path="/" component={ServerOverviewContainer}/>
|
||||
<Route path="/auth" component={AuthenticationRouter}/>
|
||||
<Route path="/account" component={AccountRouter}/>
|
||||
</div>
|
||||
</Router>
|
||||
</StoreProvider>
|
||||
);
|
||||
};
|
||||
|
||||
export default hot(App);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue