forked from github/plane
20e7dc68e6
* style: update modals typography, alignment * style: made the modal separator full width * style: delete modals consistency * style: update the remaining delete modals * chore: delete modal secondary button text * style: update the remaining create modals * chore: update cancel button text * chore: created modal core * style: modals responsiveness
89 lines
2.5 KiB
TypeScript
89 lines
2.5 KiB
TypeScript
import React, { useState } from "react";
|
|
import { observer } from "mobx-react-lite";
|
|
import { useRouter } from "next/router";
|
|
// types
|
|
import type { IModule } from "@plane/types";
|
|
// ui
|
|
import { TOAST_TYPE, setToast } from "@plane/ui";
|
|
// components
|
|
import { AlertModalCore } from "@/components/core";
|
|
// constants
|
|
import { MODULE_DELETED } from "@/constants/event-tracker";
|
|
// hooks
|
|
import { useEventTracker, useModule } from "@/hooks/store";
|
|
|
|
type Props = {
|
|
data: IModule;
|
|
isOpen: boolean;
|
|
onClose: () => void;
|
|
};
|
|
|
|
export const DeleteModuleModal: React.FC<Props> = observer((props) => {
|
|
const { data, isOpen, onClose } = props;
|
|
// states
|
|
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
|
// router
|
|
const router = useRouter();
|
|
const { workspaceSlug, projectId, moduleId, peekModule } = router.query;
|
|
// store hooks
|
|
const { captureModuleEvent } = useEventTracker();
|
|
const { deleteModule } = useModule();
|
|
|
|
const handleClose = () => {
|
|
onClose();
|
|
setIsDeleteLoading(false);
|
|
};
|
|
|
|
const handleDeletion = async () => {
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
setIsDeleteLoading(true);
|
|
|
|
await deleteModule(workspaceSlug.toString(), projectId.toString(), data.id)
|
|
.then(() => {
|
|
if (moduleId || peekModule) router.push(`/${workspaceSlug}/projects/${data.project_id}/modules`);
|
|
handleClose();
|
|
setToast({
|
|
type: TOAST_TYPE.SUCCESS,
|
|
title: "Success!",
|
|
message: "Module deleted successfully.",
|
|
});
|
|
captureModuleEvent({
|
|
eventName: MODULE_DELETED,
|
|
payload: { ...data, state: "SUCCESS" },
|
|
});
|
|
})
|
|
.catch(() => {
|
|
setToast({
|
|
type: TOAST_TYPE.ERROR,
|
|
title: "Error!",
|
|
message: "Module could not be deleted. Please try again.",
|
|
});
|
|
captureModuleEvent({
|
|
eventName: MODULE_DELETED,
|
|
payload: { ...data, state: "FAILED" },
|
|
});
|
|
})
|
|
.finally(() => {
|
|
setIsDeleteLoading(false);
|
|
});
|
|
};
|
|
|
|
return (
|
|
<AlertModalCore
|
|
handleClose={handleClose}
|
|
handleSubmit={handleDeletion}
|
|
isDeleting={isDeleteLoading}
|
|
isOpen={isOpen}
|
|
title="Delete Module"
|
|
content={
|
|
<>
|
|
Are you sure you want to delete module-{" "}
|
|
<span className="break-all font-medium text-custom-text-100">{data?.name}</span>? All of the data related to
|
|
the module will be permanently removed. This action cannot be undone.
|
|
</>
|
|
}
|
|
/>
|
|
);
|
|
});
|