Some checks failed
CodeQL / Analyze (javascript) (push) Failing after 16s
CodeQL / Analyze (python) (push) Failing after 3s
i18n sync check / check:sync (push) Failing after 3s
React Doctor / react-doctor (push) Failing after 16s
Branch Build CE / Build-Push Admin Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Merge Admin Manifest (push) Has been cancelled
Branch Build CE / Build-Push Web Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Merge Web Manifest (push) Has been cancelled
Branch Build CE / Build-Push Space Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Merge Proxy Manifest (push) Has been cancelled
Branch Build CE / Merge Space Manifest (push) Has been cancelled
Branch Build CE / Prepare AIO Assets (push) Has been cancelled
Branch Build CE / Build Setup (push) Has been cancelled
Branch Build CE / Build-Push Live Collaboration Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Merge Live Collaboration Manifest (push) Has been cancelled
Branch Build CE / Build-Push API Server Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Merge API Server Manifest (push) Has been cancelled
Branch Build CE / Build-Push Proxy Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Build-Push AIO Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Merge AIO Manifest (push) Has been cancelled
Branch Build CE / Upload Build Assets (push) Has been cancelled
Branch Build CE / Build Release (push) Has been cancelled
82 lines
2.2 KiB
TypeScript
82 lines
2.2 KiB
TypeScript
/**
|
|
* Copyright (c) 2023-present Plane Software, Inc. and contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
* See the LICENSE file for details.
|
|
*/
|
|
|
|
import { useState } from "react";
|
|
import { observer } from "mobx-react";
|
|
import { useParams } from "next/navigation";
|
|
// Plane imports
|
|
import { TOAST_TYPE, setToast } from "@plane/propel/toast";
|
|
import type { IState } from "@plane/types";
|
|
// ui
|
|
import { AlertModalCore } from "@plane/ui";
|
|
// hooks
|
|
import { useProjectState } from "@/hooks/store/use-project-state";
|
|
|
|
type TStateDeleteModal = {
|
|
isOpen: boolean;
|
|
onClose: () => void;
|
|
data: IState | null;
|
|
};
|
|
|
|
export const StateDeleteModal = observer(function StateDeleteModal(props: TStateDeleteModal) {
|
|
const { isOpen, onClose, data } = props;
|
|
// states
|
|
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
|
// router
|
|
const { workspaceSlug } = useParams();
|
|
const { deleteState } = useProjectState();
|
|
|
|
const handleClose = () => {
|
|
onClose();
|
|
setIsDeleteLoading(false);
|
|
};
|
|
|
|
const handleDeletion = async () => {
|
|
if (!workspaceSlug || !data) return;
|
|
|
|
setIsDeleteLoading(true);
|
|
|
|
await deleteState(workspaceSlug.toString(), data.project_id, data.id)
|
|
.then(() => {
|
|
handleClose();
|
|
})
|
|
.catch((err) => {
|
|
if (err.status === 400)
|
|
setToast({
|
|
type: TOAST_TYPE.ERROR,
|
|
title: "Error!",
|
|
message:
|
|
"This state contains some work items within it, please move them to some other state to delete this state.",
|
|
});
|
|
else
|
|
setToast({
|
|
type: TOAST_TYPE.ERROR,
|
|
title: "Error!",
|
|
message: "State could not be deleted. Please try again.",
|
|
});
|
|
})
|
|
.finally(() => {
|
|
setIsDeleteLoading(false);
|
|
});
|
|
};
|
|
|
|
return (
|
|
<AlertModalCore
|
|
handleClose={handleClose}
|
|
handleSubmit={handleDeletion}
|
|
isSubmitting={isDeleteLoading}
|
|
isOpen={isOpen}
|
|
title="Delete State"
|
|
content={
|
|
<>
|
|
Are you sure you want to delete state- <span className="font-medium text-primary">{data?.name}</span>? All of
|
|
the data related to the state will be permanently removed. This action cannot be undone.
|
|
</>
|
|
}
|
|
/>
|
|
);
|
|
});
|