Skip to content

Commit

Permalink
Merge pull request #1603 from MahtabBukhari/Save_Changes_button_at_Ed…
Browse files Browse the repository at this point in the history
…it_Node_Modal_should_be_enable

'Save Changes' button at edit node modal should be enable only if there is change in name OR image_url and Space in URL should not be allow
  • Loading branch information
Rassl authored Jun 11, 2024
2 parents 06a701a + 85bd87f commit 5cddf67
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
17 changes: 14 additions & 3 deletions src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +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)
loading || topicIsLoading || (!!imageUrl && !isValidImageUrl) || (!isNodeNameChanged && !isImageUrlChanged)

return (
<Wrapper>
Expand Down Expand Up @@ -146,7 +149,11 @@ export const Body = () => {
variant="contained"
>
Save Changes
{loading && <ClipLoader color={colors.BLUE_PRESS_STATE} size={10} />}
{loading && (
<ClipLoaderWrapper>
<ClipLoader color={colors.lightGray} size={12} />
</ClipLoaderWrapper>
)}
</Button>
</Flex>
</FormProvider>
Expand All @@ -171,3 +178,7 @@ const DeleteButton = styled(Button)`
}
}
`

const ClipLoaderWrapper = styled.span`
margin-top: 3px;
`
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 5cddf67

Please sign in to comment.