plane/web/hooks/use-issues-actions.tsx

649 lines
23 KiB
TypeScript
Raw Normal View History

import { EIssueFilterType, EIssuesStoreType } from "constants/issue";
import { useApplication, useIssues } from "./store";
import {
IIssueDisplayFilterOptions,
IIssueDisplayProperties,
IIssueFilterOptions,
2024-03-08 11:33:35 +00:00
IssuePaginationOptions,
TIssue,
TIssueKanbanFilters,
2024-03-08 11:33:35 +00:00
TIssuesResponse,
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>;
fetchNextIssues: () => Promise<TIssuesResponse | undefined>;
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>;
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();
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;
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 },
} = 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-08 11:33:35 +00:00
[issues.fetchIssues, workspaceSlug, projectId]
);
2024-03-08 11:33:35 +00:00
const fetchNextIssues = useCallback(async () => {
if (!workspaceSlug || !projectId) return;
return issues.fetchNextIssues(workspaceSlug.toString(), projectId.toString());
}, [issues.fetchIssues, workspaceSlug, projectId]);
const createIssue = useCallback(
async (projectId: string | undefined | null, data: Partial<TIssue>) => {
if (!workspaceSlug || !projectId) return;
return await issues.createIssue(workspaceSlug, projectId, data);
},
[issues.createIssue, workspaceSlug]
);
const updateIssue = useCallback(
async (projectId: string | undefined | null, issueId: string, data: Partial<TIssue>) => {
if (!workspaceSlug || !projectId) return;
return await issues.updateIssue(workspaceSlug, projectId, issueId, data);
},
[issues.updateIssue, workspaceSlug]
);
const removeIssue = useCallback(
async (projectId: string | undefined | null, issueId: string) => {
if (!workspaceSlug || !projectId) return;
return await issues.removeIssue(workspaceSlug, projectId, issueId);
},
[issues.removeIssue, workspaceSlug]
);
const archiveIssue = useCallback(
async (projectId: string | undefined | null, issueId: string) => {
if (!workspaceSlug || !projectId) return;
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,
createIssue,
updateIssue,
removeIssue,
archiveIssue,
updateFilters,
}),
2024-03-08 11:33:35 +00:00
[fetchIssues, fetchNextIssues, createIssue, updateIssue, removeIssue, archiveIssue, updateFilters]
);
};
const useCycleIssueActions = () => {
const { issues, issuesFilter } = useIssues(EIssuesStoreType.CYCLE);
const {
2024-03-08 11:33:35 +00:00
router: { workspaceSlug, projectId, cycleId },
} = 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-08 11:33:35 +00:00
[issues.fetchIssues, workspaceSlug, projectId, cycleId]
);
2024-03-08 11:33:35 +00:00
const fetchNextIssues = useCallback(async () => {
if (!workspaceSlug || !projectId || !cycleId) return;
return issues.fetchNextIssues(workspaceSlug.toString(), projectId.toString(), cycleId.toString());
}, [issues.fetchIssues, workspaceSlug, projectId, cycleId]);
const createIssue = useCallback(
async (projectId: string | undefined | null, data: Partial<TIssue>) => {
if (!cycleId || !workspaceSlug || !projectId) return;
return await issues.createIssue(workspaceSlug, projectId, data, cycleId);
},
[issues.createIssue, cycleId, workspaceSlug]
);
const updateIssue = useCallback(
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-08 11:33:35 +00:00
[issues.updateIssue, workspaceSlug]
);
const removeIssue = useCallback(
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-08 11:33:35 +00:00
[issues.removeIssue, workspaceSlug]
);
const removeIssueFromView = useCallback(
async (projectId: string | undefined | null, issueId: string) => {
if (!cycleId || !workspaceSlug || !projectId) return;
return await issues.removeIssueFromCycle(workspaceSlug, projectId, cycleId, issueId);
},
[issues.removeIssueFromCycle, cycleId, workspaceSlug]
);
const archiveIssue = useCallback(
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-08 11:33:35 +00:00
[issues.archiveIssue, workspaceSlug]
);
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,
createIssue,
updateIssue,
removeIssue,
removeIssueFromView,
archiveIssue,
updateFilters,
}),
2024-03-08 11:33:35 +00:00
[
fetchIssues,
fetchNextIssues,
createIssue,
updateIssue,
removeIssue,
removeIssueFromView,
archiveIssue,
updateFilters,
]
);
};
const useModuleIssueActions = () => {
const { issues, issuesFilter } = useIssues(EIssuesStoreType.MODULE);
const {
2024-03-08 11:33:35 +00:00
router: { workspaceSlug, projectId, moduleId },
} = 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-08 11:33:35 +00:00
[issues.fetchIssues, workspaceSlug, projectId, moduleId]
);
2024-03-08 11:33:35 +00:00
const fetchNextIssues = useCallback(async () => {
if (!workspaceSlug || !projectId || !moduleId) return;
return issues.fetchNextIssues(workspaceSlug.toString(), projectId.toString(), moduleId.toString());
}, [issues.fetchIssues, workspaceSlug, projectId, moduleId]);
const createIssue = useCallback(
async (projectId: string | undefined | null, data: Partial<TIssue>) => {
if (!moduleId || !workspaceSlug || !projectId) return;
return await issues.createIssue(workspaceSlug, projectId, data, moduleId);
},
[issues.createIssue, moduleId, workspaceSlug]
);
const updateIssue = useCallback(
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-08 11:33:35 +00:00
[issues.updateIssue, workspaceSlug]
);
const removeIssue = useCallback(
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-08 11:33:35 +00:00
[issues.removeIssue, workspaceSlug]
);
const removeIssueFromView = useCallback(
async (projectId: string | undefined | null, issueId: string) => {
if (!moduleId || !workspaceSlug || !projectId) return;
return await issues.removeIssueFromModule(workspaceSlug, projectId, moduleId, issueId);
},
[issues.removeIssueFromModule, moduleId, workspaceSlug]
);
const archiveIssue = useCallback(
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);
},
[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,
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-08 11:33:35 +00:00
[issues.fetchIssues, workspaceSlug, userId]
);
2024-03-08 11:33:35 +00:00
const fetchNextIssues = useCallback(async () => {
if (!workspaceSlug || !userId) return;
return issues.fetchNextIssues(workspaceSlug.toString(), userId.toString());
}, [issues.fetchIssues, workspaceSlug, userId]);
const createIssue = useCallback(
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-08 11:33:35 +00:00
[issues.createIssue, workspaceSlug]
);
const updateIssue = useCallback(
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-08 11:33:35 +00:00
[issues.updateIssue, workspaceSlug]
);
const removeIssue = useCallback(
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-08 11:33:35 +00:00
[issues.removeIssue, workspaceSlug]
);
const archiveIssue = useCallback(
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-08 11:33:35 +00:00
[issues.archiveIssue, workspaceSlug]
);
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,
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 },
} = 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-08 11:33:35 +00:00
[issues.fetchIssues, workspaceSlug, projectId]
);
2024-03-08 11:33:35 +00:00
const fetchNextIssues = useCallback(async () => {
if (!workspaceSlug || !projectId) return;
return issues.fetchNextIssues(workspaceSlug.toString(), projectId.toString());
}, [issues.fetchIssues, workspaceSlug, projectId]);
const createIssue = useCallback(
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-08 11:33:35 +00:00
[issues.createIssue, workspaceSlug]
);
const updateIssue = useCallback(
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-08 11:33:35 +00:00
[issues.updateIssue, workspaceSlug]
);
const removeIssue = useCallback(
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-08 11:33:35 +00:00
[issues.removeIssue, workspaceSlug]
);
const archiveIssue = useCallback(
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-08 11:33:35 +00:00
[issues.archiveIssue, workspaceSlug]
);
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,
createIssue,
updateIssue,
removeIssue,
archiveIssue,
updateFilters,
}),
2024-03-08 11:33:35 +00:00
[fetchIssues, fetchNextIssues, createIssue, updateIssue, removeIssue, archiveIssue, updateFilters]
);
};
const useDraftIssueActions = () => {
const { issues, issuesFilter } = useIssues(EIssuesStoreType.DRAFT);
const {
2024-03-08 11:33:35 +00:00
router: { workspaceSlug, projectId },
} = 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-08 11:33:35 +00:00
[issues.fetchIssues, workspaceSlug, projectId]
);
2024-03-08 11:33:35 +00:00
const fetchNextIssues = useCallback(async () => {
if (!workspaceSlug || !projectId) return;
return issues.fetchNextIssues(workspaceSlug.toString(), projectId.toString());
}, [issues.fetchIssues, workspaceSlug, projectId]);
const createIssue = useCallback(
async (projectId: string | undefined | null, data: Partial<TIssue>) => {
if (!workspaceSlug || !projectId) return;
return await issues.createIssue(workspaceSlug, projectId, data);
},
[issues.createIssue, workspaceSlug]
);
const updateIssue = useCallback(
async (projectId: string | undefined | null, issueId: string, data: Partial<TIssue>) => {
if (!workspaceSlug || !projectId) return;
return await issues.updateIssue(workspaceSlug, projectId, issueId, data);
},
[issues.updateIssue, workspaceSlug]
);
const removeIssue = useCallback(
async (projectId: string | undefined | null, issueId: string) => {
if (!workspaceSlug || !projectId) return;
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,
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 },
} = 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-08 11:33:35 +00:00
[issues.fetchIssues, workspaceSlug, projectId]
);
2024-03-08 11:33:35 +00:00
const fetchNextIssues = useCallback(async () => {
if (!workspaceSlug || !projectId) return;
return issues.fetchNextIssues(workspaceSlug.toString(), projectId.toString());
}, [issues.fetchIssues, workspaceSlug, projectId]);
const removeIssue = useCallback(
async (projectId: string | undefined | null, issueId: string) => {
if (!workspaceSlug || !projectId) return;
return await issues.removeIssue(workspaceSlug, projectId, issueId);
},
[issues.removeIssue]
);
const restoreIssue = useCallback(
async (projectId: string | undefined | null, issueId: string) => {
if (!workspaceSlug || !projectId) return;
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,
removeIssue,
restoreIssue,
updateFilters,
}),
2024-03-08 11:33:35 +00:00
[fetchIssues, fetchNextIssues, removeIssue, restoreIssue, updateFilters]
);
};
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]
);
const fetchNextIssues = useCallback(async () => {
if (!workspaceSlug || !globalViewId) return;
return issues.fetchNextIssues(workspaceSlug.toString(), globalViewId.toString());
}, [issues.fetchIssues, workspaceSlug, globalViewId]);
const createIssue = useCallback(
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-08 11:33:35 +00:00
[issues.createIssue, workspaceSlug]
);
const updateIssue = useCallback(
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-08 11:33:35 +00:00
[issues.updateIssue, workspaceSlug]
);
const removeIssue = useCallback(
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-08 11:33:35 +00:00
[issues.removeIssue, workspaceSlug]
);
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,
createIssue,
updateIssue,
removeIssue,
updateFilters,
}),
[createIssue, updateIssue, removeIssue, updateFilters]
);
};