2023-08-11 11:48:33 +00:00
|
|
|
// mobx
|
|
|
|
import { observable, action, makeObservable, runInAction } from "mobx";
|
|
|
|
// service
|
2024-03-19 14:38:35 +00:00
|
|
|
import ProjectService from "@/services/project.service";
|
2023-12-05 11:56:57 +00:00
|
|
|
import { TIssueBoardKeys } from "types/issue";
|
2023-08-11 11:48:33 +00:00
|
|
|
// types
|
2023-09-01 11:12:30 +00:00
|
|
|
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;
|
2023-12-05 11:56:57 +00:00
|
|
|
activeBoard: TIssueBoardKeys | null;
|
2023-09-01 11:12:30 +00:00
|
|
|
fetchProjectSettings: (workspace_slug: string, project_slug: string) => Promise<void>;
|
2023-12-05 11:56:57 +00:00
|
|
|
setActiveBoard: (value: TIssueBoardKeys) => void;
|
2023-09-01 11:12:30 +00:00
|
|
|
}
|
2023-08-11 11:48:33 +00:00
|
|
|
|
|
|
|
class ProjectStore implements IProjectStore {
|
|
|
|
loader: boolean = false;
|
|
|
|
error: any | null = null;
|
2023-09-01 11:12:30 +00:00
|
|
|
// data
|
2023-08-11 11:48:33 +00:00
|
|
|
workspace: IWorkspace | null = null;
|
|
|
|
project: IProject | null = null;
|
2023-09-01 11:12:30 +00:00
|
|
|
deploySettings: IProjectSettings | null = null;
|
|
|
|
viewOptions: any = null;
|
2023-12-05 11:56:57 +00:00
|
|
|
activeBoard: TIssueBoardKeys | null = null;
|
2023-08-11 11:48:33 +00:00
|
|
|
// root store
|
|
|
|
rootStore;
|
|
|
|
// service
|
|
|
|
projectService;
|
|
|
|
|
|
|
|
constructor(_rootStore: any | null = null) {
|
|
|
|
makeObservable(this, {
|
2023-09-01 11:12:30 +00:00
|
|
|
// loaders and error observables
|
|
|
|
loader: observable,
|
|
|
|
error: observable.ref,
|
2023-08-11 11:48:33 +00:00
|
|
|
// observable
|
|
|
|
workspace: observable.ref,
|
|
|
|
project: observable.ref,
|
2023-09-01 11:12:30 +00:00
|
|
|
deploySettings: observable.ref,
|
|
|
|
viewOptions: observable.ref,
|
|
|
|
activeBoard: observable.ref,
|
|
|
|
// actions
|
|
|
|
fetchProjectSettings: action,
|
|
|
|
setActiveBoard: action,
|
2023-08-11 11:48:33 +00:00
|
|
|
// computed
|
|
|
|
});
|
|
|
|
|
|
|
|
this.rootStore = _rootStore;
|
|
|
|
this.projectService = new ProjectService();
|
|
|
|
}
|
|
|
|
|
2023-09-01 11:12:30 +00:00
|
|
|
fetchProjectSettings = async (workspace_slug: string, project_slug: string) => {
|
2023-08-11 11:48:33 +00:00
|
|
|
try {
|
|
|
|
this.loader = true;
|
|
|
|
this.error = null;
|
|
|
|
|
2023-09-01 11:12:30 +00:00
|
|
|
const response = await this.projectService.getProjectSettings(workspace_slug, project_slug);
|
2023-08-11 11:48:33 +00:00
|
|
|
|
|
|
|
if (response) {
|
|
|
|
const _project: IProject = { ...response?.project_details };
|
|
|
|
const _workspace: IWorkspace = { ...response?.workspace_detail };
|
2023-09-01 11:12:30 +00:00
|
|
|
const _viewOptions = { ...response?.views };
|
|
|
|
const _deploySettings = { ...response };
|
2023-08-11 11:48:33 +00:00
|
|
|
runInAction(() => {
|
|
|
|
this.project = _project;
|
|
|
|
this.workspace = _workspace;
|
2023-09-01 11:12:30 +00:00
|
|
|
this.viewOptions = _viewOptions;
|
|
|
|
this.deploySettings = _deploySettings;
|
2023-08-11 11:48:33 +00:00
|
|
|
this.loader = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return response;
|
|
|
|
} catch (error) {
|
|
|
|
this.loader = false;
|
|
|
|
this.error = error;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
};
|
2023-09-01 11:12:30 +00:00
|
|
|
|
2023-12-05 11:56:57 +00:00
|
|
|
setActiveBoard = (boardValue: TIssueBoardKeys) => {
|
2023-09-01 11:12:30 +00:00
|
|
|
this.activeBoard = boardValue;
|
|
|
|
};
|
2023-08-11 11:48:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default ProjectStore;
|