diff --git a/apps/app/components/common/board-view/single-issue.tsx b/apps/app/components/common/board-view/single-issue.tsx index dc774add5..445982035 100644 --- a/apps/app/components/common/board-view/single-issue.tsx +++ b/apps/app/components/common/board-view/single-issue.tsx @@ -4,7 +4,7 @@ import Link from "next/link"; import Image from "next/image"; import { useRouter } from "next/router"; // swr -import useSWR from "swr"; +import useSWR, { mutate } from "swr"; // react-beautiful-dnd import { DraggableStateSnapshot } from "react-beautiful-dnd"; // headless ui @@ -17,48 +17,49 @@ import issuesService from "services/issues.service"; import stateService from "services/state.service"; import projectService from "services/project.service"; // components -import { AssigneesList } from "components/ui/avatar"; +import { CustomSelect, AssigneesList } from "components/ui"; // helpers import { renderShortNumericDateFormat, findHowManyDaysLeft } from "helpers/date-time.helper"; import { addSpaceIfCamelCase } from "helpers/string.helper"; // types -import { IIssue, IssueResponse, IUserLite, IWorkspaceMember, Properties } from "types"; +import { IIssue, IUserLite, IWorkspaceMember, Properties, UserAuth } from "types"; // common import { PRIORITIES } from "constants/"; -import { PROJECT_ISSUES_LIST, STATE_LIST, PROJECT_DETAILS } from "constants/fetch-keys"; +import { + STATE_LIST, + PROJECT_DETAILS, + CYCLE_ISSUES, + MODULE_ISSUES, + PROJECT_ISSUES_LIST, +} from "constants/fetch-keys"; import { getPriorityIcon } from "constants/global"; type Props = { + type?: string; + typeId?: string; issue: IIssue; properties: Properties; snapshot?: DraggableStateSnapshot; assignees: Partial[] | (Partial | undefined)[]; people: IWorkspaceMember[] | undefined; handleDeleteIssue?: React.Dispatch>; - partialUpdateIssue: any; + userAuth: UserAuth; }; const SingleBoardIssue: React.FC = ({ + type, + typeId, issue, properties, snapshot, assignees, people, handleDeleteIssue, - partialUpdateIssue, + userAuth, }) => { const router = useRouter(); const { workspaceSlug, projectId } = router.query; - const { data: issues } = useSWR( - workspaceSlug && projectId - ? PROJECT_ISSUES_LIST(workspaceSlug as string, projectId as string) - : null, - workspaceSlug && projectId - ? () => issuesService.getIssues(workspaceSlug as string, projectId as string) - : null - ); - const { data: states } = useSWR( workspaceSlug && projectId ? STATE_LIST(projectId as string) : null, workspaceSlug && projectId @@ -73,7 +74,25 @@ const SingleBoardIssue: React.FC = ({ : null ); - const totalChildren = issues?.results.filter((i) => i.parent === issue.id).length; + const partialUpdateIssue = (formData: Partial) => { + if (!workspaceSlug || !projectId) return; + + issuesService + .patchIssue(workspaceSlug as string, projectId as string, issue.id, formData) + .then((res) => { + if (typeId) { + mutate(CYCLE_ISSUES(typeId ?? "")); + mutate(MODULE_ISSUES(typeId ?? "")); + } + + mutate(PROJECT_ISSUES_LIST(workspaceSlug as string, projectId as string)); + }) + .catch((error) => { + console.log(error); + }); + }; + + const isNotAllowed = userAuth.isGuest || userAuth.isViewer; return (
= ({ }`} >
- {handleDeleteIssue && ( + {handleDeleteIssue && !isNotAllowed && (