Show loader on form submissions

This commit is contained in:
James Nuanez committed 2020-04-24 17:20:01 -07:00
1 parent a409fc7cd9
commit 344671b2f2
4 files changed
+34

No files matched your search

+9
View File
@@ -216,7 +216,9 @@ const ApplicationForm = props => {
const handleSumit = async (e) => {
let isMounted = true;
try {
setShowLoader(true);
e.preventDefault();
setErrorMessage('');
setInvalidName(false);
@@ -350,8 +352,10 @@ const ApplicationForm = props => {
});
if (props.type === 'setup') {
isMounted = false;
history.push('/configure-sip-trunk');
} else {
isMounted = false;
history.push('/internal/applications');
const dispatchMessage = props.type === 'add'
? 'Application created successfully'
@@ -367,6 +371,7 @@ const ApplicationForm = props => {
if (err.response && err.response.status === 401) {
localStorage.removeItem('token');
sessionStorage.clear();
isMounted = false;
history.push('/');
dispatch({
type: 'ADD',
@@ -377,6 +382,10 @@ const ApplicationForm = props => {
setErrorMessage((err.response && err.response.data && err.response.data.msg) || 'Something went wrong, please try again.');
console.log(err.response || err);
}
} finally {
if (isMounted) {
setShowLoader(false);
}
}
};