Fixed the errors coming out in csv.
This commit is contained in:
1 parent
ecce31ce34
commit
075559ffc3
3 files changed
+52
-28
No files matched your search
@@ -3,11 +3,9 @@ import { networkService } from "../main";
|
||||
|
||||
export const useBulkMonitors = () => {
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [error, setError] = useState(null);
|
||||
|
||||
const createBulkMonitors = async (file, user) => {
|
||||
setIsLoading(true);
|
||||
setError(null);
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append("csvFile", file);
|
||||
@@ -16,14 +14,14 @@ export const useBulkMonitors = () => {
|
||||
|
||||
try {
|
||||
const response = await networkService.createBulkMonitors(formData);
|
||||
return response.data;
|
||||
return [true, response.data, null]; // [success, data, error]
|
||||
} catch (err) {
|
||||
setError(err?.response?.data?.msg ?? err.message);
|
||||
return null;
|
||||
const errorMessage = err?.response?.data?.errors?.[0]?.message || err.message;
|
||||
return [false, null, errorMessage];
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return [createBulkMonitors, isLoading, error];
|
||||
return [createBulkMonitors, isLoading];
|
||||
};
|
||||
@@ -26,20 +26,22 @@ const BulkImport = () => {
|
||||
{ name: t("bulkImport.title"), path: `/uptime/bulk-import` },
|
||||
];
|
||||
|
||||
const [createBulkMonitors, hookLoading, error] = useBulkMonitors();
|
||||
const [createBulkMonitors, hookLoading] = useBulkMonitors();
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!selectedFile) {
|
||||
createToast({ body: t("bulkImport.noFileSelected") });
|
||||
return;
|
||||
}
|
||||
const success = await createBulkMonitors(selectedFile, user);
|
||||
|
||||
const [success, data, error] = await createBulkMonitors(selectedFile, user);
|
||||
|
||||
if (success) {
|
||||
// You can use `data` here if needed
|
||||
createToast({ body: t("bulkImport.uploadSuccess") });
|
||||
navigate("/uptime");
|
||||
} else {
|
||||
createToast({ body: error });
|
||||
createToast({ body: error || t("bulkImport.uploadFailed") });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user