mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
efd3ebf067
* refactor: updated preloaded function for the list view quick add * fix: resolved bug in the assignee dropdown * chore: issue sidebar link improvement * fix: resolved subscription store bug * chore: updated preloaded function for the kanban layout quick add * chore: resolved issues in the list filters and component * chore: filter store updated * fix: issue serializer changed * chore: quick add preload function updated * fix: build error * fix: serializer changed * fix: minor request change * chore: resolved build issues and updated the prepopulated data in the quick add issue. * fix: build fix and code refactor * fix: spreadsheet layout quick add fix * fix: issue peek overview link section updated * fix: cycle status bug fix * fix: serializer changes * fix: assignee and labels listing * chore: issue modal parent_id default value updated * fix: cycle and module issue serializer change * fix: cycle list serializer changed * chore: prepopulated validation in both list and kanban for quick add and group header add issues * chore: group header validation added * fix: issue response payload change * dev: make cycle and module issue create response simillar * chore: custom control link component added * dev: make issue create and update response simillar to list and retrieve * fix: build error * chore: control link component improvement * chore: globalise issue peek overview * chore: control link component improvement * chore: made changes and optimised the issue peek overview root * build-error: resolved build erros for issueId dependancy from issue detail store * chore: peek overview link fix * dev: update state nullable rule --------- Co-authored-by: gurusainath <gurusainath007@gmail.com> Co-authored-by: NarayanBavisetti <narayan3119@gmail.com> Co-authored-by: pablohashescobar <nikhilschacko@gmail.com>
113 lines
3.7 KiB
TypeScript
113 lines
3.7 KiB
TypeScript
import { action, makeObservable, observable, runInAction } from "mobx";
|
|
import set from "lodash/set";
|
|
// services
|
|
import { NotificationService } from "services/notification.service";
|
|
// types
|
|
import { IIssueDetail } from "./root.store";
|
|
|
|
export interface IIssueSubscriptionStoreActions {
|
|
fetchSubscriptions: (workspaceSlug: string, projectId: string, issueId: string) => Promise<any>;
|
|
createSubscription: (workspaceSlug: string, projectId: string, issueId: string) => Promise<any>;
|
|
removeSubscription: (workspaceSlug: string, projectId: string, issueId: string) => Promise<any>;
|
|
}
|
|
|
|
export interface IIssueSubscriptionStore extends IIssueSubscriptionStoreActions {
|
|
// observables
|
|
subscriptionMap: Record<string, Record<string, Record<string, boolean>>>; // Record defines subscriptionId as key and link as value
|
|
// helper methods
|
|
getSubscriptionByIssueId: (issueId: string) => Record<string, boolean> | undefined;
|
|
}
|
|
|
|
export class IssueSubscriptionStore implements IIssueSubscriptionStore {
|
|
// observables
|
|
subscriptionMap: Record<string, Record<string, Record<string, boolean>>> = {};
|
|
// root store
|
|
rootIssueDetail: IIssueDetail;
|
|
// services
|
|
notificationService;
|
|
|
|
constructor(rootStore: IIssueDetail) {
|
|
makeObservable(this, {
|
|
// observables
|
|
subscriptionMap: observable,
|
|
// actions
|
|
fetchSubscriptions: action,
|
|
createSubscription: action,
|
|
removeSubscription: action,
|
|
});
|
|
// root store
|
|
this.rootIssueDetail = rootStore;
|
|
// services
|
|
this.notificationService = new NotificationService();
|
|
}
|
|
|
|
// helper methods
|
|
getSubscriptionByIssueId = (issueId: string) => {
|
|
if (!issueId) return undefined;
|
|
const currentUserId = this.rootIssueDetail.rootIssueStore.currentUserId;
|
|
if (!currentUserId) return undefined;
|
|
return this.subscriptionMap[issueId]?.[currentUserId] ?? undefined;
|
|
};
|
|
|
|
fetchSubscriptions = async (workspaceSlug: string, projectId: string, issueId: string) => {
|
|
try {
|
|
const currentUserId = this.rootIssueDetail.rootIssueStore.currentUserId;
|
|
if (!currentUserId) throw new Error("user id not available");
|
|
|
|
const subscription = await this.notificationService.getIssueNotificationSubscriptionStatus(
|
|
workspaceSlug,
|
|
projectId,
|
|
issueId
|
|
);
|
|
|
|
runInAction(() => {
|
|
set(this.subscriptionMap, [issueId, currentUserId], subscription);
|
|
});
|
|
|
|
return subscription;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
createSubscription = async (workspaceSlug: string, projectId: string, issueId: string) => {
|
|
try {
|
|
const currentUserId = this.rootIssueDetail.rootIssueStore.currentUserId;
|
|
if (!currentUserId) throw new Error("user id not available");
|
|
|
|
runInAction(() => {
|
|
set(this.subscriptionMap, [issueId, currentUserId], { subscribed: true });
|
|
});
|
|
|
|
const response = await this.notificationService.subscribeToIssueNotifications(workspaceSlug, projectId, issueId);
|
|
|
|
return response;
|
|
} catch (error) {
|
|
this.fetchSubscriptions(workspaceSlug, projectId, issueId);
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
removeSubscription = async (workspaceSlug: string, projectId: string, issueId: string) => {
|
|
try {
|
|
const currentUserId = this.rootIssueDetail.rootIssueStore.currentUserId;
|
|
if (!currentUserId) throw new Error("user id not available");
|
|
|
|
runInAction(() => {
|
|
set(this.subscriptionMap, [issueId, currentUserId], { subscribed: false });
|
|
});
|
|
|
|
const response = await this.notificationService.unsubscribeFromIssueNotifications(
|
|
workspaceSlug,
|
|
projectId,
|
|
issueId
|
|
);
|
|
|
|
return response;
|
|
} catch (error) {
|
|
this.fetchSubscriptions(workspaceSlug, projectId, issueId);
|
|
throw error;
|
|
}
|
|
};
|
|
}
|