2023-08-11 11:48:33 +00:00
|
|
|
// mobx
|
2024-05-16 13:58:37 +00:00
|
|
|
import { observable, action, makeObservable, runInAction, computed } from "mobx";
|
2023-08-11 11:48:33 +00:00
|
|
|
// 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-16 13:58:37 +00:00
|
|
|
import { TWorkspaceDetails, TProjectDetails, TProjectSettings } 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;
|
2024-05-16 13:58:37 +00:00
|
|
|
error: any | undefined;
|
|
|
|
settings: TProjectSettings | undefined;
|
|
|
|
workspace: TWorkspaceDetails | undefined;
|
|
|
|
project: TProjectDetails | undefined;
|
2024-05-14 08:56:54 +00:00
|
|
|
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;
|
2024-05-16 13:58:37 +00:00
|
|
|
error: any | undefined = undefined;
|
|
|
|
settings: TProjectSettings | undefined = undefined;
|
|
|
|
workspace: TWorkspaceDetails | undefined = undefined;
|
|
|
|
project: TProjectDetails | undefined = undefined;
|
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,
|
2024-05-16 13:58:37 +00:00
|
|
|
// computed
|
|
|
|
canReact: computed,
|
|
|
|
canComment: computed,
|
|
|
|
canVote: computed,
|
2023-09-01 11:12:30 +00:00
|
|
|
// actions
|
|
|
|
fetchProjectSettings: action,
|
2024-05-14 08:56:54 +00:00
|
|
|
hydrate: action,
|
2023-08-11 11:48:33 +00:00
|
|
|
});
|
2024-05-16 07:37:47 +00:00
|
|
|
// services
|
2023-08-11 11:48:33 +00:00
|
|
|
this.projectService = new ProjectService();
|
|
|
|
}
|
|
|
|
|
2024-05-16 13:58:37 +00:00
|
|
|
// computed
|
|
|
|
get canReact() {
|
|
|
|
return this.settings?.reactions ?? false;
|
|
|
|
}
|
|
|
|
get canComment() {
|
|
|
|
return this.settings?.comments ?? false;
|
|
|
|
}
|
|
|
|
get canVote() {
|
|
|
|
return this.settings?.votes ?? false;
|
|
|
|
}
|
2024-05-14 08:56:54 +00:00
|
|
|
|
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-16 07:37:47 +00:00
|
|
|
this.store.issueFilter.updateLayoutOptions(response?.views);
|
2023-08-11 11:48:33 +00:00
|
|
|
runInAction(() => {
|
2024-05-16 13:58:37 +00:00
|
|
|
this.project = response?.project_details;
|
|
|
|
this.workspace = response?.workspace_detail;
|
|
|
|
this.settings = response;
|
2023-08-11 11:48:33 +00:00
|
|
|
this.loader = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return response;
|
|
|
|
} catch (error) {
|
|
|
|
this.loader = false;
|
|
|
|
this.error = error;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
};
|
2024-05-16 13:58:37 +00:00
|
|
|
|
|
|
|
hydrate = (projectSettings: TProjectSettings) => {
|
|
|
|
const { workspace_detail, project_details } = projectSettings;
|
|
|
|
this.workspace = workspace_detail;
|
|
|
|
this.project = project_details;
|
|
|
|
};
|
2023-08-11 11:48:33 +00:00
|
|
|
}
|