diff --git a/client/components/Parts/Dialogs/Input.tsx b/client/components/Parts/Dialogs/Input.tsx index 6d0b58ce..cd0e7b08 100644 --- a/client/components/Parts/Dialogs/Input.tsx +++ b/client/components/Parts/Dialogs/Input.tsx @@ -2,6 +2,7 @@ import * as React from 'react' import InputAdornment from '@mui/material/InputAdornment' import TextField from '@mui/material/TextField' import ConfirmDialog, { ConfirmDialogProps } from './Confirm' +import * as helpers from '../../../helpers' export interface InputDialogProps extends Omit { value?: string @@ -14,10 +15,23 @@ export interface InputDialogProps extends Omit export default function InputDialog(props: InputDialogProps) { const { value: initValue, prefix, placholder, spellcheck, onConfirm, ...rest } = props const [value, setValue] = React.useState(initValue || '') - const handleConfirm = () => onConfirm && onConfirm(value) + const [textFieldError, setTextFieldError] = React.useState(false) + const [errorHelperText, setErrorHelperText] = React.useState('') + const handleConfirm = () => { + if(value !== '' && helpers.isUrlValid(value)){ + setTextFieldError(false) + return onConfirm && onConfirm(value) + } else { + setTextFieldError(true) + if(value === '') { setErrorHelperText('Enter an URL') } + else if(!helpers.isUrlValid(value)) { setErrorHelperText('Enter a valid URL') } + } + } return (