forked from github/plane
1e152c666c
* chore: moved app & space from apps to root * chore: modified workspace configuration * chore: modified dockerfiles for space and web * chore: modified icons for space * feat: updated files for new svg icons supported by next-images * chore: added /spaces base path for next * chore: added compose config for space * chore: updated husky configuration * chore: updated workflows for new configuration * chore: changed app name to web * fix: resolved build errors with web * chore: reset file tracing root for both projects * chore: added nginx config for deploy * fix: eslint and tsconfig settings for space app * husky setup fixes based on new dir * eslint fixes * prettier formatting --------- Co-authored-by: Henit Chobisa <chobisa.henit@gmail.com>
87 lines
2.4 KiB
TypeScript
87 lines
2.4 KiB
TypeScript
import { useMemo } from "react";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
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 router = useRouter();
|
|
|
|
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,
|
|
subscriber: filters?.subscriber ? filters?.subscriber.join(",") : undefined,
|
|
start_date: filters?.start_date ? filters?.start_date.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 && router.pathname.includes("my-issues")
|
|
? USER_ISSUES(workspaceSlug.toString(), params)
|
|
: null,
|
|
workspaceSlug && router.pathname.includes("my-issues")
|
|
? () => userService.userIssues(workspaceSlug.toString(), params)
|
|
: null
|
|
);
|
|
|
|
const groupedIssues:
|
|
| {
|
|
[key: string]: IIssue[];
|
|
}
|
|
| undefined = useMemo(() => {
|
|
if (!myIssues) return undefined;
|
|
|
|
if (Array.isArray(myIssues))
|
|
return {
|
|
allIssues: myIssues,
|
|
};
|
|
|
|
if (groupBy === "state_detail.group") {
|
|
return myIssues
|
|
? Object.assign(
|
|
{
|
|
backlog: [],
|
|
unstarted: [],
|
|
started: [],
|
|
completed: [],
|
|
cancelled: [],
|
|
},
|
|
myIssues
|
|
)
|
|
: undefined;
|
|
}
|
|
|
|
return myIssues;
|
|
}, [groupBy, myIssues]);
|
|
|
|
const isEmpty =
|
|
Object.values(groupedIssues ?? {}).every((group) => group.length === 0) ||
|
|
Object.keys(groupedIssues ?? {}).length === 0;
|
|
|
|
return {
|
|
groupedIssues,
|
|
isEmpty,
|
|
mutateMyIssues,
|
|
params,
|
|
};
|
|
};
|
|
|
|
export default useMyIssues;
|