Browse Source

fix failed fetch toast loading

AykutSarac 3 years ago
parent
commit
9a6bcd3718
1 changed files with 3 additions and 3 deletions
  1. 3 3
      src/containers/ImportModal/index.tsx

+ 3 - 3
src/containers/ImportModal/index.tsx

@@ -65,7 +65,7 @@ export const ImportModal: React.FC<ModalProps> = ({ visible, setVisible }) => {
     if (url) {
     if (url) {
       setJsonFile(null);
       setJsonFile(null);
 
 
-      const toastId = toast.loading("Loading...");
+      toast.loading("Loading...", { id: "toastFetch" });
       return fetch(url)
       return fetch(url)
         .then((res) => res.json())
         .then((res) => res.json())
         .then((json) => {
         .then((json) => {
@@ -74,10 +74,10 @@ export const ImportModal: React.FC<ModalProps> = ({ visible, setVisible }) => {
             payload: JSON.stringify(json),
             payload: JSON.stringify(json),
           });
           });
 
 
-          toast.dismiss(toastId);
           setVisible(false);
           setVisible(false);
         })
         })
-        .catch(() => toast.error("Failed to fetch JSON!"));
+        .catch(() => toast.error("Failed to fetch JSON!"))
+        .finally(() => toast.dismiss("toastFetch"));
     }
     }
 
 
     if (jsonFile) {
     if (jsonFile) {