* refactor: migrate constants (fetch-keys) from apps/web to @plane/constants * refactor: migrate constants (ai, calenda, gaant) from apps/web to @plane/constants * refactor: migrate constants (sidebar, favorites) from apps/web to @plane/constants * refactor: migrate constants (editor) from apps/web to @plane/constants * refactor: migrate constants (plans) from apps/web to @core/components * resolved lint errors * fix: resolve coderabbit comments * refactor: resolve coderabbit comments * refactor: migrate hooks (use-file-size) from web/app/ce to web/app/core * refactor: migrate hooks (use-notification-preview) from web/app/ce to web/app/core * refactor: migrate hooks (use-timeline-chart) from web/app/ce to web/app/core * refactor: migrate hooks (use-page, use-page-store) from web/app/ce to web/app/core * refactor: migrate hooks (app-rail, indexes) from web/app/ce to web/app/core * refactor: migrate hooks (use-page-flag) from web/app/ce to web/app/core * refactor: migrate hooks (use-editor-flagging) from web/app/ce to web/app/core * refactor: migrate hooks (use-filters-operator-configs) from web/app/ce to web/app/core * refactor: migrate hooks (use-additional-editor-mention) from web/app/ce to web/app/core * refactor: migrate hooks (use-additional-favorite-item-details) from web/app/ce to web/app/core * refactor: migrate hooks (use-extended-editor-extensions, use-pages-pane-extensions) from web/app/ce to web/app/core * refactor: migrate hooks (use-work-items-filters-config) from web/app/ce to web/app/core * refactor: migrate hooks (use-extended-editor-config) from web/app/ce to web/app/core * refactor: migrate hooks (use-bulk-operations) from web/app/ce to web/app/core * refactor: migrate hooks (use-debounced-duplicate-issues) from web/app/ce to web/app/core * refactor: migrate hooks (use-issue-properties) from web/app/ce to web/app/core * refactor: migrate hooks (use-workspace-issue-properties) from web/app/ce to web/app/core * refactor: delete hook (use-issue-embed) from web/app/ce * fix: coderabbit comments * fix: React doctor comments * fix: import structure for hooks * refactor: remove command palette & sidebar components and related files from web/app/ce * refactor: update analytics tab imports and add new analytics tab components * feat: add project, work item, and workspace level modals for enhanced user interaction * refactor: replace WorkspaceActiveCyclesRoot with WorkspaceActiveCyclesUpgrade and remove obsolete components * refactor: migrate app-rail HOC to core components and remove obsolete index file * refactor: remove unused automation components and simplify layout structure * refactor: update import paths for CommonProjectBreadcrumbs and add new breadcrumb components * refactor: update import path for WorkItemDetailRoot and add new work item detail component * refactor: remove obsolete comments index file and introduce CommentBlock component in core * refactor: update import paths for common components and introduce new ExtendedAppHeader, GlobalModals, and SubscriptionPill components * refactor: remove obsolete index file and add MaintenanceMessage and InboxSourcePill components * refactor: remove obsolete cycle components and introduce new cycle-related components in core * refac: moved de-dupe directory to core * refactor: add new desktop components and update import paths for sidebar functionality * refactor: remove obsolete index file and introduce new version number and product updates components in core * refactor: add EpicModal component and update import paths in issue layouts * refactor: add HomePageHeader and HomePeekOverviewsRoot components, update import paths in home and issues sections * refactor: remove obsolete home index file, update import paths for relation options in issue detail components, and introduce new activity helper functions * refactor: remove AdditionalFilterValueInput from legacy path and reintroduce it in core filter value input component * refactor: remove legacy workspace-notifications index file and introduce new notification components in core * refactor: remove legacy license components and update import paths for PaidPlanUpgradeModal * refactor: remove legacy navigation components and update import paths for navigation items in core * refactor: introduce onboarding tour components and update import paths for tour-related files * refactor: remove legacy theme switcher component and update import paths in profile settings * refactor: update import paths for workflow components and introduce new workflow-related files in core * refactor: remove legacy estimate components and introduce new estimate-related files in core * refactor: remove legacy gantt-chart components and introduce new core components for gantt-chart functionality * refactor: remove legacy helper components and introduce new access control and publish components in core * refactor: introduce billing components and update import paths for billing-related files in core * refactor: introduce new members components and update import paths for workspace members functionality * refactor: update import paths for workspace components and introduce new workspace-related files * refactor: remove deprecated components and clean up import paths across various modules * refactor: remove unused components and clean up import paths across various modules * refactor: remove unused sidebar components and update import paths in workspace notifications * refactor: introduce new estimate, billing, and notification card components while updating import paths across various modules * refactor: remove unused estimate and billing components, update import paths, and streamline workspace notification card structure * refactor: update import paths for project components and remove unused files in the projects module * refactor: remove unused power-k components and update import paths in the command palette module * refactor: remove unused issue components and update import paths across the issues module * refactor: remove unused mentions components and update import paths in the editor module * refactor: remove unused components and update import paths across the pages module * refactor: update type imports for issue properties in issue modal context * fix: oxfmt * fix: PR checks * [GIT-254] Refactor: Store consolidation to @core/store (#9271) * refactor: remove unused store files and update import paths across the application * refactor: remove unused store files and update import paths across the core module * refactor: remove unused issue filter and store files, and update import paths in the core module * refactor: update import paths for timeline store files and introduce new base timeline store * refactor: remove deprecated root store file and update import paths across the application * refactor: update import paths for store files and correct root store type references * refactor: standardize import comments and remove 'plane-web' artifacts across various components * fix: CodeRabbit comments * fix: format * refactor: update TypeScript configuration and improve sorting method in TabNavigationRoot component * refactor: replace toSorted with sort method for navigation item sorting in TabNavigationRoot component --------- Co-authored-by: Rahulcheryala <rahulcheryala2004@gmail.com> Co-authored-by: Prateek Shourya <prateekshourya29@gmail.com>
130 lines
4.2 KiB
TypeScript
130 lines
4.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 { useEffect, useState } from "react";
|
|
import { observer } from "mobx-react";
|
|
import { useParams } from "next/navigation";
|
|
// types
|
|
import { PROJECT_ERROR_MESSAGES, EUserPermissions, EUserPermissionsLevel } from "@plane/constants";
|
|
import { useTranslation } from "@plane/i18n";
|
|
import { TOAST_TYPE, setToast } from "@plane/propel/toast";
|
|
import type { TDeDupeIssue, TIssue } from "@plane/types";
|
|
// ui
|
|
import { AlertModalCore } from "@plane/ui";
|
|
// hooks
|
|
import { useIssues } from "@/hooks/store/use-issues";
|
|
import { useProject } from "@/hooks/store/use-project";
|
|
import { useUser, useUserPermissions } from "@/hooks/store/user";
|
|
|
|
type Props = {
|
|
isOpen: boolean;
|
|
handleClose: () => void;
|
|
dataId?: string | null | undefined;
|
|
data?: TIssue | TDeDupeIssue;
|
|
isSubIssue?: boolean;
|
|
onSubmit?: () => Promise<void>;
|
|
isEpic?: boolean;
|
|
};
|
|
|
|
export const DeleteIssueModal = observer(function DeleteIssueModal(props: Props) {
|
|
const { dataId, data, isOpen, handleClose, isSubIssue = false, onSubmit, isEpic = false } = props;
|
|
// states
|
|
const [isDeleting, setIsDeleting] = useState(false);
|
|
// store hooks
|
|
const { workspaceSlug } = useParams();
|
|
const { issueMap } = useIssues();
|
|
const { getProjectById } = useProject();
|
|
const { allowPermissions } = useUserPermissions();
|
|
const { t } = useTranslation();
|
|
|
|
const { data: currentUser } = useUser();
|
|
|
|
useEffect(() => {
|
|
setIsDeleting(false);
|
|
}, [isOpen]);
|
|
|
|
if (!dataId && !data) return null;
|
|
|
|
// derived values
|
|
const issue = data ? data : issueMap[dataId!];
|
|
const projectDetails = getProjectById(issue?.project_id);
|
|
const isIssueCreator = issue?.created_by === currentUser?.id;
|
|
|
|
const canPerformProjectAdminActions = allowPermissions(
|
|
[EUserPermissions.ADMIN],
|
|
EUserPermissionsLevel.PROJECT,
|
|
workspaceSlug?.toString(),
|
|
projectDetails?.id
|
|
);
|
|
|
|
const authorized = isIssueCreator || canPerformProjectAdminActions;
|
|
|
|
const onClose = () => {
|
|
setIsDeleting(false);
|
|
handleClose();
|
|
};
|
|
|
|
const handleIssueDelete = async () => {
|
|
setIsDeleting(true);
|
|
|
|
if (!authorized) {
|
|
setToast({
|
|
title: t(PROJECT_ERROR_MESSAGES.permissionError.i18n_title),
|
|
type: TOAST_TYPE.ERROR,
|
|
message:
|
|
PROJECT_ERROR_MESSAGES.permissionError.i18n_message && t(PROJECT_ERROR_MESSAGES.permissionError.i18n_message),
|
|
});
|
|
onClose();
|
|
return;
|
|
}
|
|
if (onSubmit)
|
|
await onSubmit()
|
|
.then(() => {
|
|
setToast({
|
|
type: TOAST_TYPE.SUCCESS,
|
|
title: t("common.success"),
|
|
message: t("entity.delete.success", {
|
|
entity: isSubIssue ? t("common.sub_work_item") : isEpic ? t("common.epic") : t("common.work_item"),
|
|
}),
|
|
});
|
|
onClose();
|
|
})
|
|
.catch((errors) => {
|
|
const isPermissionError =
|
|
errors?.error ===
|
|
`Only admin or creator can delete the ${isSubIssue ? "sub-work item" : isEpic ? "epic" : "work item"}`;
|
|
const currentError = isPermissionError
|
|
? PROJECT_ERROR_MESSAGES.permissionError
|
|
: PROJECT_ERROR_MESSAGES.issueDeleteError;
|
|
setToast({
|
|
title: t(currentError.i18n_title),
|
|
type: TOAST_TYPE.ERROR,
|
|
message: currentError.i18n_message && t(currentError.i18n_message),
|
|
});
|
|
})
|
|
.finally(() => onClose());
|
|
};
|
|
|
|
return (
|
|
<AlertModalCore
|
|
handleClose={onClose}
|
|
handleSubmit={handleIssueDelete}
|
|
isSubmitting={isDeleting}
|
|
isOpen={isOpen}
|
|
title={t("entity.delete.label", { entity: isEpic ? t("common.epic") : t("common.work_item") })}
|
|
content={
|
|
<>
|
|
{/* TODO: Translate here */}
|
|
{`Are you sure you want to delete ${isEpic ? "epic" : "work item"} `}
|
|
<span className="font-medium break-words text-primary">
|
|
{projectDetails?.identifier}-{issue?.sequence_id}
|
|
</span>
|
|
{` ? All of the data related to the ${isEpic ? "epic" : "work item"} will be permanently removed. This action cannot be undone.`}
|
|
</>
|
|
}
|
|
/>
|
|
);
|
|
});
|