Skip to content

Commit

Permalink
feat: node edition update
Browse files Browse the repository at this point in the history
  • Loading branch information
Rassl committed Jan 10, 2025
1 parent 9c45bb3 commit e3d38f0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
25 changes: 15 additions & 10 deletions src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getTopicsData, putNodeData } from '~/network/fetchSourcesData'
import { useDataStore } from '~/stores/useDataStore'
import { useSelectedNode } from '~/stores/useGraphStore'
import { useModal } from '~/stores/useModalStore'
import { NodeExtended, Topic } from '~/types'
import { NodeExtended, NodeRequest, Topic } from '~/types'
import { colors } from '~/utils/colors'
import { TitleEditor } from '../Title'

Expand Down Expand Up @@ -84,25 +84,30 @@ export const Body = () => {
const node = actualTopicNode || selectedNode

const handleSave = async () => {
if (!node) {
return
}

setLoading(true)

const updatedData = getValues()
const formData: FormData = getValues()

const nodeData = {
node_type: node?.node_type,
node_data: {
name: updatedData.name,
properties: updatedData.properties,
ref_id: updatedData.ref_id,
},
properties: formData.properties,
}

try {
await putNodeData(node?.ref_id || '', nodeData)
const payloadData: NodeRequest = {
node_type: node.node_type,
ref_id: node.ref_id,
properties: nodeData.properties as { [key: string]: unknown },
}

await putNodeData(node?.ref_id || '', payloadData)

const { updateNode } = useDataStore.getState()

updateNode({ ...node, ...nodeData.node_data } as NodeExtended)
updateNode({ ...node, ...nodeData } as unknown as NodeExtended)

closeHandler()
} catch (error) {
Expand Down
10 changes: 4 additions & 6 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,10 @@ export type RadarRequest = {
}

export type NodeRequest = {
node_type?: string
node_data: {
name?: string
is_muted?: boolean
topic?: string
image_url?: string
node_type: string
ref_id: string
properties: {
[key: string]: unknown
}
}

Expand Down

0 comments on commit e3d38f0

Please sign in to comment.