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-08-11 11:48:33 +00:00
|
|
|
// types
|
2024-05-07 11:54:45 +00:00
|
|
|
import { TIssueBoardKeys } from "@/types/issue";
|
|
|
|
import { IWorkspace, IProject, IProjectSettings } from "@/types/project";
|
2023-09-01 11:12:30 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2024-05-07 11:54:45 +00:00
|
|
|
export class ProjectStore implements IProjectStore {
|
2023-08-11 11:48:33 +00:00
|
|
|
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) {
|
2024-05-07 11:54:45 +00:00
|
|
|
const currentProject: IProject = { ...response?.project_details };
|
|
|
|
const currentWorkspace: IWorkspace = { ...response?.workspace_detail };
|
|
|
|
const currentViewOptions = { ...response?.views };
|
|
|
|
const currentDeploySettings = { ...response };
|
2023-08-11 11:48:33 +00:00
|
|
|
runInAction(() => {
|
2024-05-07 11:54:45 +00:00
|
|
|
this.project = currentProject;
|
|
|
|
this.workspace = currentWorkspace;
|
|
|
|
this.viewOptions = currentViewOptions;
|
|
|
|
this.deploySettings = currentDeploySettings;
|
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
|
|
|
}
|