fix(genericModal/index.tsx): handle case when field_name is an empty string in GenericModal component

fix(genericModal/index.tsx): handle case when field_name is an empty string in GenericModal component
This commit is contained in:
anovazzi1 2023-09-29 18:22:41 -03:00 • committed by anovazzi1
commit 765db810c7

View file

@ -112,9 +112,12 @@ export default function GenericModal({
// if field_name is an empty string, then we need to set it // if field_name is an empty string, then we need to set it
// to the first key of the custom_fields object // to the first key of the custom_fields object
if (field_name === "") { if (field_name === "") {
field_name = Object.keys( console.log(apiReturn.data?.frontend_node?.custom_fields);
apiReturn.data?.frontend_node?.custom_fields ?? {} field_name = Array.isArray(
)[0]; apiReturn.data?.frontend_node?.custom_fields?.[""]
)
? apiReturn.data?.frontend_node?.custom_fields?.[""][0] ?? ""
: apiReturn.data?.frontend_node?.custom_fields?.[""] ?? "";
} }
if (apiReturn.data) { if (apiReturn.data) {
let inputVariables = apiReturn.data.input_variables ?? []; let inputVariables = apiReturn.data.input_variables ?? [];
@ -131,8 +134,10 @@ export default function GenericModal({
setNodeClass!(apiReturn.data?.frontend_node); setNodeClass!(apiReturn.data?.frontend_node);
setModalOpen(closeModal); setModalOpen(closeModal);
setValue(inputValue); setValue(inputValue);
apiReturn.data.frontend_node["template"][field_name]["value"] = if (field_name !== "") {
inputValue; apiReturn.data.frontend_node["template"][field_name]["value"] =
inputValue;
}
} else { } else {
setIsEdit(false); setIsEdit(false);
setSuccessData({ setSuccessData({
@ -145,8 +150,10 @@ export default function GenericModal({
setNodeClass!(apiReturn.data?.frontend_node); setNodeClass!(apiReturn.data?.frontend_node);
setModalOpen(closeModal); setModalOpen(closeModal);
setValue(inputValue); setValue(inputValue);
apiReturn.data.frontend_node["template"][field_name]["value"] = if (field_name !== "") {
inputValue; apiReturn.data.frontend_node["template"][field_name]["value"] =
inputValue;
}
} }
} else { } else {
setIsEdit(true); setIsEdit(true);