Jelajahi Sumber

fix upload file & add loader for fetch

AykutSarac 3 tahun lalu
induk
melakukan
d5d90ef1c7
1 mengubah file dengan 4 tambahan dan 0 penghapusan
  1. 4 0
      src/containers/ImportModal/index.tsx

+ 4 - 0
src/containers/ImportModal/index.tsx

@@ -65,6 +65,7 @@ export const ImportModal = ({ visible, setVisible }) => {
     if (url) {
       setJsonFile(null);
 
+      const toastId = toast.loading("Loading...");
       return fetch(url)
         .then((res) => res.json())
         .then((json) => {
@@ -73,6 +74,7 @@ export const ImportModal = ({ visible, setVisible }) => {
             payload: JSON.stringify(json),
           });
 
+          toast.dismiss(toastId);
           setVisible(false);
         })
         .catch(() => toast.error("Failed to fetch JSON!"));
@@ -87,6 +89,8 @@ export const ImportModal = ({ visible, setVisible }) => {
           type: ConfigActionType.SET_JSON,
           payload: data.target?.result as string,
         });
+
+        setVisible(false);
       };
     }
   };