diff --git a/src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx b/src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx index e18d257a7..57142a4df 100644 --- a/src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx +++ b/src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx @@ -86,13 +86,13 @@ export const Body = () => { const handleSave = async () => { setLoading(true) - const formData = getValues() + const updatedData = getValues() const nodeData = { node_type: node?.node_type, properties: { - name: formData.name?.trim(), - ...(formData.image_url && { image_url: formData.image_url }), + name: updatedData.name, + ...(updatedData.image_url && { image_url: updatedData.image_url }), }, ref_id: node?.ref_id, } @@ -104,8 +104,8 @@ export const Body = () => { updateNode({ ...node, - name: formData.name?.trim(), - ...(formData.image_url && { image_url: formData.image_url }), + name: updatedData.name, + ...(updatedData.image_url && { image_url: updatedData.image_url }), } as NodeExtended) closeHandler() diff --git a/src/stores/useDataStore/index.ts b/src/stores/useDataStore/index.ts index 55ba74f05..27bdd7023 100644 --- a/src/stores/useDataStore/index.ts +++ b/src/stores/useDataStore/index.ts @@ -370,25 +370,14 @@ export const useDataStore = create<DataStore>()( setSources: (sources) => set({ sources }), setHideNodeDetails: (hideNodeDetails) => set({ hideNodeDetails }), setSeedQuestions: (questions) => set({ seedQuestions: questions }), - updateNode: (updatedNode: NodeExtended) => { - set((state) => { - if (!updatedNode.ref_id) { - return state - } - - const existingNode = state.nodesNormalized.get(updatedNode.ref_id) + updateNode: (updatedNode) => { + const { nodesNormalized } = get() - if (!existingNode) { - return state - } + const newNodesNormalized = new Map(nodesNormalized) - state.nodesNormalized.set(updatedNode.ref_id, { - ...existingNode, - ...updatedNode, - }) + newNodesNormalized.set(updatedNode.ref_id, updatedNode) - return state - }) + set({ nodesNormalized: newNodesNormalized }) }, removeNode: (id) => {