Skip to content

Commit d0c8982

Browse files
committed
add pop up
1 parent d7d569f commit d0c8982

3 files changed

Lines changed: 80 additions & 5 deletions

File tree

src/component/TabBar.jsx

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useState } from 'react';
22
import {
33
MdEdit, MdClose, MdAdd,
44
} from 'react-icons/md';
@@ -8,19 +8,34 @@ import localStorageManager from '../graph-builder/local-storage-manager';
88
import { actionType as T } from '../reducer';
99
import { newProject, editDetails } from '../toolbarActions/toolbarFunctions';
1010
import './tabBar.css';
11+
import ConfirmModal from './modals/ConfirmModal';
1112

1213
const TabBar = ({ superState, dispatcher }) => {
13-
const closeTab = (i, e) => {
14+
const [confirmOpen, setConfirmOpen] = useState(false);
15+
const [tabToClose, setTabToClose] = useState(null);
16+
17+
const handleRequestCloseTab = (i, e) => {
1418
e.stopPropagation();
15-
// eslint-disable-next-line no-alert
16-
if (!window.confirm('Do you confirm to close the tab? This action is irreversable.')) return;
19+
setTabToClose(i);
20+
setConfirmOpen(true);
21+
};
22+
23+
const handleConfirmClose = () => {
24+
const i = tabToClose;
25+
setConfirmOpen(false);
26+
setTabToClose(null);
1727
localStorageManager.remove(superState.graphs[i] ? superState.graphs[i].graphID : null);
1828
dispatcher({ type: T.REMOVE_GRAPH, payload: i });
1929
if (!superState.curGraphIndex && superState.graphs.length === 1) {
2030
dispatcher({ type: T.SET_CUR_INSTANCE, payload: null });
2131
dispatcher({ type: T.SET_CUR_INDEX, payload: -1 });
2232
}
2333
};
34+
35+
const handleCancelClose = () => {
36+
setConfirmOpen(false);
37+
setTabToClose(null);
38+
};
2439
const editCur = (e) => {
2540
e.stopPropagation();
2641
editDetails(superState, dispatcher);
@@ -80,7 +95,7 @@ const TabBar = ({ superState, dispatcher }) => {
8095
) : <></>}
8196
<button
8297
className="tab-act close"
83-
onClick={closeTab.bind(this, i)}
98+
onClick={handleRequestCloseTab.bind(this, i)}
8499
type="button"
85100
data-tip="Close current Workflow (Ctrl + Shift + L)"
86101
data-for="header-tab"
@@ -90,6 +105,13 @@ const TabBar = ({ superState, dispatcher }) => {
90105
<ReactTooltip place="bottom" type="dark" effect="solid" id="header-tab" />
91106
</div>
92107
))}
108+
<ConfirmModal
109+
isOpen={confirmOpen}
110+
title="Close Tab"
111+
message="Do you confirm to close the tab? This action is irreversible."
112+
onConfirm={handleConfirmClose}
113+
onCancel={handleCancelClose}
114+
/>
93115
</div>
94116
);
95117
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from 'react';
2+
import ParentModal from './ParentModal';
3+
import './confirmModal.css';
4+
5+
const ConfirmModal = ({
6+
isOpen, title, message, onConfirm, onCancel,
7+
}) => (
8+
<ParentModal ModelOpen={isOpen} closeModal={onCancel} title={title}>
9+
<div className="confirm-modal-content">
10+
<div className="confirm-modal-message">{message}</div>
11+
<div className="confirm-modal-actions">
12+
<button type="button" className="confirm-btn" onClick={onConfirm}>Yes</button>
13+
<button type="button" className="cancel-btn" onClick={onCancel}>No</button>
14+
</div>
15+
</div>
16+
</ParentModal>
17+
);
18+
19+
export default ConfirmModal;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.confirm-modal-content {
2+
padding: 20px;
3+
text-align: center;
4+
}
5+
.confirm-modal-message {
6+
margin-bottom: 20px;
7+
font-size: 1.1em;
8+
}
9+
.confirm-modal-actions {
10+
display: flex;
11+
justify-content: center;
12+
gap: 20px;
13+
}
14+
.confirm-btn, .cancel-btn {
15+
padding: 8px 20px;
16+
font-size: 1em;
17+
border: none;
18+
border-radius: 4px;
19+
cursor: pointer;
20+
}
21+
.confirm-btn {
22+
background: #d9534f;
23+
color: #fff;
24+
}
25+
.cancel-btn {
26+
background: #f0f0f0;
27+
color: #333;
28+
}
29+
.confirm-btn:hover {
30+
background: #c9302c;
31+
}
32+
.cancel-btn:hover {
33+
background: #e0e0e0;
34+
}

0 commit comments

Comments
 (0)