1- import React from 'react' ;
1+ import React , { useState } from 'react' ;
22import {
33 MdEdit , MdClose , MdAdd ,
44} from 'react-icons/md' ;
@@ -8,19 +8,34 @@ import localStorageManager from '../graph-builder/local-storage-manager';
88import { actionType as T } from '../reducer' ;
99import { newProject , editDetails } from '../toolbarActions/toolbarFunctions' ;
1010import './tabBar.css' ;
11+ import ConfirmModal from './modals/ConfirmModal' ;
1112
1213const 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} ;
0 commit comments