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

[Create Bounty]: Confirm Button Should Disable for Empty Spaces and Only Allow Numbers #2225

Merged
merged 3 commits into from
Sep 26, 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
@@ -1,12 +1,13 @@
import { Button } from '@mui/material'
import { FC } from 'react'
import { useFormContext } from 'react-hook-form'
import styled from 'styled-components'
import { AutoComplete, TAutocompleteOption } from '~/components/common/AutoComplete'
import { Flex } from '~/components/common/Flex'
import { Text } from '~/components/common/Text'
import { useFormContext } from 'react-hook-form'
import { TextInput } from '~/components/common/TextInput'
import { AutoComplete, TAutocompleteOption } from '~/components/common/AutoComplete'
import { requiredRule } from '~/constants'
import { BUDGET_PATTERN, isBudgetValid } from '../constants'

type Props = {
errMessage: string
Expand All @@ -27,7 +28,13 @@ export const CreateBounty: FC<Props> = ({ errMessage, handleClose }) => {

const options = [{ label: 'SecondBrain', value: 'SecondBrain' }]

const isDisable = !!(watchBudget && watchNodeType)
const isDisable = isBudgetValid(watchBudget) && !!watchNodeType

const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
if (event.key === ' ') {
event.preventDefault()
}
}

return (
<Flex>
Expand All @@ -45,11 +52,12 @@ export const CreateBounty: FC<Props> = ({ errMessage, handleClose }) => {
<TextInput
id="budget"
name="budget"
onKeyDown={handleKeyDown}
placeholder="Enter budget"
rules={{
...requiredRule,
pattern: {
value: /^[0-9]+$/,
value: BUDGET_PATTERN,
message: 'Please enter a valid number',
},
}}
Expand Down
7 changes: 7 additions & 0 deletions src/components/ModalsContainer/CreateBountyModal/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const BUDGET_PATTERN = /^[0-9]+$/

export const isBudgetValid = (budget: string): boolean => {
const trimmedBudget = budget.trim()

return !!(trimmedBudget && BUDGET_PATTERN.test(trimmedBudget))
}
Loading