fix: prevent non alphanumeric in pincode

This commit is contained in:
Carlos Valente
2025-01-31 17:17:14 +01:00
committed by Carlos Valente
parent bc12531729
commit 60354f8ea3
2 changed files with 16 additions and 3 deletions
@@ -8,6 +8,7 @@ import { maybeAxiosError } from '../../../../common/api/utils';
import useSettings from '../../../../common/hooks-query/useSettings';
import { preventEscape } from '../../../../common/utils/keyEvent';
import { isOnlyNumbers } from '../../../../common/utils/regex';
import { isOntimeCloud } from '../../../../externals';
import * as Panel from '../../panel-utils/PanelUtils';
import GeneralPinInput from './GeneralPinInput';
@@ -25,6 +26,7 @@ export default function GeneralPanelForm() {
setError,
formState: { isSubmitting, isDirty, isValid, errors },
} = useForm<Settings>({
mode: 'onChange',
defaultValues: data,
values: data,
resetOptions: {
@@ -94,7 +96,11 @@ export default function GeneralPanelForm() {
<Panel.ListItem>
<Panel.Field
title='Ontime server port'
description='Port ontime server listens in. Defaults to 4001 (needs app restart)'
description={
isOntimeCloud
? 'Server port disabled for Ontime Cloud'
: 'Port ontime server listens in. Defaults to 4001 (needs app restart)'
}
error={errors.serverPort?.message}
/>
<Input
@@ -104,6 +110,7 @@ export default function GeneralPanelForm() {
variant='ontime-filled'
maxLength={5}
width='75px'
isDisabled={isOntimeCloud}
{...register('serverPort', {
required: { value: true, message: 'Required field' },
max: { value: 65535, message: 'Port must be within range 1024 - 65535' },
@@ -4,6 +4,8 @@ import { IconButton, Input, InputGroup, InputRightElement } from '@chakra-ui/rea
import { IoEyeOutline } from '@react-icons/all-files/io5/IoEyeOutline';
import { Settings } from 'ontime-types';
import { isAlphanumeric } from '../../../../common/utils/regex';
interface GeneralPinInputProps {
register: UseFormRegister<Settings>;
formName: keyof Settings;
@@ -13,14 +15,18 @@ interface GeneralPinInputProps {
export default function GeneralPinInput(props: PropsWithChildren<GeneralPinInputProps>) {
const { register, formName, isDisabled } = props;
const [isVisible, setVisible] = useState(false);
return (
<InputGroup size='sm' width='100px'>
<Input
variant='ontime-filled'
type={isVisible ? 'text' : 'password'}
maxLength={4}
{...register(formName)}
{...register(formName, {
pattern: {
value: isAlphanumeric,
message: 'Only alphanumeric characters are allowed',
},
})}
placeholder='-'
isDisabled={isDisabled}
/>