From 87fe4dfb7ff0732239ef10122f80b727931c3020 Mon Sep 17 00:00:00 2001 From: Ildar Kamalov Date: Wed, 15 Jan 2025 11:53:26 +0300 Subject: [PATCH] static lease form --- .../Settings/Dhcp/StaticLeases/Form.tsx | 96 +++++++++++-------- .../Settings/Dhcp/StaticLeases/Modal.tsx | 2 +- 2 files changed, 55 insertions(+), 43 deletions(-) diff --git a/client/src/components/Settings/Dhcp/StaticLeases/Form.tsx b/client/src/components/Settings/Dhcp/StaticLeases/Form.tsx index a57f3371..28ab7241 100644 --- a/client/src/components/Settings/Dhcp/StaticLeases/Form.tsx +++ b/client/src/components/Settings/Dhcp/StaticLeases/Form.tsx @@ -1,10 +1,9 @@ import React from 'react'; - -import { Field, reduxForm } from 'redux-form'; +import { useForm, Controller } from 'react-hook-form'; import { Trans, useTranslation } from 'react-i18next'; import { useDispatch, useSelector, shallowEqual } from 'react-redux'; -import { renderInputField, normalizeMac } from '../../../../helpers/form'; +import { normalizeMac } from '../../../../helpers/form'; import { validateIpv4, validateMac, @@ -12,12 +11,11 @@ import { validateIpv4InCidr, validateIpGateway, } from '../../../../helpers/validators'; -import { FORM_NAME } from '../../../../helpers/constants'; import { toggleLeaseModal } from '../../../../actions'; import { RootState } from '../../../../initialState'; -interface FormStaticLeaseProps { +type Props = { initialValues?: { mac?: string; ip?: string; @@ -25,63 +23,80 @@ interface FormStaticLeaseProps { cidr?: string; gatewayIp?: string; }; - pristine: boolean; - handleSubmit: (...args: unknown[]) => string; - reset: () => void; - submitting: boolean; processingAdding?: boolean; cidr?: string; isEdit?: boolean; + onSubmit: (data: any) => void; } -const Form = ({ handleSubmit, reset, pristine, submitting, processingAdding, cidr, isEdit }: FormStaticLeaseProps) => { +export const Form = ({ initialValues, processingAdding, cidr, isEdit, onSubmit }: Props) => { const { t } = useTranslation(); const dispatch = useDispatch(); - const dynamicLease = useSelector((store: RootState) => store.dhcp.leaseModalConfig, shallowEqual); + const { handleSubmit, control, reset, formState: { isSubmitting, isDirty } } = useForm({ + defaultValues: initialValues, + }); + const onClick = () => { reset(); dispatch(toggleLeaseModal()); }; return ( -
+
- ( + field.onChange(normalizeMac(e.target.value))} + /> + )} />
- ( + + )} />
- ( + + )} />
@@ -91,15 +106,17 @@ const Form = ({ handleSubmit, reset, pristine, submitting, processingAdding, cid @@ -107,8 +124,3 @@ const Form = ({ handleSubmit, reset, pristine, submitting, processingAdding, cid
); }; - -export default reduxForm< - Record, - Omit ->({ form: FORM_NAME.LEASE })(Form); diff --git a/client/src/components/Settings/Dhcp/StaticLeases/Modal.tsx b/client/src/components/Settings/Dhcp/StaticLeases/Modal.tsx index 38ed094d..e49b4e9c 100644 --- a/client/src/components/Settings/Dhcp/StaticLeases/Modal.tsx +++ b/client/src/components/Settings/Dhcp/StaticLeases/Modal.tsx @@ -4,7 +4,7 @@ import { Trans, withTranslation } from 'react-i18next'; import ReactModal from 'react-modal'; import { shallowEqual, useDispatch, useSelector } from 'react-redux'; -import Form from './Form'; +import { Form } from './Form'; import { toggleLeaseModal } from '../../../../actions'; import { MODAL_TYPE } from '../../../../helpers/constants';