Add confirm dialog

This commit is contained in:
dvirlabs 2025-07-13 00:53:52 +03:00
parent 3058fe5285
commit ce543dd347
5 changed files with 387 additions and 333 deletions

View File

@ -1,40 +0,0 @@
{
"nodes": [
{
"id": "1",
"type": "custom",
"data": {
"label": "Node 1",
"icon": "https://s3.dvirlabs.com/lab-icons/default.svg"
},
"position": {
"x": 303.3305220688578,
"y": 269.54671638680003
},
"width": 104,
"height": 104
},
{
"id": "2",
"type": "custom",
"data": {
"label": "Node 2",
"icon": "https://s3.dvirlabs.com/lab-icons/default.svg"
},
"position": {
"x": 87.45932948916324,
"y": 183.0493678043483
},
"width": 104,
"height": 104
}
],
"edges": [
{
"id": "reactflow__edge-1source-left-2target-right",
"source": "1",
"target": "2",
"animated": true
}
]
}

File diff suppressed because it is too large Load Diff

View File

@ -10,7 +10,9 @@
"preview": "vite preview"
},
"dependencies": {
"prop-types": "^15.8.1",
"react": "^19.1.0",
"react-confirm-alert": "^3.0.6",
"react-dom": "^19.1.0",
"react-toastify": "^11.0.5",
"reactflow": "^11.11.4"

View File

@ -7,6 +7,9 @@ import ReactFlow, {
useEdgesState,
} from 'reactflow';
import 'reactflow/dist/style.css';
import { confirmAlert } from 'react-confirm-alert';
import 'react-confirm-alert/src/react-confirm-alert.css';
import '../styles/ConfirmDialog.css';
import {
fetchDiagramByName,
saveDiagramByName,
@ -155,7 +158,14 @@ function Diagram() {
toast.warn("❌ Cannot delete 'default' diagram or nothing selected.");
return;
}
if (!confirm(`Delete "${diagramName}"?`)) return;
confirmAlert({
title: 'Are you sure?',
message: `Delete "${diagramName}"?`,
buttons: [
{
label: 'Yes',
onClick: async () => {
try {
await deleteDiagramByName(diagramName);
const updatedList = diagramList.filter(name => name !== diagramName);
@ -168,8 +178,17 @@ function Diagram() {
} catch (err) {
toast.error(`❌ Failed to delete diagram "${diagramName}"`);
}
}
},
{
label: 'No',
onClick: () => {} // do nothing
}
]
});
};
return (
<div style={{ width: '100vw', height: '100vh' }}>
<div style={{ position: 'absolute', zIndex: 10, right: 10, top: 10, display: 'flex', alignItems: 'center', gap: 10 }}>

View File

@ -0,0 +1,24 @@
.react-confirm-alert-overlay {
background: rgba(0, 0, 0, 0.6); /* כהה ונעים לעין */
z-index: 1000;
}
.react-confirm-alert-body {
background-color: #e6e3e3;
color: #333;
}
.react-confirm-alert-button-group button {
margin: 0 10px;
padding: 8px 18px;
border: none;
border-radius: 6px;
font-weight: bold;
background-color: #333;
color: white;
cursor: pointer;
}
.react-confirm-alert-button-group button:hover {
background-color: #555;
}