2024-06-10 15:13:10 +05:30
|
|
|
"use client";
|
|
|
|
|
|
2023-05-17 16:04:56 +05:30
|
|
|
import React, { useState } from "react";
|
2024-05-08 23:01:20 +05:30
|
|
|
import { observer } from "mobx-react";
|
2024-06-10 12:37:38 +05:30
|
|
|
import { useParams } from "next/navigation";
|
2024-05-07 12:44:36 +05:30
|
|
|
// types
|
2025-08-19 07:36:42 -07:00
|
|
|
import { PROJECT_SETTINGS_TRACKER_ELEMENTS, PROJECT_SETTINGS_TRACKER_EVENTS } from "@plane/constants";
|
2024-03-19 20:08:35 +05:30
|
|
|
import type { IIssueLabel } from "@plane/types";
|
2023-05-17 16:04:56 +05:30
|
|
|
// ui
|
2024-06-14 17:12:39 +05:30
|
|
|
import { AlertModalCore, TOAST_TYPE, setToast } from "@plane/ui";
|
2024-05-07 12:44:36 +05:30
|
|
|
// hooks
|
2025-08-06 22:29:55 +05:30
|
|
|
import { captureError, captureSuccess } from "@/helpers/event-tracker.helper";
|
2025-08-19 07:36:42 -07:00
|
|
|
import { useLabel } from "@/hooks/store/use-label";
|
2023-05-17 16:04:56 +05:30
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
isOpen: boolean;
|
|
|
|
|
onClose: () => void;
|
2023-11-19 01:46:11 +05:30
|
|
|
data: IIssueLabel | null;
|
2023-05-17 16:04:56 +05:30
|
|
|
};
|
|
|
|
|
|
2023-11-01 13:42:51 +05:30
|
|
|
export const DeleteLabelModal: React.FC<Props> = observer((props) => {
|
|
|
|
|
const { isOpen, onClose, data } = props;
|
|
|
|
|
// router
|
2024-06-10 12:37:38 +05:30
|
|
|
const { workspaceSlug, projectId } = useParams();
|
2024-01-02 18:12:55 +05:30
|
|
|
// store hooks
|
2024-01-22 17:07:32 +05:30
|
|
|
const { deleteLabel } = useLabel();
|
2023-11-01 13:42:51 +05:30
|
|
|
// states
|
|
|
|
|
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
2023-05-17 16:04:56 +05:30
|
|
|
|
|
|
|
|
const handleClose = () => {
|
|
|
|
|
onClose();
|
|
|
|
|
setIsDeleteLoading(false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleDeletion = async () => {
|
|
|
|
|
if (!workspaceSlug || !projectId || !data) return;
|
|
|
|
|
|
|
|
|
|
setIsDeleteLoading(true);
|
|
|
|
|
|
2024-01-02 18:12:55 +05:30
|
|
|
await deleteLabel(workspaceSlug.toString(), projectId.toString(), data.id)
|
2023-11-01 13:42:51 +05:30
|
|
|
.then(() => {
|
2025-08-06 22:29:55 +05:30
|
|
|
captureSuccess({
|
|
|
|
|
eventName: PROJECT_SETTINGS_TRACKER_EVENTS.label_deleted,
|
|
|
|
|
payload: {
|
|
|
|
|
name: data.name,
|
|
|
|
|
project_id: projectId,
|
|
|
|
|
},
|
|
|
|
|
});
|
2023-11-01 13:42:51 +05:30
|
|
|
handleClose();
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
2023-05-17 16:04:56 +05:30
|
|
|
setIsDeleteLoading(false);
|
|
|
|
|
|
2025-08-06 22:29:55 +05:30
|
|
|
captureError({
|
|
|
|
|
eventName: PROJECT_SETTINGS_TRACKER_EVENTS.label_deleted,
|
|
|
|
|
payload: {
|
|
|
|
|
name: data.name,
|
|
|
|
|
project_id: projectId,
|
|
|
|
|
},
|
|
|
|
|
error: err,
|
|
|
|
|
});
|
|
|
|
|
|
2023-11-01 13:42:51 +05:30
|
|
|
const error = err?.error || "Label could not be deleted. Please try again.";
|
2024-03-06 14:18:41 +05:30
|
|
|
setToast({
|
|
|
|
|
type: TOAST_TYPE.ERROR,
|
2023-05-17 16:04:56 +05:30
|
|
|
title: "Error!",
|
2023-11-01 13:42:51 +05:30
|
|
|
message: error,
|
2023-05-17 16:04:56 +05:30
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2024-05-07 12:44:36 +05:30
|
|
|
<AlertModalCore
|
|
|
|
|
handleClose={handleClose}
|
|
|
|
|
handleSubmit={handleDeletion}
|
2024-05-31 17:40:21 +05:30
|
|
|
isSubmitting={isDeleteLoading}
|
2024-05-07 12:44:36 +05:30
|
|
|
isOpen={isOpen}
|
|
|
|
|
title="Delete Label"
|
|
|
|
|
content={
|
|
|
|
|
<>
|
|
|
|
|
Are you sure you want to delete <span className="font-medium text-custom-text-100">{data?.name}</span>? This
|
2025-02-06 20:41:31 +05:30
|
|
|
will remove the label from all the work item and from any views where the label is being filtered upon.
|
2024-05-07 12:44:36 +05:30
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
/>
|
2023-05-17 16:04:56 +05:30
|
|
|
);
|
2023-11-01 13:42:51 +05:30
|
|
|
});
|