import { useCallback, useEffect } from "react"; import { useRouter } from "next/router"; import useSWR, { mutate } from "swr"; // react hook form import { useForm } from "react-hook-form"; // contexts import { useProjectMyMembership } from "contexts/project-member.context"; // services import inboxServices from "services/inbox.service"; // hooks import useInboxView from "hooks/use-inbox-view"; import useUserAuth from "hooks/use-user-auth"; // components import { AddComment, IssueActivitySection, IssueDescriptionForm, IssueDetailsSidebar, } from "components/issues"; // ui import { Loader } from "components/ui"; // icons import { ArrowTopRightOnSquareIcon, CheckCircleIcon, ClockIcon, DocumentDuplicateIcon, ExclamationTriangleIcon, XCircleIcon, } from "@heroicons/react/24/outline"; // helpers import { renderShortNumericDateFormat } from "helpers/date-time.helper"; // types import type { IInboxIssue, IIssue } from "types"; // fetch-keys import { INBOX_ISSUES, INBOX_ISSUE_DETAILS } from "constants/fetch-keys"; const defaultValues = { name: "", description: "", description_html: "", estimate_point: null, assignees_list: [], priority: "low", target_date: new Date().toString(), labels_list: [], }; export const InboxMainContent: React.FC = () => { const router = useRouter(); const { workspaceSlug, projectId, inboxId, inboxIssueId } = router.query; const { user } = useUserAuth(); const { memberRole } = useProjectMyMembership(); const { params } = useInboxView(); const { reset, control, watch } = useForm({ defaultValues, }); const { data: issueDetails, mutate: mutateIssueDetails } = useSWR( workspaceSlug && projectId && inboxId && inboxIssueId ? INBOX_ISSUE_DETAILS(inboxId.toString(), inboxIssueId.toString()) : null, workspaceSlug && projectId && inboxId && inboxIssueId ? () => inboxServices.getInboxIssueById( workspaceSlug.toString(), projectId.toString(), inboxId.toString(), inboxIssueId.toString() ) : null ); useEffect(() => { if (!issueDetails || !inboxIssueId) return; reset({ ...issueDetails, assignees_list: issueDetails.assignees_list ?? (issueDetails.assignee_details ?? []).map((user) => user.id), labels_list: issueDetails.labels_list ?? issueDetails.labels, }); }, [issueDetails, reset, inboxIssueId]); const submitChanges = useCallback( async (formData: Partial) => { if (!workspaceSlug || !projectId || !inboxIssueId || !inboxId || !issueDetails) return; mutateIssueDetails((prevData: any) => { if (!prevData) return prevData; return { ...prevData, ...formData, }; }, false); mutate( INBOX_ISSUES(inboxId.toString(), params), (prevData) => (prevData ?? []).map((i) => { if (i.bridge_id === inboxIssueId) { return { ...i, ...formData, }; } return i; }), false ); const payload = { issue: { ...formData } }; await inboxServices .patchInboxIssue( workspaceSlug.toString(), projectId.toString(), inboxId.toString(), issueDetails.issue_inbox[0].id, payload, user ) .then(() => { mutateIssueDetails(); mutate(INBOX_ISSUES(inboxId.toString(), params)); }); }, [ workspaceSlug, inboxIssueId, projectId, mutateIssueDetails, inboxId, user, issueDetails, params, ] ); const issueStatus = issueDetails?.issue_inbox[0].status; return ( <> {issueDetails ? (
{issueStatus === -2 ? ( <>

This issue is still pending.

) : issueStatus === -1 ? ( <>

This issue has been declined.

) : issueStatus === 0 ? ( <>

This issue has been snoozed till{" "} {renderShortNumericDateFormat(issueDetails.issue_inbox[0].snoozed_till ?? "")}.

) : issueStatus === 1 ? ( <>

This issue has been accepted.

) : issueStatus === 2 ? ( <>

This issue has been marked as a duplicate of this issue .

) : null}

Comments/Activity

) : (
)} ); return null; };