import React, { useCallback, useEffect } from "react"; import { useRouter } from "next/router"; import useSWR, { mutate } from "swr"; import { useFormContext, useForm, FormProvider } from "react-hook-form"; // services import { IssueService, IssueArchiveService } from "services/issue"; // fetch key import { ISSUE_DETAILS, PROJECT_ISSUES_ACTIVITY } from "constants/fetch-keys"; // hooks import useUser from "hooks/use-user"; import useProjectMembers from "hooks/use-project-members"; // layouts import WebViewLayout from "layouts/web-view-layout"; // ui import { Spinner } from "@plane/ui"; // components import { IssueWebViewForm, SubIssueList, IssueAttachments, IssuePropertiesDetail, IssueLinks, IssueActivity, } from "components/web-view"; // types import type { IIssue } from "types"; // services const issueService = new IssueService(); const issueArchiveService = new IssueArchiveService(); const MobileWebViewIssueDetail_ = () => { const router = useRouter(); const { workspaceSlug, projectId, issueId } = router.query; const isArchive = Boolean(router.query.archive); const memberRole = useProjectMembers(workspaceSlug as string, projectId as string, !!workspaceSlug && !!projectId); const isAllowed = Boolean((memberRole.isMember || memberRole.isOwner) && !isArchive); const { user } = useUser(); const formContext = useFormContext(); const { register, handleSubmit, control, watch, reset } = formContext; const { data: issue, mutate: mutateIssue, error, } = useSWR( workspaceSlug && projectId && issueId && !isArchive ? ISSUE_DETAILS(issueId.toString()) : null, workspaceSlug && projectId && issueId && !isArchive ? () => issueService.retrieve(workspaceSlug.toString(), projectId.toString(), issueId.toString()) : null ); const { data: archiveIssueDetails, mutate: mutateArchiveIssue } = useSWR( workspaceSlug && projectId && issueId && isArchive ? ISSUE_DETAILS(issueId as string) : null, workspaceSlug && projectId && issueId && isArchive ? () => issueArchiveService.retrieveArchivedIssue(workspaceSlug.toString(), projectId.toString(), issueId.toString()) : null ); const issueDetails = isArchive ? archiveIssueDetails : issue; const mutateIssueDetails = isArchive ? mutateArchiveIssue : mutateIssue; useEffect(() => { if (!issueDetails) return; reset({ ...issueDetails, name: issueDetails.name, description: issueDetails.description, description_html: issueDetails.description_html, state: issueDetails.state, assignees_list: issueDetails.assignees_list ?? issueDetails.assignee_details?.map((user) => user.id), labels_list: issueDetails.labels_list ?? issueDetails.labels, labels: issueDetails.labels_list ?? issueDetails.labels, }); }, [issueDetails, reset]); const submitChanges = useCallback( async (formData: Partial) => { if (!workspaceSlug || !projectId || !issueId) return; mutate( ISSUE_DETAILS(issueId.toString()), (prevData) => { if (!prevData) return prevData; return { ...prevData, ...formData, }; }, false ); const payload: Partial = { ...formData, }; delete payload.issue_relations; delete payload.related_issues; await issueService .patchIssue(workspaceSlug as string, projectId as string, issueId as string, payload, user) .then(() => { mutateIssueDetails(); mutate(PROJECT_ISSUES_ACTIVITY(issueId as string)); }) .catch((e) => { console.error(e); }); }, [workspaceSlug, issueId, projectId, mutateIssueDetails, user] ); if (!error && !issueDetails) return (
); if (error) return (
{error?.response?.data || "Something went wrong"}
); return ( {isArchive &&
}
); }; const MobileWebViewIssueDetail = () => { const methods = useForm(); return ( ); }; export default MobileWebViewIssueDetail;