mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-19 13:31:53 +03:00
filter check form
This commit is contained in:
parent
81f66c5b9f
commit
77420d8c96
1 changed files with 26 additions and 23 deletions
|
@ -1,53 +1,57 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { Field, reduxForm } from 'redux-form';
|
|
||||||
import { useSelector } from 'react-redux';
|
import { useSelector } from 'react-redux';
|
||||||
|
import { useForm } from 'react-hook-form';
|
||||||
|
|
||||||
import Card from '../../ui/Card';
|
import Card from '../../ui/Card';
|
||||||
|
|
||||||
import { renderInputField } from '../../../helpers/form';
|
|
||||||
|
|
||||||
import Info from './Info';
|
import Info from './Info';
|
||||||
import { FORM_NAME } from '../../../helpers/constants';
|
|
||||||
import { RootState } from '../../../initialState';
|
import { RootState } from '../../../initialState';
|
||||||
|
|
||||||
interface CheckProps {
|
interface FormValues {
|
||||||
handleSubmit: (...args: unknown[]) => string;
|
name: string;
|
||||||
pristine: boolean;
|
|
||||||
invalid: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Check = (props: CheckProps) => {
|
type Props = {
|
||||||
const { pristine, invalid, handleSubmit } = props;
|
onSubmit?: (data: FormValues) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Check = ({ onSubmit }: Props) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const processingCheck = useSelector((state: RootState) => state.filtering.processingCheck);
|
const processingCheck = useSelector((state: RootState) => state.filtering.processingCheck);
|
||||||
|
|
||||||
const hostname = useSelector((state: RootState) => state.filtering.check.hostname);
|
const hostname = useSelector((state: RootState) => state.filtering.check.hostname);
|
||||||
|
|
||||||
|
const {
|
||||||
|
register,
|
||||||
|
handleSubmit,
|
||||||
|
formState: { isDirty, isValid },
|
||||||
|
} = useForm<FormValues>({
|
||||||
|
mode: 'onChange',
|
||||||
|
defaultValues: {
|
||||||
|
name: '',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card title={t('check_title')} subtitle={t('check_desc')}>
|
<Card title={t('check_title')} subtitle={t('check_desc')}>
|
||||||
<form onSubmit={handleSubmit}>
|
<form onSubmit={handleSubmit(onSubmit)}>
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<div className="col-12 col-md-6">
|
<div className="col-12 col-md-6">
|
||||||
<div className="input-group">
|
<div className="input-group">
|
||||||
<Field
|
<input
|
||||||
id="name"
|
id="name"
|
||||||
name="name"
|
|
||||||
component={renderInputField}
|
|
||||||
type="text"
|
type="text"
|
||||||
className="form-control"
|
className="form-control"
|
||||||
placeholder={t('form_enter_host')}
|
placeholder={t('form_enter_host') ?? ''}
|
||||||
|
{...register('name', { required: true })}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<span className="input-group-append">
|
<span className="input-group-append">
|
||||||
<button
|
<button
|
||||||
className="btn btn-success btn-standard btn-large"
|
className="btn btn-success btn-standard btn-large"
|
||||||
type="submit"
|
type="submit"
|
||||||
onClick={handleSubmit}
|
disabled={!isDirty || !isValid || processingCheck}
|
||||||
disabled={pristine || invalid || processingCheck}>
|
>
|
||||||
{t('check')}
|
{t('check')}
|
||||||
</button>
|
</button>
|
||||||
</span>
|
</span>
|
||||||
|
@ -56,7 +60,6 @@ const Check = (props: CheckProps) => {
|
||||||
{hostname && (
|
{hostname && (
|
||||||
<>
|
<>
|
||||||
<hr />
|
<hr />
|
||||||
|
|
||||||
<Info />
|
<Info />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
@ -67,4 +70,4 @@ const Check = (props: CheckProps) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default reduxForm({ form: FORM_NAME.DOMAIN_CHECK })(Check);
|
export default Check;
|
||||||
|
|
Loading…
Reference in a new issue