Close pop up modal after success form state

I currently have a popup model designed to close when an X is clicked. I would like to have the modal also disappear after a user submits the form successfully after a few seconds.

I have an animation set up from the submit button, however if there is an error on the form, the pop up still closes after a few seconds, not allowing the user time to fix the error.

https://preview.webflow.com/preview/rootedinscience?utm_medium=preview_link&utm_source=designer&utm_content=rootedinscience&preview=5cf0e72f39fb16f4438f95dba31f7c63&workflow=preview

This can only be achieved with custom code as there is no callback function in interactions.

I’ve added a Div behind the form which if clicked removes the form and instruct the user to click away this way. Would be amazing if someone could share what the code should look like.