Added error catching on folder upload
This commit is contained in:
parent
2fc3541f33
commit
18d7891464
2 changed files with 28 additions and 11 deletions
|
|
@ -13,6 +13,7 @@ import IconComponent, {
|
||||||
import { Button, buttonVariants } from "../../../ui/button";
|
import { Button, buttonVariants } from "../../../ui/button";
|
||||||
import { Input } from "../../../ui/input";
|
import { Input } from "../../../ui/input";
|
||||||
import useFileDrop from "../../hooks/use-on-file-drop";
|
import useFileDrop from "../../hooks/use-on-file-drop";
|
||||||
|
import useAlertStore from "../../../../stores/alertStore";
|
||||||
|
|
||||||
type SideBarFoldersButtonsComponentProps = {
|
type SideBarFoldersButtonsComponentProps = {
|
||||||
folders: FolderType[];
|
folders: FolderType[];
|
||||||
|
|
@ -51,6 +52,7 @@ const SideBarFoldersButtonsComponent = ({
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const folderId = location?.state?.folderId ?? myCollectionId;
|
const folderId = location?.state?.folderId ?? myCollectionId;
|
||||||
const getFolderById = useFolderStore((state) => state.getFolderById);
|
const getFolderById = useFolderStore((state) => state.getFolderById);
|
||||||
|
const setErrorData = useAlertStore((state) => state.setErrorData);
|
||||||
|
|
||||||
const handleFolderChange = (folderId: string) => {
|
const handleFolderChange = (folderId: string) => {
|
||||||
getFolderById(folderId);
|
getFolderById(folderId);
|
||||||
|
|
@ -62,9 +64,17 @@ const SideBarFoldersButtonsComponent = ({
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleUploadFlowsToFolder = () => {
|
const handleUploadFlowsToFolder = () => {
|
||||||
uploadFolder(folderId).then(() => {
|
uploadFolder(folderId)
|
||||||
getFolderById(folderId);
|
.then(() => {
|
||||||
});
|
getFolderById(folderId);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
setErrorData({
|
||||||
|
title: `Error on upload`,
|
||||||
|
list: [err["response"]["data"]],
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDownloadFolder = (id: string) => {
|
const handleDownloadFolder = (id: string) => {
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ export const useFolderStore = create<FoldersStoreType>((set, get) => ({
|
||||||
folderIdDragging: "",
|
folderIdDragging: "",
|
||||||
setFolderIdDragging: (id) => set(() => ({ folderIdDragging: id })),
|
setFolderIdDragging: (id) => set(() => ({ folderIdDragging: id })),
|
||||||
uploadFolder: () => {
|
uploadFolder: () => {
|
||||||
return new Promise<void>((resolve) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
const input = document.createElement("input");
|
const input = document.createElement("input");
|
||||||
input.type = "file";
|
input.type = "file";
|
||||||
input.onchange = (event: Event) => {
|
input.onchange = (event: Event) => {
|
||||||
|
|
@ -120,15 +120,22 @@ export const useFolderStore = create<FoldersStoreType>((set, get) => ({
|
||||||
.addFlow(true, data)
|
.addFlow(true, data)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
resolve();
|
resolve();
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
reject(error);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
uploadFlowsFromFolders(formData).then(() => {
|
uploadFlowsFromFolders(formData)
|
||||||
get()
|
.then(() => {
|
||||||
.getFoldersApi(true)
|
get()
|
||||||
.then(() => {
|
.getFoldersApi(true)
|
||||||
resolve();
|
.then(() => {
|
||||||
});
|
resolve();
|
||||||
});
|
});
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue