// next import Link from "next/link"; import type { NextPage } from "next"; import { useRouter } from "next/router"; import Image from "next/image"; // react import React, { useCallback, useEffect, useState } from "react"; // swr import useSWR from "swr"; // react hook form import { useForm } from "react-hook-form"; // headless ui import { Tab } from "@headlessui/react"; // services import issuesServices from "lib/services/issues.services"; // fetch keys import { PROJECT_ISSUES_ACTIVITY, PROJECT_ISSUES_COMMENTS, STATE_LIST } from "constants/fetch-keys"; // hooks import useUser from "lib/hooks/useUser"; // layouts import ProjectLayout from "layouts/ProjectLayout"; // components import CreateUpdateIssuesModal from "components/project/issues/CreateUpdateIssueModal"; import IssueCommentSection from "components/project/issues/comment/IssueCommentSection"; // common import { timeAgo, debounce, addSpaceIfCamelCase } from "constants/common"; // components import IssueDetailSidebar from "components/project/issues/issue-detail/IssueDetailSidebar"; // ui import { Spinner, TextArea } from "ui"; // types import { IIssue, IIssueComment, IssueResponse, IState } from "types"; import { BreadcrumbItem, Breadcrumbs } from "ui/Breadcrumbs"; import stateServices from "lib/services/state.services"; const IssueDetail: NextPage = () => { const router = useRouter(); const { issueId, projectId } = router.query; const { activeWorkspace, activeProject, issues, mutateIssues } = useUser(); const [isOpen, setIsOpen] = useState(false); const [issueDetail, setIssueDetail] = useState(undefined); const { register, formState: { errors }, handleSubmit, reset, control, } = useForm({}); const { data: issueActivities } = useSWR( activeWorkspace && projectId && issueId ? PROJECT_ISSUES_ACTIVITY : null, activeWorkspace && projectId && issueId ? () => issuesServices.getIssueActivities( activeWorkspace.slug, projectId as string, issueId as string ) : null ); const { data: issueComments } = useSWR( activeWorkspace && projectId && issueId ? PROJECT_ISSUES_COMMENTS : null, activeWorkspace && projectId && issueId ? () => issuesServices.getIssueComments( activeWorkspace.slug, projectId as string, issueId as string ) : null ); const { data: states } = useSWR( activeWorkspace && activeProject ? STATE_LIST(activeProject.id) : null, activeWorkspace && activeProject ? () => stateServices.getStates(activeWorkspace.slug, activeProject.id) : null ); const submitChanges = useCallback( (formData: Partial) => { if (!activeWorkspace || !activeProject || !issueId) return; mutateIssues( (prevData) => ({ ...(prevData as IssueResponse), results: (prevData?.results ?? []).map((issue) => { if (issue.id === issueId) { return { ...issue, ...formData }; } return issue; }), }), false ); issuesServices .patchIssue(activeWorkspace.slug, projectId as string, issueId as string, formData) .then((response) => { console.log(response); }) .catch((error) => { console.log(error); }); }, [activeProject, activeWorkspace, issueId, projectId, mutateIssues] ); useEffect(() => { if (issueDetail) reset({ ...issueDetail, blockers_list: issueDetail.blockers_list ?? issueDetail.blocker_issues?.map((issue) => issue.blocker_issue_detail?.id), blocked_list: issueDetail.blocked_list ?? issueDetail.blocked_issues?.map((issue) => issue.blocked_issue_detail?.id), assignees_list: issueDetail.assignees_list ?? issueDetail.assignee_details?.map((user) => user.id), labels_list: issueDetail.labels_list ?? issueDetail.labels?.map((label) => label), }); }, [issueDetail, reset]); useEffect(() => { const issueIndex = issues?.results.findIndex((issue) => issue.id === issueId); if (issueIndex === undefined) return; const issueDetail = issues?.results[issueIndex]; setIssueDetail(issueDetail); }, [issues, issueId]); const prevIssue = issues?.results[issues?.results.findIndex((issue) => issue.id === issueId) - 1]; const nextIssue = issues?.results[issues?.results.findIndex((issue) => issue.id === issueId) + 1]; return (
{issueDetail && activeProject ? ( <>

{activeProject.name}/ {activeProject.identifier}-{issueDetail.sequence_id}