Added error checking when file is not a JSON
This commit is contained in:
parent
2c99d2ce70
commit
109b9a1172
2 changed files with 25 additions and 5 deletions
|
|
@ -298,7 +298,14 @@ export default function Page({
|
||||||
setNodes((nds) => nds.concat(newNode));
|
setNodes((nds) => nds.concat(newNode));
|
||||||
} else if (event.dataTransfer.types.some((types) => types === "Files")) {
|
} else if (event.dataTransfer.types.some((types) => types === "Files")) {
|
||||||
takeSnapshot();
|
takeSnapshot();
|
||||||
uploadFlow(false, event.dataTransfer.files.item(0)!);
|
if (event.dataTransfer.files.item(0)!.type === "application/json") {
|
||||||
|
uploadFlow(true, event.dataTransfer.files.item(0)!);
|
||||||
|
} else {
|
||||||
|
setErrorData({
|
||||||
|
title: "Invalid file type",
|
||||||
|
list: ["Please upload a JSON file"],
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// Specify dependencies for useCallback
|
// Specify dependencies for useCallback
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import Header from "../../components/headerComponent";
|
||||||
import { SkeletonCardComponent } from "../../components/skeletonCardComponent";
|
import { SkeletonCardComponent } from "../../components/skeletonCardComponent";
|
||||||
import { Button } from "../../components/ui/button";
|
import { Button } from "../../components/ui/button";
|
||||||
import { USER_PROJECTS_HEADER } from "../../constants/constants";
|
import { USER_PROJECTS_HEADER } from "../../constants/constants";
|
||||||
|
import { alertContext } from "../../contexts/alertContext";
|
||||||
import { TabsContext } from "../../contexts/tabsContext";
|
import { TabsContext } from "../../contexts/tabsContext";
|
||||||
export default function HomePage(): JSX.Element {
|
export default function HomePage(): JSX.Element {
|
||||||
const {
|
const {
|
||||||
|
|
@ -19,6 +20,7 @@ export default function HomePage(): JSX.Element {
|
||||||
uploadFlow,
|
uploadFlow,
|
||||||
isLoading,
|
isLoading,
|
||||||
} = useContext(TabsContext);
|
} = useContext(TabsContext);
|
||||||
|
const { setErrorData } = useContext(alertContext);
|
||||||
const dropdownOptions = [
|
const dropdownOptions = [
|
||||||
{
|
{
|
||||||
name: "Import from JSON",
|
name: "Import from JSON",
|
||||||
|
|
@ -55,7 +57,14 @@ export default function HomePage(): JSX.Element {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setIsDragging(false);
|
setIsDragging(false);
|
||||||
if (e.dataTransfer.types.some((types) => types === "Files")) {
|
if (e.dataTransfer.types.some((types) => types === "Files")) {
|
||||||
uploadFlow(true, e.dataTransfer.files.item(0)!);
|
if (e.dataTransfer.files.item(0).type === "application/json") {
|
||||||
|
uploadFlow(true, e.dataTransfer.files.item(0)!);
|
||||||
|
} else {
|
||||||
|
setErrorData({
|
||||||
|
title: "Invalid file type",
|
||||||
|
list: ["Please upload a JSON file"],
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -108,14 +117,18 @@ export default function HomePage(): JSX.Element {
|
||||||
onDragLeave={dragLeave}
|
onDragLeave={dragLeave}
|
||||||
onDrop={fileDrop}
|
onDrop={fileDrop}
|
||||||
className={
|
className={
|
||||||
"h-full w-full " + (isDragging
|
"h-full w-full " +
|
||||||
? "flex flex-col items-center justify-center mb-24 gap-4 text-2xl font-light"
|
(isDragging
|
||||||
|
? "mb-24 flex flex-col items-center justify-center gap-4 text-2xl font-light"
|
||||||
: "")
|
: "")
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{isDragging ? (
|
{isDragging ? (
|
||||||
<>
|
<>
|
||||||
<IconComponent name="ArrowUpToLine" className="h-12 w-12 stroke-1" />
|
<IconComponent
|
||||||
|
name="ArrowUpToLine"
|
||||||
|
className="h-12 w-12 stroke-1"
|
||||||
|
/>
|
||||||
Drop your flow here
|
Drop your flow here
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue