// react import React from "react"; // next import { useRouter } from "next/router"; // swr import useSWR, { mutate } from "swr"; // icons import { XMarkIcon } from "@heroicons/react/24/outline"; // services import issuesService from "services/issues.service"; // fetch key import { SUB_ISSUES } from "constants/fetch-keys"; // hooks import useUser from "hooks/use-user"; // ui import { Spinner } from "components/ui"; import { IIssue } from "types"; // components import { Label } from "components/web-view"; type Props = { issueDetails?: IIssue; }; export const SubIssueList: React.FC = (props) => { const { issueDetails } = props; const router = useRouter(); const { workspaceSlug } = router.query; const { user } = useUser(); const { data: subIssuesResponse } = useSWR( workspaceSlug && issueDetails ? SUB_ISSUES(issueDetails.id) : null, workspaceSlug && issueDetails ? () => issuesService.subIssues(workspaceSlug as string, issueDetails.project, issueDetails.id) : null ); const handleSubIssueRemove = (issue: any) => { if (!workspaceSlug || !issueDetails || !user) return; mutate( SUB_ISSUES(issueDetails.id), (prevData) => { if (!prevData) return prevData; const stateDistribution = { ...prevData.state_distribution }; const issueGroup = issue.state_detail.group; stateDistribution[issueGroup] = stateDistribution[issueGroup] - 1; return { state_distribution: stateDistribution, sub_issues: prevData.sub_issues.filter((i: any) => i.id !== issue.id), }; }, false ); issuesService .patchIssue(workspaceSlug.toString(), issue.project, issue.id, { parent: null }, user) .finally(() => mutate(SUB_ISSUES(issueDetails.id))); }; return (
{!subIssuesResponse && (
Loading...
)} {subIssuesResponse?.sub_issues.length === 0 && (

No sub issues

)} {subIssuesResponse?.sub_issues?.map((subIssue) => (

{subIssue.project_detail.identifier}-{subIssue.sequence_id}

{subIssue.name}

))}
); };