mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-20 14:39:06 +00:00
fix: prevent non alphanumeric in pincode
This commit is contained in:
committed by
Carlos Valente
parent
bc12531729
commit
60354f8ea3
@@ -8,6 +8,7 @@ import { maybeAxiosError } from '../../../../common/api/utils';
|
|||||||
import useSettings from '../../../../common/hooks-query/useSettings';
|
import useSettings from '../../../../common/hooks-query/useSettings';
|
||||||
import { preventEscape } from '../../../../common/utils/keyEvent';
|
import { preventEscape } from '../../../../common/utils/keyEvent';
|
||||||
import { isOnlyNumbers } from '../../../../common/utils/regex';
|
import { isOnlyNumbers } from '../../../../common/utils/regex';
|
||||||
|
import { isOntimeCloud } from '../../../../externals';
|
||||||
import * as Panel from '../../panel-utils/PanelUtils';
|
import * as Panel from '../../panel-utils/PanelUtils';
|
||||||
|
|
||||||
import GeneralPinInput from './GeneralPinInput';
|
import GeneralPinInput from './GeneralPinInput';
|
||||||
@@ -25,6 +26,7 @@ export default function GeneralPanelForm() {
|
|||||||
setError,
|
setError,
|
||||||
formState: { isSubmitting, isDirty, isValid, errors },
|
formState: { isSubmitting, isDirty, isValid, errors },
|
||||||
} = useForm<Settings>({
|
} = useForm<Settings>({
|
||||||
|
mode: 'onChange',
|
||||||
defaultValues: data,
|
defaultValues: data,
|
||||||
values: data,
|
values: data,
|
||||||
resetOptions: {
|
resetOptions: {
|
||||||
@@ -94,7 +96,11 @@ export default function GeneralPanelForm() {
|
|||||||
<Panel.ListItem>
|
<Panel.ListItem>
|
||||||
<Panel.Field
|
<Panel.Field
|
||||||
title='Ontime server port'
|
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}
|
error={errors.serverPort?.message}
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
@@ -104,6 +110,7 @@ export default function GeneralPanelForm() {
|
|||||||
variant='ontime-filled'
|
variant='ontime-filled'
|
||||||
maxLength={5}
|
maxLength={5}
|
||||||
width='75px'
|
width='75px'
|
||||||
|
isDisabled={isOntimeCloud}
|
||||||
{...register('serverPort', {
|
{...register('serverPort', {
|
||||||
required: { value: true, message: 'Required field' },
|
required: { value: true, message: 'Required field' },
|
||||||
max: { value: 65535, message: 'Port must be within range 1024 - 65535' },
|
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 { IoEyeOutline } from '@react-icons/all-files/io5/IoEyeOutline';
|
||||||
import { Settings } from 'ontime-types';
|
import { Settings } from 'ontime-types';
|
||||||
|
|
||||||
|
import { isAlphanumeric } from '../../../../common/utils/regex';
|
||||||
|
|
||||||
interface GeneralPinInputProps {
|
interface GeneralPinInputProps {
|
||||||
register: UseFormRegister<Settings>;
|
register: UseFormRegister<Settings>;
|
||||||
formName: keyof Settings;
|
formName: keyof Settings;
|
||||||
@@ -13,14 +15,18 @@ interface GeneralPinInputProps {
|
|||||||
export default function GeneralPinInput(props: PropsWithChildren<GeneralPinInputProps>) {
|
export default function GeneralPinInput(props: PropsWithChildren<GeneralPinInputProps>) {
|
||||||
const { register, formName, isDisabled } = props;
|
const { register, formName, isDisabled } = props;
|
||||||
const [isVisible, setVisible] = useState(false);
|
const [isVisible, setVisible] = useState(false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<InputGroup size='sm' width='100px'>
|
<InputGroup size='sm' width='100px'>
|
||||||
<Input
|
<Input
|
||||||
variant='ontime-filled'
|
variant='ontime-filled'
|
||||||
type={isVisible ? 'text' : 'password'}
|
type={isVisible ? 'text' : 'password'}
|
||||||
maxLength={4}
|
maxLength={4}
|
||||||
{...register(formName)}
|
{...register(formName, {
|
||||||
|
pattern: {
|
||||||
|
value: isAlphanumeric,
|
||||||
|
message: 'Only alphanumeric characters are allowed',
|
||||||
|
},
|
||||||
|
})}
|
||||||
placeholder='-'
|
placeholder='-'
|
||||||
isDisabled={isDisabled}
|
isDisabled={isDisabled}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user