11import { ArrowForwardIos } from '@mui/icons-material' ;
2- import { Alert , Button , Snackbar , Typography } from '@mui/material' ;
3- import { useContext , useState } from 'react' ;
2+ import {
3+ Alert ,
4+ Button ,
5+ CircularProgress ,
6+ Grid ,
7+ Snackbar ,
8+ Typography ,
9+ } from '@mui/material' ;
10+ import { useContext , useEffect , useState } from 'react' ;
411import { useTranslation } from 'react-i18next' ;
512import { ApplicationContext } from '../../contexts/ApplicationContext' ;
13+ import { EventContext } from '../../contexts/EventContext' ;
614import { DEFAULT_BORDER_RADIUS } from '../../theme' ;
715
816interface Props {
@@ -16,6 +24,9 @@ export const RunButton: React.FC<Props> = ({ endpoint, payload, disabled }) => {
1624 const [ showSnackbar , setShowSnackbar ] = useState ( false ) ;
1725 const { activeForm, setApiStatus, setApiResponse, payloadMissingFields } =
1826 useContext ( ApplicationContext ) ;
27+ const { dumbAwaitedEventID, addAwaitedEventID } = useContext ( EventContext ) ;
28+ // TODO: Remove soon
29+ const [ justSubmitted , setJustSubmitted ] = useState < boolean > ( false ) ;
1930
2031 const handleCloseSnackbar = ( _ : any , reason ?: string ) => {
2132 if ( reason === 'clickaway' ) {
@@ -25,6 +36,11 @@ export const RunButton: React.FC<Props> = ({ endpoint, payload, disabled }) => {
2536 setShowSnackbar ( false ) ;
2637 } ;
2738
39+ // TODO: Remove soon
40+ useEffect ( ( ) => {
41+ setJustSubmitted ( false ) ;
42+ } , [ dumbAwaitedEventID ] ) ;
43+
2844 const handlePost = ( ) => {
2945 const blobUpload = activeForm . includes ( 'blob' ) ;
3046 managePayload ( ) ;
@@ -48,6 +64,8 @@ export const RunButton: React.FC<Props> = ({ endpoint, payload, disabled }) => {
4864 . then ( ( data ) => {
4965 setShowSnackbar ( true ) ;
5066 setApiResponse ( data ) ;
67+ setJustSubmitted ( true ) ;
68+ addAwaitedEventID ( data ) ;
5169 } )
5270 . catch ( ( err ) => {
5371 setShowSnackbar ( true ) ;
@@ -82,29 +100,50 @@ export const RunButton: React.FC<Props> = ({ endpoint, payload, disabled }) => {
82100
83101 return (
84102 < >
85- < Button
86- endIcon = { < ArrowForwardIos /> }
87- variant = "contained"
88- disabled = { disabled || payloadMissingFields }
89- sx = { { borderRadius : DEFAULT_BORDER_RADIUS } }
90- onClick = { handlePost }
91- >
92- < Typography > { t ( 'run' ) } </ Typography >
93- </ Button >
94- < Snackbar
95- open = { showSnackbar }
96- autoHideDuration = { 6000 }
97- onClose = { handleCloseSnackbar }
98- >
99- < Alert
100- onClose = { handleCloseSnackbar }
101- severity = { 'info' }
102- sx = { { width : '100%' } }
103- variant = { 'filled' }
103+ { dumbAwaitedEventID || justSubmitted ? (
104+ < Grid
105+ justifyContent = "space-between"
106+ direction = "row"
107+ container
108+ alignItems = { 'center' }
104109 >
105- { `${ t ( 'postSentTo' ) } ${ endpoint } ` }
106- </ Alert >
107- </ Snackbar >
110+ < Grid item xs = { 11 } >
111+ < Typography sx = { { fontSize : '14px' , fontWeight : '500' } } >
112+ { t ( 'waitingForTxEventsToFinish' ) }
113+ </ Typography >
114+ </ Grid >
115+ < Grid item xs = { 1 } container justifyContent = "flex-end" >
116+ < CircularProgress size = { 16 } color = "warning" />
117+ </ Grid >
118+ </ Grid >
119+ ) : (
120+ < >
121+ < Button
122+ endIcon = { < ArrowForwardIos /> }
123+ variant = "contained"
124+ disabled = { disabled || payloadMissingFields }
125+ sx = { { borderRadius : DEFAULT_BORDER_RADIUS } }
126+ onClick = { handlePost }
127+ size = "small"
128+ >
129+ < Typography > { t ( 'run' ) } </ Typography >
130+ </ Button >
131+ < Snackbar
132+ open = { showSnackbar }
133+ autoHideDuration = { 6000 }
134+ onClose = { handleCloseSnackbar }
135+ >
136+ < Alert
137+ onClose = { handleCloseSnackbar }
138+ severity = { 'success' }
139+ sx = { { width : '100%' } }
140+ variant = { 'filled' }
141+ >
142+ { `${ t ( 'postSentTo' ) } ${ endpoint } ` }
143+ </ Alert >
144+ </ Snackbar >
145+ </ >
146+ ) }
108147 </ >
109148 ) ;
110149} ;
0 commit comments