diff --git a/src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx b/src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx index d08c2de4f..4f1b898ea 100644 --- a/src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx +++ b/src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx @@ -17,6 +17,7 @@ export type FormData = { name: string image_url: string imageInputType?: boolean + [key: string]: unknown } export const Body = () => { @@ -24,22 +25,20 @@ export const Body = () => { const form = useForm({ mode: 'onChange' }) const { watch, setValue, reset, getValues } = form const [loading, setLoading] = useState(false) - const [topicIsLoading, setTopicIsLoading] = useState(false) - const [actualTopicNode, setActualTopicNode] = useState() - const selectedNode = useSelectedNode() - const { open: openRemoveNodeModal } = useModal('removeNode') useEffect(() => { if (actualTopicNode) { - setValue('name', actualTopicNode?.name) + Object.keys(actualTopicNode).forEach((key) => { + setValue(key, actualTopicNode[key as keyof Topic]) + }) } else if (selectedNode) { - setValue('name', selectedNode.name) - - setValue('image_url', selectedNode?.image_url ?? '') + Object.keys(selectedNode).forEach((key) => { + setValue(key, selectedNode[key as keyof NodeExtended]) + }) } return () => { @@ -72,9 +71,6 @@ export const Body = () => { }, [selectedNode]) const isValidImageUrl = watch('imageInputType') - - const topicValue = watch('name') - const imageUrl = watch('image_url') useEffect(() => { @@ -90,8 +86,7 @@ export const Body = () => { const handleSave = async () => { setLoading(true) - const propName = 'name' - const updatedData = { [propName]: topicValue.trim(), image_url: imageUrl.trim() } + const updatedData = getValues() try { await putNodeData(node?.ref_id || '', { node_data: updatedData }) @@ -130,23 +125,21 @@ export const Body = () => { ) : ( )} - + Delete - + @@ -170,6 +163,8 @@ const DeleteButton = styled(Button)` && { color: ${colors.primaryRed}; background-color: rgba(237, 116, 116, 0.1); + flex: 1; + margin-right: 10px; &:hover, &:active, @@ -180,6 +175,12 @@ const DeleteButton = styled(Button)` } ` +const SaveButton = styled(Button)` + && { + flex: 1; + } +` + const ClipLoaderWrapper = styled.span` margin-top: 3px; ` diff --git a/src/components/ModalsContainer/EditNodeNameModal/Title/index.tsx b/src/components/ModalsContainer/EditNodeNameModal/Title/index.tsx index d3d882358..75c704a69 100644 --- a/src/components/ModalsContainer/EditNodeNameModal/Title/index.tsx +++ b/src/components/ModalsContainer/EditNodeNameModal/Title/index.tsx @@ -1,6 +1,6 @@ +import { useEffect, useState } from 'react' import styled from 'styled-components' import EditNodeIcon from '~/components/Icons/EditNodeIcon' -import { imageUrlRegex } from '~/components/ModalsContainer/EditNodeNameModal/utils' import { Flex } from '~/components/common/Flex' import { Text } from '~/components/common/Text' import { TextInput } from '~/components/common/TextInput' @@ -22,11 +22,26 @@ export const TitleEditor = () => { const selectedNode = useSelectedNode() const nodeType = selectedNode?.node_type as string + const [properties, setProperties] = useState<{ [key: string]: unknown }>({}) + + useEffect(() => { + if (selectedNode?.properties) { + setProperties(selectedNode.properties) + } + }, [selectedNode]) + const handleEditNode = () => { close() openAddItemNodeModal() } + const handleChange = (key: string, value: string) => { + setProperties((prev) => ({ + ...prev, + [key]: value, + })) + } + return ( @@ -43,46 +58,27 @@ export const TitleEditor = () => { - - - Node Name - - - - - - - Image Url - - - + + {Object.keys(properties).map((key) => ( + + + {key} + + handleChange(key, value)} + placeholder={`Please Enter the ${key}`} + rules={key === 'name' ? { ...requiredRule } : {}} + /> + + ))} + ) } @@ -113,3 +109,11 @@ const EditIconWrapper = styled(Flex)` align-items: center; cursor: pointer; ` + +const ScrollableContent = styled(Flex)` + display: flex; + max-height: 60vh; + overflow-y: auto; + padding-right: 40px; + width: calc(100% + 40px); +`