Changed from Alert to Toast to work well with mui v18

This commit is contained in:
Frikky
2023-08-17 03:16:43 +02:00
parent 1461d6ad6b
commit 99d1a96c63
36 changed files with 553 additions and 542 deletions
+39 -38
View File
@@ -66,7 +66,8 @@ import { DataGrid, GridToolbar } from "@mui/x-data-grid";
import Dropzone from "../components/Dropzone.jsx";
import { useNavigate, Link, useParams } from "react-router-dom";
import { useAlert } from "react-alert";
//import { useAlert
import { ToastContainer, toast } from "react-toastify"
import { MuiChipsInput } from "mui-chips-input";
import { v4 as uuidv4 } from "uuid";
@@ -123,7 +124,7 @@ const GettingStarted = (props) => {
const { globalUrl, isLoggedIn, isLoaded, userdata } = props;
document.title = "Getting Started with Shuffle";
const alert = useAlert();
//const alert = useAlert();
const classes = useStyles(theme);
let navigate = useNavigate();
const imgSize = 60;
@@ -442,7 +443,7 @@ const GettingStarted = (props) => {
const files = isDropzone ? e.dataTransfer.files : e.target.files;
const reader = new FileReader();
alert.info("Starting upload. Please wait while we validate the workflows");
toast("Starting upload. Please wait while we validate the workflows");
try {
reader.addEventListener("load", (e) => {
@@ -451,7 +452,7 @@ const GettingStarted = (props) => {
try {
data = JSON.parse(reader.result);
} catch (e) {
alert.error("Invalid JSON: " + e);
toast("Invalid JSON: " + e);
return;
}
@@ -479,13 +480,13 @@ const GettingStarted = (props) => {
false
).then((response) => {
if (response !== undefined) {
alert.success(`Successfully imported ${data.name}`);
toast(`Successfully imported ${data.name}`);
}
});
}
})
.catch((error) => {
alert.error("Import error: " + error.toString());
toast("Import error: " + error.toString());
});
});
} catch (e) {
@@ -518,7 +519,7 @@ const GettingStarted = (props) => {
window.location.pathname = "/login";
}
alert.info("Failed getting workflows.");
toast("Failed getting workflows.");
setWorkflowDone(true);
return;
@@ -559,7 +560,7 @@ const GettingStarted = (props) => {
}, 100)
} else {
if (isLoggedIn) {
alert.error("An error occurred while loading workflows");
toast("An error occurred while loading workflows");
}
return;
@@ -568,7 +569,7 @@ const GettingStarted = (props) => {
.catch((error) => {
setVideoViewOpen(true)
alert.error(error.toString());
toast(error.toString());
});
};
@@ -685,7 +686,7 @@ const GettingStarted = (props) => {
trigger.parameters[1].value = "webhook_" + trigger.id;
// FIXME: Add auth here?
} else {
alert.info("Something is wrong with the webhook in the copy");
toast("Something is wrong with the webhook in the copy");
}
}
@@ -803,7 +804,7 @@ const GettingStarted = (props) => {
data = sanitizeWorkflow(data);
if (data.subflows !== null && data.subflows !== undefined) {
alert.info(
toast(
"Not exporting with subflows when sanitizing. Please manually export them."
);
data.subflows = [];
@@ -830,7 +831,7 @@ const GettingStarted = (props) => {
const publishWorkflow = (data) => {
data = JSON.parse(JSON.stringify(data));
data = sanitizeWorkflow(data);
alert.info("Sanitizing and publishing " + data.name);
toast("Sanitizing and publishing " + data.name);
// This ALWAYS talks to Shuffle cloud
fetch(globalUrl + "/api/v1/workflows/" + data.id + "/publish", {
@@ -847,9 +848,9 @@ const GettingStarted = (props) => {
console.log("Status not 200 for workflow publish :O!");
} else {
if (isCloud) {
alert.success("Successfully published workflow");
toast("Successfully published workflow");
} else {
alert.success(
toast(
"Successfully published workflow to https://shuffler.io"
);
}
@@ -859,19 +860,19 @@ const GettingStarted = (props) => {
})
.then((responseJson) => {
if (responseJson.reason !== undefined) {
alert.error("Failed publishing: ", responseJson.reason);
toast("Failed publishing: ", responseJson.reason);
}
getAvailableWorkflows();
})
.catch((error) => {
alert.error(error.toString());
toast(error.toString());
});
};
const copyWorkflow = (data) => {
data = JSON.parse(JSON.stringify(data));
alert.success("Copying workflow " + data.name);
toast("Copying workflow " + data.name);
data.id = "";
data.name = data.name + "_copy";
data = deduplicateIds(data);
@@ -898,7 +899,7 @@ const GettingStarted = (props) => {
}, 1000);
})
.catch((error) => {
alert.error(error.toString());
toast(error.toString());
});
};
@@ -914,9 +915,9 @@ const GettingStarted = (props) => {
.then((response) => {
if (response.status !== 200) {
console.log("Status not 200 for setting workflows :O!");
alert.error("Failed deleting workflow. Do you have access?");
toast("Failed deleting workflow. Do you have access?");
} else {
alert.success("Deleted workflow " + id);
toast("Deleted workflow " + id);
}
return response.json();
@@ -927,7 +928,7 @@ const GettingStarted = (props) => {
}, 1000);
})
.catch((error) => {
alert.error(error.toString());
toast(error.toString());
});
};
@@ -1272,7 +1273,7 @@ const GettingStarted = (props) => {
}}
onClick={() => {
if (subflows === 0) {
alert.info("No subflows for " + data.name);
toast("No subflows for " + data.name);
return;
}
@@ -1434,9 +1435,9 @@ const GettingStarted = (props) => {
.then((responseJson) => {
if (responseJson.success === false) {
if (responseJson.reason !== undefined) {
alert.error("Error setting workflow: ", responseJson.reason)
toast("Error setting workflow: ", responseJson.reason)
} else {
alert.error("Error setting workflow.")
toast("Error setting workflow.")
}
return
@@ -1453,14 +1454,14 @@ const GettingStarted = (props) => {
setImportLoading(false);
setModalOpen(false);
} else {
alert.info("Successfully changed basic info for workflow");
toast("Successfully changed basic info for workflow");
setModalOpen(false);
}
return responseJson;
})
.catch((error) => {
alert.error(error.toString());
toast(error.toString());
setImportLoading(false);
setModalOpen(false);
setSubmitLoading(false);
@@ -1476,7 +1477,7 @@ const GettingStarted = (props) => {
const file = event.target.files[key];
if (file.type !== "application/json") {
if (file.type !== undefined) {
alert.error("File has to contain valid json");
toast("File has to contain valid json");
setImportLoading(false);
}
@@ -1490,7 +1491,7 @@ const GettingStarted = (props) => {
try {
data = JSON.parse(reader.result);
} catch (e) {
alert.error("Invalid JSON: " + e);
toast("Invalid JSON: " + e);
setImportLoading(false);
return;
}
@@ -1522,13 +1523,13 @@ const GettingStarted = (props) => {
false
).then((response) => {
if (response !== undefined) {
alert.success("Successfully imported " + data.name);
toast("Successfully imported " + data.name);
}
});
}
})
.catch((error) => {
alert.error("Import error: " + error.toString());
toast("Import error: " + error.toString());
});
});
@@ -1727,7 +1728,7 @@ const GettingStarted = (props) => {
}}
onClick={() => {
if (subflows === 0) {
alert.info("No subflows for " + data.name);
toast("No subflows for " + data.name);
return;
}
@@ -2168,7 +2169,7 @@ const GettingStarted = (props) => {
})
return
} else {
alert.success("TBD: Coming in version 1.0.0");
toast("TBD: Coming in version 1.0.0");
}
const ele = document.getElementById("shuffle_search_field")
@@ -2179,7 +2180,7 @@ const GettingStarted = (props) => {
ele.style.borderWidth = "2px"
} else {
//alert.success("TBD: Coming in version 1.0.0");
//toast("TBD: Coming in version 1.0.0");
}
}}>
workflows made by other creators</span>!
@@ -2599,7 +2600,7 @@ const GettingStarted = (props) => {
parsedData["field_2"] = field2;
}
alert.success("Getting specific workflows from your URL.");
toast("Getting specific workflows from your URL.");
fetch(globalUrl + "/api/v1/workflows/download_remote", {
method: "POST",
mode: "cors",
@@ -2611,7 +2612,7 @@ const GettingStarted = (props) => {
})
.then((response) => {
if (response.status === 200) {
alert.success("Successfully loaded workflows from " + downloadUrl);
toast("Successfully loaded workflows from " + downloadUrl);
setTimeout(() => {
getAvailableWorkflows();
}, 1000);
@@ -2622,14 +2623,14 @@ const GettingStarted = (props) => {
.then((responseJson) => {
if (!responseJson.success) {
if (responseJson.reason !== undefined) {
alert.error("Failed loading: " + responseJson.reason);
toast("Failed loading: " + responseJson.reason);
} else {
alert.error("Failed loading");
toast("Failed loading");
}
}
})
.catch((error) => {
alert.error(error.toString());
toast(error.toString());
});
};