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-08 17:31:20 +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;
|
2024-05-14 08:56:54 +00:00
|
|
|
settings: IProjectSettings | null;
|
|
|
|
activeLayout: TIssueBoardKeys;
|
|
|
|
layoutOptions: Record<TIssueBoardKeys, boolean>;
|
|
|
|
canReact: boolean;
|
|
|
|
canComment: boolean;
|
|
|
|
canVote: boolean;
|
2023-09-01 11:12:30 +00:00
|
|
|
fetchProjectSettings: (workspace_slug: string, project_slug: string) => Promise<void>;
|
2024-05-14 08:56:54 +00:00
|
|
|
setActiveLayout: (value: TIssueBoardKeys) => void;
|
|
|
|
hydrate: (projectSettings: any) => void;
|
2023-09-01 11:12:30 +00:00
|
|
|
}
|
2023-08-11 11:48:33 +00:00
|
|
|
|
2024-05-08 17:31:20 +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;
|
2024-05-14 08:56:54 +00:00
|
|
|
settings: IProjectSettings | null = null;
|
|
|
|
activeLayout: TIssueBoardKeys = "list";
|
|
|
|
layoutOptions: Record<TIssueBoardKeys, boolean> = {
|
|
|
|
list: true,
|
|
|
|
kanban: true,
|
|
|
|
calendar: false,
|
|
|
|
gantt: false,
|
|
|
|
spreadsheet: false,
|
|
|
|
};
|
|
|
|
canReact: boolean = false;
|
|
|
|
canComment: boolean = false;
|
|
|
|
canVote: boolean = false;
|
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
|
2024-05-14 08:56:54 +00:00
|
|
|
workspace: observable,
|
|
|
|
project: observable,
|
|
|
|
settings: observable,
|
|
|
|
layoutOptions: observable,
|
|
|
|
activeLayout: observable.ref,
|
|
|
|
canReact: observable.ref,
|
|
|
|
canComment: observable.ref,
|
|
|
|
canVote: observable.ref,
|
2023-09-01 11:12:30 +00:00
|
|
|
// actions
|
|
|
|
fetchProjectSettings: action,
|
2024-05-14 08:56:54 +00:00
|
|
|
setActiveLayout: action,
|
|
|
|
hydrate: action,
|
2023-08-11 11:48:33 +00:00
|
|
|
// computed
|
|
|
|
});
|
|
|
|
|
|
|
|
this.rootStore = _rootStore;
|
|
|
|
this.projectService = new ProjectService();
|
|
|
|
}
|
|
|
|
|
2024-05-14 08:56:54 +00:00
|
|
|
hydrate = (projectSettings: any) => {
|
|
|
|
const { workspace_detail, project_details, views, votes, comments, reactions } = projectSettings;
|
|
|
|
this.workspace = workspace_detail;
|
|
|
|
this.project = project_details;
|
|
|
|
this.layoutOptions = views;
|
|
|
|
this.canComment = comments;
|
|
|
|
this.canVote = votes;
|
|
|
|
this.canReact = reactions;
|
|
|
|
};
|
|
|
|
|
|
|
|
setActiveLayout = (boardValue: TIssueBoardKeys) => {
|
|
|
|
this.activeLayout = boardValue;
|
|
|
|
};
|
|
|
|
|
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-08 17:31:20 +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-08 17:31:20 +00:00
|
|
|
this.project = currentProject;
|
|
|
|
this.workspace = currentWorkspace;
|
2024-05-14 08:56:54 +00:00
|
|
|
this.layoutOptions = currentViewOptions;
|
|
|
|
this.settings = currentDeploySettings;
|
2023-08-11 11:48:33 +00:00
|
|
|
this.loader = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return response;
|
|
|
|
} catch (error) {
|
|
|
|
this.loader = false;
|
|
|
|
this.error = error;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|