@@ -177,35 +177,50 @@ export function useGetModulesNeedingSetupThatCanCurrentlyBeSetUp(): AttachedModu
177177}
178178
179179export function useModuleAttachedToast (
180- launchModuleSetupCallback : ( ) => void
180+ launchModuleSetupCallback : ( open : boolean ) => void
181181) : void {
182182 const currentlySetuppableModules = useGetModulesNeedingSetupThatCanCurrentlyBeSetUp ( )
183183
184184 const currentRunId = useCurrentRunId ( { refetchInterval : CURRENT_RUN_POLL } )
185185 const { t, i18n } = useTranslation ( [ 'module_wizard_flows' , 'shared' ] )
186- const { makeToast } = useToaster ( )
186+ const { makeToast, eatToast } = useToaster ( )
187187 const moduleSerials = currentlySetuppableModules . map ( m => m . serialNumber )
188188 const moduleSerialsRef = useRef ( moduleSerials )
189189 const runInProgress = currentRunId != null
190+ const [ toastID , setToastID ] = useState < string > ( '' )
190191
191192 const [ firstRun , setFirstRun ] = useState < boolean > ( true )
192193
193194 useEffect ( ( ) => {
194195 const newModuleSerials = difference ( moduleSerials , moduleSerialsRef . current )
195196 if ( ! runInProgress && newModuleSerials . length > 0 ) {
196- makeToast ( t ( 'module_added' ) as string , 'info' , {
197- buttonText : i18n . format ( t ( 'shared:close' ) , 'capitalize' ) ,
198- linkText : t ( 'module_added_link' ) ,
199- onLinkClick : launchModuleSetupCallback ,
200- disableTimeout : true ,
201- displayType : 'odd' ,
202- } )
197+ setToastID (
198+ makeToast ( t ( 'module_added' ) as string , 'info' , {
199+ buttonText : i18n . format ( t ( 'shared:close' ) , 'capitalize' ) ,
200+ linkText : t ( 'module_added_link' ) ,
201+ onLinkClick : ( ) => {
202+ launchModuleSetupCallback ( true )
203+ } ,
204+ disableTimeout : true ,
205+ displayType : 'odd' ,
206+ } )
207+ )
203208 }
209+
204210 moduleSerialsRef . current = moduleSerials
205211 setFirstRun ( false )
206212 // dont want this hook to rerun when other deps change
207213 // eslint-disable-next-line react-hooks/exhaustive-deps
208214 } , [ moduleSerials , runInProgress , firstRun ] )
215+
216+ useEffect ( ( ) => {
217+ // Close toast if there are no new modules to setup
218+ if ( toastID && currentlySetuppableModules . length === 0 ) {
219+ launchModuleSetupCallback ( false )
220+ eatToast ( toastID )
221+ setToastID ( '' )
222+ }
223+ } , [ toastID , currentlySetuppableModules ] )
209224}
210225
211226export function useScrollRef ( ) : {
0 commit comments