@@ -4,9 +4,15 @@ import { ArchiveBoxIcon, DocumentIcon, TrashIcon } from '@heroicons/react/24/out
44import { OBJ_TYPES } from 'constants/Common' ;
55import { deleteEnvironmentFile } from 'service/collection' ;
66import EnvOptionsMenu from 'components/atoms/sidebar/environments/EnvOptionsMenu' ;
7+ import ConfirmActionModal from 'components/molecules/modals/ConfirmActionModal' ;
78
89const Environment = ( { collectionId, collection } ) => {
910 const [ isExpanded , setIsExpanded ] = useState ( false ) ;
11+ const [ confirmActionModalOpen , setConfirmActionModalOpen ] = useState ( false ) ;
12+ const [ envToDelete , setEnvToDelete ] = useState ( '' ) ;
13+
14+ const messageForConfirmActionModal = 'Do you wish to delete this environment' ;
15+
1016 return (
1117 < >
1218 < li >
@@ -46,18 +52,8 @@ const Environment = ({ collectionId, collection }) => {
4652 < div
4753 className = 'relative inline-block p-2 text-left transition duration-200 ease-out rounded rounded-l-none hover:bg-slate-200'
4854 onClick = { ( ) => {
49- deleteEnvironmentFile ( environment . name , collectionId )
50- . then ( ( result ) => {
51- console . log (
52- `Deleted environment: name = ${ environment . name } , path = ${ environment . pathname } , collectionId = ${ collectionId } , result: ${ result } ` ,
53- ) ;
54- } )
55- . catch ( ( error ) => {
56- // TODO: show error in UI
57- console . log (
58- `Error deleting environment: name = ${ environment . name } , path = ${ environment . pathname } , collectionId = ${ collectionId } and error: ${ error } ` ,
59- ) ;
60- } ) ;
55+ setEnvToDelete ( environment . name ) ;
56+ setConfirmActionModalOpen ( true ) ;
6157 } }
6258 >
6359 < TrashIcon className = 'w-4 h-4' aria-hidden = 'true' />
@@ -69,6 +65,26 @@ const Environment = ({ collectionId, collection }) => {
6965 </ >
7066 ) }
7167 </ li >
68+ < ConfirmActionModal
69+ closeFn = { ( ) => setConfirmActionModalOpen ( false ) }
70+ open = { confirmActionModalOpen }
71+ message = { messageForConfirmActionModal }
72+ actionFn = { ( ) => {
73+ deleteEnvironmentFile ( envToDelete , collectionId )
74+ . then ( ( result ) => {
75+ console . log (
76+ `Deleted environment: name = ${ envToDelete } , collectionId = ${ collectionId } , result: ${ result } ` ,
77+ ) ;
78+ } )
79+ . catch ( ( error ) => {
80+ // TODO: show error in UI
81+ console . log (
82+ `Error deleting environment: name = ${ envToDelete } , collectionId = ${ collectionId } and error: ${ error } ` ,
83+ ) ;
84+ } ) ;
85+ setConfirmActionModalOpen ( false ) ;
86+ } }
87+ />
7288 </ >
7389 ) ;
7490} ;
0 commit comments