diff --git a/apps/app/components/analytics/scope-and-demand/scope.tsx b/apps/app/components/analytics/scope-and-demand/scope.tsx index 6697b775b..f7cf53be5 100644 --- a/apps/app/components/analytics/scope-and-demand/scope.tsx +++ b/apps/app/components/analytics/scope-and-demand/scope.tsx @@ -29,7 +29,6 @@ export const AnalyticsScope: React.FC = ({ defaultAnalytics }) => ( return (
- Issue count-{" "} {assignee ? assignee.assignees__first_name + " " + assignee.assignees__last_name : "No assignee"} diff --git a/apps/app/components/core/board-view/single-board.tsx b/apps/app/components/core/board-view/single-board.tsx index d0fe1834a..0ebc77d5b 100644 --- a/apps/app/components/core/board-view/single-board.tsx +++ b/apps/app/components/core/board-view/single-board.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect } from "react"; +import { useState } from "react"; import { useRouter } from "next/router"; @@ -60,11 +60,6 @@ export const SingleBoard: React.FC = ({ const isNotAllowed = userAuth.isGuest || userAuth.isViewer || isCompleted; - useEffect(() => { - if (currentState?.group === "completed" || currentState?.group === "cancelled") - setIsCollapsed(false); - }, [currentState]); - return (
void; + data: IIssueLabels | null; +}; + +export const DeleteLabelModal: React.FC = ({ isOpen, onClose, data }) => { + const [isDeleteLoading, setIsDeleteLoading] = useState(false); + + const router = useRouter(); + const { workspaceSlug, projectId } = router.query; + + const { setToastAlert } = useToast(); + + const handleClose = () => { + onClose(); + setIsDeleteLoading(false); + }; + + const handleDeletion = async () => { + if (!workspaceSlug || !projectId || !data) return; + + setIsDeleteLoading(true); + + mutate( + PROJECT_ISSUE_LABELS(projectId.toString()), + (prevData) => (prevData ?? []).filter((p) => p.id !== data.id), + false + ); + + await issuesService + .deleteIssueLabel(workspaceSlug.toString(), projectId.toString(), data.id) + .then(() => handleClose()) + .catch(() => { + setIsDeleteLoading(false); + + mutate(PROJECT_ISSUE_LABELS(projectId.toString())); + setToastAlert({ + type: "error", + title: "Error!", + message: "Label could not be deleted. Please try again.", + }); + }); + }; + + return ( + + + +
+ + +
+
+ + +
+
+
+
+
+ + Delete Label + +
+

+ Are you sure you want to delete label-{" "} + {data?.name}? The + label will be removed from all the issues. +

+
+
+
+
+
+ Cancel + + {isDeleteLoading ? "Deleting..." : "Delete"} + +
+
+
+
+
+
+
+ ); +}; diff --git a/apps/app/components/labels/index.ts b/apps/app/components/labels/index.ts index db02d29f0..0c0629d92 100644 --- a/apps/app/components/labels/index.ts +++ b/apps/app/components/labels/index.ts @@ -1,5 +1,6 @@ export * from "./create-label-modal"; export * from "./create-update-label-inline"; +export * from "./delete-label-modal"; export * from "./labels-list-modal"; export * from "./single-label-group"; export * from "./single-label"; diff --git a/apps/app/components/labels/single-label-group.tsx b/apps/app/components/labels/single-label-group.tsx index 196914cbc..00837a05c 100644 --- a/apps/app/components/labels/single-label-group.tsx +++ b/apps/app/components/labels/single-label-group.tsx @@ -29,7 +29,7 @@ type Props = { labelChildren: IIssueLabels[]; addLabelToGroup: (parentLabel: IIssueLabels) => void; editLabel: (label: IIssueLabels) => void; - handleLabelDelete: (labelId: string) => void; + handleLabelDelete: () => void; }; export const SingleLabelGroup: React.FC = ({ @@ -94,7 +94,7 @@ export const SingleLabelGroup: React.FC = ({ Edit label - handleLabelDelete(label.id)}> + Delete label @@ -150,7 +150,7 @@ export const SingleLabelGroup: React.FC = ({ Edit label - handleLabelDelete(child.id)}> + Delete label diff --git a/apps/app/components/labels/single-label.tsx b/apps/app/components/labels/single-label.tsx index 131deb509..58e6d2932 100644 --- a/apps/app/components/labels/single-label.tsx +++ b/apps/app/components/labels/single-label.tsx @@ -11,7 +11,7 @@ type Props = { label: IIssueLabels; addLabelToGroup: (parentLabel: IIssueLabels) => void; editLabel: (label: IIssueLabels) => void; - handleLabelDelete: (labelId: string) => void; + handleLabelDelete: () => void; }; export const SingleLabel: React.FC = ({ @@ -44,7 +44,7 @@ export const SingleLabel: React.FC = ({ Edit label - handleLabelDelete(label.id)}> + Delete label diff --git a/apps/app/components/workspace/issues-list.tsx b/apps/app/components/workspace/issues-list.tsx index 9cf7b4295..cfae13687 100644 --- a/apps/app/components/workspace/issues-list.tsx +++ b/apps/app/components/workspace/issues-list.tsx @@ -23,11 +23,12 @@ export const IssuesList: React.FC = ({ issues, type }) => { const getDateDifference = (date: Date) => { const today = new Date(); - let diffDays = 0; - if (type === "overdue") { - const diffTime = Math.abs(today.valueOf() - date.valueOf()); - diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); - } else return date.getDate() - today.getDate(); + let diffTime = 0; + + if (type === "overdue") diffTime = Math.abs(today.valueOf() - date.valueOf()); + else diffTime = Math.abs(date.valueOf() - today.valueOf()); + + const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); return diffDays; }; diff --git a/apps/app/pages/[workspaceSlug]/projects/[projectId]/settings/labels.tsx b/apps/app/pages/[workspaceSlug]/projects/[projectId]/settings/labels.tsx index 7f1f47ddf..eea76527a 100644 --- a/apps/app/pages/[workspaceSlug]/projects/[projectId]/settings/labels.tsx +++ b/apps/app/pages/[workspaceSlug]/projects/[projectId]/settings/labels.tsx @@ -12,6 +12,7 @@ import { ProjectAuthorizationWrapper } from "layouts/auth-layout"; // components import { CreateUpdateLabelInline, + DeleteLabelModal, LabelsListModal, SingleLabel, SingleLabelGroup, @@ -40,6 +41,9 @@ const LabelsSettings: NextPage = () => { const [labelsListModal, setLabelsListModal] = useState(false); const [parentLabel, setParentLabel] = useState(undefined); + // delete label + const [selectDeleteLabel, setSelectDeleteLabel] = useState(null); + const router = useRouter(); const { workspaceSlug, projectId } = router.query; @@ -52,7 +56,7 @@ const LabelsSettings: NextPage = () => { : null ); - const { data: issueLabels, mutate } = useSWR( + const { data: issueLabels } = useSWR( workspaceSlug && projectId ? PROJECT_ISSUE_LABELS(projectId as string) : null, workspaceSlug && projectId ? () => issuesService.getIssueLabels(workspaceSlug as string, projectId as string) @@ -75,15 +79,6 @@ const LabelsSettings: NextPage = () => { setLabelToUpdate(label); }; - const handleLabelDelete = (labelId: string) => { - if (workspaceSlug && projectDetails) { - mutate((prevData) => prevData?.filter((p) => p.id !== labelId), false); - issuesService - .deleteIssueLabel(workspaceSlug as string, projectDetails.id, labelId) - .catch((e) => console.log(e)); - } - }; - return ( <> { handleClose={() => setLabelsListModal(false)} parent={parentLabel} /> + setSelectDeleteLabel(null)} + /> @@ -143,7 +143,7 @@ const LabelsSettings: NextPage = () => { behavior: "smooth", }); }} - handleLabelDelete={handleLabelDelete} + handleLabelDelete={() => setSelectDeleteLabel(label)} /> ); } else @@ -159,7 +159,7 @@ const LabelsSettings: NextPage = () => { behavior: "smooth", }); }} - handleLabelDelete={handleLabelDelete} + handleLabelDelete={() => setSelectDeleteLabel(label)} /> ); })