Skip to content

Commit

Permalink
fix(disable-save-changes): disable if there is no change in name of i…
Browse files Browse the repository at this point in the history
…mage url
  • Loading branch information
MahtabBukhari committed Jun 7, 2024
1 parent c2eefe5 commit 85bd87f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
12 changes: 5 additions & 7 deletions src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,13 @@ export const Body = () => {
openRemoveNodeModal()
}

const isNodeNameChanged = getValues().name && actualTopicNode?.name !== getValues().name
const name = getValues()?.name?.trim()

const isNodeNameChanged = name && actualTopicNode?.name.trim() !== name
const isImageUrlChanged = getValues().image_url && selectedNode?.image_url !== getValues()?.image_url

const shouldDisableSave =
loading ||
topicIsLoading ||
(!!imageUrl && !isValidImageUrl) ||
(!imageUrl && !isNodeNameChanged) ||
!imageUrl ||
!topicValue
loading || topicIsLoading || (!!imageUrl && !isValidImageUrl) || (!isNodeNameChanged && !isImageUrlChanged)

return (
<Wrapper>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import styled from 'styled-components'
import { imageUrlRegex, validateImageInputType } from '~/components/ModalsContainer/EditNodeNameModal/utils'
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'
Expand Down Expand Up @@ -74,9 +74,6 @@ export const TitleEditor = () => {
message: 'Please enter a valid URL',
value: imageUrlRegex,
},
validate: {
source: validateImageInputType,
},
}}
/>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const imageUrlRegex = /^https:\/\/.*\.(png|jpe?g|svg)$/
export const imageUrlRegex = /^https:\/\/\S+\.(png|jpe?g|svg)$/

export function validateImageInputType(url: string): boolean {
if (imageUrlRegex.test(url)) {
Expand Down

0 comments on commit 85bd87f

Please sign in to comment.