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";
|
2024-05-16 07:37:47 +00:00
|
|
|
// store types
|
|
|
|
import { RootStore } from "@/store/root.store";
|
2023-08-11 11:48:33 +00:00
|
|
|
// types
|
2024-05-08 17:31:20 +00:00
|
|
|
import { IWorkspace, IProject, IProjectSettings } from "@/types/project";
|
2023-09-01 11:12:30 +00:00
|
|
|
|
|
|
|
export interface IProjectStore {
|
2024-05-16 07:37:47 +00:00
|
|
|
// observables
|
2023-09-01 11:12:30 +00:00
|
|
|
loader: boolean;
|
|
|
|
error: any | null;
|
|
|
|
workspace: IWorkspace | null;
|
|
|
|
project: IProject | null;
|
2024-05-14 08:56:54 +00:00
|
|
|
settings: IProjectSettings | null;
|
|
|
|
canReact: boolean;
|
|
|
|
canComment: boolean;
|
|
|
|
canVote: boolean;
|
2024-05-16 07:37:47 +00:00
|
|
|
// actions
|
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
|
|
|
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 {
|
2024-05-16 07:37:47 +00:00
|
|
|
// observables
|
2023-08-11 11:48:33 +00:00
|
|
|
loader: boolean = false;
|
|
|
|
error: any | null = null;
|
|
|
|
workspace: IWorkspace | null = null;
|
|
|
|
project: IProject | null = null;
|
2024-05-14 08:56:54 +00:00
|
|
|
settings: IProjectSettings | null = null;
|
|
|
|
canReact: boolean = false;
|
|
|
|
canComment: boolean = false;
|
|
|
|
canVote: boolean = false;
|
2023-08-11 11:48:33 +00:00
|
|
|
// service
|
|
|
|
projectService;
|
|
|
|
|
2024-05-16 07:37:47 +00:00
|
|
|
constructor(private store: RootStore) {
|
2023-08-11 11:48:33 +00:00
|
|
|
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,
|
|
|
|
canReact: observable.ref,
|
|
|
|
canComment: observable.ref,
|
|
|
|
canVote: observable.ref,
|
2023-09-01 11:12:30 +00:00
|
|
|
// actions
|
|
|
|
fetchProjectSettings: action,
|
2024-05-16 07:37:47 +00:00
|
|
|
|
2024-05-14 08:56:54 +00:00
|
|
|
hydrate: action,
|
2023-08-11 11:48:33 +00:00
|
|
|
// computed
|
|
|
|
});
|
|
|
|
|
2024-05-16 07:37:47 +00:00
|
|
|
// services
|
2023-08-11 11:48:33 +00:00
|
|
|
this.projectService = new ProjectService();
|
|
|
|
}
|
|
|
|
|
2024-05-14 08:56:54 +00:00
|
|
|
hydrate = (projectSettings: any) => {
|
2024-05-16 07:37:47 +00:00
|
|
|
const { workspace_detail, project_details, votes, comments, reactions } = projectSettings;
|
2024-05-14 08:56:54 +00:00
|
|
|
this.workspace = workspace_detail;
|
|
|
|
this.project = project_details;
|
|
|
|
this.canComment = comments;
|
|
|
|
this.canVote = votes;
|
|
|
|
this.canReact = reactions;
|
|
|
|
};
|
|
|
|
|
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 currentDeploySettings = { ...response };
|
2024-05-16 07:37:47 +00:00
|
|
|
this.store.issueFilter.updateLayoutOptions(response?.views);
|
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.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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|