mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
3d7fe40035
* refactor: issue views and my issues * chore: update view dropdown options * refactor: render emoji function * refactor: api calss * fix: build errors * fix: fetch states only when dropdown is opened * chore: my issues dnd * fix: build errors * refactor: folder structure
62 lines
1.8 KiB
TypeScript
62 lines
1.8 KiB
TypeScript
import { useMemo } from "react";
|
|
|
|
import useSWR from "swr";
|
|
|
|
// services
|
|
import userService from "services/user.service";
|
|
// hooks
|
|
import useMyIssuesFilters from "hooks/my-issues/use-my-issues-filter";
|
|
// types
|
|
import { IIssue } from "types";
|
|
// fetch-keys
|
|
import { USER_ISSUES } from "constants/fetch-keys";
|
|
|
|
const useMyIssues = (workspaceSlug: string | undefined) => {
|
|
const { filters, groupBy, orderBy } = useMyIssuesFilters(workspaceSlug);
|
|
|
|
const params: any = {
|
|
assignees: filters?.assignees ? filters?.assignees.join(",") : undefined,
|
|
created_by: filters?.created_by ? filters?.created_by.join(",") : undefined,
|
|
group_by: groupBy,
|
|
labels: filters?.labels ? filters?.labels.join(",") : undefined,
|
|
order_by: orderBy,
|
|
priority: filters?.priority ? filters?.priority.join(",") : undefined,
|
|
state_group: filters?.state_group ? filters?.state_group.join(",") : undefined,
|
|
target_date: filters?.target_date ? filters?.target_date.join(",") : undefined,
|
|
type: filters?.type ? filters?.type : undefined,
|
|
};
|
|
|
|
const { data: myIssues, mutate: mutateMyIssues } = useSWR(
|
|
workspaceSlug ? USER_ISSUES(workspaceSlug.toString(), params) : null,
|
|
workspaceSlug ? () => userService.userIssues(workspaceSlug.toString(), params) : null
|
|
);
|
|
|
|
const groupedIssues:
|
|
| {
|
|
[key: string]: IIssue[];
|
|
}
|
|
| undefined = useMemo(() => {
|
|
if (!myIssues) return undefined;
|
|
|
|
if (Array.isArray(myIssues))
|
|
return {
|
|
allIssues: myIssues,
|
|
};
|
|
|
|
return myIssues;
|
|
}, [myIssues]);
|
|
|
|
const isEmpty =
|
|
Object.values(groupedIssues ?? {}).every((group) => group.length === 0) ||
|
|
Object.keys(groupedIssues ?? {}).length === 0;
|
|
|
|
return {
|
|
groupedIssues,
|
|
isEmpty,
|
|
mutateMyIssues,
|
|
params,
|
|
};
|
|
};
|
|
|
|
export default useMyIssues;
|