[WEB-3066] refactor: replace Space Services with Services Package (#6353)

* [WEB-3066] refactor: replace Space Services with Services Package

* chore: minor improvements

* fix: type

---------

Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com>
This commit is contained in:
Prateek Shourya 2025-01-11 15:16:11 +05:30 committed by GitHub
parent 39ca600091
commit ade4d290f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
66 changed files with 1002 additions and 631 deletions

View file

@ -3,6 +3,8 @@
import React, { FC, useEffect, useState } from "react";
import { observer } from "mobx-react";
import { useSearchParams } from "next/navigation";
// plane imports
import { SitesAuthService } from "@plane/services";
import { IEmailCheckData } from "@plane/types";
// components
import {
@ -23,12 +25,10 @@ import {
} from "@/helpers/authentication.helper";
// hooks
import { useInstance } from "@/hooks/store";
// services
import { AuthService } from "@/services/auth.service";
// types
import { EAuthModes, EAuthSteps } from "@/types/auth";
const authService = new AuthService();
const authService = new SitesAuthService();
export const AuthRoot: FC = observer(() => {
// router params

View file

@ -3,14 +3,14 @@
import React, { useEffect, useMemo, useRef, useState } from "react";
import { observer } from "mobx-react";
import { Eye, EyeOff, XCircle } from "lucide-react";
// plane imports
import { API_BASE_URL } from "@plane/constants";
import { AuthService } from "@plane/services";
import { Button, Input, Spinner } from "@plane/ui";
// components
import { PasswordStrengthMeter } from "@/components/account";
// helpers
import { E_PASSWORD_STRENGTH, getPasswordStrength } from "@/helpers/password.helper";
// services
import { AuthService } from "@/services/auth.service";
// types
import { EAuthModes, EAuthSteps } from "@/types/auth";

View file

@ -2,12 +2,12 @@
import React, { useEffect, useState } from "react";
import { CircleCheck, XCircle } from "lucide-react";
// plane imports
import { API_BASE_URL } from "@plane/constants";
import { AuthService } from "@plane/services";
import { Button, Input, Spinner } from "@plane/ui";
// hooks
import useTimer from "@/hooks/use-timer";
// services
import { AuthService } from "@/services/auth.service";
// types
import { EAuthModes } from "@/types/auth";

View file

@ -7,15 +7,15 @@ import { usePathname, useSearchParams } from "next/navigation";
import { usePopper } from "react-popper";
import { LogOut } from "lucide-react";
import { Popover, Transition } from "@headlessui/react";
// plane imports
import { API_BASE_URL } from "@plane/constants";
import { AuthService } from "@plane/services";
import { Avatar, Button } from "@plane/ui";
// helpers
import { getFileURL } from "@/helpers/file.helper";
import { queryParamGenerator } from "@/helpers/query-param-generator";
// hooks
import { useUser } from "@/hooks/store";
// services
import { AuthService } from "@/services/auth.service";
const authService = new AuthService();

View file

@ -3,21 +3,19 @@
import React, { useRef, useState } from "react";
import { observer } from "mobx-react";
import { useForm, Controller } from "react-hook-form";
// editor
// plane imports
import { EditorRefApi } from "@plane/editor";
// ui
import { SitesFileService } from "@plane/services";
import { TIssuePublicComment } from "@plane/types";
import { TOAST_TYPE, setToast } from "@plane/ui";
// editor components
import { LiteTextEditor } from "@/components/editor/lite-text-editor";
// hooks
import { useIssueDetails, usePublish, useUser } from "@/hooks/store";
// services
import { FileService } from "@/services/file.service";
const fileService = new FileService();
// types
import { Comment } from "@/types/issue";
const fileService = new SitesFileService();
const defaultValues: Partial<Comment> = {
const defaultValues: Partial<TIssuePublicComment> = {
comment_html: "",
};
@ -43,9 +41,9 @@ export const AddComment: React.FC<Props> = observer((props) => {
watch,
formState: { isSubmitting },
reset,
} = useForm<Comment>({ defaultValues });
} = useForm<TIssuePublicComment>({ defaultValues });
const onSubmit = async (formData: Comment) => {
const onSubmit = async (formData: TIssuePublicComment) => {
if (!anchor || !issueId || isSubmitting || !formData.comment_html) return;
await addIssueComment(anchor, issueId, formData)

View file

@ -3,8 +3,10 @@ import { observer } from "mobx-react";
import { Controller, useForm } from "react-hook-form";
import { Check, MessageSquare, MoreVertical, X } from "lucide-react";
import { Menu, Transition } from "@headlessui/react";
// components
// plane imports
import { EditorRefApi } from "@plane/editor";
import { TIssuePublicComment } from "@plane/types";
// components
import { LiteTextEditor, LiteTextReadOnlyEditor } from "@/components/editor";
import { CommentReactions } from "@/components/issues/peek-overview";
// helpers
@ -13,12 +15,10 @@ import { getFileURL } from "@/helpers/file.helper";
// hooks
import { useIssueDetails, usePublish, useUser } from "@/hooks/store";
import useIsInIframe from "@/hooks/use-is-in-iframe";
// types
import { Comment } from "@/types/issue";
type Props = {
anchor: string;
comment: Comment;
comment: TIssuePublicComment;
};
export const CommentCard: React.FC<Props> = observer((props) => {
@ -48,7 +48,7 @@ export const CommentCard: React.FC<Props> = observer((props) => {
deleteIssueComment(anchor, peekId, comment.id);
};
const handleCommentUpdate = async (formData: Comment) => {
const handleCommentUpdate = async (formData: TIssuePublicComment) => {
if (!anchor || !peekId) return;
updateIssueComment(anchor, peekId, comment.id, formData);
setIsEditing(false);

View file

@ -1,13 +1,12 @@
import { useRef, useEffect } from "react";
import useSWR from "swr";
// types
// plane imports
import { UserService } from "@plane/services";
import { IUser } from "@plane/types";
// services
import { UserService } from "@/services/user.service";
export const useMention = () => {
const userService = new UserService();
const { data: user, isLoading: userDataLoading } = useSWR("currentUser", async () => userService.currentUser());
const { data: user, isLoading: userDataLoading } = useSWR("currentUser", async () => userService.me());
const userRef = useRef<IUser | undefined>();

View file

@ -1,54 +0,0 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import axios, { AxiosInstance } from "axios";
// store
// import { rootStore } from "@/lib/store-context";
export abstract class APIService {
protected baseURL: string | undefined;
private axiosInstance: AxiosInstance;
constructor(baseURL: string | undefined) {
this.baseURL = baseURL;
this.axiosInstance = axios.create({
baseURL: baseURL || "",
withCredentials: true,
});
this.setupInterceptors();
}
private setupInterceptors() {
// this.axiosInstance.interceptors.response.use(
// (response) => response,
// (error) => {
// const store = rootStore;
// if (error.response && error.response.status === 401 && store.user.data) store.user.reset();
// return Promise.reject(error);
// }
// );
}
get(url: string, params = {}) {
return this.axiosInstance.get(url, params);
}
post(url: string, data = {}, config = {}) {
return this.axiosInstance.post(url, data, config);
}
put(url: string, data = {}, config = {}) {
return this.axiosInstance.put(url, data, config);
}
patch(url: string, data = {}, config = {}) {
return this.axiosInstance.patch(url, data, config);
}
delete(url: string, data?: any, config = {}) {
return this.axiosInstance.delete(url, { data, ...config });
}
request(config = {}) {
return this.axiosInstance(config);
}
}

View file

@ -1,35 +0,0 @@
import { API_BASE_URL } from "@plane/constants";
// services
import { APIService } from "@/services/api.service";
// types
import { ICsrfTokenData, IEmailCheckData, IEmailCheckResponse } from "@/types/auth";
export class AuthService extends APIService {
constructor() {
super(API_BASE_URL);
}
async requestCSRFToken(): Promise<ICsrfTokenData> {
return this.get("/auth/get-csrf-token/")
.then((response) => response.data)
.catch((error) => {
throw error;
});
}
async emailCheck(data: IEmailCheckData): Promise<IEmailCheckResponse> {
return this.post("/auth/spaces/email-check/", data, { headers: {} })
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async generateUniqueCode(data: { email: string }): Promise<void> {
return this.post("/auth/spaces/magic-generate/", data, { headers: {} })
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
}

View file

@ -1,19 +0,0 @@
import { API_BASE_URL } from "@plane/constants";
// services
import { APIService } from "@/services/api.service";
// types
import { TPublicCycle } from "@/types/cycle";
export class CycleService extends APIService {
constructor() {
super(API_BASE_URL);
}
async getCycles(anchor: string): Promise<TPublicCycle[]> {
return this.get(`/api/public/anchor/${anchor}/cycles/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
}

View file

@ -1,34 +0,0 @@
import axios from "axios";
// services
import { APIService } from "@/services/api.service";
export class FileUploadService extends APIService {
private cancelSource: any;
constructor() {
super("");
}
async uploadFile(url: string, data: FormData): Promise<void> {
this.cancelSource = axios.CancelToken.source();
return this.post(url, data, {
headers: {
"Content-Type": "multipart/form-data",
},
cancelToken: this.cancelSource.token,
withCredentials: false,
})
.then((response) => response?.data)
.catch((error) => {
if (axios.isCancel(error)) {
console.log(error.message);
} else {
throw error?.response?.data;
}
});
}
cancelUpload() {
this.cancelSource.cancel("Upload canceled");
}
}

View file

@ -1,99 +0,0 @@
import { API_BASE_URL } from "@plane/constants";
import { TFileEntityInfo, TFileSignedURLResponse } from "@plane/types";
// helpers
import { generateFileUploadPayload, getAssetIdFromUrl, getFileMetaDataForUpload } from "@/helpers/file.helper";
// services
import { APIService } from "@/services/api.service";
import { FileUploadService } from "@/services/file-upload.service";
export class FileService extends APIService {
private cancelSource: any;
fileUploadService: FileUploadService;
constructor() {
super(API_BASE_URL);
this.cancelUpload = this.cancelUpload.bind(this);
// services
this.fileUploadService = new FileUploadService();
}
private async updateAssetUploadStatus(anchor: string, assetId: string): Promise<void> {
return this.patch(`/api/public/assets/v2/anchor/${anchor}/${assetId}/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async updateBulkAssetsUploadStatus(
anchor: string,
entityId: string,
data: {
asset_ids: string[];
}
): Promise<void> {
return this.post(`/api/public/assets/v2/anchor/${anchor}/${entityId}/bulk/`, data)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async uploadAsset(anchor: string, data: TFileEntityInfo, file: File): Promise<TFileSignedURLResponse> {
const fileMetaData = getFileMetaDataForUpload(file);
return this.post(`/api/public/assets/v2/anchor/${anchor}/`, {
...data,
...fileMetaData,
})
.then(async (response) => {
const signedURLResponse: TFileSignedURLResponse = response?.data;
const fileUploadPayload = generateFileUploadPayload(signedURLResponse, file);
await this.fileUploadService.uploadFile(signedURLResponse.upload_data.url, fileUploadPayload);
await this.updateAssetUploadStatus(anchor, signedURLResponse.asset_id);
return signedURLResponse;
})
.catch((error) => {
throw error?.response?.data;
});
}
async deleteNewAsset(assetPath: string): Promise<void> {
return this.delete(assetPath)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async deleteOldEditorAsset(workspaceId: string, src: string): Promise<any> {
const assetKey = getAssetIdFromUrl(src);
return this.delete(`/api/workspaces/file-assets/${workspaceId}/${assetKey}/`)
.then((response) => response?.status)
.catch((error) => {
throw error?.response?.data;
});
}
async restoreNewAsset(workspaceSlug: string, src: string): Promise<void> {
// remove the last slash and get the asset id
const assetId = getAssetIdFromUrl(src);
return this.post(`/api/public/assets/v2/workspaces/${workspaceSlug}/restore/${assetId}/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async restoreOldEditorAsset(workspaceId: string, src: string): Promise<void> {
const assetKey = getAssetIdFromUrl(src);
return this.post(`/api/workspaces/file-assets/${workspaceId}/${assetKey}/restore/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
cancelUpload() {
this.cancelSource.cancel("Upload cancelled");
}
}

View file

@ -1,18 +0,0 @@
import { API_BASE_URL } from "@plane/constants";
import type { IInstanceInfo } from "@plane/types";
// services
import { APIService } from "@/services/api.service";
export class InstanceService extends APIService {
constructor() {
super(API_BASE_URL);
}
async getInstanceInfo(): Promise<IInstanceInfo> {
return this.get("/api/instances/")
.then((response) => response.data)
.catch((error) => {
throw error;
});
}
}

View file

@ -1,133 +0,0 @@
import { API_BASE_URL } from "@plane/constants";
// services
import { APIService } from "@/services/api.service";
// types
import { Comment, TIssuesResponse, IIssue } from "@/types/issue";
class IssueService extends APIService {
constructor() {
super(API_BASE_URL);
}
async fetchPublicIssues(anchor: string, params: any): Promise<TIssuesResponse> {
return this.get(`/api/public/anchor/${anchor}/issues/`, {
params,
})
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
async getIssueById(anchor: string, issueID: string): Promise<IIssue> {
return this.get(`/api/public/anchor/${anchor}/issues/${issueID}/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
async getIssueVotes(anchor: string, issueID: string): Promise<any> {
return this.get(`/api/public/anchor/${anchor}/issues/${issueID}/votes/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
async createIssueVote(anchor: string, issueID: string, data: any): Promise<any> {
return this.post(`/api/public/anchor/${anchor}/issues/${issueID}/votes/`, data)
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
async deleteIssueVote(anchor: string, issueID: string): Promise<any> {
return this.delete(`/api/public/anchor/${anchor}/issues/${issueID}/votes/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
async getIssueReactions(anchor: string, issueID: string): Promise<any> {
return this.get(`/api/public/anchor/${anchor}/issues/${issueID}/reactions/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
async createIssueReaction(anchor: string, issueID: string, data: any): Promise<any> {
return this.post(`/api/public/anchor/${anchor}/issues/${issueID}/reactions/`, data)
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
async deleteIssueReaction(anchor: string, issueID: string, reactionId: string): Promise<any> {
return this.delete(`/api/public/anchor/${anchor}/issues/${issueID}/reactions/${reactionId}/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
async getIssueComments(anchor: string, issueID: string): Promise<any> {
return this.get(`/api/public/anchor/${anchor}/issues/${issueID}/comments/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
async createIssueComment(anchor: string, issueID: string, data: any): Promise<Comment> {
return this.post(`/api/public/anchor/${anchor}/issues/${issueID}/comments/`, data)
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
async updateIssueComment(anchor: string, issueID: string, commentId: string, data: any): Promise<any> {
return this.patch(`/api/public/anchor/${anchor}/issues/${issueID}/comments/${commentId}/`, data)
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
async deleteIssueComment(anchor: string, issueID: string, commentId: string): Promise<any> {
return this.delete(`/api/public/anchor/${anchor}/issues/${issueID}/comments/${commentId}/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
async createCommentReaction(
anchor: string,
commentId: string,
data: {
reaction: string;
}
): Promise<any> {
return this.post(`/api/public/anchor/${anchor}/comments/${commentId}/reactions/`, data)
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
async deleteCommentReaction(anchor: string, commentId: string, reactionHex: string): Promise<any> {
return this.delete(`/api/public/anchor/${anchor}/comments/${commentId}/reactions/${reactionHex}/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
}
export default IssueService;

View file

@ -1,18 +0,0 @@
import { API_BASE_URL } from "@plane/constants";
import { IIssueLabel } from "@plane/types";
// services
import { APIService } from "./api.service";
export class LabelService extends APIService {
constructor() {
super(API_BASE_URL);
}
async getLabels(anchor: string): Promise<IIssueLabel[]> {
return this.get(`/api/public/anchor/${anchor}/labels/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
}

View file

@ -1,19 +0,0 @@
import { API_BASE_URL } from "@plane/constants";
// services
import { APIService } from "@/services/api.service";
// types
import { TPublicMember } from "@/types/member";
export class MemberService extends APIService {
constructor() {
super(API_BASE_URL);
}
async getAnchorMembers(anchor: string): Promise<TPublicMember[]> {
return this.get(`/api/public/anchor/${anchor}/members/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
}

View file

@ -1,19 +0,0 @@
import { API_BASE_URL } from "@plane/constants";
// services
import { APIService } from "@/services/api.service";
// types
import { TPublicModule } from "@/types/modules";
export class ModuleService extends APIService {
constructor() {
super(API_BASE_URL);
}
async getModules(anchor: string): Promise<TPublicModule[]> {
return this.get(`/api/public/anchor/${anchor}/modules/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
}

View file

@ -1,26 +0,0 @@
import { API_BASE_URL } from "@plane/constants";
import type { IProjectMember, IProjectMembership } from "@plane/types";
// services
import { APIService } from "@/services/api.service";
export class ProjectMemberService extends APIService {
constructor() {
super(API_BASE_URL);
}
async fetchProjectMembers(anchor: string): Promise<IProjectMembership[]> {
return this.get(`/api/anchor/${anchor}/members/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async getProjectMember(anchor: string, memberID: string): Promise<IProjectMember> {
return this.get(`/api/anchor/${anchor}/members/${memberID}/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
}

View file

@ -1,28 +0,0 @@
import { API_BASE_URL } from "@plane/constants";
import { TProjectPublishSettings } from "@plane/types";
// services
import { APIService } from "@/services/api.service";
class PublishService extends APIService {
constructor() {
super(API_BASE_URL);
}
async fetchPublishSettings(anchor: string): Promise<TProjectPublishSettings> {
return this.get(`/api/public/anchor/${anchor}/settings/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
async fetchAnchorFromProjectDetails(workspaceSlug: string, projectID: string): Promise<TProjectPublishSettings> {
return this.get(`/api/public/workspaces/${workspaceSlug}/projects/${projectID}/anchor/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
}
export default PublishService;

View file

@ -1,18 +0,0 @@
import { API_BASE_URL } from "@plane/constants";
import { IState } from "@plane/types";
// services
import { APIService } from "./api.service";
export class StateService extends APIService {
constructor() {
super(API_BASE_URL);
}
async getStates(anchor: string): Promise<IState[]> {
return this.get(`/api/public/anchor/${anchor}/states/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
}

View file

@ -1,41 +0,0 @@
import { API_BASE_URL } from "@plane/constants";
import { IUser, TUserProfile } from "@plane/types";
// services
import { APIService } from "@/services/api.service";
export class UserService extends APIService {
constructor() {
super(API_BASE_URL);
}
async currentUser(): Promise<IUser> {
return this.get("/api/users/me/")
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
async updateUser(data: Partial<IUser>): Promise<IUser> {
return this.patch("/api/users/me/", data)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async getCurrentUserProfile(): Promise<TUserProfile> {
return this.get("/api/users/me/profile/")
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
async updateCurrentUserProfile(data: Partial<TUserProfile>): Promise<TUserProfile> {
return this.patch("/api/users/me/profile/", data)
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
}

View file

@ -1,6 +1,8 @@
import { action, makeObservable, observable, runInAction } from "mobx";
// plane imports
import { SitesCycleService } from "@plane/services";
import { TPublicCycle } from "@/types/cycle";
import { CycleService } from "../services/cycle.service";
// store
import { CoreRootStore } from "./root.store";
export interface ICycleStore {
@ -14,7 +16,7 @@ export interface ICycleStore {
export class CycleStore implements ICycleStore {
cycles: TPublicCycle[] | undefined = undefined;
cycleService: CycleService;
cycleService: SitesCycleService;
rootStore: CoreRootStore;
constructor(_rootStore: CoreRootStore) {
@ -24,14 +26,14 @@ export class CycleStore implements ICycleStore {
// fetch action
fetchCycles: action,
});
this.cycleService = new CycleService();
this.cycleService = new SitesCycleService();
this.rootStore = _rootStore;
}
getCycleById = (cycleId: string | undefined) => this.cycles?.find((cycle) => cycle.id === cycleId);
fetchCycles = async (anchor: string) => {
const cyclesResponse = await this.cycleService.getCycles(anchor);
const cyclesResponse = await this.cycleService.list(anchor);
runInAction(() => {
this.cycles = cyclesResponse;
});

View file

@ -5,9 +5,9 @@ import uniq from "lodash/uniq";
import update from "lodash/update";
import { action, makeObservable, observable, runInAction } from "mobx";
import { computedFn } from "mobx-utils";
// plane constants
// plane imports
import { ALL_ISSUES } from "@plane/constants";
// types
import { SitesIssueService } from "@plane/services";
import {
TIssueGroupByOptions,
TGroupedIssues,
@ -19,8 +19,7 @@ import {
TGroupedIssueCount,
TPaginationData,
} from "@plane/types";
// services
import IssueService from "@/services/issue.service";
// types
import { IIssue, TIssuesResponse } from "@/types/issue";
import { CoreRootStore } from "../root.store";
// constants
@ -98,7 +97,7 @@ export abstract class BaseIssuesStore implements IBaseIssuesStore {
setLoader: action.bound,
});
this.rootIssueStore = _rootStore;
this.issueService = new IssueService();
this.issueService = new SitesIssueService();
}
getIssueIds = (groupId?: string, subGroupId?: string) => {

View file

@ -1,9 +1,8 @@
import set from "lodash/set";
import { observable, action, makeObservable, runInAction } from "mobx";
// types
// plane imports
import { InstanceService } from "@plane/services";
import { IInstance, IInstanceConfig } from "@plane/types";
// services
import { InstanceService } from "@/services/instance.service";
// store
import { CoreRootStore } from "@/store/root.store";
@ -59,7 +58,7 @@ export class InstanceStore implements IInstanceStore {
try {
this.isLoading = true;
this.error = undefined;
const instanceInfo = await this.instanceService.getInstanceInfo();
const instanceInfo = await this.instanceService.info();
runInAction(() => {
this.isLoading = false;
this.instance = instanceInfo.instance;

View file

@ -3,16 +3,14 @@ import set from "lodash/set";
import { makeObservable, observable, action, runInAction } from "mobx";
import { computedFn } from "mobx-utils";
import { v4 as uuidv4 } from "uuid";
// plane types
import { TFileSignedURLResponse } from "@plane/types";
// plane imports
import { SitesFileService, SitesIssueService } from "@plane/services";
import { TFileSignedURLResponse, TIssuePublicComment } from "@plane/types";
import { EFileAssetType } from "@plane/types/src/enums";
// services
import { FileService } from "@/services/file.service";
import IssueService from "@/services/issue.service";
// store
import { CoreRootStore } from "@/store/root.store";
// types
import { Comment, IIssue, IPeekMode, IVote } from "@/types/issue";
import { IIssue, IPeekMode, IVote } from "@/types/issue";
export interface IIssueDetailStore {
loader: boolean;
@ -32,7 +30,7 @@ export interface IIssueDetailStore {
// issue actions
fetchIssueDetails: (anchor: string, issueID: string) => void;
// comment actions
addIssueComment: (anchor: string, issueID: string, data: any) => Promise<Comment>;
addIssueComment: (anchor: string, issueID: string, data: any) => Promise<TIssuePublicComment>;
updateIssueComment: (anchor: string, issueID: string, commentID: string, data: any) => Promise<any>;
deleteIssueComment: (anchor: string, issueID: string, commentID: string) => void;
uploadCommentAsset: (file: File, anchor: string, commentID?: string) => Promise<TFileSignedURLResponse>;
@ -59,8 +57,8 @@ export class IssueDetailStore implements IIssueDetailStore {
// root store
rootStore: CoreRootStore;
// services
issueService: IssueService;
fileService: FileService;
issueService: SitesIssueService;
fileService: SitesFileService;
constructor(_rootStore: CoreRootStore) {
makeObservable(this, {
@ -91,8 +89,8 @@ export class IssueDetailStore implements IIssueDetailStore {
removeIssueVote: action,
});
this.rootStore = _rootStore;
this.issueService = new IssueService();
this.fileService = new FileService();
this.issueService = new SitesIssueService();
this.fileService = new SitesFileService();
}
setPeekId = (issueID: string | null) => {
@ -123,7 +121,7 @@ export class IssueDetailStore implements IIssueDetailStore {
*/
fetchIssueById = async (anchorId: string, issueId: string) => {
try {
const issueDetails = await this.issueService.getIssueById(anchorId, issueId);
const issueDetails = await this.issueService.retrieve(anchorId, issueId);
runInAction(() => {
set(this.details, [issueId], issueDetails);
@ -146,7 +144,7 @@ export class IssueDetailStore implements IIssueDetailStore {
this.error = null;
const issueDetails = await this.fetchIssueById(anchor, issueID);
const commentsResponse = await this.issueService.getIssueComments(anchor, issueID);
const commentsResponse = await this.issueService.listComments(anchor, issueID);
if (issueDetails) {
runInAction(() => {
@ -168,7 +166,7 @@ export class IssueDetailStore implements IIssueDetailStore {
addIssueComment = async (anchor: string, issueID: string, data: any) => {
try {
const issueDetails = this.getIssueById(issueID);
const issueCommentResponse = await this.issueService.createIssueComment(anchor, issueID, data);
const issueCommentResponse = await this.issueService.addComment(anchor, issueID, data);
if (issueDetails) {
runInAction(() => {
set(this.details, [issueID, "comments"], [...(issueDetails?.comments ?? []), issueCommentResponse]);
@ -196,9 +194,9 @@ export class IssueDetailStore implements IIssueDetailStore {
};
});
await this.issueService.updateIssueComment(anchor, issueID, commentID, data);
await this.issueService.updateComment(anchor, issueID, commentID, data);
} catch (error) {
const issueComments = await this.issueService.getIssueComments(anchor, issueID);
const issueComments = await this.issueService.listComments(anchor, issueID);
runInAction(() => {
this.details = {
@ -214,7 +212,7 @@ export class IssueDetailStore implements IIssueDetailStore {
deleteIssueComment = async (anchor: string, issueID: string, commentID: string) => {
try {
await this.issueService.deleteIssueComment(anchor, issueID, commentID);
await this.issueService.removeComment(anchor, issueID, commentID);
const remainingComments = this.details[issueID].comments.filter((c) => c.id != commentID);
runInAction(() => {
this.details = {
@ -288,11 +286,11 @@ export class IssueDetailStore implements IIssueDetailStore {
};
});
await this.issueService.createCommentReaction(anchor, commentID, {
await this.issueService.addCommentReaction(anchor, commentID, {
reaction: reactionHex,
});
} catch (error) {
const issueComments = await this.issueService.getIssueComments(anchor, issueID);
const issueComments = await this.issueService.listComments(anchor, issueID);
runInAction(() => {
this.details = {
@ -324,9 +322,9 @@ export class IssueDetailStore implements IIssueDetailStore {
};
});
await this.issueService.deleteCommentReaction(anchor, commentID, reactionHex);
await this.issueService.removeCommentReaction(anchor, commentID, reactionHex);
} catch (error) {
const issueComments = await this.issueService.getIssueComments(anchor, issueID);
const issueComments = await this.issueService.listComments(anchor, issueID);
runInAction(() => {
this.details = {
@ -356,12 +354,12 @@ export class IssueDetailStore implements IIssueDetailStore {
);
});
await this.issueService.createIssueReaction(anchor, issueID, {
await this.issueService.addReaction(anchor, issueID, {
reaction: reactionHex,
});
} catch (error) {
console.log("Failed to add issue vote");
const issueReactions = await this.issueService.getIssueReactions(anchor, issueID);
const issueReactions = await this.issueService.listReactions(anchor, issueID);
runInAction(() => {
set(this.details, [issueID, "reaction_items"], issueReactions);
});
@ -378,10 +376,10 @@ export class IssueDetailStore implements IIssueDetailStore {
set(this.details, [issueID, "reaction_items"], newReactions);
});
await this.issueService.deleteIssueReaction(anchor, issueID, reactionHex);
await this.issueService.removeReaction(anchor, issueID, reactionHex);
} catch (error) {
console.log("Failed to remove issue reaction");
const reactions = await this.issueService.getIssueReactions(anchor, issueID);
const reactions = await this.issueService.listReactions(anchor, issueID);
runInAction(() => {
set(this.details, [issueID, "reaction_items"], reactions);
});
@ -410,10 +408,10 @@ export class IssueDetailStore implements IIssueDetailStore {
});
});
await this.issueService.createIssueVote(anchor, issueID, data);
await this.issueService.addVote(anchor, issueID, data);
} catch (error) {
console.log("Failed to add issue vote");
const issueVotes = await this.issueService.getIssueVotes(anchor, issueID);
const issueVotes = await this.issueService.listVotes(anchor, issueID);
runInAction(() => {
set(this.details, [issueID, "vote_items"], issueVotes);
@ -431,10 +429,10 @@ export class IssueDetailStore implements IIssueDetailStore {
set(this.details, [issueID, "vote_items"], newVotes);
});
await this.issueService.deleteIssueVote(anchor, issueID);
await this.issueService.removeVote(anchor, issueID);
} catch (error) {
console.log("Failed to remove issue vote");
const issueVotes = await this.issueService.getIssueVotes(anchor, issueID);
const issueVotes = await this.issueService.listVotes(anchor, issueID);
runInAction(() => {
set(this.details, [issueID, "vote_items"], issueVotes);

View file

@ -1,8 +1,7 @@
import { action, makeObservable, runInAction } from "mobx";
// types
// plane imports
import { SitesIssueService } from "@plane/services";
import { IssuePaginationOptions, TLoader } from "@plane/types";
// services
import IssueService from "@/services/issue.service";
// store
import { CoreRootStore } from "@/store/root.store";
// types
@ -24,7 +23,7 @@ export class IssueStore extends BaseIssuesStore implements IIssueStore {
// root store
rootStore: CoreRootStore;
// services
issueService: IssueService;
issueService: SitesIssueService;
constructor(_rootStore: CoreRootStore) {
super(_rootStore);
@ -36,7 +35,7 @@ export class IssueStore extends BaseIssuesStore implements IIssueStore {
});
this.rootStore = _rootStore;
this.issueService = new IssueService();
this.issueService = new SitesIssueService();
}
/**
@ -59,7 +58,7 @@ export class IssueStore extends BaseIssuesStore implements IIssueStore {
const params = this.rootStore.issueFilter.getFilterParams(options, anchor, undefined, undefined, undefined);
const response = await this.issueService.fetchPublicIssues(anchor, params);
const response = await this.issueService.list(anchor, params);
// after fetching issues, call the base method to process the response further
this.onfetchIssues(response, options);
@ -86,7 +85,7 @@ export class IssueStore extends BaseIssuesStore implements IIssueStore {
subGroupId
);
// call the fetch issues API with the params for next page in issues
const response = await this.issueService.fetchPublicIssues(anchor, params);
const response = await this.issueService.list(anchor, params);
// after the next page of issues are fetched, call the base method to process the response
this.onfetchNexIssues(response, groupId, subGroupId);

View file

@ -1,7 +1,9 @@
import set from "lodash/set";
import { action, computed, makeObservable, observable, runInAction } from "mobx";
// plane imports
import { SitesLabelService } from "@plane/services";
import { IIssueLabel } from "@plane/types";
import { LabelService } from "@/services/label.service";
// store
import { CoreRootStore } from "./root.store";
export interface IIssueLabelStore {
@ -16,7 +18,7 @@ export interface IIssueLabelStore {
export class LabelStore implements IIssueLabelStore {
labelMap: Record<string, IIssueLabel> = {};
labelService: LabelService;
labelService: SitesLabelService;
rootStore: CoreRootStore;
constructor(_rootStore: CoreRootStore) {
@ -28,7 +30,7 @@ export class LabelStore implements IIssueLabelStore {
// fetch action
fetchLabels: action,
});
this.labelService = new LabelService();
this.labelService = new SitesLabelService();
this.rootStore = _rootStore;
}
@ -51,7 +53,7 @@ export class LabelStore implements IIssueLabelStore {
};
fetchLabels = async (anchor: string) => {
const labelsResponse = await this.labelService.getLabels(anchor);
const labelsResponse = await this.labelService.list(anchor);
runInAction(() => {
this.labelMap = {};
for (const label of labelsResponse) {

View file

@ -1,7 +1,9 @@
import set from "lodash/set";
import { action, computed, makeObservable, observable, runInAction } from "mobx";
// plane imports
import { SitesMemberService } from "@plane/services";
import { TPublicMember } from "@/types/member";
import { MemberService } from "../services/member.service";
import { CoreRootStore } from "./root.store";
export interface IIssueMemberStore {
@ -16,7 +18,7 @@ export interface IIssueMemberStore {
export class MemberStore implements IIssueMemberStore {
memberMap: Record<string, TPublicMember> = {};
memberService: MemberService;
memberService: SitesMemberService;
rootStore: CoreRootStore;
constructor(_rootStore: CoreRootStore) {
@ -28,7 +30,7 @@ export class MemberStore implements IIssueMemberStore {
// fetch action
fetchMembers: action,
});
this.memberService = new MemberService();
this.memberService = new SitesMemberService();
this.rootStore = _rootStore;
}
@ -52,7 +54,7 @@ export class MemberStore implements IIssueMemberStore {
fetchMembers = async (anchor: string) => {
try {
const membersResponse = await this.memberService.getAnchorMembers(anchor);
const membersResponse = await this.memberService.list(anchor);
runInAction(() => {
this.memberMap = {};
for (const member of membersResponse) {

View file

@ -1,7 +1,10 @@
import set from "lodash/set";
import { action, computed, makeObservable, observable, runInAction } from "mobx";
// plane imports
import { SitesModuleService } from "@plane/services";
// types
import { TPublicModule } from "@/types/modules";
import { ModuleService } from "../services/module.service";
// root store
import { CoreRootStore } from "./root.store";
export interface IIssueModuleStore {
@ -16,7 +19,7 @@ export interface IIssueModuleStore {
export class ModuleStore implements IIssueModuleStore {
moduleMap: Record<string, TPublicModule> = {};
moduleService: ModuleService;
moduleService: SitesModuleService;
rootStore: CoreRootStore;
constructor(_rootStore: CoreRootStore) {
@ -28,7 +31,7 @@ export class ModuleStore implements IIssueModuleStore {
// fetch action
fetchModules: action,
});
this.moduleService = new ModuleService();
this.moduleService = new SitesModuleService();
this.rootStore = _rootStore;
}
@ -52,7 +55,7 @@ export class ModuleStore implements IIssueModuleStore {
fetchModules = async (anchor: string) => {
try {
const modulesResponse = await this.moduleService.getModules(anchor);
const modulesResponse = await this.moduleService.list(anchor);
runInAction(() => {
this.moduleMap = {};
for (const issueModule of modulesResponse) {

View file

@ -1,9 +1,8 @@
import set from "lodash/set";
import { action, makeObservable, observable, runInAction } from "mobx";
// types
// plane imports
import { UserService } from "@plane/services";
import { TUserProfile } from "@plane/types";
// services
import { UserService } from "@/services/user.service";
// store
import { CoreRootStore } from "@/store/root.store";
@ -85,7 +84,7 @@ export class ProfileStore implements IProfileStore {
this.isLoading = true;
this.error = undefined;
});
const userProfile = await this.userService.getCurrentUserProfile();
const userProfile = await this.userService.profile();
runInAction(() => {
this.isLoading = false;
this.data = userProfile;
@ -116,7 +115,7 @@ export class ProfileStore implements IProfileStore {
if (this.data) set(this.data, userKey, data[userKey]);
});
}
const userProfile = await this.userService.updateCurrentUserProfile(data);
const userProfile = await this.userService.updateProfile(data);
return userProfile;
} catch (error) {
if (currentUserProfileData) {

View file

@ -1,9 +1,8 @@
import set from "lodash/set";
import { makeObservable, observable, runInAction, action } from "mobx";
// types
// plane imports
import { SitesProjectPublishService } from "@plane/services";
import { TProjectPublishSettings } from "@plane/types";
// services
import PublishService from "@/services/publish.service";
// store
import { PublishStore } from "@/store/publish/publish.store";
import { CoreRootStore } from "@/store/root.store";
@ -29,7 +28,7 @@ export class PublishListStore implements IPublishListStore {
fetchPublishSettings: action,
});
// services
this.publishService = new PublishService();
this.publishService = new SitesProjectPublishService();
}
/**
@ -37,7 +36,7 @@ export class PublishListStore implements IPublishListStore {
* @param {string} anchor
*/
fetchPublishSettings = async (anchor: string) => {
const response = await this.publishService.fetchPublishSettings(anchor);
const response = await this.publishService.retrieveSettingsByAnchor(anchor);
runInAction(() => {
if (response.anchor) {
set(this.publishMap, [response.anchor], new PublishStore(this.rootStore, response));

View file

@ -1,8 +1,11 @@
import clone from "lodash/clone";
import { action, computed, makeObservable, observable, runInAction } from "mobx";
// plane imports
import { SitesStateService } from "@plane/services";
import { IState } from "@plane/types";
// helpers
import { sortStates } from "@/helpers/state.helper";
import { StateService } from "@/services/state.service";
// store
import { CoreRootStore } from "./root.store";
export interface IStateStore {
@ -18,7 +21,7 @@ export interface IStateStore {
export class StateStore implements IStateStore {
states: IState[] | undefined = undefined;
stateService: StateService;
stateService: SitesStateService;
rootStore: CoreRootStore;
constructor(_rootStore: CoreRootStore) {
@ -30,7 +33,7 @@ export class StateStore implements IStateStore {
// fetch action
fetchStates: action,
});
this.stateService = new StateService();
this.stateService = new SitesStateService();
this.rootStore = _rootStore;
}
@ -42,7 +45,7 @@ export class StateStore implements IStateStore {
getStateById = (stateId: string | undefined) => this.states?.find((state) => state.id === stateId);
fetchStates = async (anchor: string) => {
const statesResponse = await this.stateService.getStates(anchor);
const statesResponse = await this.stateService.list(anchor);
runInAction(() => {
this.states = statesResponse;
});

View file

@ -1,10 +1,8 @@
import set from "lodash/set";
import { action, computed, makeObservable, observable, runInAction } from "mobx";
// types
// plane imports
import { UserService } from "@plane/services";
import { IUser } from "@plane/types";
// services
import { AuthService } from "@/services/auth.service";
import { UserService } from "@/services/user.service";
// store types
import { ProfileStore, IProfileStore } from "@/store/profile.store";
// store
@ -45,14 +43,12 @@ export class UserStore implements IUserStore {
profile: IProfileStore;
// service
userService: UserService;
authService: AuthService;
constructor(private store: CoreRootStore) {
// stores
this.profile = new ProfileStore(store);
// service
this.userService = new UserService();
this.authService = new AuthService();
// observables
makeObservable(this, {
// observables
@ -95,7 +91,7 @@ export class UserStore implements IUserStore {
if (this.data === undefined) this.isLoading = true;
this.error = undefined;
});
const user = await this.userService.currentUser();
const user = await this.userService.me();
if (user && user?.id) {
await this.profile.fetchUserProfile();
runInAction(() => {
@ -137,7 +133,7 @@ export class UserStore implements IUserStore {
if (this.data) set(this.data, userKey, data[userKey]);
});
}
const user = await this.userService.updateUser(data);
const user = await this.userService.update(data);
return user;
} catch (error) {
if (currentUserData) {

View file

@ -1,4 +1,4 @@
import { IWorkspaceLite, TIssue, TIssuePriorities, TStateGroups } from "@plane/types";
import { IWorkspaceLite, TIssue, TIssuePriorities, TStateGroups, TIssuePublicComment } from "@plane/types";
export type TIssueLayout = "list" | "kanban" | "calendar" | "spreadsheet" | "gantt";
export type TIssueLayoutOptions = {
@ -58,7 +58,7 @@ export interface IIssue
| "link_count"
| "estimate_point"
> {
comments: Comment[];
comments: TIssuePublicComment[];
reaction_items: IIssueReaction[];
vote_items: IVote[];
}
@ -106,33 +106,6 @@ export interface IVote {
actor_details: ActorDetail;
}
export interface Comment {
actor_detail: ActorDetail;
access: string;
actor: string;
attachments: any[];
comment_html: string;
comment_reactions: {
actor_detail: ActorDetail;
comment: string;
id: string;
reaction: string;
}[];
comment_stripped: string;
created_at: Date;
created_by: string;
id: string;
is_member: boolean;
issue: string;
issue_detail: IssueDetail;
project: string;
project_detail: ProjectDetail;
updated_at: Date;
updated_by: string;
workspace: string;
workspace_detail: IWorkspaceLite;
}
export interface IIssueReaction {
actor_details: ActorDetail;
reaction: string;