Generated project
This commit is contained in:
48
frontend/stores/app-store.ts
Normal file
48
frontend/stores/app-store.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { RouterLocation } from '@vaadin/router';
|
||||
import User from 'Frontend/generated/com/cubetiqs/fusion/data/entity/User';
|
||||
import Role from 'Frontend/generated/com/cubetiqs/fusion/data/Role';
|
||||
import { UserEndpoint } from 'Frontend/generated/UserEndpoint';
|
||||
import { makeAutoObservable } from 'mobx';
|
||||
|
||||
export class AppStore {
|
||||
applicationName = 'Fusion Management';
|
||||
|
||||
// The location, relative to the base path, e.g. "hello" when viewing "/hello"
|
||||
location = '';
|
||||
|
||||
currentViewTitle = '';
|
||||
|
||||
user: User | undefined = undefined;
|
||||
|
||||
constructor() {
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
setLocation(location: RouterLocation) {
|
||||
if (location.route) {
|
||||
this.location = location.route.path;
|
||||
} else if (location.pathname.startsWith(location.baseUrl)) {
|
||||
this.location = location.pathname.substr(location.baseUrl.length);
|
||||
} else {
|
||||
this.location = location.pathname;
|
||||
}
|
||||
this.currentViewTitle = (location?.route as any)?.title || '';
|
||||
}
|
||||
|
||||
async fetchUserInfo() {
|
||||
this.user = await UserEndpoint.getAuthenticatedUser();
|
||||
}
|
||||
|
||||
clearUserInfo() {
|
||||
this.user = undefined;
|
||||
}
|
||||
|
||||
get loggedIn() {
|
||||
return !!this.user;
|
||||
}
|
||||
|
||||
isUserInRole(role: Role) {
|
||||
return this.user?.roles?.includes(role);
|
||||
}
|
||||
}
|
||||
export const appStore = new AppStore();
|
||||
Reference in New Issue
Block a user