From 2cd431b4a45f7767834a1bda96319c0fb90c67dd Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal <65252264+aaryan610@users.noreply.github.com> Date: Tue, 1 Aug 2023 18:40:04 +0530 Subject: [PATCH] fix: my issues mutation (#1753) * fix: my issues mutation * fix: activity message and icon return value --- apps/app/components/core/activity.tsx | 4 ++-- apps/app/components/issues/modal.tsx | 4 ++++ .../profile/profile-issues-view.tsx | 19 +++++++++++++++---- apps/app/hooks/my-issues/use-my-issues.tsx | 12 ++++++++++-- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/apps/app/components/core/activity.tsx b/apps/app/components/core/activity.tsx index 078941b02..f7622baa6 100644 --- a/apps/app/components/core/activity.tsx +++ b/apps/app/components/core/activity.tsx @@ -481,7 +481,7 @@ const activityDetails: { }; export const ActivityIcon = ({ activity }: { activity: IIssueActivity }) => ( - <>{activityDetails[activity.field as keyof typeof activityDetails].icon} + <>{activityDetails[activity.field as keyof typeof activityDetails]?.icon} ); export const ActivityMessage = ({ @@ -492,6 +492,6 @@ export const ActivityMessage = ({ showIssue?: boolean; }) => ( <> - {activityDetails[activity.field as keyof typeof activityDetails].message(activity, showIssue)} + {activityDetails[activity.field as keyof typeof activityDetails]?.message(activity, showIssue)} ); diff --git a/apps/app/components/issues/modal.tsx b/apps/app/components/issues/modal.tsx index c738dbf07..be3b556a1 100644 --- a/apps/app/components/issues/modal.tsx +++ b/apps/app/components/issues/modal.tsx @@ -18,6 +18,7 @@ import useToast from "hooks/use-toast"; import useInboxView from "hooks/use-inbox-view"; import useSpreadsheetIssuesView from "hooks/use-spreadsheet-issues-view"; import useProjects from "hooks/use-projects"; +import useMyIssues from "hooks/my-issues/use-my-issues"; // components import { IssueForm } from "components/issues"; // types @@ -85,6 +86,8 @@ export const CreateUpdateIssueModal: React.FC = ({ const { user } = useUser(); const { projects } = useProjects(); + const { groupedIssues, mutateMyIssues } = useMyIssues(workspaceSlug?.toString()); + const { setToastAlert } = useToast(); if (cycleId) prePopulateData = { ...prePopulateData, cycle: cycleId as string }; @@ -243,6 +246,7 @@ export const CreateUpdateIssueModal: React.FC = ({ if (issueView === "calendar") mutate(calendarFetchKey); if (issueView === "gantt_chart") mutate(ganttFetchKey); if (issueView === "spreadsheet") mutate(spreadsheetFetchKey); + if (groupedIssues) mutateMyIssues(); setToastAlert({ type: "success", diff --git a/apps/app/components/profile/profile-issues-view.tsx b/apps/app/components/profile/profile-issues-view.tsx index 64632f0b9..401ac22d3 100644 --- a/apps/app/components/profile/profile-issues-view.tsx +++ b/apps/app/components/profile/profile-issues-view.tsx @@ -8,6 +8,7 @@ import useSWR from "swr"; import { DropResult } from "react-beautiful-dnd"; // services import issuesService from "services/issues.service"; +import userService from "services/user.service"; // hooks import useProfileIssues from "hooks/use-profile-issues"; import useUser from "hooks/use-user"; @@ -19,7 +20,7 @@ import { orderArrayBy } from "helpers/array.helper"; // types import { IIssue, IIssueFilterOptions } from "types"; // fetch-keys -import { WORKSPACE_LABELS } from "constants/fetch-keys"; +import { USER_PROFILE_PROJECT_SEGREGATION, WORKSPACE_LABELS } from "constants/fetch-keys"; export const ProfileIssuesView = () => { // create issue modal @@ -60,6 +61,16 @@ export const ProfileIssuesView = () => { params, } = useProfileIssues(workspaceSlug?.toString(), userId?.toString()); + const { data: profileData } = useSWR( + workspaceSlug && userId + ? USER_PROFILE_PROJECT_SEGREGATION(workspaceSlug.toString(), userId.toString()) + : null, + workspaceSlug && userId + ? () => + userService.getUserProfileProjectsSegregation(workspaceSlug.toString(), userId.toString()) + : null + ); + const { data: labels } = useSWR( workspaceSlug && (filters?.labels ?? []).length > 0 ? WORKSPACE_LABELS(workspaceSlug.toString()) @@ -268,10 +279,10 @@ export const ProfileIssuesView = () => { dragDisabled={groupByProperty !== "priority"} emptyState={{ title: router.pathname.includes("assigned") - ? `Issues assigned to ${user?.first_name} ${user?.last_name} will appear here` + ? `Issues assigned to ${profileData?.user_data.first_name} ${profileData?.user_data.last_name} will appear here` : router.pathname.includes("created") - ? `Issues created by ${user?.first_name} ${user?.last_name} will appear here` - : `Issues subscribed by ${user?.first_name} ${user?.last_name} will appear here`, + ? `Issues created by ${profileData?.user_data.first_name} ${profileData?.user_data.last_name} will appear here` + : `Issues subscribed by ${profileData?.user_data.first_name} ${profileData?.user_data.last_name} will appear here`, }} handleOnDragEnd={handleOnDragEnd} handleIssueAction={handleIssueAction} diff --git a/apps/app/hooks/my-issues/use-my-issues.tsx b/apps/app/hooks/my-issues/use-my-issues.tsx index 164fad4d4..f9063b4de 100644 --- a/apps/app/hooks/my-issues/use-my-issues.tsx +++ b/apps/app/hooks/my-issues/use-my-issues.tsx @@ -1,5 +1,7 @@ import { useMemo } from "react"; +import { useRouter } from "next/router"; + import useSWR from "swr"; // services @@ -12,6 +14,8 @@ import { IIssue } from "types"; import { USER_ISSUES } from "constants/fetch-keys"; const useMyIssues = (workspaceSlug: string | undefined) => { + const router = useRouter(); + const { filters, groupBy, orderBy } = useMyIssuesFilters(workspaceSlug); const params: any = { @@ -27,8 +31,12 @@ const useMyIssues = (workspaceSlug: string | undefined) => { }; const { data: myIssues, mutate: mutateMyIssues } = useSWR( - workspaceSlug ? USER_ISSUES(workspaceSlug.toString(), params) : null, - workspaceSlug ? () => userService.userIssues(workspaceSlug.toString(), params) : null + workspaceSlug && router.pathname.includes("my-issues") + ? USER_ISSUES(workspaceSlug.toString(), params) + : null, + workspaceSlug && router.pathname.includes("my-issues") + ? () => userService.userIssues(workspaceSlug.toString(), params) + : null ); const groupedIssues: