chore: minor optimizations

This commit is contained in:
sriram veeraghanta 2023-11-01 12:56:06 +05:30
parent 80e6d7e1ea
commit dcf04b21f9
3 changed files with 47 additions and 75 deletions

View File

@ -62,7 +62,7 @@ export class UserService extends APIService {
});
}
async updateUser(data: Partial<IUser>): Promise<any> {
async updateUser(data: Partial<IUser>): Promise<IUser> {
return this.patch("/api/users/me/", data)
.then((response) => response?.data)
.catch((error) => {

View File

@ -3,7 +3,7 @@ import { action, observable, runInAction, makeAutoObservable } from "mobx";
// services
import { IssueDraftService } from "services/issue";
// types
import type { IIssue, IUser } from "types";
import type { IIssue } from "types";
export class DraftIssuesStore {
issues: { [key: string]: IIssue } = {};
@ -58,23 +58,15 @@ export class DraftIssuesStore {
getIssueById = async (workspaceSlug: string, projectId: string, issueId: string): Promise<IIssue> => {
if (this.issues[issueId]) return this.issues[issueId];
try {
const issueResponse: IIssue = await this.issueDraftService.getDraftIssueById(workspaceSlug, projectId, issueId);
const issues = {
...this.issues,
[issueId]: { ...issueResponse },
};
runInAction(() => {
this.issues = issues;
});
return issueResponse;
} catch (error) {
throw error;
}
};
/**
@ -86,37 +78,18 @@ export class DraftIssuesStore {
* @returns {IIssue}
*/
createDraftIssue = async (
workspaceSlug: string,
projectId: string,
issueForm: IIssue,
user: IUser
): Promise<IIssue> => {
try {
createDraftIssue = async (workspaceSlug: string, projectId: string, issueForm: IIssue): Promise<IIssue> => {
const issueResponse = await this.issueDraftService.createDraftIssue(workspaceSlug, projectId, issueForm);
const issues = {
runInAction(() => {
this.issues = {
...this.issues,
[issueResponse.id]: { ...issueResponse },
};
runInAction(() => {
this.issues = issues;
});
return issueResponse;
} catch (error) {
console.error("Creating issue error", error);
throw error;
}
};
updateDraftIssue = async (
workspaceSlug: string,
projectId: string,
issueId: string,
issueForm: Partial<IIssue>,
user: IUser
) => {
updateDraftIssue = async (workspaceSlug: string, projectId: string, issueId: string, issueForm: Partial<IIssue>) => {
// keep a copy of the issue in the store
const originalIssue = { ...this.issues[issueId] };
@ -152,7 +125,7 @@ export class DraftIssuesStore {
}
};
deleteDraftIssue = async (workspaceSlug: string, projectId: string, issueId: string, user: IUser) => {
deleteDraftIssue = async (workspaceSlug: string, projectId: string, issueId: string) => {
const issues = { ...this.issues };
delete issues[issueId];

View File

@ -100,29 +100,19 @@ class UserStore implements IUserStore {
};
fetchCurrentUserSettings = async () => {
try {
const response = await this.userService.currentUserSettings();
if (response) {
runInAction(() => {
this.currentUserSettings = response;
});
}
return response;
} catch (error) {
throw error;
}
};
fetchUserDashboardInfo = async (workspaceSlug: string, month: number) => {
try {
const response = await this.userService.userWorkspaceDashboard(workspaceSlug, month);
runInAction(() => {
this.dashboardInfo = response;
});
return response;
} catch (error) {
throw error;
}
};
fetchUserWorkspaceInfo = async (workspaceSlug: string) => {
@ -176,20 +166,22 @@ class UserStore implements IUserStore {
return response;
}
} catch (error) {
runInAction(() => {
this.currentUser = {
...this.currentUser,
is_tour_completed: false,
} as IUser;
});
throw error;
}
};
updateCurrentUser = async (data: Partial<IUser>) => {
try {
const response = await this.userService.updateUser(data);
runInAction(() => {
this.currentUser = response;
});
return response;
} catch (error) {
throw error;
}
};
updateCurrentUserTheme = async (theme: string) => {
@ -208,6 +200,13 @@ class UserStore implements IUserStore {
} as IUser);
return response;
} catch (error) {
const response = await this.userService.currentUser();
runInAction(() => {
this.currentUser = {
...this.currentUser,
theme: response.theme,
} as IUser;
});
throw error;
}
};