mirror of
https://github.com/makeplane/plane.git
synced 2026-05-03 06:29:43 -05:00
[WEB-2150] fix: issue selection redirect alert (#5406)
* fix issue selection redirect alert * change message content for user prompt
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
import { useCallback, useEffect, useMemo } from "react";
|
||||
// hooks
|
||||
import { useMultipleSelectStore } from "@/hooks/store";
|
||||
//
|
||||
import useReloadConfirmations from "./use-reload-confirmation";
|
||||
|
||||
export type TEntityDetails = {
|
||||
entityID: string;
|
||||
@@ -52,6 +54,15 @@ export const useMultipleSelect = (props: Props) => {
|
||||
getEntityDetailsFromEntityID,
|
||||
} = useMultipleSelectStore();
|
||||
|
||||
useReloadConfirmations(
|
||||
selectedEntityIds && selectedEntityIds.length > 0,
|
||||
"Are you sure you want to leave? Your current bulk operation selections will be lost.",
|
||||
true,
|
||||
() => {
|
||||
clearSelection();
|
||||
}
|
||||
);
|
||||
|
||||
const groups = useMemo(() => Object.keys(entities), [entities]);
|
||||
|
||||
const entitiesList: TEntityDetails[] = useMemo(
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
|
||||
//TODO: remove temp flag isActive later and use showAlert as the source of truth
|
||||
const useReloadConfirmations = (isActive = true) => {
|
||||
const [showAlert, setShowAlert] = useState(false);
|
||||
const useReloadConfirmations = (isActive = true, message?: string, defaultShowAlert = false, onLeave?: () => void) => {
|
||||
const [showAlert, setShowAlert] = useState(defaultShowAlert);
|
||||
|
||||
const alertMessage = message ?? "Are you sure you want to leave? Changes you made may not be saved.";
|
||||
|
||||
const handleBeforeUnload = useCallback(
|
||||
(event: BeforeUnloadEvent) => {
|
||||
@@ -28,8 +30,10 @@ const useReloadConfirmations = (isActive = true) => {
|
||||
const isAnchorTargetBlank = anchorElement.getAttribute("target") === "_blank";
|
||||
if (isAnchorTargetBlank) return;
|
||||
// show confirm dialog
|
||||
const leave = confirm("Are you sure you want to leave? Changes you made may not be saved.");
|
||||
if (!leave) {
|
||||
const isLeaving = confirm(alertMessage);
|
||||
if (isLeaving) {
|
||||
onLeave && onLeave();
|
||||
} else {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user