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
+41 -40
View File
@@ -46,7 +46,8 @@ import { v4 as uuidv4 } from "uuid";
import { Link, useParams } from "react-router-dom";
import YAML from "yaml";
import { MuiChipsInput } from "mui-chips-input";
import { useAlert } from "react-alert";
//import { useAlert
import { ToastContainer, toast } from "react-toastify"
import words from "shellwords";
import AvatarEditor from "react-avatar-editor";
@@ -350,7 +351,7 @@ const getJsonObject = (properties) => {
const AppCreator = (defaultprops) => {
const { globalUrl, isLoaded } = defaultprops;
const classes = useStyles();
const alert = useAlert();
//const alert = useAlert();
const params = useParams();
var props = JSON.parse(JSON.stringify(defaultprops))
@@ -451,7 +452,7 @@ const AppCreator = (defaultprops) => {
})
.then((responseJson) => {
if (responseJson.success === false) {
alert.error("Failed to get the app");
toast("Failed to get the app");
setIsAppLoaded(true);
window.location.pathname = "/search";
} else {
@@ -459,7 +460,7 @@ const AppCreator = (defaultprops) => {
}
})
.catch((error) => {
alert.error(error.toString());
toast(error.toString());
});
};
@@ -494,14 +495,14 @@ const AppCreator = (defaultprops) => {
.then((responseJson) => {
setIsAppLoaded(true);
if (!responseJson.success) {
alert.error("Failed to get app config. Do you have access?");
toast("Failed to get app config. Do you have access?");
} else {
parseIncomingOpenapiData(responseJson);
}
})
.catch((error) => {
console.log("Error: ", error.toString());
alert.error(error.toString());
toast(error.toString());
});
};
@@ -568,7 +569,7 @@ const AppCreator = (defaultprops) => {
}
if (data.openapi === null) {
alert.info("Failed to load OpenAPI for app. Please contact support if this persists.")
toast("Failed to load OpenAPI for app. Please contact support if this persists.")
setIsAppLoaded(true);
return
}
@@ -600,7 +601,7 @@ const AppCreator = (defaultprops) => {
}
if (!jsonvalid) {
alert.info("OpenAPI data is invalid.");
toast("OpenAPI data is invalid.");
return;
}
@@ -726,7 +727,7 @@ const AppCreator = (defaultprops) => {
for (let [method, methodvalue] of Object.entries(pathvalue)) {
if (methodvalue === null) {
alert.info("Skipped method (null)" + method);
toast("Skipped method (null)" + method);
continue;
}
@@ -734,7 +735,7 @@ const AppCreator = (defaultprops) => {
// Typical YAML issue
if (method !== "parameters") {
console.log("Invalid method: ", method, "data: ", methodvalue);
//alert.info("Skipped method (not allowed): " + method);
//toast("Skipped method (not allowed): " + method);
}
continue;
}
@@ -1596,7 +1597,7 @@ const AppCreator = (defaultprops) => {
setParameterLocation(value.in);
if (!apikeySelection.includes(value.in)) {
console.log("APIKEY SELECT: ", apikeySelection);
alert.error("Might be error in setting up API key authentication");
toast("Might be error in setting up API key authentication");
}
console.log("PARAM NAME: ", value.name);
@@ -1637,7 +1638,7 @@ const AppCreator = (defaultprops) => {
optionset = true
} else if (value.type === "oauth2" || key === "Oauth2" || key === "Oauth2c" || (key !== undefined && key !== null && key.toLowerCase().includes("oauth2"))) {
//alert.info("Can't handle Oauth2 auth yet.")
//toast("Can't handle Oauth2 auth yet.")
setAuthenticationOption("Oauth2");
setAuthenticationRequired(true);
optionset = true
@@ -1686,7 +1687,7 @@ const AppCreator = (defaultprops) => {
const scopekeysplit = scopekey.split("/");
if (scopekeysplit.length < 5) {
console.log("Skipping scope: ", scopekey);
alert.info("Skipping scope: " + scopekey);
toast("Skipping scope: " + scopekey);
continue;
}
@@ -1707,7 +1708,7 @@ const AppCreator = (defaultprops) => {
);
}
} else {
alert.error("Couldn't handle AUTH type: ", key);
toast("Couldn't handle AUTH type: ", key);
//newauth.push({
// "name": key,
// "type": value.in,
@@ -1716,7 +1717,7 @@ const AppCreator = (defaultprops) => {
}
}
} catch (e) {
alert.error("Failed to handle auth")
toast("Failed to handle auth")
console.log("Error: ", e)
}
@@ -1790,7 +1791,7 @@ const AppCreator = (defaultprops) => {
//const isCloud = window.location.host === "localhost:3002" || window.location.host === "shuffler.io"
if (newActions.length > 1000 && isCloud) {
alert.error("Cut down actions from " + newActions.length + " to 999 because of limit");
toast("Cut down actions from " + newActions.length + " to 999 because of limit");
newActions = newActions.slice(0, 999);
}
@@ -1812,7 +1813,7 @@ const AppCreator = (defaultprops) => {
// Saving the app that's been configured.
// Save SAVE app
const submitApp = () => {
alert.info("Uploading and building app " + name);
toast("Uploading and building app " + name);
setAppBuilding(true);
setErrorCode("");
@@ -1881,7 +1882,7 @@ const AppCreator = (defaultprops) => {
for (let actionkey in actions) {
var item = JSON.parse(JSON.stringify(actions[actionkey]))
if (item.errors.length > 0) {
alert.error("Saving with error in action " + item.name);
toast("Saving with error in action " + item.name);
}
if (item.name === undefined && item.description !== undefined) {
@@ -2107,7 +2108,7 @@ const AppCreator = (defaultprops) => {
// Bad code as it doesn't allow for "anything".
if (skipped) {
alert.info(
toast(
"Bad configuration of " +
item.name +
". Skipping because queries are invalid."
@@ -2358,7 +2359,7 @@ const AppCreator = (defaultprops) => {
if (authenticationOption === "API key") {
if (parameterName.length === 0) {
alert.error("A field name for the APIkey must be defined");
toast("A field name for the APIkey must be defined");
setAppBuilding(false);
return;
}
@@ -2424,7 +2425,7 @@ const AppCreator = (defaultprops) => {
const curauth = extraAuth[authkey];
if (curauth.name.toLowerCase() == "url") {
alert.error("Can't add extra auth with Name URL");
toast("Can't add extra auth with Name URL");
setAppBuilding(false);
return;
}
@@ -2459,10 +2460,10 @@ const AppCreator = (defaultprops) => {
if (!responseJson.success) {
if (responseJson.reason !== undefined) {
setErrorCode(responseJson.reason);
alert.error("Failed to verify: " + responseJson.reason);
toast("Failed to verify: " + responseJson.reason);
}
} else {
alert.success("Successfully uploaded openapi");
toast("Successfully uploaded openapi");
if (window.location.pathname.includes("/new")) {
if (responseJson.id !== undefined && responseJson.id !== null) {
window.location = `/apps/edit/${responseJson.id}`;
@@ -2473,7 +2474,7 @@ const AppCreator = (defaultprops) => {
.catch((error) => {
setAppBuilding(false);
setErrorCode(error.toString());
alert.error(error.toString());
toast(error.toString());
});
};
@@ -2805,7 +2806,7 @@ const AppCreator = (defaultprops) => {
!tmpstring.startsWith("http") &&
!tmpstring.startsWith("ftp")
) {
alert.error("Auth URL must start with http(s)://");
toast("Auth URL must start with http(s)://");
}
if (tmpstring.includes("?")) {
@@ -2854,7 +2855,7 @@ const AppCreator = (defaultprops) => {
!tmpstring.startsWith("http") &&
!tmpstring.startsWith("ftp")
) {
alert.error("Token URL must start with http(s)://");
toast("Token URL must start with http(s)://");
}
if (tmpstring.includes("?")) {
@@ -2900,7 +2901,7 @@ const AppCreator = (defaultprops) => {
!tmpstring.startsWith("http") &&
!tmpstring.startsWith("ftp")
) {
alert.error("Refresh URL must start with http(s)://");
toast("Refresh URL must start with http(s)://");
}
if (tmpstring.includes("?")) {
@@ -3791,7 +3792,7 @@ const AppCreator = (defaultprops) => {
value = keysplit[1].trim()
} else {
alert.error("Removed key: ", key)
toast("Removed key: ", key)
continue
}
}
@@ -4626,11 +4627,11 @@ const AppCreator = (defaultprops) => {
setSelectedAction(selectedAction);
}
//alert.error("Failed getting authentications")
//toast("Failed getting authentications")
}
})
.catch((error) => {
alert.error("Auth loading error: " + error.toString());
toast("Auth loading error: " + error.toString());
});
};
@@ -4686,17 +4687,17 @@ const AppCreator = (defaultprops) => {
})
.then((responseJson) => {
if (!responseJson.success) {
alert.error("Failed to set app auth: " + responseJson.reason);
toast("Failed to set app auth: " + responseJson.reason);
} else {
getAppAuthentication(true);
setAuthenticationModalOpen(false);
// Needs a refresh with the new authentication..
//alert.success("Successfully saved new app auth")
//toast("Successfully saved new app auth")
}
})
.catch((error) => {
alert.error(error.toString());
toast(error.toString());
});
};
@@ -4747,7 +4748,7 @@ const AppCreator = (defaultprops) => {
console.log("NEW AUTH: ", authenticationOption);
if (authenticationOption.label.length === 0) {
authenticationOption.label = `Auth for ${selectedApp.name}`;
//alert.info("Label can't be empty")
//toast("Label can't be empty")
//return
}
@@ -4757,7 +4758,7 @@ const AppCreator = (defaultprops) => {
selectedApp.authentication.parameters[key].name
].length === 0
) {
alert.info(
toast(
"Field " +
selectedApp.authentication.parameters[key].name +
" can't be empty"
@@ -5165,7 +5166,7 @@ const AppCreator = (defaultprops) => {
setFileBase64(canvasUrl);
}
} catch (e) {
alert.error("Failed to parse canvasurl!");
toast("Failed to parse canvasurl!");
}
};
@@ -5253,7 +5254,7 @@ const AppCreator = (defaultprops) => {
setOpenImageModal(false);
setDisableImageUpload(true);
} catch (e) {
alert.error("Failed to set image. Replace it if this persists.");
toast("Failed to set image. Replace it if this persists.");
}
}
};
@@ -5468,7 +5469,7 @@ const AppCreator = (defaultprops) => {
const invalid = ["#", ":", "."];
for (var key in invalid) {
if (e.target.value.includes(invalid[key])) {
alert.error("Can't use " + invalid[key] + " in name");
toast("Can't use " + invalid[key] + " in name");
setName(e.target.value.replaceAll(".", "").replaceAll("#", "").replaceAll(":", "").replaceAll(",", ""))
return;
@@ -5476,7 +5477,7 @@ const AppCreator = (defaultprops) => {
}
if (e.target.value.length > 29) {
alert.error("Choose a shorter name (max 29).");
toast("Choose a shorter name (max 29).");
setName(e.target.value.slice(0,28))
return;
}
@@ -5588,7 +5589,7 @@ const AppCreator = (defaultprops) => {
!tmpstring.startsWith("http") &&
!tmpstring.startsWith("ftp")
) {
alert.error("URL must start with http(s)://");
toast("URL must start with http(s)://");
}
if (tmpstring.includes("?")) {