forked from github/plane
8a95a41100
Co-authored-by: Bavisetti Narayan <72156168+NarayanBavisetti@users.noreply.github.com> Co-authored-by: NarayanBavisetti <narayan3119@gmail.com> Co-authored-by: Bavisetti Narayan <narayan@Bavisettis-MacBook-Pro.local> Co-authored-by: Nikhil <118773738+pablohashescobar@users.noreply.github.com> Co-authored-by: M. Palanikannan <73993394+Palanikannan1437@users.noreply.github.com> Co-authored-by: Lakhan Baheti <94619783+1akhanBaheti@users.noreply.github.com> Co-authored-by: Dakshesh Jain <65905942+dakshesh14@users.noreply.github.com> Co-authored-by: Aaryan Khandelwal <65252264+aaryan610@users.noreply.github.com>
89 lines
2.5 KiB
TypeScript
89 lines
2.5 KiB
TypeScript
// mobx
|
|
import { observable, action, makeObservable, runInAction } from "mobx";
|
|
// service
|
|
import ProjectService from "services/project.service";
|
|
// types
|
|
import { IWorkspace, IProject, IProjectSettings } from "types/project";
|
|
|
|
export interface IProjectStore {
|
|
loader: boolean;
|
|
error: any | null;
|
|
workspace: IWorkspace | null;
|
|
project: IProject | null;
|
|
deploySettings: IProjectSettings | null;
|
|
viewOptions: any;
|
|
activeBoard: string | null;
|
|
fetchProjectSettings: (workspace_slug: string, project_slug: string) => Promise<void>;
|
|
setActiveBoard: (value: string) => void;
|
|
}
|
|
|
|
class ProjectStore implements IProjectStore {
|
|
loader: boolean = false;
|
|
error: any | null = null;
|
|
// data
|
|
workspace: IWorkspace | null = null;
|
|
project: IProject | null = null;
|
|
deploySettings: IProjectSettings | null = null;
|
|
viewOptions: any = null;
|
|
activeBoard: string | null = null;
|
|
// root store
|
|
rootStore;
|
|
// service
|
|
projectService;
|
|
|
|
constructor(_rootStore: any | null = null) {
|
|
makeObservable(this, {
|
|
// loaders and error observables
|
|
loader: observable,
|
|
error: observable.ref,
|
|
// observable
|
|
workspace: observable.ref,
|
|
project: observable.ref,
|
|
deploySettings: observable.ref,
|
|
viewOptions: observable.ref,
|
|
activeBoard: observable.ref,
|
|
// actions
|
|
fetchProjectSettings: action,
|
|
setActiveBoard: action,
|
|
// computed
|
|
});
|
|
|
|
this.rootStore = _rootStore;
|
|
this.projectService = new ProjectService();
|
|
}
|
|
|
|
fetchProjectSettings = async (workspace_slug: string, project_slug: string) => {
|
|
try {
|
|
this.loader = true;
|
|
this.error = null;
|
|
|
|
const response = await this.projectService.getProjectSettings(workspace_slug, project_slug);
|
|
|
|
if (response) {
|
|
const _project: IProject = { ...response?.project_details };
|
|
const _workspace: IWorkspace = { ...response?.workspace_detail };
|
|
const _viewOptions = { ...response?.views };
|
|
const _deploySettings = { ...response };
|
|
runInAction(() => {
|
|
this.project = _project;
|
|
this.workspace = _workspace;
|
|
this.viewOptions = _viewOptions;
|
|
this.deploySettings = _deploySettings;
|
|
this.loader = false;
|
|
});
|
|
}
|
|
return response;
|
|
} catch (error) {
|
|
this.loader = false;
|
|
this.error = error;
|
|
return error;
|
|
}
|
|
};
|
|
|
|
setActiveBoard = (boardValue: string) => {
|
|
this.activeBoard = boardValue;
|
|
};
|
|
}
|
|
|
|
export default ProjectStore;
|