🐛 fix(formModal/index.tsx): handle case when tabsState or formKeysData is undefined to prevent errors

✨ feat(formModal/index.tsx): add support for displaying input keys and handling input changes in the form modal
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-08-07 20:28:41 -03:00
commit 2abc0d2fb4

View file

@ -67,14 +67,17 @@ export default function FormModal({
const id = useRef(flow.id);
const tabsStateFlowId = tabsState[flow.id];
const tabsStateFlowIdFormKeysData = tabsStateFlowId.formKeysData;
const [chatKey, setChatKey] = useState(
Object.keys(tabsState[flow.id].formKeysData.input_keys).find(
const [chatKey, setChatKey] = useState(() => {
if (tabsState[flow.id]?.formKeysData?.input_keys) {
return Object.keys(tabsState[flow.id].formKeysData.input_keys).find(
(k) =>
!tabsState[flow.id].formKeysData.handle_keys.some((j) => j === k) &&
tabsState[flow.id].formKeysData.input_keys[k] === ""
)
);
}
// TODO: return a sensible default
return "";
});
useEffect(() => {
if (messagesRef.current) {
messagesRef.current.scrollTop = messagesRef.current.scrollHeight;
@ -419,8 +422,10 @@ export default function FormModal({
</div>
</div>
{Object.keys(tabsState[id.current].formKeysData.input_keys).map(
(i, k) => (
{tabsState[id.current]?.formKeysData?.input_keys
? Object.keys(
tabsState[id.current].formKeysData.input_keys
).map((i, k) => (
<div className="file-component-accordion-div" key={k}>
<AccordionComponent
trigger={
@ -467,9 +472,9 @@ export default function FormModal({
onChange={(e) => {
setTabsState((old) => {
let newTabsState = _.cloneDeep(old);
newTabsState[id.current].formKeysData.input_keys[
i
] = e.target.value;
newTabsState[
id.current
].formKeysData.input_keys[i] = e.target.value;
return newTabsState;
});
}}
@ -479,8 +484,8 @@ export default function FormModal({
</div>
</AccordionComponent>
</div>
)
)}
))
: null}
{tabsState[id.current].formKeysData.memory_keys.map((i, k) => (
<div className="file-component-accordion-div" key={k}>
<AccordionComponent