Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update regex checker for images with .jpeg extension and made image_url optional when editing a node #1291

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

setActualTopicNode(node)
} catch (error) {
console.log(error)

Check warning on line 64 in src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run

Unexpected console statement

Check warning on line 64 in src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx

View workflow job for this annotation

GitHub Actions / craco-build-run

Unexpected console statement

Check warning on line 64 in src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx

View workflow job for this annotation

GitHub Actions / eslint-run

Unexpected console statement
} finally {
setTopicIsLoading(false)
}
Expand Down Expand Up @@ -108,6 +108,9 @@

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

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

return (
<Wrapper>
<FormProvider {...form}>
Expand All @@ -116,7 +119,7 @@
<Skeleton />
</Flex>
) : (
<TitleEditor isValidImageUrl={isValidImageUrl} />
<TitleEditor />
)}
<Flex direction="row" mb={6}>
<DeleteButton
Expand All @@ -131,7 +134,7 @@
</DeleteButton>
<Button
color="secondary"
disabled={loading || topicIsLoading || !isNodeNameChanged || !isValidImageUrl}
disabled={shouldDisableSave}
onClick={handleSave}
size="large"
style={{ flex: 1 }}
Expand Down
26 changes: 8 additions & 18 deletions src/components/ModalsContainer/EditNodeNameModal/Title/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { FC } from 'react'
import styled from 'styled-components'
import { imageUrlRegex, validateImageInputType } from '~/components/ModalsContainer/EditNodeNameModal/utils'
import { Flex } from '~/components/common/Flex'
Expand All @@ -7,11 +6,7 @@ import { TextInput } from '~/components/common/TextInput'
import { requiredRule } from '~/constants'
import { colors } from '~/utils'

type Props = {
isValidImageUrl?: boolean
}

export const TitleEditor: FC<Props> = ({ isValidImageUrl }) => (
export const TitleEditor = () => (
<Flex>
<Flex align="center" direction="row" justify="space-between" mb={18}>
<Flex align="center" direction="row">
Expand Down Expand Up @@ -52,18 +47,13 @@ export const TitleEditor: FC<Props> = ({ isValidImageUrl }) => (
name="image_url"
placeholder="image_url"
rules={{
...requiredRule,
...(!isValidImageUrl
? {
pattern: {
message: 'Please enter a valid URL',
value: imageUrlRegex,
},
validate: {
source: validateImageInputType,
},
}
: {}),
pattern: {
message: 'Please enter a valid URL',
value: imageUrlRegex,
},
validate: {
source: validateImageInputType,
},
}}
/>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ describe('validateImageInputType function', () => {
true,
)

expect(
validateImageInputType('https://pbs.twimg.com/profile_images/1729542498006294529/AjwhArl6_normal.jpeg'),
).toBe(true)

expect(validateImageInputType('https://pbs.twimg.com/profile_images/1729542498006294529/AjwhArl6_normal.svg')).toBe(
true,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const imageUrlRegex = /^https:\/\/.*\.(png|jpg|svg)$/
export const imageUrlRegex = /^https:\/\/.*\.(png|jpe?g|svg)$/

export function validateImageInputType(url: string): boolean {
if (imageUrlRegex.test(url)) {
Expand Down
4 changes: 3 additions & 1 deletion src/components/common/TextInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ export const TextInput = ({
register,
control,
formState: { errors },
getValues,
} = useFormContext() || {}

const error = get(errors, name)
const feildValue = getValues(name)

useEffect(() => {
const inputElement = document.getElementById(id)
Expand Down Expand Up @@ -118,7 +120,7 @@ export const TextInput = ({
/>
</Wrapper>

{error && (
{feildValue && error && (
<Flex pl={4} pt={8} shrink={1} tabIndex={0}>
<Text color="primaryRed" kind="regularBold">
<Flex align="center" direction="row" shrink={1}>
Expand Down
Loading