chat nodes validation done
This commit is contained in:
parent
cf79a6ee76
commit
0fa6d8346c
1 changed files with 20 additions and 8 deletions
|
|
@ -31,6 +31,13 @@ export default function Chat({ reactFlowInstance }) {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
function validateChatNodes(){
|
||||||
|
console.log(reactFlowInstance.getNodes());
|
||||||
|
if(!reactFlowInstance.getNodes().some((n)=> (n.type === 'chatOutputNode')) || !reactFlowInstance.getNodes().some((n)=> (n.type === 'chatInputNode'))){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
const ref = useRef(null);
|
const ref = useRef(null);
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
@ -95,14 +102,19 @@ export default function Chat({ reactFlowInstance }) {
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if(chatValue !== ""){
|
if(chatValue !== ""){
|
||||||
if(validateNodes()){
|
if(validateNodes()){
|
||||||
let message = chatValue;
|
if(validateChatNodes()){
|
||||||
setChatValue("");
|
let message = chatValue;
|
||||||
addChatHistory(message, true);
|
setChatValue("");
|
||||||
sendAll({
|
addChatHistory(message, true);
|
||||||
message,
|
sendAll({
|
||||||
nodes: JSON.stringify(reactFlowInstance.getNodes()),
|
message,
|
||||||
edges: JSON.stringify(reactFlowInstance.getEdges()),
|
nodes: JSON.stringify(reactFlowInstance.getNodes()),
|
||||||
}).then((r) => {addChatHistory(r.data.messsage, false);});
|
edges: JSON.stringify(reactFlowInstance.getEdges()),
|
||||||
|
}).then((r) => {addChatHistory(r.data.messsage, false);});
|
||||||
|
} else {
|
||||||
|
setErrorData({title: 'Error sending message', list:['Chat nodes are missing.']})
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
setErrorData({title: 'Error sending message', list:['There are required fields not filled yet.']})
|
setErrorData({title: 'Error sending message', list:['There are required fields not filled yet.']})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue