2024-03-06 15:17:38 +00:00
|
|
|
import { EIssueFilterType, EIssuesStoreType } from "constants/issue";
|
|
|
|
import { useApplication, useIssues } from "./store";
|
|
|
|
import {
|
|
|
|
IIssueDisplayFilterOptions,
|
|
|
|
IIssueDisplayProperties,
|
|
|
|
IIssueFilterOptions,
|
2024-03-08 11:33:35 +00:00
|
|
|
IssuePaginationOptions,
|
2024-03-06 15:17:38 +00:00
|
|
|
TIssue,
|
|
|
|
TIssueKanbanFilters,
|
2024-03-08 11:33:35 +00:00
|
|
|
TIssuesResponse,
|
2024-03-06 15:17:38 +00:00
|
|
|
TLoader,
|
|
|
|
} from "@plane/types";
|
|
|
|
import { useCallback, useMemo } from "react";
|
|
|
|
|
|
|
|
interface IssueActions {
|
2024-03-08 11:33:35 +00:00
|
|
|
fetchIssues: (
|
|
|
|
loadType: TLoader,
|
|
|
|
options: IssuePaginationOptions,
|
|
|
|
userViewId?: "assigned" | "created" | "subscribed"
|
|
|
|
) => Promise<TIssuesResponse | undefined>;
|
2024-03-22 10:25:08 +00:00
|
|
|
fetchNextIssues: (groupId?: string, subGroupId?: string) => Promise<TIssuesResponse | undefined>;
|
2024-03-08 12:51:28 +00:00
|
|
|
removeIssue: (projectId: string | undefined | null, issueId: string) => Promise<void>;
|
|
|
|
createIssue?: (projectId: string | undefined | null, data: Partial<TIssue>) => Promise<TIssue | undefined>;
|
|
|
|
updateIssue?: (projectId: string | undefined | null, issueId: string, data: Partial<TIssue>) => Promise<void>;
|
|
|
|
removeIssueFromView?: (projectId: string | undefined | null, issueId: string) => Promise<void>;
|
|
|
|
archiveIssue?: (projectId: string | undefined | null, issueId: string) => Promise<void>;
|
|
|
|
restoreIssue?: (projectId: string | undefined | null, issueId: string) => Promise<void>;
|
2024-03-06 15:17:38 +00:00
|
|
|
updateFilters: (
|
|
|
|
projectId: string,
|
|
|
|
filterType: EIssueFilterType,
|
|
|
|
filters: IIssueFilterOptions | IIssueDisplayFilterOptions | IIssueDisplayProperties | TIssueKanbanFilters
|
|
|
|
) => Promise<void>;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const useIssuesActions = (storeType: EIssuesStoreType): IssueActions => {
|
|
|
|
const projectIssueActions = useProjectIssueActions();
|
|
|
|
const cycleIssueActions = useCycleIssueActions();
|
|
|
|
const moduleIssueActions = useModuleIssueActions();
|
|
|
|
const projectViewIssueActions = useProjectViewIssueActions();
|
2024-03-08 11:33:35 +00:00
|
|
|
const globalIssueActions = useGlobalIssueActions();
|
|
|
|
const profileIssueActions = useProfileIssueActions();
|
2024-03-06 15:17:38 +00:00
|
|
|
const draftIssueActions = useDraftIssueActions();
|
|
|
|
const archivedIssueActions = useArchivedIssueActions();
|
|
|
|
|
|
|
|
switch (storeType) {
|
|
|
|
case EIssuesStoreType.PROJECT_VIEW:
|
|
|
|
return projectViewIssueActions;
|
|
|
|
case EIssuesStoreType.PROFILE:
|
|
|
|
return profileIssueActions;
|
|
|
|
case EIssuesStoreType.ARCHIVED:
|
|
|
|
return archivedIssueActions;
|
|
|
|
case EIssuesStoreType.DRAFT:
|
|
|
|
return draftIssueActions;
|
2024-03-08 11:33:35 +00:00
|
|
|
case EIssuesStoreType.CYCLE:
|
|
|
|
return cycleIssueActions;
|
|
|
|
case EIssuesStoreType.MODULE:
|
|
|
|
return moduleIssueActions;
|
2024-03-06 15:17:38 +00:00
|
|
|
case EIssuesStoreType.GLOBAL:
|
|
|
|
return globalIssueActions;
|
|
|
|
case EIssuesStoreType.PROJECT:
|
|
|
|
default:
|
|
|
|
return projectIssueActions;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const useProjectIssueActions = () => {
|
|
|
|
const { issues, issuesFilter } = useIssues(EIssuesStoreType.PROJECT);
|
|
|
|
|
|
|
|
const {
|
2024-03-08 11:33:35 +00:00
|
|
|
router: { workspaceSlug, projectId },
|
2024-03-06 15:17:38 +00:00
|
|
|
} = useApplication();
|
|
|
|
|
|
|
|
const fetchIssues = useCallback(
|
2024-03-08 11:33:35 +00:00
|
|
|
async (loadType: TLoader, options: IssuePaginationOptions) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
return issues.fetchIssues(workspaceSlug.toString(), projectId.toString(), loadType, options);
|
2024-03-06 15:17:38 +00:00
|
|
|
},
|
2024-03-08 11:33:35 +00:00
|
|
|
[issues.fetchIssues, workspaceSlug, projectId]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
2024-03-22 10:25:08 +00:00
|
|
|
const fetchNextIssues = useCallback(
|
|
|
|
async (groupId?: string, subGroupId?: string) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
return issues.fetchNextIssues(workspaceSlug.toString(), projectId.toString(), groupId, subGroupId);
|
|
|
|
},
|
|
|
|
[issues.fetchIssues, workspaceSlug, projectId]
|
|
|
|
);
|
2024-03-08 11:33:35 +00:00
|
|
|
|
2024-03-06 15:17:38 +00:00
|
|
|
const createIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, data: Partial<TIssue>) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2024-03-06 15:17:38 +00:00
|
|
|
return await issues.createIssue(workspaceSlug, projectId, data);
|
|
|
|
},
|
|
|
|
[issues.createIssue, workspaceSlug]
|
|
|
|
);
|
|
|
|
const updateIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, issueId: string, data: Partial<TIssue>) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2024-03-06 15:17:38 +00:00
|
|
|
return await issues.updateIssue(workspaceSlug, projectId, issueId, data);
|
|
|
|
},
|
|
|
|
[issues.updateIssue, workspaceSlug]
|
|
|
|
);
|
|
|
|
const removeIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, issueId: string) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2024-03-06 15:17:38 +00:00
|
|
|
return await issues.removeIssue(workspaceSlug, projectId, issueId);
|
|
|
|
},
|
|
|
|
[issues.removeIssue, workspaceSlug]
|
|
|
|
);
|
|
|
|
const archiveIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, issueId: string) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2024-03-06 15:17:38 +00:00
|
|
|
return await issues.archiveIssue(workspaceSlug, projectId, issueId);
|
|
|
|
},
|
|
|
|
[issues.archiveIssue, workspaceSlug]
|
|
|
|
);
|
|
|
|
|
|
|
|
const updateFilters = useCallback(
|
|
|
|
async (
|
|
|
|
projectId: string,
|
|
|
|
filterType: EIssueFilterType,
|
|
|
|
filters: IIssueFilterOptions | IIssueDisplayFilterOptions | IIssueDisplayProperties | TIssueKanbanFilters
|
|
|
|
) => {
|
|
|
|
if (!workspaceSlug) return;
|
|
|
|
return await issuesFilter.updateFilters(workspaceSlug, projectId, filterType, filters);
|
|
|
|
},
|
|
|
|
[issuesFilter.updateFilters, workspaceSlug]
|
|
|
|
);
|
|
|
|
|
|
|
|
return useMemo(
|
|
|
|
() => ({
|
|
|
|
fetchIssues,
|
2024-03-08 11:33:35 +00:00
|
|
|
fetchNextIssues,
|
2024-03-06 15:17:38 +00:00
|
|
|
createIssue,
|
|
|
|
updateIssue,
|
|
|
|
removeIssue,
|
|
|
|
archiveIssue,
|
|
|
|
updateFilters,
|
|
|
|
}),
|
2024-03-08 11:33:35 +00:00
|
|
|
[fetchIssues, fetchNextIssues, createIssue, updateIssue, removeIssue, archiveIssue, updateFilters]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const useCycleIssueActions = () => {
|
|
|
|
const { issues, issuesFilter } = useIssues(EIssuesStoreType.CYCLE);
|
|
|
|
|
|
|
|
const {
|
2024-03-08 11:33:35 +00:00
|
|
|
router: { workspaceSlug, projectId, cycleId },
|
2024-03-06 15:17:38 +00:00
|
|
|
} = useApplication();
|
|
|
|
|
|
|
|
const fetchIssues = useCallback(
|
2024-03-08 11:33:35 +00:00
|
|
|
async (loadType: TLoader, options: IssuePaginationOptions) => {
|
|
|
|
if (!workspaceSlug || !projectId || !cycleId) return;
|
|
|
|
return issues.fetchIssues(workspaceSlug.toString(), projectId.toString(), loadType, options, cycleId.toString());
|
2024-03-06 15:17:38 +00:00
|
|
|
},
|
2024-03-08 11:33:35 +00:00
|
|
|
[issues.fetchIssues, workspaceSlug, projectId, cycleId]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
2024-03-22 10:25:08 +00:00
|
|
|
const fetchNextIssues = useCallback(
|
|
|
|
async (groupId?: string, subGroupId?: string) => {
|
|
|
|
if (!workspaceSlug || !projectId || !cycleId) return;
|
|
|
|
return issues.fetchNextIssues(
|
|
|
|
workspaceSlug.toString(),
|
|
|
|
projectId.toString(),
|
|
|
|
cycleId.toString(),
|
|
|
|
groupId,
|
|
|
|
subGroupId
|
|
|
|
);
|
|
|
|
},
|
|
|
|
[issues.fetchIssues, workspaceSlug, projectId, cycleId]
|
|
|
|
);
|
2024-03-08 11:33:35 +00:00
|
|
|
|
2024-03-06 15:17:38 +00:00
|
|
|
const createIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, data: Partial<TIssue>) => {
|
|
|
|
if (!cycleId || !workspaceSlug || !projectId) return;
|
2024-03-06 15:17:38 +00:00
|
|
|
return await issues.createIssue(workspaceSlug, projectId, data, cycleId);
|
|
|
|
},
|
|
|
|
[issues.createIssue, cycleId, workspaceSlug]
|
|
|
|
);
|
|
|
|
const updateIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, issueId: string, data: Partial<TIssue>) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2024-03-08 11:33:35 +00:00
|
|
|
return await issues.updateIssue(workspaceSlug, projectId, issueId, data);
|
2024-03-06 15:17:38 +00:00
|
|
|
},
|
2024-03-08 11:33:35 +00:00
|
|
|
[issues.updateIssue, workspaceSlug]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
|
|
|
const removeIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, issueId: string) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2024-03-08 11:33:35 +00:00
|
|
|
return await issues.removeIssue(workspaceSlug, projectId, issueId);
|
2024-03-06 15:17:38 +00:00
|
|
|
},
|
2024-03-08 11:33:35 +00:00
|
|
|
[issues.removeIssue, workspaceSlug]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
|
|
|
const removeIssueFromView = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, issueId: string) => {
|
|
|
|
if (!cycleId || !workspaceSlug || !projectId) return;
|
2024-03-06 15:17:38 +00:00
|
|
|
return await issues.removeIssueFromCycle(workspaceSlug, projectId, cycleId, issueId);
|
|
|
|
},
|
|
|
|
[issues.removeIssueFromCycle, cycleId, workspaceSlug]
|
|
|
|
);
|
|
|
|
const archiveIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, issueId: string) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2024-03-08 11:33:35 +00:00
|
|
|
return await issues.archiveIssue(workspaceSlug, projectId, issueId);
|
2024-03-06 15:17:38 +00:00
|
|
|
},
|
2024-03-08 11:33:35 +00:00
|
|
|
[issues.archiveIssue, workspaceSlug]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const updateFilters = useCallback(
|
|
|
|
async (
|
|
|
|
projectId: string,
|
|
|
|
filterType: EIssueFilterType,
|
|
|
|
filters: IIssueFilterOptions | IIssueDisplayFilterOptions | IIssueDisplayProperties | TIssueKanbanFilters
|
|
|
|
) => {
|
|
|
|
if (!cycleId || !workspaceSlug) return;
|
|
|
|
return await issuesFilter.updateFilters(workspaceSlug, projectId, filterType, filters, cycleId);
|
|
|
|
},
|
|
|
|
[issuesFilter.updateFilters, cycleId, workspaceSlug]
|
|
|
|
);
|
|
|
|
|
|
|
|
return useMemo(
|
|
|
|
() => ({
|
|
|
|
fetchIssues,
|
2024-03-08 11:33:35 +00:00
|
|
|
fetchNextIssues,
|
2024-03-06 15:17:38 +00:00
|
|
|
createIssue,
|
|
|
|
updateIssue,
|
|
|
|
removeIssue,
|
|
|
|
removeIssueFromView,
|
|
|
|
archiveIssue,
|
|
|
|
updateFilters,
|
|
|
|
}),
|
2024-03-08 11:33:35 +00:00
|
|
|
[
|
|
|
|
fetchIssues,
|
|
|
|
fetchNextIssues,
|
|
|
|
createIssue,
|
|
|
|
updateIssue,
|
|
|
|
removeIssue,
|
|
|
|
removeIssueFromView,
|
|
|
|
archiveIssue,
|
|
|
|
updateFilters,
|
|
|
|
]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const useModuleIssueActions = () => {
|
|
|
|
const { issues, issuesFilter } = useIssues(EIssuesStoreType.MODULE);
|
|
|
|
|
|
|
|
const {
|
2024-03-08 11:33:35 +00:00
|
|
|
router: { workspaceSlug, projectId, moduleId },
|
2024-03-06 15:17:38 +00:00
|
|
|
} = useApplication();
|
|
|
|
|
|
|
|
const fetchIssues = useCallback(
|
2024-03-08 11:33:35 +00:00
|
|
|
async (loadType: TLoader, options: IssuePaginationOptions) => {
|
|
|
|
if (!workspaceSlug || !projectId || !moduleId) return;
|
|
|
|
return issues.fetchIssues(workspaceSlug.toString(), projectId.toString(), loadType, options, moduleId.toString());
|
2024-03-06 15:17:38 +00:00
|
|
|
},
|
2024-03-08 11:33:35 +00:00
|
|
|
[issues.fetchIssues, workspaceSlug, projectId, moduleId]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
2024-03-22 10:25:08 +00:00
|
|
|
const fetchNextIssues = useCallback(
|
|
|
|
async (groupId?: string, subGroupId?: string) => {
|
|
|
|
if (!workspaceSlug || !projectId || !moduleId) return;
|
|
|
|
return issues.fetchNextIssues(
|
|
|
|
workspaceSlug.toString(),
|
|
|
|
projectId.toString(),
|
|
|
|
moduleId.toString(),
|
|
|
|
groupId,
|
|
|
|
subGroupId
|
|
|
|
);
|
|
|
|
},
|
|
|
|
[issues.fetchIssues, workspaceSlug, projectId, moduleId]
|
|
|
|
);
|
2024-03-08 11:33:35 +00:00
|
|
|
|
2024-03-06 15:17:38 +00:00
|
|
|
const createIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, data: Partial<TIssue>) => {
|
|
|
|
if (!moduleId || !workspaceSlug || !projectId) return;
|
2024-03-06 15:17:38 +00:00
|
|
|
return await issues.createIssue(workspaceSlug, projectId, data, moduleId);
|
|
|
|
},
|
|
|
|
[issues.createIssue, moduleId, workspaceSlug]
|
|
|
|
);
|
|
|
|
const updateIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, issueId: string, data: Partial<TIssue>) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2024-03-08 11:33:35 +00:00
|
|
|
return await issues.updateIssue(workspaceSlug, projectId, issueId, data);
|
2024-03-06 15:17:38 +00:00
|
|
|
},
|
2024-03-08 11:33:35 +00:00
|
|
|
[issues.updateIssue, workspaceSlug]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
|
|
|
const removeIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, issueId: string) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2024-03-08 11:33:35 +00:00
|
|
|
return await issues.removeIssue(workspaceSlug, projectId, issueId);
|
2024-03-06 15:17:38 +00:00
|
|
|
},
|
2024-03-08 11:33:35 +00:00
|
|
|
[issues.removeIssue, workspaceSlug]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
|
|
|
const removeIssueFromView = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, issueId: string) => {
|
|
|
|
if (!moduleId || !workspaceSlug || !projectId) return;
|
2024-03-06 15:17:38 +00:00
|
|
|
return await issues.removeIssueFromModule(workspaceSlug, projectId, moduleId, issueId);
|
|
|
|
},
|
|
|
|
[issues.removeIssueFromModule, moduleId, workspaceSlug]
|
|
|
|
);
|
|
|
|
const archiveIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, issueId: string) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2024-03-08 11:33:35 +00:00
|
|
|
return await issues.archiveIssue(workspaceSlug, projectId, issueId);
|
2024-03-06 15:17:38 +00:00
|
|
|
},
|
|
|
|
[issues.archiveIssue, moduleId, workspaceSlug]
|
|
|
|
);
|
|
|
|
|
|
|
|
const updateFilters = useCallback(
|
|
|
|
async (
|
|
|
|
projectId: string,
|
|
|
|
filterType: EIssueFilterType,
|
|
|
|
filters: IIssueFilterOptions | IIssueDisplayFilterOptions | IIssueDisplayProperties | TIssueKanbanFilters
|
|
|
|
) => {
|
|
|
|
if (!moduleId || !workspaceSlug) return;
|
|
|
|
return await issuesFilter.updateFilters(workspaceSlug, projectId, filterType, filters, moduleId);
|
|
|
|
},
|
|
|
|
[issuesFilter.updateFilters, moduleId]
|
|
|
|
);
|
|
|
|
|
|
|
|
return useMemo(
|
|
|
|
() => ({
|
|
|
|
fetchIssues,
|
2024-03-08 11:33:35 +00:00
|
|
|
fetchNextIssues,
|
2024-03-06 15:17:38 +00:00
|
|
|
createIssue,
|
|
|
|
updateIssue,
|
|
|
|
removeIssue,
|
|
|
|
removeIssueFromView,
|
|
|
|
archiveIssue,
|
|
|
|
updateFilters,
|
|
|
|
}),
|
|
|
|
[fetchIssues, createIssue, updateIssue, removeIssue, removeIssueFromView, archiveIssue, updateFilters]
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const useProfileIssueActions = () => {
|
|
|
|
const { issues, issuesFilter } = useIssues(EIssuesStoreType.PROFILE);
|
|
|
|
|
|
|
|
const {
|
|
|
|
router: { workspaceSlug, userId },
|
|
|
|
} = useApplication();
|
|
|
|
|
|
|
|
const fetchIssues = useCallback(
|
2024-03-08 11:33:35 +00:00
|
|
|
async (loadType: TLoader, options: IssuePaginationOptions, viewId?: "assigned" | "created" | "subscribed") => {
|
|
|
|
if (!workspaceSlug || !userId || !viewId) return;
|
|
|
|
return issues.fetchIssues(workspaceSlug.toString(), userId.toString(), loadType, options, viewId);
|
2024-03-06 15:17:38 +00:00
|
|
|
},
|
2024-03-08 11:33:35 +00:00
|
|
|
[issues.fetchIssues, workspaceSlug, userId]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
2024-03-22 10:25:08 +00:00
|
|
|
const fetchNextIssues = useCallback(
|
|
|
|
async (groupId?: string, subGroupId?: string) => {
|
|
|
|
if (!workspaceSlug || !userId) return;
|
|
|
|
return issues.fetchNextIssues(workspaceSlug.toString(), userId.toString(), groupId, subGroupId);
|
|
|
|
},
|
|
|
|
[issues.fetchIssues, workspaceSlug, userId]
|
|
|
|
);
|
2024-03-08 11:33:35 +00:00
|
|
|
|
2024-03-06 15:17:38 +00:00
|
|
|
const createIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, data: Partial<TIssue>) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2024-03-08 11:33:35 +00:00
|
|
|
return await issues.createIssue(workspaceSlug, projectId, data);
|
2024-03-06 15:17:38 +00:00
|
|
|
},
|
2024-03-08 11:33:35 +00:00
|
|
|
[issues.createIssue, workspaceSlug]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
|
|
|
const updateIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, issueId: string, data: Partial<TIssue>) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2024-03-08 11:33:35 +00:00
|
|
|
return await issues.updateIssue(workspaceSlug, projectId, issueId, data);
|
2024-03-06 15:17:38 +00:00
|
|
|
},
|
2024-03-08 11:33:35 +00:00
|
|
|
[issues.updateIssue, workspaceSlug]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
|
|
|
const removeIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, issueId: string) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2024-03-08 11:33:35 +00:00
|
|
|
return await issues.removeIssue(workspaceSlug, projectId, issueId);
|
2024-03-06 15:17:38 +00:00
|
|
|
},
|
2024-03-08 11:33:35 +00:00
|
|
|
[issues.removeIssue, workspaceSlug]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
|
|
|
const archiveIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, issueId: string) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2024-03-08 11:33:35 +00:00
|
|
|
return await issues.archiveIssue(workspaceSlug, projectId, issueId);
|
2024-03-06 15:17:38 +00:00
|
|
|
},
|
2024-03-08 11:33:35 +00:00
|
|
|
[issues.archiveIssue, workspaceSlug]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const updateFilters = useCallback(
|
|
|
|
async (
|
|
|
|
projectId: string,
|
|
|
|
filterType: EIssueFilterType,
|
|
|
|
filters: IIssueFilterOptions | IIssueDisplayFilterOptions | IIssueDisplayProperties | TIssueKanbanFilters
|
|
|
|
) => {
|
|
|
|
if (!userId || !workspaceSlug) return;
|
|
|
|
return await issuesFilter.updateFilters(workspaceSlug, projectId, filterType, filters, userId);
|
|
|
|
},
|
|
|
|
[issuesFilter.updateFilters, userId, workspaceSlug]
|
|
|
|
);
|
|
|
|
|
|
|
|
return useMemo(
|
|
|
|
() => ({
|
|
|
|
fetchIssues,
|
2024-03-08 11:33:35 +00:00
|
|
|
fetchNextIssues,
|
2024-03-06 15:17:38 +00:00
|
|
|
createIssue,
|
|
|
|
updateIssue,
|
|
|
|
removeIssue,
|
|
|
|
archiveIssue,
|
|
|
|
updateFilters,
|
|
|
|
}),
|
|
|
|
[fetchIssues, createIssue, updateIssue, removeIssue, archiveIssue, updateFilters]
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const useProjectViewIssueActions = () => {
|
|
|
|
const { issues, issuesFilter } = useIssues(EIssuesStoreType.PROJECT_VIEW);
|
|
|
|
|
|
|
|
const {
|
2024-03-08 11:33:35 +00:00
|
|
|
router: { workspaceSlug, projectId, viewId },
|
2024-03-06 15:17:38 +00:00
|
|
|
} = useApplication();
|
|
|
|
|
|
|
|
const fetchIssues = useCallback(
|
2024-03-08 11:33:35 +00:00
|
|
|
async (loadType: TLoader, options: IssuePaginationOptions) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
return issues.fetchIssues(workspaceSlug.toString(), projectId.toString(), loadType, options);
|
2024-03-06 15:17:38 +00:00
|
|
|
},
|
2024-03-08 11:33:35 +00:00
|
|
|
[issues.fetchIssues, workspaceSlug, projectId]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
2024-03-22 10:25:08 +00:00
|
|
|
const fetchNextIssues = useCallback(
|
|
|
|
async (groupId?: string, subGroupId?: string) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
return issues.fetchNextIssues(workspaceSlug.toString(), projectId.toString(), groupId, subGroupId);
|
|
|
|
},
|
|
|
|
[issues.fetchIssues, workspaceSlug, projectId]
|
|
|
|
);
|
2024-03-08 11:33:35 +00:00
|
|
|
|
2024-03-06 15:17:38 +00:00
|
|
|
const createIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, data: Partial<TIssue>) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2024-03-08 11:33:35 +00:00
|
|
|
return await issues.createIssue(workspaceSlug, projectId, data);
|
2024-03-06 15:17:38 +00:00
|
|
|
},
|
2024-03-08 11:33:35 +00:00
|
|
|
[issues.createIssue, workspaceSlug]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
|
|
|
const updateIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, issueId: string, data: Partial<TIssue>) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2024-03-08 11:33:35 +00:00
|
|
|
return await issues.updateIssue(workspaceSlug, projectId, issueId, data);
|
2024-03-06 15:17:38 +00:00
|
|
|
},
|
2024-03-08 11:33:35 +00:00
|
|
|
[issues.updateIssue, workspaceSlug]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
|
|
|
const removeIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, issueId: string) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2024-03-08 11:33:35 +00:00
|
|
|
return await issues.removeIssue(workspaceSlug, projectId, issueId);
|
2024-03-06 15:17:38 +00:00
|
|
|
},
|
2024-03-08 11:33:35 +00:00
|
|
|
[issues.removeIssue, workspaceSlug]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
|
|
|
const archiveIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, issueId: string) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2024-03-08 11:33:35 +00:00
|
|
|
return await issues.archiveIssue(workspaceSlug, projectId, issueId);
|
2024-03-06 15:17:38 +00:00
|
|
|
},
|
2024-03-08 11:33:35 +00:00
|
|
|
[issues.archiveIssue, workspaceSlug]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const updateFilters = useCallback(
|
|
|
|
async (
|
|
|
|
projectId: string,
|
|
|
|
filterType: EIssueFilterType,
|
|
|
|
filters: IIssueFilterOptions | IIssueDisplayFilterOptions | IIssueDisplayProperties | TIssueKanbanFilters
|
|
|
|
) => {
|
|
|
|
if (!viewId || !workspaceSlug) return;
|
|
|
|
return await issuesFilter.updateFilters(workspaceSlug, projectId, filterType, filters, viewId);
|
|
|
|
},
|
|
|
|
[issuesFilter.updateFilters, viewId, workspaceSlug]
|
|
|
|
);
|
|
|
|
|
|
|
|
return useMemo(
|
|
|
|
() => ({
|
|
|
|
fetchIssues,
|
2024-03-08 11:33:35 +00:00
|
|
|
fetchNextIssues,
|
2024-03-06 15:17:38 +00:00
|
|
|
createIssue,
|
|
|
|
updateIssue,
|
|
|
|
removeIssue,
|
|
|
|
archiveIssue,
|
|
|
|
updateFilters,
|
|
|
|
}),
|
2024-03-08 11:33:35 +00:00
|
|
|
[fetchIssues, fetchNextIssues, createIssue, updateIssue, removeIssue, archiveIssue, updateFilters]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const useDraftIssueActions = () => {
|
|
|
|
const { issues, issuesFilter } = useIssues(EIssuesStoreType.DRAFT);
|
|
|
|
|
|
|
|
const {
|
2024-03-08 11:33:35 +00:00
|
|
|
router: { workspaceSlug, projectId },
|
2024-03-06 15:17:38 +00:00
|
|
|
} = useApplication();
|
|
|
|
|
|
|
|
const fetchIssues = useCallback(
|
2024-03-08 11:33:35 +00:00
|
|
|
async (loadType: TLoader, options: IssuePaginationOptions) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
return issues.fetchIssues(workspaceSlug.toString(), projectId.toString(), loadType, options);
|
2024-03-06 15:17:38 +00:00
|
|
|
},
|
2024-03-08 11:33:35 +00:00
|
|
|
[issues.fetchIssues, workspaceSlug, projectId]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
2024-03-22 10:25:08 +00:00
|
|
|
const fetchNextIssues = useCallback(
|
|
|
|
async (groupId?: string, subGroupId?: string) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
return issues.fetchNextIssues(workspaceSlug.toString(), projectId.toString(), groupId, subGroupId);
|
|
|
|
},
|
|
|
|
[issues.fetchIssues, workspaceSlug, projectId]
|
|
|
|
);
|
2024-03-08 11:33:35 +00:00
|
|
|
|
2024-03-06 15:17:38 +00:00
|
|
|
const createIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, data: Partial<TIssue>) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2024-03-06 15:17:38 +00:00
|
|
|
return await issues.createIssue(workspaceSlug, projectId, data);
|
|
|
|
},
|
|
|
|
[issues.createIssue, workspaceSlug]
|
|
|
|
);
|
|
|
|
const updateIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, issueId: string, data: Partial<TIssue>) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2024-03-06 15:17:38 +00:00
|
|
|
return await issues.updateIssue(workspaceSlug, projectId, issueId, data);
|
|
|
|
},
|
|
|
|
[issues.updateIssue, workspaceSlug]
|
|
|
|
);
|
|
|
|
const removeIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, issueId: string) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2024-03-06 15:17:38 +00:00
|
|
|
return await issues.removeIssue(workspaceSlug, projectId, issueId);
|
|
|
|
},
|
|
|
|
[issues.removeIssue, workspaceSlug]
|
|
|
|
);
|
|
|
|
|
|
|
|
const updateFilters = useCallback(
|
|
|
|
async (
|
|
|
|
projectId: string,
|
|
|
|
filterType: EIssueFilterType,
|
|
|
|
filters: IIssueFilterOptions | IIssueDisplayFilterOptions | IIssueDisplayProperties | TIssueKanbanFilters
|
|
|
|
) => {
|
|
|
|
if (!workspaceSlug) return;
|
|
|
|
return await issuesFilter.updateFilters(workspaceSlug, projectId, filterType, filters);
|
|
|
|
},
|
|
|
|
[issuesFilter.updateFilters]
|
|
|
|
);
|
|
|
|
|
|
|
|
return useMemo(
|
|
|
|
() => ({
|
|
|
|
fetchIssues,
|
2024-03-08 11:33:35 +00:00
|
|
|
fetchNextIssues,
|
2024-03-06 15:17:38 +00:00
|
|
|
createIssue,
|
|
|
|
updateIssue,
|
|
|
|
removeIssue,
|
|
|
|
updateFilters,
|
|
|
|
}),
|
|
|
|
[fetchIssues, createIssue, updateIssue, removeIssue, updateFilters]
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const useArchivedIssueActions = () => {
|
|
|
|
const { issues, issuesFilter } = useIssues(EIssuesStoreType.ARCHIVED);
|
|
|
|
|
|
|
|
const {
|
2024-03-08 11:33:35 +00:00
|
|
|
router: { workspaceSlug, projectId },
|
2024-03-06 15:17:38 +00:00
|
|
|
} = useApplication();
|
|
|
|
|
|
|
|
const fetchIssues = useCallback(
|
2024-03-08 11:33:35 +00:00
|
|
|
async (loadType: TLoader, options: IssuePaginationOptions) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
return issues.fetchIssues(workspaceSlug.toString(), projectId.toString(), loadType, options);
|
2024-03-06 15:17:38 +00:00
|
|
|
},
|
2024-03-08 11:33:35 +00:00
|
|
|
[issues.fetchIssues, workspaceSlug, projectId]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
2024-03-22 10:25:08 +00:00
|
|
|
const fetchNextIssues = useCallback(
|
|
|
|
async (groupId?: string, subGroupId?: string) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
return issues.fetchNextIssues(workspaceSlug.toString(), projectId.toString(), groupId, subGroupId);
|
|
|
|
},
|
|
|
|
[issues.fetchIssues, workspaceSlug, projectId]
|
|
|
|
);
|
2024-03-08 11:33:35 +00:00
|
|
|
|
2024-03-06 15:17:38 +00:00
|
|
|
const removeIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, issueId: string) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2024-03-06 15:17:38 +00:00
|
|
|
return await issues.removeIssue(workspaceSlug, projectId, issueId);
|
|
|
|
},
|
|
|
|
[issues.removeIssue]
|
|
|
|
);
|
|
|
|
const restoreIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, issueId: string) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2024-03-06 15:17:38 +00:00
|
|
|
return await issues.restoreIssue(workspaceSlug, projectId, issueId);
|
|
|
|
},
|
|
|
|
[issues.restoreIssue]
|
|
|
|
);
|
|
|
|
|
|
|
|
const updateFilters = useCallback(
|
|
|
|
async (
|
|
|
|
projectId: string,
|
|
|
|
filterType: EIssueFilterType,
|
|
|
|
filters: IIssueFilterOptions | IIssueDisplayFilterOptions | IIssueDisplayProperties | TIssueKanbanFilters
|
|
|
|
) => {
|
|
|
|
if (!workspaceSlug) return;
|
|
|
|
return await issuesFilter.updateFilters(workspaceSlug, projectId, filterType, filters);
|
|
|
|
},
|
|
|
|
[issuesFilter.updateFilters]
|
|
|
|
);
|
|
|
|
|
|
|
|
return useMemo(
|
|
|
|
() => ({
|
|
|
|
fetchIssues,
|
2024-03-08 11:33:35 +00:00
|
|
|
fetchNextIssues,
|
2024-03-06 15:17:38 +00:00
|
|
|
removeIssue,
|
|
|
|
restoreIssue,
|
|
|
|
updateFilters,
|
|
|
|
}),
|
2024-03-08 11:33:35 +00:00
|
|
|
[fetchIssues, fetchNextIssues, removeIssue, restoreIssue, updateFilters]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const useGlobalIssueActions = () => {
|
|
|
|
const { issues, issuesFilter } = useIssues(EIssuesStoreType.GLOBAL);
|
|
|
|
|
|
|
|
const {
|
|
|
|
router: { workspaceSlug, globalViewId },
|
|
|
|
} = useApplication();
|
2024-03-08 11:33:35 +00:00
|
|
|
const fetchIssues = useCallback(
|
|
|
|
async (loadType: TLoader, options: IssuePaginationOptions) => {
|
|
|
|
if (!workspaceSlug || !globalViewId) return;
|
|
|
|
return issues.fetchIssues(workspaceSlug.toString(), globalViewId.toString(), loadType, options);
|
|
|
|
},
|
|
|
|
[issues.fetchIssues, workspaceSlug, globalViewId]
|
|
|
|
);
|
2024-03-22 10:25:08 +00:00
|
|
|
const fetchNextIssues = useCallback(
|
|
|
|
async (groupId?: string, subGroupId?: string) => {
|
|
|
|
if (!workspaceSlug || !globalViewId) return;
|
|
|
|
return issues.fetchNextIssues(workspaceSlug.toString(), globalViewId.toString(), groupId, subGroupId);
|
|
|
|
},
|
|
|
|
[issues.fetchIssues, workspaceSlug, globalViewId]
|
|
|
|
);
|
2024-03-08 11:33:35 +00:00
|
|
|
|
2024-03-06 15:17:38 +00:00
|
|
|
const createIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, data: Partial<TIssue>) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2024-03-08 11:33:35 +00:00
|
|
|
return await issues.createIssue(workspaceSlug, projectId, data);
|
2024-03-06 15:17:38 +00:00
|
|
|
},
|
2024-03-08 11:33:35 +00:00
|
|
|
[issues.createIssue, workspaceSlug]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
|
|
|
const updateIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, issueId: string, data: Partial<TIssue>) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2024-03-08 11:33:35 +00:00
|
|
|
return await issues.updateIssue(workspaceSlug, projectId, issueId, data);
|
2024-03-06 15:17:38 +00:00
|
|
|
},
|
2024-03-08 11:33:35 +00:00
|
|
|
[issues.updateIssue, workspaceSlug]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
|
|
|
const removeIssue = useCallback(
|
2024-03-08 12:51:28 +00:00
|
|
|
async (projectId: string | undefined | null, issueId: string) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2024-03-08 11:33:35 +00:00
|
|
|
return await issues.removeIssue(workspaceSlug, projectId, issueId);
|
2024-03-06 15:17:38 +00:00
|
|
|
},
|
2024-03-08 11:33:35 +00:00
|
|
|
[issues.removeIssue, workspaceSlug]
|
2024-03-06 15:17:38 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const updateFilters = useCallback(
|
|
|
|
async (
|
|
|
|
projectId: string,
|
|
|
|
filterType: EIssueFilterType,
|
|
|
|
filters: IIssueFilterOptions | IIssueDisplayFilterOptions | IIssueDisplayProperties | TIssueKanbanFilters
|
|
|
|
) => {
|
|
|
|
if (!globalViewId || !workspaceSlug) return;
|
|
|
|
return await issuesFilter.updateFilters(workspaceSlug, projectId, filterType, filters, globalViewId);
|
|
|
|
},
|
|
|
|
[issuesFilter.updateFilters, globalViewId, workspaceSlug]
|
|
|
|
);
|
|
|
|
|
|
|
|
return useMemo(
|
|
|
|
() => ({
|
2024-03-08 11:33:35 +00:00
|
|
|
fetchIssues,
|
|
|
|
fetchNextIssues,
|
2024-03-06 15:17:38 +00:00
|
|
|
createIssue,
|
|
|
|
updateIssue,
|
|
|
|
removeIssue,
|
|
|
|
updateFilters,
|
|
|
|
}),
|
|
|
|
[createIssue, updateIssue, removeIssue, updateFilters]
|
|
|
|
);
|
|
|
|
};
|