plane/web/core/components/views/delete-view-modal.tsx
Aaryan Khandelwal 244986554c
chore: move modal core components to the UI package (#4794)
* chore: move modal core components to the UI package

* fix: build errors
2024-06-14 17:12:39 +05:30

77 lines
1.9 KiB
TypeScript

"use client";
import React, { useState } from "react";
import { observer } from "mobx-react";
import { useParams } from "next/navigation";
// types
import { IProjectView } from "@plane/types";
// ui
import { AlertModalCore, TOAST_TYPE, setToast } from "@plane/ui";
// hooks
import { useProjectView } from "@/hooks/store";
type Props = {
data: IProjectView;
isOpen: boolean;
onClose: () => void;
};
export const DeleteProjectViewModal: React.FC<Props> = observer((props) => {
const { data, isOpen, onClose } = props;
// states
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
// router
const { workspaceSlug, projectId } = useParams();
// store hooks
const { deleteView } = useProjectView();
const handleClose = () => {
onClose();
setIsDeleteLoading(false);
};
const handleDeleteView = async () => {
if (!workspaceSlug || !projectId) return;
setIsDeleteLoading(true);
await deleteView(workspaceSlug.toString(), projectId.toString(), data.id)
.then(() => {
handleClose();
setToast({
type: TOAST_TYPE.SUCCESS,
title: "Success!",
message: "View deleted successfully.",
});
})
.catch(() =>
setToast({
type: TOAST_TYPE.ERROR,
title: "Error!",
message: "View could not be deleted. Please try again.",
})
)
.finally(() => {
setIsDeleteLoading(false);
});
};
return (
<AlertModalCore
handleClose={handleClose}
handleSubmit={handleDeleteView}
isSubmitting={isDeleteLoading}
isOpen={isOpen}
title="Delete View"
content={
<>
Are you sure you want to delete view-{" "}
<span className="break-all font-medium text-custom-text-100">{data?.name}</span>? All of the data related to
the view will be permanently removed. This action cannot be undone.
</>
}
/>
);
});