mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
fix: store changes
This commit is contained in:
parent
c67e097fc2
commit
7915121dd9
1
packages/types/src/instance.d.ts
vendored
1
packages/types/src/instance.d.ts
vendored
@ -14,6 +14,7 @@ export interface IInstance {
|
||||
namespace: string | null;
|
||||
is_telemetry_enabled: boolean;
|
||||
is_support_required: boolean;
|
||||
is_signup_screen_visited: boolean;
|
||||
created_by: string | null;
|
||||
updated_by: string | null;
|
||||
is_activated: boolean;
|
||||
|
59
web/store/instance.store.ts
Normal file
59
web/store/instance.store.ts
Normal file
@ -0,0 +1,59 @@
|
||||
import { observable, action, makeObservable } from "mobx";
|
||||
import set from "lodash/set";
|
||||
// types
|
||||
import { IInstance } from "@plane/types";
|
||||
// services
|
||||
import { InstanceService } from "services/instance.service";
|
||||
|
||||
export interface IInstanceStore {
|
||||
id: string | undefined;
|
||||
instance_id: string | undefined;
|
||||
instance_name: string | undefined;
|
||||
is_activated: boolean | undefined;
|
||||
is_setup_done: boolean | undefined;
|
||||
is_signup_screen_visited: boolean | undefined;
|
||||
is_support_required: boolean | undefined;
|
||||
is_telemetry_enabled: boolean | undefined;
|
||||
license_key: string | undefined;
|
||||
namespace: string | undefined;
|
||||
version: string | undefined;
|
||||
// actions
|
||||
fetchInstanceInfo: () => Promise<IInstance>;
|
||||
}
|
||||
|
||||
export class InstanceStore implements IInstanceStore {
|
||||
id: string | undefined;
|
||||
instance_id: string | undefined;
|
||||
instance_name: string | undefined;
|
||||
is_activated: boolean | undefined;
|
||||
is_setup_done: boolean | undefined;
|
||||
is_signup_screen_visited: boolean | undefined;
|
||||
is_support_required: boolean | undefined;
|
||||
is_telemetry_enabled: boolean | undefined;
|
||||
license_key: string | undefined;
|
||||
namespace: string | undefined;
|
||||
version: string | undefined;
|
||||
// service
|
||||
instanceService;
|
||||
|
||||
constructor() {
|
||||
makeObservable(this, {
|
||||
// actions
|
||||
fetchInstanceInfo: action,
|
||||
});
|
||||
|
||||
this.instanceService = new InstanceService();
|
||||
}
|
||||
|
||||
updateInstanceInfo = async (data: Partial<IInstance>) => {
|
||||
Object.keys(data).forEach((key) => {
|
||||
set(this, key, data[key as keyof IInstance]);
|
||||
});
|
||||
};
|
||||
|
||||
fetchInstanceInfo = async () => {
|
||||
const instance = await this.instanceService.getInstanceInfo();
|
||||
this.updateInstanceInfo(instance);
|
||||
return instance;
|
||||
};
|
||||
}
|
@ -17,6 +17,7 @@ import { IMentionStore, MentionStore } from "./mention.store";
|
||||
import { DashboardStore, IDashboardStore } from "./dashboard.store";
|
||||
import { IProjectPageStore, ProjectPageStore } from "./project-page.store";
|
||||
import { ILabelStore, LabelStore } from "./label.store";
|
||||
import { IInstanceStore, InstanceStore } from "./instance.store";
|
||||
|
||||
enableStaticRendering(typeof window === "undefined");
|
||||
|
||||
@ -38,10 +39,14 @@ export class RootStore {
|
||||
mention: IMentionStore;
|
||||
dashboard: IDashboardStore;
|
||||
projectPages: IProjectPageStore;
|
||||
// new store implementation
|
||||
instance: IInstanceStore;
|
||||
|
||||
constructor() {
|
||||
this.app = new AppRootStore(this);
|
||||
this.instance = new InstanceStore();
|
||||
this.user = new UserRootStore(this);
|
||||
// old implementation
|
||||
this.app = new AppRootStore(this);
|
||||
this.workspaceRoot = new WorkspaceRootStore(this);
|
||||
this.projectRoot = new ProjectRootStore(this);
|
||||
this.memberRoot = new MemberRootStore(this);
|
||||
|
80
web/store/user/current-user.store.ts
Normal file
80
web/store/user/current-user.store.ts
Normal file
@ -0,0 +1,80 @@
|
||||
import { makeObservable, runInAction, observable } from "mobx";
|
||||
import set from "lodash/set";
|
||||
// types
|
||||
import { IUser } from "@plane/types";
|
||||
// store
|
||||
import { UserStore, IUserStore } from "./user.store";
|
||||
// services
|
||||
import { UserService } from "services/user.service";
|
||||
|
||||
interface ICurrentUserStore extends IUserStore {
|
||||
// fetch actions
|
||||
fetchCurrentUser: () => Promise<IUser>;
|
||||
fetchUserInstanceAdminStatus: () => Promise<boolean>;
|
||||
updateCurrentUser: (data: Partial<IUser>) => Promise<IUser>;
|
||||
}
|
||||
|
||||
export class CurrentUserStore extends UserStore implements ICurrentUserStore {
|
||||
is_instance_admin: boolean = false;
|
||||
|
||||
userService;
|
||||
|
||||
constructor(user: IUser) {
|
||||
super(user);
|
||||
makeObservable(this, {
|
||||
is_instance_admin: observable.ref,
|
||||
});
|
||||
this.userService = new UserService();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the current user
|
||||
* @returns Promise<IUser>
|
||||
*/
|
||||
fetchCurrentUser = async () => {
|
||||
const response = await this.userService.currentUser();
|
||||
this.updateUserInfo(response);
|
||||
return response;
|
||||
};
|
||||
|
||||
updateUserInfo = async (data: Partial<IUser>) => {
|
||||
runInAction(() => {
|
||||
Object.keys(data).forEach((key) => {
|
||||
set(this, key, data[key as keyof IUser]);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Fetches the current user instance admin status
|
||||
* @returns Promise<boolean>
|
||||
*/
|
||||
fetchUserInstanceAdminStatus = async () =>
|
||||
await this.userService.currentUserInstanceAdminStatus().then((response) => {
|
||||
runInAction(() => {
|
||||
this.is_instance_admin = response.is_instance_admin;
|
||||
});
|
||||
return response.is_instance_admin;
|
||||
});
|
||||
|
||||
/**
|
||||
* Updates the current user
|
||||
* @param data
|
||||
* @returns Promise<IUser>
|
||||
*/
|
||||
updateCurrentUser = async (data: Partial<IUser>) => {
|
||||
try {
|
||||
runInAction(() => {
|
||||
this.updateUserInfo(data);
|
||||
});
|
||||
const response = await this.userService.updateUser(data);
|
||||
runInAction(() => {
|
||||
this.updateUserInfo(response);
|
||||
});
|
||||
return response;
|
||||
} catch (error) {
|
||||
this.fetchCurrentUser();
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
48
web/store/user/user.store.ts
Normal file
48
web/store/user/user.store.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import { IUser } from "@plane/types";
|
||||
import { makeObservable, observable } from "mobx";
|
||||
|
||||
export interface IUserStore {
|
||||
avatar: string | undefined;
|
||||
cover_image: string | undefined;
|
||||
date_joined: string | undefined;
|
||||
display_name: string | undefined;
|
||||
email: string | undefined;
|
||||
first_name: string | undefined;
|
||||
id: string | undefined;
|
||||
is_active: boolean | undefined;
|
||||
is_bot: boolean | undefined;
|
||||
is_email_verified: boolean | undefined;
|
||||
is_managed: boolean | undefined;
|
||||
last_name: string | undefined;
|
||||
}
|
||||
|
||||
export class UserStore implements IUserStore {
|
||||
avatar: string | undefined;
|
||||
cover_image: string | undefined;
|
||||
date_joined: string | undefined;
|
||||
display_name: string | undefined;
|
||||
email: string | undefined;
|
||||
first_name: string | undefined;
|
||||
id: string | undefined;
|
||||
is_active: boolean | undefined;
|
||||
is_bot: boolean | undefined;
|
||||
is_email_verified: boolean | undefined;
|
||||
is_managed: boolean | undefined;
|
||||
last_name: string | undefined;
|
||||
|
||||
constructor(user: IUser) {
|
||||
makeObservable(this);
|
||||
this.avatar = user?.avatar;
|
||||
this.cover_image = user?.cover_image || undefined;
|
||||
this.date_joined = user?.date_joined;
|
||||
this.display_name = user?.display_name;
|
||||
this.email = user?.email;
|
||||
this.first_name = user?.first_name;
|
||||
this.id = user?.id;
|
||||
this.is_active = user?.is_active;
|
||||
this.is_bot = user?.is_bot;
|
||||
this.is_email_verified = user?.is_email_verified;
|
||||
this.is_managed = user?.is_managed;
|
||||
this.last_name = user?.last_name;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user