forked from github/plane
3a6d72e4b6
* chore: workspace view types, services and hooks added * style: spreadsheet view revamp and code refactor * feat: workspace view * fix: build fix * chore: sidebar workspace issues redirection updated
35 lines
925 B
TypeScript
35 lines
925 B
TypeScript
import { useEffect, useState } from "react";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import useSWR from "swr";
|
|
|
|
// services
|
|
import issuesService from "services/issues.service";
|
|
// types
|
|
import { ISubIssueResponse } from "types";
|
|
// fetch-keys
|
|
import { SUB_ISSUES } from "constants/fetch-keys";
|
|
|
|
const useSubIssue = (projectId: string, issueId: string, isExpanded: boolean) => {
|
|
const router = useRouter();
|
|
const { workspaceSlug } = router.query;
|
|
|
|
const shouldFetch = workspaceSlug && projectId && issueId && isExpanded;
|
|
|
|
const { data: subIssuesResponse, isLoading } = useSWR<ISubIssueResponse>(
|
|
shouldFetch ? SUB_ISSUES(issueId as string) : null,
|
|
shouldFetch
|
|
? () =>
|
|
issuesService.subIssues(workspaceSlug as string, projectId as string, issueId as string)
|
|
: null
|
|
);
|
|
|
|
return {
|
|
subIssues: subIssuesResponse?.sub_issues ?? [],
|
|
isLoading,
|
|
};
|
|
};
|
|
|
|
export default useSubIssue;
|